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;
}
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);
}
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));
}
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;
}
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();
}
Aggregations