Skip to content

Commit 2adb1f6

Browse files
committed
Moved SetDistortion functions to VRSurface class.
1 parent 9a325ec commit 2adb1f6

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@ public void SetProjectionMatrix(Matrix4x4 projMatrix)
7171
_camera.projectionMatrix = projMatrix;
7272
}
7373

74+
//Given distortion parameters, setup the appropriate distortion method
75+
//@todo this should be more generalized when we have more distortion options
76+
public void SetDistortion(OSVR.ClientKit.RadialDistortionParameters distortionParameters)
77+
{
78+
float k1Red = (float)distortionParameters.k1.x;
79+
float k1Green = (float)distortionParameters.k1.y;
80+
float k1Blue = (float)distortionParameters.k1.z;
81+
Vector2 center = new Vector2((float)distortionParameters.centerOfProjection.x,
82+
(float)distortionParameters.centerOfProjection.y);
83+
84+
//@todo figure out which type of distortion to use
85+
//right now, there is only one option
86+
SetK1RadialDistortion(k1Red, k1Green, k1Blue, center);
87+
}
88+
89+
//set distortion parameters for K1 Radial Distortion method
90+
private void SetK1RadialDistortion(float k1Red, float k1Green, float k1Blue, Vector2 center)
91+
{
92+
// disable distortion if there is no distortion for this HMD
93+
if (k1Red == 0 && k1Green == 0 && k1Blue == 0)
94+
{
95+
if (DistortionEffect)
96+
{
97+
DistortionEffect.enabled = false;
98+
}
99+
return;
100+
}
101+
// Otherwise try to create distortion and set its parameters
102+
var distortionFactory = new K1RadialDistortionFactory();
103+
var effect = distortionFactory.GetOrCreateDistortion(this);
104+
if (effect)
105+
{
106+
effect.k1Red = k1Red;
107+
effect.k1Green = k1Green;
108+
effect.k1Blue = k1Blue;
109+
effect.center = center;
110+
}
111+
}
112+
74113
//Render the camera
75114
public void Render()
76115
{

0 commit comments

Comments
 (0)