cela faisait un bail !
Je viens quérir votre aide, car j'ai un petit souci. Je suis en train de développer une Appli VR mobile sous Android, Mon petit souci est de rendre compatible cette appli avec les téléphones comme le mien qui ne disposent pas de gyroscope.
J'ai orienté mes recherches sur l’accéléromètre et le compas. Mais je n'arrive à rien de fabuleux.
Auriez-vous quelconque tuyaux ? à noter que l'objectif est qu'aucune application ne soit téléchargée en plus.
Une partie de mon code :
Code : Tout sélectionner
public class CameraControllerVR : MonoBehaviour {
private GameObject cameraContainer;
private Quaternion rotation;
private bool isEnabled = false;
private Gyroscope gyro;
float xRot, yRot, zRot;
public float rotationSpeed = 20f;
private Vector3 direction = Vector3.zero;
void Start () {
/*
* 1- Create new gameObject
* 2- Retrieve position of the camera
* 3- Parent to mainCamera
*/
cameraContainer = new GameObject("CameraContainer");
cameraContainer.transform.position = transform.position;
transform.SetParent(cameraContainer.transform);
}
void EnableCompass()
{
if (!isEnabled)
{
//Debug.Log("Enable compass");
Input.compass.enabled = true;
Input.location.Start();
//Debug.Log(Input.location.status);
//Debug.Log(Input.compass.enabled);
// isEnabled = true;
}
}
void Update () {
/* if (isEnabled)
{
transform.localRotation = gyro.attitude * rotation;
}
*/
EnableGyro();
EnableCompass();
Debug.Log(Input.compass.rawVector.y);
if (Input.acceleration != direction) {
Debug.Log("x :"+Input.acceleration.x+ " y : "+Input.acceleration.y +" z : " + Input.acceleration.z);
direction.x = Input.acceleration.z * -90f;
direction.y = 0f;//-Input.compass.trueHeading * 0.5f;
direction.z = 0f; //Input.acceleration.x * -90f;
//cameraContainer.transform.rotation = Quaternion.Euler(0, -Input.compass.magneticHeading, 0);
Quaternion quat = transform.localRotation;
transform.rotation = Quaternion.Lerp(quat, Quaternion.Euler(new Vector3(direction.x, direction.y, direction.z)), Time.deltaTime * rotationSpeed);
}
}