Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: What is the best way to group objects in SFML?  (Read 1870 times)

0 Members and 2 Guests are viewing this topic.

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
What is the best way to group objects in SFML?
« 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?

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: What is the best way to group objects in SFML?
« Reply #1 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.

 

anything