Archived

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

Rotate arounf an axis.

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

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 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 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 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 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 on other sites
Ok ill try to figure this out, if you see any source as an example with that code beeing used please tell me, and thx!

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 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 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 roomglRotatef(variable,0,1,0); //rotate to the room''s roatationDrawRoom();glRotatef(-variable,0,1,0); //rotate the matrix back//glTranslatef(0,0,-15); //dont need anymoreglRotatef(variable2,0,1,0); //rotate the object with a different variableDrawObject(); //draw the objectglRotatef(-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.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×