SFML community forums

Help => General => Topic started by: rogeriodec on April 25, 2018, 10:18:28 pm

Title: What is the best way to group objects in SFML?
Post by: rogeriodec on April 25, 2018, 10:18:28 pm
If I have for example 3 different shapes in SFML, and I want to rotate them all relative to a single center, as if these 3 shapes were inside a square, what would be the best shape?
Would it be leaving them inside a view and rotating the view?
Or is there some more practical way?
Title: Re: What is the best way to group objects in SFML?
Post by: Tigre Pablito on April 27, 2018, 04:46:23 pm
Hi

You can set the centre (x, y) around which the shapes will move, then decide the starting angle (in radians) of each shape (from the centre), and the distance, then on each frame each shape's (x, y) = (centreX + cos(angle) * distance, centreY + sin(angle) * distance) and increase angle (when angle >= 360 then angle -= 360). Also each shape's Rotation = angle (in degrees).

I think this is the best way.

Other is to draw the shapes to a RenderTexture and rotate it, but I don't think it's good.