Search in sources :

Example 11 with Vector3

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

the class MatrixJNITest method create.

@Override
public void create() {
    Matrix4 mat1 = new Matrix4();
    Matrix4 mat2 = new Matrix4();
    Matrix4 mat3 = new Matrix4();
    Vector3 vec = new Vector3(1, 2, 3);
    float[] fvec = { 1, 2, 3 };
    float[] fvecs = { 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0 };
    mat1.setToRotation(0, 1, 0, 45);
    mat2.setToRotation(1, 0, 0, 45);
    vec.mul(mat1);
    Matrix4.mulVec(mat1.val, fvec);
    Matrix4.mulVec(mat1.val, fvecs, 0, 3, 5);
    check(vec, fvec);
    check(vec, fvecs, 3, 5);
    vec.prj(mat1);
    Matrix4.prj(mat1.val, fvec);
    Matrix4.prj(mat1.val, fvecs, 0, 3, 5);
    check(vec, fvec);
    check(vec, fvecs, 3, 5);
    vec.rot(mat1);
    Matrix4.rot(mat1.val, fvec);
    Matrix4.rot(mat1.val, fvecs, 0, 3, 5);
    check(vec, fvec);
    check(vec, fvecs, 3, 5);
    if (mat1.det() != Matrix4.det(mat1.val))
        throw new GdxRuntimeException("det doesn't work");
    mat2.set(mat1);
    mat1.inv();
    Matrix4.inv(mat2.val);
    check(mat1, mat2);
    mat3.set(mat1);
    mat1.mul(mat2);
    Matrix4.mul(mat3.val, mat2.val);
    check(mat1, mat3);
    bench();
    System.out.println("All tests passed.");
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 12 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 13 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 14 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)

Example 15 with Vector3

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

the class BulletConstructor method create.

private void create(final Model model, final float mass, final btCollisionShape shape) {
    this.model = model;
    this.shape = shape;
    if (shape != null && mass >= 0) {
        // Calculate the local inertia, bodies with no mass are static
        Vector3 localInertia;
        if (mass == 0)
            localInertia = Vector3.Zero;
        else {
            shape.calculateLocalInertia(mass, tmpV);
            localInertia = tmpV;
        }
        // For now just pass null as the motionstate, we'll add that to the body in the entity itself
        bodyInfo = new btRigidBodyConstructionInfo(mass, null, shape, localInertia);
    }
}
Also used : Vector3(com.badlogic.gdx.math.Vector3) com.badlogic.gdx.physics.bullet.dynamics.btRigidBody.btRigidBodyConstructionInfo(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody.btRigidBodyConstructionInfo)

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