Android Open Source - Cardboard Screen Params






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   ww w  .jav  a 2  s.  co  m*/
import android.util.DisplayMetrics;
import android.view.Display;

public class ScreenParams {
  public static final float METERS_PER_INCH = 0.0254F;
  private static final float DEFAULT_BORDER_SIZE_METERS = 0.0030F;
  private int mWidth;
  private int mHeight;
  private float mXMetersPerPixel;
  private float mYMetersPerPixel;
  private float mBorderSizeMeters;

  public ScreenParams(Display display) {
    DisplayMetrics metrics = new DisplayMetrics();
    try {
      display.getRealMetrics(metrics);
    } catch (NoSuchMethodError e) {
      display.getMetrics(metrics);
    }
    this.mXMetersPerPixel = (0.0254F / metrics.xdpi);
    this.mYMetersPerPixel = (0.0254F / metrics.ydpi);
    this.mWidth = metrics.widthPixels;
    this.mHeight = metrics.heightPixels;
    this.mBorderSizeMeters = 0.0030F;
    if (this.mHeight > this.mWidth) {
      int tempPx = this.mWidth;
      this.mWidth = this.mHeight;
      this.mHeight = tempPx;

      float tempMetersPerPixel = this.mXMetersPerPixel;
      this.mXMetersPerPixel = this.mYMetersPerPixel;
      this.mYMetersPerPixel = tempMetersPerPixel;
    }
  }

  public ScreenParams(ScreenParams params) {
    this.mWidth = params.mWidth;
    this.mHeight = params.mHeight;
    this.mXMetersPerPixel = params.mXMetersPerPixel;
    this.mYMetersPerPixel = params.mYMetersPerPixel;
    this.mBorderSizeMeters = params.mBorderSizeMeters;
  }

  public void setWidth(int width) {
    this.mWidth = width;
  }

  public int getWidth() {
    return this.mWidth;
  }

  public void setHeight(int height) {
    this.mHeight = height;
  }

  public int getHeight() {
    return this.mHeight;
  }

  public float getWidthMeters() {
    return this.mWidth * this.mXMetersPerPixel;
  }

  public float getHeightMeters() {
    return this.mHeight * this.mYMetersPerPixel;
  }

  public void setBorderSizeMeters(float screenBorderSize) {
    this.mBorderSizeMeters = screenBorderSize;
  }

  public float getBorderSizeMeters() {
    return this.mBorderSizeMeters;
  }

  public boolean equals(Object other) {
    if (other == null) {
      return false;
    }
    if (other == this) {
      return true;
    }
    if (!(other instanceof ScreenParams)) {
      return false;
    }
    ScreenParams o = (ScreenParams) other;

    return (this.mWidth == o.mWidth) && (this.mHeight == o.mHeight)
        && (this.mXMetersPerPixel == o.mXMetersPerPixel)
        && (this.mYMetersPerPixel == o.mYMetersPerPixel)
        && (this.mBorderSizeMeters == o.mBorderSizeMeters);
  }
}




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