Example #1
0
        bool Process()
        {
            oculus = new OculusWrap.Wrap();

            // Initialize the Oculus runtime.
            bool success = oculus.Initialize();

            if (!success)
            {
                Console.WriteLine("Failed to initialize the Oculus runtime library.");
                return(false);
            }
            int numberOfHeadMountedDisplays = oculus.Hmd_Detect();

            if (numberOfHeadMountedDisplays > 0)
            {
                hmd = oculus.Hmd_Create(0);
            }
            else
            {
                hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2);
            }

            if (hmd == null)
            {
                Console.WriteLine("Oculus Rift not detected.");
                return(false);
            }

            if (hmd.ProductName == string.Empty)
            {
                Console.WriteLine("The HMD is not enabled.");
            }

            // Specify which head tracking capabilities to enable.
            hmd.SetEnabledCaps(OculusWrap.OVR.HmdCaps.LowPersistence | OculusWrap.OVR.HmdCaps.DynamicPrediction);

            // Start the sensor which informs of the Rift's pose and motion
            hmd.ConfigureTracking(OculusWrap.OVR.TrackingCaps.ovrTrackingCap_Orientation | OculusWrap.OVR.TrackingCaps.ovrTrackingCap_MagYawCorrection | OculusWrap.OVR.TrackingCaps.ovrTrackingCap_Position, OculusWrap.OVR.TrackingCaps.None);

            Console.WriteLine("-- HmdDump --");
            Console.WriteLine("EyeHeight {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_EYE_HEIGHT, 0));

            var eyeToNoseDistance = new float[] { 0, 0 };

            hmd.GetFloatArray(OculusWrap.OVR.OVR_KEY_EYE_TO_NOSE_DISTANCE, ref eyeToNoseDistance);
            Console.WriteLine("EyeToNoseDist {0} {1}", eyeToNoseDistance[0], eyeToNoseDistance[1]);

            Console.WriteLine("IPD {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_IPD, 0));

            var neckToEyeDistance = new float[] { 0, 0 };

            hmd.GetFloatArray(OculusWrap.OVR.OVR_KEY_NECK_TO_EYE_DISTANCE, ref neckToEyeDistance);
            Console.WriteLine("NeckEyeDistance {0} {1}", neckToEyeDistance[0], neckToEyeDistance[1]);

            Console.WriteLine("PlayerHeight {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_PLAYER_HEIGHT, 0));

            hmd.Dispose();
            oculus.Dispose();

            return(true);
        }
Example #2
0
        /// <summary>
        /// 次のシーンフレームに進みます。
        /// </summary>
        public void FrameMove()
        {
            if (motion_enabled)
            {
                int frame_len = figures.GetMaxFrameLength();
                if (frame_len > 0)
                {
                    long dt = DateTime.Now.Ticks - start_ticks;
                    int  new_frame_index = (int)((start_frame_index + dt / wait) % frame_len);
                    Debug.Assert(new_frame_index >= 0);
                    Debug.Assert(new_frame_index < frame_len);
                    this.frame_index = new_frame_index;
                }
                figures.SetFrameIndex(this.frame_index);
                figures.UpdateBoneMatrices(true);
            }

            KeyboardState currentKeyboardState = keyboard.GetCurrentState();

            if (!keyboardState.IsPressed(Key.LeftControl) && currentKeyboardState.IsPressed(Key.LeftControl))
            {
                sneaked = !sneaked;
            }
            if (!keyboardState.IsPressed(Key.RightControl) && currentKeyboardState.IsPressed(Key.RightControl))
            {
                sneaked = !sneaked;
            }

            if (currentKeyboardState.IsPressed(Key.Left))
            {
                main_camera.RotY(+ocu_config.Angle);
            }
            if (currentKeyboardState.IsPressed(Key.Right))
            {
                main_camera.RotY(-ocu_config.Angle);
            }

            {
                float speed = sneaked ? ocu_config.Sneak.Speed : ocu_config.Speed;

                if (currentKeyboardState.IsPressed(Key.W))
                {
                    main_camera.Move(0, 0, -speed);
                }
                if (currentKeyboardState.IsPressed(Key.S))
                {
                    main_camera.Move(0, 0, +speed);
                }
                if (currentKeyboardState.IsPressed(Key.A))
                {
                    main_camera.Move(-speed, 0, 0);
                }
                if (currentKeyboardState.IsPressed(Key.D))
                {
                    main_camera.Move(+speed, 0, 0);
                }
            }

            {
                float y = sneaked ? ocu_config.Sneak.Y : ocu_config.Position.Y;

                main_camera.Position.Y = hmd.GetFloat(OculusWrap.OVR.OVR_KEY_EYE_HEIGHT, 0) + y;
            }

            keyboardState = currentKeyboardState;
        }