Example #1
0
        /// <summary>
        /// Updates the controller.
        /// </summary>
        /// <param name="role">The role.</param>
        /// <param name="state">The state.</param>
        /// <param name="pose">The pose.</param>
        internal void Update(VRControllerRole role, ref VRControllerState_t state, ref VRPose pose)
        {
            IsConnected = true;
            Pose        = pose;
            Role        = role;

            // Trackpad
            Trackpad.X     = state.rAxis0.x;
            Trackpad.Y     = state.rAxis0.y;
            TrackpadTouch  = state.GetButtonTouched(EVRButtonId.k_EButton_Axis0);
            TrackpadButton = state.GetButtonPressed(EVRButtonId.k_EButton_Axis0).ToButtonState();

            // Trigger
            Trigger       = state.rAxis1.x;
            TriggerButton = state.GetButtonPressed(EVRButtonId.k_EButton_Axis1).ToButtonState();

            // Buttons
            ApplicationMenu = state.GetButtonPressed(EVRButtonId.k_EButton_ApplicationMenu).ToButtonState();
            A    = state.GetButtonPressed(EVRButtonId.k_EButton_A).ToButtonState();
            Grip = state.GetButtonPressed(EVRButtonId.k_EButton_Grip).ToButtonState();

            // DPad
            DPad.Up    = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Up).ToButtonState();
            DPad.Down  = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Down).ToButtonState();
            DPad.Left  = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Left).ToButtonState();
            DPad.Right = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Right).ToButtonState();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VRSystem"/> class.
        /// </summary>
        public VRSystem()
        {
            // ShowHMDMirrorTexture = false;

            // Setup arrays
            renderPoses             = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
            gamePoses               = new TrackedDevicePose_t[0];
            poses                   = new VRPose[OpenVR.k_unMaxTrackedDeviceCount];
            controllers             = new List <VRControllerState>();
            trackingReferences      = new List <VRTrackingReference>();
            trackingReferencesArray = trackingReferences.ToArray();
            controllersArray        = controllers.ToArray();

            // Initialize
            InitOpenVR();
            InitRendering();
            Scripting.Update += Update;
            Scripting.Exit   += Dispose;
        }
Example #3
0
 /// <summary>
 /// Converts <see cref="Matrix"/> to <see cref="VRPose"/>
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 /// <param name="pose">The pose.</param>
 public static void ToVRPose(this Matrix matrix, out VRPose pose)
 {
     pose.Position    = matrix.TranslationVector * 100; //m -> cm
     pose.Orientation = Quaternion.RotationMatrix(matrix);
 }
Example #4
0
 /// <summary>
 /// Converts <see cref="TrackedDevicePose_t"/> to <see cref="VRPose"/>
 /// </summary>
 /// <param name="trackedPose">The tracked pose.</param>
 /// <param name="pose">The pose.</param>
 public static void ToVRPose(this TrackedDevicePose_t trackedPose, out VRPose pose)
 {
     trackedPose.mDeviceToAbsoluteTracking.ToMatrix(out Matrix matrix);
     pose.Position    = matrix.TranslationVector * 100; //m -> cm
     pose.Orientation = Quaternion.RotationMatrix(matrix);
 }