Search in sources :

Example 16 with Matrix4

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

the class PixmapBlendingTest method create.

@Override
public void create() {
    if (spriteBatch != null)
        return;
    spriteBatch = new SpriteBatch();
    Matrix4 transform = new Matrix4();
    transform.setToTranslation(0, Gdx.graphics.getHeight(), 0);
    transform.mul(new Matrix4().setToScaling(1, -1, 1));
    spriteBatch.setTransformMatrix(transform);
    pixS1 = new Pixmap(Gdx.files.getFileHandle("data/test4.png", Files.FileType.Internal));
    pixS2 = new Pixmap(Gdx.files.getFileHandle("data/test3.png", Files.FileType.Internal));
    pixD = new Pixmap(512, 1024, Pixmap.Format.RGBA8888);
    pixD.setBlending(Pixmap.Blending.SourceOver);
    pixD.setFilter(Pixmap.Filter.NearestNeighbour);
    pixD.drawPixmap(pixS1, 0, 0, 38, 76, 0, 0, 512, 1024);
    pixD.drawPixmap(pixS2, 0, 0, 38, 76, 0, 0, 512, 1024);
    logoSprite = new Sprite(new Texture(pixD));
    logoSprite.flip(false, true);
    pixS1.dispose();
    pixS2.dispose();
    pixD.dispose();
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 17 with Matrix4

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

the class CpuSpriteBatch method setTransformMatrix.

/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block,
	 * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed
	 * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by
	 * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()} or {@link #end()}. */
public void setTransformMatrix(Affine2 transform) {
    Matrix4 realMatrix = super.getTransformMatrix();
    if (checkEqual(realMatrix, transform)) {
        adjustNeeded = false;
    } else {
        virtualMatrix.setAsAffine(transform);
        if (isDrawing()) {
            adjustNeeded = true;
            if (haveIdentityRealMatrix) {
                adjustAffine.set(transform);
            } else {
                adjustAffine.set(realMatrix).inv().mul(transform);
            }
        } else {
            realMatrix.setAsAffine(transform);
            haveIdentityRealMatrix = checkIdt(realMatrix);
        }
    }
}
Also used : Matrix4(com.badlogic.gdx.math.Matrix4)

Example 18 with Matrix4

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

the class CpuSpriteBatch method setTransformMatrix.

/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block,
	 * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed
	 * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by
	 * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()}. */
@Override
public void setTransformMatrix(Matrix4 transform) {
    Matrix4 realMatrix = super.getTransformMatrix();
    if (checkEqual(realMatrix, transform)) {
        adjustNeeded = false;
    } else {
        if (isDrawing()) {
            virtualMatrix.setAsAffine(transform);
            adjustNeeded = true;
            if (haveIdentityRealMatrix) {
                adjustAffine.set(transform);
            } else {
                tmpAffine.set(transform);
                adjustAffine.set(realMatrix).inv().mul(tmpAffine);
            }
        } else {
            realMatrix.setAsAffine(transform);
            haveIdentityRealMatrix = checkIdt(realMatrix);
        }
    }
}
Also used : Matrix4(com.badlogic.gdx.math.Matrix4)

Example 19 with Matrix4

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

the class G3dModelLoader method parseNodesRecursively.

private ModelNode parseNodesRecursively(JsonValue json) {
    ModelNode jsonNode = new ModelNode();
    String id = json.getString("id", null);
    if (id == null)
        throw new GdxRuntimeException("Node id missing.");
    jsonNode.id = id;
    JsonValue translation = json.get("translation");
    if (translation != null && translation.size != 3)
        throw new GdxRuntimeException("Node translation incomplete");
    jsonNode.translation = translation == null ? null : new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2));
    JsonValue rotation = json.get("rotation");
    if (rotation != null && rotation.size != 4)
        throw new GdxRuntimeException("Node rotation incomplete");
    jsonNode.rotation = rotation == null ? null : new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3));
    JsonValue scale = json.get("scale");
    if (scale != null && scale.size != 3)
        throw new GdxRuntimeException("Node scale incomplete");
    jsonNode.scale = scale == null ? null : new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2));
    String meshId = json.getString("mesh", null);
    if (meshId != null)
        jsonNode.meshId = meshId;
    JsonValue materials = json.get("parts");
    if (materials != null) {
        jsonNode.parts = new ModelNodePart[materials.size];
        int i = 0;
        for (JsonValue material = materials.child; material != null; material = material.next, i++) {
            ModelNodePart nodePart = new ModelNodePart();
            String meshPartId = material.getString("meshpartid", null);
            String materialId = material.getString("materialid", null);
            if (meshPartId == null || materialId == null) {
                throw new GdxRuntimeException("Node " + id + " part is missing meshPartId or materialId");
            }
            nodePart.materialId = materialId;
            nodePart.meshPartId = meshPartId;
            JsonValue bones = material.get("bones");
            if (bones != null) {
                nodePart.bones = new ArrayMap<String, Matrix4>(true, bones.size, String.class, Matrix4.class);
                int j = 0;
                for (JsonValue bone = bones.child; bone != null; bone = bone.next, j++) {
                    String nodeId = bone.getString("node", null);
                    if (nodeId == null)
                        throw new GdxRuntimeException("Bone node ID missing");
                    Matrix4 transform = new Matrix4();
                    JsonValue val = bone.get("translation");
                    if (val != null && val.size >= 3)
                        transform.translate(val.getFloat(0), val.getFloat(1), val.getFloat(2));
                    val = bone.get("rotation");
                    if (val != null && val.size >= 4)
                        transform.rotate(tempQ.set(val.getFloat(0), val.getFloat(1), val.getFloat(2), val.getFloat(3)));
                    val = bone.get("scale");
                    if (val != null && val.size >= 3)
                        transform.scale(val.getFloat(0), val.getFloat(1), val.getFloat(2));
                    nodePart.bones.put(nodeId, transform);
                }
            }
            jsonNode.parts[i] = nodePart;
        }
    }
    JsonValue children = json.get("children");
    if (children != null) {
        jsonNode.children = new ModelNode[children.size];
        int i = 0;
        for (JsonValue child = children.child; child != null; child = child.next, i++) {
            jsonNode.children[i] = parseNodesRecursively(child);
        }
    }
    return jsonNode;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Quaternion(com.badlogic.gdx.math.Quaternion) JsonValue(com.badlogic.gdx.utils.JsonValue) ModelNodePart(com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart) Vector3(com.badlogic.gdx.math.Vector3) ModelNode(com.badlogic.gdx.graphics.g3d.model.data.ModelNode) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 20 with Matrix4

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

the class MatrixTest method create.

@Override
public void create() {
    font = new BitmapFont();
    batch = new SpriteBatch();
    Matrix4 m1 = new Matrix4();
    Matrix4 m2 = new Matrix4();
    float[] a1 = new float[16];
    float[] a2 = new float[16];
    float[] a3 = new float[16];
    Matrix.setIdentityM(a1, 0);
    Matrix.setIdentityM(a2, 0);
    Matrix.setIdentityM(a3, 0);
    long startTime = System.nanoTime();
    int ops = 0;
    while (System.nanoTime() - startTime < 5000000000l) {
        Matrix.multiplyMM(a1, 0, a2, 0, a3, 0);
        ops++;
    }
    results = "Matrix ops: " + ops + "\n";
    // warm up
    startTime = System.nanoTime();
    ops = 0;
    while (System.nanoTime() - startTime < 2000000000l) {
        m1.mul(m2);
        ops++;
    }
    startTime = System.nanoTime();
    ops = 0;
    while (System.nanoTime() - startTime < 5000000000l) {
        m1.mul(m2);
        ops++;
    }
    results += "Matrix4 ops: " + ops + "\n";
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) 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