JOGL - moving in the direction, that camera points at

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JOGL - moving in the direction, that camera points at

Humberd
public void display(GLAutoDrawable drawable) {
    keyMoving(); //method, that reads key pressing
    GL2 gl = drawable.getGL().getGL2();
    GLUT glut = new GLUT();
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

    gl.glRotatef(mouseY, 1.0f, 0.0f,0.0f);               <--
    gl.glRotatef(mouseX, 0.0f, 1.0f, 0.0f);              <--
    gl.glTranslatef(left_Right, 0.0f, forward_Backward); <--
    ///////////////////BELOW I CREATE OBJECTS////////////////
    gl.glPushMatrix();
    cube(gl); 
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(5.0f, 1.0f, -10.0f); 
    glut.glutWireTeapot(0.505);
    gl.glPopMatrix();

    gl.glPushMatrix();
    platform(gl);
    gl.glPopMatrix();
}
Hello, I try to make a feature, that allows me to move with WSAD and rotate a camera with my mouse (something like free cam). I currently have moving offsets: left_Right - x axis and forward_Backward - z axis. I also have mouse coordinates: mouseX and mouseY. I've tried many combinations of how to make it, but this solution seems fine, except camera rotation doesn't affect my movement. I read many things about it, but half of them are ununderstandable to me and half doesn't solve my problem. Can you show me how to do it correctly?
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - moving in the direction, that camera points at

gouessej
Administrator
Hi

Why not using GluLookAt? Does this example help?
http://stackoverflow.com/a/4295174
Julien Gouesse | Personal blog | Website