BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / VR / Scripts / OVRMixedReality.cs

OVRMixedReality.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
OVRMixedReality.cs 4.4 KiB Download Raw
1/************************************************************************************
2Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
3
4Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use
5the Utilities SDK except in compliance with the License, which is provided at the time of installation
6or download, or which otherwise accompanies this software in either electronic or hard copy form.
7
8You may obtain a copy of the License at
9https://developer.oculus.com/licenses/utilities-1.31
10
11Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
12under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
13ANY KIND, either express or implied. See the License for the specific language governing
14permissions and limitations under the License.
15************************************************************************************/
16
17#if UNITY_ANDROID && !UNITY_EDITOR
18#define OVR_ANDROID_MRC
19#endif
20
21using System;
22using System.Runtime.InteropServices;
23using System.Text.RegularExpressions;
24using System.Collections.Generic;
25using UnityEngine;
26
27#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID
28
29/// <summary>
30/// Manages mix-reality elements
31/// </summary>
32internal static class OVRMixedReality
33{
34 /// <summary>
35 /// For Debugging purpose, we can use preset parameters to fake a camera when external camera is not available
36 /// </summary>
37 public static bool useFakeExternalCamera = false;
38 public static Vector3 fakeCameraFloorLevelPosition = new Vector3(0.0f, 2.0f, -0.5f);
39 public static Vector3 fakeCameraEyeLevelPosition = fakeCameraFloorLevelPosition - new Vector3(0.0f, 1.8f, 0.0f);
40 public static Quaternion fakeCameraRotation = Quaternion.LookRotation((new Vector3(0.0f, fakeCameraFloorLevelPosition.y, 0.0f) - fakeCameraFloorLevelPosition).normalized, Vector3.up);
41 public static float fakeCameraFov = 60.0f;
42 public static float fakeCameraAspect = 16.0f / 9.0f;
43
44 /// <summary>
45 /// Composition object
46 /// </summary>
47 public static OVRComposition currentComposition = null;
48
49 /// <summary>
50 /// Updates the internal state of the Mixed Reality Camera. Called by OVRManager.
51 /// </summary>
52
53 public static void Update(GameObject parentObject, Camera mainCamera, OVRManager.CompositionMethod compositionMethod, bool useDynamicLighting, OVRManager.CameraDevice cameraDevice, OVRManager.DepthQuality depthQuality)
54 {
55 if (!OVRPlugin.initialized)
56 {
57 Debug.LogError("OVRPlugin not initialized");
58 return;
59 }
60
61 if (!OVRPlugin.IsMixedRealityInitialized())
62 {
63 OVRPlugin.InitializeMixedReality();
64 if (OVRPlugin.IsMixedRealityInitialized())
65 {
66 Debug.Log("OVRPlugin_MixedReality initialized");
67 }
68 else
69 {
70 Debug.LogError("Unable to initialize OVRPlugin_MixedReality");
71 return;
72 }
73 }
74
75 if (!OVRPlugin.IsMixedRealityInitialized())
76 {
77 return;
78 }
79
80 OVRPlugin.UpdateExternalCamera();
81#if !OVR_ANDROID_MRC
82 OVRPlugin.UpdateCameraDevices();
83#endif
84
85#if OVR_ANDROID_MRC
86 useFakeExternalCamera = OVRPlugin.Media.UseMrcDebugCamera();
87#endif
88
89 if (currentComposition != null && currentComposition.CompositionMethod() != compositionMethod)
90 {
91 currentComposition.Cleanup();
92 currentComposition = null;
93 }
94
95 if (compositionMethod == OVRManager.CompositionMethod.External)
96 {
97 if (currentComposition == null)
98 {
99 currentComposition = new OVRExternalComposition(parentObject, mainCamera);
100 }
101 }
102#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
103 else if (compositionMethod == OVRManager.CompositionMethod.Direct)
104 {
105 if (currentComposition == null)
106 {
107 currentComposition = new OVRDirectComposition(parentObject, mainCamera, cameraDevice, useDynamicLighting, depthQuality);
108 }
109 }
110 else if (compositionMethod == OVRManager.CompositionMethod.Sandwich)
111 {
112 if (currentComposition == null)
113 {
114 currentComposition = new OVRSandwichComposition(parentObject, mainCamera, cameraDevice, useDynamicLighting, depthQuality);
115 }
116 }
117#endif
118 else
119 {
120 Debug.LogError("Unknown CompositionMethod : " + compositionMethod);
121 return;
122 }
123 currentComposition.Update(mainCamera);
124 }
125
126 public static void Cleanup()
127 {
128 if (currentComposition != null)
129 {
130 currentComposition.Cleanup();
131 currentComposition = null;
132 }
133 if (OVRPlugin.IsMixedRealityInitialized())
134 {
135 OVRPlugin.ShutdownMixedReality();
136 }
137 }
138
139 public static void RecenterPose()
140 {
141 if (currentComposition != null)
142 {
143 currentComposition.RecenterPose();
144 }
145 }
146
147}
148
149#endif