Handles collisions.
More...
#include <Collider.hpp>
Handles collisions.
Contains basic set of points which can be later transformed to represent bounds of an object. Also supports globalBounds to make collision detection more efficient.
Sample code:
auto t = sf::Transform().translate({9, 0});
void sfgf::Collider::applyTransform |
( |
const sf::Transform & |
t | ) |
|
Applies transform.
- Parameters
-
Used to adjust position/rotation/scale of collider to actual object.
Sample code:
this->collider.applyTransform(this->polygon.getTransform());
Collider sfgf::Collider::circle |
( |
float |
radius, |
|
|
size_t |
cnt = 128 |
|
) |
| |
|
static |
Returns collider in shape of circle.
- Parameters
-
[in] | radius | – radius of circle |
[in] | cnt | – count of points to make |
- Returns
- new collider
void sfgf::Collider::clear |
( |
| ) |
|
Clears points.
Simply clears internal array (std::vector), empty collider never detects any collision.
bool sfgf::Collider::collides |
( |
const Collider & |
poly | ) |
const |
Check if two colliders collide.
- Parameters
-
[in] | poly | – collider to check against |
Tests whether colliders collide or not. They do, if any of theirs side intersect or if no point of one collider is outside of another.
- Returns
- True if they collide, False otherwise.
bool sfgf::Collider::contains |
( |
sf::Vector2f |
point | ) |
const |
Check if point is inside of collider.
- Parameters
-
[in] | point | – point to check |
Tests if given point is inside of (*this).
- Returns
- True if point is in collider, false otherwise
sf::FloatRect sfgf::Collider::getGlobalBounds |
( |
| ) |
const |
|
inline |
Returns global bounds.
Get the global bounding rectangle of the entity.
The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, …) that are applied to the entity. In other words, this function returns the bounds of the collider in the global 2D world's coordinate system.
- Returns
- Global bounding rectangle of the entity
bool sfgf::Collider::intersects |
( |
const Collider & |
poly | ) |
const |
Check for intersection.
- Parameters
-
[in] | poly | – collider to check |
Tests if any side of (*this) intersects with any side of poly.
- Returns
- True if colliders intersect, False otherwise
bool sfgf::Collider::lineIntersection |
( |
sf::Vector2f |
p1, |
|
|
sf::Vector2f |
q1, |
|
|
sf::Vector2f |
p2, |
|
|
sf::Vector2f |
q2 |
|
) |
| |
|
static |
Check two lines for intersection.
- Parameters
-
[in] | p1 | – beginning of line I |
[in] | q1 | – end of line I |
[in] | p2 | – beginning of line II |
[in] | q2 | – end of line II |
- Returns
- True if lines intersect, False otherwise
void sfgf::Collider::pushBack |
( |
sf::Vector2f |
pt | ) |
|
Adds point to internal array.
- Parameters
-
[in] | pt | – coordinates in local system |
Can be used to create collider in non–standard shape, aka custom polygon.
Sample code:
while(inputFile >> x >> y) {
collider.pushBack({x, y});
}
Collider sfgf::Collider::rectangle |
( |
sf::Vector2f |
size | ) |
|
|
static |
Returns collider in shape of rectangle.
- Parameters
-
[in] | size | – dimensions of rectangle |
- Returns
- new collider
The documentation for this class was generated from the following file: