コード例 #1
0
        //NOTE: Late update used bc. OpenVR is updated during Update() and this way we ensure, that we have latest data and we're not frame behind
        private void LateUpdate()
        {
            if (VRSystem.Instance == null || !VRSystem.Instance.IsConnected)
            {
                return;
            }
            VREye[] eyes = VRSystem.Instance.EyesProperties;
            VRPose  pose = VRSystem.Instance.TrackerCameraPose;

            UpdateCamera(LeftEyeCamera, 0);
            UpdateCamera(RightEyeCamera, 1);

            var transform = TrackerAnchor.LocalTransform;

            transform.Translation = pose.Position;
            transform.Orientation = pose.Orientation;

            TrackerAnchor.LocalTransform = transform;

            foreach (VRController controller in vrControllers)
            {
                VRControllerRole role = controller.Role;
                int cIndex;
                if (role == VRControllerRole.LeftHand)
                {
                    cIndex = VRSystem.Instance.LeftControllerIndex;
                }
                else if (role == VRControllerRole.RightHand)
                {
                    cIndex = VRSystem.Instance.RightControllerIndex;
                }
                else
                {
                    cIndex = controller.ControllerIndex;
                }

                VRControllerState[] states = VRSystem.Instance.Controllers;
                VRControllerState   newState;

                if (cIndex >= 0 && states != null && cIndex < states.Length)
                {
                    newState = states[cIndex];
                }
                else
                {
                    newState = new VRControllerState();
                }

                controller.UpdateState(newState);
            }
            VRPose centerPose = eyes[2].Pose;

            transform             = CenterEyeAnchor.LocalTransform;
            transform.Translation = centerPose.Position;
            transform.Orientation = centerPose.Orientation;

            CenterEyeAnchor.LocalTransform = transform;
        }
コード例 #2
0
        public static void ToVRPose(this TrackedDevicePose_t trackedPose, out VRPose pose)
        {
            Matrix poseMatrix;

            trackedPose.mDeviceToAbsoluteTracking.ToMatrix(out poseMatrix);

            pose.Position    = poseMatrix.Translation;
            pose.Orientation = poseMatrix.Orientation;
        }
コード例 #3
0
        private void UpdateCamera(Camera camera, int eyeIndex)
        {
            VREye  eye  = VRSystem.Instance.EyesProperties[eyeIndex];
            VRPose pose = eye.Pose;

            // HACK... TODO: better method?
            camera.FieldOfView = VRSystem.Instance.FieldOfView;
            if (eyeIndex == 0)
            {
                VRSystem.Instance.Left.Camera = camera;
            }
            else if (eyeIndex == 1)
            {
                VRSystem.Instance.Right.Camera = camera;
            }

            var transform = camera.LocalTransform;

            transform.Translation = Monoscopic ? CenterEyeAnchor.LocalTransform.Translation : pose.Position;
            transform.Orientation = Monoscopic ? CenterEyeAnchor.LocalTransform.Orientation : pose.Orientation;
            camera.LocalTransform = transform;
        }
コード例 #4
0
 /// <summary>
 /// Updates the specified pose.
 /// </summary>
 /// <param name="pose">The pose.</param>
 internal void Update(VRPose pose)
 {
     IsConnected = true;
     Pose        = pose;
 }
コード例 #5
0
 /// <summary>
 /// Update this instance
 /// </summary>
 /// <param name="id">The Id</param>
 /// <param name="pose">The pose</param>
 internal void Update(int id, VRPose pose)
 {
     this.Id          = id;
     this.IsConnected = true;
     this.Pose        = pose;
 }
コード例 #6
0
 public static void ToVRPose(this Matrix matrix, out VRPose pose)
 {
     pose.Position    = matrix.Translation;
     pose.Orientation = matrix.Orientation;
 }
コード例 #7
0
        internal void Update(int id, VRControllerRole role, ref VRControllerState_t state, ref VRPose pose)
        {
            this.Update(id, pose);

            this.Role = role;

            // Axies
            this.Trackpad.X = state.rAxis0.x;
            this.Trackpad.Y = state.rAxis0.y;
            this.Trigger    = state.rAxis1.x;

            // Buttons
            this.TrackpadButton  = state.GetButtonPressed(EVRButtonId.k_EButton_SteamVR_Touchpad).ToButtonState();
            this.TriggerButton   = state.GetButtonPressed(EVRButtonId.k_EButton_SteamVR_Trigger).ToButtonState();
            this.ApplicationMenu = state.GetButtonPressed(EVRButtonId.k_EButton_ApplicationMenu).ToButtonState();
            this.A    = state.GetButtonPressed(EVRButtonId.k_EButton_A).ToButtonState();
            this.Grip = state.GetButtonPressed(EVRButtonId.k_EButton_Grip).ToButtonState();

            this.TrackpadTouch = state.GetButtonTouched(EVRButtonId.k_EButton_SteamVR_Touchpad);

            // DPad
            this.DPad.Up    = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Up).ToButtonState();
            this.DPad.Right = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Right).ToButtonState();
            this.DPad.Left  = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Left).ToButtonState();
            this.DPad.Down  = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Down).ToButtonState();
        }