Example 23.16: A large city of cubes

There's a lot still to be added to this package, but first let's see how you might use this package to create a larger VRML world than you could easily do by hand. Example 23.16 fills a section of the x-y plane with a series of cubes ranging in height and width from 1 to 10 and in depth from 1 to 100.

import elharo.vrml.*;

public class city {

  public static void main (String[] args) {
  
    world city = new world();
    int block = 10;

    for (int street = 1; street < 250; street ++) {
      for (int avenue = 1; avenue < 12; avenue++) {
        Cube building = new Cube();
        building.moveTo(street * block, 
          avenue * 4 * block, 0);
        building.sizeTo(street * (block-1), 
          avenue*4*(block-1), 30);
        city.addShape(building);
      }
    }
    
    city.draw();
  
  }
} As long as you have an algorithmic means of describing your world it is possible to use Java to create far more complex worlds than would be possible either by writing VRML directly or by using a graphical 3-D modeler like Virtus World Builder. In fact the first worlds the author created using these techniques quickly overwhelmed and crashed his VRML viewer.


Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home