Skip to content

Commit 507c08d

Browse files
committed
Added a bunch of comments.
1 parent 03f540a commit 507c08d

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ namespace OSVR
2828
{
2929
namespace Unity
3030
{
31-
//This class is responsible for creating the head, eyes, and surfaces in our scene.
32-
//Rendering parameters are obtained from ClientKit.
33-
//DisplayController creates VRViewer and VREyes as children. Each eye has a VRSurface child with a camera.
34-
//In this implementation, we are assuming that there is exactly one viewer and one surface per eye.
31+
//*This class is responsible for creating stereo rendering in a scene, and updating viewing parameters
32+
// throughout a scene's lifecycle.
33+
// The number of viewers, eyes, and surfaces, as well as viewports, projection matrices,and distortion
34+
// paramerters are obtained from OSVR via ClientKit.
35+
//
36+
// DisplayController creates VRViewers and VREyes as children. Although VRViewers and VREyes are siblings
37+
// in the scene hierarchy, conceptually VREyes are indeed children of VRViewers. The reason they are siblings
38+
// in the Unity scene is because GetViewerEyePose(...) returns a pose relative to world space, not head space.
39+
//
40+
// In this implementation, we are assuming that there is exactly one viewer and one surface per eye.
41+
//*/
3542
[RequireComponent(typeof(Camera))] //requires a "dummy" camera
3643
public class DisplayController : MonoBehaviour
3744
{
@@ -41,7 +48,7 @@ public class DisplayController : MonoBehaviour
4148

4249
private ClientKit _clientKit;
4350
private OSVR.ClientKit.DisplayConfig _displayConfig;
44-
private VRViewer[] _viewers;
51+
private VRViewer[] _viewers;
4552
private uint _viewerCount;
4653
private bool _renderedStereo = false;
4754
private bool _displayConfigInitialized = false;
@@ -80,6 +87,7 @@ void Awake()
8087
}
8188
void Start()
8289
{
90+
//attempt to setup the display here, but it might take a few frames before we have data
8391
SetupDisplay();
8492
}
8593

@@ -104,6 +112,8 @@ void SetupApplicationSettings()
104112
Application.targetFrameRate = TARGET_FRAME_RATE;
105113
}
106114

115+
//Get a DisplayConfig object from the server via ClientKit.
116+
//Setup stereo rendering with DisplayConfig data.
107117
void SetupDisplay()
108118
{
109119
//get the DisplayConfig object from ClientKit
@@ -178,15 +188,16 @@ void Update()
178188
//helper method for updating the client context
179189
public void UpdateClient()
180190
{
181-
_clientKit.context.update(); //update the client
191+
_clientKit.context.update();
182192
}
183193

184194
//Culling determines which objects are visible to the camera. OnPreCull is called just before this process.
195+
//This gets called because we have a camera component, but we disable the camera here so it doesn't render.
196+
//We have the "dummy" camera so existing Unity game code can refer to a MainCamera object.
197+
//We update our viewer and eye transforms here because it is as late as possible before rendering happens.
198+
//OnPreRender is not called because we disable the camera here.
185199
void OnPreCull()
186200
{
187-
//update the client
188-
UpdateClient();
189-
190201
// Disable dummy camera during rendering
191202
// Enable after frame ends
192203
_camera.enabled = false;
@@ -222,6 +233,9 @@ IEnumerator EndOfFrame()
222233
_disabledCamera = false;
223234
}
224235
yield return new WaitForEndOfFrame();
236+
//@todo any post-frame activity goes here.
237+
//Send a timestamp?
238+
//GL.IssuePluginEvent?
225239
}
226240
}
227241
}

0 commit comments

Comments
 (0)