Search in sources :

Example 46 with Matrix4f

use of org.joml.Matrix4f in project Terasology by MovingBlocks.

the class GLTFMeshFormat method getMatrix.

private Matrix4f getMatrix(GLTF gltf, int nodeIndex) {
    Matrix4f transform = new Matrix4f();
    if (nodeIndex != -1) {
        GLTFNode node = gltf.getNodes().get(nodeIndex);
        if (node.getMatrix() == null) {
            Vector3f position = new Vector3f();
            Quaternionf rotation = new Quaternionf();
            Vector3f scale = new Vector3f(1, 1, 1);
            if (node.getTranslation() != null) {
                position.set(node.getTranslation());
            }
            if (node.getRotation() != null) {
                rotation.set(node.getRotation());
            }
            if (node.getScale() != null) {
                scale.set(node.getScale());
            }
            transform.translationRotateScale(position, rotation, scale);
        } else {
            transform.set(node.getMatrix());
        }
        int parentNodeIndex = getParentNode(gltf, nodeIndex);
        Matrix4f parentTransform = getMatrix(gltf, parentNodeIndex);
        // Must be multiplied in the right order
        parentTransform.mul(transform);
        transform.set(parentTransform);
    }
    return transform;
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) GLTFNode(org.terasology.engine.rendering.gltf.model.GLTFNode)

Example 47 with Matrix4f

use of org.joml.Matrix4f in project Terasology by MovingBlocks.

the class GLTFMeshFormat method applyTransformations.

private void applyTransformations(GLTF gltf, TFloatList vertices, TFloatList normals) {
    int nodeIndex = -1;
    for (int i = 0; i < gltf.getNodes().size(); i++) {
        if (gltf.getNodes().get(i).getMesh() == 0) {
            nodeIndex = i;
            break;
        }
    }
    Matrix4f transform = getMatrix(gltf, nodeIndex);
    applyTransformations(vertices, transform, false);
    transform.setTranslation(new Vector3f());
    applyTransformations(normals, transform, true);
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f)

Example 48 with Matrix4f

use of org.joml.Matrix4f in project Terasology by MovingBlocks.

the class Matrix4fDeserializer method deserialize.

@Override
public Matrix4f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    TFloatList result = new TFloatArrayList();
    json.getAsJsonArray().forEach(x -> result.add(x.getAsFloat()));
    if (result.size() != 16) {
        throw new JsonParseException("Incorrect number of values for ImmutableMatrix4f - expected 16");
    }
    return new Matrix4f(result.get(0), result.get(1), result.get(2), result.get(3), result.get(4), result.get(5), result.get(6), result.get(7), result.get(8), result.get(9), result.get(10), result.get(11), result.get(12), result.get(13), result.get(14), result.get(15));
}
Also used : Matrix4f(org.joml.Matrix4f) TFloatList(gnu.trove.list.TFloatList) JsonParseException(com.google.gson.JsonParseException) TFloatArrayList(gnu.trove.list.array.TFloatArrayList)

Example 49 with Matrix4f

use of org.joml.Matrix4f in project Terasology by MovingBlocks.

the class OpenVRState method getEyePose.

/**
 * Get the pose of an eye.
 * @param eyeIndex - An integer specifying the eye: 0 for the left eye, 1 for the right eye.
 * @return the pose, as a Matrix4f
 */
public Matrix4f getEyePose(int eyeIndex) {
    Matrix4f matrixReturn = new Matrix4f(headPose);
    matrixReturn.mul(eyePoses[eyeIndex]);
    return matrixReturn;
}
Also used : Matrix4f(org.joml.Matrix4f)

Example 50 with Matrix4f

use of org.joml.Matrix4f in project Terasology by MovingBlocks.

the class BlockSelectionRenderer method renderMark.

public void renderMark(Vector3ic blockPos) {
    Camera camera = worldRenderer.getActiveCamera();
    final Vector3f cameraPosition = camera.getPosition();
    Matrix4f modelView = new Matrix4f();
    modelView.set(camera.getViewMatrix()).mul(new Matrix4f().setTranslation(blockPos.x() - cameraPosition.x, blockPos.y() - cameraPosition.y, blockPos.z() - cameraPosition.z));
    blockSelectionMat.setMatrix4("modelViewMatrix", modelView);
    overlayMesh.render();
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Camera(org.terasology.engine.rendering.cameras.Camera)

Aggregations

Matrix4f (org.joml.Matrix4f)62 Vector3f (org.joml.Vector3f)34 Quaternionf (org.joml.Quaternionf)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)7 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)5 Vector3d (org.joml.Vector3d)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 Shader (io.xol.chunkstories.api.rendering.shader.Shader)4 AABBf (org.terasology.joml.geom.AABBf)4 com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject (com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject)3 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)3 Location (io.xol.chunkstories.api.Location)3 GameWindow (io.xol.chunkstories.api.rendering.GameWindow)3 ByteBuffer (java.nio.ByteBuffer)3 Matrix3f (org.joml.Matrix3f)3 Vector4f (org.joml.Vector4f)3 PointerBuffer (org.lwjgl.PointerBuffer)3 Camera (org.terasology.engine.rendering.cameras.Camera)3 ClosestRayResultCallback (com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)2 TFloatList (gnu.trove.list.TFloatList)2