PDA

View Full Version : Matrix Math and 3D rotations



JamesD
04-10-2001, 10:28 AM
Does anyone out there know how to rotate a 3D point about an arbitrary axiz. I know how to rotate about the x,y, and z-axis, but would like to write a function that mirrors the glRotatef() function.
Thanks a lot,
James
-James@dempsey.net

LordKronos
04-10-2001, 11:39 AM
This is from my matrix class. You should be able to get what you want from it. If you want a description of how/why it works, well....thats a bit more difficult, so I will skip that unless you REALLY want to know




CMatrix CMatrix::getRotation(const CVector &axis, const float degrees)
{
CMatrix mat;
CVector ax = axis.normalized();

float rad = degrees * 3.14159f / 180.0f;
float c = cosf(rad);
float s = sinf(rad);
float t = 1.0f - c;

mat.m._00 = t*ax.x*ax.x+c; mat.m._01 = t*ax.x*ax.y-s*ax.z; mat.m._02 = t*ax.x*ax.z+s*ax.y; mat.m._03 = 0.0f;
mat.m._10 = t*ax.x*ax.y+s*ax.z; mat.m._11 = t*ax.y*ax.y+c; mat.m._12 = t*ax.y*ax.z-s*ax.x; mat.m._13 = 0.0f;
mat.m._20 = t*ax.x*ax.z-s*ax.y; mat.m._21 = t*ax.y*ax.z+s*ax.x; mat.m._22 = t*ax.z*ax.z+c; mat.m._23 = 0.0f;
mat.m._30 = 0.0f; mat.m._31 = 0.0f; mat.m._32 = 0.0f; mat.m._33 = 1.0f;

return mat;
}


Hopefully that formats alright.

[This message has been edited by LordKronos (edited 04-10-2001).]

Michael Steinberg
04-11-2001, 01:01 AM
I also have something like that in my mathematics library... but don't know why it works.

DaViper
04-11-2001, 01:08 AM
here you can find the math which is used for glRotate
http://shiva.missouri.edu:88/SGI_Developer/OpenGL_PG/28051#X

Chris

Michael Steinberg
04-11-2001, 01:15 AM
The link doesn't work http://www.opengl.org/discussion_boards/ubb/frown.gif

I found it really crappy that my mathematics teacher couldn't explain that to me...

DaViper
04-11-2001, 01:25 AM
hmm the link works for me... but I don't think its something new for you, because its juts the Matrix-Appendix of the Red Book.

Chris

DaViper
04-11-2001, 01:28 AM
try this one http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html

Michael Steinberg
04-11-2001, 01:43 AM
Thnx! works ok but doesn't enlighten me in a theoretical way... ;-) Anyway... my code works... ;-)

DaViper
04-11-2001, 01:55 AM
maybe this one helps you a little more

http://chesworth.com/pv/graphics/3d/the_3d_coding_blackhold_tutorial.htm#Trigo

if it doesn't I am getting in trouble, because i am running out of bookmarks http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by DaViper (edited 04-11-2001).]

Michael Steinberg
04-11-2001, 02:00 AM
http://www.opengl.org/discussion_boards/ubb/smile.gif Thank you very much!

Michael Steinberg
04-11-2001, 02:03 AM
This pages uses the easiest attempt creating three rotation matrices around the major axes and multiplies them together. No rotation around a vector.

Now, where's your next bookmark??? http://www.opengl.org/discussion_boards/ubb/smile.gif

DaViper
04-11-2001, 02:13 AM
not over yet http://www.opengl.org/discussion_boards/ubb/biggrin.gif
http://www.makegames.com/3drotation/

Michail Bespalov
04-11-2001, 02:14 AM
Hi
I use code from mesa. www.mesa3d.org (http://www.mesa3d.org)
Download source and take a look at matrix.c


[This message has been edited by Michail Bespalov (edited 04-11-2001).]

Michael Steinberg
04-11-2001, 02:33 AM
I actually have working code, so I only need to understand it... http://www.opengl.org/discussion_boards/ubb/smile.gif