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

Author Topic: Having issues understanding the Bounding Box of Shapes?  (Read 3682 times)

0 Members and 3 Guests are viewing this topic.

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Having issues understanding the Bounding Box of Shapes?
« on: May 14, 2014, 11:22:23 pm »
Okay can someone show me a small code sample of how to get a bounding box for a rectangle or any shape.

// get the bounding box of the entity
sf::FloatRect boundingBox = entity.getGlobalBounds();

// check collision with a point
sf::Vector2f point = ...;
if (boundingBox.contains(point))
{
    // collision!
}

// check collision with another box (like the bounding box of another entity)
sf::FloatRect otherBox = ...;
if (boundingBox.intersects(otherBox))
{
    // collision!
}
 

I understand the syntax but i dont understand whats going on! Could someone elaborate?

I'd really appreciate it!

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Having issues understanding the Bounding Box of Shapes?
« Reply #1 on: May 14, 2014, 11:27:41 pm »
Well...you appear to be answering your own question, since getGlobalBounds() is the correct method for getting a drawable's bounding box.  So what exactly are you asking for help with?

If you're trying to ask for details about what exactly SFML computes the bounding box, you should try to ask a far more specific question so we know what it is you're after (or look at the source code).

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Having issues understanding the Bounding Box of Shapes?
« Reply #2 on: May 14, 2014, 11:51:39 pm »
Well...you appear to be answering your own question, since getGlobalBounds() is the correct method for getting a drawable's bounding box.  So what exactly are you asking for help with?

If you're trying to ask for details about what exactly SFML computes the bounding box, you should try to ask a far more specific question so we know what it is you're after (or look at the source code).

That is the example that comes with the 2.1 Tutorial for SFML. The thing is, I'm not sure what i need to initialize the vector object or how the whole bounding box works. I'm not sure if i understand that section, i know im not being very specific but i cant seem to offer any more details as to my problem since the only problem i have is understanding Boundary Boxes or how to set it up exactly.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Having issues understanding the Bounding Box of Shapes?
« Reply #3 on: May 15, 2014, 12:06:15 am »
If the question is how to initialize a Vector2f, all you need is general C++ knowledge and the documentation for that class's constructor(s).  I believe these should all work:
sf::Vector2f vec1 = sf::Vector2f(10, 20);
sf::Vector2f vec2(10, 20);
sf::Vector2f vec3{10, 20}; // C++11
There's probably one or two other ways I can't remember the syntax for right now.

If any of these look mystifying to you, you should go read a proper C++ book until you fully understand object constructors and other basic features.



A bounding box is just a rectangle.  There is no "set up" for a bounding box, unless you mean creating an object that would have a bounding box.

Specifically, the AABB (axis-aligned bounding box) for a given entity is the smallest possible rectangle which completely contains the entity and has axis-aligned edges (ie, two sides are horizontal and two are vertical).

Here's a random image I googled that might help:


If that doesn't answer your question, then please try to be more specific so we can figure out where the confusion lies.
« Last Edit: May 15, 2014, 12:09:14 am by Ixrec »

AndreeU17

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Having issues understanding the Bounding Box of Shapes?
« Reply #4 on: May 15, 2014, 02:50:10 am »
Yes I understand a lot better, I managed to get my problem solved as we'll, thank you !

jannugimes

  • Guest
Re: Having issues understanding the Bounding Box of Shapes?
« Reply #5 on: May 19, 2014, 09:04:09 am »
Is there really no function in ogre to recalculate the bounding box based on the current vertex positions due to animation?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Having issues understanding the Bounding Box of Shapes?
« Reply #6 on: May 19, 2014, 03:24:53 pm »
Is there really no function in ogre to recalculate the bounding box based on the current vertex positions due to animation?

What does this forum have to do with Ogre?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything