0

I have downloaded the sdk and tried to load up the demo scene but there is no head tracking when I export an apk, any suggestions?

on installing the apk, i get the stereo scene and the cube is rotating, but no head tracking. I can turn on and off the distortion but have not found where I can enable head tracking.

Any help would be much appreciated.

euvrco
  • 11

3 Answers3

1

1.) Create a new c# script in Unity3D with this content:

using UnityEngine;
using System.Collections;

public class VROneRotateAround : MonoBehaviour {
    public Transform target;
    public float distance = 5f;
    public Vector3 offset = Vector3.zero;
    public bool useAngleX = true;   
    public bool useAngleY = true;
    public bool useAngleZ = true;
    public bool useRealHorizontalAngle = true;
    public bool resetViewOnTouch = true;

    private Quaternion initialRotation = Quaternion.identity;
    private Quaternion currentRotation;
    private static Vector3 gyroAngles; // original angles from gyro
    private static Vector3 usedAngles; // converted into unity world coordinates

    private int userSleepTimeOut; // original device SleepTimeOut setting
    private bool gyroAvail = false;

    void Start() {
        Input.compensateSensors = true;
        transform.position = (target.position + offset) - transform.forward * distance;
    }
    void FixedUpdate() {
        if (gyroAvail == false) {
            if (Input.gyro.attitude.eulerAngles != Vector3.zero && Time.frameCount > 30) {
                gyroAvail = true;
                initialRotation = Input.gyro.attitude;
                target.gameObject.SendMessage("StartFlight");
            }
            return; // early out
        }

        // reset origin on touch or not yet set origin
        if(resetViewOnTouch && (Input.touchCount > 0))
            initialRotation = Input.gyro.attitude;

        // new rotation
        currentRotation = Quaternion.Inverse(initialRotation)*Input.gyro.attitude;

        gyroAngles = currentRotation.eulerAngles;

        //usedAngles = Quaternion.Inverse (currentRotation).eulerAngles;
        usedAngles = gyroAngles;

        // reset single angle values
        if (useAngleX == false)
            usedAngles.x = 0f;
        if (useAngleY == false)
            usedAngles.y = 0f;
        if (useAngleZ == false)
            usedAngles.z = 0f;

        if (useRealHorizontalAngle)
            usedAngles.y *= -1;
        transform.localRotation = Quaternion.Euler (new Vector3(-usedAngles.x, usedAngles.y, usedAngles.z));
        transform.position = (target.position + offset) - transform.forward * distance;
    }

    public static Vector3 GetUsedAngles() {
        return usedAngles;
    }

    public static Vector3 GetGyroAngles() {
        return gyroAngles;
    }

    public void ResetView() {
        initialRotation = Input.gyro.attitude;
    }

    void OnEnable() {
        // sensor on
        Input.gyro.enabled = true;
        initialRotation = Quaternion.identity;
        gyroAvail = false;

        // store device sleep timeout setting
        userSleepTimeOut = Screen.sleepTimeout;
        // disable sleep timeout when app is running
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
    }

    void OnDisable() {
        // restore original sleep timeout
        Screen.sleepTimeout = userSleepTimeOut;
        //sensor off
        Input.gyro.enabled = false;
    }
}

Open the demo scene and attach this script to the VROneSDK prefab.

In the property editor select Cube as Target and enter 6 for distance.

Build the app and test it on a device or use UnityRemote to test the behaviour in the editor.

Harry
  • 36
  • 1
  • Thanks, I have completed all but one of the above steps, im not too sure how to do the following: "In the property editor select Cube as Target and enter 6 for distance." Might you be able to advise how I can select cube as target? Is this done within the script you posted? – euvrco Oct 11 '14 at 21:23
  • The first public parameter in the above script is named target. When then script is attached to the VROneSDK prefab drag any object from the unity scene into this field in the property editor. The target will be the gameobject the cameras rotate around. – Harry Oct 14 '14 at 05:56
0

the SDK seems to run only on the supported deviced you need to get a S5 to get it working. You also need to get the Android Pro Plugin for Unity. We actually did get the distotion going but the screen is cropped for like 10 pxels on either side. That can't be right.

-1

Same here: I see the demo scene (rotating cube on a grid backdrop and three light sources) in a left/right split-screen, but there is no head tracking. No pre-distortion either. This is on a Samsung Galaxy S3 (Android 4.3) with Unity 4.5.3f3.