VoxelEngine
 
Loading...
Searching...
No Matches
engine::AABBCollider Class Reference

Classes

struct  SweptResult
 

Public Member Functions

 AABBCollider (std::shared_ptr< AABB > aabb, float stepHeight=0.0f)
 
void setWorld (std::shared_ptr< World > world)
 Sets the world for this collider.
 
void setAABB (std::shared_ptr< AABB > aabb)
 Sets the AABB that will be checked for collisions against the world.
 
CollisionInfo collide (glm::vec3 &moveStep, const glm::vec3 &position, float dt)
 Checks if the AABB collides with any blocks in the world.
 

Protected Member Functions

void updateAABBCache (const glm::vec3 &velocity, const glm::vec3 &position)
 
SweptResult swept (const glm::vec3 &velocity, const AABB &other) const
 
float swept1D (int axis, float velocity, const AABB &other)
 
float tryStepUp (const glm::vec3 &horizontalMove, const SweptResult &bestRes)
 Attempts to step up when hitting a horizontal obstacle.
 

Protected Attributes

std::shared_ptr< Worldm_world = nullptr
 
std::shared_ptr< AABBm_aabb
 
float m_stepHeight
 
float m_height
 
std::vector< AABBm_aabbCache
 
glm::ivec3 m_lastPosition
 
glm::vec3 m_cacheDirection
 
float m_stepUpCooldown = 0.0f
 

Static Protected Attributes

static constexpr glm::vec3 s_checkBox {1.5f}
 The box around the AABB that will be generated, thus checked for collisions against the world.
 
static constexpr float s_epsGap = std::numeric_limits<float>::epsilon() * 64.0f
 

Member Function Documentation

◆ collide()

CollisionInfo AABBCollider::collide ( glm::vec3 &  moveStep,
const glm::vec3 &  position,
float  dt 
)

Checks if the AABB collides with any blocks in the world.

Parameters
moveStepThe move delta or velocity of the AABB. The components will be modified to reflect the collision response.
positionThe position of the AABB feet. Based on this surrounding AABBs will be generated.
dtThe delta time since the last collision check.

◆ tryStepUp()

float AABBCollider::tryStepUp ( const glm::vec3 &  horizontalMove,
const SweptResult bestRes 
)
protected

Attempts to step up when hitting a horizontal obstacle.

Parameters
horizontalMoveThe horizontal movement vector on the colliding axis
collidingBBThe AABB that was collided with
Returns
The step height if stepping is possible, -1.0f otherwise

Member Data Documentation

◆ s_checkBox

constexpr glm::vec3 engine::AABBCollider::s_checkBox {1.5f}
staticconstexprprotected

The box around the AABB that will be generated, thus checked for collisions against the world.

Note
This box is generated by taking the AABB and adding the amount of blocks in given direction to all sides.

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