public void render() { if (render_wireframe) GL11.glBegin(GL11.GL_LINE_LOOP); else GL11.glBegin(GL11.GL_TRIANGLES); for (Mesh m : meshes) { for (Face face : m.getFaces()) { try { // One renderVert(m, face, 0); // Two renderVert(m, face, 1); // Three renderVert(m, face, 2); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } } } GL11.glEnd(); if (render_normals) { GL11.glColor3f(Color.BLUE.getRed(), Color.BLUE.getGreen(), Color.BLUE.getBlue()); for (Mesh m : meshes) { for (Face face : m.getFaces()) { Vert center = center2( m.vertices.get(face.vertexIndices[0]), m.vertices.get(face.vertexIndices[1]), m.vertices.get(face.vertexIndices[2])); Vert out = center.add(m.normals.get(face.normalIndices[0])); GL11.glBegin(GL11.GL_LINE_LOOP); GL11.glVertex3f(center.xf(), center.yf(), center.zf()); GL11.glVertex3f(out.xf(), out.yf(), out.zf()); GL11.glEnd(); } } } }
static Vert center2(Vert v1, Vert v2, Vert v3) { return v1.add(v2).add(v3).divide(3); }