Example usage for com.badlogic.gdx.math Vector3 set

List of usage examples for com.badlogic.gdx.math Vector3 set

Introduction

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

Prototype

public Vector3 set(final float[] values) 

Source Link

Document

Sets the components from the array.

Usage

From source file:com.badlogic.gdx.physics.bullet.demo.simulationobjects.StaticPlaneSimulationObject.java

@Override
public void render(SimulationScreen screen) {
    /*/*from   www.  j  ava  2 s. com*/
     * Our StaticPlaneShape holds the plane vector and scalar. Use it instead of the applied render transform from
     * the kinematic (not updated/calculated for static planes).
     */

    Gdx.gl10.glPushMatrix();

    // Get the plane normal
    final Vector3 planeNormal = Pools.VECTOR3.obtain();
    planeNormal.set(staticPlaneShape.getPlaneNormal());

    final float planeConstant = staticPlaneShape.getPlaneConstant();

    // Calculate the plane origin
    final Vector3 planeOrigin = Pools.VECTOR3.obtain();
    planeOrigin.set(planeNormal);
    planeOrigin.scale(planeConstant, planeConstant, planeConstant);

    // Move to the origin
    Gdx.gl10.glTranslatef(planeOrigin.x, planeOrigin.y, planeOrigin.z);

    // Compute the angle difference between the plane and mesh normal ("up")
    float angle = MathUtils.radiansToDegrees * BulletDemoMath.angle(planeNormal, MESH_NORMAL);

    // Cross product gives us the vector around which to rotate
    planeNormal.crs(MESH_NORMAL);

    // Rotate by that angle
    Gdx.gl10.glRotatef(angle, planeNormal.x, planeNormal.y, planeNormal.z);

    Gdx.gl10.glColor4f(1, 1, 1, 1);
    Gdx.gl10.glEnable(GL10.GL_TEXTURE_2D);
    Gdx.gl10.glEnable(GL10.GL_COLOR_MATERIAL);

    screen.enableLights();
    texture.bind();
    mesh.render(GL10.GL_TRIANGLE_STRIP);

    Gdx.gl10.glPopMatrix();

    Pools.VECTOR3.free(planeNormal);
    Pools.VECTOR3.free(planeOrigin);
}

From source file:com.badlogic.gdx.tests.g3d.HeightField.java

public Vector3 getPositionAt(Vector3 out, int x, int y) {
    final float dx = (float) x / (float) (width - 1);
    final float dy = (float) y / (float) (height - 1);
    final float a = data[y * width + x];
    out.set(corner00).lerp(corner10, dx).lerp(tmpV1.set(corner01).lerp(corner11, dx), dy);
    out.add(tmpV1.set(magnitude).scl(a));
    return out;/* w  w  w. j a v  a  2  s  . c om*/
}

From source file:com.digitale.mygdxgame.Renderer.java

License:Open Source License

private void setProjectionAndCamera(Graphics graphics, Ship ship, Application app, GL10 gl) {
    gl.glMatrixMode(GL10.GL_MODELVIEW);//from w w  w . j a v  a 2 s .c  o  m
    gl.glLoadIdentity();
    // x=left-right, y=up-down, z=back-forward

    camera.far = 1000000;
    // camera.near=0.01f;
    Vector3 heading = new Vector3(0, 0, -1);
    Ship.shipRot.transform(heading);
    camera.direction.set(heading.x, heading.y, heading.z);
    camera.fieldOfView = 67;
    camera.position.set(Ship.position.x, 20f + Ship.position.y, 20f + Ship.position.z);

    float orbitRadius = 30f;
    camera.rotate(GameLoop.cameraHorizAngle, 0, 1, 0);
    Vector3 orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.position.set(Ship.position);
    orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    if (Ship.pitchAngle > 90 && Ship.pitchAngle < 270) {
        camera.up.set(0, -1, 0);
    } else {
        camera.up.set(0, 1, 0);
    }
    camera.up.nor();
    camera.translate(0, GameLoop.cameraVertAngle, 0);
    camera.lookAt(Ship.position.x, Ship.position.y, Ship.position.z);
    camera.update();
    camera.apply(gl);
    Simulation.camera = camera.position;
}

From source file:com.digitale.mygdxgame.Renderer.java

License:Open Source License

private void setStaticProjectionAndCamera(Graphics graphics, Application app, GL10 gl) {
    gl.glMatrixMode(GL10.GL_MODELVIEW);/*from w w  w .  ja  v a2 s.  co  m*/

    gl.glLoadIdentity();
    // x=left-right, y=up-down, z=back-forward
    camera.far = 1000;
    // camera.near=0.01f;
    Vector3 heading = new Vector3(0, 0, -1);
    camera.direction.set(heading.x, heading.y, heading.z);
    camera.fieldOfView = 67;
    camera.position.set(0, 4f + 0, 9f + 0);
    float orbitRadius = 18f;
    camera.rotate(GameLoop.cameraHorizAngle, 0, 1, 0);
    Vector3 orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.position.set(new Vector3(0, 0, 0));
    orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.up.set(0, 1, 0);
    camera.up.nor();
    camera.translate(0, ((float) (GameLoop.cameraVertAngle)) / 10, 0);
    camera.lookAt(0, 0, 0);
    camera.update();
    camera.apply(gl);
}

From source file:com.digitale.mygdxgame.SplashRenderer.java

License:Open Source License

private void setStaticProjectionAndCamera(Graphics graphics, Application app, GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();//from   w  w  w .  j a  v  a2  s  . c  o  m
    //x=left-right, y=up-down, z=back-forward
    camera.far = 1000000;
    camera.position.set(0, 7f + 0, 9f + 0);
    //camera.direction.set(0, 0, -4f).sub(camera.position).nor();
    camera.fieldOfView = 67;
    float orbitRadius = (new Vector3(0, 0, 0).dst(camera.position));
    camera.position.set(new Vector3(0, 0, 0));

    camera.rotate(Splash.cameraHorizAngle, 0, 1, 0);
    Vector3 orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.update();
    camera.apply(gl);

    orbitRadius = (new Vector3(0, 0, 0)).dst(camera.position);
    camera.position.set(new Vector3(0, 0, 0));
    camera.rotate(Splash.cameraVertAngle, 1, 0, 0);
    orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.update();
    camera.apply(gl);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    Splash.cameraHorizAngle = 0;
    Splash.cameraVertAngle = 0;
}

From source file:com.lyeeedar.Roguelike3D.Game.Actor.AI_Enemy_VFFG.java

License:Open Source License

@Override
public void evaluateAI(float delta) {
    Vector3 tmp = Pools.obtain(Vector3.class);

    int x = (int) ((actor.position.x / 10) + 0.5f);
    int y = (int) ((actor.position.y / 10) + 0.5f);

    move = GameData.calculateSpeed(actor.WEIGHT, actor.STRENGTH);
    actor.velocity.add(0, -GameData.gravity * move * actor.WEIGHT, 0);

    if (moves.size() == 0) {

    } else if (moves.getFirst()[0] == x && moves.getFirst()[1] == y) {
        moves.removeFirst();/*from  ww w  .jav a  2s  .  c om*/
    } else {
        int[] temp = moves.getFirst();
        tile[0] = temp[0] * 10;
        tile[1] = temp[1] * 10;

        double a = angle(actor.rotation, tmp.set(actor.position).sub(tile[0], 0, tile[1]).nor());

        if (Math.abs(a) < delta * 100) {
            actor.rotate(0, 1, 0, (float) a);
            actor.forward_backward(move);
        } else if (a > 0) {
            actor.rotate(0, 1, 0, -delta * 100);
        } else {
            actor.rotate(0, 1, 0, delta * 100);
        }
    }

    Bag<GameActor> actors = getVisibleActors();

    for (GameActor ga : actors) {
        if (!actor.checkFaction(ga.FACTIONS)) {
            double a = angle(actor.rotation, tmp.set(actor.position).sub(ga.position).nor());
            float dist = actor.position.dst(ga.position);

            if (Math.abs(a) < 15) {
                if (actor.L_HAND != null) {
                    actor.L_HAND.released();
                    if (dist <= actor.L_HAND.range) {
                        actor.L_HAND.held();
                    }
                }

                if (actor.R_HAND != null) {
                    actor.R_HAND.released();
                    if (dist <= actor.R_HAND.range) {
                        actor.R_HAND.held();
                    }
                }

                break;
            }
        }
    }

    Pools.free(tmp);
    actor.applyMovement(delta, GameData.gravity * 10 * (float) actor.WEIGHT);
}

From source file:com.lyeeedar.Roguelike3D.Game.GameObject.java

License:Open Source License

public void Yrotate(float angle) {
    Vector3 dir = Pools.obtain(Vector3.class);
    dir.set(rotation).nor();
    if (dir.y > -0.7 && angle < 0 || dir.y < +0.7 && angle > 0) {
        Vector3 localAxisX = Pools.obtain(Vector3.class).set(rotation);
        localAxisX.crs(up).nor();//  w  w  w  .  j  a  v  a2 s .  com
        rotate(localAxisX.x, localAxisX.y, localAxisX.z, angle);
        Pools.free(localAxisX);
    }
    Pools.free(dir);
}

From source file:com.mbrlabs.mundus.commons.scene3d.SimpleNode.java

License:Apache License

@Override
public Vector3 getLocalPosition(Vector3 out) {
    return out.set(localPosition);
}

From source file:com.mbrlabs.mundus.commons.scene3d.SimpleNode.java

License:Apache License

@Override
public Vector3 getLocalScale(Vector3 out) {
    return out.set(localScale);
}

From source file:com.mygdx.game.debugdrawers.NavMeshDebugDrawer.java

License:Apache License

public void drawClosestPointDebug(GameCharacter character) {
    Vector3 position = tmp1;/*  ww  w  .  j a  va 2s . co  m*/
    Vector3 direction = tmp2;
    Vector3 closestPoint = tmp3;
    Vector3 aimPoint = tmp4;
    float radius = 2;
    character.getDirection(direction);
    character.getGroundPosition(position);
    aimPoint.set(direction).scl(radius).add(position);
    Triangle closest = navMesh.getClosestValidPointAt(position, direction, radius, closestPoint,
            character.visibleOnLayers);

    shapeRenderer.set(MyShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(0, 0, 1, 0.2f);
    shapeRenderer.triangle(closest.a, closest.b, closest.c);
    drawVertex(aimPoint, 0.05f, Color.GREEN);
    drawVertex(closestPoint, 0.05f, Color.WHITE);

}