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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - sfmlnoob123

Pages: [1]
1
Hey,
I want to make the object rotation so it's relative to the mouse position.

In constructor I set the origin to the centre of the object and set its position:
Quote
Player::Player() {
   setOrigin(width / 2, height / 2);
   pos.x = 600.f;
   pos.y = 300.f;
}

then I calculate the angle:
Quote
float Player::getAngle(sf::RenderWindow& window) {
   x = sf::Mouse::getPosition(window).x - (pos.x + width / 2);
   y = sf::Mouse::getPosition(window).y - (pos.y + height / 2);
   angle = std::atan2(y, x) * 180 / M_PI;
   printf("%f\n", angle);
   return angle;
}

and draw it. However the origin seems to be very off because it rotates around a different point.
What am I missing?

Pages: [1]
anything