Archived

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

ATronic

Rotation Formula

Recommended Posts

Hey all, I was wodering what math was involved in the rotation operations in opengl. See, I''m trying to do specialized rotations with static points on a triangle, and you can''t do that due to restrictions as to what commands may be used with in an opengl drawing area (ie: glbegin() glend()). So what would the code be for a custom rotation? Such as: myVertex Rotate(myVertex point, GLfloat degrees, myVector axis); that returns the point after it has been rotated about an axis (like the glrotate function). Thank you very much to anyone who helps me out with this. Posting here is fine, but it would be even better if someone could e-mail this to me at alexb@a-tronic.com Thanks Again!! Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
Well, here''s the mathematical view, and then you can determine how to code it yourself...

For starters (now sure how much of that will be useful), you might consider checking out the other topic on rotation that''s currently here. However, there I didn''t cover an arbitary axis.

So let''s say you''re making this call... (I''m laying it out as if it were to be written mathematically)

  
[ X'' ] [ X ] [ x ]
[ Y'' ] = MyRotate ( [ Y ], a, [ y ] )
[ Z'' ] [ Z ] [ z ]


where {X, Y, Z} is the vertex (and {X'', Y'', Z''} is the output vertex), a is the angle in degrees, and {x, y, z} is the vector to rotate about.

As I found at http://www.makegames.com/3drotation/, the rotation matrix about an arbitrary axis will be...

  
[ tx^2 + c txy - sz txz + sy 0 ]
[ txy + sz ty^2 + c tyz - sx 0 ]
[ txz - sy tyz + sx tz^2 + c 0 ]
[ 0 0 0 1 ]


for t = cos(a), s = sin(a), and c = cos(a)

As I mentioned in the other topic, the rotation matrix is the upper-left 3-by-3 matrix of the modelview matrix. So just take that subset and multiply it by your input vector to get your output vector, like so...

  
[ X'' ] [ tx^2 + c txy - sz txz + sy 0 ] [ X ]
[ Y'' ] = [ txy + sz ty^2 + c tyz - sx 0 ] * [ Y ]
[ Z'' ] [ txz - sy tyz + sx tz^2 + c 0 ] [ Z ]


and voila! Your vertex after rotation is returned to you.

Hope this helps!

~ Dragonus

Share this post


Link to post
Share on other sites