|
Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
|
Base class for collision shape components. More...
#include <CollisionComponent.h>
Classes | |
| struct | CallbackSubscription |
Public Types | |
| using | CollisionCallbackHandle = std::uint64_t |
| Opaque handle for an overlap callback subscription. | |
Public Member Functions | |
| 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 btCollisionShape * | createShape ()=0 |
| Creates the Bullet collision shape. | |
| 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. | |
| virtual void | debugDraw (const glm::mat4 &worldTransform) const |
| Draws debug visualization of the collision shape. | |
| 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 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 |
| 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. | |
Protected Member Functions | |
| 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 | |
| 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 | |
| static bool | debugDrawEnabled_ |
| Global collision debug draw toggle. | |
Private Member Functions | |
| CollisionCallbackHandle | addOverlapBeginCallback (std::function< void(Components::Collision *)> callback) |
| CollisionCallbackHandle | addOverlapEndCallback (std::function< void(Components::Collision *)> callback) |
| void | clearCallbacks () |
| void | registerWithBody () |
| void | unregisterFromBody () |
Private Attributes | |
| CollisionCallbackHandle | nextCallbackHandle_ = 1 |
| std::vector< CallbackSubscription > | overlapBeginCallbacks_ |
| std::vector< CallbackSubscription > | overlapEndCallbacks_ |
Base class for collision shape components.
Collision is the abstract base for shape components such as boxes, spheres, capsules, convex hulls, and triangle meshes. Multiple collision components can be attached to one entity and are combined by Engine::Components::PhysicsBody into one Bullet compound shape.
Derived classes must implement Collision::createShape() and return a heap-allocated Bullet shape. The base class deletes the shape in Collision::destroyShape().
Definition at line 32 of file CollisionComponent.h.
| using Engine::Components::Collision::CollisionCallbackHandle = std::uint64_t |
Opaque handle for an overlap callback subscription.
Definition at line 40 of file CollisionComponent.h.
| Engine::Components::Collision::Collision | ( | Engine::Entities::Scene * | scene, |
| entt::entity | entity ) |
Constructs a CollisionComponent.
| scene | The owning scene. |
| entity | The ECS entity associated with this component. |
|
override |
Clears callback subscriptions and destroys the current Bullet shape.
|
private |
|
private |
|
overridevirtual |
Creates the Bullet shape and registers this component with a same-entity physics body.
Reimplemented from Engine::Components::Logic.
|
private |
|
pure virtual |
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().
Implemented in Engine::Components::BoxCollision, and Engine::Components::CapsuleCollision.
|
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.
| worldTransform | World transform of the entity. |
Reimplemented in Engine::Components::BoxCollision, and Engine::Components::CapsuleCollision.
|
virtual |
Destroys the current shape.
Derived classes that allocate auxiliary Bullet data must override this and release that data after calling the base implementation.
| void Engine::Components::Collision::dispatchCollisionBegin | ( | Components::Collision * | other | ) |
Dispatches collision begin hooks.
| other | Other collision component. |
| void Engine::Components::Collision::dispatchCollisionEnd | ( | Components::Collision * | other | ) |
Dispatches collision end hooks.
| other | Other collision component. |
| void Engine::Components::Collision::dispatchCollisionStay | ( | Components::Collision * | other | ) |
Dispatches collision stay hooks.
| other | Other collision component. |
| void Engine::Components::Collision::dispatchOverlapBegin | ( | Components::Collision * | other | ) |
Dispatches overlap begin hooks and callbacks.
| other | Other collision component, or nullptr for lifetime end invalidation paths. |
| void Engine::Components::Collision::dispatchOverlapEnd | ( | Components::Collision * | other | ) |
Dispatches overlap end hooks and callbacks.
| other | Other collision component, or nullptr for lifetime end invalidation paths. |
| void Engine::Components::Collision::dispatchOverlapStay | ( | Components::Collision * | other | ) |
Dispatches overlap stay hooks.
| other | Other collision component. |
|
overridevirtual |
Draws the base logic component ImGui controls.
Reimplemented from Engine::Components::Logic.
|
overridevirtual |
Clears callbacks, unregisters from the physics body, and destroys the Bullet shape.
Reimplemented from Engine::Components::Logic.
|
inlinenodiscard |
Gets the physics body component this collision is registered with.
Definition at line 356 of file CollisionComponent.h.
References bodyComponent_.
Referenced by onOverlapBegin(), and onOverlapEnd().
|
inlinenodiscard |
Gets the runtime collision handle assigned by the physics engine.
Definition at line 362 of file CollisionComponent.h.
References collisionHandle_.
|
nodiscard |
Gets the effective collision profile handle.
|
nodiscardprotected |
Gets the color used by debug drawing.
Returns fallbackColor unless random collision debug colors are enabled in engine config. When random colors are enabled, the color comes from Collision::setDebugColorSeed() or from this component's address.
| fallbackColor | Color to use when random debug colors are disabled. |
|
inlinenodiscard |
Gets the debug display name for this collision component.
Definition at line 403 of file CollisionComponent.h.
References debugName_.
|
inlinenodiscard |
Gets the local position offset.
Definition at line 125 of file CollisionComponent.h.
References localOffset_.
|
inlinenodiscard |
Gets the local rotation.
Definition at line 137 of file CollisionComponent.h.
References localRotation_.
|
nodiscard |
Gets the local transform matrix.
|
inlinenodiscard |
Gets the current collision shape.
Definition at line 109 of file CollisionComponent.h.
References shape_.
|
staticnodiscard |
Check if debug drawing is enabled globally.
|
inlinenodiscard |
Checks if this collision is a trigger.
Definition at line 163 of file CollisionComponent.h.
References isTrigger_.
| void Engine::Components::Collision::markDirty | ( | ) |
Marks the shape as needing rebuild. Call after changing shape properties (halfExtents, radius, etc.).
|
virtual |
Called when a collision with another object begins.
| other | The other collision component. |
|
virtual |
Called when a collision with another object ends.
| other | The other collision component. |
|
virtual |
Called every frame while colliding with another object.
| other | The other collision component. |
|
inline |
Registers a typed overlap-begin callback.
The callback runs only when the other collision's owning actor is an ActorType. The callback receives that actor by reference.
| ActorType | Actor type required for callback dispatch. |
| Callback | Callable type invocable with ActorType &. |
| callback | Callback invoked on matching overlap begin events. |
Definition at line 263 of file CollisionComponent.h.
References addOverlapBeginCallback(), getBodyComponent(), and Engine::Components::PhysicsBody::getHitActor().
|
virtual |
Called when an overlap with another collision component begins.
| other | The other collision component. |
|
inline |
Registers a typed overlap-end callback.
The callback runs only when the other collision's owning actor is an ActorType. The callback receives that actor by reference.
| ActorType | Actor type required for callback dispatch. |
| Callback | Callable type invocable with ActorType &. |
| callback | Callback invoked on matching overlap end events. |
Definition at line 292 of file CollisionComponent.h.
References addOverlapEndCallback(), getBodyComponent(), and Engine::Components::PhysicsBody::getHitActor().
|
virtual |
Called when an overlap with another collision component ends.
| other | The other collision component. |
|
virtual |
Called every frame while overlapping another collision component.
| other | The other collision component. |
| void Engine::Components::Collision::rebuild | ( | ) |
Rebuilds the shape and notifies PhysicsBodyComponent.
If this component is not dirty, the call does nothing.
|
private |
| void Engine::Components::Collision::removeOverlapCallback | ( | CollisionCallbackHandle | handle | ) |
Removes an overlap callback registered with Collision::onOverlapBegin() or Collision::onOverlapEnd().
| handle | Callback handle returned at registration time. |
|
inline |
Sets the runtime collision handle assigned by the physics engine.
| handle | Collision handle to store. |
Definition at line 368 of file CollisionComponent.h.
References collisionHandle_.
| void Engine::Components::Collision::setCollisionProfile | ( | Physics::CollisionProfileHandle | profile | ) |
Sets the collision profile handle used for filtering and response lookup.
Invalid handles are replaced with the active registry fallback profile when a registry exists. Changing the profile marks collision filters dirty on the owning physics body.
| profile | Collision profile handle to assign. |
Referenced by setCollisionProfile().
|
inline |
Sets the collision profile from an enum registered with the active collision profile registry.
If no active registry exists, the call does nothing.
| ProfileEnum | Enum type registered with Physics::CollisionProfileRegistry. |
| profile | Enum value to resolve. |
Definition at line 203 of file CollisionComponent.h.
References Engine::Physics::getActiveCollisionProfileRegistry(), and setCollisionProfile().
| void Engine::Components::Collision::setCollisionProfileByName | ( | const std::string & | profileName | ) |
Sets the collision profile by registered profile name.
If no active registry exists or profileName is unknown, the call does nothing.
| profileName | Full profile name registered in the active collision profile registry. |
| void Engine::Components::Collision::setDebugColorSeed | ( | std::uint64_t | seed | ) |
Sets a stable seed used for random debug color selection.
The seed is used only when random collision debug colors are enabled in engine config.
| seed | Stable debug color seed. |
|
static |
Enable or disable debug drawing for all collision components.
| enabled | True to enable debug drawing. |
| void Engine::Components::Collision::setDebugName | ( | std::string | name | ) |
Sets the debug display name for this collision component.
| name | Debug name shown by tooling and logs. |
| void Engine::Components::Collision::setIsTrigger | ( | bool | trigger | ) |
Sets whether this collision is a trigger (overlap only, no physics response).
Prefer collision profiles that resolve to Physics::CollisionResponse::Overlap. This legacy flag marks collision filters dirty on the owning physics body.
| trigger | True for trigger mode. |
| void Engine::Components::Collision::setLocalOffset | ( | const glm::vec3 & | offset | ) |
Sets the local position offset relative to the body.
| offset | Position offset in local space. |
| void Engine::Components::Collision::setLocalRotation | ( | const glm::quat & | rotation | ) |
Sets the local rotation relative to the body.
| rotation | Rotation quaternion. |
|
private |
|
protected |
Physics body this collision is registered with.
Definition at line 435 of file CollisionComponent.h.
Referenced by getBodyComponent().
|
protected |
Runtime handle assigned by the physics engine.
Definition at line 442 of file CollisionComponent.h.
Referenced by getCollisionHandle(), and setCollisionHandle().
|
protected |
Explicit collision profile override.
Definition at line 441 of file CollisionComponent.h.
|
staticconstexpr |
Component type name used by engine tools.
Definition at line 37 of file CollisionComponent.h.
|
protected |
Stable seed for random debug color selection.
Definition at line 437 of file CollisionComponent.h.
|
staticprotected |
Global collision debug draw toggle.
Definition at line 430 of file CollisionComponent.h.
|
protected |
Debug display name.
Definition at line 436 of file CollisionComponent.h.
Referenced by getDebugName().
|
protected |
ECS entity associated with this component.
Definition at line 431 of file CollisionComponent.h.
|
protected |
True when debugColorSeed_ was explicitly set.
Definition at line 438 of file CollisionComponent.h.
|
protected |
True when the shape needs rebuild.
Definition at line 440 of file CollisionComponent.h.
|
protected |
Legacy trigger flag retained for compatibility.
Definition at line 439 of file CollisionComponent.h.
Referenced by isTrigger().
|
staticconstexpr |
Multiple collision components can exist on one entity.
Definition at line 36 of file CollisionComponent.h.
|
protected |
Local position offset relative to the owning body.
Definition at line 433 of file CollisionComponent.h.
Referenced by getLocalOffset().
|
protected |
Local rotation relative to the owning body.
Definition at line 434 of file CollisionComponent.h.
Referenced by getLocalRotation().
|
private |
Definition at line 458 of file CollisionComponent.h.
|
private |
Definition at line 459 of file CollisionComponent.h.
|
private |
Definition at line 460 of file CollisionComponent.h.
|
protected |
Current Bullet shape owned by this component.
Definition at line 432 of file CollisionComponent.h.
Referenced by getShape().