Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Tiling the Floor

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
The floor and its QuadArray (from above)

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); } // ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page