FrontWheelTracker.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Tracking
  5. {
  6. public class FrontWheelTracker : CalibratableTracker
  7. {
  8. protected override string KeyPrefix => "fw";
  9. public float trackerDistanceToWheelCenterPoint;
  10. public KineticLegTracker legTracker;
  11. public float SteerRotation
  12. {
  13. get
  14. {
  15. //legTracker position is added to compensate movements of the whole installation
  16. Vector3 legTrackerPos = Vector3.zero;
  17. if (legTracker.isActiveAndEnabled)
  18. {
  19. legTrackerPos = legTracker.RelativePosition;
  20. }
  21. var posOnBikePlane = Vector3.ProjectOnPlane(RelativePosition + legTrackerPos, bicycleTransform.up);
  22. Debug.Log("LegTrackerPos = "+legTrackerPos);
  23. Debug.Log("RelitvePos = "+ RelativePosition);
  24. Debug.Log("PosOnBikePlane.x = "+posOnBikePlane.x);
  25. if (Mathf.Abs(posOnBikePlane.x / trackerDistanceToWheelCenterPoint) >= 1f)
  26. {
  27. Debug.LogError("Strange behaviour!");
  28. //EditorApplication.isPaused = true;
  29. }
  30. var theta = Mathf.Acos(Mathf.Clamp(posOnBikePlane.x / trackerDistanceToWheelCenterPoint, -1f, 1f));
  31. return 90f - theta * Mathf.Rad2Deg;
  32. }
  33. }
  34. }
  35. }