• Advertisement

Archived

This topic is now archived and is closed to further replies.

Model View Matrix

This topic is 5270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whenever you do a glRotatef, the model view matrix changes based on the transformation ryt? I was wondering if there was a way to rotate an object while not changing the model view matrix. What i want to do is rotate the matrix by the xangle, and then rotate it again by the original yangle and not the "transformed" model view matrix. Then i draw the object. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
By rotating around any axis you are changing the coordinate system. Your description wasnt clear what rotation you are looking for, but i am taking a guess.
The 1st rotation rotates your object *AND* the y as well as the z-axis. To compensate you have to change the world y-axis to the rotated one. This can be easily done by appling the 1st rotation on the y-axis unit vector (0.0,1.0,0.0). The result of this rotation is the former y-axis of your rotated object. Use the rotated y-axis as axis parameter for glRotate and the result should be what you are looking for.

Michael

Share this post


Link to post
Share on other sites
... ok my explanatioon was probably at least as cryptic as yours so let me try some example code. i cant give any guarantees that it will be correct, since its 4am here and i have no way to test this right now. but i can still try.

void MultMatrix(float *matrix,float *vector)
{
float result[4];

for (int j=0;j != 4;j++){
result[j] = matrix[j*4] * vector[0];
result[j] += matrix[j*4 + 1] * vector[1];
result[j] += matrix[j*4 + 2] * vector[2];
result[j] += matrix[j*4 + 3] * vector[3];
}
vector[0] = result[0];
vector[1] = result[1];
vector[2] = result[2];
vector[3] = result[3];
}

.......

float matrix[4][4];
float yaxis[4] = {0.0,1.0,0.0,0.0};

glLoadIdentity()
glRotatef(anyangle,1.0,0.0,0.0);
glGetFloatv(GL_MODELVIEW_MATRIX,matrix);
MultMatrix(matrix,yaxis);
glRotatef(anyangle2,yaxis[0],yaxis[1],yaxis[2]);

... et voila... that should be it assuming i guessed correct which way GL and C orient arrays... if not you have to play around with the rows and colums of the matrix.

Michael

[edited by - plasm on August 17, 2003 10:12:03 PM]

[edited by - plasm on August 17, 2003 10:14:36 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think he wants to rotate around a global fixed coordinate system. The answer is just to reverse the order of the rotations!
In your example should you first rotate around the Y-axis followed by the rotation around the X-axis.

Euler vs fixed angles is really the same thing as local vs global coordinate system. This is covered in the red book.

Share this post


Link to post
Share on other sites
Hmm... i''m not sure if were referring to the same thing but, what i was thinking is if i do a glrotate, the y-axis and z-axis changes ryt? This means that if i roate by (0,1,0) im going to rotate along the "transformed" y-axis.
Lets say I have a point, i rotate it by 45 degrees along the x-axis. Then i rotate the point again by the original y-axis and not the transformed one. The final location of the point is the effect i want to get. How do i get this using glrotatef?

Share this post


Link to post
Share on other sites
> what i was thinking is if i do a glrotate, the y-axis and z-axis changes ryt?
Correct.

> This means that if i roate by (0,1,0) im going to rotate along the "transformed" y-axis.
You rotate by the y-axis. But its not the original y-axis of the object since the 1st rotation was already applied.

> Lets say I have a point, i rotate it by 45 degrees along the x-axis. Then i rotate the point again by the original y-axis and not the transformed one.
To do that you have to apply the 1st rotation to your 'transformed y-axis'. I tried to do that in my example. Not sure if it does that.

Michael

[edited by - plasm on August 17, 2003 10:55:59 PM]

Share this post


Link to post
Share on other sites
the easiest way if you want to do it global instead of local:
glGetFloatv(GL_MODELVIEW_MATRIX,matrix);
glRotatef(angle,matrix[1],matrix[5], matrix[9]);

simply using the transposed.. or use mutliply and switch the matrices, the question of local or global is just a matter of if your matrix is on the left or right side of the multiplication.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Trienco
mutliply and switch the matrices, the question of local or global is just a matter of if your matrix is on the left or right side of the multiplication.


This was exactly my suggestion and is by far the easiest solution in my opinion. A combination of rotations around X-Y-Z has two interpretaions. You can think of a local coordinate systems rotated around X-Y-Z. Or you can think in terms of a fixed coordinate system and then is the order reversed to Z-Y-X. Both interpretations is correct and useful.

Its really non-iniutive to find that reversing the order of rotations switches between local and fixed coordinate systems. Rotating the model or the coordinate system is like moving the camera or the model.

Share this post


Link to post
Share on other sites
hehe, i always hated that "opengl is doing things backward" explanation. without thinking in local coordinates you will have a pretty hard time in some situations anyway. and what headache would it cause to think "backwards" when rendering a complex hierarchical model?

Share this post


Link to post
Share on other sites

  • Advertisement