In order to avoid confusion, I have given you a copy of the triangle code that I used in my own implementation of this project rather some other version. However, I've removed the code segments that you were asked to implement for this project. You should be able to compile the given Java files into a functional, albeit incomplete, version of the project. I have also decided to give you the code for z-buffering (this allowed me to verify that the disabled code did not introduce any bugs, consider it an early Thanksgiving present). You are welcome to use this code as a starting point for you own. However, if you do so I insist that you include comments in your code and on your project web page indicating that you did.
// 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();
}
Of course there are also 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.