示例#1
0
  /**
   * The main function opens a 3D rendering window, constructs a simple 3D scene, and starts a timer
   * task to generate an animation.
   *
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {

    sceneManager = new SimpleSceneManager();

    Landscape landscape = new Landscape(7, 50, 20, 10, 5);
    // Set up the vertex data and integrate
    VertexData vLandscape = landscape.getVertexData();
    sLandscape = new Shape(vLandscape);
    sceneManager.addShape(sLandscape);

    // adjust the camera
    camera = sceneManager.getCamera();

    Vector3f centerOfProjection = new Vector3f(0, 0, 40);
    Vector3f lookAtPoint = new Vector3f(0, 0, 0);
    Vector3f upVector = new Vector3f(0, 1, 0);
    camera.setCameraMatrix(centerOfProjection, lookAtPoint, upVector);

    // adjust the frustum
    Frustum frustum = sceneManager.getFrustum();

    float nearPlane = 1;
    float farPlane = 100;
    float aspectRatio = 1;
    float vFieldOfView = 60;
    frustum.setFrustum(nearPlane, farPlane, aspectRatio, vFieldOfView);

    // Make a render panel. The init function of the renderPanel
    // (see above) will be called back for initialization.
    renderPanel = new SimpleRenderPanel();

    // Make the main window of this application and add the renderer to it
    // JFrame
    jframe = new JFrame("simple");
    jframe.setSize(750, 750);
    jframe.setLocationRelativeTo(null); // center of screen
    jframe.getContentPane().add(renderPanel.getCanvas()); // put the canvas into a JFrame window

    // Add a mouse listener
    SimpleMouseListener mouse = new SimpleMouseListener();
    renderPanel.getCanvas().addMouseListener(mouse); // change proposed in forum
    renderPanel.getCanvas().addMouseMotionListener(mouse);
    renderPanel.getCanvas().addKeyListener(new MyKeyListener());

    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.setVisible(true); // show window
  }
示例#2
0
    public void run() {
      adjustToScreenSize =
          (float)
              Math.min(
                  jframe.getWidth(),
                  jframe.getHeight()); // used here, since you can change the screen-Size

      Matrix4f newTranslation = new Matrix4f();
      newTranslation.setIdentity();

      Matrix4f oldcTranslation = new Matrix4f();
      oldcTranslation = camera.getCameraMatrix();

      // world z-Axis-turn
      if (mouseWorldTurn != null) {
        newTranslation.mul(mouseWorldTurn);
        mouseWorldTurn.setIdentity();
      }

      // camera x-Axis-turn
      if (mouseTurn != null) {
        newTranslation.mul(mouseTurn);
        mouseTurn.setIdentity();
      }

      // camera movement
      if (keyMove != null) {
        newTranslation.mul(keyMove);
        keyMove.setIdentity();
      }

      newTranslation.mul(oldcTranslation);

      camera.setCameraMatrix(newTranslation);
      // something still appears to be wrong while turning

      // Trigger redrawing of the render window
      renderPanel.getCanvas().repaint();
    }