// This code fragment replaces corresponding code
// in the ReadInput method of the Pipeline applet
if (st.sval.equals("f")) {
int faceTris = 0;
int v0 = (int) getNumber(st);
int v1 = (int) getNumber(st);
while (st.nextToken() == StreamTokenizer.TT_NUMBER) {
st.pushBack();
int v2 = (int) getNumber(st);
if (v2 == v0) continue;
if (triangles == triList.length) growList();
triList[triangles] = new Triangle(v0, v1, v2);
float nx = (vertList[v1].z - vertList[v0].z) * (vertList[v2].y - vertList[v1].y)
- (vertList[v1].y - vertList[v0].y) * (vertList[v2].z - vertList[v1].z);
float ny = (vertList[v1].x - vertList[v0].x) * (vertList[v2].z - vertList[v1].z)
- (vertList[v1].z - vertList[v0].z) * (vertList[v2].x - vertList[v1].x);
float nz = (vertList[v1].y - vertList[v0].y) * (vertList[v2].x - vertList[v1].x)
- (vertList[v1].x - vertList[v0].x) * (vertList[v2].y - vertList[v1].y);
if (faceTris == 0) {
// the normal could be computed here instead if all
// facets are planar... I'll just play it safe
vertList[v0].addNormal(nx, ny, nz);
vertList[v1].addNormal(nx, ny, nz);
}
if (surfaces == 0) {
surfaceList[surfaces] = new Surface(0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 5.0f);
surfaces += 1;
}
triList[triangles].setSurface(surfaceList[surfaces-1]);
vertList[v2].addNormal(nx, ny, nz);
v1 = v2;
faceTris += 1;
triangles += 1;
}
st.pushBack();
} else
// This code fragment appears in the
// init method of the Pipeline applet
for (int i = 0; i < vertices; i++) {
vertList[i].averageNormals();
}
You will need to make some modifications to the Vertex3D object you were given, but you should be able
to figure those out for yourself.
Warning: This is by far the most time consuming project this semester.