November 6, 2019 update:
  • There's a new open source Cardboard SDK for iOS and Android NDK that offers a streamlined API, improved device compatibility, and built-in viewer profile QR code scanning. A corresponding Unity package (SDK) is planned for a future release. We recommend that all developers actively building for Google Cardboard migrate (iOS, Android NDK) to the new Cardboard SDK.
October 15, 2019 update:
  • The Daydream View VR headset is no longer available for purchase. However, you can continue to use the existing Google VR SDK to update and distribute your apps to the Google Play Store, and make them available to users in the Daydream app.

Distortion

public class Distortion

Defines all required parameters to correct the distortion caused by the lenses.

Public Constructors

Distortion(Distortion other)
Constructs a copy of another distortion object.

Public Methods

static Distortion
cardboardV1Distortion()
Return distortion parameters for Cardboard v1.0.0.
float
distort(float radius)
Distorts a radius by its distortion factor from the center of the lenses.
float
distortionFactor(float radius)
Returns the distortion factor of a point.
boolean
equals(Object other)
Compares this instance with the specified object and indicates if they are equal.
Distortion
getApproximateInverseDistortion(float maxRadius, int numCoefficients)
Builds an inverse-distortion object with least-squares-fitted coefficients.
float[]
getCoefficients()
Returns the current coefficients for lens distortion correction.
void
setCoefficients(float[] coefficients)
Sets the coefficients for lens distortion correction.
String
toString()
Returns a string containing a concise, human-readable description of this object.

Inherited Methods

Public Constructors

public Distortion ()

public Distortion (Distortion other)

Constructs a copy of another distortion object.

Parameters
other The distortion object to copy from.

Public Methods

public static Distortion cardboardV1Distortion ()

Return distortion parameters for Cardboard v1.0.0.

public float distort (float radius)

Distorts a radius by its distortion factor from the center of the lenses.

Parameters
radius Radius from the lens center in tan-angle units.
Returns
  • The distorted radius in tan-angle units.

public float distortionFactor (float radius)

Returns the distortion factor of a point.

Parameters
radius Radius of the point from the lens center in tan-angle units.
Returns
  • The distortion factor. Multiply by this factor to distort points.

public boolean equals (Object other)

Compares this instance with the specified object and indicates if they are equal.

Parameters
other The object to compare this instance with.
Returns
  • true if the objects are equal, false otherwise.

public Distortion getApproximateInverseDistortion (float maxRadius, int numCoefficients)

Builds an inverse-distortion object with least-squares-fitted coefficients.

This is intended for implementing application-side custom distortion. Use .getCoefficients() on the returned object to retrieve the inverse distortion function's coefficients.

This is an approximate inverse, and using .distort() on the returned object will be faster but less accurate than using the distortInverse() method on the original. For useful results, the input distortion must be well-behaved in the 0..maxRadius range.

Example for 50 degree half-angle FOV (100 degrees total), this will create an inverse distortion where inverse.distort(r) approximately equals distortion.distortInverse(r) in the range r = 0 ... maxFovHalfAngle.

 float maxFovHalfAngle = 50.0f * Math.PI / 180.0f;
 float maxRadiusLens = distortion.distortInverse(maxFovHalfAngle);
 Distortion inverse = distortion.getApproximateInverseDistortion(
     maxRadiusLens, 6);

Parameters
maxRadius Maximum supported radius in tan-angle units in lens space (after applying barrel distortion). Should be set to inverseDistort(tan(maximum expected FOV angle)) to create an inverse that will be usable for inputs up to tan(maximum expected FOV angle).
numCoefficients Number of desired coefficients, more provide a better fit. Does not need to match the number of coefficients in the input distortion object. 6 coefficients recommended for current GVR viewers, using more can get numerically unstable.
Returns
  • New distortion object.

public float[] getCoefficients ()

Returns the current coefficients for lens distortion correction.

Returns
  • A floating point array with the current barrel distortion coefficients.

public void setCoefficients (float[] coefficients)

Sets the coefficients for lens distortion correction.

The coefficients Ki correspond to the pincushion distortion equation:

p' = p (1 + K1 r^2 + K2 r^4 + ... + Kn r^(2n))

Where r is the distance from the optical center, p the input point and p' the output point.

Parameters
coefficients Barrel distortion coefficients to set.

public String toString ()

Returns a string containing a concise, human-readable description of this object.

Returns
  • A printable representation of this object.