Rotation around an arbitrary vector

Started by
4 comments, last by BigCarlito 24 years, 4 months ago
Hi
I’ve had a similar problem for quite a while. Here I’ll describe rotation around an arbitrary point.
The trick is that you must move to the arbitrary point FIRST and then do the rotation. Like this:

gltranslatef(p.x,p.y,p.z);

glRotatef(ang.x,1,0,0);
glRotatef(ang.y,0,1,0);
glRotatef(ang.z,0,0,1);
gltranslatef(-p.x,-p.y,-p.z);
glGetfloatv(GL_MODELVIEW_MATRIX,@m1);

I’m to lazy to do my own matrix calculations, but I think that 3d cards will accelerate this soon. If it’s slower to read the matrix from the OpenGl pipeline please somebody correct me.

God luck.
Ajasja.

------------------

Advertisement
Hi
I’ve had a similar problem for quite a while. Here I’ll describe rotation around an arbitrary point.
The trick is that you must move to the arbitrary point FIRST and then do the rotation. Like this:

gltranslatef(p.x,p.y,p.z);

glRotatef(ang.x,1,0,0);
glRotatef(ang.y,0,1,0);
glRotatef(ang.z,0,0,1);
gltranslatef(-p.x,-p.y,-p.z);
glGetfloatv(GL_MODELVIEW_MATRIX,@m1);

I’m to lazy to do my own matrix calculations, but I think that 3d cards will accelerate this soon. If it’s slower to read the matrix from the OpenGl pipeline please somebody correct me.

God luck.
Ajasja.

------------------

Yep, that will work for rotating around a point, but I need the object to SPIN in a certain direction.
Let's say the player is facing in the direction (-1,0,1), which in my world coordinates is to the left and into the screen. Then when he shoots the ball, the ball should spin (assuming his shot is a little more fundamentally sound than mine) backwards along that vector, so back and to the right. Hope I didn't confuse everyone more:-)

P.S. What about quaternions, I've had a difficult time grasping them, but I know there is a vector and scalar in there and they can represent rotations. Does anyone know how the vector relates to the direction of rotation?

Thanks for all replies!

You can set glrotate() to an arbitrary unit vector(i think). It doesn't need to be aligned along the X, Y, or Z axis. If you check out the manual page on opengl.org it'll give you the actual transformation matrix used(if you're not using openGL)

[This message has been edited by logistix (edited November 30, 1999).]

-the logistical one-http://members.bellatlantic.net/~olsongt
Hi everyone, in my game there is a basketball. Now when then the ball gets shot or rolls around, I want the ball to spin appropriately. I know how to make a matrix for rotation around the x,y, or z axis, but what about rotation around an arbitrary vector? Anyone have a slick solution for this one? Thanks!
You're right, I couldn't find it on the website, but it is in the back of the OpenGL Reference Manual. Thanks!

This topic is closed to new replies.

Advertisement