Ejemplo n.º 1
0
 private void Update()
 {
     rightHandDorsalDevice.GetScreenPoint();
 }
Ejemplo n.º 2
0
        public void UpdateFromDorsalDevice()
        {
            Int64 timeSinceLastPacket;

            if (motionDevice != null)
            {
                timeSinceLastPacket = motionDevice.lastTimestamp - controllerData.motionTimestamp;
            }
            else
            {
                timeSinceLastPacket = (Int64)(Time.realtimeSinceStartup * 1000000) - controllerData.motionTimestamp;
            }
            if (timeSinceLastPacket < minTimeBetweenPackets)
            {
                return;
            }

            if (motionDevice != null)
            {
                controllerData.motionTimestamp = motionDevice.lastTimestamp;
                controllerData.accelerometerX  = motionDevice.accelerometer.x;
                controllerData.accelerometerY  = motionDevice.accelerometer.y;
                controllerData.accelerometerZ  = motionDevice.accelerometer.z;
                controllerData.gyroPitchRate   = motionDevice.gyroscopeRate.x;
                controllerData.gyroYawRate     = motionDevice.gyroscopeRate.y;
                controllerData.gyroRollRate    = motionDevice.gyroscopeRate.z;
            }
            else
            {
                controllerData.motionTimestamp = (Int64)(Time.realtimeSinceStartup * 1000000);
            }
            if (buttonDevice != null)
            {
                controllerData.aButton        = buttonDevice.primaryButton;
                controllerData.analogAButton  = (byte)(buttonDevice.primaryButton ? 255 : 0);
                controllerData.bButton        = buttonDevice.secondaryButton;
                controllerData.analogBButton  = (byte)(buttonDevice.secondaryButton ? 255 : 0);
                controllerData.l1Button       = buttonDevice.gripButton;
                controllerData.analogL1Button = (byte)(buttonDevice.grip * 255);
                controllerData.l2Button       = buttonDevice.triggerButton;
                controllerData.analogL2Button = (byte)(buttonDevice.trigger * 255);
                controllerData.analogBButton  = (byte)(buttonDevice.secondaryButton ? 255 : 0);
                controllerData.leftStickX     = (byte)((buttonDevice.primary2DAxis.x * 127.5) + 128);
                controllerData.leftStickY     = (byte)((buttonDevice.primary2DAxis.y * 127.5) + 128);
                controllerData.l3Button       = buttonDevice.primary2DAxisClick;
            }
            if (pointerDevice != null)
            {
                Vector2 screenPoint = pointerDevice.GetScreenPoint();
                float   pointX      = screenPoint.x * 4;
                controllerData.analogDpadLeft  = (byte)Math.Max((pointX >= 1 ? 255 : pointX * 255), 0);
                controllerData.analogDpadRight = (byte)Math.Max((pointX >= 2 ? 255 : (pointX - 1) * 255), 0);
                controllerData.analogL1Button  = (byte)Math.Max((pointX >= 3 ? 255 : (pointX - 2) * 255), 0);
                controllerData.analogL2Button  = (byte)Math.Max((pointX >= 4 ? 255 : (pointX - 3) * 255), 0);

                float pointY = screenPoint.y * 4;
                controllerData.analogDpadUp   = (byte)Math.Max((pointY >= 1 ? 255 : pointY * 255), 0);
                controllerData.analogDpadDown = (byte)Math.Max((pointY >= 2 ? 255 : (pointY - 1) * 255), 0);
                controllerData.analogR1Button = (byte)Math.Max((pointY >= 3 ? 255 : (pointY - 2) * 255), 0);
                controllerData.analogR2Button = (byte)Math.Max((pointY >= 4 ? 255 : (pointY - 3) * 255), 0);
            }
            controllerData.packetNumber++;
            manager.DeviceUpdated(this);
        }