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();
}
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();
}
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;
}
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;
}
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;
}
Aggregations