Beispiel #1
0
  // ***************************************************************************
  // run
  // ***************************************************************************
  private void run() {
    // Main camera = new Main(0, 0, 0);

    float dx = 0.0f;
    float dy = 0.0f;
    float dt = 0.0f;

    float lastTime = 0.0f; // when the last frame was
    float time = 0.0f;

    float mouseSensitivity = 0.15f;
    float movementSpeed = 10.0f; // move 10 units per second

    // hide the mouse
    Mouse.setGrabbed(true);

    while ((gameRunning) && (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))) {
      // update();

      // render();
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
      // GL11.glLoadIdentity();
      GL11.glTranslatef(0.0f, 0.0f, -5.0f);

      axis.draw();
      grid.render();
      // cube.render();

      /*
      {
         Color.white.bind();
         texture.bind(); // or GL11.glBind(texture.getTextureID());

         GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(0,0);
         GL11.glVertex2f(100,100);
         GL11.glTexCoord2f(1,0);
         GL11.glVertex2f(100+texture.getTextureWidth(),100);
         GL11.glTexCoord2f(1,1);
         GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
         GL11.glTexCoord2f(0,1);
         GL11.glVertex2f(100,100+texture.getTextureHeight());
         GL11.glEnd();
      }
      */

      Display.update();

      // keep looping till the display window is closed the ESC key is down
      /*
      while (!Display.isCloseRequested() ||
      !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
      {
       */
      time = Sys.getTime();

      // here is your movement speed, which can be changed to anything
      dt = 0.0005f;

      lastTime = time;

      // distance in mouse movement from the last getDX() call.
      dx = Mouse.getDX();
      // distance in mouse movement from the last getDY() call.
      dy = Mouse.getDY();

      // control camera yaw from x movement from the mouse
      camera.yaw(dx * mouseSensitivity);
      // control camera pitch from y movement from the mouse
      camera.pitch(-dy * mouseSensitivity);

      // when passing in the distrance to move
      // we times the movementSpeed with dt this is a time scale
      // so if its a slow frame u move more then a fast frame
      // so on a slow computer you move just as fast as on a fast computer

      if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
        camera.moveForward(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
        camera.moveBackwards(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
        camera.moveLeft(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
        camera.moveRight(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
        camera.moveRight(movementSpeed * dt);
      }

      if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
        camera.moveUp(movementSpeed * dt);
      }

      if (Keyboard.isKeyDown(Keyboard.KEY_P)) {

        // camera.moveRight(movementSpeed * dt);
      }

      // set the modelview matrix back to the identity
      GL11.glLoadIdentity();
      // look through the camera before you draw anything
      camera.lookThrough();

      // you would draw your scene here.

      if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Sys.alert("Close", "To continue, press ESCAPE on your keyboard or OK on the screen.");
        System.exit(0);
      }
    }
  }