SFML community forums

Help => Graphics => Topic started by: ScriptingTacos on July 16, 2015, 06:10:01 pm

Title: Rotating a RectangleShape according to another RectangleShapes origin
Post by: ScriptingTacos on July 16, 2015, 06:10:01 pm
I want to be able to rotate a rectangle using another rectangles origin
So I thought I would have to do this:

rect2.setOrigin(rect1.getOrgin());

But that made rect2 rotate differently.
Any help?
Title: Re: Rotating a RectangleShape according to another RectangleShapes origin
Post by: eXpl0it3r on July 16, 2015, 06:14:02 pm
All transformations are applied relative to the origin. If you set the origin to the top left corner (default) your rectangle shape will rotate around the top left corner. If you set the origin to the middle of the rectangle shape it will rotate around its center.

As such the origin is local to an object and if you "copy" the origin of another rectangle shape, you'll just copy the local origin. If you want to rotate around another object, you need to use the global position instead:

rect2.setOrigin(rect.getPosition());
Title: Re: Rotating a RectangleShape according to another RectangleShapes origin
Post by: ScriptingTacos on July 16, 2015, 06:31:20 pm
All transformations are applied relative to the origin. If you set the origin to the top left corner (default) your rectangle shape will rotate around the top left corner. If you set the origin to the middle of the rectangle shape it will rotate around its center.

As such the origin is local to an object and if you "copy" the origin of another rectangle shape, you'll just copy the local origin. If you want to rotate around another object, you need to use the global position instead:

rect2.setOrigin(rect.getPosition));

This did work but it sets rect2 far from the rect1
If I try to move it closer to rect1 also moves rects2 orgin
Title: Re: Rotating a RectangleShape according to another RectangleShapes origin
Post by: eXpl0it3r on July 16, 2015, 06:55:39 pm
You really need to understand how the transformations (translation, rotation and scale) works, what roles position and origin have and how global and local space operate.
Once you got that, it's trivial to implement whatever you're trying to implement. ;)