@@ -43,109 +43,101 @@ public Camera Camera
4343 }
4444 return _camera ;
4545 }
46- set { _camera = value ; } }
46+ set { _camera = value ; }
47+ }
4748 public DisplayController DisplayController { get { return _displayController ; } set { _displayController = value ; } }
49+ [ HideInInspector ]
50+ public Transform cachedTransform ;
4851 #endregion
4952
5053 #region Private Variables
5154 private DisplayController _displayController ;
5255 private Camera _camera ;
53- private bool renderedStereo = true ;
54- private bool updated = false ; //whether the headpose has been updated this frame
55- private bool updateEarly = false ; //if false, update in LateUpdate
56+ private bool disabledCamera = true ;
5657 #endregion
5758
58- void OnEnable ( )
59+ void Awake ( )
5960 {
60- StartCoroutine ( "EndOfFrame" ) ;
61+ Init ( ) ;
6162 }
6263
63- void OnDisable ( )
64+ void Init ( )
6465 {
65- StopCoroutine ( "EndOfFrame" ) ;
66+ //cache:
67+ cachedTransform = transform ;
6668 }
6769
68- // Update is called once per frame.
69- void Update ( )
70+ void OnEnable ( )
7071 {
71- updated = false ; // OK to recompute head pose.
72- if ( updateEarly )
73- {
74- UpdateHeadPose ( ) ;
75- }
72+ StartCoroutine ( "EndOfFrame" ) ;
7673 }
77- // LateUpdate is called once per frame, after Update has finished.
78- void LateUpdate ( )
74+
75+ void OnDisable ( )
7976 {
80- UpdateHeadPose ( ) ;
77+ StopCoroutine ( "EndOfFrame" ) ;
8178 }
82- //Updates the position and rotation of the head
83- private void UpdateHeadPose ( )
84- {
85- if ( updated )
86- { // Only one update per frame.
87- return ;
88- }
89- updated = true ;
9079
91- _displayController . UpdateClient ( ) ;
92-
93- OSVR . ClientKit . Pose3 headPose = _displayController . DisplayConfig . GetViewerPose ( DisplayController . DEFAULT_VIEWER ) ;
80+ //Updates the position and rotation of the head
81+ public void UpdateViewerHeadPose ( OSVR . ClientKit . Pose3 headPose )
82+ {
9483 transform . localPosition = Math . ConvertPosition ( headPose . translation ) ;
9584 transform . localRotation = Math . ConvertOrientation ( headPose . rotation ) ;
9685 }
9786
87+ //Culling determines which objects are visible to the camera. OnPreCull is called just before this process.
9888 void OnPreCull ( )
9989 {
90+ //update the client
10091 _displayController . UpdateClient ( ) ;
10192
102- // Turn off the mono camera so it doesn't waste time rendering.
103- // @note mono camera is left on from beginning of frame till now
104- // in order that other game logic (e.g. Camera.main) continues
105- // to work as expected.
93+ // Disable dummy camera during rendering
94+ // Enable after frame ends
10695 _camera . enabled = false ;
10796
97+ //update the viewer's head pose
98+ UpdateViewerHeadPose ( _displayController . DisplayConfig . GetViewerPose ( DisplayController . DEFAULT_VIEWER ) ) ;
99+
108100 //render each eye camera (each surface)
109101 //assumes one surface per eye
110- //@todo cache eyes, eyecount?
111102 for ( int i = 0 ; i < _displayController . EyeCount ; i ++ )
112103 {
113- //get the eye's surface
114- VRSurface surface = _displayController . Eyes [ i ] . Surface ;
104+ //update the eye pose
105+ VREye eye = _displayController . Eyes [ i ] ;
106+ eye . UpdateEyePose ( _displayController . DisplayConfig . GetViewerEyePose ( DisplayController . DEFAULT_VIEWER , ( byte ) i ) ) ;
115107
116- // OSVR.ClientKit.Matrix44f viewMatrix = _displayController.DisplayConfig.GetViewerEyeViewMatrixf(
117- // DisplayController.DEFAULT_VIEWER, (byte)i, OSVR.ClientKit.MatrixConventionsFlags.ColMajor) ;
108+ //get the eye's surface
109+ VRSurface surface = eye . Surface ;
118110
119- //surface.SetViewMatrix(Math.ConvertMatrix(viewMatrix));
120-
121- //get viewport from ClientKit
111+ //get viewport from ClientKit and set surface viewport
122112 OSVR . ClientKit . Viewport viewport = _displayController . DisplayConfig . GetRelativeViewportForViewerEyeSurface (
123113 DisplayController . DEFAULT_VIEWER , ( byte ) i , DisplayController . DEFAULT_SURFACE ) ;
124114
125115 surface . SetViewport ( Math . ConvertViewport ( viewport ) ) ;
126116
127- //get projection matrix from ClientKit
117+ //get projection matrix from ClientKit and set surface projection matrix
128118 OSVR . ClientKit . Matrix44f projMatrix = _displayController . DisplayConfig . GetProjectionMatrixForViewerEyeSurfacef (
129119 DisplayController . DEFAULT_VIEWER , ( byte ) i , DisplayController . DEFAULT_SURFACE ,
130120 _camera . nearClipPlane , _camera . farClipPlane , OSVR . ClientKit . MatrixConventionsFlags . ColMajor ) ;
131121
132122 surface . SetProjectionMatrix ( Math . ConvertMatrix ( projMatrix ) ) ;
133- //surface.Render();
123+
124+ //render the surface
125+ surface . Render ( ) ;
134126 }
135127
136128 // Remember to reenable.
137- renderedStereo = true ;
129+ disabledCamera = true ;
138130 }
139131
140132 IEnumerator EndOfFrame ( )
141133 {
142134 while ( true )
143135 {
144- // If *we* turned off the mono cam, turn it back on for next frame.
145- if ( renderedStereo )
136+ //if we disabled the dummy camera, enable it here
137+ if ( disabledCamera )
146138 {
147139 Camera . enabled = true ;
148- renderedStereo = false ;
140+ disabledCamera = false ;
149141 }
150142 yield return new WaitForEndOfFrame ( ) ;
151143 }
0 commit comments