glMultMatrixf and rotations
I want to set a matrix up to store rotations for all my objects. Since if you call glRotate three times for each matrix the result will depend on the order, etc.
So by default each objects rotation matrix is set to the identity matrix. So there should be no change when I multiply the current matrix with glMultMatrixf. But it messes it all up when I do that. Here is some code.
So each objects rotation is set to that, then the drawing code.
If I comment out the glMultMatrixf it looks fine. Every thing is where it should be. But it should be the same since I multiply it with the identity matrix.
If there is another way to get the rotations I need, that would work too.
So by default each objects rotation matrix is set to the identity matrix. So there should be no change when I multiply the current matrix with glMultMatrixf. But it messes it all up when I do that. Here is some code.
Code:
rotMatrix[0] = 1; rotMatrix[4] = 0; rotMatrix[8] = 0; rotMatrix[12] = 0;// Set rot matrix to identity matrix
rotMatrix[1] = 0; rotMatrix[5] = 1; rotMatrix[9] = 0; rotMatrix[13] = 0;
rotMatrix[2] = 0; rotMatrix[6] = 0; rotMatrix[10] = 1; rotMatrix[14] = 0;
rotMatrix[3] = 0; rotMatrix[7] = 0; rotMatrix[11] = 0; rotMatrix[15] = 1;
So each objects rotation is set to that, then the drawing code.
Code:
glPushMatrix();
glTranslatef(tempModel>xPos, tempModel>yPos, tempModel>zPos); // Translate To the models position
glMultMatrixf(tempModel>rotMatrix);
tempModel>Draw(); // draw the model
glPopMatrix();
If I comment out the glMultMatrixf it looks fine. Every thing is where it should be. But it should be the same since I multiply it with the identity matrix.
If there is another way to get the rotations I need, that would work too.
My guess is that the matrix isn't the identity. Try printing it just before you call multmatrix to check.
Technically, the code you wrote works. I actually copied and pasted it in a test project and it works fine. So the matrix you defined IS the identity matrix. So the problem lies somewhere else (uninitialized memory for example).
Make sure the initialization block of code is properly executed.
good luck!
Make sure the initialization block of code is properly executed.
good luck!
 Sohta
Are you in the correct matrix mode? (model view)
Kelvin
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Come to think of it, glRotatef could pretty well do what you need. It depends what kind of rotation you want. You can define any single 3D rotation with two calls to glRotatef.
it's just a matter of splitting your rotation along those two components.
Also, if you know the arbitrary axis along wich you want to rotate tyour object, you can simply give that axis to glRotatef. For example, if I want to rotate 90 degrees along the X = Y, Z=0 axis, i would call
The last three parameters of the glRotatef function represent a normalized (I think) vector along wich to rotate.
Nevertheless, your approach should work too.
Code:
glRotatef(xRot,1.0,0.0,0.0);
glRotatef(yRot,0.0,1.0,0.0);
it's just a matter of splitting your rotation along those two components.
Also, if you know the arbitrary axis along wich you want to rotate tyour object, you can simply give that axis to glRotatef. For example, if I want to rotate 90 degrees along the X = Y, Z=0 axis, i would call
Code:
glRotatef(90.0,0.7071,0.7071,0.0);
The last three parameters of the glRotatef function represent a normalized (I think) vector along wich to rotate.
Nevertheless, your approach should work too.
 Sohta
Thanks for all the input. I completely got rid of using matrices for rotations. I decided to go with quaternions instead.
It works great since I have fixed rotation coordinates now. If a want to rotate an object relative to its position, I simply take its orientation vectors against the rotation degree before putting it into the quaternion.
I still don't get why the matrix when multiplied got messed up.
It works great since I have fixed rotation coordinates now. If a want to rotate an object relative to its position, I simply take its orientation vectors against the rotation degree before putting it into the quaternion.
I still don't get why the matrix when multiplied got messed up.
Well, I figured out the problem. Everything was fine but the matrix I created was m[15] not m[16]. Very lame.
But I might need to use them, since it would would be faster to go from a quaternion to a matrix and then use glMultMatrix instead going from a quaternion to axis and angles and then using glRotatef. It would be faster since glRotatef will multiply the current matrix anyway, and first it will calculate the rotation matrix, right? glMultMatrix would be more direct, no?
But I might need to use them, since it would would be faster to go from a quaternion to a matrix and then use glMultMatrix instead going from a quaternion to axis and angles and then using glRotatef. It would be faster since glRotatef will multiply the current matrix anyway, and first it will calculate the rotation matrix, right? glMultMatrix would be more direct, no?
glMultMatrix does the same work, but it is fast to create a matrix from a quaternion, and you let OpenGL do the matrix multiply, which may be faster than doing it manually.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
AxisAngle Rotations  DoG  2  4,075 
Apr 21, 2006 05:16 PM Last Post: DoG 

World and Object Rotations (Quaternions Are Killing Me)  Nickolei  3  6,148 
Feb 14, 2005 06:12 PM Last Post: Nickolei 

glMultMatrixf(): rotation order?  Feanor  4  10,746 
Jul 13, 2002 09:19 AM Last Post: codemattic 