Ejemplo n.º 1
0
        /// <summary>
        /// Sends full controller state as defined by arguments.
        /// </summary>
        public void SetControllerState(
            // Controller ID
            int controllerId,

            // Pose data
            HeadRelation headRelation,
            HandType suggestedHand,
            Quaternion orientation,
            Vector3?position,

            // Touchpad state [-1,1]
            double analogX,
            double analogY,

            // Trigger state
            double analogTrigger,

            // Button states
            bool isMenuPressed,
            bool isSystemPressed,
            bool isTriggerPressed,
            bool isGripPressed,
            bool isTouchpadPressed,
            bool isTouchpadTouched)
        {
            // See openvr.h in OpenVR SDK for mappings and masks
            // https://github.com/ValveSoftware/openvr/blob/master/headers/openvr.h

            var buttons = new VRControllerState_t()
            {
                rAxis0          = new VRControllerAxis_t((float)analogX, (float)analogY), // Touchpad
                rAxis1          = new VRControllerAxis_t((float)analogTrigger, 0),        // Trigger
                rAxis2          = new VRControllerAxis_t(0, 0),
                rAxis3          = new VRControllerAxis_t(0, 0),
                rAxis4          = new VRControllerAxis_t(0, 0),
                ulButtonPressed = BuildButtonPressedMask(isMenuPressed, isSystemPressed, isTriggerPressed, isGripPressed, isTouchpadPressed),
                ulButtonTouched = BuildButtonTouchedMask(isTouchpadTouched, true),
                unPacketNum     = ++packetNum
            };

            var controllerState = new VRController()
            {
                ButtonState   = buttons,
                Status        = 0,
                ControllerId  = controllerId,
                Position      = position.HasValue ? new[] { position.Value.X, position.Value.Y, position.Value.Z } : null,
                Orientation   = new [] { orientation.X, orientation.Y, orientation.Z, orientation.W },
                HeadRelation  = headRelation,
                SuggestedHand = suggestedHand
            };

            WrapTimeouts(() => { Proxy.SendControllerData(controllerState); });
        }
Ejemplo n.º 2
0
 public void SendControllerData(VRController state)
 {
     controller.ControllerState = state;
     controller.Version         = ControllerStateRequest.CurrentVersion;
     SendMessage(controller);
 }