use of org.joml.Matrix4f in project chunkstories-api by Hugobros3.
the class CompoundAnimationHelper method getBoneHierarchyTransformationMatrixWithOffset.
/**
* Used to draw mesh parts in OpenGL
*/
public Matrix4fc getBoneHierarchyTransformationMatrixWithOffset(String nameOfEndBone, double animationTime) {
Matrix4f matrix = new Matrix4f(getBoneHierarchyTransformationMatrix(nameOfEndBone, animationTime));
// Apply the offset matrix
matrix.mul(getBoneHierarchyMeshOffsetMatrix(nameOfEndBone, animationTime));
return matrix;
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class ChunkMeshesRenderer method renderChunks.
@Override
public void renderChunks(RenderingInterface renderingInterface) {
RenderPass currentPass = renderingInterface.getCurrentPass();
List<ChunkRenderCommand> culledChunks = currentPass.name.startsWith("shadow") ? culledChunksShadow : culledChunksNormal;
ShadingType shadingType = currentPass.name.startsWith("water") ? ShadingType.LIQUIDS : ShadingType.OPAQUE;
if (currentPass.name.startsWith("shadow"))
renderingInterface.currentShader().setUniform1f("useVoxelCoordinates", 1f);
Matrix4f matrix = new Matrix4f();
for (ChunkRenderCommand command : culledChunks) {
matrix.identity();
matrix.translate(new Vector3f(command.displayWorldX, command.displayWorldY, command.displayWorldZ));
renderingInterface.setObjectMatrix(matrix);
Vector3d chunkPos = new Vector3d(command.displayWorldX + 16, command.displayWorldY + 16, command.displayWorldZ + 16);
double distance = renderingInterface.getCamera().getCameraPosition().distance(chunkPos);
RenderLodLevel lodToUse;
lodToUse = distance < Math.max(64, world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance") / 4.0) ? RenderLodLevel.HIGH : RenderLodLevel.LOW;
((ClientChunk) command.chunk).getChunkRenderData().renderPass(renderingInterface, lodToUse, shadingType);
}
if (currentPass.name.startsWith("shadow"))
renderingInterface.currentShader().setUniform1f("useVoxelCoordinates", 0f);
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class TrianglesClipper method clipTriangles.
public static synchronized int clipTriangles(ByteBuffer in, ByteBuffer out, Matrix4f rotationMatrix, Vector3dc originPosition, Vector3fc direction, Vector3dc size) {
int actualCount = 0;
toClipSpace = new Matrix4f(rotationMatrix);
toClipSpace.translate(new Vector3f((float) originPosition.x(), (float) originPosition.y(), (float) originPosition.z()).negate());
Matrix4f resize = new Matrix4f();
resize.scale(new Vector3f(1f / (float) size.x(), 1f / (float) size.y(), 1));
resize.transpose();
resize.mul(toClipSpace, toClipSpace);
Matrix4f decal = new Matrix4f();
decal.translate(new Vector3f(0.5f, 0.5f, 1.0f));
decal.mul(toClipSpace, toClipSpace);
fromClipSpace = new Matrix4f();
toClipSpace.invert(fromClipSpace);
TrianglesClipper.out = out;
while (in.hasRemaining()) {
Vector3f triVert1 = new Vector3f(in.getFloat(), in.getFloat(), in.getFloat());
// Skip backward-facing tris
Vector3f normal = new Vector3f(in.getFloat(), in.getFloat(), in.getFloat());
if (normal.dot(direction) >= 0) {
for (int i = 0; i < 12; i++) in.getFloat();
continue;
}
Vector3f triVert2 = new Vector3f(in.getFloat(), in.getFloat(), in.getFloat());
// Etc
for (int i = 0; i < 3; i++) in.getFloat();
Vector3f triVert3 = new Vector3f(in.getFloat(), in.getFloat(), in.getFloat());
// Etc
for (int i = 0; i < 3; i++) in.getFloat();
actualCount += 3 * cull(triVert1, triVert2, triVert3);
}
return actualCount;
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class BVHAnimation method getOffsetMatrix.
public Matrix4f getOffsetMatrix(String boneName) {
Matrix4f offsetMatrix = new Matrix4f();
Vector3f offsetTotal = new Vector3f();
BVHTreeBone bone = getBone(boneName);
// Accumulate the transformation offset
BVHTreeBone loop = bone;
while (loop != null) {
// Swap yz arround and negate input Y to apply blender -> ingame coordinates system transformation
offsetTotal.x = (offsetTotal.x() + loop.offset.x());
offsetTotal.y = (offsetTotal.y() + loop.offset.z());
offsetTotal.z = (offsetTotal.z() + -loop.offset.y());
loop = loop.parent;
}
// Negate it and build the offset matrix
offsetTotal.negate();
offsetMatrix.m30(offsetMatrix.m30() + offsetTotal.x());
offsetMatrix.m31(offsetMatrix.m31() + offsetTotal.y());
offsetMatrix.m32(offsetMatrix.m32() + offsetTotal.z());
return offsetMatrix;
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class BVHAnimation method main.
public static void main(String[] a) throws FileNotFoundException {
BVHAnimation test = new BVHAnimation(new FileInputStream(new File("res/animations/human/human.bvh")));
System.out.println(test.toString());
float rotX = (float) (Math.random() * 2.0 * Math.PI);
float rotY = (float) (Math.random() * 2.0 * Math.PI);
float rotZ = (float) (Math.random() * 2.0 * Math.PI);
Quaternion4d quaternionXLower = Quaternion4d.fromAxisAngle(new Vector3d(1.0, 0.0, 0.0), rotX);
Quaternion4d quaternionYLower = Quaternion4d.fromAxisAngle(new Vector3d(0.0, 1.0, 0.0), rotY);
Quaternion4d quaternionZLower = Quaternion4d.fromAxisAngle(new Vector3d(0.0, 0.0, 1.0), rotZ);
Quaternion4d total = new Quaternion4d(quaternionXLower);
total = total.mult(quaternionYLower);
total.normalize();
total = total.mult(quaternionZLower);
Matrix4f matrix = new Matrix4f();
// Apply rotations
matrix.rotate(rotX, new Vector3f(1, 0, 0));
matrix.rotate(rotY, new Vector3f(0, 1, 0));
matrix.rotate(rotZ, new Vector3f(0, 0, 1));
Matrix4f mX = new Matrix4f();
Matrix4f mY = new Matrix4f();
Matrix4f mZ = new Matrix4f();
mX.rotate(rotX, new Vector3f(1, 0, 0));
mY.rotate(rotY, new Vector3f(0, 1, 0));
mZ.rotate(rotZ, new Vector3f(0, 0, 1));
/*System.out.println("Old:\n"+matrix);
System.out.println("New:\n"+Matrix4f.mul(Matrix4f.mul(mX, mY, null), mZ, null));
System.out.println("mX:\n"+mX);
System.out.println("mY:\n"+mY);
System.out.println("mZ:\n"+mZ);*/
// System.out.println(quaternionXLower);
// System.out.println(quaternionYLower);
// System.out.println(quaternionZLower);
mX = Quaternion4d.fromAxisAngle(new Vector3d(1.0, 0.0, 0.0), rotX).toMatrix4f();
mY = Quaternion4d.fromAxisAngle(new Vector3d(0.0, 1.0, 0.0), rotY).toMatrix4f();
mZ = Quaternion4d.fromAxisAngle(new Vector3d(0.0, 0.0, 1.0), rotZ).toMatrix4f();
// System.out.println("Old:\n"+matrix);
// System.out.println("New:\n"+Matrix4f.mul(Matrix4f.mul(mX, mY, null), mZ, null));
// System.out.println("mX:\n"+mX);
// System.out.println("mY:\n"+mY);
// System.out.println("mZ:\n"+mZ);
// total = Matrix4f.invert(total, null);
// System.out.println("Qml:\n"+total.toMatrix4f());
// System.out.println("Inv:\n"+Matrix4f.invert(total.toMatrix4f(), null));
// Swaps Y and Z axises arround
// matrix = new Matrix4f();
System.out.println(matrix);
System.out.println("");
Matrix4f blender2ingame = new Matrix4f();
blender2ingame.m11(0);
blender2ingame.m22(0);
blender2ingame.m12(1);
blender2ingame.m21(1);
// Rotate the matrix first to apply the transformation in blender space
blender2ingame.mul(matrix, matrix);
// Matrix4f.mul(blender2ingame, matrix, matrix);
// Mirror it
Matrix4f mirror = new Matrix4f();
mirror.m22(-1);
mirror.mul(matrix, matrix);
// Matrix4f.mul(mirror, matrix, matrix);
// Rotate again after so it's back the correct way arround
matrix.mul(blender2ingame);
// Matrix4f.mul(matrix, blender2ingame, matrix);
matrix.mul(mirror);
// Matrix4f.mul(matrix, mirror, matrix);
System.out.println(matrix);
}
Aggregations