Sign in to follow this  
TheGD

Help With Rotations and Translations

Recommended Posts

Okay...I have been working on this for the past week. I finally am able to accomplish the desired rotation scheme, but now the panning is screwy. A little background. We need to be able to look at a model (in our case a VERY long skinny point cloud). We need to start a predefined distance away from the point cloud and be able to zoom in (hence the initial translate). Also, we need to be able to rotate the point cloud around to see it from all sides/aspects, etc (hence the next rotation). Finally, we need to be able to MOVE that point of rotation to anywhere within the point cloud. Now...I have the rotation working okay. But if I rotate 90 degrees and then try to PAN along the X-axis, it retains the original axis and appears to move along the Z axis. Here is the code I am using right now: glLoadIdentity(); glTranslatef (0.0F, 0.0F, obj_pos[2]); glRotatef (m_RotAmount, m_yRotation, m_xRotation, m_zRotation); glMultMatrixf(rotationMatrix); /*** Draw a center point cross hair ***/ glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); glVertex3f( 0.0F, 0.0F, 0.0F); glVertex3f( 4.0F, 0.0F, 0.0F); glColor3f( 0.0F, 1.0F, 0.0F); glVertex3f( 0.0F, 0.0F, 0.0F); glVertex3f( 0.0F, 4.0F, 0.0F); glColor3f( 0.0F, 0.0F, 1.0F); glVertex3f( 0.0F, 0.0F, 0.0F); glVertex3f( 0.0F, 0.0F, 4.0F); glEnd(); glTranslatef (obj_pos[0], obj_pos[1], 0.0f); /**** DRAW the scene ****/ DrawScene(); I have tried to put all the translations up front BEFORE the rotation, but then this enables me to move the point of rotation, but my EYE still looks at the center of the screen. HELP!...this can be very frustrating...I am hoping someone has encountered something similar and has the solution! Thanks! TheGD

Share this post


Link to post
Share on other sites
The flipping of the camera axis is typical of the Gimbal Lock (google for it). There are two ways of solving this: One by maintaining your own local camera co-ordinates (vis forward, right and up axis) for all rotation operations. That is, everytime you rotate the camera, you use the forward, right and up axis you've defined to rotate the camera. You will need to recalculate the forward and right vectors when doing yaw, forward and up vectors when doing pitch and up and right when doing roll.

The other and probably the better way to do this is to use quaternions since they allow you to rotate about any arbitary axis, which is perfect for a camera.

Share this post


Link to post
Share on other sites
That is what I was thinking as well. Right now...the rotations are working fine...they always rotate about the current axis...the problem is the translations AFTER a rotation...but I am thinking that QUATs will solve the problem...but as is typical...have never used them...can you recommend a good source to hjelp me get started using quaternions to store and update the current position.

TheGD

Share this post


Link to post
Share on other sites
To avoid gimbal lock you have to drop the usage of Euler angles. It is possible but not necessary to use quaternions for that purpose. You could stay with matrices (at a certain level you always stay with matrices ;) and use quaternions or axis/angle pairs for intermediate operations. The trick is to pick a global axis (as said for an axis/angle pair or quaternion) to rotate around, converting it into a matrix, and multiplying it onto the current orientation matrix. So you do an incremental rotation around free selected axes! (As opposite, with Euler angles you do sequences of 3 rotations around pre-defined axes.)

See that using matrices will introduce an error over time. So you have to re-orthogonalize the matrix from time to time, or else your scene becomes somewhat sheared. Here using a quaternion for storing an orientation (and not only using it as intermediate representation) has an advantage since it has only 4 variables for the 3 DoF (where the matrix has 9 variables). So a quaternion accumulates errors with a lesser rate than a matrix does.

Now let us look at the order of transformations. Your desire is to rotate around a free aiming point, as fas as I understood. So you have to do the following. First translate the camera so that the aiming point becomes the origin. That normally means that the camera is apart from the origin. Now rotate the camera. After that translate the camera system so that the aiming point becomes located in the world where desired. So you have to do a translation before and after the rotation (and notice that the rotation does a displacement, too, since the rotated object isn't located above the rotation origin). Setting-up the view system with that definition of the camera's position and orientation should solve your problem.

[Edited by - haegarr on April 18, 2006 6:37:16 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this