Search in sources :

Example 1 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 2 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 3 with Matrix4

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

the class ModelInstance method invalidate.

/** Makes sure that each {@link NodePart} of the {@link Node} and its sub-nodes, doesn't reference a node outside this node
	 * tree and that all materials are listed in the {@link #materials} array. */
private void invalidate(Node node) {
    for (int i = 0, n = node.parts.size; i < n; ++i) {
        NodePart part = node.parts.get(i);
        ArrayMap<Node, Matrix4> bindPose = part.invBoneBindTransforms;
        if (bindPose != null) {
            for (int j = 0; j < bindPose.size; ++j) {
                bindPose.keys[j] = getNode(bindPose.keys[j].id);
            }
        }
        if (!materials.contains(part.material, true)) {
            final int midx = materials.indexOf(part.material, false);
            if (midx < 0)
                materials.add(part.material = part.material.copy());
            else
                part.material = materials.get(midx);
        }
    }
    for (int i = 0, n = node.getChildCount(); i < n; ++i) {
        invalidate(node.getChild(i));
    }
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 4 with Matrix4

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

the class SplitPane method draw.

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();
    Color color = getColor();
    Drawable handle = style.handle;
    applyTransform(batch, computeTransform());
    Matrix4 transform = batch.getTransformMatrix();
    if (firstWidget != null) {
        batch.flush();
        getStage().calculateScissors(firstWidgetBounds, firstScissors);
        if (ScissorStack.pushScissors(firstScissors)) {
            if (firstWidget.isVisible())
                firstWidget.draw(batch, parentAlpha * color.a);
            batch.flush();
            ScissorStack.popScissors();
        }
    }
    if (secondWidget != null) {
        batch.flush();
        getStage().calculateScissors(secondWidgetBounds, secondScissors);
        if (ScissorStack.pushScissors(secondScissors)) {
            if (secondWidget.isVisible())
                secondWidget.draw(batch, parentAlpha * color.a);
            batch.flush();
            ScissorStack.popScissors();
        }
    }
    batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
    handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
    resetTransform(batch);
}
Also used : Color(com.badlogic.gdx.graphics.Color) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 5 with Matrix4

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

the class MatrixJNITest method bench.

private void bench() {
    Matrix4 mata = new Matrix4();
    Matrix4 matb = new Matrix4();
    long start = TimeUtils.nanoTime();
    for (int i = 0; i < 1000000; i++) {
        mata.mul(matb);
    }
    Gdx.app.log("MatrixJNITest", "java matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    start = TimeUtils.nanoTime();
    for (int i = 0; i < 1000000; i++) {
        Matrix4.mul(mata.val, matb.val);
    }
    Gdx.app.log("MatrixJNITest", "jni matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    Vector3 vec = new Vector3();
    start = TimeUtils.nanoTime();
    for (int i = 0; i < 500000; i++) {
        vec.mul(mata);
    }
    Gdx.app.log("MatrixJNITest", "java vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    float[] fvec = new float[3];
    start = TimeUtils.nanoTime();
    for (int i = 0; i < 500000; i++) {
        Matrix4.mulVec(mata.val, fvec);
    }
    Gdx.app.log("MatrixJNITest", "jni vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    float[] fvecs = new float[3 * 500000];
    start = TimeUtils.nanoTime();
    Matrix4.mulVec(mata.val, fvecs, 0, 500000, 3);
    Gdx.app.log("MatrixJNITest", "jni bulk vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    start = TimeUtils.nanoTime();
    for (int i = 0; i < 1000000; i++) {
        mata.inv();
    }
    Gdx.app.log("MatrixJNITest", "java inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    start = TimeUtils.nanoTime();
    for (int i = 0; i < 1000000; i++) {
        Matrix4.inv(mata.val);
    }
    Gdx.app.log("MatrixJNITest", "jni inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
}
Also used : Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Aggregations

Matrix4 (com.badlogic.gdx.math.Matrix4)40 Vector3 (com.badlogic.gdx.math.Vector3)10 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)6 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 Batch (com.badlogic.gdx.graphics.g2d.Batch)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 Group (com.badlogic.gdx.scenes.scene2d.Group)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2