🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Matrix math for OPENGL

Started by
0 comments, last by Max 24 years, 8 months ago
I've been stuck on this particular routine for a couple of weeks now and I need help.

The routine I need is a function that would calculate a 4x4 rotation matrix in opengl around an arbitrary point (vertex T(x,y,z,w)) based on a previous matrix. Something like

function RotateAroundAoint(point,angx,angy,angz,matrix): matrix.

for example:

glLoadidentity;

gltranslatef(10,-1,5);

glRotatef(20,10,-30);

glGetfloatv(GL_MODELVIEW_MATRIX,@m);

M:=RotateAroundPoint(Vetex(1,2,3,1),10,20,40,M)

GlLoadMatrixfv(@m);

DrawScene;

So if somebody could help me with some code or an precise idea how I could do this I would really appreciated it.

Advertisement
Are you just doing this for rendering purposes? For stuff like weighed verticies and collision detection, you might need to calculate your own matrix, but for the rendering you should let openGL do it. Right now only GeForce would accelerate it but you still want to keep things in the GL pipeline if possible.

If the order isn't extremely important, you just do the transformation and rotations at the arbitrary point BEFORE your other transformations:


glTranslatef(...)
glRotatef(...) // X-axis
glRotatef(...) // Y-axis
glRotatef(...) // Z-axis

THEN

// from your code
gltranslatef(10,-1,5);
glRotatef(20,10,-30);

and this will achieve the same effect. If you absolutely positively have to rotate around the point after the fact, I believe you could load the matrix into memory, loadIdentity(), perform transformation/ rotation, and then multiply the matrix by the one stored in memory(although I haven't tried it out.)

Good luck.

This topic is closed to new replies.

Advertisement