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

Author Topic: possible bug with sf::circleShape points not updating  (Read 258 times)

0 Members and 1 Guest are viewing this topic.

oncleJhon

  • Newbie
  • *
  • Posts: 1
    • View Profile
possible bug with sf::circleShape points not updating
« on: October 12, 2023, 10:09:52 pm »
I think I have discovered a bug with the circleShape.

I was trying to positions elements in a circle formation by creating a circle and using its points positions to determine the positions of the elements I wanted to create. But it seems that using the setPosition() on circleShape doesn't move the circle points locations with it.

Here is a simple code proving it

#include <SFML/Graphics.hpp>

void printPointsLocations(sf::CircleShape& circle) {
    for (int i = 0; i < circle.getPointCount(); i++) {
        printf("Point %d: (%f, %f)\n", i, circle.getPoint(i).x,
               circle.getPoint(i).y);
    }
}

int main() {
    sf::CircleShape circle(100.f, 5);
    printf("Default circle:\n");
    printPointsLocations(circle);
    printf("Default circle position: (%f, %f)\n", circle.getPosition().x,
           circle.getPosition().y);
    circle.setPosition(sf::Vector2f(100.f, 0));
    printf("Moved circle circle:\n");
    printPointsLocations(circle);
    printf("Moved circle position: (%f, %f)\n", circle.getPosition().x,
           circle.getPosition().y);
}

and in attached files my result in my terminal. As you can see the circle has been moved, but the points are at the same place, while I am expecting them to be 100px further after setting the new positions of the circle.
I am aware my issue can be fixed by applying my transformation the the points I am given instead, but it is still a bug for me

I am using SFML 2.6 and VS 2019 compiler on Windows 11.
« Last Edit: October 12, 2023, 10:16:58 pm by oncleJhon »

kimci86

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: possible bug with sf::circleShape points not updating
« Reply #1 on: October 12, 2023, 11:09:17 pm »
This is expected. getPoint ignores the shape transform.

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account.

If you want transformed positions, you can get the shape transform (getTransform) and use it to transform the points (transformPoint).

 

anything