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!
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) (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Vector2.php#a58c32383b5291380db4b43a289f75988). 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:
(http://workshops.boundlessgeo.com/postgis-intro/_images/boundingbox.png)
If that doesn't answer your question, then please try to be more specific so we can figure out where the confusion lies.