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

Author Topic: Understanding the getPoint() index for sf::RectangleShape getPoint()  (Read 183 times)

0 Members and 1 Guest are viewing this topic.

SeikenPunch

  • Newbie
  • *
  • Posts: 4
    • View Profile
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!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
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().
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SeikenPunch

  • Newbie
  • *
  • Posts: 4
    • View Profile
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

SeikenPunch

  • Newbie
  • *
  • Posts: 4
    • View Profile
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!

SeikenPunch

  • Newbie
  • *
  • Posts: 4
    • View Profile
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!