Search in sources :

Example 11 with Matrix4f

use of org.joml.Matrix4f in project chunkstories by Hugobros3.

the class BVHAnimation method transformBlenderBVHExportToChunkStoriesWorldSpace.

public static Matrix4f transformBlenderBVHExportToChunkStoriesWorldSpace(Matrix4f matrix) {
    // Swaps Y and Z axises arround
    Matrix4f blender2ingame = new Matrix4f();
    blender2ingame.m11(0.0f);
    blender2ingame.m22(0.0f);
    blender2ingame.m12(1.0f);
    blender2ingame.m21(1.0f);
    // Rotate the matrix first to apply the transformation in blender space
    blender2ingame.mul(matrix, matrix);
    // Mirror it
    Matrix4f mirror = new Matrix4f();
    mirror.m22(-1.0f);
    mirror.mul(matrix, matrix);
    // Rotate again after so it's back the correct way arround
    matrix.mul(blender2ingame, matrix);
    matrix.mul(mirror, matrix);
    return matrix;
}
Also used : Matrix4f(org.joml.Matrix4f)

Example 12 with Matrix4f

use of org.joml.Matrix4f in project chunkstories by Hugobros3.

the class BVHAnimation method getBoneHierarchyTransformationMatrixWithOffset.

public Matrix4f getBoneHierarchyTransformationMatrixWithOffset(String boneName, double animationTime) {
    Matrix4f matrix = null;
    if (frames == 0) {
        System.out.println("Invalid bone : " + boneName + "in animation" + this);
        return new Matrix4f();
    }
    // Get the normal bone transformation
    matrix = getBoneHierarchyTransformationMatrix(boneName, animationTime);
    // Apply the offset matrix
    matrix.mul(getOffsetMatrix(boneName));
    return matrix;
}
Also used : Matrix4f(org.joml.Matrix4f)

Example 13 with Matrix4f

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

the class LocalPlayerSystem method onTargetChanged.

@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
    EntityRef target = event.getNewTarget();
    hasTarget = target.exists();
    if (hasTarget) {
        LocationComponent location = target.getComponent(LocationComponent.class);
        if (location != null) {
            BlockComponent blockComp = target.getComponent(BlockComponent.class);
            BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
            if (blockComp != null || blockRegion != null) {
                Vector3f blockPos = location.getWorldPosition(new Vector3f());
                Block block = worldProvider.getBlock(blockPos);
                aabb.set(block.getBounds(blockPos));
            } else {
                MeshComponent mesh = target.getComponent(MeshComponent.class);
                if (mesh != null && mesh.mesh != null) {
                    aabb.set(mesh.mesh.getAABB());
                    aabb.transform(new Matrix4f().translationRotateScale(location.getWorldPosition(new Vector3f()), location.getWorldRotation(new Quaternionf()), location.getWorldScale()));
                }
            }
        }
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) MeshComponent(org.terasology.engine.rendering.logic.MeshComponent) Matrix4f(org.joml.Matrix4f) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Block(org.terasology.engine.world.block.Block) Quaternionf(org.joml.Quaternionf) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 14 with Matrix4f

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

the class SpriteParticleRenderer method renderAlphaBlend.

@Override
public void renderAlphaBlend() {
    if (!opengl33) {
        return;
    }
    PerspectiveCamera camera = (PerspectiveCamera) worldRenderer.getActiveCamera();
    Vector3f cameraPosition = camera.getPosition();
    Matrix4f viewProjection = new Matrix4f(camera.getViewProjectionMatrix()).translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);
    Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
    material.enable();
    material.setFloat3("camera_position", cameraPosition.x, cameraPosition.y, cameraPosition.z);
    material.setMatrix4("view_projection", viewProjection.get(matrixBuffer));
    particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(particleSystem -> drawParticles(material, particleSystem));
}
Also used : ParticleDataSpriteComponent(org.terasology.engine.particles.components.ParticleDataSpriteComponent) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Material(org.terasology.engine.rendering.assets.material.Material) PerspectiveCamera(org.terasology.engine.rendering.cameras.PerspectiveCamera)

Example 15 with Matrix4f

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

the class BulletSweepCallback method calculateAverageSlope.

@Override
public float calculateAverageSlope(float originalSlope, float checkingOffset) {
    Vector3f contactPoint = this.getHitPointWorld();
    float slope = 1f;
    boolean foundSlope = false;
    Vector3f fromWorld = new Vector3f(contactPoint);
    fromWorld.y += 0.2f;
    Vector3f toWorld = new Vector3f(contactPoint);
    toWorld.y -= 0.2f;
    ClosestRayResultCallback resultCallback = new ClosestRayResultCallback(fromWorld, toWorld);
    Matrix4f from = new Matrix4f().setTranslation(fromWorld);
    Matrix4f to = new Matrix4f().setTranslation(toWorld);
    Matrix4f targetTransform = this.getHitCollisionObject().getWorldTransform();
    btDiscreteDynamicsWorld.rayTestSingle(from, to, this.getHitCollisionObject(), this.getHitCollisionObject().getCollisionShape(), targetTransform, resultCallback);
    if (resultCallback.hasHit()) {
        foundSlope = true;
        Vector3f result = new Vector3f();
        resultCallback.getHitNormalWorld(result);
        slope = Math.min(slope, result.dot(0, 1, 0));
    }
    Vector3f secondTraceOffset = new Vector3f();
    this.getHitNormalWorld(secondTraceOffset);
    secondTraceOffset.y = 0;
    secondTraceOffset.normalize();
    secondTraceOffset.mul(checkingOffset);
    fromWorld.add(secondTraceOffset);
    toWorld.add(secondTraceOffset);
    resultCallback = new ClosestRayResultCallback(fromWorld, toWorld);
    from = new Matrix4f().setTranslation(fromWorld);
    to = new Matrix4f().setTranslation(toWorld);
    targetTransform = this.getHitCollisionObject().getWorldTransform();
    btDiscreteDynamicsWorld.rayTestSingle(from, to, this.getHitCollisionObject(), this.getHitCollisionObject().getCollisionShape(), targetTransform, resultCallback);
    if (resultCallback.hasHit()) {
        foundSlope = true;
        Vector3f hitNormal = new Vector3f();
        resultCallback.getHitNormalWorld(hitNormal);
        slope = Math.min(slope, hitNormal.dot(0, 1, 0));
    }
    if (!foundSlope) {
        slope = originalSlope;
    }
    resultCallback.dispose();
    return slope;
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ClosestRayResultCallback(com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)

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