Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Components::CapsuleCollision Class Reference

Collision component using a capsule shape (cylinder with hemispherical ends). More...

#include <CapsuleCollisionComponent.h>

Inheritance diagram for Engine::Components::CapsuleCollision:
Collaboration diagram for Engine::Components::CapsuleCollision:

Public Member Functions

 CapsuleCollision (Entities::Scene *scene, entt::entity entity, float radius=0.5f, float height=1.0f)
 Constructs a CapsuleCollisionComponent.
 ~CapsuleCollision () override=default
 Destroys the capsule collision component.
btCollisionShape * createShape () override
 Creates the Bullet collision shape.
void debugDraw (const glm::mat4 &worldTransform) const override
 Draws debug visualization of the capsule.
void setRadius (float radius)
 Sets the radius of the capsule.
float getRadius () const
 Gets the radius of the capsule.
void setHeight (float height)
 Sets the height of the cylindrical portion.
float getHeight () const
 Gets the height of the cylindrical portion.
Public Member Functions inherited from Engine::Components::Collision
 Collision (Engine::Entities::Scene *scene, entt::entity entity)
 Constructs a CollisionComponent.
 ~Collision () override
 Clears callback subscriptions and destroys the current Bullet shape.
void beginPlay () override
 Creates the Bullet shape and registers this component with a same-entity physics body.
void endPlay () override
 Clears callbacks, unregisters from the physics body, and destroys the Bullet shape.
bool drawImGui () override
 Draws the base logic component ImGui controls.
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.
void setCollisionProfile (Physics::CollisionProfileHandle profile)
 Sets the collision profile handle used for filtering and response lookup.
void setCollisionProfileByName (const std::string &profileName)
 Sets the collision profile by registered profile name.
Physics::CollisionProfileHandle getCollisionProfile () const
 Gets the effective collision profile handle.
template<typename ProfileEnum>
void setCollisionProfile (ProfileEnum profile)
 Sets the collision profile from an enum registered with the active collision profile registry.
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.
virtual void onOverlapBegin (Components::Collision *other)
 Called when an overlap with another collision component begins.
virtual void onOverlapEnd (Components::Collision *other)
 Called when an overlap with another collision component ends.
virtual void onOverlapStay (Components::Collision *other)
 Called every frame while overlapping another collision component.
template<typename ActorType, typename Callback>
CollisionCallbackHandle onOverlapBegin (Callback &&callback)
 Registers a typed overlap-begin callback.
template<typename ActorType, typename Callback>
CollisionCallbackHandle onOverlapEnd (Callback &&callback)
 Registers a typed overlap-end callback.
void removeOverlapCallback (CollisionCallbackHandle handle)
 Removes an overlap callback registered with Collision::onOverlapBegin() or Collision::onOverlapEnd().
void dispatchOverlapBegin (Components::Collision *other)
 Dispatches overlap begin hooks and callbacks.
void dispatchOverlapEnd (Components::Collision *other)
 Dispatches overlap end hooks and callbacks.
void dispatchOverlapStay (Components::Collision *other)
 Dispatches overlap stay hooks.
void dispatchCollisionBegin (Components::Collision *other)
 Dispatches collision begin hooks.
void dispatchCollisionEnd (Components::Collision *other)
 Dispatches collision end hooks.
void dispatchCollisionStay (Components::Collision *other)
 Dispatches collision stay hooks.
Components::PhysicsBody * getBodyComponent () const
 Gets the physics body component this collision is registered with.
Physics::CollisionHandle getCollisionHandle () const
 Gets the runtime collision handle assigned by the physics engine.
void setCollisionHandle (Physics::CollisionHandle handle)
 Sets the runtime collision handle assigned by the physics engine.
void setDebugColorSeed (std::uint64_t seed)
 Sets a stable seed used for random debug color selection.
void setDebugName (std::string name)
 Sets the debug display name for this collision component.
const std::string & getDebugName () const
 Gets the debug display name for this collision component.
Public Member Functions inherited from Engine::Components::Logic
 Logic (Entities::Scene *owningScene)
 Constructs a logic component owned by a scene.
 Logic (const Entities::SpawnContext &context)
 Constructs a logic component from spawn context data.
virtual ~Logic ()=default
 Destroys the logic component.
virtual std::string getComponentName () const
 Gets the component type name for debugging/UI.
virtual bool drawImGuiName ()
 Used to alter the name of the entity in the outliner.
virtual void tick (double deltaTime)
 Called every frame if ticking is enabled.
bool hasBegunPlay () const
 Checks whether beginPlay() has been called without a matching endPlay().
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
Entities::Entity * getOwningEntity () const
 Gets the entity this component belongs to.

Static Public Attributes

static constexpr const char * ComponentName = "CapsuleCollision"
 Component registry name.
Static Public Attributes inherited from Engine::Components::Collision
static constexpr bool IsUnique = false
 Multiple collision components can exist on one entity.
static constexpr const char * ComponentName = "Collision"
 Component type name used by engine tools.
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.

Private Attributes

float radius_
float height_

Additional Inherited Members

Public Types inherited from Engine::Components::Collision
using CollisionCallbackHandle = std::uint64_t
 Opaque handle for an overlap callback subscription.
Static Public Member Functions inherited from Engine::Components::Collision
static void setDebugDrawEnabled (bool enabled)
 Enable or disable debug drawing for all collision components.
static bool isDebugDrawEnabled ()
 Check if debug drawing is enabled globally.
Protected Member Functions inherited from Engine::Components::Collision
glm::vec4 getDebugDrawColor (const glm::vec4 &fallbackColor) const
 Gets the color used by debug drawing.
Protected Member Functions inherited from Engine::Components::Logic
Entities::Scene * getScene () const
 Gets the scene this component belongs to.
Core::SceneManager * getSceneManager () const
 Helper to get the SceneManager from the owning scene.
Protected Attributes inherited from Engine::Components::Collision
entt::entity entity_
 ECS entity associated with this component.
btCollisionShape * shape_ = nullptr
 Current Bullet shape owned by this component.
glm::vec3 localOffset_ {0.0f}
 Local position offset relative to the owning body.
glm::quat localRotation_ {glm::identity<glm::quat>()}
 Local rotation relative to the owning body.
Components::PhysicsBody * bodyComponent_ = nullptr
 Physics body this collision is registered with.
std::string debugName_
 Debug display name.
std::uint64_t debugColorSeed_ = 0
 Stable seed for random debug color selection.
bool hasDebugColorSeed_ = false
 True when debugColorSeed_ was explicitly set.
bool isTrigger_ = false
 Legacy trigger flag retained for compatibility.
bool isDirty_ = false
 True when the shape needs rebuild.
Physics::CollisionProfileHandle collisionProfile_
 Explicit collision profile override.
Physics::CollisionHandle collisionHandle_
 Runtime handle assigned by the physics engine.
Static Protected Attributes inherited from Engine::Components::Collision
static bool debugDrawEnabled_
 Global collision debug draw toggle.

Detailed Description

Collision component using a capsule shape (cylinder with hemispherical ends).

The capsule is aligned along the Y axis by default.

Definition at line 12 of file CapsuleCollisionComponent.h.

Constructor & Destructor Documentation

◆ CapsuleCollision()

Engine::Components::CapsuleCollision::CapsuleCollision ( Entities::Scene * scene,
entt::entity entity,
float radius = 0.5f,
float height = 1.0f )

Constructs a CapsuleCollisionComponent.

Parameters
sceneThe owning scene.
entityThe ECS entity associated with this component.
radiusRadius of the capsule (default 0.5).
heightHeight of the cylindrical portion (default 1.0).

◆ ~CapsuleCollision()

Engine::Components::CapsuleCollision::~CapsuleCollision ( )
overridedefault

Destroys the capsule collision component.

Member Function Documentation

◆ createShape()

btCollisionShape * Engine::Components::CapsuleCollision::createShape ( )
overridevirtual

Creates the Bullet collision shape.

Derived implementations must allocate the shape with new and return ownership to the collision component. The base component deletes it from Collision::destroyShape().

Returns
Newly allocated Bullet collision shape.

Implements Engine::Components::Collision.

◆ debugDraw()

void Engine::Components::CapsuleCollision::debugDraw ( const glm::mat4 & worldTransform) const
overridevirtual

Draws debug visualization of the capsule.

Parameters
worldTransformWorld transform of the entity.

Reimplemented from Engine::Components::Collision.

◆ getHeight()

float Engine::Components::CapsuleCollision::getHeight ( ) const
inlinenodiscard

Gets the height of the cylindrical portion.

Returns
Height in meters.

Definition at line 60 of file CapsuleCollisionComponent.h.

References height_.

◆ getRadius()

float Engine::Components::CapsuleCollision::getRadius ( ) const
inlinenodiscard

Gets the radius of the capsule.

Returns
Radius in meters.

Definition at line 48 of file CapsuleCollisionComponent.h.

References radius_.

◆ setHeight()

void Engine::Components::CapsuleCollision::setHeight ( float height)

Sets the height of the cylindrical portion.

Parameters
heightHeight in meters.

◆ setRadius()

void Engine::Components::CapsuleCollision::setRadius ( float radius)

Sets the radius of the capsule.

Parameters
radiusRadius in meters.

Member Data Documentation

◆ ComponentName

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

Component registry name.

Definition at line 14 of file CapsuleCollisionComponent.h.

◆ height_

float Engine::Components::CapsuleCollision::height_
private

Definition at line 64 of file CapsuleCollisionComponent.h.

Referenced by getHeight().

◆ radius_

float Engine::Components::CapsuleCollision::radius_
private

Definition at line 63 of file CapsuleCollisionComponent.h.

Referenced by getRadius().


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