private void HandleTrackIRUpdate(TrackIRClient.LPTRACKIRDATA state)
        {
            // Resolve yaw to left stick X and Y positions
            // -180 = full right, 180 = full left
            // We only care about the forward 120 degrees
            double yaw = TrackIRWrapper.ToDegrees(state.fNPYaw);

            if (yaw > 60 || yaw < -60)
            {
                return;
            }

            // Move phase for trig calculations
            // This isn't *really* necessary, but to me cos is X and sin is Y.
            yaw += 90;

            // full left:  X = 0,            Y = ushort.max/2
            // full right: X = ushort.max,   Y = ushort.max/2
            // ahead:      X = ushort.max/2, Y = ushort.max
            short stickX = (short)((Math.Cos(yaw * (Math.PI / 180)) * short.MaxValue));
            short stickY = (short)((Math.Sin(yaw * (Math.PI / 180)) * ushort.MaxValue));

            ControllerState newState = new ControllerState();

            newState.Z         = stickX;
            newState.RotationZ = stickY;

            _trackIRState = newState;
        }
Beispiel #2
0
 public void Poll()
 {
     try {
         TrackIRClient.LPTRACKIRDATA state;
         state = _trackIR.client_HandleTrackIRData();
         if (TrackIRWrapper.IsChanged(_trackIRState, state))
         {
             if (UpdateHandler != null)
             {
                 UpdateHandler(state);
             }
         }
     }
     catch (NullReferenceException)
     {
         // We'll get one of these if TrackIR is not connected
         if (_active)
         {
             _active = false;
             if (Disconnected != null)
             {
                 Disconnected();
             }
         }
     }
 }
        public FakeController() : base(BUS_CLASS_GUID)
        {
            TrackIR = new TrackIRWrapper();

            TrackIR.UpdateHandler += HandleTrackIRUpdate;
        }