SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::ColliderComponent Class Reference

#include <ColliderComponent.hpp>

Inheritance diagram for Sleak::ColliderComponent:

Public Member Functions

 ColliderComponent (GameObject *owner, const MeshData &meshData, bool asMesh)
 ColliderComponent (GameObject *owner, const MeshData &meshData, Physics::ColliderType preferred)
 Derives a bounding shape of the given type from the mesh's vertex positions.
 ColliderComponent (GameObject *owner, const Physics::AABB &aabb)
 Wraps a pre-built axis-aligned box shape.
 ColliderComponent (GameObject *owner, const Physics::BoundingCapsule &capsule)
 Wraps a pre-built capsule shape.
 ColliderComponent (GameObject *owner, const Physics::BoundingSphere &sphere)
 Wraps a pre-built sphere shape.
 ~ColliderComponent () override=default
uint32_t GetLayer () const
uint32_t GetMask () const
Math::Vector3D GetOffset () const
int GetProxyId () const
const Physics::ColliderShapeGetShape () const
Physics::ColliderType GetType () const
Physics::AABB GetWorldAABB () const
 Local shape transformed into world space by the owner's current transform.
bool Initialize () override
 One-time setup, called after the component is attached and the owner is initialized.
bool IsTrigger () const
void SetLayer (uint32_t layer)
void SetMask (uint32_t mask)
void SetOffset (const Math::Vector3D &offset)
void SetProxyId (int id)
void SetTrigger (bool trigger)
void Update (float deltaTime) override
Public Member Functions inherited from Sleak::Component
 Component (GameObject *object)
virtual ~Component ()=default
virtual void FixedUpdate (float fixedDeltaTime)
GameObjectGetOwner ()
virtual void LateUpdate (float deltaTime)
virtual void OnDestroy ()
 Called when the component is detached or the owner is destroyed.
virtual void OnDisable ()
virtual void OnEnable ()
Public Member Functions inherited from Sleak::Object
 Object (const std::string &name="Object")
virtual ~Object ()=default
const std::string & GetName () const
uint64_t GetUniqueID () const
void SetName (const std::string &value)

Additional Inherited Members

Protected Attributes inherited from Sleak::Component
bool bIsInitialized
GameObjectowner

Detailed Description

Attaches a collision shape to a GameObject and registers it with PhysicsWorld's broadphase.

Attach the shape that matches the object: Physics::AABB for boxes and level geometry, Physics::BoundingSphere for projectiles and simple characters, Physics::BoundingCapsule for upright figures. Two more constructors derive a shape from MeshData, either a bounding volume of a type you pick or an exact triangle mesh.

Registration is automatic. Adding the owning GameObject to a scene registers the collider (and any on child objects) with that scene's Physics::PhysicsWorld, and removing the object unregisters it. The shape you supply is in local space; GetWorldAABB() applies the owner's current transform.

Layer and mask filter both collision response and the world query API, so put triggers, terrain, and characters on distinct layers and a raycast can ignore the ones it does not care about. Marking a collider as a trigger keeps it in the broadphase while skipping physical response.

// Static level geometry
floor->AddComponent<Sleak::ColliderComponent>(
Sleak::Math::Vector3D(-0.5f, -0.5f, -0.5f),
Sleak::Math::Vector3D( 0.5f, 0.5f, 0.5f)));
floor->AddComponent<Sleak::RigidbodyComponent>(
AddObject(floor); // registers with the scene's PhysicsWorld
// An upright character, raised to sit on the ground
player->AddComponent<Sleak::ColliderComponent>(
Sleak::Math::Vector3D(0, 0, 0), 0.35f, 0.9f));
// A pickup volume that reports overlaps but never pushes
if (auto* c = pickup->GetComponent<Sleak::ColliderComponent>()) {
c->SetTrigger(true);
c->SetLayer(LAYER_PICKUP);
}
See also
RigidbodyComponent, Physics::PhysicsWorld, Physics::AABB, Physics::BoundingSphere, Physics::BoundingCapsule

Definition at line 57 of file ColliderComponent.hpp.

Constructor & Destructor Documentation

◆ ColliderComponent() [1/5]

Sleak::ColliderComponent::ColliderComponent ( GameObject * owner,
const Physics::AABB & aabb )

Wraps a pre-built axis-aligned box shape.

Definition at line 9 of file ColliderComponent.cpp.

◆ ColliderComponent() [2/5]

Sleak::ColliderComponent::ColliderComponent ( GameObject * owner,
const Physics::BoundingSphere & sphere )

Wraps a pre-built sphere shape.

Definition at line 12 of file ColliderComponent.cpp.

◆ ColliderComponent() [3/5]

Sleak::ColliderComponent::ColliderComponent ( GameObject * owner,
const Physics::BoundingCapsule & capsule )

Wraps a pre-built capsule shape.

Definition at line 15 of file ColliderComponent.cpp.

◆ ColliderComponent() [4/5]

Sleak::ColliderComponent::ColliderComponent ( GameObject * owner,
const MeshData & meshData,
Physics::ColliderType preferred )

Derives a bounding shape of the given type from the mesh's vertex positions.

Definition at line 18 of file ColliderComponent.cpp.

◆ ColliderComponent() [5/5]

Sleak::ColliderComponent::ColliderComponent ( GameObject * owner,
const MeshData & meshData,
bool asMesh )

Builds an exact triangle-mesh collider when asMesh is true; otherwise falls back to an AABB computed from the mesh's vertices.

Definition at line 57 of file ColliderComponent.cpp.

◆ ~ColliderComponent()

Sleak::ColliderComponent::~ColliderComponent ( )
overridedefault

Member Function Documentation

◆ GetLayer()

uint32_t Sleak::ColliderComponent::GetLayer ( ) const
inline

Definition at line 90 of file ColliderComponent.hpp.

◆ GetMask()

uint32_t Sleak::ColliderComponent::GetMask ( ) const
inline

Definition at line 92 of file ColliderComponent.hpp.

◆ GetOffset()

Math::Vector3D Sleak::ColliderComponent::GetOffset ( ) const
inline

Definition at line 86 of file ColliderComponent.hpp.

◆ GetProxyId()

int Sleak::ColliderComponent::GetProxyId ( ) const
inline

Definition at line 100 of file ColliderComponent.hpp.

◆ GetShape()

const Physics::ColliderShape & Sleak::ColliderComponent::GetShape ( ) const
inline

Definition at line 78 of file ColliderComponent.hpp.

◆ GetType()

Physics::ColliderType Sleak::ColliderComponent::GetType ( ) const
inline

Definition at line 79 of file ColliderComponent.hpp.

◆ GetWorldAABB()

Physics::AABB Sleak::ColliderComponent::GetWorldAABB ( ) const

Local shape transformed into world space by the owner's current transform.

Definition at line 87 of file ColliderComponent.cpp.

◆ Initialize()

bool Sleak::ColliderComponent::Initialize ( )
overridevirtual

One-time setup, called after the component is attached and the owner is initialized.

Implements Sleak::Component.

Definition at line 78 of file ColliderComponent.cpp.

◆ IsTrigger()

bool Sleak::ColliderComponent::IsTrigger ( ) const
inline

Definition at line 96 of file ColliderComponent.hpp.

◆ SetLayer()

void Sleak::ColliderComponent::SetLayer ( uint32_t layer)
inline

Definition at line 89 of file ColliderComponent.hpp.

◆ SetMask()

void Sleak::ColliderComponent::SetMask ( uint32_t mask)
inline

Definition at line 91 of file ColliderComponent.hpp.

◆ SetOffset()

void Sleak::ColliderComponent::SetOffset ( const Math::Vector3D & offset)
inline

Definition at line 85 of file ColliderComponent.hpp.

◆ SetProxyId()

void Sleak::ColliderComponent::SetProxyId ( int id)
inline

Definition at line 99 of file ColliderComponent.hpp.

◆ SetTrigger()

void Sleak::ColliderComponent::SetTrigger ( bool trigger)
inline

Definition at line 95 of file ColliderComponent.hpp.

◆ Update()

void Sleak::ColliderComponent::Update ( float deltaTime)
overridevirtual

Implements Sleak::Component.

Definition at line 83 of file ColliderComponent.cpp.