May 2005
Intermediate to advanced
998 pages
26h
English
The floor is a QuadArray made up of a series of quads, which taken together cover the entire floor. Each quad is assigned a texture and an upward facing normal. The sides of the entire floor have the length FLOOR_LEN, and each quad has sides of length STEP, as shown in Figure 25-7.
The paving of the floor starts at the front, leftmost point (-FLOOR_LEN/2, FLOOR_LEN/2) and continues left to right and forward to back. This work is carried out by TexturedFloor's constructor and createCoords():
public TexturedFloor()
// create quad coords, make TexturedPlane, add to floorBG
Figure 25-7. The floor and its QuadArray (from above)
{
ArrayList coords = new ArrayList();
floorBG = new BranchGroup();
// create coords for the quad
for(int z=FLOOR_LEN/2; z >= (-FLOOR_LEN/2)+STEP; z-=STEP) {
for(int x=-FLOOR_LEN/2; x <= (FLOOR_LEN/2)-STEP; x+=STEP)
createCoords(x, z, coords); } Vector3f upNormal = new Vector3f(0.0f, 1.0f, 0.0f); // upwards floorBG.addChild( new TexturedPlane(coords,FLOOR_IMG,upNormal) ); } private void createCoords(int x, int z, ArrayList coords) { // points created in counter-clockwise order, from front left // of length STEP Point3f p1 = new Point3f(x, 0.0f, z); Point3f p2 = new Point3f(x+STEP, 0.0f, z); Point3f p3 = new Point3f(x+STEP, 0.0f, z-STEP); Point3f p4 = new Point3f(x, 0.0f, z-STEP); coords.add(p1); coords.add(p2); coords.add(p3); coords.add(p4); } // ...