@@ -51,16 +51,24 @@ public class VRHead : MonoBehaviour
5151 float _previousStereoAmount ;
5252 ViewMode _previousViewMode ;
5353 private Camera _camera ;
54+ private DeviceDescriptor _deviceDescriptor ;
5455 #endregion
5556
5657 #region Init
5758 void Start ( )
5859 {
5960 Init ( ) ;
60- GetDeviceDescription ( ) ;
6161 CatalogEyes ( ) ;
62+ GetDeviceDescription ( ) ;
63+ MatchEyes ( ) ; //copy camera properties to each eye
64+ //rotate each eye based on overlap percent, must do this after match eyes
65+ if ( _deviceDescriptor != null )
66+ {
67+ SetEyeRotation ( _deviceDescriptor . OverlapPercent , _deviceDescriptor . MonocularHorizontal ) ;
68+ SetEyeRoll ( _deviceDescriptor . LeftRoll , _deviceDescriptor . RightRoll ) ;
69+ }
70+
6271 }
63-
6472 #endregion
6573
6674 #region Loop
@@ -109,13 +117,11 @@ void UpdateStereoAmount()
109117 }
110118 }
111119
120+ //this function finds and initializes each eye
112121 void CatalogEyes ( )
113122 {
114123 foreach ( VREye currentEye in GetComponentsInChildren < VREye > ( ) )
115124 {
116- //match:
117- currentEye . MatchCamera ( _camera ) ;
118-
119125 //catalog:
120126 switch ( currentEye . eye )
121127 {
@@ -130,6 +136,16 @@ void CatalogEyes()
130136 }
131137 }
132138
139+ //this function matches the camera on each eye to the camera on the head
140+ void MatchEyes ( )
141+ {
142+ foreach ( VREye currentEye in GetComponentsInChildren < VREye > ( ) )
143+ {
144+ //match:
145+ currentEye . MatchCamera ( _camera ) ;
146+ }
147+ }
148+
133149 void Init ( )
134150 {
135151 if ( _camera == null )
@@ -153,11 +169,11 @@ void Init()
153169 /// </summary>
154170 private void GetDeviceDescription ( )
155171 {
156- DeviceDescriptor deviceDescriptor = GetComponent < DisplayInterface > ( ) . GetDeviceDescription ( ) ;
172+ _deviceDescriptor = GetComponent < DisplayInterface > ( ) . GetDeviceDescription ( ) ;
157173 // Debug.Log(deviceDescriptor.ToString());
158- if ( deviceDescriptor != null )
174+ if ( _deviceDescriptor != null )
159175 {
160- switch ( deviceDescriptor . DisplayMode )
176+ switch ( _deviceDescriptor . DisplayMode )
161177 {
162178 case "full_screen" :
163179 viewMode = ViewMode . mono ;
@@ -168,12 +184,12 @@ private void GetDeviceDescription()
168184 viewMode = ViewMode . stereo ;
169185 break ;
170186 }
171- stereoAmount = Mathf . Clamp ( deviceDescriptor . OverlapPercent , 0 , 100 ) ;
172- _camera . fieldOfView = Mathf . Clamp ( deviceDescriptor . MonocularVertical , 0 , 180 ) ; //unity camera FOV is vertical
173- SetResolution ( deviceDescriptor . Width , deviceDescriptor . Height ) ;
174-
187+ stereoAmount = Mathf . Clamp ( _deviceDescriptor . OverlapPercent , 0 , 100 ) ;
188+ SetResolution ( _deviceDescriptor . Width , _deviceDescriptor . Height ) ; //set resolution before FOV
189+ _camera . fieldOfView = Mathf . Clamp ( _deviceDescriptor . MonocularVertical , 0 , 180 ) ; //unity camera FOV is vertical
190+
175191 //if the view needs to be rotated 180 degrees, create a parent game object that is flipped 180 degrees on the z axis.
176- if ( deviceDescriptor . Rotate180 > 0 )
192+ if ( _deviceDescriptor . Rotate180 > 0 )
177193 {
178194 GameObject vrHeadParent = new GameObject ( ) ;
179195 vrHeadParent . name = this . transform . name + "_parent" ;
@@ -200,6 +216,48 @@ private void SetResolution(int width, int height)
200216 UnityEditor . PlayerSettings . defaultIsFullScreen = true ;
201217#endif
202218 }
219+
220+ //rotate each eye based on overlap percent and horizontal FOV
221+ //Formula: ((OverlapPercent/100) * hFOV)/2
222+ private void SetEyeRotation ( float overlapPercent , float horizontalFov )
223+ {
224+ float overlap = overlapPercent * .01f * horizontalFov * 0.5f ;
225+
226+ //with a 90 degree FOV with 100% overlap, the eyes should not be rotated
227+ //compare rotationY with half of FOV
228+
229+ float halfFOV = horizontalFov * 0.5f ;
230+ float rotateYAmount = Mathf . Abs ( overlap - halfFOV ) ;
231+
232+ foreach ( VREye currentEye in GetComponentsInChildren < VREye > ( ) )
233+ {
234+ switch ( currentEye . eye )
235+ {
236+ case Eye . left :
237+ _leftEye . SetEyeRotationY ( - rotateYAmount ) ;
238+ break ;
239+ case Eye . right :
240+ _rightEye . SetEyeRotationY ( rotateYAmount ) ;
241+ break ;
242+ }
243+ }
244+ }
245+ //rotate each eye on the z axis by the specified amount, in degrees
246+ private void SetEyeRoll ( float leftRoll , float rightRoll )
247+ {
248+ foreach ( VREye currentEye in GetComponentsInChildren < VREye > ( ) )
249+ {
250+ switch ( currentEye . eye )
251+ {
252+ case Eye . left :
253+ _leftEye . SetEyeRoll ( leftRoll ) ;
254+ break ;
255+ case Eye . right :
256+ _rightEye . SetEyeRoll ( rightRoll ) ;
257+ break ;
258+ }
259+ }
260+ }
203261 #endregion
204262 }
205263 }
0 commit comments