Search in sources :

Example 81 with Vector3f

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

the class TelemetrySystem method recordDistanceTraveled.

private void recordDistanceTraveled() {
    Vector3f position = localPlayer.getPosition(new Vector3f());
    float distanceMoved = position.distance(previousPos);
    gamePlayStatsComponent.distanceTraveled += distanceMoved;
    previousPos.set(position);
    localPlayer.getCharacterEntity().addOrSaveComponent(gamePlayStatsComponent);
}
Also used : Vector3f(org.joml.Vector3f)

Example 82 with Vector3f

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

the class BlockSelectionRenderer method buildBlockMesh.

private static void buildBlockMesh(StandardMeshData mesh, float size, Rectanglef texRect, Colorc c) {
    Vector3f pos = new Vector3f();
    Vector3f norm = new Vector3f();
    Vector2f texCoord = new Vector2f();
    final float sizeHalf = size / 2;
    int firstIndex = mesh.position.getPosition();
    // top
    mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, -sizeHalf));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
    for (int i = 0; i < 4; i++) {
        mesh.normal.put(norm.set(0, 1.0f, 0));
        mesh.color0.put(c);
    }
    // left
    mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, -sizeHalf));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.minY, texRect.minY));
    for (int i = 0; i < 4; i++) {
        mesh.normal.put(norm.set(-1.0f, 0, 0));
        mesh.color0.put(c);
    }
    // right
    mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, -sizeHalf));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
    for (int i = 0; i < 4; i++) {
        mesh.normal.put(norm.set(1.0f, 0, 0));
        mesh.color0.put(c);
    }
    // back
    mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, -sizeHalf));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
    for (int i = 0; i < 4; i++) {
        mesh.normal.put(norm.set(0, 0, -1.0f));
        mesh.color0.put(c);
    }
    // front
    mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, sizeHalf));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.minY, texRect.minY));
    for (int i = 0; i < 4; i++) {
        mesh.normal.put(norm.set(0, 0, 1.0f));
        mesh.color0.put(c);
    }
    // bottom
    mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, -sizeHalf));
    mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, sizeHalf));
    mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, sizeHalf));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
    mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
    mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
    for (int i = 0; i < 4; i++) {
        mesh.normal.put(norm.set(0, -1, 0f));
        mesh.color0.put(c);
    }
    int lastIndex = mesh.position.getPosition();
    for (int i = firstIndex; i < lastIndex - 2; i += 4) {
        mesh.indices.put(i);
        mesh.indices.put(i + 1);
        mesh.indices.put(i + 2);
        mesh.indices.put(i + 2);
        mesh.indices.put(i + 3);
        mesh.indices.put(i);
    }
}
Also used : Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f)

Example 83 with Vector3f

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

the class TessellatorHelper method addGUIQuadMesh.

public static void addGUIQuadMesh(Tessellator tessellator, Vector4f color, float sizeX, float sizeY) {
    tessellator.resetParams();
    tessellator.setColor(new Vector4f(color.x, color.y, color.z, color.w));
    tessellator.setUseLighting(false);
    tessellator.setUseNormals(false);
    tessellator.addPoly(new Vector3f[] { new Vector3f(0, 0, 0), new Vector3f(sizeX, 0, 0), new Vector3f(sizeX, sizeY, 0), new Vector3f(0, sizeY, 0) }, new Vector2f[] { new Vector2f(0, 0), new Vector2f(1, 0), new Vector2f(1, 1), new Vector2f(0, 1) });
    tessellator.setUseLighting(true);
    tessellator.setUseNormals(true);
}
Also used : Vector4f(org.joml.Vector4f) Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f)

Example 84 with Vector3f

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

the class NetClient method sendNewChunks.

private void sendNewChunks(NetData.NetMessage.Builder message) {
    if (!readyChunks.isEmpty()) {
        chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
        if (chunkSendCounter > 1.0f) {
            chunkSendCounter -= 1.0f;
            Vector3i center = new Vector3i();
            LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
            if (loc != null) {
                Vector3f target = loc.getWorldPosition(new Vector3f());
                if (target.isFinite()) {
                    // use center as temporary variable
                    center.set(target, RoundingMode.HALF_UP);
                    // update center to chunkPos
                    Chunks.toChunkPos(center, center);
                }
            }
            Vector3i pos = null;
            long distance = Integer.MAX_VALUE;
            for (Vector3i chunkPos : readyChunks.keySet()) {
                long chunkDistance = chunkPos.distanceSquared(center);
                if (pos == null || chunkDistance < distance) {
                    pos = chunkPos;
                    distance = chunkDistance;
                }
            }
            Chunk chunk = readyChunks.remove(pos);
            relevantChunks.add(pos);
            message.addChunkInfo(chunk.encode());
        }
    } else {
        chunkSendCounter = 1.0f;
    }
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 85 with Vector3f

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

the class Bone method getLocalPosition.

public Vector3f getLocalPosition() {
    Vector3f result = new Vector3f();
    relativeTransform.transformPosition(result);
    return result;
}
Also used : Vector3f(org.joml.Vector3f)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8