VEGO-Engine  0.1
Loading...
Searching...
No Matches
CollisionHandler Class Reference

Class responsible for collision detection and handling. More...

#include <CollisionHandler.h>

Public Member Functions

template<typename T>
getAnyIntersection (Entity *entity, Vector2D posMod={}, std::initializer_list< Entity::GroupLabel > const &groupLabels={}, std::initializer_list< Entity * > const &excludedEntities={})
 Tests entity against all entities with the specified labels for a collision.
 
template<>
IntersectionBitSet getAnyIntersection (Entity *entity, Vector2D posMod, std::initializer_list< Entity::GroupLabel > const &groupLabels, std::initializer_list< Entity * > const &excludedEntities)
 
template<>
EntitygetAnyIntersection (Entity *entity, Vector2D posMod, std::initializer_list< Entity::GroupLabel > const &groupLabels, std::initializer_list< Entity * > const &excludedEntities)
 
template<>
bool getAnyIntersection (Entity *entity, Vector2D posMod, std::initializer_list< Entity::GroupLabel > const &groupLabels, std::initializer_list< Entity * > const &excludedEntities)
 

Static Public Member Functions

static IntersectionBitSet getIntersection (Entity *entityA, Entity *entityB, Vector2D posModA=Vector2D(0, 0), Vector2D posModB=Vector2D(0, 0))
 Checks for intersections relative to entityA.
 

Detailed Description

Class responsible for collision detection and handling.

Member Function Documentation

◆ getAnyIntersection() [1/4]

template<>
IntersectionBitSet CollisionHandler::getAnyIntersection ( Entity * entity,
Vector2D posMod,
std::initializer_list< Entity::GroupLabel > const & groupLabels,
std::initializer_list< Entity * > const & excludedEntities )

Refer to getAnyIntersection() for more details

Returns
A bitset of intersections, describing the directions of intersection. Position Direction in bitset true if edge in that direction collides
See also
Direction
IntersectionBitSet
constexpr uint8_t DIRECTION_C = 4;
using IntersectionBitSet = std::bitset<DIRECTION_C>;

Example usage for IntersectionBitSet (TransformComponent::update()):

IntersectionBitSet intersections =
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) |
(this->entity->getManager()
.getGame()->collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(positionChange.x, 0), colliders)) &
IntersectionBitSet("0011")) |
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(0, positionChange.y)) |
(this->entity->getManager()
.getGame()->collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(0, positionChange.y), colliders)) &
IntersectionBitSet("1100"));
if (intersections.test((size_t)Direction::LEFT) || intersections.test((size_t)Direction::RIGHT))
positionChange.x = 0;
if (intersections.test((size_t)Direction::UP) || intersections.test((size_t)Direction::DOWN))
positionChange.y = 0;

◆ getAnyIntersection() [2/4]

template<>
Entity * CollisionHandler::getAnyIntersection ( Entity * entity,
Vector2D posMod,
std::initializer_list< Entity::GroupLabel > const & groupLabels,
std::initializer_list< Entity * > const & excludedEntities )

Refer to getAnyIntersection() for more details

Returns
The first entity with collision found
See also
Entity

◆ getAnyIntersection() [3/4]

template<>
bool CollisionHandler::getAnyIntersection ( Entity * entity,
Vector2D posMod,
std::initializer_list< Entity::GroupLabel > const & groupLabels,
std::initializer_list< Entity * > const & excludedEntities )

Refer to getAnyIntersection() for more details

Returns
True if any collision was found, otherwise false

◆ getAnyIntersection() [4/4]

template<typename T>
T CollisionHandler::getAnyIntersection ( Entity * entity,
Vector2D posMod = {},
std::initializer_list< Entity::GroupLabel > const & groupLabels = {},
std::initializer_list< Entity * > const & excludedEntities = {} )

Tests entity against all entities with the specified labels for a collision.

Tests the given entity against every other entity with the specified labels for intersections between their collison boxes. If the primary entity has no ColliderComponent, the equivalent of no collision is returned immediately, other entities are skipped if they don't have a ColliderComponent

Parameters
entityThe primary entity to check against. Return values will be relative to this entity
posModModifier to apply toposition before checking collisions.
groupLabelsEntities need to have at least one listed GroupLabels to get checked against
teamLabelsEntities need to have one of the specified TeamLabels to get checked against
negateTeamIf set to true, entities will only be checked against if they don't have one of the specified TeamLabels
See also
ColliderComponent

◆ getIntersection()

IntersectionBitSet CollisionHandler::getIntersection ( Entity * entityA,
Entity * entityB,
Vector2D posModA = Vector2D(0,0),
Vector2D posModB = Vector2D(0,0) )
static

Checks for intersections relative to entityA.

Parameters
entityAThe first entity to check against
entityBThe second entity to check against
posModAModifier to apply to entityA's position before checking collisions

The documentation for this class was generated from the following files: