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

Author Topic: Rotate a shape around a point  (Read 6645 times)

0 Members and 1 Guest are viewing this topic.

chhenning

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Rotate a shape around a point
« on: February 15, 2015, 06:57:51 pm »
Hi all,

In SFML how would I rotate a shape around some point which is outside the shape's boundary, using transformations? I know how to use cos and sin but like to understand how to use transformation.

Here is one example:

    // Draw circle at center
    sf::CircleShape c;
    c.setFillColor(sf::Color::Red);
    c.setPosition(width / 2, height / 2 - 100);
    c.setRadius(50);
    c.setOrigin({50, 50});


    while(true)
    {
        window.clear(sf::Color::Black);

       
        // rotate around center of screen

        window.draw(c);

        window.display();
    }
 

Thanks all!

Christian


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Rotate a shape around a point
« Reply #1 on: February 15, 2015, 06:59:35 pm »
sf::Transform transform;
transform.rotate(angle, center);
window.draw(c, transform);
Laurent Gomila - SFML developer

chhenning

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Rotate a shape around a point
« Reply #2 on: February 15, 2015, 08:25:13 pm »
Thanks, that's exactly what I was looking for!