Tom Kelliher, CS 320
Feb. 13, 2009
Re-read Chapter 2.
tetra.c
discussion.
2-D graphics and OpenGL lab.
Orthogonal projection; viewing volume.
reshape()
in quadric.c
.
Fall backs:
Entrance lower-left bottom, exit upper-right top.
Redundancy: remove.
Draw south, west maze walls.
struct
declaration:
typedef struct cell { int visited; int north; int east; } cell;
cell maze[ROWS][COLS]; main(...) { process args; set-up window; set-up world; initialize maze and seed random number generator; /* Create a random maze. */ visit(start cell); /* Exit on mouse click. */ register MouseFunc; /* On re-display clear window, redraw maze, re-compute * and display path. */ register DisplayFunc; /* IdleFunc unused!!! */ /* "Prime the pump." */ post a redisplay event; enter MainLoop; }
visit(current cell) { mark current cell visited; Randomly arrange the four compass directions for each of the four randomly arranged compass directions if new cell exists and is unvisited { remove appropriate wall; visit(new cell); } }
Idea: Get a sequence of cells from start cell to end cell on the call stack and draw path from end to start.
Don't forget to mark all maze cells as unvisited before first call!
Initial call: path(start cell, end cell);
path(current cell, target cell) { mark current cell visited; if current cell == target cell return 1; for each of the four neighbor cells if new cell exists and is unvisited if (path(new cell, target cell)) { draw segment from current cell to new cell; return 1; } return 0; }
Need to draw entry/exit segments. Use two colors. maze: