示例#1
0
        private static void ReadPoses(float seconsdAhead)
        {//to be called from RENDER thread
            if (m_vrCompositor == null)
            {
                return;
            }
            ProfilerShort.Begin("MOVR:ReadPoses");
            //MyLog.Default.WriteLine("   GetPoses");
            var error3 = m_vrCompositor.WaitGetPoses(renderPose, gamePose);//TODO will not initialize correctly without it but maybe not necessary to do all the time

            m_vrSystem.GetDeviceToAbsoluteTrackingPose(m_vrCompositor.GetTrackingSpace(), seconsdAhead, gamePose);

            uint nDevice = 0;
            bool firstControllerFound = false;

            foreach (var rPose in gamePose)
            {
                if (!rPose.bDeviceIsConnected)
                {
                    break;
                }
                if (rPose.bPoseIsValid)
                {
                    switch (m_vrSystem.GetTrackedDeviceClass(nDevice))
                    {
                    case ETrackedDeviceClass.HMD:
                        if (rPose.eTrackingResult != ETrackingResult.Running_OK)
                        {
                            Log.WriteLineAndConsole("Pose: " + nDevice + " not Running OK");
                            continue;
                        }
                        PoseToViewMatrix(ref m_viewHMD, ref gamePose[nDevice].mDeviceToAbsoluteTracking);
                        PoseToTransMatrixD(ref m_headsetPosD, ref gamePose[nDevice].mDeviceToAbsoluteTracking);
                        m_viewHMD.M42 -= FloorOffset;

                        //QS1 axes: X red ship's rear
                        //          Y up
                        //          Z from red ship to platform

                        //translation up-down is inverted
                        break;

                    case ETrackedDeviceClass.Controller:
                        if (!firstControllerFound)
                        {
                            firstControllerFound = true;
                            if (m_controller1ID != nDevice)
                            {
                                Log.WriteLine("Controller1 is now ID #" + nDevice);
                                m_controller1ID = nDevice;
                            }
                        }
                        else
                        if (m_controller2ID != nDevice)
                        {
                            Log.WriteLine("Controller2 is now ID #" + nDevice);
                            m_controller2ID = nDevice;
                        }
                        if (nDevice == m_controller1ID)
                        {
                            PoseToTransMatrix(ref m_c1pos, ref gamePose[nDevice].mDeviceToAbsoluteTracking);
                        }
                        else
                        if (nDevice == m_controller2ID)
                        {
                            PoseToTransMatrix(ref m_c2pos, ref gamePose[nDevice].mDeviceToAbsoluteTracking);
                        }
                        break;
                    }
                }
                //else
                //    Log.WriteLineAndConsole("Pose: " + nDevice + " not valid");

                nDevice++;
            }
            ProfilerShort.End();
        }