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

Author Topic: Sprite: Corner Points  (Read 2634 times)

0 Members and 1 Guest are viewing this topic.

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Sprite: Corner Points
« on: June 07, 2011, 01:43:53 pm »
I want to access the corner Points of a Sprite, but i can't
find a suitable method. Is it possible to get these points directly?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Sprite: Corner Points
« Reply #1 on: June 07, 2011, 01:50:06 pm »
Not directly, but like this:
Code: [Select]
leftUpperCorner = position - origin;
rightLowerCorner = position - origin + size;

By the way, I should really add methods for direct access of border coordinates to my Thor library. In fact, I had implemented them, but removed them before 1.0 because they weren't mature enough.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite: Corner Points
« Reply #2 on: June 07, 2011, 01:51:24 pm »
The points in local coordinates are:
- (0, 0)
- (0, sprite.GetSubRect().GetHeight())
- (sprite.GetSubRect().GetWidth(), 0)
- (sprite.GetSubRect().GetWidth(), sprite.GetSubRect().GetHeight())

The points in global coordinates are:
- sprite.TransformToGlobal(px)
where px is one of the local points.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Sprite: Corner Points
« Reply #3 on: June 07, 2011, 02:03:23 pm »
Laurent, your approach is better since it takes rotation and scale into account. Apparently, I was right with the "not mature" ;)

But this raises another question: How would one implement something like
Code: [Select]
float GetRight(const sf::Sprite& sprite);? There is no meaningful way because the right edge may be rotated. There are however still enough cases where a sprite is axis-aligned... Hm, I'll probably just wait with this stuff, there are more important tasks anyway :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Sprite: Corner Points
« Reply #4 on: June 07, 2011, 02:04:04 pm »
Well, my sprites may have an arbitrary rotation. Thus, in my case it is not
that easy. So i guess i have to do some trigonometrics?

By the way, what i want to do is to draw a rectangle (with sf::Shape)
around the sprite, when the user selects it. If there is a better way
to archive this, please let me know.

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Sprite: Corner Points
« Reply #5 on: June 07, 2011, 02:11:00 pm »
Another approach i can think of is to have another image/sprite with just
the rectangle, and the rest of it transparent. Then i keep the position and
rotation of the two synchronized and only draw the second sprite, when
the user selects that unit.

Which approach is better in your opinion?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Sprite: Corner Points
« Reply #6 on: June 07, 2011, 02:30:32 pm »
Quote from: "MickeyKnox"
Well, my sprites may have an arbitrary rotation. Thus, in my case it is not
that easy. So i guess i have to do some trigonometrics?
No, that should work the way Laurent explained. It is just my approach that doesn't cope with rotation :D

Quote from: "MickeyKnox"
By the way, what i want to do is to draw a rectangle (with sf::Shape)
around the sprite, when the user selects it. If there is a better way
to archive this, please let me know.
I think this is a good way, better than creating a separate sprite with only a border. The sf::Shape rectangle can be rotated and scaled the same way as the original sf::Sprite in order to align it correctly.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Sprite: Corner Points
« Reply #7 on: June 07, 2011, 03:35:44 pm »
ok, thank you guys ~