Skip to content

Commit f88fa62

Browse files
committed
Moved create eye loop into create viewer loop, so we can make eyes for each viewer when we have more than one.
1 parent c2baee8 commit f88fa62

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

OSVR-Unity/Assets/OSVRUnity/src/DisplayController.cs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,12 @@ void SetupDisplay()
9494
_displayConfig = _clientKit.context.GetDisplayConfig();
9595
if (_displayConfig == null)
9696
{
97-
Debug.LogError("Unable to setup display. No DisplayConfig object found.");
9897
return;
9998
}
100-
Debug.Log("DisplayConfig initialized on frame " + Time.frameCount);
10199
displayConfigInitialized = true;
102-
Debug.Log("Let's get the viewer count");
100+
103101
//get the number of viewers, bail if there isn't exactly one viewer for now
104102
_viewerCount = _displayConfig.GetNumViewers();
105-
Debug.Log("Viewer count is " + _viewerCount);
106103
if(_viewerCount != 1)
107104
{
108105
Debug.LogError(_viewerCount + " viewers found, but this implementation requires exactly one viewer.");
@@ -127,45 +124,45 @@ private void CreateHeadAndEyes()
127124
return;
128125
}
129126
viewers = new VRViewer[_viewerCount];
130-
for (int i = 0; i < _viewerCount; i++)
127+
for (uint viewerIndex = 0; viewerIndex < _viewerCount; viewerIndex++)
131128
{
132129
//create a VRViewer
133-
GameObject vrViewer = new GameObject("VRViewer" + i);
130+
GameObject vrViewer = new GameObject("VRViewer" + viewerIndex);
134131
vrViewer.AddComponent<AudioListener>(); //add an audio listener
135132
VRViewer vrViewerComponent = vrViewer.AddComponent<VRViewer>();
136133
vrViewerComponent.Camera = vrViewer.GetComponent<Camera>(); //add a dummy camera, VRViewer requires that it has a camera already
137134
vrViewerComponent.Camera.nearClipPlane = nearClippingPlane;
138135
vrViewerComponent.Camera.farClipPlane = farClippingPlane;
139136
vrViewerComponent.DisplayController = this; //pass DisplayController to Viewers
140-
if(i == 0)
137+
if(viewerIndex == 0)
141138
{
142139
vrViewer.tag = "MainCamera"; //tag a VRViewer as the MainCamera so other gameobjects can reference it
143140
}
144141
vrViewer.transform.parent = this.transform; //child of DisplayController
145142
vrViewer.transform.localPosition = Vector3.zero;
146-
}
147-
143+
viewers[viewerIndex] = vrViewerComponent;
148144

149-
//create VREyes
150-
_eyeCount = (uint)_displayConfig.GetNumEyesForViewer(DEFAULT_VIEWER); //get the number of eyes
151-
eyes = new VREye[_eyeCount];
152-
for (int i = 0; i < _eyeCount; i++)
153-
{
154-
GameObject eyeGameObject = new GameObject("Eye" + i); //add an eye gameobject to the scene
155-
VREye eye = eyeGameObject.AddComponent<VREye>(); //add the VReye component
156-
eye.DisplayController = this; //pass DisplayController to Eye
157-
eye.EyeIndex = i; //set the eye's index
158-
eyeGameObject.transform.parent = this.transform; //child of DisplayController
159-
eyeGameObject.transform.localPosition = Vector3.zero;
160-
eyes[i] = eye;
161-
CreateEyeSurface(i);
162-
SetDistortion(i);
163-
}
145+
//create Viewer's VREyes
146+
_eyeCount = (uint)_displayConfig.GetNumEyesForViewer(viewerIndex); //get the number of eyes
147+
eyes = new VREye[_eyeCount];
148+
for (uint eyeIndex = 0; eyeIndex < _eyeCount; eyeIndex++)
149+
{
150+
GameObject eyeGameObject = new GameObject("Eye" + eyeIndex); //add an eye gameobject to the scene
151+
VREye eye = eyeGameObject.AddComponent<VREye>(); //add the VReye component
152+
eye.Viewer = viewers[viewerIndex]; //ASSUME THERE IS ONLY ONE VIEWER
153+
eye.EyeIndex = eyeIndex; //set the eye's index
154+
eyeGameObject.transform.parent = this.transform; //child of DisplayController
155+
eyeGameObject.transform.localPosition = Vector3.zero;
156+
eyes[eyeIndex] = eye;
157+
CreateEyeSurface(eyeIndex);
158+
SetDistortion(eyeIndex);
159+
}
160+
}
164161
}
165162

166163
//Creates a Surface for a given Eye
167164
//bail if there isn't exactly one surface per eye
168-
private void CreateEyeSurface(int eyeIndex)
165+
private void CreateEyeSurface(uint eyeIndex)
169166
{
170167
uint surfaceCount = _displayConfig.GetNumSurfacesForViewerEye(DEFAULT_VIEWER, (byte)eyeIndex);
171168
if(surfaceCount != 1)
@@ -176,18 +173,19 @@ private void CreateEyeSurface(int eyeIndex)
176173
}
177174
GameObject surfaceGameObject = new GameObject("Surface");
178175
VRSurface surface = surfaceGameObject.AddComponent<VRSurface>();
176+
surface.Eye = eyes[eyeIndex];
179177
surface.Camera = surfaceGameObject.AddComponent<Camera>();
180178
surface.Camera.nearClipPlane = nearClippingPlane;
181179
surface.Camera.farClipPlane = farClippingPlane;
182-
surface.Camera.enabled = true; //@todo do we want this disabled?
183-
surfaceGameObject.transform.parent = eyes[eyeIndex].transform; //child of Eye
180+
surface.Camera.enabled = false;
181+
surfaceGameObject.transform.parent = eyes[eyeIndex].transform; //surface is child of Eye
184182
surfaceGameObject.transform.localPosition = Vector3.zero;
185183
eyes[eyeIndex].Surface = surface;
186184
}
187185

188186
//determines if distortion will be used, and what type of distortion will be used
189187
//set distortion parameters accordingly for the given eye.
190-
private void SetDistortion(int eyeIndex)
188+
private void SetDistortion(uint eyeIndex)
191189
{
192190
bool useDistortion = _displayConfig.DoesViewerEyeSurfaceWantDistortion(DEFAULT_VIEWER, (byte)eyeIndex, DEFAULT_SURFACE);
193191
if (!useDistortion)
@@ -208,7 +206,7 @@ private void SetDistortion(int eyeIndex)
208206
}
209207

210208
//set distortion parameters for K1 Radial Distortion method
211-
private void SetK1RadialDistortion(int eyeIndex, float k1Red, float k1Green, float k1Blue, Vector2 center)
209+
private void SetK1RadialDistortion(uint eyeIndex, float k1Red, float k1Green, float k1Blue, Vector2 center)
212210
{
213211
VREye eye = eyes[eyeIndex];
214212
// disable distortion if there is no distortion for this HMD

0 commit comments

Comments
 (0)