Search in sources :

Example 1 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx-inGameConsole by StrongJoshua.

the class Box2DTest method render.

@Override
public void render() {
    if (Gdx.input.isTouched()) {
        float x = Gdx.input.getX();
        float y = Gdx.input.getY();
        if (!console.hitsConsole(x, y)) {
            Vector3 worldVector = c.unproject(new Vector3(x, y, 0));
            createExplosion(worldVector.x, worldVector.y, 2000);
            console.log(String.format("Created touch explosion at %.2f, %.2f!", worldVector.x, worldVector.y), LogLevel.SUCCESS);
        }
    }
    if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE))
        Gdx.app.exit();
    world.step(1 / 60f, 6, 2);
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    for (int i = 0; i < bodies.length; i++) {
        Vector2 pos = bodies[i].getPosition();
        sprites[i].setPosition(pos.x - sprites[i].getWidth() / 2, pos.y - sprites[i].getHeight() / 2);
        sprites[i].setRotation(MathUtils.radiansToDegrees * bodies[i].getAngle());
        sprites[i].draw(batch);
    }
    batch.end();
    debugRenderer.render(world, c.combined);
    console.draw();
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) Vector3(com.badlogic.gdx.math.Vector3)

Example 2 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx-inGameConsole by StrongJoshua.

the class Box2DTest method createExplosion.

/**
	 * Creates an explosion that applies forces to the bodies relative to their
	 * position and the given x and y values.
	 * 
	 * @param maxForce
	 *            The maximum force to be applied to the bodies (diminishes as
	 *            distance from touch increases).
	 */
private void createExplosion(float x, float y, float maxForce) {
    float force;
    Vector2 touch = new Vector2(x, y);
    for (int i = 0; i < bodies.length; i++) {
        Body b = bodies[i];
        Vector2 v = b.getPosition();
        float dist = v.dst2(touch);
        if (dist == 0)
            force = maxForce;
        else
            force = MathUtils.clamp(maxForce / dist, 0, maxForce);
        float angle = v.cpy().sub(touch).angle();
        float xForce = force * MathUtils.cosDeg(angle);
        float yForce = force * MathUtils.sinDeg(angle);
        Vector3 touch3, v3, boundMin, boundMax, intersection;
        touch3 = new Vector3(touch.x, touch.y, 0);
        v3 = new Vector3(v.x, v.y, 0);
        boundMin = new Vector3(v.x - 1, v.y - 1, 0);
        boundMax = new Vector3(v.x + 1, v.y + 1, 0);
        intersection = Vector3.Zero;
        Intersector.intersectRayBounds(new Ray(touch3, v3), new BoundingBox(boundMin, boundMax), intersection);
        b.applyForce(new Vector2(xForce, yForce), new Vector2(intersection.x, intersection.y), true);
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Vector3(com.badlogic.gdx.math.Vector3) Ray(com.badlogic.gdx.math.collision.Ray) Body(com.badlogic.gdx.physics.box2d.Body)

Example 3 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class Mesh method transform.

/** Method to transform the positions in the float array. Normals will be kept as is. This is a potentially slow operation, use
	 * with care.
	 * @param matrix the transformation matrix
	 * @param vertices the float array
	 * @param vertexSize the number of floats in each vertex
	 * @param offset the offset within a vertex to the position
	 * @param dimensions the size of the position
	 * @param start the vertex to start with
	 * @param count the amount of vertices to transform */
public static void transform(final Matrix4 matrix, final float[] vertices, int vertexSize, int offset, int dimensions, int start, int count) {
    if (offset < 0 || dimensions < 1 || (offset + dimensions) > vertexSize)
        throw new IndexOutOfBoundsException();
    if (start < 0 || count < 1 || ((start + count) * vertexSize) > vertices.length)
        throw new IndexOutOfBoundsException("start = " + start + ", count = " + count + ", vertexSize = " + vertexSize + ", length = " + vertices.length);
    final Vector3 tmp = new Vector3();
    int idx = offset + (start * vertexSize);
    switch(dimensions) {
        case 1:
            for (int i = 0; i < count; i++) {
                tmp.set(vertices[idx], 0, 0).mul(matrix);
                vertices[idx] = tmp.x;
                idx += vertexSize;
            }
            break;
        case 2:
            for (int i = 0; i < count; i++) {
                tmp.set(vertices[idx], vertices[idx + 1], 0).mul(matrix);
                vertices[idx] = tmp.x;
                vertices[idx + 1] = tmp.y;
                idx += vertexSize;
            }
            break;
        case 3:
            for (int i = 0; i < count; i++) {
                tmp.set(vertices[idx], vertices[idx + 1], vertices[idx + 2]).mul(matrix);
                vertices[idx] = tmp.x;
                vertices[idx + 1] = tmp.y;
                vertices[idx + 2] = tmp.z;
                idx += vertexSize;
            }
            break;
    }
}
Also used : Vector3(com.badlogic.gdx.math.Vector3)

Example 4 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class FloatTextureTest method createScreenQuad.

private void createScreenQuad() {
    if (screenQuad != null)
        return;
    screenQuad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
    Vector3 vec0 = new Vector3(0, 0, 0);
    screenCamera.unproject(vec0);
    Vector3 vec1 = new Vector3(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0);
    screenCamera.unproject(vec1);
    screenQuad.setVertices(new float[] { vec0.x, vec0.y, 0, 1, 1, 1, 1, 0, 1, vec1.x, vec0.y, 0, 1, 1, 1, 1, 1, 1, vec1.x, vec1.y, 0, 1, 1, 1, 1, 1, 0, vec0.x, vec1.y, 0, 1, 1, 1, 1, 0, 0 });
    screenQuad.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh) Vector3(com.badlogic.gdx.math.Vector3)

Example 5 with Vector3

use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.

the class CharacterTest method createWorld.

@Override
public BulletWorld createWorld() {
    // We create the world using an axis sweep broadphase for this test
    btDefaultCollisionConfiguration collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher dispatcher = new btCollisionDispatcher(collisionConfiguration);
    btAxisSweep3 sweep = new btAxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
    btSequentialImpulseConstraintSolver solver = new btSequentialImpulseConstraintSolver();
    btDiscreteDynamicsWorld collisionWorld = new btDiscreteDynamicsWorld(dispatcher, sweep, solver, collisionConfiguration);
    ghostPairCallback = new btGhostPairCallback();
    sweep.getOverlappingPairCache().setInternalGhostPairCallback(ghostPairCallback);
    return new BulletWorld(collisionConfiguration, dispatcher, sweep, solver, collisionWorld);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher(com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher) com.badlogic.gdx.physics.bullet.collision.btAxisSweep3(com.badlogic.gdx.physics.bullet.collision.btAxisSweep3) com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld) com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration(com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration) Vector3(com.badlogic.gdx.math.Vector3) com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver(com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver) com.badlogic.gdx.physics.bullet.collision.btGhostPairCallback(com.badlogic.gdx.physics.bullet.collision.btGhostPairCallback)

Aggregations

Vector3 (com.badlogic.gdx.math.Vector3)64 Matrix4 (com.badlogic.gdx.math.Matrix4)10 Quaternion (com.badlogic.gdx.math.Quaternion)9 Vector2 (com.badlogic.gdx.math.Vector2)6 Node (com.badlogic.gdx.graphics.g3d.model.Node)5 Texture (com.badlogic.gdx.graphics.Texture)4 Model (com.badlogic.gdx.graphics.g3d.Model)4 NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)4 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)4 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 Material (com.badlogic.gdx.graphics.g3d.Material)3 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)3 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)3 Mesh (com.badlogic.gdx.graphics.Mesh)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)2 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)2 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)2