View Full Version : How to turn Rotate(degree, x, y,z) to Rotate(degreex, x,0,0), Rotate(degreey, 0,y,0).
10-07-2000, 08:11 PM
I have met a problem, I have some objects in the viewport, and the program should let someone to move them, rotate and and scale them.
While, if I rotate object a and move it to somewhere, what if I want rotate in the future? I mean sure I can use one rotatef() to do it, but once I have done that rotation, I lost the axis and the degree it rotated about, then how can I start it to move or ratate again about another axis and dgree?
Sure I can maintain an array of all the action it do, but seems costly.
My idea is to make it rotate about x, y, z seperately instead of use the rotatef(degree, x, y, z), but do OPENGL has a function that return's the different degrees on the x, y, z?
OpenGL has no functions for returning the corresponding rotations about the original axes. But you can calculate them yourself if you want to using the modelview matrix.
Not going to explain it for two reasons. First, me and Eric have already discussed this before. And second, it wasn't that easy to find out. So I just post a link so you can read it yourself. http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/001029.html
The actual problem wasn't the same, but the result is the same in both yours and Eric's problem. What you need to do is obtain the modelview matrix, and identify each elements with a resulting rotation matrix. And don't worry, in the end of the post there is an example on how to calculate the values, so no need to do the identification yourself.
10-09-2000, 12:35 AM
Why don't you rotate around your own rotation matrix?
User moves mouse.
Calculate rotation matrix m from user input.
Multiply your matrix with the gl matrix -> glMultMatrixf(m);
For my applications this works perfect. Only calculation here is setting up a rotation matrix and sending it to OpenGL.
10-09-2000, 12:52 AM
How can I use glMultMatrix ? Do I need to calculate my matrix ? if yes how ?... Sorry, I'm a beginner.
Thank you for the moment
Hi Kilam !
Your idea is good in principles...
But as a matter of fact, what you will end up doing is add small transformations to the modelview matrix. This can lead to a corrupted matrix due to roundoff errors...
There are algorithms that enable you to check for those errors and correct them but they are usually really heavy...
It is almost always better to define your matrix as a set of parameters (here angles around X,Y and Z) and reconstruct it on each frame...
Hope this helps !
10-09-2000, 07:27 AM
Eric: Yes, you're right. But for some application that doesn't matter. I'm working on a CAD application where the user can rotate the part on the screen. This application sometimes runs very long and I never recognized any corruptions in the matrix. In games I can think of such a corruption, as there is always some movement.
By the way, correction of such a matrix is not very expensive. Assume v1, v2 and v3 are the first three columns of my matrix (x, y and z-vector):
Normalize sets the length of the vector to 1.
How about calling the correction every 1000 frames?
Calculate a rotation matrix in an array m like openGL has it (rows are the vectors x, y, z). Then call glMultMatrix(m).
Hi Again !
Well I thought this corruption could happen more often than that !
Thanks for the info !
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.