Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
eoinmc20's avatar
eoinmc20
Honored Guest
11 years ago

how to Invert Oculus OVRCameraRig in Unity????

hello,

I'm developing a game in unity with the Oculus rift DK1, I have the OVRCamerarig set up in my project and it works with no problem as it is but I need to invert the view from the OVRcameraRig ( so its upside down ) but everything iv tried hasn't worked or just makes the camera glitch out like its stuck in a infinite spin.

if anybody has done this or knows of a way it will be greatly appreciated :D

4 Replies

  • try setting the localScale of the LeftEyeAnchor and RightEyeAnchor to (1, -1, 1)
  • thanks for your reply PhyterJet,
    Below is the code in my UpdateAnchors Method, unfortunately it isnt working, any other ideas or am i doing something wrong?

    Thanks
    :)

    private void UpdateAnchors()
    {
    OVRPose leftEye = OVRManager.display.GetEyePose(OVREye.Left);
    OVRPose rightEye = OVRManager.display.GetEyePose(OVREye.Right);

    leftEyeAnchor.localRotation = leftEye.orientation;
    centerEyeAnchor.localRotation = leftEye.orientation; // using left eye for now
    rightEyeAnchor.localRotation = rightEye.orientation;

    leftEyeAnchor.localPosition = leftEye.position;
    centerEyeAnchor.localPosition = 0.5f * (leftEye.position + rightEye.position);
    rightEyeAnchor.localPosition = rightEye.position;
    rightEyeAnchor.localScale = new Vector3 (1, -1, 1);
    leftEyeAnchor.localScale = new Vector3 (1, -1, 1);

    }
  • I'm sorry but I was wrong, the scale does not affect the cameras viewport.

    As I learned in this thread https://forums.oculus.com/viewtopic.php?f=37&t=22522: as of the 0.5.0 Unity Integration we are advised not change the transform of the "anchor" gameObjects (which are leftEyeAnchor, rightEyeAnchor, CenterEyeAnchor and TrackerAnchor).

    So instead we modify the new parent gameObject: 'TrackingSpace'

    This update method rotates the attached gameObject by 180 degrees when the the A key is pressed. So add this to a script attached to the TrackingSpace object and see if it does what you want.

    bool rotated = false;
    void Update () {
    float z_rotation;
    if (Input.GetKeyDown (KeyCode.A)) {
    if (rotated)
    z_rotation = Mathf.PI; // 180 degrees
    else
    z_rotation = 0; // 0 degrees

    transform.rotation = Quaternion.EulerAngles (0, 0, z_rotation);
    rotated= !rotated;
    }
    }


    EDIT:
    If you want to 'flip' the cameras vertically (and not rotate) then you can use this script. Which should be attached to both cameras 'leftEyeAnchor' and 'rightEyeAnchor'.
    using UnityEngine;
    using System.Collections;

    public class FlipCamera : MonoBehaviour {
    void OnPreCull () {
    camera.ResetWorldToCameraMatrix ();
    camera.ResetProjectionMatrix ();
    camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale (new Vector3 (1, -1, 1));
    }
    void OnPreRender () {
    GL.SetRevertBackfacing (true);
    }
    void OnPostRender () {
    GL.SetRevertBackfacing (false);
    }
    }
  • You're a Saint, it worked!! thanks for the help really appreciate it :D