Mercurial > hg > Game > Games
comparison Orchestland/Assets/OVR/Scripts/OVRTracker.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 /************************************************************************************ | |
2 | |
3 Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved. | |
4 | |
5 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); | |
6 you may not use the Oculus VR Rift SDK except in compliance with the License, | |
7 which is provided at the time of installation or download, or which | |
8 otherwise accompanies this software in either electronic or hard copy form. | |
9 | |
10 You may obtain a copy of the License at | |
11 | |
12 http://www.oculusvr.com/licenses/LICENSE-3.2 | |
13 | |
14 Unless required by applicable law or agreed to in writing, the Oculus VR SDK | |
15 distributed under the License is distributed on an "AS IS" BASIS, | |
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
17 See the License for the specific language governing permissions and | |
18 limitations under the License. | |
19 | |
20 ************************************************************************************/ | |
21 | |
22 using System; | |
23 using System.Runtime.InteropServices; | |
24 using UnityEngine; | |
25 using Ovr; | |
26 | |
27 /// <summary> | |
28 /// An infrared camera that tracks the position of a head-mounted display. | |
29 /// </summary> | |
30 public class OVRTracker | |
31 { | |
32 /// <summary> | |
33 /// The (symmetric) visible area in front of the tracker. | |
34 /// </summary> | |
35 public struct Frustum | |
36 { | |
37 /// <summary> | |
38 /// The tracker cannot track the HMD unless it is at least this far away. | |
39 /// </summary> | |
40 public float nearZ; | |
41 /// <summary> | |
42 /// The tracker cannot track the HMD unless it is at least this close. | |
43 /// </summary> | |
44 public float farZ; | |
45 /// <summary> | |
46 /// The tracker's horizontal and vertical fields of view in degrees. | |
47 /// </summary> | |
48 public Vector2 fov; | |
49 } | |
50 | |
51 /// <summary> | |
52 /// If true, a tracker is attached to the system. | |
53 /// </summary> | |
54 public bool isPresent | |
55 { | |
56 get { | |
57 #if !UNITY_ANDROID || UNITY_EDITOR | |
58 return (OVRManager.capiHmd.GetTrackingState().StatusFlags & (uint)StatusBits.PositionConnected) != 0; | |
59 #else | |
60 return false; | |
61 #endif | |
62 } | |
63 } | |
64 | |
65 /// <summary> | |
66 /// If true, the tracker can see and track the HMD. Otherwise the HMD may be occluded or the system may be malfunctioning. | |
67 /// </summary> | |
68 public bool isPositionTracked | |
69 { | |
70 get { | |
71 #if !UNITY_ANDROID || UNITY_EDITOR | |
72 return (OVRManager.capiHmd.GetTrackingState().StatusFlags & (uint)StatusBits.PositionTracked) != 0; | |
73 #else | |
74 return false; | |
75 #endif | |
76 } | |
77 } | |
78 | |
79 /// <summary> | |
80 /// If this is true and a tracker is available, the system will use position tracking when isPositionTracked is also true. | |
81 /// </summary> | |
82 public bool isEnabled | |
83 { | |
84 get { | |
85 #if !UNITY_ANDROID || UNITY_EDITOR | |
86 uint trackingCaps = OVRManager.capiHmd.GetDesc().TrackingCaps; | |
87 return (trackingCaps & (uint)TrackingCaps.Position) != 0; | |
88 #else | |
89 return false; | |
90 #endif | |
91 } | |
92 | |
93 set { | |
94 #if !UNITY_ANDROID || UNITY_EDITOR | |
95 uint trackingCaps = (uint)TrackingCaps.Orientation | (uint)TrackingCaps.MagYawCorrection; | |
96 | |
97 if (value) | |
98 trackingCaps |= (uint)TrackingCaps.Position; | |
99 | |
100 OVRManager.capiHmd.ConfigureTracking(trackingCaps, 0); | |
101 #endif | |
102 } | |
103 } | |
104 | |
105 /// <summary> | |
106 /// Gets the tracker's viewing frustum. | |
107 /// </summary> | |
108 public Frustum frustum | |
109 { | |
110 get { | |
111 #if !UNITY_ANDROID || UNITY_EDITOR | |
112 HmdDesc desc = OVRManager.capiHmd.GetDesc(); | |
113 | |
114 return new Frustum | |
115 { | |
116 nearZ = desc.CameraFrustumNearZInMeters, | |
117 farZ = desc.CameraFrustumFarZInMeters, | |
118 fov = Mathf.Rad2Deg * new Vector2(desc.CameraFrustumHFovInRadians, desc.CameraFrustumVFovInRadians) | |
119 }; | |
120 #else | |
121 return new Frustum | |
122 { | |
123 nearZ = 0.1f, | |
124 farZ = 1000.0f, | |
125 fov = new Vector2(90.0f, 90.0f) | |
126 }; | |
127 #endif | |
128 } | |
129 } | |
130 | |
131 /// <summary> | |
132 /// Gets the tracker's pose, relative to the head's pose at the time of the last pose recentering. | |
133 /// </summary> | |
134 public OVRPose GetPose(double predictionTime = 0d) | |
135 { | |
136 #if !UNITY_ANDROID || UNITY_EDITOR | |
137 double abs_time_plus_pred = Hmd.GetTimeInSeconds() + predictionTime; | |
138 | |
139 return OVRManager.capiHmd.GetTrackingState(abs_time_plus_pred).CameraPose.ToPose(); | |
140 #else | |
141 return new OVRPose | |
142 { | |
143 position = Vector3.zero, | |
144 orientation = Quaternion.identity | |
145 }; | |
146 #endif | |
147 } | |
148 } |