Search in sources :

Example 51 with Matrix4f

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

the class BlockSelectionRenderer method renderMark2.

public void renderMark2(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);
    overlayMesh2.render();
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Camera(org.terasology.engine.rendering.cameras.Camera)

Example 52 with Matrix4f

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

the class BulletPhysics method removeRigidBody.

@Override
public boolean removeRigidBody(EntityRef entity) {
    BulletRigidBody rigidBody = entityRigidBodies.remove(entity);
    if (rigidBody != null) {
        removeRigidBody(rigidBody);
        // wake up this entities neighbors
        Matrix4f m = new Matrix4f();
        Vector3f aabbMin = new Vector3f();
        Vector3f aabbMax = new Vector3f();
        rigidBody.rb.getCollisionShape().getAabb(m, aabbMin, aabbMax);
        awakenArea(rigidBody.getLocation(new Vector3f()), (aabbMax.sub(aabbMin)).length() * .5f);
        return true;
    } else {
        logger.warn("Deleting non existing rigidBody from physics engine?! Entity: {}", entity);
        return false;
    }
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f)

Example 53 with Matrix4f

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

the class BulletPhysics method updateTrigger.

@Override
public // TODO: update if detectGroups changed
boolean updateTrigger(EntityRef entity) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    if (location == null) {
        logger.warn("Trying to update or create trigger of entity that has no LocationComponent?! Entity: {}", entity);
        return false;
    }
    btPairCachingGhostObject triggerObj = entityTriggers.get(entity);
    if (triggerObj != null) {
        float scale = location.getWorldScale();
        if (Math.abs(triggerObj.getCollisionShape().getLocalScaling().x - scale) > SIMD_EPSILON) {
            discreteDynamicsWorld.removeCollisionObject(triggerObj);
            newTrigger(entity);
        } else {
            Quaternionf worldRotation = location.getWorldRotation(new Quaternionf());
            Vector3f position = location.getWorldPosition(new Vector3f());
            if (!position.isFinite() || !worldRotation.isFinite()) {
                logger.warn("Can't update Trigger entity with a non-finite position/rotation?! Entity: {}", entity);
                return false;
            }
            triggerObj.setWorldTransform(new Matrix4f().translationRotateScale(position, worldRotation, 1.0f));
        }
        return true;
    } else {
        newTrigger(entity);
        return false;
    }
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) LocationComponent(org.terasology.engine.logic.location.LocationComponent) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject)

Example 54 with Matrix4f

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

the class BulletCollisionShape method getAABB.

@Override
public AABBf getAABB(Vector3fc origin, Quaternionfc rotation, float scale) {
    Vector3f min = new Vector3f();
    Vector3f max = new Vector3f();
    Matrix4f m = new Matrix4f();
    underlyingShape.getAabb(m, min, max);
    return new AABBf(min, max).translate(origin);
}
Also used : Matrix4f(org.joml.Matrix4f) AABBf(org.terasology.joml.geom.AABBf) Vector3f(org.joml.Vector3f)

Example 55 with Matrix4f

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

the class BulletCompoundShape method rotate.

// TODO: Add removeChildShape if needed
@Override
public CollisionShape rotate(Quaternionf rot) {
    BulletCompoundShape shape = new BulletCompoundShape();
    for (BulletCompoundShapeChild child : childList) {
        Matrix4f transform = new Matrix4f().rotate(rot).mul(child.transform);
        shape.compoundShape.addChildShape(transform, child.childShape.underlyingShape);
        shape.childList.add(new BulletCompoundShapeChild(transform, child.childShape, compoundShape.getChildShape(compoundShape.getNumChildShapes() - 1)));
    }
    return shape;
}
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