OVRTracker.cs
4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
https://developer.oculus.com/licenses/oculussdk/
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
ANY KIND, either express or implied. See the License for the specific language governing
permissions and limitations under the License.
************************************************************************************/
using System;
using System.Runtime.InteropServices;
using UnityEngine;
/// <summary>
/// An infrared camera that tracks the position of a head-mounted display.
/// </summary>
public class OVRTracker
{
/// <summary>
/// The (symmetric) visible area in front of the sensor.
/// </summary>
public struct Frustum
{
/// <summary>
/// The sensor's minimum supported distance to the HMD.
/// </summary>
public float nearZ;
/// <summary>
/// The sensor's maximum supported distance to the HMD.
/// </summary>
public float farZ;
/// <summary>
/// The sensor's horizontal and vertical fields of view in degrees.
/// </summary>
public Vector2 fov;
}
/// <summary>
/// If true, a sensor is attached to the system.
/// </summary>
public bool isPresent
{
get {
if (!OVRManager.isHmdPresent)
return false;
return OVRPlugin.positionSupported;
}
}
/// <summary>
/// If true, the sensor is actively tracking the HMD's position. Otherwise the HMD may be temporarily occluded, the system may not support position tracking, etc.
/// </summary>
public bool isPositionTracked
{
get {
return OVRPlugin.positionTracked;
}
}
/// <summary>
/// If this is true and a sensor is available, the system will use position tracking when isPositionTracked is also true.
/// </summary>
public bool isEnabled
{
get {
if (!OVRManager.isHmdPresent)
return false;
return OVRPlugin.position;
}
set {
if (!OVRManager.isHmdPresent)
return;
OVRPlugin.position = value;
}
}
/// <summary>
/// Returns the number of sensors currently connected to the system.
/// </summary>
public int count
{
get {
int count = 0;
for (int i = 0; i < (int)OVRPlugin.Tracker.Count; ++i)
{
if (GetPresent(i))
count++;
}
return count;
}
}
/// <summary>
/// Gets the sensor's viewing frustum.
/// </summary>
public Frustum GetFrustum(int tracker = 0)
{
if (!OVRManager.isHmdPresent)
return new Frustum();
return OVRPlugin.GetTrackerFrustum((OVRPlugin.Tracker)tracker).ToFrustum();
}
/// <summary>
/// Gets the sensor's pose, relative to the head's pose at the time of the last pose recentering.
/// </summary>
public OVRPose GetPose(int tracker = 0)
{
if (!OVRManager.isHmdPresent)
return OVRPose.identity;
OVRPose p;
switch (tracker)
{
case 0:
p = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerZero, OVRPlugin.Step.Render).ToOVRPose();
break;
case 1:
p = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerOne, OVRPlugin.Step.Render).ToOVRPose();
break;
case 2:
p = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerTwo, OVRPlugin.Step.Render).ToOVRPose();
break;
case 3:
p = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerThree, OVRPlugin.Step.Render).ToOVRPose();
break;
default:
return OVRPose.identity;
}
return new OVRPose()
{
position = p.position,
orientation = p.orientation * Quaternion.Euler(0, 180, 0)
};
}
/// <summary>
/// If true, the pose of the sensor is valid and is ready to be queried.
/// </summary>
public bool GetPoseValid(int tracker = 0)
{
if (!OVRManager.isHmdPresent)
return false;
switch (tracker)
{
case 0:
return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerZero);
case 1:
return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerOne);
case 2:
return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerTwo);
case 3:
return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerThree);
default:
return false;
}
}
public bool GetPresent(int tracker = 0)
{
if (!OVRManager.isHmdPresent)
return false;
switch (tracker)
{
case 0:
return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerZero);
case 1:
return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerOne);
case 2:
return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerTwo);
case 3:
return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerThree);
default:
return false;
}
}
}