Search in sources :

Example 1 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class DebugOverlay method initialise.

@Override
public void initialise() {
    bindVisible(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return config.getSystem().isDebugEnabled();
        }
    });
    UILabel debugLine1 = find("debugLine1", UILabel.class);
    if (debugLine1 != null) {
        debugLine1.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                double memoryUsage = ((double) Runtime.getRuntime().totalMemory() - (double) Runtime.getRuntime().freeMemory()) / 1048576.0;
                return String.format("fps: %.2f, mem usage: %.2f MB, total mem: %.2f MB, max mem: %.2f MB", time.getFps(), memoryUsage, Runtime.getRuntime().totalMemory() / 1048576.0, Runtime.getRuntime().maxMemory() / 1048576.0);
            }
        });
    }
    UILabel debugLine2 = find("debugLine2", UILabel.class);
    if (debugLine2 != null) {
        debugLine2.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return String.format("Active Entities: %s, Current Target: %s", entityManager.getActiveEntityCount(), cameraTarget.toString());
            }
        });
    }
    UILabel debugLine3 = find("debugLine3", UILabel.class);
    if (debugLine3 != null) {
        debugLine3.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                Vector3f pos = localPlayer.getPosition();
                Vector3i chunkPos = ChunkMath.calcChunkPos((int) pos.x, (int) pos.y, (int) pos.z);
                Vector3f rotation = localPlayer.getViewDirection();
                Vector3f cameraPos = localPlayer.getViewPosition();
                return String.format(Locale.US, "Pos (%.2f, %.2f, %.2f), Chunk (%d, %d, %d), Eye (%.2f, %.2f, %.2f), Rot (%.2f, %.2f, %.2f)", pos.x, pos.y, pos.z, chunkPos.x, chunkPos.y, chunkPos.z, cameraPos.x, cameraPos.y, cameraPos.z, rotation.x, rotation.y, rotation.z);
            }
        });
    }
    UILabel debugLine4 = find("debugLine4", UILabel.class);
    if (debugLine4 != null) {
        debugLine4.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                String biomeId = "unavailable";
                Vector3i blockPos = new Vector3i(localPlayer.getPosition());
                if (worldProvider.isBlockRelevant(blockPos)) {
                    Biome biome = worldProvider.getBiome(blockPos);
                    biomeId = CoreRegistry.get(BiomeManager.class).getBiomeId(biome);
                }
                return String.format("total vus: %s | worldTime: %.3f | tiDi: %.1f |  biome: %s", ChunkTessellator.getVertexArrayUpdateCount(), // use floor instead of rounding up
                worldProvider.getTime().getDays() - 0.0005f, time.getGameTimeDilation(), biomeId);
            }
        });
    }
    UILabel saveStatusLabel = find("saveStatusLabel", UILabel.class);
    // clients do not have a storage manager
    if (saveStatusLabel != null && storageManager != null) {
        saveStatusLabel.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return "Saving... ";
            }
        });
        saveStatusLabel.bindVisible(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return storageManager.isSaving();
            }
        });
    }
    metricsLabel = find("metrics", UILabel.class);
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) BiomeManager(org.terasology.world.biomes.BiomeManager) Biome(org.terasology.world.biomes.Biome) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i)

Example 2 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class OpenGLSkeletalMesh method doRender.

public void doRender(List<Vector3f> verts, List<Vector3f> normals) {
    FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(verts.size() * 6);
    for (int i = 0; i < verts.size(); ++i) {
        Vector3f vert = verts.get(i);
        vertBuffer.put(vert.x * scale.x + translate.x);
        vertBuffer.put(vert.y * scale.y + translate.y);
        vertBuffer.put(vert.z * scale.z + translate.z);
        Vector3f norm = normals.get(i);
        vertBuffer.put(norm.x);
        vertBuffer.put(norm.y);
        vertBuffer.put(norm.z);
    }
    vertBuffer.flip();
    VertexBufferObjectUtil.bufferVboData(disposalAction.vboPosNormBuffer, vertBuffer, GL15.GL_DYNAMIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, disposalAction.vboPosNormBuffer);
    glVertexPointer(VECTOR3_SIZE, GL_FLOAT, STRIDE, 0);
    glNormalPointer(GL_FLOAT, STRIDE, NORMAL_OFFSET);
    GL11.glDrawElements(GL11.GL_TRIANGLES, data.getIndices().size(), GL_UNSIGNED_INT, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 3 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class ChunkTessellator method generateOptimizedBuffers.

private void generateOptimizedBuffers(ChunkView chunkView, ChunkMesh mesh) {
    PerformanceMonitor.startActivity("OptimizeBuffers");
    for (ChunkMesh.RenderType type : ChunkMesh.RenderType.values()) {
        ChunkMesh.VertexElements elements = mesh.getVertexElements(type);
        // Vertices double to account for light info
        elements.finalVertices = BufferUtils.createIntBuffer(elements.vertices.size() + /* POSITION */
        elements.tex.size() + /* TEX0 (UV0 and flags) */
        elements.tex.size() + /* TEX1 (lighting data) */
        elements.flags.size() + /* FLAGS */
        elements.color.size() + /* COLOR */
        elements.normals.size());
        int cTex = 0;
        int cColor = 0;
        int cFlags = 0;
        for (int i = 0; i < elements.vertices.size(); i += 3, cTex += 2, cColor += 4, cFlags++) {
            Vector3f vertexPos = new Vector3f(elements.vertices.get(i), elements.vertices.get(i + 1), elements.vertices.get(i + 2));
            /* POSITION */
            elements.finalVertices.put(Float.floatToIntBits(vertexPos.x));
            elements.finalVertices.put(Float.floatToIntBits(vertexPos.y));
            elements.finalVertices.put(Float.floatToIntBits(vertexPos.z));
            /* UV0 - TEX DATA 0 */
            elements.finalVertices.put(Float.floatToIntBits(elements.tex.get(cTex)));
            elements.finalVertices.put(Float.floatToIntBits(elements.tex.get(cTex + 1)));
            /* FLAGS */
            elements.finalVertices.put(Float.floatToIntBits(elements.flags.get(cFlags)));
            float[] result = new float[3];
            Vector3f normal = new Vector3f(elements.normals.get(i), elements.normals.get(i + 1), elements.normals.get(i + 2));
            calcLightingValuesForVertexPos(chunkView, vertexPos, result, normal);
            /* LIGHTING DATA / TEX DATA 1 */
            elements.finalVertices.put(Float.floatToIntBits(result[0]));
            elements.finalVertices.put(Float.floatToIntBits(result[1]));
            elements.finalVertices.put(Float.floatToIntBits(result[2]));
            /* PACKED COLOR */
            final int packedColor = RenderMath.packColor(elements.color.get(cColor), elements.color.get(cColor + 1), elements.color.get(cColor + 2), elements.color.get(cColor + 3));
            elements.finalVertices.put(packedColor);
            /* NORMALS */
            elements.finalVertices.put(Float.floatToIntBits(normal.x));
            elements.finalVertices.put(Float.floatToIntBits(normal.y));
            elements.finalVertices.put(Float.floatToIntBits(normal.z));
        }
        elements.finalIndices = BufferUtils.createIntBuffer(elements.indices.size());
        TIntIterator indexIterator = elements.indices.iterator();
        while (indexIterator.hasNext()) {
            elements.finalIndices.put(indexIterator.next());
        }
        elements.finalVertices.flip();
        elements.finalIndices.flip();
    }
    PerformanceMonitor.endActivity();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) Vector3f(org.terasology.math.geom.Vector3f)

Example 4 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class Tessellator method addMeshPart.

private void addMeshPart(BlockMeshPart part, boolean doubleSided) {
    for (int i = 0; i < part.size(); ++i) {
        Vector3f vertex = part.getVertex(i);
        meshData.getVertices().add(vertex.x);
        meshData.getVertices().add(vertex.y);
        meshData.getVertices().add(vertex.z);
        meshData.getColors().add(activeColor.x);
        meshData.getColors().add(activeColor.y);
        meshData.getColors().add(activeColor.z);
        meshData.getColors().add(activeColor.w);
        Vector3f normal = part.getNormal(i);
        meshData.getNormals().add(normal.x);
        meshData.getNormals().add(normal.y);
        meshData.getNormals().add(normal.z);
        Vector2f uv = part.getTexCoord(i);
        meshData.getTexCoord0().add(uv.x);
        meshData.getTexCoord0().add(uv.y);
        meshData.getTexCoord1().add(lighting.x);
        meshData.getTexCoord1().add(lighting.y);
        meshData.getTexCoord1().add(lighting.z);
    }
    for (int i = 0; i < part.indicesSize(); ++i) {
        meshData.getIndices().add(nextIndex + part.getIndex(i));
    }
    if (doubleSided) {
        for (int i = 0; i < part.indicesSize(); i += 3) {
            int i1 = nextIndex + part.getIndex(i);
            int i2 = nextIndex + part.getIndex(i + 1);
            int i3 = nextIndex + part.getIndex(i + 2);
            meshData.getIndices().add(i1);
            meshData.getIndices().add(i3);
            meshData.getIndices().add(i2);
        }
    }
    nextIndex += part.size();
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector3f(org.terasology.math.geom.Vector3f)

Example 5 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class TessellatorHelper method addBlockMesh.

public static void addBlockMesh(Tessellator tessellator, Vector4f color, Vector2f[] texOffsets, Vector2f[] texSizes, float size, float light1, float light2, float posX, float posY, float posZ) {
    final float sizeHalf = size / 2;
    tessellator.resetParams();
    tessellator.setColor(new Vector4f(light1 * color.x, light1 * color.y, light1 * color.z, color.w));
    tessellator.setNormal(new Vector3f(0, 1, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y + texSizes[0].y), new Vector2f(texOffsets[0].x, texOffsets[0].y + texSizes[0].y) });
    tessellator.setNormal(new Vector3f(-1, 0, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y), new Vector2f(texOffsets[1].x, texOffsets[1].y) });
    tessellator.setNormal(new Vector3f(1, 0, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y + texSizes[2].y), new Vector2f(texOffsets[2].x, texOffsets[2].y + texSizes[2].y) });
    tessellator.setColor(new Vector4f(light2 * color.x, light2 * color.y, light2 * color.z, color.w));
    tessellator.setNormal(new Vector3f(0, 0, -1));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y + texSizes[3].y), new Vector2f(texOffsets[3].x, texOffsets[3].y + texSizes[3].y) });
    tessellator.setNormal(new Vector3f(0, 0, 1));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y), new Vector2f(texOffsets[4].x, texOffsets[4].y) });
    tessellator.setNormal(new Vector3f(0, -1, 0));
    tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y + texSizes[5].y), new Vector2f(texOffsets[5].x, texOffsets[5].y + texSizes[5].y) });
}
Also used : Vector4f(org.terasology.math.geom.Vector4f) Vector2f(org.terasology.math.geom.Vector2f) Vector3f(org.terasology.math.geom.Vector3f)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)189 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)29 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)15 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5