help w/ rotations

Hey all,

I’ve got rotation working w/ the up, down, pg_up, pg_down, right and left arrows. But now I’d like to get it working with the mouse cursor so that I can rotate my objects on screen. Can anyone help me out w/ how to do that. Below is the rotations I currently have in my display() method.

    gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f);

And here’s my keyPressed() method …

public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
                                                                            
        case KeyEvent.VK_PAGE_UP:
            zrot += 2.0f;
            break;
                                                                            
        case KeyEvent.VK_PAGE_DOWN:
            zrot -= 2.0f;
            break;
                                                                            
        case KeyEvent.VK_UP:
            xrot += 2.0f;
            break;
                                                                            
        case KeyEvent.VK_DOWN:
            xrot -= 2.0f;
            break;
             
        case KeyEvent.VK_RIGHT:
            yrot += 2.0f;
            break;
             
       case KeyEvent.VK_LEFT:
            yrot -= 2.0f;
            break;
    }
              
    this.gldrawable.display();
}

Also, anyone know what’s needed to make my objects zoom in and out?

Any help much appreciated.

For an intuitive rotation control, take a look at http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=48. Although it doesn’t have JOGL code specifically, it should be easy to convert. For zooming in, just move your camera closer to the object.

What is it exactly you want to do? From your post I’m not quite sure:

  • Move the objects in the scene?
  • Zoom the view in and out?
  • Add mouse control to your app?
  • Something else altogether?

Kev

Ah, ok… to get mouse control you use a java.awt.MouseListener/MouseEvent like you already do with Keyboard events.

If you want to implement mouse look then each frame evaluate where the mouse has moved to (by recording the x,y from mouse events). Next use java.awt.Robot to recenter the mouse cursor on the screen ready for the next move.

The change in X does your Y axis rotation, the change in Y does your X axis rotation.

Kev

This one may be useful for bookmarking and referencing later. The Matrix FAQ has all the maths you need for interacting with navigation. In particular, when you start doing rotations and concepts such as gimbal lock etc. The FAQ can be found here:

http://www.j3d.org/matrix_faq/

You may want to look at the gleem library, which is used for the mouse interactions with objects and the camera in the JOGL demos. The source code for gleem is in the jogl-demos workspace.