Richard145
03-13-2007, 01:31 PM
Please Help,
I am sure this is a common problem with OpenGL newbies. I am having some difficulty with the glRotatef and glTranslatef functions I hope someone can help me with. I want to allow the user to rotate (with left-mouse button) and move the Model (with right-mouse button). When I comment out either the rotations or translates separately they work fine, but when used together I get basically a rotation with some periodic jittering.
A snippet of my code follows:
public void draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
// Rotate around the X, Y, and Z axes
glRotatef(angleX, 1.0f, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
gl.glRotatef(angleZ, 0.0f, 0.0f, 1.0f);
// Move the Model
glTranslatef(xTrans, 0.0f, 0.0f);
glTranslatef(0.0f, yTrans, 0.0f);
glTranslatef(0.0f, 0.0f, 1.0f);
// Draw Model here
drawCube();
glPopMatrix();
glFlush();
}The xTrans, yTrans, angleX, angleY, and angleZ have been previously calculated from coordinates from the mouse. I think the problem may be the order of the Matrix transformations? Can anyone give me some hints as to why this is happening?
Thanks in advance
I am sure this is a common problem with OpenGL newbies. I am having some difficulty with the glRotatef and glTranslatef functions I hope someone can help me with. I want to allow the user to rotate (with left-mouse button) and move the Model (with right-mouse button). When I comment out either the rotations or translates separately they work fine, but when used together I get basically a rotation with some periodic jittering.
A snippet of my code follows:
public void draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
// Rotate around the X, Y, and Z axes
glRotatef(angleX, 1.0f, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
gl.glRotatef(angleZ, 0.0f, 0.0f, 1.0f);
// Move the Model
glTranslatef(xTrans, 0.0f, 0.0f);
glTranslatef(0.0f, yTrans, 0.0f);
glTranslatef(0.0f, 0.0f, 1.0f);
// Draw Model here
drawCube();
glPopMatrix();
glFlush();
}The xTrans, yTrans, angleX, angleY, and angleZ have been previously calculated from coordinates from the mouse. I think the problem may be the order of the Matrix transformations? Can anyone give me some hints as to why this is happening?
Thanks in advance