Skip to content

Commit 47ca607

Browse files
author
David Kline (ANALOG)
committed
add IsPosition/RotationAvailable and tracking accuracy
1 parent 9d322f6 commit 47ca607

File tree

7 files changed

+156
-23
lines changed

7 files changed

+156
-23
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,36 @@ 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 the accuracy of the position data being reported.
36+
/// </summary>
37+
public TrackingAccuracy PositionAccuracy { get; set; }
38+
39+
/// <summary>
40+
/// Indicates whether or not the headset is currently providing rotation data.
41+
/// </summary>
42+
public bool IsRotationAvailable { get; set; }
43+
2944
/// <summary>
3045
/// Outputs the current rotation of the headset, as defined by the SDK / Unity.
3146
/// </summary>
3247
public Quaternion Rotation { get; set; }
3348

49+
/// <summary>
50+
/// Indicates the accuracy of the rotation data being reported.
51+
/// </summary>
52+
public TrackingAccuracy RotationAccuracy { get; set; }
53+
3454
/// <summary>
3555
/// Outputs the current state of the headset, whether it is tracked or not. As defined by the SDK / Unity.
3656
/// </summary>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace Microsoft.MixedReality.Toolkit.Internal.Definitions.Devices
5+
{
6+
/// <summary>
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
9+
/// </summary>
10+
public enum TrackingAccuracy
11+
{
12+
/// <summary>
13+
/// There is no accuracy data for this device.
14+
/// </summary>
15+
/// <remarks>
16+
/// This indicates that the device is either not tracked or does not support tracking. The level
17+
/// of accuracy is defined by the device's platform or driver and may vary by, for example, the
18+
/// distance between values returned (ex: degrees of rotation or physical distance of position).
19+
/// </remarks>
20+
None = 0,
21+
/// <summary>
22+
/// The device is returning approximate data.
23+
/// </summary>
24+
/// <remarks>
25+
/// Approximate accuracy generally implies that the device is not
26+
/// visible to sensors and that the system is inferring the data by
27+
/// other means.
28+
/// </remarks>
29+
Approximate,
30+
/// <summary>
31+
/// The device is returning a low level of accuracy.
32+
/// </summary>
33+
Low,
34+
/// <summary>
35+
/// The device is returning a medium level of accuracy.
36+
/// </summary>
37+
Medium,
38+
/// <summary>
39+
/// The device is returning a high level of accuracy.
40+
/// </summary>
41+
High
42+
}
43+
}

Assets/MixedRealityToolkit/_Core/Definitions/Devices/TrackingAccuracy.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
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+
/// Reserved, for systems that provide alternate tracking.
1821
/// </summary>
19-
Approximate,
22+
Other,
2023
/// <summary>
21-
/// The controller is currently fully tracked and has accurate positioning.
24+
/// The device is not tracked.
2225
/// </summary>
23-
Tracked,
26+
NotTracked,
2427
/// <summary>
25-
/// Reserved, for systems that provide alternate tracking.
28+
/// The device is tracked (positionally and/or rotationally).
2629
/// </summary>
27-
Other,
30+
/// <remarks>
31+
/// Some devices provide additional details regarding the accuracy of the tracking.
32+
/// <See cref="Definitions.Devices.TrackingAccuracy"/> for more information.
33+
/// </remarks>
34+
Tracked
2835
}
2936
}

Assets/MixedRealityToolkit/_Core/Devices/BaseController.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ protected BaseController(TrackingState trackingState, Handedness controllerHande
2929
ControllerHandedness = controllerHandedness;
3030
InputSource = inputSource;
3131
Interactions = interactions;
32+
33+
IsPositionAvailable = false;
34+
PositionAccuracy = TrackingAccuracy.None;
35+
IsRotationAvailable = false;
36+
RotationAccuracy = TrackingAccuracy.None;
3237
}
3338

3439
/// <summary>
@@ -58,6 +63,18 @@ protected IMixedRealityInputSystem InputSystem
5863
/// <inheritdoc />
5964
public IMixedRealityInputSource InputSource { get; }
6065

66+
/// <inheritdoc />
67+
public bool IsPositionAvailable { get; protected set; }
68+
69+
/// <inheritdoc />
70+
public TrackingAccuracy PositionAccuracy { get; protected set; }
71+
72+
/// <inheritdoc />
73+
public bool IsRotationAvailable { get; protected set; }
74+
75+
/// <inheritdoc />
76+
public TrackingAccuracy RotationAccuracy { get; protected set; }
77+
6178
/// <inheritdoc />
6279
public MixedRealityInteractionMapping[] Interactions { get; private set; }
6380

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

Lines changed: 20 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,24 +109,26 @@ 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+
PositionAccuracy = (interactionSourceState.sourcePose.positionAccuracy == InteractionSourcePositionAccuracy.High) ?
118+
TrackingAccuracy.High : TrackingAccuracy.Approximate;
119+
}
120+
else
121+
{
122+
PositionAccuracy = TrackingAccuracy.None;
123123
}
124124

125+
IsRotationAvailable = interactionSourceState.sourcePose.TryGetRotation(out currentControllerRotation);
126+
// Windows Mixed Reality does not have a concept of rotation accuracy, therefore we return high accuracy
127+
RotationAccuracy = IsRotationAvailable ? TrackingAccuracy.High : TrackingAccuracy.None;
128+
129+
// Windows Mixed Reality controllers are tracked if we are receiving position or rotation data
130+
TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked;
131+
125132
if (lastState != TrackingState)
126133
{
127134
InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,34 @@ 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+
TrackingAccuracy PositionAccuracy { 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+
53+
/// <summary>
54+
/// Indicates the accuracy of the rotation data being reported.
55+
/// </summary>
56+
TrackingAccuracy RotationAccuracy { get; }
57+
3058
/// <summary>
3159
/// Mapping definition for this controller, linking the Physical inputs to logical Input System Actions
3260
/// </summary>

0 commit comments

Comments
 (0)