- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Quazar_100 · Jun 11, 2015 at 10:44 AM ·
android
ALPSVR Camera Roll & Yaw
Hi,
It's now some days I'm struggling with it, as the title says, I just want the gyro when tilting & yawing to rotate correctly in between some limits (-90° Y -> +90° Y, -60° X -> +60° X, -45° Z -> +45° Z).
For now, it's just moving forward & also keeps rotating, only when you keep your head rotating on itself, so it's not practical, in a situation were we sit on a chair.
/************************************************************************
ALPSNavigation provides an input-free navigation system
Copyright (C) 2014 ALPS VR.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
************************************************************************/
using UnityEngine;
using System.Collections;
//[RequireComponent (typeof (CharacterController))]
[System.Serializable]
public class ALPSNavigation : MonoBehaviour {
//=====================================================================================================
// Attributes
//=====================================================================================================
/**Public**/
public static float pitch;
public static float yaw;
public static float roll;
public float speed = 3;
public int vibration = 20;
public float forwardLowerBound = 20;
public float forwardUpperBound = 30;
public float forwardLimit = 50;
public float backwardLowerBound = 20;
public float backwardUpperBound = 30;
public float backwardLimit = 50;
public static float ForwardLowerBound;
public static float ForwardUpperBound;
public static float BackwardLowerBound;
public static float BackwardUpperBound;
public static float ForwardLimit;
public static float BackwardLimit;
/**Private**/
//private CharacterController controller;
private bool moving;
private GameObject head;
private Transform target;
//=====================================================================================================
// Functions
//=====================================================================================================
/// <summary>
/// Initializes navigation system.
/// </summary>
public void Start () {
ForwardLowerBound = forwardLowerBound;
ForwardUpperBound = forwardUpperBound;
BackwardLowerBound = 360 - backwardLowerBound;
BackwardUpperBound = 360 - backwardUpperBound;
ForwardLimit = forwardLimit;
BackwardLimit = 360 - backwardLimit;
//controller = this.GetComponent ("CharacterController") as CharacterController;
head = GameObject.Find ("ALPSHead");
if (Application.platform == RuntimePlatform.Android) {
moving = false;
}
target = head.transform;
}
/// <summary>
/// Updates navigation state.
/// </summary>
public void Update () {
if (!moving){
moving = true;
}
print ("Rotation : " + target.rotation);
pitch = head.transform.eulerAngles.x;
print ("Pitch : " + pitch);
yaw = head.transform.eulerAngles.y;
print ("Yaw : " + yaw);
//roll += Input.GetAxis("Roll");
roll += head.transform.eulerAngles.z;
print ("Roll : " + roll);
head.transform.Translate(Vector3.forward * Time.deltaTime * speed);
}
/// <summary>
/// Initialize Android ALPS Activity.
/// </summary>
public static float Progress(){
if (pitch >= ForwardLowerBound && pitch <= ForwardUpperBound || pitch >= BackwardUpperBound && pitch <= BackwardLowerBound) {
return 1f;
} else {
if(pitch>=0 && pitch < ForwardLowerBound) return pitch/25f;
else if(pitch<=360 && pitch > BackwardLowerBound)return (360-pitch)/25f;
else if(pitch>ForwardUpperBound && pitch <= ForwardLimit)return (ForwardLimit-pitch)/25f;
else if(pitch<BackwardUpperBound && pitch >= BackwardLimit)return (pitch-BackwardLimit)/25f;
else return 0f;
}
}
}
It's a free VR SDK for VR : ALPSVR
Thanks in advance for any advice & help !
Comment
Your answer
Follow this Question
Related Questions
android terrain textures problem 2 Answers
Android Remote Unty 3.4 2 Answers
Why SetActive Game Objects generate too much Garbage in the profiler? 1 Answer
Photon refusing connection on Android 0 Answers
How do you make falling text? 4 Answers