Search in sources :

Example 56 with Matrix4f

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

the class BulletPhysics method createCollider.

private btPairCachingGhostObject createCollider(Vector3f pos, btCollisionShape shape, short groups, short filters, int collisionFlags) {
    Matrix4f startTransform = new Matrix4f().translation(pos);
    btPairCachingGhostObject result = new btPairCachingGhostObject();
    result.setWorldTransform(startTransform);
    result.setCollisionShape(shape);
    result.setCollisionFlags(collisionFlags);
    discreteDynamicsWorld.addCollisionObject(result, groups, filters);
    return result;
}
Also used : Matrix4f(org.joml.Matrix4f) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject)

Example 57 with Matrix4f

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

the class BulletPhysics method awakenArea.

@Override
public void awakenArea(Vector3fc pos, float radius) {
    btPairCachingGhostObject ghost = new btPairCachingGhostObject();
    btSphereShape shape = new btSphereShape(radius);
    ghost.setCollisionShape(shape);
    ghost.setWorldTransform(new Matrix4f().translationRotateScale(pos, new Quaternionf(), 1.0f));
    discreteDynamicsWorld.addCollisionObject(ghost, (short) -1, (short) -1);
    for (int i = 0; i < ghost.getNumOverlappingObjects(); ++i) {
        btCollisionObject other = ghost.getOverlappingObject(i);
        other.activate(true);
    }
    discreteDynamicsWorld.removeCollisionObject(ghost);
}
Also used : Matrix4f(org.joml.Matrix4f) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) Quaternionf(org.joml.Quaternionf) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject) com.badlogic.gdx.physics.bullet.collision.btManifoldPoint(com.badlogic.gdx.physics.bullet.collision.btManifoldPoint) com.badlogic.gdx.physics.bullet.collision.btCollisionObject(com.badlogic.gdx.physics.bullet.collision.btCollisionObject)

Example 58 with Matrix4f

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

the class LwjglCanvasRenderer method drawMesh.

@Override
public void drawMesh(Mesh mesh, Material material, Rectanglei drawRegion, Rectanglei cropRegion, Quaternionfc rotation, Vector3fc offset, float scale, float alpha) {
    if (!material.isRenderable()) {
        return;
    }
    AABBfc meshAABB = mesh.getAABB();
    Vector3f meshExtents = meshAABB.extent(new Vector3f());
    float fitScale = 0.35f * Math.min(drawRegion.getSizeX(), drawRegion.getSizeY()) / Math.max(meshExtents.x, Math.max(meshExtents.y, meshExtents.z));
    Vector3f centerOffset = meshAABB.center(new Vector3f());
    centerOffset.mul(-1.0f);
    Matrix4f centerTransform = new Matrix4f().translationRotateScale(centerOffset, new Quaternionf(), 1);
    Matrix4f userTransform = new Matrix4f().translationRotateScale(offset, rotation, -fitScale * scale);
    Matrix4f translateTransform = new Matrix4f().translationRotateScale(new Vector3f((drawRegion.minX + drawRegion.getSizeX() / 2) * uiScale, (drawRegion.minY + drawRegion.getSizeY() / 2) * uiScale, 0), new Quaternionf(), 1);
    userTransform.mul(centerTransform);
    translateTransform.mul(userTransform);
    Matrix4f finalMat = new Matrix4f().setTranslation(0, 0, -1024f);
    finalMat.mul(translateTransform);
    material.setFloat4(CROPPING_BOUNDARIES_PARAM, cropRegion.minX * uiScale, cropRegion.maxX * uiScale, cropRegion.minY * uiScale, cropRegion.maxY * uiScale);
    glEnable(GL11.GL_DEPTH_TEST);
    glClear(GL11.GL_DEPTH_BUFFER_BIT);
    modelMatrixStack.pushMatrix();
    modelMatrixStack.set(finalMat);
    modelMatrixStack.scale(this.uiScale, this.uiScale, this.uiScale);
    material.setMatrix4("posMatrix", translateTransform);
    material.setMatrix4("projectionMatrix", projMatrix);
    material.setMatrix4("modelViewMatrix", modelMatrixStack);
    material.setMatrix3("normalMatrix", modelMatrixStack.normal(new Matrix3f()));
    material.setFloat("alpha", alpha);
    material.bindTextures();
    mesh.render();
    modelMatrixStack.popMatrix();
    glDisable(GL11.GL_DEPTH_TEST);
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Matrix4f(org.joml.Matrix4f) Matrix3f(org.joml.Matrix3f) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf)

Example 59 with Matrix4f

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

the class LwjglCanvasRenderer method preRender.

@Override
public void preRender() {
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    // TODO: figure out previous call to viewport scaling is handled
    // changing resolution scaling affect viewport of LWJGLCanvas causing strange scaling artifact.
    glViewport(0, 0, displayDevice.getWidth(), displayDevice.getHeight());
    projMatrix.setOrtho(0, displayDevice.getWidth(), displayDevice.getHeight(), 0, 0, 2048f);
    modelMatrixStack.pushMatrix();
    modelMatrixStack.set(new Matrix4f().setTranslation(0, 0, -1024));
    modelMatrixStack.scale(uiScale, uiScale, uiScale);
    requestedCropRegion = new Rectanglei(0, 0, displayDevice.getWidth(), displayDevice.getHeight());
    currentTextureCropRegion = requestedCropRegion;
    textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX, requestedCropRegion.maxX, requestedCropRegion.minY, requestedCropRegion.maxY);
}
Also used : Matrix4f(org.joml.Matrix4f) Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 60 with Matrix4f

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

the class GLTFCommonFormat method loadBones.

protected List<Bone> loadBones(GLTF gltf, GLTFSkin skin, List<byte[]> loadedBuffers) {
    List<Bone> bones = new ArrayList<>();
    TIntIntMap boneToJoint = new TIntIntHashMap();
    List<Matrix4f> inverseMats = loadInverseMats(skin.getInverseBindMatrices(), skin.getJoints().size(), gltf, loadedBuffers);
    for (int i = 0; i < skin.getJoints().size(); i++) {
        int nodeIndex = skin.getJoints().get(i);
        GLTFNode node = gltf.getNodes().get(nodeIndex);
        Vector3f position = new Vector3f();
        Quaternionf rotation = new Quaternionf();
        Vector3f scale = new Vector3f(1, 1, 1);
        if (node.getTranslation() != null) {
            position.set(node.getTranslation());
        }
        if (node.getRotation() != null) {
            rotation.set(node.getRotation());
        }
        if (node.getScale() != null) {
            scale.set(node.getScale());
        }
        String boneName = node.getName();
        if (Strings.isNullOrEmpty(boneName)) {
            boneName = "bone_" + i;
        }
        Bone bone = new Bone(i, boneName, new Matrix4f().translationRotateScale(position, rotation, scale));
        bone.setInverseBindMatrix(inverseMats.get(i));
        bones.add(bone);
        boneToJoint.put(nodeIndex, i);
    }
    for (int i = 0; i < skin.getJoints().size(); i++) {
        int nodeIndex = skin.getJoints().get(i);
        GLTFNode node = gltf.getNodes().get(nodeIndex);
        Bone bone = bones.get(i);
        TIntIterator iterator = node.getChildren().iterator();
        while (iterator.hasNext()) {
            bone.addChild(bones.get(boneToJoint.get(iterator.next())));
        }
    }
    return bones;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) Quaternionf(org.joml.Quaternionf) TIntIntMap(gnu.trove.map.TIntIntMap) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) GLTFNode(org.terasology.engine.rendering.gltf.model.GLTFNode) Bone(org.terasology.engine.rendering.assets.skeletalmesh.Bone) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

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