Android Open Source - Cardboard Distortion






From Project

Back to project page Cardboard.

License

The source code is released under:

Apache License

If you think the Android project Cardboard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.google.vrtoolkit.cardboard;
/*from w  w  w. ja  va2  s .  c  om*/
public class Distortion {
  private static final float[] DEFAULT_COEFFICIENTS = { 250.0F, 50000.0F };
  private float[] mCoefficients;

  public Distortion() {
    this.mCoefficients = new float[2];
    this.mCoefficients[0] = DEFAULT_COEFFICIENTS[0];
    this.mCoefficients[1] = DEFAULT_COEFFICIENTS[1];
  }

  public Distortion(Distortion other) {
    this.mCoefficients = new float[2];
    this.mCoefficients[0] = other.mCoefficients[0];
    this.mCoefficients[1] = other.mCoefficients[1];
  }

  public void setCoefficients(float[] coefficients) {
    this.mCoefficients[0] = coefficients[0];
    this.mCoefficients[1] = coefficients[1];
  }

  public float[] getCoefficients() {
    return this.mCoefficients;
  }

  public float distortionFactor(float radius) {
    float rSq = radius * radius;
    return 1.0F + this.mCoefficients[0] * rSq + this.mCoefficients[1] * rSq
        * rSq;
  }

  public float distort(float radius) {
    return radius * distortionFactor(radius);
  }

  public float distortInverse(float radius) {
    float r0 = radius / 0.9F;
    float r1 = radius * 0.9F;

    float dr0 = radius - distort(r0);
    while (Math.abs(r1 - r0) > 1.0E-4D) {
      float dr1 = radius - distort(r1);
      float r2 = r1 - dr1 * ((r1 - r0) / (dr1 - dr0));
      r0 = r1;
      r1 = r2;
      dr0 = dr1;
    }
    return r1;
  }

  public boolean equals(Object other) {
    if (other == null) {
      return false;
    }
    if (other == this) {
      return true;
    }
    if (!(other instanceof Distortion)) {
      return false;
    }
    Distortion o = (Distortion) other;
    return (this.mCoefficients[0] == o.mCoefficients[0])
        && (this.mCoefficients[1] == o.mCoefficients[1]);
  }

  public String toString() {
    return "Distortion {" + this.mCoefficients[0] + ", "
        + this.mCoefficients[1] + "}";
  }
}




Java Source Code List

com.google.vrtoolkit.cardboard.BuildConfig.java
com.google.vrtoolkit.cardboard.CardboardActivity.java
com.google.vrtoolkit.cardboard.CardboardDeviceParams.java
com.google.vrtoolkit.cardboard.CardboardView.java
com.google.vrtoolkit.cardboard.DistortionRenderer.java
com.google.vrtoolkit.cardboard.Distortion.java
com.google.vrtoolkit.cardboard.EyeParams.java
com.google.vrtoolkit.cardboard.EyeTransform.java
com.google.vrtoolkit.cardboard.FieldOfView.java
com.google.vrtoolkit.cardboard.HeadMountedDisplay.java
com.google.vrtoolkit.cardboard.HeadTransform.java
com.google.vrtoolkit.cardboard.ScreenParams.java
com.google.vrtoolkit.cardboard.Viewport.java
com.google.vrtoolkit.cardboard.samples.treasurehunt.CardboardOverlayView.java
com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
com.google.vrtoolkit.cardboard.samples.treasurehunt.WorldLayoutData.java
com.google.vrtoolkit.cardboard.sensors.HeadTracker.java
com.google.vrtoolkit.cardboard.sensors.MagnetSensor.java
com.google.vrtoolkit.cardboard.sensors.NfcSensor.java
com.google.vrtoolkit.cardboard.sensors.internal.Matrix3x3d.java
com.google.vrtoolkit.cardboard.sensors.internal.OrientationEKF.java
com.google.vrtoolkit.cardboard.sensors.internal.So3Util.java
com.google.vrtoolkit.cardboard.sensors.internal.Vector3d.java