示例#1
0
  // This gets called by the constructor, hopefully only
  // once but it can be called at any time. Called prior to any
  // Window creation so it can only set variables, not draw things
  public void init() {
    /* initialize the widget */
    int width = gl.getWidth();
    int height = gl.getHeight();

    // Initialize the rendering viewport size to OpenGL
    gl.viewport(0, 0, width, height);
    gl.matrixMode(GL.PROJECTION); // Set up the camera mode
    gl.loadIdentity(); // Reset the transformation matrix
    if (width <= height)
      gl.ortho(
          -50.0,
          50.0,
          -50.0 * (double) height / (double) width,
          50.0 * (double) height / (double) width,
          -1.0,
          1.0);
    else
      gl.ortho(
          -50.0 * (double) width / (double) height,
          50.0 * (double) width / (double) height,
          -50.0,
          50.0,
          -1.0,
          1.0);
    gl.matrixMode(GL.MODELVIEW); // Reset to model transforms
  }
示例#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();
  }