Example usage for com.badlogic.gdx.math Plane Plane

List of usage examples for com.badlogic.gdx.math Plane Plane

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Plane Plane.

Prototype

public Plane(Vector3 point1, Vector3 point2, Vector3 point3) 

Source Link

Document

Constructs a new plane out of the three given points that are considered to be on the plane.

Usage

From source file:com.davidykay.shootout.screens.GameLoop.java

License:Apache License

@Override
public void update(Application app) {
    simulation.update(app.getGraphics().getDeltaTime());

    Input input = app.getInput();/*from   w  ww .j  av a2s.  c  om*/
    final boolean ACCELEROMETER_STEERING = false;
    if (ACCELEROMETER_STEERING) {
        if (input.getAccelerometerY() < 0)
            simulation.moveShipLeft(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10);
        else
            simulation.moveShipRight(app.getGraphics().getDeltaTime(),
                    Math.abs(input.getAccelerometerY()) / 10);
    }

    if (input.isKeyPressed(Keys.DPAD_LEFT))
        simulation.moveShipLeft(app.getGraphics().getDeltaTime(), 0.5f);
    if (input.isKeyPressed(Keys.DPAD_RIGHT))
        simulation.moveShipRight(app.getGraphics().getDeltaTime(), 0.5f);

    if (input.justTouched()) {
        final float x = input.getX();
        final float y = input.getY();
        Vector3 nearVector = new Vector3(x, y, 0);
        Vector3 farVector = new Vector3(x, y, 1);

        renderer.unproject(nearVector);
        renderer.unproject(farVector);

        /** Vector tracing between the near plane and the far plane **/
        Vector3 inVector = new Vector3(nearVector);

        final Plane gamePlane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1));

        Ray pickRay = renderer.getCamera().getPickRay(x, y);

        Vector3 intersection = new Vector3();
        Vector3 finalVector;

        if (FLAT_MODE) {
            // Flat Mode
            if (Intersector.intersectRayPlane(pickRay, gamePlane, intersection)) {
                finalVector = new Vector3(intersection);
                if (finalVector.equals(nearVector)) {
                    Gdx.app.log(TAG, String.format("Near Vector! finalVector:(%s)", finalVector.toString()));
                } else {
                    Gdx.app.log(TAG, String.format("INTERSECTION! finalVector:(%s)", finalVector.toString()));
                }
            } else {
                Gdx.app.log(TAG, String.format("NO INTERSECTION. nearVector:(%s)", nearVector.toString()));
                finalVector = new Vector3(nearVector);
            }
        } else {
            // 3D Mode

            finalVector = new Vector3(nearVector);

            //for (Alien alien : aliens) {
            //  if (
            //      Intersector.intersectRayPlane(
            //          pickRay,
            //          gamePlane,
            //          intersection
            //          )
            //     ) {

            //  }
            //}
        }

        //simulation.tapShot(nearVector);
        //simulation.tapShot(finalVector);
        simulation.tapRay(pickRay);
    } else {
        // If we haven't been touched, let's look at the orientation. This in an attempt to lower
        // impulse from user's finger.
        float azimuth = input.getAzimuth();
        float pitch = input.getPitch();
        float roll = input.getRoll();

        simulation.updateOrientation(azimuth, pitch, roll);
    }
}

From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.Object3d.java

License:Apache License

/**
 * @param p1/* w w w.j  a  v a2s .c  o  m*/
 * @param p2
 * @param p3
 * @param n1
 * @param n2
 * @param n3
 */
protected static void addTrilange(Vector3 p1, Vector3 p2, Vector3 p3, Vector2 n1, Vector2 n2, Vector2 n3) {
    //  Plane f1=new Plane(p1, p3, p2);
    Plane f1 = new Plane(p3, p2, p1);
    mesh.addVertex(p3.x, p3.y, p3.z, n3.x, n3.y, f1.normal.x, f1.normal.y, f1.normal.z, f1.normal.x,
            f1.normal.y, f1.normal.z, 1f);
    mesh.addVertex(p2.x, p2.y, p2.z, n2.x, n2.y, f1.normal.x, f1.normal.y, f1.normal.z, f1.normal.x,
            f1.normal.y, f1.normal.z, 1f);
    mesh.addVertex(p1.x, p1.y, p1.z, n1.x, n1.y, f1.normal.x, f1.normal.y, f1.normal.z, f1.normal.x,
            f1.normal.y, f1.normal.z, 1f);
    numTrilange++;
}

From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.Object3d.java

License:Apache License

/**
 * @param p1//from  w  ww  . j a  va  2  s.c om
 * @param p2
 * @param p3
 */
protected static void addTrilange(Vertex p1, Vertex p2, Vertex p3) {

    Plane f1 = new Plane(p1.position, p2.position, p3.position);
    mesh.addVertex(p3.position.x, p3.position.y, p3.position.z, p3.uv.x, p3.uv.y, f1.normal.x, f1.normal.y,
            f1.normal.z, f1.normal.x, f1.normal.y, f1.normal.z, 1f);
    mesh.addVertex(p2.position.x, p2.position.y, p2.position.z, p2.uv.x, p2.uv.y, f1.normal.x, f1.normal.y,
            f1.normal.z, f1.normal.x, f1.normal.y, f1.normal.z, 1f);
    mesh.addVertex(p1.position.x, p1.position.y, p1.position.z, p1.uv.x, p1.uv.y, f1.normal.x, f1.normal.y,
            f1.normal.z, f1.normal.x, f1.normal.y, f1.normal.z, 1f);
    numTrilange++;
}

From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.ObjectMesh.java

License:Apache License

public void addQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector2 textCoordMin,
        Vector2 textCoordMax) {//from  w  w  w . j a v a 2 s  .  co  m

    //
    // Normal
    //
    tempPlane = new Plane(p1, p3, p2);

    //
    // UV Coords
    //
    temp1Vector2.set(textCoordMin.x, textCoordMin.y);
    temp2Vector2.set(textCoordMax.x, textCoordMin.y);
    temp3Vector2.set(textCoordMax.x, textCoordMax.y);
    temp4Vector2.set(textCoordMin.x, textCoordMax.y);

    //
    // Add Vertex
    //
    addVertex(p1, temp1Vector2, tempPlane.normal);
    addVertex(p2, temp2Vector2, tempPlane.normal);
    addVertex(p3, temp3Vector2, tempPlane.normal);
    addVertex(p4, temp4Vector2, tempPlane.normal);

    //
    // Add Indeices
    //
    indicesBuffer.ensureCapacity(3);
    indicesBuffer.add((short) (vertexIndex - 2));
    indicesBuffer.add((short) (vertexIndex - 3));
    indicesBuffer.add((short) (vertexIndex - 4));

    indicesBuffer.add((short) (vertexIndex - 4));
    indicesBuffer.add((short) (vertexIndex - 1));
    indicesBuffer.add((short) (vertexIndex - 2));

    indicesIndex = indicesBuffer.size;
    isUpdate = true;
}

From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.ObjectMesh.java

License:Apache License

public void addTrilange(Vector3 p1, Vector3 p2, Vector3 p3, Vector2 t1, Vector2 t2, Vector2 t3, Color c1,
        Color c2, Color c3) {
    Plane f1 = new Plane(p1, p3, p2);
    addVertex(p1.x, p1.y, p1.z, t1.x, t1.y, f1.getNormal().x, f1.getNormal().y, f1.getNormal().z, c1.r, c1.g,
            c1.b, c1.a);/*from   ww w  . j a  v a2 s. c om*/
    addVertex(p2.x, p2.y, p2.z, t2.x, t2.y, f1.getNormal().x, f1.getNormal().y, f1.getNormal().z, c2.r, c2.g,
            c2.b, c2.a);
    addVertex(p3.x, p3.y, p3.z, t3.x, t3.y, f1.getNormal().x, f1.getNormal().y, f1.getNormal().z, c3.r, c3.g,
            c3.b, c3.a);
    isUpdate = true;
}

From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.ObjectMesh.java

License:Apache License

public void addTrilange(Vector3 p1, Vector3 p2, Vector3 p3, Vector2 t1, Vector2 t2, Vector2 t3) {
    Plane f1 = new Plane(p1, p3, p2);
    addVertex(p1.x, p1.y, p1.z, t1.x, t1.y, f1.getNormal().x, f1.getNormal().y, f1.getNormal().z, 1.0f, 1.0f,
            1.0f, 1.0f);//  w  w  w.  j a v  a2 s  .c o  m
    addVertex(p2.x, p2.y, p2.z, t2.x, t2.y, f1.getNormal().x, f1.getNormal().y, f1.getNormal().z, 1.0f, 1.0f,
            1.0f, 1.0f);
    addVertex(p3.x, p3.y, p3.z, t3.x, t3.y, f1.getNormal().x, f1.getNormal().y, f1.getNormal().z, 1.0f, 1.0f,
            1.0f, 1.0f);
    isUpdate = true;
}