I am trying to rotate an object (say a sphere at 3,3,3) around a point (say at 1,1,1). The rotation can go any arbitary direction, I think (not sure) I should use two angle to decide the direction (angel to rotate on xy plane and xz plane).
Can anyone help me?
note: I need to rotate the object to any direction, not the axis.
To rotate an object around an arbitary position in 3D space - the best way of doing that is to consider the concept of Local and World coordinate systems and order of operations inside a pushed matrix.
Let’s look at what you should have.
a DrawSphere() function that draws a sphere with radius r around the local coordinate system point (0,0)
glTranslatef(); function that we will use to move the sphere to a given point
and glRotate3f(); function that will rotate the object at a specified angle in any of the three axis.
It’s simply a matter of putting those functions as a correct combination inside it’s own transformation Matrix, remembering that we do this in REVERSE order to how we could conceptually see it:
You can move the rotation axis to any point using glTranslate.
You must remember that matrix calls work in reverse, and all rotations are done from 0,0,0.
glTranslate(…); Where the new axis of rotation is the be, example if we wanted to orbit around 10,10,10 in stead of 0,0,0
glRotate(…); Rotate sphere from some Radius (or think of orbit of a planet around the sun, the sun beening 0,0,0)
glTranslate(…); Radius of rotation, from 0,0,0
glRotate(…); Rotate sphere on it’s axis
Draw_sphere();
Just to clear things up do you want to object to spin on its axis at some point or orbit like a moon around the earth at that point?
Originally posted by Fier: I tried the code u given, it ends up he object is rotating around distant point’s AXIS rather than the around the distant point itself.