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

Author Topic: Rect class?  (Read 2482 times)

0 Members and 1 Guest are viewing this topic.

pabloist

  • Newbie
  • *
  • Posts: 26
    • View Profile
Rect class?
« on: September 19, 2010, 08:52:05 am »
I don't really understand how the rect class works; the reference says

Rect (T LeftCoord, T TopCoord, T RightCoord, T BottomCoord)

but coordinates need to be pairs of numbers, right? so how does an IntRect work? That requires using single integers for each coordinate..?

I'd appreciate if someone could explain (:

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Rect class?
« Reply #1 on: September 19, 2010, 09:02:39 am »
I think other people have been confused by the use of 'coord' before but I find sf::Rect much simpler to use and understand than other rect implementations.

Left, Top, Right, Bottom refer to the positions of the 'sides' or 'edges'. Left and Right are on the X axis, Top and Bottom are on Y.

So Left is the X coordinate of the Left side/edge and Top is the Y coordinate of the Top side/edge. So the point at (Left, Top) would be the top left corner of the rect.

Hard to explain in words! Make sense though?

Beliar

  • Newbie
  • *
  • Posts: 27
    • View Profile
Rect class?
« Reply #2 on: September 19, 2010, 09:04:36 am »
Hmm, you got the TopLeft coordinates and the BottomRight ones, what do you need more for an Rectangle?


If you don't know what i mean, look at this:
Code: [Select]
Top/Left------------------Top/Right
    |                        |
    |                        |
    |                        |
    |                        |
Bottom/Left------------Bottom/Right
Debuggers don't remove bugs. They only show them in slow motion.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Rect class?
« Reply #3 on: September 19, 2010, 03:09:46 pm »
You should take a look at the sf::Rect class template in SFML 2. It uses Left, Top, Width and Height. As far as I remember, one of the decisive reasons why Laurent changed the API was the confusion coming up again and again, concerning whether Bottom/Right coordinates were inclusive or exclusive.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

pabloist

  • Newbie
  • *
  • Posts: 26
    • View Profile
Rect class?
« Reply #4 on: September 19, 2010, 11:53:15 pm »
Thanks very much everyone (: That clears it up a lot for me.

 

anything