SFML community forums

Help => Graphics => Topic started by: SeikenPunch on March 27, 2024, 09:52:13 am

Title: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: SeikenPunch on March 27, 2024, 09:52:13 am
I was looking to get the coordinates of the points of a RectangleShape and saw a post saying you can use rect.getTransform().transformPoint(rect.getPoint(i)) where rect is a RectangleShape and i is the index, but I could not find any information about how the points are in the index. Is 0 the top left point and 1 the top right point and so on or is it something else?

Thank you for any help!
Title: Re: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: eXpl0it3r on March 27, 2024, 10:23:31 am
I guess you can check the source code, but the order is not part of the API and instead is an implementation detail.

If you want to know the specific points, you're better off with getPosition() and getPosition() + getSize().
Title: Re: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: SeikenPunch on March 27, 2024, 11:08:25 am
I guess you can check the source code, but the order is not part of the API and instead is an implementation detail.

If you want to know the specific points, you're better off with getPosition() and getPosition() + getSize().

But how would I get the location of the points if the RectangleShape is rotated? I am trying to code collision and I think I can do it if I know the location of the points.
Title: Re: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: eXpl0it3r on March 27, 2024, 12:44:59 pm
No, they're axis aligned.

If you want to get the rotated points, you can get the local bounds and apply the transformation as you've shown on each point of the sf::Rect. Which still provides a better guarantee than deciding on a specific order of the index.
Title: Re: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: Hapax on March 27, 2024, 03:22:49 pm
As an example of collision, you could take a look at:
https://github.com/SFML/SFML/wiki/Source%3A-Rectangular-Boundary-Collision

If you feel that it doesn't already do for you the collision that you need, it at least shows an example of how to get the points of a rectangle (using local points and its transform) as well as using an inverse transform to convert into local co-ordinates of a different shape.
Title: Re: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: SeikenPunch on March 28, 2024, 03:21:11 am
No, they're axis aligned.

If you want to get the rotated points, you can get the local bounds and apply the transformation as you've shown on each point of the sf::Rect. Which still provides a better guarantee than deciding on a specific order of the index.

Ohh okay. I am still pretty new to SFML thank you!
Title: Re: Understanding the getPoint() index for sf::RectangleShape getPoint()
Post by: SeikenPunch on March 28, 2024, 03:23:01 am
As an example of collision, you could take a look at:
https://github.com/SFML/SFML/wiki/Source%3A-Rectangular-Boundary-Collision

If you feel that it doesn't already do for you the collision that you need, it at least shows an example of how to get the points of a rectangle (using local points and its transform) as well as using an inverse transform to convert into local co-ordinates of a different shape.

This helps. I think they are doing what I was planning to do or something very similar. Thank you!