tile2d
Loading...
Searching...
No Matches
Classes | Functions | Variables
collide.hpp File Reference

Contains different types of collision detection and resolve functions. More...

#include "tileMap.hpp"

Go to the source code of this file.

Classes

class  CollisionManifold
 Defines the relevant collision information generated by detectNarrowColllision() to both resolve the collision through its normals and impulse. More...
 
struct  debug::CollideInfo
 
class  TileBodyCollisionCache< TileData >
 Used to speed up the collision detection between two tile bodies. More...
 
class  ImpulseMethod
 Resolves the collision between two bodies using the impulse method. More...
 
struct  ImpulseMethod::Impulse
 

Functions

template<class BoxVertexContainer , class NormalContainer >
bool satBoxTest (const BoxVertexContainer &vertices1, const BoxVertexContainer &vertices2, const NormalContainer &normals, CollisionManifold &manifold)
 Returns the normal and depth of two polygons defined by the vertices vertices1 and vertices2 by using normals inside of the manifold.
 
template<typename Container , typename Integer >
void findClosestPoint (vec2 &cp1, vec2 &cp2, Integer &count, Float &distance1, const Container &points1, const Container &points2)
 Finds the closest point between points1 and the faces defined by points2.
 
template<typename Container >
void computeBoxManifold (const Container &points1, const Container &points2, CollisionManifold &manifold)
 Finds the closest point between points1 and the faces defined by points2.
 
template<class TileData >
bool detectNarrowCollision (const TileBody< TileData > &body1, const glm::i32vec2 &tilePos1, const vec2 &body1Offset, const TileBody< TileData > &body2, const glm::i32vec2 &tilePos2, const vec2 &body2Offset, CollisionManifold &manifold)
 Detects the collision between the tile in tilePos1 of body1 and the tile tilePos2 of body2.
 
template<class TileData >
void detectTileBodyCollision (const TileBody< TileData > &body1, const TileBody< TileData > &body2, TileBodyCollisionCache< TileData > &cache, std::vector< CollisionManifold > &manifolds, vec2 &body1Offset, vec2 &body2Offset)
 Detects the collision between the tiles bodies, body1 and body2.
 

Variables

std::vector< CollideInfodebug::collideInfos
 

Detailed Description

Contains different types of collision detection and resolve functions.

Function Documentation

◆ computeBoxManifold()

template<typename Container >
void computeBoxManifold ( const Container & points1,
const Container & points2,
CollisionManifold & manifold )
inline

Finds the closest point between points1 and the faces defined by points2.

The size of vertices1 and vertices2 must be 4. The size of normals must be 2.

Parameters
[in]points1The set of points used to find the closest point in the faces defined by points2
[in]points2The set of points that define faces that points1 will check against
[in,out]manifoldThe normal and depth must be already calculated within manifold. The contact points betweeen the shapes defined by points1 and points2 will be written inside of manifold

◆ detectNarrowCollision()

template<class TileData >
bool detectNarrowCollision ( const TileBody< TileData > & body1,
const glm::i32vec2 & tilePos1,
const vec2 & body1Offset,
const TileBody< TileData > & body2,
const glm::i32vec2 & tilePos2,
const vec2 & body2Offset,
CollisionManifold & manifold )

Detects the collision between the tile in tilePos1 of body1 and the tile tilePos2 of body2.

In order to not modify body1 and body2, detectTileBodyCollision() uses offsets that are applied to body1 and body2 that would correctly resolve the collision between the two bodies. The offsets after each call to detectNarrowCollision() will have "normal * depth" added to them.

Parameters
[in]body1The first body to grab the tile data defined by tilePos1
[in]tilePos1The tile position of body1 to check against tilePos2
[in]body1OffsetA world offset to apply to the OBB of the tile defined by tilePos1 of body1
[in]body2The second body to grab the tile data defined by tilePos2
[in]tilePos2The tile position of body2 to check against tilePos1
[in]body2OffsetA world offset to apply to the OBB of the tile defined by tilePos2 of body2
[out]manifoldIf detectNarrowCollision() returns true, Will contain a set of contact points and the normal and depth that may be applied to body1 and body2 to resolve the collision of the tiles defined by tilePos1 and tilePos2
Returns
If true, the collision between the tile of tilePos1 of body1 and the tile of tilePos2 of body2 is occuring.

◆ detectTileBodyCollision()

template<class TileData >
void detectTileBodyCollision ( const TileBody< TileData > & body1,
const TileBody< TileData > & body2,
TileBodyCollisionCache< TileData > & cache,
std::vector< CollisionManifold > & manifolds,
vec2 & body1Offset,
vec2 & body2Offset )

Detects the collision between the tiles bodies, body1 and body2.

Uses chunking as a broad phase to speed up the collision of extremely large tile bodies

Parameters
[in]body1The first tile body
[in]body2The second tile body
[in,out]cacheIn order to speed up collisions, a cache is used to lessen calls to malloc() and free()
[out]manifoldsthe contact manifolds between the tiles of body1 and body2
[out]body1OffsetA world offset to apply to body1 to resolve the collision
[out]body2OffsetA world offset to apply to body2 to resolve the collision

◆ findClosestPoint()

template<typename Container , typename Integer >
void findClosestPoint ( vec2 & cp1,
vec2 & cp2,
Integer & count,
Float & distance1,
const Container & points1,
const Container & points2 )
inline

Finds the closest point between points1 and the faces defined by points2.

The size of vertices1 and vertices2 must be 4. The size of normals must be 2.

Parameters
[in,out]cp1The first closest point between points1 and points2
[in,out]cp2The second closest point between points1 and points2, may not exist
[in,out]countThe count of closest points between points1 and points2
[in,out]distance1Contains the minimum distance between points1 and faces defined by points2
[in]points1The set of points used to find the closest point in the faces defined by points2
[in]points2The set of points that define faces that points1 will check against

◆ satBoxTest()

template<class BoxVertexContainer , class NormalContainer >
bool satBoxTest ( const BoxVertexContainer & vertices1,
const BoxVertexContainer & vertices2,
const NormalContainer & normals,
CollisionManifold & manifold )

Returns the normal and depth of two polygons defined by the vertices vertices1 and vertices2 by using normals inside of the manifold.

The size of vertices1 and vertices2 must be 4. The size of normals must be 2.

Parameters
[in]vertices1The first set of vertices that define a convex polygon
[in]vertices2The second set of vertices that define a convex polygon
[out]manifoldIf satBoxTest() returns true, it will contain the normal and depth of penetration between vertices1 and vertices2 inside of its members, 'normal' and 'depth'
Returns
Will return true if there was a collision detected, false otherwise