Archived

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

Rotation around an arbitrary vector

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

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 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 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 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 on other sites
You're right, I couldn't find it on the website, but it is in the back of the OpenGL Reference Manual. Thanks!

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!

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×