Example #1
0
    void OnRenderObject()
    {
        // The overlay must be specified every eye frame, because it is positioned relative to the
        // current head location.  If frames are dropped, it will be time warped appropriately,
        // just like the eye buffers.

        if (currentOverlayType == OverlayType.None)
        {
            GetComponent <Renderer>().enabled = true;                   // use normal renderer
            return;
        }

        bool overlay = (currentOverlayType == OverlayType.Overlay);

        Transform camPose       = Camera.current.transform;
        Matrix4x4 modelToCamera = camPose.worldToLocalMatrix * transform.localToWorldMatrix;

        Vector3    headPos       = VR.InputTracking.GetLocalPosition(VR.VRNode.Head);
        Quaternion headOrt       = VR.InputTracking.GetLocalRotation(VR.VRNode.Head);
        Matrix4x4  cameraToStart = Matrix4x4.TRS(headPos, headOrt, Vector3.one);

        Matrix4x4 modelToStart = cameraToStart * modelToCamera;

        OVRPose pose;

        pose.position    = modelToStart.GetColumn(3);
        pose.orientation = Quaternion.LookRotation(modelToStart.GetColumn(2), modelToStart.GetColumn(1));

        // Convert left-handed to right-handed.
        pose.position.z    = -pose.position.z;
        pose.orientation.w = -pose.orientation.w;

        Vector3 scale = transform.lossyScale;

        for (int i = 0; i < 3; ++i)
        {
            scale[i] /= Camera.current.transform.lossyScale[i];
        }

        OVRPlugin.Bool result = OVRPlugin.SetOverlayQuad(overlay.ToBool(), texId, IntPtr.Zero, pose.ToPosef(), scale.ToVector3f());

        GetComponent <Renderer>().enabled = (result == OVRPlugin.Bool.False);                   // render with the overlay plane instead of the normal renderer
    }
Example #2
0
 public static extern void SetSpaceWarp(OVRPlugin.Bool on);