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; }
// Update is called once per frame void Update() { if (running) { data = trackIRclient.client_TestTrackIRData(); // Data for debugging output, can be removed if not debugging/testing TrackIRClient.LPTRACKIRDATA tid = trackIRclient.client_HandleTrackIRData(); // Data for head tracking Vector3 pos = trackIRCamera.transform.localPosition; // Updates main camera, change to whatever Vector3 rot = trackIRCamera.transform.localRotation.eulerAngles; if (!useLimits) { pos.x = -tid.fNPX * positionReductionFactor; pos.y = tid.fNPY * positionReductionFactor; pos.z = -tid.fNPZ * positionReductionFactor; rot.y = -tid.fNPYaw * rotationReductionFactor; rot.x = tid.fNPPitch * rotationReductionFactor; rot.z = tid.fNPRoll * rotationReductionFactor; } else { pos.x = Mathf.Clamp(-tid.fNPX * -positionReductionFactor, positionXLimits.lower, positionXLimits.upper); pos.y = Mathf.Clamp(tid.fNPY * positionReductionFactor, positionYLimits.lower, positionYLimits.upper); pos.z = Mathf.Clamp(-tid.fNPZ * positionReductionFactor, positionZLimits.lower, positionZLimits.upper); rot.y = Mathf.Clamp(-tid.fNPYaw * rotationReductionFactor, yawLimits.lower, yawLimits.upper); rot.x = Mathf.Clamp(tid.fNPPitch * rotationReductionFactor, pitchLimits.lower, pitchLimits.upper); rot.z = Mathf.Clamp(tid.fNPRoll * rotationReductionFactor, rollLimits.lower, rollLimits.upper); } Camera.main.transform.localRotation = Quaternion.Euler(rot); Camera.main.transform.localPosition = pos; } }
private void Update() { if (running) { TrackIRClient.LPTRACKIRDATA temptid = trackIRclient.client_HandleTrackIRData(); // Data for head tracking if (lastSig == temptid.wPFrameSignature) { if (counter < timeout) { counter++; } else { active = false; } } else { tid = temptid; counter = 0; active = true; lastSig = tid.wPFrameSignature; } } else { active = false; } }
private void HandleTrackIRUpdate(TrackIRClient.LPTRACKIRDATA state) { try { } catch (Exception) { // thread is no longer active, so just quit } }
// Update is called once per frame void Update(Object source, ElapsedEventArgs e) { if (started) { //data = trackIRclient.client_TestTrackIRData(); // Data for debugging output, can be removed if not debugging/testing tid = trackIRclient.client_HandleTrackIRData(); // Data for head tracking } aTimer.Start(); }
public void GetData(ref Vector3 rot, ref Vector3 pos) { if (trackIRclient != null) { TrackIRClient.LPTRACKIRDATA data = trackIRclient.client_HandleTrackIRData(); rot.x = -data.fNPPitch / 100; rot.y = data.fNPYaw / 100; rot.z = data.fNPRoll / 100; pos.x = -data.fNPX / 10000; pos.y = data.fNPY / 10000; pos.z = data.fNPZ / 10000; } }
/* * Fields in LPTRACKIRDATA: * public ushort wNPStatus; * public ushort wPFrameSignature; * public uint dwNPIOData; * public float fNPRoll; * public float fNPPitch; * public float fNPYaw; * public float fNPX; * public float fNPY; * public float fNPZ; * public float fNPRawX; * public float fNPRawY; * public float fNPRawZ; * public float fNPDeltaX; * public float fNPDeltaY; * public float fNPDeltaZ; * public float fNPSmoothX; * public float fNPSmoothY; * public float fNPSmoothZ; */ /// <summary> /// Check if there's any difference between oldState and newState. /// </summary> /// <param name="oldState"></param> /// <param name="newState"></param> /// <returns></returns> private static bool IsChanged(TrackIRClient.LPTRACKIRDATA oldState, TrackIRClient.LPTRACKIRDATA newState) { return( (oldState.wNPStatus != newState.wNPStatus) || (oldState.wPFrameSignature != newState.wPFrameSignature) || (oldState.dwNPIOData != newState.dwNPIOData) || (oldState.fNPRoll != newState.fNPRoll) || (oldState.fNPPitch != newState.fNPPitch) || (oldState.fNPYaw != newState.fNPYaw) || (oldState.fNPX != newState.fNPX) || (oldState.fNPY != newState.fNPY) || (oldState.fNPZ != newState.fNPZ) || (oldState.fNPRawX != newState.fNPRawX) || (oldState.fNPRawY != newState.fNPRawY) || (oldState.fNPRawZ != newState.fNPRawZ) || (oldState.fNPDeltaX != newState.fNPDeltaX) || (oldState.fNPDeltaY != newState.fNPDeltaY) || (oldState.fNPDeltaZ != newState.fNPDeltaZ) || (oldState.fNPSmoothX != newState.fNPSmoothX) || (oldState.fNPSmoothY != newState.fNPSmoothY) || (oldState.fNPSmoothZ != newState.fNPSmoothZ) ); }
private void Update() { if (running) { TrackIRClient.LPTRACKIRDATA temptid = trackIRclient.client_HandleTrackIRData(); // Data for head tracking if (lastSig == temptid.wPFrameSignature) { if (counter < timeout) counter++; else active = false; } else { tid = temptid; counter = 0; active = true; lastSig = tid.wPFrameSignature; } } else active = false; }