Skip to main content
Up and Coming
August 2, 2014

Getting IR Camera Transform

Just curious if anyone's poked around and found a way to get the transform for the IR camera in worldspace? It's the sort of thing that would be quite nice to have, similar to the way you can enable camera bounds in the demo scene, to help inform the player of the bounds of their movement.
    This topic has been closed for replies.

    26 replies

    Up and Coming
    July 8, 2015
    I got this working with the latest OculusUtilities_0_1_0_beta...

    First, download the UnityPackage linked in this post https://forums.oculus.com/viewtopic.php?f=37&t=11779#p160605

    Then modify the OVRViewCone.cs file in the package like so.

    using UnityEngine;
    using System.Collections;


    public class OVRViewCone : MonoBehaviour
    {

    private GameObject viewConeMesh;
    public OVRManager camController;
    public OVRTracker tracker;
    public GameObject TrackedCam;

    public float updateInterval = 5f;
    float lastUpdate = 0;

    // Use this for initialization
    void Start()
    {
    //OVRDevice.ResetOrientation ();
    //updateCameraTracker ();

    viewConeMesh = transform.FindChild("viewConeMesh").gameObject;
    }

    // Update is called once per frame
    void Update()
    {
    /*
    if (Input.GetKeyDown (KeyCode.JoystickButton0) || Input.GetKeyDown (KeyCode.KeypadEnter))
    {
    OVRDevice.ResetOrientation ();
    updateCameraTracker ();
    }
    */

    if (lastUpdate + updateInterval < Time.time)
    {
    if (camController.usePositionTracking)
    {
    updateCameraTracker();
    }
    lastUpdate = Time.time;
    }

    Vector3 cameraPos = TrackedCam.transform.position;
    viewConeMesh.GetComponent<Renderer>().material.SetVector("_CameraPos", new Vector4(cameraPos.x, cameraPos.y, cameraPos.z, 0));
    }

    public void updateCameraTracker()
    {
    Vector3 IRCameraPos = Vector3.zero;
    Quaternion IRCameraRot = Quaternion.identity;

    float cameraHFov = 0;
    float cameraVFov = 0;
    float cameraNearZ = 0;
    float cameraFarZ = 0;

    GetIRCamera(ref IRCameraPos, ref IRCameraRot, ref cameraHFov, ref cameraVFov, ref cameraNearZ, ref cameraFarZ);

    //IRCameraPos.z *= -1;

    transform.localPosition = IRCameraPos;
    transform.localRotation = IRCameraRot;

    //Debug.Log ("HFov " + cameraHFov.ToString ());
    //Debug.Log ("VFov " + cameraVFov.ToString ());

    float horizontalScale = Mathf.Tan(cameraHFov / 2f);
    float verticalScale = Mathf.Tan(cameraVFov / 2f);

    //Debug.Log ("HDistance " + horizontalScale.ToString ());
    //Debug.Log ("VDistance " + verticalScale.ToString ());

    transform.localScale = new Vector3(horizontalScale * cameraFarZ, verticalScale * cameraFarZ, cameraFarZ);
    }

    bool GetIRCamera(ref Vector3 position,
    ref Quaternion rotation,
    ref float cameraHFov,
    ref float cameraVFov,
    ref float cameraNearZ,
    ref float cameraFarZ)
    {
    //if (!OVRManager.isSupportedPlatform || Hmd==null) return false;
    /*
    ovrTrackingState ss = OVRDevice.HMD.GetTrackingState();

    rotation = new Quaternion( ss.CameraPose.Orientation.x,
    ss.CameraPose.Orientation.y,
    ss.CameraPose.Orientation.z,
    ss.CameraPose.Orientation.w);

    position = new Vector3( ss.CameraPose.Position.x,
    ss.CameraPose.Position.y,
    ss.CameraPose.Position.z);
    */
    OVRPose ss = OVRManager.tracker.GetPose(0f);

    rotation = new Quaternion(ss.orientation.x,
    ss.orientation.y,
    ss.orientation.z,
    ss.orientation.w);

    position = new Vector3(ss.position.x,
    ss.position.y,
    ss.position.z);

    OVRTracker.Frustum ff = OVRManager.tracker.frustum;


    cameraHFov = ff.fov.x * (float)Mathf.PI / 180.0f;
    cameraVFov = ff.fov.y * (float)Mathf.PI / 180.0f;
    cameraNearZ = ff.nearZ;
    cameraFarZ = ff.farZ;

    /*
    HmdDesc desc = Hmd.HmdDesc();

    cameraHFov = desc.CameraFrustumHFovInRadians;
    cameraVFov = desc.CameraFrustumVFovInRadians;
    cameraNearZ = desc.CameraFrustumNearZInMeters;
    cameraFarZ = desc.CameraFrustumFarZInMeters;
    */
    //OVRDevice.OrientSensor (ref rotation);

    return true;
    }
    }



    Add the view cone parented by the TrackerAnchor from the Oculus Utilities. Rotated to (0,180,0).
    Add the modified script to TrackerAnchor and assign the variables.

    Play.
    Inspiring
    July 8, 2015
    Cool. Thanks for sharing.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    July 12, 2015
    Thank you Oculus for releasing the Utilities pack!

    I also used it to render a basic view cone with the line renderer which I use for development.

    It's not as sophisticated as the one above, but this one has no dependencies and is quick to setup. The 'i' key will toggle the view cone, and 'r' key resets orientation.

    viewCone2.PNG

    To use it with OVR Camera Rig: create a gameobject under your "Tracking Space" and attach this script. Drag the center eye camera on to the VR Camera param. Done.

    To use it with Unity's VR, lets say with FirstPersonController: create a new game object named "Tracking Space" under the top level FPSController and move the FirstPersonCharacter as it's child. Then as above, make a game object under the Tracking Space and attach this script. Drag the FirstPersonCharacter camera onto the VR Param. Done.

    Note: In both cases, the game object with the View Cone should be set to the same transform values as on the VR Camera.
    Check out my Unity VR development blog: http://talesfromtherift.com @peterept
    March 18, 2016
    Hi, I need the IR Camera transform infos so i can align VR content with the same elements build in real life ,and this thread is the closest answer i found .
    After reading all , i tried my best, but it seems that since it s been simplified in the editor, OVR elements aren t accessible anymore ? Of course they have to be somewhere but couldn t figure where . Am i missing something? an update would be greatly apreciated , thx !
    Up and Coming
    March 21, 2016
    If you know where the IR camera is located in the real world, you should be able to move the align in scene objects with that point. What's not working for you?
    Check out my Unity VR development blog: http://talesfromtherift.com @peterept
    New Participant
    June 5, 2016
    @peterept .. Could you help me with integration into the LeapMotion 'HeadMountedRig' .. I've tried various combinations in the hierarchy, but cannot get a result. Thank you.