PDA

View Full Version : problems with rotations



brett01
09-13-2009, 04:35 PM
hi,

I am having a problem with a simple rotation problem.I have attached a rectangle to a coordinate axes such that one of its vertices align with the origin.I want to translate rectangle center to the origin and rotate the rectangle with respect to the current center.
In init() I translated rectangle's center to origin.Now I need to rotate it in run(). what Ive done is
init()
{
translate(T);
scale(s);
rectangle();
}
in run()
{
gltranslate(-T)
rotate(x,1,0,0);
gltranslate(t);

}
The problem is the rectangle is always rotating wrt to the vertex but not the center of the rectangle.what is the problem with my code??Can someone help me please.

Thank you.

todayman
09-13-2009, 04:49 PM
What happens if you leave out the translates in run() out? That will change the center of rotation.

brett01
09-13-2009, 05:00 PM
glrotate(x,1,0,0);
gltranslate(t)
glscale(s);
rectangle();

Is this thing right??This thing dont work for me.I want to rotate the rectangle about its center.I also want to do the scale about the center.Thanks in advance.

brett01
09-13-2009, 05:43 PM
What happens if you leave out the translates in run() out? That will change the center of rotation.

I removed the translates out it doesnt work!! Its rotating with the vertex as center.

what should my matrix transforms order be??Otherwise Im just setting the matrix directly in run() what Ive to do,

S*R*T is not working??

brett01
09-13-2009, 06:57 PM
Thank you very much.I did it.