Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Components::Collision Class Referenceabstract

Base class for collision shape components. More...

#include <CollisionComponent.h>

Inheritance diagram for Engine::Components::Collision:
Collaboration diagram for Engine::Components::Collision:

Public Member Functions

 Collision (Engine::Entities::Scene *scene, entt::entity entity)
 Constructs a CollisionComponent.
 ~Collision () 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 (Components::Collision *other)
 Called when a collision with another object begins.
virtual void onCollisionEnd (Components::Collision *other)
 Called when a collision with another object ends.
virtual void onCollisionStay (Components::Collision *other)
 Called every frame while colliding with another object.
Components::PhysicsBodygetBodyComponent () const
 Gets the physics body component this collision is registered with.
virtual void debugDraw (const glm::mat4 &worldTransform) const
 Draws debug visualization of the collision shape.
void setDebugColorSeed (std::uint64_t seed)
void setDebugName (std::string name)
const std::string & getDebugName () const
Public Member Functions inherited from Engine::Components::Logic
 Logic (Entities::Scene *owningScene)
virtual ~Logic ()=default
virtual std::string getComponentName () const
 Gets the component type name for debugging/UI.
virtual void tick (double deltaTime)
 Called every frame if ticking is enabled.
bool hasBegunPlay () const
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
Entities::EntitygetOwningEntity () const
 Gets the entity this component belongs to.

Static Public Member Functions

static void setDebugDrawEnabled (bool enabled)
 Enable or disable debug drawing for all collision components.
static bool isDebugDrawEnabled ()
 Check if debug drawing is enabled globally.

Static Public Attributes

static constexpr bool IsUnique = false
static constexpr const char * ComponentName = "Collision"
Static Public Attributes inherited from Engine::Components::Logic
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.
static constexpr const char * ComponentName = "Logic"
 Fallback component type name. Derived classes may override getComponentName() for custom labels.

Protected Member Functions

glm::vec4 getDebugDrawColor (const glm::vec4 &fallbackColor) const
Protected Member Functions inherited from Engine::Components::Logic
Entities::ScenegetScene () const
 Gets the scene this component belongs to.
Core::SceneManagergetSceneManager () const
 Helper to get the SceneManager from the owning scene.

Protected Attributes

entt::entity entity_
btCollisionShape * shape_ = nullptr
glm::vec3 localOffset_ {0.0f}
glm::quat localRotation_ {glm::identity<glm::quat>()}
Components::PhysicsBodybodyComponent_ = nullptr
std::string debugName_
std::uint64_t debugColorSeed_ = 0
bool hasDebugColorSeed_ = false
bool isTrigger_ = false
bool isDirty_ = false

Static Protected Attributes

static bool debugDrawEnabled_

Private Member Functions

void registerWithBody ()
void unregisterFromBody ()

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.

Definition at line 27 of file CollisionComponent.h.

Constructor & Destructor Documentation

◆ Collision()

Engine::Components::Collision::Collision ( Engine::Entities::Scene * scene,
entt::entity entity )

Constructs a CollisionComponent.

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

◆ ~Collision()

Engine::Components::Collision::~Collision ( )
override

Member Function Documentation

◆ beginPlay()

void Engine::Components::Collision::beginPlay ( )
overridevirtual

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

Reimplemented from Engine::Components::Logic.

◆ createShape()

virtual btCollisionShape * Engine::Components::Collision::createShape ( )
pure virtual

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

Returns
Pointer to the created shape.

Implemented in Engine::Components::BoxCollision, and Engine::Components::CapsuleCollision.

◆ debugDraw()

virtual void Engine::Components::Collision::debugDraw ( const glm::mat4 & worldTransform) const
virtual

Draws debug visualization of the collision shape.

Override in derived classes to visualize the specific shape type. Uses DebugDraw API to render wireframe representation.

Parameters
worldTransformWorld transform of the entity.

Reimplemented in Engine::Components::BoxCollision, and Engine::Components::CapsuleCollision.

◆ destroyShape()

virtual void Engine::Components::Collision::destroyShape ( )
virtual

Destroys the current shape.

◆ endPlay()

void Engine::Components::Collision::endPlay ( )
overridevirtual

Called when the component is removed or the game ends.

Reimplemented from Engine::Components::Logic.

◆ getBodyComponent()

Components::PhysicsBody * Engine::Components::Collision::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 154 of file CollisionComponent.h.

References bodyComponent_.

◆ getDebugDrawColor()

glm::vec4 Engine::Components::Collision::getDebugDrawColor ( const glm::vec4 & fallbackColor) const
nodiscardprotected

◆ getDebugName()

const std::string & Engine::Components::Collision::getDebugName ( ) const
inlinenodiscard

Definition at line 173 of file CollisionComponent.h.

References debugName_.

◆ getLocalOffset()

glm::vec3 Engine::Components::Collision::getLocalOffset ( ) const
inlinenodiscard

Gets the local position offset.

Returns
Position offset in local space.

Definition at line 92 of file CollisionComponent.h.

References localOffset_.

◆ getLocalRotation()

glm::quat Engine::Components::Collision::getLocalRotation ( ) const
inlinenodiscard

Gets the local rotation.

Returns
Rotation quaternion.

Definition at line 104 of file CollisionComponent.h.

References localRotation_.

◆ getLocalTransform()

glm::mat4 Engine::Components::Collision::getLocalTransform ( ) const
nodiscard

Gets the local transform matrix.

Returns
4x4 transform matrix combining offset and rotation.

◆ getShape()

btCollisionShape * Engine::Components::Collision::getShape ( ) const
inlinenodiscard

Gets the current collision shape.

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

Definition at line 76 of file CollisionComponent.h.

References shape_.

◆ isDebugDrawEnabled()

bool Engine::Components::Collision::isDebugDrawEnabled ( )
staticnodiscard

Check if debug drawing is enabled globally.

Returns
True if debug drawing is enabled.

◆ isTrigger()

bool Engine::Components::Collision::isTrigger ( ) const
inlinenodiscard

Checks if this collision is a trigger.

Returns
True if trigger mode.

Definition at line 126 of file CollisionComponent.h.

References isTrigger_.

◆ markDirty()

void Engine::Components::Collision::markDirty ( )

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

◆ onCollisionBegin()

virtual void Engine::Components::Collision::onCollisionBegin ( Components::Collision * other)
virtual

Called when a collision with another object begins.

Parameters
otherThe other collision component.

◆ onCollisionEnd()

virtual void Engine::Components::Collision::onCollisionEnd ( Components::Collision * other)
virtual

Called when a collision with another object ends.

Parameters
otherThe other collision component.

◆ onCollisionStay()

virtual void Engine::Components::Collision::onCollisionStay ( Components::Collision * other)
virtual

Called every frame while colliding with another object.

Parameters
otherThe other collision component.

◆ rebuild()

void Engine::Components::Collision::rebuild ( )

Rebuilds the shape and notifies PhysicsBodyComponent.

◆ registerWithBody()

void Engine::Components::Collision::registerWithBody ( )
private

◆ setDebugColorSeed()

void Engine::Components::Collision::setDebugColorSeed ( std::uint64_t seed)

◆ setDebugDrawEnabled()

void Engine::Components::Collision::setDebugDrawEnabled ( bool enabled)
static

Enable or disable debug drawing for all collision components.

Parameters
enabledTrue to enable debug drawing.

◆ setDebugName()

void Engine::Components::Collision::setDebugName ( std::string name)

◆ setIsTrigger()

void Engine::Components::Collision::setIsTrigger ( bool trigger)

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

Parameters
triggerTrue for trigger mode.

◆ setLocalOffset()

void Engine::Components::Collision::setLocalOffset ( const glm::vec3 & offset)

Sets the local position offset relative to the body.

Parameters
offsetPosition offset in local space.

◆ setLocalRotation()

void Engine::Components::Collision::setLocalRotation ( const glm::quat & rotation)

Sets the local rotation relative to the body.

Parameters
rotationRotation quaternion.

◆ unregisterFromBody()

void Engine::Components::Collision::unregisterFromBody ( )
private

Member Data Documentation

◆ bodyComponent_

Components::PhysicsBody* Engine::Components::Collision::bodyComponent_ = nullptr
protected

Definition at line 195 of file CollisionComponent.h.

Referenced by getBodyComponent().

◆ ComponentName

const char* Engine::Components::Collision::ComponentName = "Collision"
staticconstexpr

Definition at line 32 of file CollisionComponent.h.

◆ debugColorSeed_

std::uint64_t Engine::Components::Collision::debugColorSeed_ = 0
protected

Definition at line 197 of file CollisionComponent.h.

◆ debugDrawEnabled_

bool Engine::Components::Collision::debugDrawEnabled_
staticprotected

Definition at line 190 of file CollisionComponent.h.

◆ debugName_

std::string Engine::Components::Collision::debugName_
protected

Definition at line 196 of file CollisionComponent.h.

Referenced by getDebugName().

◆ entity_

entt::entity Engine::Components::Collision::entity_
protected

Definition at line 191 of file CollisionComponent.h.

◆ hasDebugColorSeed_

bool Engine::Components::Collision::hasDebugColorSeed_ = false
protected

Definition at line 198 of file CollisionComponent.h.

◆ isDirty_

bool Engine::Components::Collision::isDirty_ = false
protected

Definition at line 200 of file CollisionComponent.h.

◆ isTrigger_

bool Engine::Components::Collision::isTrigger_ = false
protected

Definition at line 199 of file CollisionComponent.h.

Referenced by isTrigger().

◆ IsUnique

bool Engine::Components::Collision::IsUnique = false
staticconstexpr

Definition at line 31 of file CollisionComponent.h.

◆ localOffset_

glm::vec3 Engine::Components::Collision::localOffset_ {0.0f}
protected

Definition at line 193 of file CollisionComponent.h.

Referenced by getLocalOffset().

◆ localRotation_

glm::quat Engine::Components::Collision::localRotation_ {glm::identity<glm::quat>()}
protected

Definition at line 194 of file CollisionComponent.h.

Referenced by getLocalRotation().

◆ shape_

btCollisionShape* Engine::Components::Collision::shape_ = nullptr
protected

Definition at line 192 of file CollisionComponent.h.

Referenced by getShape().


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Component/Collision/CollisionComponent.h