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

Author Topic: How do I make a circle rotate in a bigger circumference  (Read 4125 times)

0 Members and 1 Guest are viewing this topic.

habed123

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
How do I make a circle rotate in a bigger circumference
« 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?
« Last Edit: May 26, 2021, 09:24:52 am by eXpl0it3r »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: How do I make a circle rotate in a bigger circumference
« Reply #1 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)
Visit my game site (and hopefully help funding it? )
Website | IndieDB

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: How do I make a circle rotate in a bigger circumference
« Reply #2 on: May 26, 2021, 02:55:39 pm »
3) or use transform.rotate and pass the resulting transform to the draw function when drawing the circle