Search in sources :

Example 6 with Matrix4f

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);
}
Also used : Matrix4f(org.joml.Matrix4f)

Example 7 with Matrix4f

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;
}
Also used : Matrix4f(org.joml.Matrix4f) Vector4f(org.joml.Vector4f) Vector3f(org.joml.Vector3f)

Example 8 with Matrix4f

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);
}
Also used : Matrix4fc(org.joml.Matrix4fc) Matrix4f(org.joml.Matrix4f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 9 with Matrix4f

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);
}
Also used : Matrix4f(org.joml.Matrix4f) PointerBuffer(org.lwjgl.PointerBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 10 with Matrix4f

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;
}
Also used : Matrix4f(org.joml.Matrix4f)

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