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

Author Topic: Getting position of the circle that is rotated around a point  (Read 1680 times)

0 Members and 1 Guest are viewing this topic.

Remi749

  • Newbie
  • *
  • Posts: 3
    • View Profile
Getting position of the circle that is rotated around a point
« 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.
« Last Edit: November 19, 2017, 04:50:13 pm by Remi749 »

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Getting position of the circle that is rotated around a point
« Reply #1 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

Remi749

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Getting position of the circle that is rotated around a point
« Reply #2 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 :)

 

anything