Skip to content

Commit 4e47ee7

Browse files
committed
Put the eye stuff in the namespace.
1 parent 94fff59 commit 4e47ee7

3 files changed

Lines changed: 163 additions & 153 deletions

File tree

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,11 @@ public class InterfaceCallbacks : MonoBehaviour
3232
public delegate void ButtonCallback(string source, bool pressed);
3333
public delegate void AnalogCallback(string source, float value);
3434

35-
private OSVR.Unity.ClientKit clientKit;
36-
3735
void Start()
3836
{
39-
if (null == clientKit)
40-
{
41-
clientKit = OSVR.Unity.ClientKit.Get();
42-
}
4337
if (null == iface)
4438
{
45-
iface = clientKit.GetContext().getInterface(path);
39+
iface = OSVR.Unity.ClientKit.instance.context.getInterface(path);
4640
}
4741
}
4842

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

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,59 @@
1414
using UnityEngine;
1515
using System.Collections;
1616

17-
public enum Eye{ left, right };
18-
19-
public class VREye : MonoBehaviour
17+
namespace OSVR
2018
{
21-
#region Public Variables
22-
public Eye eye;
23-
[HideInInspector]
24-
public Transform cachedTransform;
25-
#endregion
19+
namespace Unity
20+
{
21+
public enum Eye { left, right };
22+
23+
public class VREye : MonoBehaviour
24+
{
25+
#region Public Variables
26+
public Eye eye;
27+
28+
[HideInInspector]
29+
public Transform cachedTransform;
30+
#endregion
2631

27-
#region Init
28-
void Awake()
29-
{
30-
Init();
31-
}
32-
#endregion
32+
#region Init
33+
void Awake()
34+
{
35+
Init();
36+
}
37+
#endregion
3338

34-
#region Public Methods
35-
public void MatchCamera( Camera sourceCamera )
36-
{
37-
camera.nearClipPlane = sourceCamera.nearClipPlane;
38-
camera.farClipPlane = sourceCamera.farClipPlane;
39-
camera.backgroundColor = sourceCamera.backgroundColor;
40-
camera.clearFlags = sourceCamera.clearFlags;
41-
camera.cullingMask = sourceCamera.cullingMask;
42-
}
43-
#endregion
39+
#region Public Methods
40+
public void MatchCamera(Camera sourceCamera)
41+
{
42+
camera.nearClipPlane = sourceCamera.nearClipPlane;
43+
camera.farClipPlane = sourceCamera.farClipPlane;
44+
camera.backgroundColor = sourceCamera.backgroundColor;
45+
camera.clearFlags = sourceCamera.clearFlags;
46+
camera.cullingMask = sourceCamera.cullingMask;
47+
}
48+
#endregion
4449

45-
#region Private Methods
46-
void Init()
47-
{
48-
//cache:
49-
cachedTransform = transform;
50+
#region Private Methods
51+
void Init()
52+
{
53+
//cache:
54+
cachedTransform = transform;
5055

51-
if ( camera == null ) gameObject.AddComponent<Camera>();
56+
if (camera == null) gameObject.AddComponent<Camera>();
5257

53-
//camera setups:
54-
switch( eye )
55-
{
56-
case Eye.left:
57-
camera.rect = new Rect( 0, 0, .5f, 1 );
58-
break;
59-
case Eye.right:
60-
camera.rect = new Rect( .5f, 0, .5f, 1 );
61-
break;
62-
}
63-
}
64-
#endregion
65-
}
58+
//camera setups:
59+
switch (eye)
60+
{
61+
case Eye.left:
62+
camera.rect = new Rect(0, 0, .5f, 1);
63+
break;
64+
case Eye.right:
65+
camera.rect = new Rect(.5f, 0, .5f, 1);
66+
break;
67+
}
68+
}
69+
#endregion
70+
}
71+
}
72+
}

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

Lines changed: 112 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -14,107 +14,116 @@
1414
using UnityEngine;
1515
using System.Collections;
1616

17-
public enum ViewMode{ stereo, mono };
18-
19-
[RequireComponent( typeof( Camera ) ) ]
20-
public class VRHead : MonoBehaviour
17+
namespace OSVR
2118
{
22-
#region Public Variables
23-
public ViewMode viewMode;
24-
[Range( 0, 1 )]
25-
public float stereoAmount;
26-
public float maxStereo = .03f;
27-
#endregion
28-
29-
#region Private Variables
30-
VREye _leftEye;
31-
VREye _rightEye;
32-
float _previousStereoAmount;
33-
ViewMode _previousViewMode;
34-
#endregion
35-
36-
#region Init
37-
void Start()
38-
{
39-
Init();
40-
CatalogEyes();
41-
}
42-
#endregion
43-
44-
#region Loop
45-
void Update()
46-
{
47-
UpdateStereoAmount();
48-
UpdateViewMode();
49-
}
50-
#endregion
51-
52-
#region Public Methods
53-
#endregion
54-
55-
#region Private Methods
56-
void UpdateViewMode()
57-
{
58-
if( Time.realtimeSinceStartup < 100 || _previousViewMode != viewMode )
59-
{
60-
switch( viewMode )
61-
{
62-
case ViewMode.mono:
63-
camera.enabled = true;
64-
_leftEye.camera.enabled = false;
65-
_rightEye.camera.enabled = false;
66-
break;
67-
68-
case ViewMode.stereo:
69-
camera.enabled = false;
70-
_leftEye.camera.enabled = true;
71-
_rightEye.camera.enabled = true;
72-
break;
73-
}
74-
}
75-
76-
_previousViewMode = viewMode;
77-
}
78-
79-
void UpdateStereoAmount()
80-
{
81-
if( stereoAmount != _previousStereoAmount )
82-
{
83-
stereoAmount = Mathf.Clamp( stereoAmount, 0, 1 );
84-
_rightEye.cachedTransform.localPosition = Vector3.right * ( maxStereo * stereoAmount );
85-
_leftEye.cachedTransform.localPosition = Vector3.left * ( maxStereo * stereoAmount );
86-
_previousStereoAmount = stereoAmount;
87-
}
88-
}
89-
90-
void CatalogEyes()
91-
{
92-
foreach( VREye currentEye in GetComponentsInChildren<VREye>() )
93-
{
94-
//match:
95-
currentEye.MatchCamera( camera );
96-
97-
//catalog:
98-
switch( currentEye.eye )
99-
{
100-
case Eye.left:
101-
_leftEye = currentEye;
102-
break;
103-
104-
case Eye.right:
105-
_rightEye = currentEye;
106-
break;
107-
}
108-
}
109-
}
110-
111-
void Init()
112-
{
113-
//VR should never timeout the screen:
114-
Screen.sleepTimeout = SleepTimeout.NeverSleep;
115-
116-
//60 FPS whenever possible:
117-
Application.targetFrameRate = 60;
118-
}
119-
#endregion
120-
}
19+
namespace Unity
20+
{
21+
22+
public enum ViewMode { stereo, mono };
23+
24+
[RequireComponent(typeof(Camera))]
25+
public class VRHead : MonoBehaviour
26+
{
27+
#region Public Variables
28+
public ViewMode viewMode;
29+
30+
[Range(0, 1)]
31+
public float stereoAmount;
32+
33+
public float maxStereo = .03f;
34+
#endregion
35+
36+
#region Private Variables
37+
VREye _leftEye;
38+
VREye _rightEye;
39+
float _previousStereoAmount;
40+
ViewMode _previousViewMode;
41+
#endregion
42+
43+
#region Init
44+
void Start()
45+
{
46+
Init();
47+
CatalogEyes();
48+
}
49+
#endregion
50+
51+
#region Loop
52+
void Update()
53+
{
54+
UpdateStereoAmount();
55+
UpdateViewMode();
56+
}
57+
#endregion
58+
59+
#region Public Methods
60+
#endregion
61+
62+
#region Private Methods
63+
void UpdateViewMode()
64+
{
65+
if (Time.realtimeSinceStartup < 100 || _previousViewMode != viewMode)
66+
{
67+
switch (viewMode)
68+
{
69+
case ViewMode.mono:
70+
camera.enabled = true;
71+
_leftEye.camera.enabled = false;
72+
_rightEye.camera.enabled = false;
73+
break;
74+
75+
case ViewMode.stereo:
76+
camera.enabled = false;
77+
_leftEye.camera.enabled = true;
78+
_rightEye.camera.enabled = true;
79+
break;
80+
}
81+
}
82+
83+
_previousViewMode = viewMode;
84+
}
85+
86+
void UpdateStereoAmount()
87+
{
88+
if (stereoAmount != _previousStereoAmount)
89+
{
90+
stereoAmount = Mathf.Clamp(stereoAmount, 0, 1);
91+
_rightEye.cachedTransform.localPosition = Vector3.right * (maxStereo * stereoAmount);
92+
_leftEye.cachedTransform.localPosition = Vector3.left * (maxStereo * stereoAmount);
93+
_previousStereoAmount = stereoAmount;
94+
}
95+
}
96+
97+
void CatalogEyes()
98+
{
99+
foreach (VREye currentEye in GetComponentsInChildren<VREye>())
100+
{
101+
//match:
102+
currentEye.MatchCamera(camera);
103+
104+
//catalog:
105+
switch (currentEye.eye)
106+
{
107+
case Eye.left:
108+
_leftEye = currentEye;
109+
break;
110+
111+
case Eye.right:
112+
_rightEye = currentEye;
113+
break;
114+
}
115+
}
116+
}
117+
118+
void Init()
119+
{
120+
//VR should never timeout the screen:
121+
Screen.sleepTimeout = SleepTimeout.NeverSleep;
122+
123+
//60 FPS whenever possible:
124+
Application.targetFrameRate = 60;
125+
}
126+
#endregion
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)