Search in sources :

Example 11 with Matrix4

use of com.badlogic.gdx.math.Matrix4 in project commons-gdx by gemserk.

the class ImmediateModeRendererUtils method getProjectionMatrix.

public static Matrix4 getProjectionMatrix() {
    if (projectionMatrix == null) {
        projectionMatrix = new Matrix4();
        // don't like the Gdx.graphics here
        projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }
    return projectionMatrix;
}
Also used : Matrix4(com.badlogic.gdx.math.Matrix4)

Example 12 with Matrix4

use of com.badlogic.gdx.math.Matrix4 in project nhglib by VoidZombie.

the class TiledForwardShader method cullSpotLight.

private void cullSpotLight(NhgLight light) {
    Matrix4 a = MatrixPool.getMatrix4();
    a.setToTranslation(light.position);
    Matrix4 b = MatrixPool.getMatrix4();
    b.set(a).translate(new Vector3(light.direction).scl(light.radius));
    Vector3 p1 = VectorPool.getVector3();
    Vector3 p2 = VectorPool.getVector3();
    Vector3 m = VectorPool.getVector3();
    a.getTranslation(p1);
    b.getTranslation(p2);
    m.set(p1).add(p2).scl(0.5f);
    float radius = p1.dst(p2) * 0.5f;
    if (camera.frustum.sphereInFrustum(m, radius)) {
        lightsToRender.add(light);
    }
    VectorPool.freeVector3(p1, p2, m);
    MatrixPool.freeMatrix4(a, b);
}
Also used : Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 13 with Matrix4

use of com.badlogic.gdx.math.Matrix4 in project nhglib by VoidZombie.

the class PhysicsSystem method process.

@Override
protected void process(int entityId) {
    NodeComponent nodeComponent = nodeMapper.get(entityId);
    RigidBodyComponent bodyComponent = rigidBodyMapper.get(entityId);
    if (!bodyComponent.isAdded()) {
        Matrix4 initialTransform = new Matrix4();
        Vector3 trn = nodeComponent.getTranslation();
        Vector3 scl = new Vector3(1, 1, 1);
        Quaternion rtn = nodeComponent.getRotationQuaternion();
        initialTransform.set(trn, rtn, scl);
        bodyComponent.addToWorld(dynamicsWorld, initialTransform);
    } else {
        nodeComponent.setTranslation(bodyComponent.getTranslation());
        nodeComponent.setRotation(bodyComponent.getRotation());
        nodeComponent.applyTransforms();
    }
}
Also used : RigidBodyComponent(io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent) Quaternion(com.badlogic.gdx.math.Quaternion) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 14 with Matrix4

use of com.badlogic.gdx.math.Matrix4 in project bdx by GoranM.

the class GameObject method scale.

public void scale(float x, float y, float z, boolean updateLocal) {
    activate();
    // Set unit scale
    Matrix4 t = modelInstance.transform;
    Matrix4 mat_scale = new Matrix4();
    Vector3 s = new Vector3();
    t.getScale(s);
    mat_scale.scl(1 / s.x, 1 / s.y, 1 / s.z);
    t.mul(mat_scale);
    scale.set(x, y, z);
    // Set target scale
    mat_scale.idt();
    mat_scale.scl(x, y, z);
    t.mul(mat_scale);
    // Relevant bullet body update
    CollisionShape cs = body.getCollisionShape();
    cs.setLocalScaling(new Vector3f(x, y, z));
    if (body.isInWorld() && body.isStaticOrKinematicObject())
        scene.world.updateSingleAabb(body);
    // Child propagation
    Vector3f ps = scale();
    Matrix4f pt = transform();
    Matrix4f ct = new Matrix4f();
    Matrix4f ms = new Matrix4f();
    ms.setIdentity();
    ms.m00 = ps.x;
    ms.m11 = ps.y;
    ms.m22 = ps.z;
    pt.mul(ms);
    for (GameObject c : children) {
        c.scale(scale().mul(c.localScale), false);
        ct.mul(pt, c.localTransform);
        c.transform(ct, false);
    }
    if (parent != null && updateLocal) {
        updateLocalScale();
    }
}
Also used : Matrix4f(javax.vecmath.Matrix4f) CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) Vector3f(javax.vecmath.Vector3f) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 15 with Matrix4

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

the class ArrowShapeBuilder method build.

/** Build an arrow
	 * @param x1 source x
	 * @param y1 source y
	 * @param z1 source z
	 * @param x2 destination x
	 * @param y2 destination y
	 * @param z2 destination z
	 * @param capLength is the height of the cap in percentage, must be in (0,1)
	 * @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1]
	 * @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */
public static void build(MeshPartBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions) {
    Vector3 begin = obtainV3().set(x1, y1, z1), end = obtainV3().set(x2, y2, z2);
    float length = begin.dst(end);
    float coneHeight = length * capLength;
    float coneDiameter = 2 * (float) (coneHeight * Math.sqrt(1f / 3));
    float stemLength = length - coneHeight;
    float stemDiameter = coneDiameter * stemThickness;
    Vector3 up = obtainV3().set(end).sub(begin).nor();
    Vector3 forward = obtainV3().set(up).crs(Vector3.Z);
    if (forward.isZero())
        forward.set(Vector3.X);
    forward.crs(up).nor();
    Vector3 left = obtainV3().set(up).crs(forward).nor();
    Vector3 direction = obtainV3().set(end).sub(begin).nor();
    // Matrices
    Matrix4 userTransform = builder.getVertexTransform(obtainM4());
    Matrix4 transform = obtainM4();
    float[] val = transform.val;
    val[Matrix4.M00] = left.x;
    val[Matrix4.M01] = up.x;
    val[Matrix4.M02] = forward.x;
    val[Matrix4.M10] = left.y;
    val[Matrix4.M11] = up.y;
    val[Matrix4.M12] = forward.y;
    val[Matrix4.M20] = left.z;
    val[Matrix4.M21] = up.z;
    val[Matrix4.M22] = forward.z;
    Matrix4 temp = obtainM4();
    // Stem
    transform.setTranslation(obtainV3().set(direction).scl(stemLength / 2).add(x1, y1, z1));
    builder.setVertexTransform(temp.set(transform).mul(userTransform));
    CylinderShapeBuilder.build(builder, stemDiameter, stemLength, stemDiameter, divisions);
    // Cap
    transform.setTranslation(obtainV3().set(direction).scl(stemLength).add(x1, y1, z1));
    builder.setVertexTransform(temp.set(transform).mul(userTransform));
    ConeShapeBuilder.build(builder, coneDiameter, coneHeight, coneDiameter, divisions);
    builder.setVertexTransform(userTransform);
    freeAll();
}
Also used : Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Aggregations

Matrix4 (com.badlogic.gdx.math.Matrix4)31 Vector3 (com.badlogic.gdx.math.Vector3)10 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)5 Texture (com.badlogic.gdx.graphics.Texture)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)3 Material (com.badlogic.gdx.graphics.g3d.Material)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 Quaternion (com.badlogic.gdx.math.Quaternion)3 JsonValue (com.badlogic.gdx.utils.JsonValue)3 InputAdapter (com.badlogic.gdx.InputAdapter)2 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)2 Environment (com.badlogic.gdx.graphics.g3d.Environment)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape (com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape)2 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 NodeComponent (io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)2 ArrayList (java.util.ArrayList)2