Esempio n. 1
0
  public void init() {

    int i;

    thePlanes = new plane[MAX_PLANES];
    for (i = 0; i < MAX_PLANES; i++) thePlanes[i] = new plane();

    int width = gl.getWidth();
    int height = gl.getHeight();

    gl.viewport(0, 0, width, height);

    // setup OpenGL state
    gl.clearDepth(1.0);
    gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.matrixMode(GL.PROJECTION);
    gl.frustum(-1.0, 1.0, -1.0, 1.0, 1.0, 20);
    gl.matrixMode(GL.MODELVIEW);

    // add three initial random thePlanes
    random = new Random(System.currentTimeMillis());
    for (i = 0; i < 3; i++) addPlane();

    moving = true;
  }
Esempio n. 2
0
  // Handle the keystrokes
  public void keyTyped(KeyEvent e) {

    switch (e.getKeyChar()) {
      case 'h':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(15.0, 0.0, 1.0, 0.0);
        break;
      case 'j':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(15.0, 1.0, 0.0, 0.0);
        break;
      case 'k':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(-15.0, 1.0, 0.0, 0.0);
        break;
      case 'l':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(-15.0, 0.0, 1.0, 0.0);
        break;
      case '+':
        gl.matrixMode(GL.PROJECTION); /* manipulate Projection matrix  */
        gl.translate(0.0, 0.0, 0.5);
        e.consume();
        break;
      case '-':
        gl.matrixMode(GL.PROJECTION); /* manipulate Projection matrix  */
        gl.translate(0.0, 0.0, -0.5);
        e.consume();
        break;
      case 's':
        if (r_thread == null) {
          r_thread = new Thread(this);
          r_thread.start();
        }
        break;
      case 'p':
        if (r_thread != null) {
          r_thread.interrupt();
          r_thread = null;
        }
        break;
      case 27: /* Esc will quit */
        System.exit(1);
        break;
      default:
        break;
    }
    e.consume();
    display();
  }