|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
Base class for collision shape components. More...
#include <CollisionComponent.h>
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. | |
| PhysicsBodyComponent * | getBodyComponent () 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. | |
| Entity * | getOwningEntity () 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>()} |
| PhysicsBodyComponent * | bodyComponent_ = 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 | |
| Scene * | getScene () const |
| Gets the scene this component belongs to. | |
| SceneManager * | getSceneManager () const |
| Helper to get the SceneManager from the owning scene. | |
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 26 of file CollisionComponent.h.
| EngineCore::CollisionComponent::CollisionComponent | ( | Scene * | scene, |
| entt::entity | entity ) |
Constructs a CollisionComponent.
| scene | The owning scene. |
| entity | The 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().
|
override |
Definition at line 16 of file CollisionComponent.cpp.
References destroyShape().
|
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_.
|
pure virtual |
Creates the Bullet collision shape. Must be implemented by derived classes.
Implemented in EngineCore::BoxCollisionComponent, EngineCore::CapsuleCollisionComponent, and EngineCore::SphereCollisionComponent.
Referenced by beginPlay(), and rebuild().
|
virtual |
Destroys the current shape.
Definition at line 38 of file CollisionComponent.cpp.
References shape_.
Referenced by endPlay(), rebuild(), and ~CollisionComponent().
|
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().
|
inlinenodiscard |
Gets the physics body component this collision is registered with.
Definition at line 153 of file CollisionComponent.h.
References bodyComponent_, and PhysicsBodyComponent.
|
inlinenodiscard |
Gets the local position offset.
Definition at line 91 of file CollisionComponent.h.
References localOffset_.
|
inlinenodiscard |
Gets the local rotation.
Definition at line 103 of file CollisionComponent.h.
References localRotation_.
|
nodiscard |
Gets the local transform matrix.
Definition at line 78 of file CollisionComponent.cpp.
References localOffset_, and localRotation_.
|
inlinenodiscard |
Gets the current collision shape.
Definition at line 75 of file CollisionComponent.h.
References shape_.
|
inlinenodiscard |
Checks if this collision is a trigger.
Definition at line 125 of file CollisionComponent.h.
References isTrigger_.
| 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().
|
virtual |
Called when a collision with another object begins.
| other | The other collision component. |
Definition at line 94 of file CollisionComponent.cpp.
References CollisionComponent().
|
virtual |
Called when a collision with another object ends.
| other | The other collision component. |
Definition at line 99 of file CollisionComponent.cpp.
References CollisionComponent().
|
virtual |
Called every frame while colliding with another object.
| other | The other collision component. |
Definition at line 103 of file CollisionComponent.cpp.
References CollisionComponent().
| 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_.
|
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().
| void EngineCore::CollisionComponent::setIsTrigger | ( | bool | trigger | ) |
Sets whether this collision is a trigger (overlap only, no physics response).
| trigger | True for trigger mode. |
Definition at line 85 of file CollisionComponent.cpp.
References bodyComponent_, and isTrigger_.
| void EngineCore::CollisionComponent::setLocalOffset | ( | const glm::vec3 & | offset | ) |
Sets the local position offset relative to the body.
| offset | Position offset in local space. |
Definition at line 64 of file CollisionComponent.cpp.
References bodyComponent_, and localOffset_.
| void EngineCore::CollisionComponent::setLocalRotation | ( | const glm::quat & | rotation | ) |
Sets the local rotation relative to the body.
| rotation | Rotation quaternion. |
Definition at line 71 of file CollisionComponent.cpp.
References bodyComponent_, and localRotation_.
|
private |
Definition at line 120 of file CollisionComponent.cpp.
References bodyComponent_.
Referenced by endPlay().
|
friend |
Definition at line 27 of file CollisionComponent.h.
References PhysicsBodyComponent.
Referenced by getBodyComponent(), PhysicsBodyComponent, and registerWithBody().
|
protected |
Definition at line 160 of file CollisionComponent.h.
Referenced by getBodyComponent(), rebuild(), EngineCore::PhysicsBodyComponent::registerCollision(), registerWithBody(), setIsTrigger(), setLocalOffset(), setLocalRotation(), EngineCore::PhysicsBodyComponent::unregisterCollision(), and unregisterFromBody().
|
protected |
Definition at line 156 of file CollisionComponent.h.
Referenced by CollisionComponent().
|
protected |
Definition at line 162 of file CollisionComponent.h.
Referenced by markDirty(), and rebuild().
|
protected |
Definition at line 161 of file CollisionComponent.h.
Referenced by isTrigger(), and setIsTrigger().
|
staticconstexpr |
Definition at line 30 of file CollisionComponent.h.
|
protected |
Definition at line 158 of file CollisionComponent.h.
Referenced by getLocalOffset(), getLocalTransform(), and setLocalOffset().
|
protected |
Definition at line 159 of file CollisionComponent.h.
Referenced by getLocalRotation(), getLocalTransform(), and setLocalRotation().
|
protected |
Definition at line 157 of file CollisionComponent.h.
Referenced by beginPlay(), destroyShape(), getShape(), and rebuild().