Hey all,
Can anyone help w/ the following code. I’m trying to rotate an object using LEFT, RIGHT, UP, DOWN, PAGE UP, and PAGE DOWN keys. The work but my object doesn’t rotate as it should. If I press the LEFT key, I’d like it to turn left (which I think is a rotation on the Y axis). It turns left wierd like.
I’ve been using the NEHE tutorials, but I can’t tell what’s wrong here. Any help much appreciated.
private float xrot = 0.0f;
private float yrot = 0.0f;
private float zrot = 0.0f;
private float xspeed = 0.0f;
private float yspeed = 0.0f;
// i’ve tried many different values here.
private float angle = 10.0f;
public void display(GLDrawable drawable) {
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
this.gldrawable = drawable;
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glColor3f(1.0f, 1.0f, 1.0f);
// viewing transformation
gl.glMatrixMode(GL.GL_MODELVIEW);
// this is default
//glu.gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
gl.glRotatef(angle, xrot, yrot, zrot);
if (selectedFile) {
model.draw();
}
gl.glFlush();
}
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();
}