Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
EngineCore::CollisionComponent Class Referenceabstract

Base class for collision shape components. More...

#include <CollisionComponent.h>

Inheritance diagram for EngineCore::CollisionComponent:
Collaboration diagram for EngineCore::CollisionComponent:

Public Member Functions

 CollisionComponent (Scene *scene, entt::entity entity)
 Constructs a CollisionComponent.
 ~CollisionComponent () override
void beginPlay () override
 Called when the component is added to the scene or the game starts.
void endPlay () override
 Called when the component is removed or the game ends.
virtual btCollisionShape * createShape ()=0
 Creates the Bullet collision shape. Must be implemented by derived classes.
virtual void destroyShape ()
 Destroys the current shape.
void markDirty ()
 Marks the shape as needing rebuild. Call after changing shape properties (halfExtents, radius, etc.).
void rebuild ()
 Rebuilds the shape and notifies PhysicsBodyComponent.
btCollisionShape * getShape () const
 Gets the current collision shape.
void setLocalOffset (const glm::vec3 &offset)
 Sets the local position offset relative to the body.
glm::vec3 getLocalOffset () const
 Gets the local position offset.
void setLocalRotation (const glm::quat &rotation)
 Sets the local rotation relative to the body.
glm::quat getLocalRotation () const
 Gets the local rotation.
glm::mat4 getLocalTransform () const
 Gets the local transform matrix.
void setIsTrigger (bool trigger)
 Sets whether this collision is a trigger (overlap only, no physics response).
bool isTrigger () const
 Checks if this collision is a trigger.
virtual void onCollisionBegin (CollisionComponent *other)
 Called when a collision with another object begins.
virtual void onCollisionEnd (CollisionComponent *other)
 Called when a collision with another object ends.
virtual void onCollisionStay (CollisionComponent *other)
 Called every frame while colliding with another object.
PhysicsBodyComponentgetBodyComponent () const
 Gets the physics body component this collision is registered with.
Public Member Functions inherited from EngineCore::LogicComponent
 LogicComponent (Scene *owningScene)
virtual ~LogicComponent ()=default
virtual void tick (double deltaTime)
 Called every frame if ticking is enabled.
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
EntitygetOwningEntity () const
 Gets the entity this component belongs to.

Static Public Attributes

static constexpr bool IsUnique = false
Static Public Attributes inherited from EngineCore::LogicComponent
static constexpr bool IsUnique = false
 Defines whether multiple instances of this component can exist on the same entity. Defaults to false (multiple allowed). Override in derived classes with static constexpr bool IsUnique = true; if needed.

Protected Attributes

entt::entity entity_
btCollisionShape * shape_ = nullptr
glm::vec3 localOffset_ {0.0f}
glm::quat localRotation_ {glm::identity<glm::quat>()}
PhysicsBodyComponentbodyComponent_ = nullptr
bool isTrigger_ = false
bool isDirty_ = false

Private Member Functions

void registerWithBody ()
void unregisterFromBody ()

Friends

class PhysicsBodyComponent

Additional Inherited Members

Protected Member Functions inherited from EngineCore::LogicComponent
ScenegetScene () const
 Gets the scene this component belongs to.
SceneManagergetSceneManager () const
 Helper to get the SceneManager from the owning scene.

Detailed Description

Base class for collision shape components.

CollisionComponent is the abstract base for all collision shapes. Multiple collision components can be attached to a single entity, and they will be combined into a compound shape by PhysicsBodyComponent.

Derived classes must implement createShape() to create the Bullet shape.

Author
Konstantin Passig
Date
2026-01-16

Definition at line 26 of file CollisionComponent.h.

Constructor & Destructor Documentation

◆ CollisionComponent()

EngineCore::CollisionComponent::CollisionComponent ( Scene * scene,
entt::entity entity )

Constructs a CollisionComponent.

Parameters
sceneThe owning scene.
entityThe ECS entity associated with this component.

Definition at line 10 of file CollisionComponent.cpp.

References entity_, EngineCore::LogicComponent::LogicComponent(), and EngineCore::LogicComponent::scene.

Referenced by EngineCore::BoxCollisionComponent::BoxCollisionComponent(), EngineCore::CapsuleCollisionComponent::CapsuleCollisionComponent(), onCollisionBegin(), onCollisionEnd(), onCollisionStay(), and EngineCore::SphereCollisionComponent::SphereCollisionComponent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~CollisionComponent()

EngineCore::CollisionComponent::~CollisionComponent ( )
override

Definition at line 16 of file CollisionComponent.cpp.

References destroyShape().

Here is the call graph for this function:

Member Function Documentation

◆ beginPlay()

void EngineCore::CollisionComponent::beginPlay ( )
overridevirtual

Called when the component is added to the scene or the game starts.

Reimplemented from EngineCore::LogicComponent.

Definition at line 20 of file CollisionComponent.cpp.

References EngineCore::LogicComponent::beginPlay(), createShape(), registerWithBody(), and shape_.

Here is the call graph for this function:

◆ createShape()

virtual btCollisionShape * EngineCore::CollisionComponent::createShape ( )
pure virtual

Creates the Bullet collision shape. Must be implemented by derived classes.

Returns
Pointer to the created shape.

Implemented in EngineCore::BoxCollisionComponent, EngineCore::CapsuleCollisionComponent, and EngineCore::SphereCollisionComponent.

Referenced by beginPlay(), and rebuild().

Here is the caller graph for this function:

◆ destroyShape()

void EngineCore::CollisionComponent::destroyShape ( )
virtual

Destroys the current shape.

Definition at line 38 of file CollisionComponent.cpp.

References shape_.

Referenced by endPlay(), rebuild(), and ~CollisionComponent().

Here is the caller graph for this function:

◆ endPlay()

void EngineCore::CollisionComponent::endPlay ( )
overridevirtual

Called when the component is removed or the game ends.

Reimplemented from EngineCore::LogicComponent.

Definition at line 32 of file CollisionComponent.cpp.

References destroyShape(), EngineCore::LogicComponent::endPlay(), and unregisterFromBody().

Here is the call graph for this function:

◆ getBodyComponent()

PhysicsBodyComponent * EngineCore::CollisionComponent::getBodyComponent ( ) const
inlinenodiscard

Gets the physics body component this collision is registered with.

Returns
Pointer to the body component, or nullptr if not registered.

Definition at line 153 of file CollisionComponent.h.

References bodyComponent_, and PhysicsBodyComponent.

Here is the call graph for this function:

◆ getLocalOffset()

glm::vec3 EngineCore::CollisionComponent::getLocalOffset ( ) const
inlinenodiscard

Gets the local position offset.

Returns
Position offset in local space.

Definition at line 91 of file CollisionComponent.h.

References localOffset_.

◆ getLocalRotation()

glm::quat EngineCore::CollisionComponent::getLocalRotation ( ) const
inlinenodiscard

Gets the local rotation.

Returns
Rotation quaternion.

Definition at line 103 of file CollisionComponent.h.

References localRotation_.

◆ getLocalTransform()

glm::mat4 EngineCore::CollisionComponent::getLocalTransform ( ) const
nodiscard

Gets the local transform matrix.

Returns
4x4 transform matrix combining offset and rotation.

Definition at line 78 of file CollisionComponent.cpp.

References localOffset_, and localRotation_.

◆ getShape()

btCollisionShape * EngineCore::CollisionComponent::getShape ( ) const
inlinenodiscard

Gets the current collision shape.

Returns
Pointer to the shape, or nullptr if not created.

Definition at line 75 of file CollisionComponent.h.

References shape_.

◆ isTrigger()

bool EngineCore::CollisionComponent::isTrigger ( ) const
inlinenodiscard

Checks if this collision is a trigger.

Returns
True if trigger mode.

Definition at line 125 of file CollisionComponent.h.

References isTrigger_.

◆ markDirty()

void EngineCore::CollisionComponent::markDirty ( )

Marks the shape as needing rebuild. Call after changing shape properties (halfExtents, radius, etc.).

Definition at line 45 of file CollisionComponent.cpp.

References isDirty_.

Referenced by EngineCore::BoxCollisionComponent::setHalfExtents(), EngineCore::CapsuleCollisionComponent::setHeight(), EngineCore::CapsuleCollisionComponent::setRadius(), and EngineCore::SphereCollisionComponent::setRadius().

Here is the caller graph for this function:

◆ onCollisionBegin()

void EngineCore::CollisionComponent::onCollisionBegin ( CollisionComponent * other)
virtual

Called when a collision with another object begins.

Parameters
otherThe other collision component.

Definition at line 94 of file CollisionComponent.cpp.

References CollisionComponent().

Here is the call graph for this function:

◆ onCollisionEnd()

void EngineCore::CollisionComponent::onCollisionEnd ( CollisionComponent * other)
virtual

Called when a collision with another object ends.

Parameters
otherThe other collision component.

Definition at line 99 of file CollisionComponent.cpp.

References CollisionComponent().

Here is the call graph for this function:

◆ onCollisionStay()

void EngineCore::CollisionComponent::onCollisionStay ( CollisionComponent * other)
virtual

Called every frame while colliding with another object.

Parameters
otherThe other collision component.

Definition at line 103 of file CollisionComponent.cpp.

References CollisionComponent().

Here is the call graph for this function:

◆ rebuild()

void EngineCore::CollisionComponent::rebuild ( )

Rebuilds the shape and notifies PhysicsBodyComponent.

Definition at line 49 of file CollisionComponent.cpp.

References bodyComponent_, createShape(), destroyShape(), isDirty_, and shape_.

Here is the call graph for this function:

◆ registerWithBody()

void EngineCore::CollisionComponent::registerWithBody ( )
private

Definition at line 107 of file CollisionComponent.cpp.

References bodyComponent_, EngineCore::LogicComponent::Entity, EngineCore::Entity::getComponent(), EngineCore::LogicComponent::getOwningEntity(), and PhysicsBodyComponent.

Referenced by beginPlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIsTrigger()

void EngineCore::CollisionComponent::setIsTrigger ( bool trigger)

Sets whether this collision is a trigger (overlap only, no physics response).

Parameters
triggerTrue for trigger mode.

Definition at line 85 of file CollisionComponent.cpp.

References bodyComponent_, and isTrigger_.

◆ setLocalOffset()

void EngineCore::CollisionComponent::setLocalOffset ( const glm::vec3 & offset)

Sets the local position offset relative to the body.

Parameters
offsetPosition offset in local space.

Definition at line 64 of file CollisionComponent.cpp.

References bodyComponent_, and localOffset_.

◆ setLocalRotation()

void EngineCore::CollisionComponent::setLocalRotation ( const glm::quat & rotation)

Sets the local rotation relative to the body.

Parameters
rotationRotation quaternion.

Definition at line 71 of file CollisionComponent.cpp.

References bodyComponent_, and localRotation_.

◆ unregisterFromBody()

void EngineCore::CollisionComponent::unregisterFromBody ( )
private

Definition at line 120 of file CollisionComponent.cpp.

References bodyComponent_.

Referenced by endPlay().

Here is the caller graph for this function:

◆ PhysicsBodyComponent

friend class PhysicsBodyComponent
friend

Definition at line 27 of file CollisionComponent.h.

References PhysicsBodyComponent.

Referenced by getBodyComponent(), PhysicsBodyComponent, and registerWithBody().

Member Data Documentation

◆ bodyComponent_

◆ entity_

entt::entity EngineCore::CollisionComponent::entity_
protected

Definition at line 156 of file CollisionComponent.h.

Referenced by CollisionComponent().

◆ isDirty_

bool EngineCore::CollisionComponent::isDirty_ = false
protected

Definition at line 162 of file CollisionComponent.h.

Referenced by markDirty(), and rebuild().

◆ isTrigger_

bool EngineCore::CollisionComponent::isTrigger_ = false
protected

Definition at line 161 of file CollisionComponent.h.

Referenced by isTrigger(), and setIsTrigger().

◆ IsUnique

bool EngineCore::CollisionComponent::IsUnique = false
staticconstexpr

Definition at line 30 of file CollisionComponent.h.

◆ localOffset_

glm::vec3 EngineCore::CollisionComponent::localOffset_ {0.0f}
protected

Definition at line 158 of file CollisionComponent.h.

Referenced by getLocalOffset(), getLocalTransform(), and setLocalOffset().

◆ localRotation_

glm::quat EngineCore::CollisionComponent::localRotation_ {glm::identity<glm::quat>()}
protected

Definition at line 159 of file CollisionComponent.h.

Referenced by getLocalRotation(), getLocalTransform(), and setLocalRotation().

◆ shape_

btCollisionShape* EngineCore::CollisionComponent::shape_ = nullptr
protected

Definition at line 157 of file CollisionComponent.h.

Referenced by beginPlay(), destroyShape(), getShape(), and rebuild().


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