Skip to content

Commit 381cb14

Browse files
author
David Kline
authored
Merge pull request #2369 from davidkline-ms/vNext-TrackingAccuracy
add IsPosition/RotationAvailable and IsPositionApproximate
2 parents 59aaa5a + f7656b9 commit 381cb14

File tree

5 files changed

+77
-25
lines changed

5 files changed

+77
-25
lines changed

Assets/MixedRealityToolkit/_Core/Definitions/Devices/Headset.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@ public struct Headset
2121
/// </summary>
2222
public SDKType HeadsetSDKType { get; set; }
2323

24+
/// <summary>
25+
/// Indicates whether or not the headset is currently providing position data.
26+
/// </summary>
27+
public bool IsPositionAvailable { get; set; }
28+
2429
/// <summary>
2530
/// Outputs the current position of the headset, as defined by the SDK / Unity.
2631
/// </summary>
2732
public Vector3 Position { get; set; }
2833

34+
/// <summary>
35+
/// Indicates whether or not the headset is currently providing rotation data.
36+
/// </summary>
37+
public bool IsRotationAvailable { get; set; }
38+
2939
/// <summary>
3040
/// Outputs the current rotation of the headset, as defined by the SDK / Unity.
3141
/// </summary>

Assets/MixedRealityToolkit/_Core/Definitions/Devices/TrackingState.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@
44
namespace Microsoft.MixedReality.Toolkit.Internal.Definitions.Devices
55
{
66
/// <summary>
7-
/// The Tracking State defines how a controller or headset is currently being tracked.
8-
/// This enables developers to be able to handle non-tracked situations and react accordingly
7+
/// The Tracking State defines how a device is currently being tracked.
8+
/// This enables developers to be able to handle non-tracked situations and react accordingly.
99
/// </summary>
10+
/// <remarks>
11+
/// Tracking is being defined as receiving sensor (positional and/or rotational) data from the device.
12+
/// </remarks>
1013
public enum TrackingState
1114
{
1215
/// <summary>
13-
/// The controller is currently not tracked.
16+
/// The device does not support tracking (ex: a traditional game controller).
1417
/// </summary>
15-
NotTracked = 0,
18+
NotApplicable = 0,
1619
/// <summary>
17-
/// The controller is tracked, but has approximate positioning.
20+
/// The device is not tracked.
1821
/// </summary>
19-
Approximate,
22+
NotTracked,
2023
/// <summary>
21-
/// The controller is currently fully tracked and has accurate positioning.
24+
/// The device is tracked (positionally and/or rotationally).
2225
/// </summary>
23-
Tracked,
24-
/// <summary>
25-
/// Reserved, for systems that provide alternate tracking.
26-
/// </summary>
27-
Other,
26+
/// <remarks>
27+
/// Some devices provide additional details regarding the accuracy of the tracking.
28+
/// <See cref="Definitions.Devices.TrackingAccuracy"/> for more information.
29+
/// </remarks>
30+
Tracked
2831
}
2932
}

Assets/MixedRealityToolkit/_Core/Devices/BaseController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ protected BaseController(TrackingState trackingState, Handedness controllerHande
2929
ControllerHandedness = controllerHandedness;
3030
InputSource = inputSource;
3131
Interactions = interactions;
32+
33+
IsPositionAvailable = false;
34+
IsPositionApproximate = false;
35+
IsRotationAvailable = false;
3236
}
3337

3438
/// <summary>
@@ -58,6 +62,15 @@ protected IMixedRealityInputSystem InputSystem
5862
/// <inheritdoc />
5963
public IMixedRealityInputSource InputSource { get; }
6064

65+
/// <inheritdoc />
66+
public bool IsPositionAvailable { get; protected set; }
67+
68+
/// <inheritdoc />
69+
public bool IsPositionApproximate { get; protected set; }
70+
71+
/// <inheritdoc />
72+
public bool IsRotationAvailable { get; protected set; }
73+
6174
/// <inheritdoc />
6275
public MixedRealityInteractionMapping[] Interactions { get; private set; }
6376

Assets/MixedRealityToolkit/_Core/Devices/MixedReality/WindowsMixedRealityController.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public WindowsMixedRealityController(TrackingState trackingState, Handedness con
3838
/// </summary>
3939
public InteractionSourceState LastSourceStateReading { get; private set; }
4040

41+
private Vector3 currentControllerPosition = Vector3.zero;
42+
private Quaternion currentControllerRotation = Quaternion.identity;
43+
4144
private Vector3 currentPointerPosition = Vector3.zero;
4245
private Quaternion currentPointerRotation = Quaternion.identity;
4346
private MixedRealityPose currentPointerData = new MixedRealityPose(Vector3.zero, Quaternion.identity);
@@ -96,6 +99,8 @@ public void UpdateController(InteractionSourceState interactionSourceState)
9699
throw new ArgumentOutOfRangeException();
97100
}
98101
}
102+
103+
LastSourceStateReading = interactionSourceState;
99104
}
100105

101106
/// <summary>
@@ -104,23 +109,21 @@ public void UpdateController(InteractionSourceState interactionSourceState)
104109
/// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform</param>
105110
private void UpdateControllerData(InteractionSourceState interactionSourceState)
106111
{
107-
LastSourceStateReading = interactionSourceState;
108112
var lastState = TrackingState;
109113

110-
switch (interactionSourceState.sourcePose.positionAccuracy)
114+
IsPositionAvailable = interactionSourceState.sourcePose.TryGetPosition(out currentControllerPosition);
115+
if (IsPositionAvailable)
111116
{
112-
case InteractionSourcePositionAccuracy.None:
113-
TrackingState = TrackingState.NotTracked;
114-
break;
115-
case InteractionSourcePositionAccuracy.Approximate:
116-
TrackingState = TrackingState.Approximate;
117-
break;
118-
case InteractionSourcePositionAccuracy.High:
119-
TrackingState = TrackingState.Tracked;
120-
break;
121-
default:
122-
throw new ArgumentOutOfRangeException();
117+
TrackingState = TrackingState.Tracked;
118+
IsPositionApproximate = (interactionSourceState.sourcePose.positionAccuracy == InteractionSourcePositionAccuracy.Approximate);
123119
}
120+
else
121+
{
122+
TrackingState = TrackingState.NotTracked;
123+
IsPositionApproximate = true;
124+
}
125+
126+
IsRotationAvailable = interactionSourceState.sourcePose.TryGetRotation(out currentControllerRotation);
124127

125128
if (lastState != TrackingState)
126129
{

Assets/MixedRealityToolkit/_Core/Interfaces/Devices/IMixedRealityController.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ public interface IMixedRealityController
2727
/// </summary>
2828
IMixedRealityInputSource InputSource { get; }
2929

30+
/// <summary>
31+
/// Indicates that this controller is currently providing position data.
32+
/// </summary>
33+
/// <remarks>
34+
/// This value may change during usage for some controllers. As a best practice,
35+
/// be sure to check this value before using position data.
36+
/// </remarks>
37+
bool IsPositionAvailable { get; }
38+
39+
/// <summary>
40+
/// Indicates the accuracy of the position data being reported.
41+
/// </summary>
42+
bool IsPositionApproximate { get; }
43+
44+
/// <summary>
45+
/// Indicates that this controller is currently providing rotation data.
46+
/// </summary>
47+
/// <remarks>
48+
/// This value may change during usage for some controllers. As a best practice,
49+
/// be sure to check this value before using rotation data.
50+
/// </remarks>
51+
bool IsRotationAvailable { get; }
52+
3053
/// <summary>
3154
/// Mapping definition for this controller, linking the Physical inputs to logical Input System Actions
3255
/// </summary>

0 commit comments

Comments
 (0)