Archived

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

Rotate arounf an axis.

This topic is 5584 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

Im new to opengl and would just like to know how do i make an object rotate on another axis than one his own..want to make multiple rotate at a time and dont know how..

Share this post


Link to post
Share on other sites
When you create an boject, you declare the vertices.
Often you declare them around 0. if you declare them around 100(x) then it would be far on the right side. And when you rotate that object it would rotate around the 0, and not the center of itself.

Hope this helps but I think you mean rotate an object around another object?

Share this post


Link to post
Share on other sites
yep exactly, here''s the exatc situation, i have a 3d object at -30 on the z axis that rotate on its own y axis, and i want another object farther in -45 on the z axis to rotate on the same axis as the 3d object, is there some code i have to put between the two object so that their propiety wont interfer?

Share this post


Link to post
Share on other sites
hmmm, i think you need to that sort of transformation on your own. with 3d math and such. im not entirely sure on the math, but i think you need to minus the position vector of the stationery object away from the position vector of the other object first.
ie. vector.x = object1.x - object2.x;
vector.y = object1.y - object2.y;
the new vector created from that will be what you use to rotate the object around the point. the mathematical explanation is long and boring (never did like math that much)... the beauty of learning it, is that its used so frequently that you''ll probably write it once and never touch it again.

Get busy livin'' or get busy dyin''... - Shawshank Redemption

Share this post


Link to post
Share on other sites
scratch the first line of my reply... you could do it in opengl by using the matrix stack and pushing and popping the stack... but i think my other suggestion is more fun :D

Get busy livin'' or get busy dyin''... - Shawshank Redemption

Share this post


Link to post
Share on other sites
Just when you translate to the object rotate it, draw it, and then roatate it back:

glTranslatef(0,0,-30)
glRotatef(variable,0,1,0);
DrawObject();
glRotatef(-variable,0,1,0);
glTranslatef(0,0,-15)
glRotatef(variable,0,1,0);

hope it helped.

Share this post


Link to post
Share on other sites
i think i understand what you mean, suppose i have a 3d object in a center of a room, i want the 3d object to rotate on its own y axis, and i want the four room walls to rotate on that same axis exactly at the same point but counterclockwise, what would be the translate, draw and rotate order?

Share this post


Link to post
Share on other sites
Since you said the object is in the center of the room you should only tranlsate once to the center of the room:


glTranslatef(0,0,-30) //move to the center of room
glRotatef(variable,0,1,0); //rotate to the room''s roatation
DrawRoom();
glRotatef(-variable,0,1,0); //rotate the matrix back
//glTranslatef(0,0,-15); //dont need anymore
glRotatef(variable2,0,1,0); //rotate the object with a different variable
DrawObject(); //draw the object
glRotatef(-variable2,0,1,0); //rotate the matrix back if you want


you could also draw the object first, or instead of rotating back, just loadIdentity(); (check this command) to reset the position of everything afterwards.

the translate and rotate commands affect everything after they are used.

try using them a bit till you get the hang of it.

Share this post


Link to post
Share on other sites