Your assignment this week is to create a maze and let the user walk through it (by pressing the arrow keys), as in the following applet. (Hit the "G" key to change between the global view of the maze and view of the "avatar" within the maze.)
The assignment is due on Wednesday of next week, April 7.
You can start with the file Maze.java, which already implements keyboard interaction but show only a blue rectangle on which you can build the maze. (Copies of this file and other files mentioned on this page can be found in /classes/s10/cs225/lab9.) If you have not already added the file SimpleAvatar.java to the glutil package, you will need to do so now.
To create the maze, you can use the MazeData class that is defined in
MazeData.java. Create the data for a 51-by-51 maze using
maze = new MazeData(51,51). The result is a 51-by-51 grid of cells
where each cell is either open or is part of a wall. You can find out whether the
cell at position (i,j) is open by calling
maze.isOpen(i,j). All cells along
the edges of the maze are walls; there is no exit from the maze.
You should create a 3D OpenGL realization of the maze by using a cube to fill each cell that is part of a wall. (Use the Cube class from the glutil package.) The cube should be 1 unit on a side, and the cube for grid position (i,j) should go at (i-25,0,j-25). This will center the maze at the origin, and it will lie on the blue plane that is already rendered in the Maze program. As soon as you create the maze, you can use the arrow keys to navigate through it (in the avatar view). However, you will be able to walk through walls -- and it probably won't look very good.
To complete the assignment, you have to do four things:
init()to load the texture and a couple lines in
display()to enable and disable the texture.
The last point, of course, the hard one. One surprise that I should have expected but didn't is that you can't even let the viewer get too close to a wall. The viewer has a "near clipping plane" that has to be at some non-zero distance in front of the viewer. If the viewer is within the near clipping distance of the wall, then the wall disappears from view, even though the viewer has not yet passed through the wall. In effect, you have to add a small buffer zone around each cube.
There are various approaches to this sort of "collision detection". The easiest, in this case, is probably just to go through all the cubes and test whether the viewer is too close to any one of them. Only the x and z coordinates are relevant.