Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Physics::Component::CapsuleCollider Struct Reference

#include <CapsuleCollider.hpp>

Public Member Functions

 CapsuleCollider ()=default
 Default constructor.
 CapsuleCollider (float hHeight, float r)
 Construct with half-height and radius.
 CapsuleCollider (float hHeight, float r, const glm::vec3 &localOffset)
 Construct with half-height, radius and offset.
float GetTotalHeight () const
 Get total height of the capsule.
float GetCylinderHeight () const
 Get height of just the cylindrical part.
float GetDiameter () const
 Get diameter of the capsule.
void SetHeight (float capsuleHeight)
 Set height (distributes between cylinder and caps).
bool IsValid () const
 Check if collider is valid.
bool IsSphere () const
 Check if this capsule degenerates to a sphere.

Static Public Member Functions

static CapsuleCollider CreateFromHeight (float capsuleHeight, float r)
 Create a capsule from total height and radius.
static CapsuleCollider AtOffset (float hHeight, float r, const glm::vec3 &localOffset)
 Create a capsule at an offset (useful for compound shapes).

Public Attributes

float halfHeight = 0.5f
 Half height of the cylindrical part (distance from center to cap start).
float radius = 0.25f
 Radius of the capsule (both cylinder and hemisphere caps).
glm::vec3 offset {0.0f, 0.0f, 0.0f}
 Local offset from entity transform (center of capsule).

Detailed Description

Constructor & Destructor Documentation

◆ CapsuleCollider() [1/3]

Physics::Component::CapsuleCollider::CapsuleCollider ( )
default

Default constructor.

◆ CapsuleCollider() [2/3]

Physics::Component::CapsuleCollider::CapsuleCollider ( float hHeight,
float r )
inline

Construct with half-height and radius.

Parameters
hHeightHalf height of the cylindrical part
rRadius of the capsule

◆ CapsuleCollider() [3/3]

Physics::Component::CapsuleCollider::CapsuleCollider ( float hHeight,
float r,
const glm::vec3 & localOffset )
inline

Construct with half-height, radius and offset.

Parameters
hHeightHalf height of the cylindrical part
rRadius of the capsule
localOffsetLocal position offset from entity center

Member Function Documentation

◆ AtOffset()

CapsuleCollider Physics::Component::CapsuleCollider::AtOffset ( float hHeight,
float r,
const glm::vec3 & localOffset )
inlinestatic

Create a capsule at an offset (useful for compound shapes).

Parameters
hHeightHalf height
rRadius
localOffsetPosition offset from entity center
Returns
CapsuleCollider

◆ CreateFromHeight()

CapsuleCollider Physics::Component::CapsuleCollider::CreateFromHeight ( float capsuleHeight,
float r )
inlinestatic

Create a capsule from total height and radius.

Parameters
capsuleHeightTotal height including caps
rWidth/depth radius
Returns
CapsuleCollider
Note
By default capsules are vertical (Y-up). Use rotation in Transform to make it horizontal, or use offset to position it differently.
Can be used for Character, common values: height 1.8m, radius 0.3m

◆ GetCylinderHeight()

float Physics::Component::CapsuleCollider::GetCylinderHeight ( ) const
inlinenodiscard

Get height of just the cylindrical part.

Returns
Cylinder height (2 * halfHeight)

◆ GetDiameter()

float Physics::Component::CapsuleCollider::GetDiameter ( ) const
inlinenodiscard

Get diameter of the capsule.

Returns
Diameter (2 * radius)

◆ GetTotalHeight()

float Physics::Component::CapsuleCollider::GetTotalHeight ( ) const
inlinenodiscard

Get total height of the capsule.

Returns
Total height (2 * halfHeight + 2 * radius)

◆ IsSphere()

bool Physics::Component::CapsuleCollider::IsSphere ( ) const
inlinenodiscard

Check if this capsule degenerates to a sphere.

Returns
true if halfHeight == 0

◆ IsValid()

bool Physics::Component::CapsuleCollider::IsValid ( ) const
inlinenodiscard

Check if collider is valid.

Returns
true if halfHeight >= 0 and radius > 0

◆ SetHeight()

void Physics::Component::CapsuleCollider::SetHeight ( float capsuleHeight)
inline

Set height (distributes between cylinder and caps).

Parameters
capsuleHeightTotal height of the capsule
Note
This keeps the current radius and adjusts halfHeight accordingly

Member Data Documentation

◆ halfHeight

float Physics::Component::CapsuleCollider::halfHeight = 0.5f

Half height of the cylindrical part (distance from center to cap start).

Examples
Basic usage for a character capsule.

◆ offset

glm::vec3 Physics::Component::CapsuleCollider::offset {0.0f, 0.0f, 0.0f}

Local offset from entity transform (center of capsule).

◆ radius

float Physics::Component::CapsuleCollider::radius = 0.25f

Radius of the capsule (both cylinder and hemisphere caps).

Examples
Basic usage for a character capsule.

The documentation for this struct was generated from the following file: