Exemplo n.º 1
0
// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    glLoadIdentity();
    double dt = GetDeltaTime();
    if (gFirstPerson)
    {
        double rad = gRat.getDegrees()/180.0 * M_PI;
        double dx = cos(rad) * MOVE_SPEED * dt;
        double dy = sin(rad) * MOVE_SPEED * dt;

        double hover = 2.0;
        double terrainHeight = gMaze.getZ(gRat.getX() + dx, gRat.getY() + dy);
        double waterHeight = gWaterHeight + .4;
        double H = fmax(terrainHeight, waterHeight) + hover;
        double currentTerrainHeight = fmax(waterHeight, gMaze.getZ(gRat.getX(), gRat.getY()));
        double tilt = (fmax(terrainHeight, waterHeight) - currentTerrainHeight);
        double lookZ = H + tilt;
        gluLookAt(gRat.getX(), gRat.getY(), H, gRat.getX() + dx, gRat.getY() + dy, lookZ, 0, 0, 1);
        // when doing rat, calculate at point but z will stay.
    }
    else
    {
        gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
    }

	gMaze.draw(gWaterHeight);
    gRat.draw(gFirstPerson);
    if (gLeft) gRat.spinLeft(dt);
    if (gRight) gRat.spinRight(dt);
    if (gMiddle) gRat.move(dt);

    if (gFirstPerson)
    {
        gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
    }
    else
    {
        gluPerspective(40, (double)screen_x/screen_y, RES*.5, 3*(RES+RES));
    }

	glutSwapBuffers();
	glutPostRedisplay();
}
Exemplo n.º 2
0
// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);

  glLoadIdentity();
  double dt = GetDeltaTime();
  if (gFirstPerson)
  {
    double rad = gRat.getDegrees()/180.0 * M_PI;
    double dx = cos(rad) * MOVE_SPEED * dt;
    double dy = sin(rad) * MOVE_SPEED * dt;
    gluLookAt(gRat.getX(), gRat.getY(), gRatHeight, gRat.getX() + dx, gRat.getY() + dy, gRatHeight, 0, 0, 1);
    // when doing rat, calculate at point but z will stay.
  }
  else
  {
    gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
  }

	gMaze.draw();
  gRat.draw(gFirstPerson);

  if (gLeft) gRat.spinLeft(dt);
  if (gRight) gRat.spinRight(dt);
  if (gMiddle) gRat.move(dt);

  if (gFirstPerson)
  {
    gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
  }
  else
  {
    gluPerspective(40, (double)screen_x/screen_y, N*.5, 3*(M+N));
  }

	glutSwapBuffers();
	glutPostRedisplay();

}