Search in sources :

Example 61 with Matrix4f

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

the class FloatingTextRenderer method render.

private void render(Iterable<EntityRef> floatingTextEntities) {
    Vector3fc cameraPosition = camera.getPosition();
    Matrix4f model = new Matrix4f();
    Matrix4f modelView = new Matrix4f();
    Vector3f worldPos = new Vector3f();
    for (EntityRef entity : floatingTextEntities) {
        FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
        LocationComponent location = entity.getComponent(LocationComponent.class);
        if (location == null) {
            logger.warn("location component is not defined can't render text: {}", floatingText.text);
            continue;
        }
        location.getWorldPosition(worldPos);
        if (!worldProvider.isBlockRelevant(worldPos) || !worldPos.isFinite()) {
            continue;
        }
        String[] linesOfText = floatingText.text.split("\n");
        Color baseColor = floatingText.textColor;
        Color shadowColor = floatingText.textShadowColor;
        boolean underline = false;
        int textWidth = 0;
        for (String singleLine : linesOfText) {
            if (font.getWidth(singleLine) > textWidth) {
                textWidth = font.getWidth(singleLine);
            }
        }
        FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
        Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
        if (meshMap == null) {
            meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
            entityMeshCache.put(entity, meshMap);
        }
        if (floatingText.isOverlay) {
            glDisable(GL_DEPTH_TEST);
        }
        float scale = METER_PER_PIXEL * floatingText.scale;
        model.setTranslation(worldPos.sub(cameraPosition));
        modelView.set(camera.getViewMatrix()).mul(model).m00(1.0f).m10(0.0f).m20(0.0f).m01(0.0f).m11(1.0f).m21(0.0f).m02(0.0f).m12(0.0f).m22(1.0f);
        modelView.scale(scale, -scale, scale);
        modelView.translate(-textWidth / 2.0f, 0.0f, 0.0f);
        for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
            Mesh mesh = meshMapEntry.getValue();
            Material material = meshMapEntry.getKey();
            material.enable();
            material.bindTextures();
            material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
            material.setMatrix4("modelViewMatrix", modelView);
            material.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
            material.setFloat2("offset", 0.0f, 0.0f);
            material.setFloat("alpha", 1.0f);
            mesh.render();
        }
        // Revert to default state
        if (floatingText.isOverlay) {
            glEnable(GL_DEPTH_TEST);
        }
    }
}
Also used : Color(org.terasology.nui.Color) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) Material(org.terasology.engine.rendering.assets.material.Material) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Vector3fc(org.joml.Vector3fc) Matrix4f(org.joml.Matrix4f) FontMeshBuilder(org.terasology.engine.rendering.assets.font.FontMeshBuilder) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Map(java.util.Map)

Example 62 with Matrix4f

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

the class FirstPersonHeldItemMountPointComponent method copyFrom.

@Override
public void copyFrom(FirstPersonHeldItemMountPointComponent other) {
    this.mountPointEntity = other.mountPointEntity;
    this.rotateDegrees = new Vector3f(other.rotateDegrees);
    this.translate = new Vector3f(other.translate);
    this.rotationQuaternion = new Quaternionf(other.rotationQuaternion);
    this.scale = other.scale;
    this.trackingDataReceived = other.trackingDataReceived;
    this.toolAdjustmentMatrix = new Matrix4f(other.toolAdjustmentMatrix);
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf)

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