SFML community forums

Help => Graphics => Topic started by: Remi749 on November 19, 2017, 04:29:53 pm

Title: Getting position of the circle that is rotated around a point
Post by: Remi749 on November 19, 2017, 04:29:53 pm
Hi, in the code below I have a circle shape, which rotates around the player in my game. If I try to do a getPosition for the circle, it gives the point at which it rotates around. this is not what I'm looking for.

I want to be able to get the exact position where the circle is during its circular movement around the point. So I can use that position and shoot bullets towards the circle.


//header file:

sf::CircleShape c;

//cppfile:

c.setFillColor(sf::Color::Red);
c.setPosition(this->sprite->getPosition().x + width / 2, this->sprite->getPosition().y + height / 2);
c.setRadius(25);
c.setOrigin({1, -100});

c.rotate(1.f);

c.setPosition(this->sprite->getPosition().x + width / 2, this->sprite->getPosition().y + height / 2);

std::cout << "Circle.x: " << c.getEXACTPOS.y << " | Circle.y: " << c.getEXACTPOS.y << std::endl;

window.draw(c);
 

If there is a better solution to rotate a circle around a point, don't hesitate to tell me :)

If this is not possible, I am looking for a way to use the rightstick on a joystick to shoot in the direction it's pointing to.
Title: Re: Getting position of the circle that is rotated around a point
Post by: achpile on November 19, 2017, 05:22:25 pm
x = c.x + r*cos(a)
y = c.y + r*sin(a)

(c) is the center of rotation
(r) is radius
(a) in radians

radian = degree * 3.14 / 180
Title: Re: Getting position of the circle that is rotated around a point
Post by: Remi749 on November 19, 2017, 09:21:06 pm
Thanks for the reply, I figured it out in a different way. If anyone is interested to know how, let me know :)