Search in sources :

Example 41 with Vector3f

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

the class AABBRenderer method render.

/**
 * Renders this AABB.
 * <br><br>
 *
 * @param lineThickness The thickness of the line
 */
@Override
public void render(float lineThickness) {
    CoreRegistry.get(ShaderManager.class).enableDefault();
    glPushMatrix();
    Vector3f cameraPosition = CoreRegistry.get(LocalPlayer.class).getViewPosition();
    glTranslated(aabb.getCenter().x - cameraPosition.x, -cameraPosition.y, aabb.getCenter().z - cameraPosition.z);
    renderLocally(lineThickness);
    glPopMatrix();
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) Vector3f(org.terasology.math.geom.Vector3f)

Example 42 with Vector3f

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

the class AABBRenderer method generateDisplayListWire.

private void generateDisplayListWire() {
    float offset = 0.001f;
    displayListWire = glGenLists(1);
    glNewList(displayListWire, GL11.GL_COMPILE);
    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
    Vector3f dimensions = aabb.getExtents();
    // FRONT
    glBegin(GL_LINE_LOOP);
    glVertex3f(-dimensions.x - offset, -dimensions.y - offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, -dimensions.y - offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, +dimensions.y + offset, -dimensions.z - offset);
    glVertex3f(-dimensions.x - offset, +dimensions.y + offset, -dimensions.z - offset);
    glEnd();
    // BACK
    glBegin(GL_LINE_LOOP);
    glVertex3f(-dimensions.x - offset, -dimensions.y - offset, +dimensions.z + offset);
    glVertex3f(+dimensions.x + offset, -dimensions.y - offset, +dimensions.z + offset);
    glVertex3f(+dimensions.x + offset, +dimensions.y + offset, +dimensions.z + offset);
    glVertex3f(-dimensions.x - offset, +dimensions.y + offset, +dimensions.z + offset);
    glEnd();
    // TOP
    glBegin(GL_LINE_LOOP);
    glVertex3f(-dimensions.x - offset, -dimensions.y - offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, -dimensions.y - offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, -dimensions.y - offset, +dimensions.z + offset);
    glVertex3f(-dimensions.x - offset, -dimensions.y - offset, +dimensions.z + offset);
    glEnd();
    // BOTTOM
    glBegin(GL_LINE_LOOP);
    glVertex3f(-dimensions.x - offset, +dimensions.y + offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, +dimensions.y + offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, +dimensions.y + offset, +dimensions.z + offset);
    glVertex3f(-dimensions.x - offset, +dimensions.y + offset, +dimensions.z + offset);
    glEnd();
    // LEFT
    glBegin(GL_LINE_LOOP);
    glVertex3f(-dimensions.x - offset, -dimensions.y - offset, -dimensions.z - offset);
    glVertex3f(-dimensions.x - offset, -dimensions.y - offset, +dimensions.z + offset);
    glVertex3f(-dimensions.x - offset, +dimensions.y + offset, +dimensions.z + offset);
    glVertex3f(-dimensions.x - offset, +dimensions.y + offset, -dimensions.z - offset);
    glEnd();
    // RIGHT
    glBegin(GL_LINE_LOOP);
    glVertex3f(+dimensions.x + offset, -dimensions.y - offset, -dimensions.z - offset);
    glVertex3f(+dimensions.x + offset, -dimensions.y - offset, +dimensions.z + offset);
    glVertex3f(+dimensions.x + offset, +dimensions.y + offset, +dimensions.z + offset);
    glVertex3f(+dimensions.x + offset, +dimensions.y + offset, -dimensions.z - offset);
    glEnd();
    glEndList();
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 43 with Vector3f

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

the class MeshBuilder method addBox.

/**
 * Add vertices, texture coordinate and indices for a box specified by offset and size.
 * <br><br>
 * Use the texture mapper to change how texture coordinates (u and v) are applied to each vertex.
 */
public MeshBuilder addBox(Vector3f offset, Vector3f size, float u, float v) {
    int vertexId = vertexCount;
    textureMapper.initialize(offset, size);
    for (int i = 0; i < VERTICES.length / 3; i++) {
        addVertex(new Vector3f(offset.x + size.x * VERTICES[i * 3], offset.y + size.y * VERTICES[i * 3 + 1], offset.z + size.z * VERTICES[i * 3 + 2]));
        addTexCoord(textureMapper.map(i, u, v));
    }
    for (int i : INDICES) {
        addIndex(vertexId + i);
    }
    return this;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 44 with Vector3f

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

the class MeshBuilder method addPoly.

public MeshBuilder addPoly(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f... vn) {
    for (int i = 0; i < vn.length + 1; i++) {
        addIndices(vertexCount, vertexCount + i + 2, vertexCount + i + 1);
    }
    addVertex(v1);
    addVertex(v2);
    addVertex(v3);
    for (Vector3f v : vn) {
        addVertex(v);
    }
    return this;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 45 with Vector3f

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

the class ObjMeshFormat method processData.

private MeshData processData(List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
    MeshData result = new MeshData();
    TFloatList vertices = result.getVertices();
    TFloatList texCoord0 = result.getTexCoord0();
    TFloatList normals = result.getNormals();
    TIntList indices = result.getIndices();
    int vertCount = 0;
    for (Vector3i[] face : rawIndices) {
        for (Vector3i indexSet : face) {
            if (indexSet.x > rawVertices.size()) {
                throw new IOException("Vertex index out of range: " + indexSet.x);
            }
            Vector3f vertex = rawVertices.get(indexSet.x - 1);
            vertices.add(vertex.x);
            vertices.add(vertex.y);
            vertices.add(vertex.z);
            if (indexSet.y != -1) {
                if (indexSet.y > rawTexCoords.size()) {
                    throw new IOException("TexCoord index out of range: " + indexSet.y);
                }
                Vector2f texCoord = rawTexCoords.get(indexSet.y - 1);
                texCoord0.add(texCoord.x);
                texCoord0.add(1 - texCoord.y);
            }
            if (indexSet.z != -1) {
                if (indexSet.z > rawNormals.size()) {
                    throw new IOException("Normal index out of range: " + indexSet.z);
                }
                Vector3f normal = rawNormals.get(indexSet.z - 1);
                normals.add(normal.x);
                normals.add(normal.y);
                normals.add(normal.z);
            }
        }
        for (int i = 0; i < face.length - 2; ++i) {
            indices.add(vertCount);
            indices.add(vertCount + i + 1);
            indices.add(vertCount + i + 2);
        }
        vertCount += face.length;
    }
    return result;
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector3f(org.terasology.math.geom.Vector3f) TFloatList(gnu.trove.list.TFloatList) Vector3i(org.terasology.math.geom.Vector3i) IOException(java.io.IOException) TIntList(gnu.trove.list.TIntList)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 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