Archived

This topic is now archived and is closed to further replies.

Rotation around an arbitrary vector

This topic is 6587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

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

Share this post


Link to post
Share on other sites
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.

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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).]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites