123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- namespace Tracking
- {
- public class HMDTracker : CalibratableTracker
- {
- public int framesToConsider = 10;
- public float SteerRotation => framesToConsider > 1
- ? CalculateSteerRotationMultiFrame()
- : CalculateSteerRotationSingleFrame();
- protected override string KeyPrefix => "fw";
- private Queue<float> previousValues;
- private void OnEnable()
- {
- if (framesToConsider > 1) previousValues = new Queue<float>(framesToConsider);
- }
- /*private void OnGUI()
- {
- GUI.TextArea(new Rect(0, 400, 200, 90),
- $"LeanRotation: {LeanRotation}\nRelativeRotation: {RelativeRotation}\nRelativePosition: {RelativePosition}");
- }*/
- private float CalculateSteerRotationSingleFrame()
- {
- return RelativeRotation.y;
- }
- private float CalculateSteerRotationMultiFrame()
- {
- var angleThisFrame = CalculateSteerRotationSingleFrame();
- if (previousValues.Count > framesToConsider) previousValues.Dequeue();
- previousValues.Enqueue(angleThisFrame);
- //easiest way -> avg; TODO maybe in future, remove outliers
- return previousValues.Average();
- }
- }
- }
|