Beispiel #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
  }