示例#1
0
void Maze::generate() {
	long old_time = time(0);
	while(has_next_step()) {
		step_maze();
	}
	std::cout << "Finished maze generation in: " << time(0) - old_time << "ms" << std::endl;
}
示例#2
0
文件: maze.c 项目: briansherman/Maze
void
mouse(int btn, int state, int x, int y)
{
  /* create a new maze */
  if ((btn==GLUT_LEFT_BUTTON) && (state==GLUT_DOWN)) {
    done = 0;
    init_maze(w, h);
    while (!done) {
      step_maze();
    }
    display();
  }

  /* exit */
  if ((btn==GLUT_RIGHT_BUTTON) && (state==GLUT_DOWN)) {
    exit(1);
  }
}
示例#3
0
文件: maze.c 项目: briansherman/Maze
void
myinit()
{
  printf("Move around with WASD. Press t for a top down view.\n");
  GLfloat light0_ambient[]={0.0, 0.0, 0.0, 1.0};
  GLfloat light0_diffuse[]={0.5, 0.5, 0.5, 1.0};
  GLfloat light0_specular[]={1.0, 1.0, .0, 1.0};

  GLfloat light0_position[4];

  light0_position[0] = 0.0;
  light0_position[1] = 0.0;
  light0_position[2] = 15.0;
  light0_position[3] = 1.0;
  
   /* set up ambient, diffuse, and specular components for light 0 */
  glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
  
  GLfloat light1_ambient[] = {1.0, 0.0, 0.0, 1.0};
  GLfloat light1_diffuse[] = {0.5, 0.2, 0.2, 1.0};
  GLfloat light1_specular[] = {1.0, 0.0, 0.2, 1.0};
  

    GLfloat light1_position[] = {(GLfloat)(eyeX), (GLfloat)(eyeY), (GLfloat)(eyeZ)/3, 1.0};
    GLfloat light1_direction[] = {(GLfloat)(cos(theta)), (GLfloat)(sin(theta)), (eyeZ)/3, 1.0};
  
  glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
  glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
  glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_direction);
  glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 10);
  
  lightingMaterialReset();

  glEnable(GL_LIGHTING); /* enable lighting */
  glEnable(GL_LIGHT0);  /* enable light 0 */
  glEnable(GL_LIGHT1); /* enable light 1 */
  glEnable(GL_DEPTH_TEST); /* enable z buffer */
  glClearColor (0.0, 0.0, 0.0, 1.0);
  
  // initialize the projection stack
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(60.0, 1.0, 0.1, 100);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.0, 0.0, 15.0, 0.0, 0.0, 9.0, 0.0, 1.0, 0.0);
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  //glRotatef(-45,1,0,0);
  /* build maze */
  init_maze(w, h);
  while (!done) {
    /* remove one edge */
    step_maze();
  }
  
  //printEdges();
  eyeX = col0*wall_spacing+xoff + wall_spacing/2;
  eyeY = row0*wall_spacing+yoff + wall_spacing/2;
  lookX = eyeX + 1;
  lookY = eyeY;
}