Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created April 1, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demonixis/279327770795293a448cf0b0e531521a to your computer and use it in GitHub Desktop.
Save demonixis/279327770795293a448cf0b0e531521a to your computer and use it in GitHub Desktop.
A function to get the distortion parameters for an OSVR Application.
public Vector3[] GetDistortionParams()
{
var displayConfig = _context.GetDisplayConfig();
var numViewers = displayConfig.GetNumViewers();
var distortionParams = new Vector3[2];
if (numViewers != 1)
return -1;
for (uint viewer = 0; viewer < numViewers; viewer++)
{
var numEyes = displayConfig.GetNumEyesForViewer(viewer);
if (numEyes != 2)
return -2;
for (byte eye = 0; eye < numEyes; eye++)
{
var numSurfaces = displayConfig.GetNumSurfacesForViewerEye(viewer, eye);
if (numSurfaces != 1)
return -3;
for (uint surface = 0; surface < numSurfaces; surface++)
{
var distortionCorrectionRequired = displayConfig.DoesViewerEyeSurfaceWantDistortion(viewer, eye, surface);
if (distortionCorrectionRequired)
{
var radialDistortionPriority = displayConfig.GetViewerEyeSurfaceRadialDistortionPriority(viewer, eye, surface);
if (radialDistortionPriority >= 0)
{
var dist = displayConfig.GetViewerEyeSurfaceRadialDistortion(viewer, eye, surface);
distortionParams[eye].X = (float)dist.k1.x;
distortionParams[eye].Y = (float)dist.k1.y;
distortionParams[eye].Z = (float)dist.k1.z;
}
}
}
}
}
return distortionParams;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment