PDA

View Full Version : How to keep track of transformation position

Fier
04-05-2004, 06:20 AM
Hello everyone,
I am currently has a problem cannot be solved. Really hope you guys can help me out.

I have a object(say a sphere at point 3,3,3) rotating around a point(say origin) in an arbitrary direction. These are the code.

//start at origin of world space
glLoadIdentity();

glPushMatrix();

//rotating ang1 around y-ax, so cursor will be at z=3 position
glRotatef(ang1, 0,1,0);
//rotating ang2 around z-ax, so cursor will be at y=3 position
glRotatef(ang2, 0,0,1);

//rotating the object coordinate around its a axis, this changes the rotational path the object can rotate around the origiin.

glRotatef(rotPathDegree, 1,0,0);

//rotate around object's z axis, so it can rotate 'rotDegree" degrees around the origin on the direction path.
glRotatef(rotDegree, 0,0,1);

//move alone the object's new x-axis, it will reach 3,3,3
glTranslatef(3, 0,0);

drawTheSphereFunction();

glPopMatrix();

Ok, I know this sounds complicated, but this is what I have to do to make an object rotate around a point in ANY path. Now the question is, How do I keep track of the object (sphere)'s coordinate after all this rotation and tranformation?

Any help would be very very thankful, thank you a lot.

ce110ut
04-05-2004, 03:06 PM
see this thread (http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=015985) .

i hope that helps.

-=[ regards ]=-

ioquan
04-05-2004, 07:35 PM
This is a problem of overdependence on glRotate and glTranslate. In my opinion, you should not be using glRotate/glTranslate in this way. For every object in your scene you should keep track of its origin and orientation manually. Then you use one glRotate and one glTranslate to position the object when you draw it, or better yet, one call to glMultMatrixd. You should have all of your object's origin's and orientations stored at all times.

What you are trying to do is mix your physics code and your drawing code. That is not a good idea.