HoloLens 2 Gait Training
The purpose of this project is to create gait training application.
Loading...
Searching...
No Matches
CamMovementTracker.cs
Go to the documentation of this file.
1using Microsoft.MixedReality.Toolkit.Utilities;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5
10public class CamMovementTracker : MonoBehaviour
11{
17 public static CamMovementTracker m_CamTrackerInstance { get; private set; }
18
20 [SerializeField]
21 private readonly float m_SampleTime = 1.0f;
22
24 private Vector3 m_LastSampleLocation;
25
27 private Quaternion m_LastSampleRotation;
28
30 private float m_LastSampleTime;
31
33 public float Speed { get; private set; }
34
36 public float RotationDelta { get; private set; }
37
39 public float Distance { get; private set; }
40
42 public bool IsMoving { get; private set; }
43
47 private void Awake()
48 {
49 if( m_CamTrackerInstance != null && m_CamTrackerInstance != this )
50 {
51 Destroy( this );
52 }
53 else
54 {
56 }
57 }
58
60 void Start()
61 {
62 m_LastSampleTime = Time.time;
63 m_LastSampleLocation = CameraCache.Main.transform.position;
64 m_LastSampleRotation = CameraCache.Main.transform.rotation;
65 }
66
68 void Update()
69 {
70 if( Time.time - m_LastSampleTime > m_SampleTime)
71 {
76
77 m_LastSampleTime = Time.time;
78 m_LastSampleLocation = CameraCache.Main.transform.position;
79 m_LastSampleRotation = CameraCache.Main.transform.rotation;
80 }
81 }
82
87 {
88 return Vector3.Distance( m_LastSampleLocation, CameraCache.Main.transform.position );
89 }
90
94 private float CalculateSpeed()
95 {
96 return Mathf.Abs( CalculateDistanceCovered() / ( Time.time - m_LastSampleTime ) * 3.6f );
97 }
98
102 private float CalculateRotation()
103 {
104 return Mathf.Abs( Quaternion.Angle( m_LastSampleRotation, CameraCache.Main.transform.rotation ) );
105 }
106
110 private bool IsCameraMoving( float speed )
111 {
112 if( speed > 0.6f )
113 {
114 return true;
115 }
116
117 return false;
118 }
119}
A singleton Instance to track Camera Movements This will also calculate distance, rotation and speed ...
float CalculateDistanceCovered()
Calculate Distance
static CamMovementTracker m_CamTrackerInstance
Singleton Instance We have 1 Camera instance and 1 User at all time. Therefore, I believe Singleton i...
Quaternion m_LastSampleRotation
Holds last rotation value.
float Distance
Property to get and set Distance.
bool IsCameraMoving(float speed)
Calculate whether the player is moving or not.
Vector3 m_LastSampleLocation
Holds last location value
float RotationDelta
Property to get and set RotationDelta.
float CalculateSpeed()
Calculate Speed in killo meters per hour.
float CalculateRotation()
Calculate the rotations.
float m_LastSampleTime
Holds last timestamp value.
bool IsMoving
Property to get and set IsMoving flag.
void Awake()
If there is an instance, and it is not me, delete myself.
void Start()
Start is called before the first frame update.
float Speed
Property to get and set Speed.
void Update()
Update is called once per frame.
readonly float m_SampleTime
Just a default value to compare against.