use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class Camera method updateMatricesForShaderUniforms.
/**
* Computes inverted and derived matrices
*/
public void updateMatricesForShaderUniforms() {
// Invert two main patrices
projectionMatrix4f.invert(projectionMatrix4fInverted);
modelViewMatrix4f.invert(modelViewMatrix4fInverted);
// Build normal matrix
Matrix4f tempMatrix = new Matrix4f();
modelViewMatrix4f.invert(tempMatrix);
tempMatrix.transpose();
normalMatrix3f.m00 = tempMatrix.m00();
normalMatrix3f.m01 = tempMatrix.m01();
normalMatrix3f.m02 = tempMatrix.m02();
normalMatrix3f.m10 = tempMatrix.m10();
normalMatrix3f.m11 = tempMatrix.m11();
normalMatrix3f.m12 = tempMatrix.m12();
normalMatrix3f.m20 = tempMatrix.m20();
normalMatrix3f.m21 = tempMatrix.m21();
normalMatrix3f.m22 = tempMatrix.m22();
// Invert it
normalMatrix3f.invert(normalMatrix3fInverted);
// Premultiplied versions ( optimization for poor drivers that don't figure it out themselves )
projectionMatrix4f.mul(modelViewMatrix4f, modelViewProjectionMatrix4f);
modelViewProjectionMatrix4f.invert(modelViewProjectionMatrix4fInverted);
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class Camera method transform3DCoordinate.
public Vector3f transform3DCoordinate(Vector4fc in) {
Matrix4f mvm = this.modelViewMatrix4f;
Matrix4f pm = this.projectionMatrix4f;
Vector4f transormed = new Vector4f();
mvm.transform(in, transormed);
pm.transform(transormed, transormed);
Vector3f posOnScreen = new Vector3f((float) in.x(), (float) in.y(), 0f);
float scale = 1 / in.z();
posOnScreen.mul(scale);
posOnScreen.x = ((posOnScreen.x() * 0.5f + 0.5f) * viewportWidth);
posOnScreen.y = (((posOnScreen.y() * 0.5f + 0.5f)) * viewportHeight);
posOnScreen.z = (scale);
return posOnScreen;
}
use of org.joml.Matrix4f in project chunkstories by Hugobros3.
the class BonedRenderer method internalRenderer.
private void internalRenderer(RenderingInterface renderingContext, SkeletonAnimator skeleton, double animationTime) {
prepareDraw(renderingContext);
Shader shader = renderingContext.currentShader();
if (skeleton != null) {
for (int i = 0; i < boneName.length; i++) {
if (skeleton.shouldHideBone(renderingContext, boneName[i])) {
Matrix4f boneMatrix = new Matrix4f();
boneMatrix.translate(50000, 50000, 50000);
shader.setUniformMatrix4f("bones[" + i + "]", boneMatrix);
} else {
Matrix4fc boneMatrix = skeleton.getBoneHierarchyTransformationMatrixWithOffset(boneName[i], animationTime < 0 ? 0 : animationTime);
shader.setUniformMatrix4f("bones[" + i + "]", boneMatrix);
}
}
}
renderingContext.draw(Primitive.TRIANGLE, 0, verticesCount);
}
use of org.joml.Matrix4f in project lwjgl3-demos by LWJGL.
the class ColoredRotatingQuadDemo method updateUbo.
private static void updateUbo(VkDevice device, UboDescriptor ubo, float angle) {
Matrix4f m = new Matrix4f().scale(1, -1, 1).rotateZ(angle);
PointerBuffer pData = memAllocPointer(1);
int err = vkMapMemory(device, ubo.memory, 0, ubo.allocationSize, 0, pData);
long data = pData.get(0);
memFree(pData);
if (err != VK_SUCCESS) {
throw new AssertionError("Failed to map UBO memory: " + translateVulkanResult(err));
}
ByteBuffer matrixBuffer = memByteBuffer(data, 16 * 4);
m.get(matrixBuffer);
vkUnmapMemory(device, ubo.memory);
}
use of org.joml.Matrix4f in project chunkstories-api by Hugobros3.
the class Quaternion4d method toMatrix4f.
public Matrix4f toMatrix4f() {
Matrix4f matrix = new Matrix4f();
double n = v.x * v.x + v.y * v.y + v.z * v.z + s * s;
double ss = (n > 0.0f) ? (2.0f / n) : 0.0f;
double xs = v.x * ss, ys = v.y * ss, zs = v.z * ss;
double wx = s * xs, wy = s * ys, wz = s * zs;
double xx = v.x * xs, xy = v.x * ys, xz = v.x * zs;
double yy = v.y * ys, yz = v.y * zs, zz = v.z * zs;
matrix.m00((float) (1.0f - (yy + zz)));
matrix.m10((float) (xy - wz));
matrix.m20((float) (xz + wy));
matrix.m01((float) (xy + wz));
matrix.m11((float) (1.0f - (xx + zz)));
matrix.m21((float) (yz - wx));
matrix.m02((float) (xz - wy));
matrix.m12((float) (yz + wx));
matrix.m22((float) (1.0f - (xx + yy)));
return matrix;
}
Aggregations