Rotate arounf an axis.

Started by
7 comments, last by AngelBass 21 years, 7 months ago
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..
Advertisement
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?
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?
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
Get busy livin' or get busy dyin'... - Shawshank RedemptionIf a man is talking in the forest, and no woman is around to hear him, is he still wrong? - UnknownFulcrum
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
Get busy livin' or get busy dyin'... - Shawshank RedemptionIf a man is talking in the forest, and no woman is around to hear him, is he still wrong? - UnknownFulcrum
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!
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.

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?
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.

This topic is closed to new replies.

Advertisement