HMDTracker.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace Tracking
  5. {
  6. public class HMDTracker : CalibratableTracker
  7. {
  8. public int framesToConsider = 10;
  9. public float SteerRotation => framesToConsider > 1
  10. ? CalculateSteerRotationMultiFrame()
  11. : CalculateSteerRotationSingleFrame();
  12. protected override string KeyPrefix => "fw";
  13. private Queue<float> previousValues;
  14. private void OnEnable()
  15. {
  16. if (framesToConsider > 1) previousValues = new Queue<float>(framesToConsider);
  17. }
  18. /*private void OnGUI()
  19. {
  20. GUI.TextArea(new Rect(0, 400, 200, 90),
  21. $"LeanRotation: {LeanRotation}\nRelativeRotation: {RelativeRotation}\nRelativePosition: {RelativePosition}");
  22. }*/
  23. private float CalculateSteerRotationSingleFrame()
  24. {
  25. return RelativeRotation.y;
  26. }
  27. private float CalculateSteerRotationMultiFrame()
  28. {
  29. var angleThisFrame = CalculateSteerRotationSingleFrame();
  30. if (previousValues.Count > framesToConsider) previousValues.Dequeue();
  31. previousValues.Enqueue(angleThisFrame);
  32. //easiest way -> avg; TODO maybe in future, remove outliers
  33. return previousValues.Average();
  34. }
  35. }
  36. }