View Full Version : Matrix Math and 3D rotations
04-10-2001, 11: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,
04-10-2001, 12:39 PM
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)
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;
Hopefully that formats alright.
[This message has been edited by LordKronos (edited 04-10-2001).]
04-11-2001, 02:01 AM
I also have something like that in my mathematics library... but don't know why it works.
04-11-2001, 02:08 AM
here you can find the math which is used for glRotate
04-11-2001, 02: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...
04-11-2001, 02: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.
04-11-2001, 02:28 AM
try this one http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html
04-11-2001, 02:43 AM
Thnx! works ok but doesn't enlighten me in a theoretical way... ;-) Anyway... my code works... ;-)
04-11-2001, 02:55 AM
maybe this one helps you a little more
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).]
04-11-2001, 03:00 AM
http://www.opengl.org/discussion_boards/ubb/smile.gif Thank you very much!
04-11-2001, 03: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
04-11-2001, 03:13 AM
not over yet http://www.opengl.org/discussion_boards/ubb/biggrin.gif
04-11-2001, 03:14 AM
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).]
04-11-2001, 03:33 AM
I actually have working code, so I only need to understand it... http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.