예제 #1
0
        /// <summary>
        ///
        /// </summary>
        public override void Prepare()
        {
            hmd.BeginFrame(0);

            OVR.EyeType eye = hmd.EyeRenderOrder[0];
            eyeRenderPose[(int)eye] = hmd.GetHmdPosePerEye(eye);
            eye = hmd.EyeRenderOrder[1];
            eyeRenderPose[(int)eye] = hmd.GetHmdPosePerEye(eye);

            var trackingState = hmd.GetTrackingState(oculus.GetTimeInSeconds());
            var hPos          = trackingState.HeadPose.ThePose.Position;
            var hRot          = trackingState.HeadPose.ThePose.Orientation;

            var left = new OculusRiftSensors.Eye {
                Position = new Vector3(eyeRenderPose[0].Position.X, eyeRenderPose[0].Position.Y, eyeRenderPose[0].Position.Z),
                Rotation = new Quaternion(eyeRenderPose[0].Orientation.X, eyeRenderPose[0].Orientation.Y, eyeRenderPose[0].Orientation.Z, eyeRenderPose[0].Orientation.W),
            };

            var right = new OculusRiftSensors.Eye {
                Position = new Vector3(eyeRenderPose[1].Position.X, eyeRenderPose[1].Position.Y, eyeRenderPose[1].Position.Z),
                Rotation = new Quaternion(eyeRenderPose[1].Orientation.X, eyeRenderPose[1].Orientation.Y, eyeRenderPose[1].Orientation.Z, eyeRenderPose[1].Orientation.W),
            };


            var leftProj = oculus.Matrix4f_Projection(eyeRenderDesc[0].Fov, 0.1f, 1000.0f, true).ToMatrix();

            leftProj.Transpose();
            var rightProj = oculus.Matrix4f_Projection(eyeRenderDesc[1].Fov, 0.1f, 1000.0f, true).ToMatrix();

            rightProj.Transpose();


            left.Projection  = leftProj;
            right.Projection = rightProj;

            OculusRiftSensors.LeftEye      = left;
            OculusRiftSensors.RightEye     = right;
            OculusRiftSensors.HeadPosition = new Vector3(hPos.X, hPos.Y, hPos.Z);
            OculusRiftSensors.HeadRotation = new Quaternion(hRot.X, hRot.Y, hRot.Z, hRot.W);

            //Console.WriteLine("Cam pose: " + trackingState.CameraPose.Position.X + " " + trackingState.CameraPose.Position.Y + " " +trackingState.CameraPose.Position.Z);
            //Console.WriteLine("Leveled Cam pose: " + trackingState.LeveledCameraPose.Position.X + " " + trackingState.LeveledCameraPose.Position.Y + " " + trackingState.LeveledCameraPose.Position.Z);
        }