Matrix Math and 3D rotations

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

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 = tax.xax.x+c; mat.m._01 = tax.xax.y-sax.z; mat.m._02 = tax.xax.z+sax.y; mat.m._03 = 0.0f;
mat.m._10 = tax.xax.y+sax.z; mat.m._11 = tax.yax.y+c; mat.m._12 = tax.yax.z-sax.x; mat.m._13 = 0.0f;
mat.m._20 = tax.xax.z-sax.y; mat.m._21 = tax.yax.z+sax.x; mat.m._22 = tax.zax.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).]

I also have something like that in my mathematics library… but don’t know why it works.

here you can find the math which is used for glRotate
http://shiva.missouri.edu:88/SGI_Developer/OpenGL_PG/28051#X

Chris

The link doesn’t work

I found it really crappy that my mathematics teacher couldn’t explain that to me…

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

try this one http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html

Thnx! works ok but doesn’t enlighten me in a theoretical way… :wink: Anyway… my code works… :wink:

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

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

Thank you very much!

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???

not over yet
http://www.makegames.com/3drotation/

Hi
I use code from mesa. www.mesa3d.org
Download source and take a look at matrix.c

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

I actually have working code, so I only need to understand it…