Rotation woes
Hi. I''m writing a demo at the moment using my own model format I''m devising. I''m having some trouble with rotation. My model format does not store individual frame vertex data, but the rotation and position information for individual "segments" such as arms and legs.
The problem is, when I tell the program to rotate an individual segment using glRotatef*(), it rotates it around the origin. I would like to use a rotation function which rotates the segment around a specified point (or joint - if your''e with me. E.g. Rotate the forearm around the elbow, not around the center of the forearm), ignoring the origin, very much like the rotate around user point routine in Milkshape 3D...
Any ideas, any feedback would be useful.
Thanks, all the best, Dan
Transformers Rulez!!
Transformers Rulez!!
Look into md3 format (quake3). It has this kind of structure. And there are tons of viewers with cource code for this format. The point is that you translate first and then rotate...
You should never let your fears become the boundaries of your dreams.
quote:
The point is that you translate first and then rotate...
Actually, in OpenGL, you have to rotate then translate. Rotations always happen around the origin, so if the object is away from the origin (i.e. tranlation first) it will rotate around the origin and not around it''s own axis.
You need to move the forearm to the origin, rotate in relation to the rotations already existing in the elbow, then translate it back to the position of the elbow. I''m assuming that you forearm has it''s point of rotation at it''s own elbow position. You can encapsulate this functionality, so all you have to do is tell it the rotations.
Here are a few tips:
-Use matricies (research translation matricies and rotation matricies)
-To rotate a joint about a certain point:
1.create a translation matrix which moves that point back to the origin
2.create a rotation matrix for the rotation you want to do
3.create a translation matrix to move back to the original position
4.Now multiply all these matricies in this order:
-multiply the matrix from step 1 to 2
-then multiply that matrix to step 3
-Now all you have to do is multiply this matrix to the verticies (treat the verticies like a matrix) and you have you point rotated about the joint you specified
Simple right
Note: you could multiply your matricies through all your points when you create your matrix but its faster to multiply them to each other then to the verticies. And this way you can only store one matrix.
Hope that helped.
Ancient Wisdom:
"Copy and paste fills the page, coding fills the mind...and the debugger."
-Use matricies (research translation matricies and rotation matricies)
-To rotate a joint about a certain point:
1.create a translation matrix which moves that point back to the origin
2.create a rotation matrix for the rotation you want to do
3.create a translation matrix to move back to the original position
4.Now multiply all these matricies in this order:
-multiply the matrix from step 1 to 2
-then multiply that matrix to step 3
-Now all you have to do is multiply this matrix to the verticies (treat the verticies like a matrix) and you have you point rotated about the joint you specified
Simple right

Note: you could multiply your matricies through all your points when you create your matrix but its faster to multiply them to each other then to the verticies. And this way you can only store one matrix.
Hope that helped.
Ancient Wisdom:
"Copy and paste fills the page, coding fills the mind...and the debugger."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement