SFML community forums

Help => Graphics => Topic started by: habed123 on May 26, 2021, 08:18:06 am

Title: How do I make a circle rotate in a bigger circumference
Post by: habed123 on May 26, 2021, 08:18:06 am
#include <SFML/Graphics.hpp>
// done -- orbitting circle



int main()
{
    sf::RenderWindow window(sf::VideoMode(1000, 1000), "SFML works!");
    window.setFramerateLimit(10);

    sf::CircleShape shape(50.f);
    shape.setFillColor(sf::Color::Black);
    //orbit


    sf::CircleShape shapeTwo(50.f);
    shapeTwo.setFillColor(sf::Color::Red);
    //base

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);

        shape.setPosition(500.f, 500.f);
        shape.rotate(10.f);
        shape.setOutlineThickness(10);
        shape.setOutlineColor(sf::Color(255, 255,255));
        //orbit

        window.draw(shapeTwo);
        shapeTwo.setPosition(450.f, 450.f);
        shapeTwo.setOutlineColor(sf::Color::White);
        //base

        window.display();
    }

    return 0;
}
 

This is my code. I want the circles to be able to rotate in a bigger range instead of just around it's origin/center/whatever.

Is this possible?
Title: Re: How do I make a circle rotate in a bigger circumference
Post by: Stauricus on May 26, 2021, 01:22:37 pm
you need to:
1) change the shape's origin to the center of the translation circle, or
2) calculate it manually with sin and cos:

(click to show/hide)
Title: Re: How do I make a circle rotate in a bigger circumference
Post by: G. on May 26, 2021, 02:55:39 pm
3) or use transform.rotate (https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transform.php#af0b7cc3fed36d0fa22d5d331a779eee2) and pass the resulting transform to the draw function when drawing the circle