pcharb
pcharb

Reputation: 184

How to control oculus rotation and potition in unity 5.3.x

I want to control the rotation and position of the Oculus DK2 in Unity 5.3 over. It doesn't seems to be trivial, I've already tried all I could find on unity forum, but nothing seems to works. The CameraRig script doesn't look to do anything when i change it. I want to disable all rotation and position because I have a mocap system that more reliable for those things.

Need some help!

Upvotes: 2

Views: 2464

Answers (1)

Scott Chamberlain
Scott Chamberlain

Reputation: 127543

To be able to control the pose your camera must be represented by using a OVRCameraRig that is included with the OVRPlugin for Unity 5.

Once you have that you can use the UpdatedAnchors event from the camera to transform the mocap data on to the camera position, just overwrite the value of OVRCameraRig.trackerAnchor for the head and OVRCameraRig.leftHandAnchor and OVRCameraRig.rightEyeAnchorfor hand positions if your suit supports those.

public class MocapController : MonoBehavior
{    
    public OVRCameraRig camera; //Drag camera rig object on to the script in the editor.

    void Awake()
    {
        camera.UpdatedAnchors += UpdateAnchors 
    }

    void UpdatedAnchors(OVRCameraRig rigToUpdate)
    {
        Transform headTransform = GetHeadTransform(); //Write yourself
        Transform lHandTransform = GetLHandTransform(); //Write yourself
        Transform rHandTransform = GetRHandTransform(); //Write yourself

        rigToUpdate.trackerAnchor = headTransform;
        rigToUpdate.leftHandAnchor= lHandTransform;
        rigToUpdate.rightHandAnchor= rHandTransform;
    }
}

Upvotes: 2

Related Questions