/** * Recalculate the vertex normal, by averagin the normals of the neighboring triangles. The * neighbor list holds only triangles that we want to average with this vertex. * * @see GL_Object.registerNeighbors() * @param neighbors neighboring triangles for this vert * @return vertex normal */ public GL_Vector recalcVertexNormal(ArrayList neighbors) { float nx = 0; float ny = 0; float nz = 0; GL_Triangle tri; GL_Vector wn = new GL_Vector(); // for each neighbor triangle, average the normals for (int i = 0; i < neighbors.size(); i++) { tri = (GL_Triangle) neighbors.get(i); wn = tri.getWeightedNormal(); nx += wn.x; ny += wn.y; nz += wn.z; } GL_Vector vertn = new GL_Vector(nx, ny, nz); vertn.normalize(); return vertn; }