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

Collision component using a box shape. More...

#include <BoxCollisionComponent.h>

Inheritance diagram for Engine::Components::BoxCollision:
Collaboration diagram for Engine::Components::BoxCollision:

Public Member Functions

 BoxCollision (Entities::Scene *scene, entt::entity entity, const glm::vec3 &halfExtents=glm::vec3(0.5f))
 Constructs a BoxCollisionComponent.
 BoxCollision (const Entities::SpawnContext &context, const glm::vec3 &halfExtents=glm::vec3(0.5f))
 Constructs a BoxCollisionComponent from spawn context data.
 ~BoxCollision () override=default
 Destroys the box collision component.
btCollisionShape * createShape () override
 Creates the Bullet collision shape.
void debugDraw (const glm::mat4 &worldTransform) const override
 Draws debug visualization of the box.
void setHalfExtents (const glm::vec3 &halfExtents)
 Sets the half extents of the box.
glm::vec3 getHalfExtents () const
 Gets the half extents of the box.
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 = "BoxCollision"
 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

glm::vec3 halfExtents_

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 box shape.

Definition at line 12 of file BoxCollisionComponent.h.

Constructor & Destructor Documentation

◆ BoxCollision() [1/2]

Engine::Components::BoxCollision::BoxCollision ( Entities::Scene * scene,
entt::entity entity,
const glm::vec3 & halfExtents = glm::vec3(0.5f) )

Constructs a BoxCollisionComponent.

Parameters
sceneThe owning scene.
entityThe ECS entity associated with this component.
halfExtentsHalf-size of the box in each axis (default 0.5 = 1m cube).

◆ BoxCollision() [2/2]

Engine::Components::BoxCollision::BoxCollision ( const Entities::SpawnContext & context,
const glm::vec3 & halfExtents = glm::vec3(0.5f) )

Constructs a BoxCollisionComponent from spawn context data.

Parameters
contextSpawn context containing the owning scene and entity data.
halfExtentsHalf-size of the box in each axis (default 0.5 = 1m cube).

◆ ~BoxCollision()

Engine::Components::BoxCollision::~BoxCollision ( )
overridedefault

Destroys the box collision component.

Member Function Documentation

◆ createShape()

btCollisionShape * Engine::Components::BoxCollision::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::BoxCollision::debugDraw ( const glm::mat4 & worldTransform) const
overridevirtual

Draws debug visualization of the box.

Parameters
worldTransformWorld transform of the entity.

Reimplemented from Engine::Components::Collision.

◆ getHalfExtents()

glm::vec3 Engine::Components::BoxCollision::getHalfExtents ( ) const
inlinenodiscard

Gets the half extents of the box.

Returns
Half-size in each axis.

Definition at line 61 of file BoxCollisionComponent.h.

References halfExtents_.

◆ setHalfExtents()

void Engine::Components::BoxCollision::setHalfExtents ( const glm::vec3 & halfExtents)

Sets the half extents of the box.

Parameters
halfExtentsHalf-size in each axis.

Member Data Documentation

◆ ComponentName

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

Component registry name.

Definition at line 15 of file BoxCollisionComponent.h.

◆ halfExtents_

glm::vec3 Engine::Components::BoxCollision::halfExtents_
private

Definition at line 67 of file BoxCollisionComponent.h.

Referenced by getHalfExtents().


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