@@ -30,16 +30,18 @@ namespace Unity
3030 {
3131 //This class is responsible for creating the head, eyes, and surfaces in our scene.
3232 //Rendering parameters are obtained from ClientKit.
33- //DisplayController creates VRHead and VREyes as children. Each eye has a VRSurface child with a camera.
33+ //DisplayController creates VRViewer and VREyes as children. Each eye has a VRSurface child with a camera.
3434 //In this implementation, we are assuming that there is exactly one viewer and one surface per eye.
3535 public class DisplayController : MonoBehaviour
3636 {
3737 public const uint DEFAULT_VIEWER = 0 ; //assume exactly one viewer in this Unity implementation
3838 public const uint DEFAULT_SURFACE = 0 ; //assume exactly one viewer in this Unity implementation
39+ public const uint NUM_VIEWERS = 1 ;
40+ public const uint NUM_SURFACE_PER_EYE = 1 ;
3941
4042 private ClientKit _clientKit ;
4143 private OSVR . ClientKit . DisplayConfig _displayConfig ;
42- private VRHead _head ;
44+ private VRViewer [ ] viewers ;
4345 private VREye [ ] eyes ;
4446 private uint _eyeCount ;
4547 private uint _viewerCount ;
@@ -51,9 +53,10 @@ public OSVR.ClientKit.DisplayConfig DisplayConfig
5153 get { return _displayConfig ; }
5254 set { _displayConfig = value ; }
5355 }
54- public VRHead Head { get { return _head ; } }
56+ public VRViewer [ ] Viewers { get { return viewers ; } }
5557 public VREye [ ] Eyes { get { return eyes ; } }
5658 public uint EyeCount { get { return _eyeCount ; } }
59+ public uint ViewerCount { get { return _viewerCount ; } }
5760 public float nearClippingPlane = 0.01f ;
5861 public float farClippingPlane = 1000f ;
5962
@@ -111,27 +114,41 @@ void SetupDisplay()
111114 }
112115
113116 //Creates a head and eyes as configured in clientKit
114- //Head and Eyes are siblings, children of DisplayController
117+ //Viewers and Eyes are siblings, children of DisplayController
115118 //Each eye has one child Surface which has a camera
116119 private void CreateHeadAndEyes ( )
117120 {
118121 /* ASSUME ONE VIEWER */
119- //create a VRHead
120- GameObject vrHead = new GameObject ( "VRHead" ) ;
121- vrHead . AddComponent < AudioListener > ( ) ; //add an audio listener
122- _head = vrHead . AddComponent < VRHead > ( ) ;
123- _head . Camera = vrHead . GetComponent < Camera > ( ) ; //add a dummy camera, VRHead requires that it has a camera already
124- _head . Camera . nearClipPlane = nearClippingPlane ;
125- _head . Camera . farClipPlane = farClippingPlane ;
126- _head . tag = "MainCamera" ; //tag this as the MainCamera so other gameobjects can reference it
127- _head . DisplayController = this ; //pass DisplayController to Head
128- vrHead . transform . parent = this . transform ; //child of DisplayController
129- vrHead . transform . localPosition = Vector3 . zero ;
122+ //Create VRViewers, only one in this implementation
123+ _viewerCount = ( uint ) _displayConfig . GetNumViewers ( ) ;
124+ if ( _viewerCount != NUM_VIEWERS )
125+ {
126+ Debug . LogError ( _viewerCount + " viewers detected. This implementation supports exactly one viewer." ) ;
127+ return ;
128+ }
129+ viewers = new VRViewer [ _viewerCount ] ;
130+ for ( int i = 0 ; i < _viewerCount ; i ++ )
131+ {
132+ //create a VRViewer
133+ GameObject vrViewer = new GameObject ( "VRViewer" + i ) ;
134+ vrViewer . AddComponent < AudioListener > ( ) ; //add an audio listener
135+ VRViewer vrViewerComponent = vrViewer . AddComponent < VRViewer > ( ) ;
136+ vrViewerComponent . Camera = vrViewer . GetComponent < Camera > ( ) ; //add a dummy camera, VRViewer requires that it has a camera already
137+ vrViewerComponent . Camera . nearClipPlane = nearClippingPlane ;
138+ vrViewerComponent . Camera . farClipPlane = farClippingPlane ;
139+ vrViewerComponent . DisplayController = this ; //pass DisplayController to Viewers
140+ if ( i == 0 )
141+ {
142+ vrViewer . tag = "MainCamera" ; //tag a VRViewer as the MainCamera so other gameobjects can reference it
143+ }
144+ vrViewer . transform . parent = this . transform ; //child of DisplayController
145+ vrViewer . transform . localPosition = Vector3 . zero ;
146+ }
147+
130148
131149 //create VREyes
132150 _eyeCount = ( uint ) _displayConfig . GetNumEyesForViewer ( DEFAULT_VIEWER ) ; //get the number of eyes
133151 eyes = new VREye [ _eyeCount ] ;
134- Debug . Log ( "Eye count is " + _eyeCount ) ;
135152 for ( int i = 0 ; i < _eyeCount ; i ++ )
136153 {
137154 GameObject eyeGameObject = new GameObject ( "Eye" + i ) ; //add an eye gameobject to the scene
0 commit comments