Android Open Source - gdx-vr Stage3 D






From Project

Back to project page gdx-vr.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project gdx-vr 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

/*******************************************************************************
 * Copyright 2011 See AUTHORS file./* w w w .j a  va  2s  .c  o  m*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.vr;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Plane;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.Ray;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.Viewport;

/**
 * @author Daniel Holderbaum
 */
public class Stage3D extends Stage {

  private final Plane plane;

  // private final Vector2 offsetOnPlane;

  public Stage3D() {
    super();
    this.plane = new Plane(new Vector3(0, 0, 1), Vector3.Zero);
  }

  public Stage3D(Viewport viewport) {
    super(viewport);
    this.plane = new Plane(new Vector3(0, 0, 1), Vector3.Zero);
  }

  public Stage3D(Viewport viewport, SpriteBatch batch) {
    super(viewport, batch);
    this.plane = new Plane(new Vector3(0, 0, 1), Vector3.Zero);
  }

  public Stage3D(Plane plane, Viewport viewport, SpriteBatch batch) {
    super(viewport, batch);
    this.plane = plane;
  }

  private static final Vector3 tmp = new Vector3();

  @Override
  public Vector2 screenToStageCoordinates(Vector2 screenCoords) {
    Ray pickRay = getViewport().getPickRay(screenCoords.x, screenCoords.y);
    Vector3 intersection = tmp;
    if (Intersector.intersectRayPlane(pickRay, plane, intersection)) {
      screenCoords.x = intersection.x;
      screenCoords.y = intersection.y;
    } else {
      screenCoords.x = Float.MAX_VALUE;
      screenCoords.y = Float.MAX_VALUE;
    }
    return screenCoords;
  }

  @Override
  public void calculateScissors(Rectangle localRect, Rectangle scissorRect) {
    super.calculateScissors(localRect, scissorRect);
    scissorRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
  }

  private static final Matrix4 transform = new Matrix4();

  @Override
  public void draw() {
    transform.idt();
    transform.setToLookAt(plane.normal, Vector3.Z);
    // TODO: no cpy()
    transform.translate(plane.normal.cpy().nor().scl(plane.d));

    getBatch().setTransformMatrix(transform);

    super.draw();
  }

}




Java Source Code List

com.badlogic.gdx.vr.Body.java
com.badlogic.gdx.vr.CardboardDistortionRenderer.java
com.badlogic.gdx.vr.CardboardDistortion.java
com.badlogic.gdx.vr.CardboardHMD.java
com.badlogic.gdx.vr.CardboardImplementation.java
com.badlogic.gdx.vr.CardboardMetaInformation.java
com.badlogic.gdx.vr.CardboardOpticsInformation.java
com.badlogic.gdx.vr.CardboardScreenInformation.java
com.badlogic.gdx.vr.DeviceMetaInformation.java
com.badlogic.gdx.vr.DeviceOpticsInformation.java
com.badlogic.gdx.vr.DeviceScreenInformation.java
com.badlogic.gdx.vr.DistortionRenderer.java
com.badlogic.gdx.vr.Distortion.java
com.badlogic.gdx.vr.HeadMountedDisplay.java
com.badlogic.gdx.vr.Head.java
com.badlogic.gdx.vr.MeshBuilder.java
com.badlogic.gdx.vr.OculusDistortionRenderer.java
com.badlogic.gdx.vr.OculusHMD.java
com.badlogic.gdx.vr.OculusImplementation.java
com.badlogic.gdx.vr.OculusMetaInformation.java
com.badlogic.gdx.vr.OculusOpticsInformation.java
com.badlogic.gdx.vr.OculusScreenInformation.java
com.badlogic.gdx.vr.SoftwareAntiDistortionRenderer.java
com.badlogic.gdx.vr.SplitViewport.java
com.badlogic.gdx.vr.Stage3D.java
com.badlogic.gdx.vr.TypeTransformer.java
com.badlogic.gdx.vr.TypeTransformer.java
com.badlogic.gdx.vr.VirtualRealityDeviceListener.java
com.badlogic.gdx.vr.VirtualRealityImplementation.java
com.badlogic.gdx.vr.VirtualRealityRenderListener.java
com.badlogic.gdx.vr.VirtualRealityRenderer.java
com.badlogic.gdx.vr.VirtualReality.java
com.badlogic.gdx.vr.simpleroom.IOSLauncher.java
com.badlogic.gdx.vr.simpleroom.SimpleRoom.java
com.badlogic.gdx.vr.simpleroom.android.AndroidLauncher.java
com.badlogic.gdx.vr.simpleroom.desktop.DesktopLauncher.java