3#include "Engine/Component/LogicComponent.h"
4#include "Engine/Component/PhysicsBodyComponent.h"
5#include "Engine/Physics/CollisionProfileRegistry.h"
7#include <glm/gtc/quaternion.hpp>
8#include <entt/entt.hpp>
17class btCollisionShape;
157 [[deprecated(
"Use setCollisionProfile() with an overlap profile instead")]]
void setIsTrigger(
bool trigger);
202 template <
typename ProfileEnum >
262 template<
typename ActorType,
typename Callback>
269 auto * actor = otherBody !=
nullptr
270 ?
dynamic_cast<ActorType *
>( otherBody->
getHitActor() )
272 if ( actor !=
nullptr )
291 template<
typename ActorType,
typename Callback>
298 auto * actor = otherBody !=
nullptr
299 ?
dynamic_cast<ActorType *
>( otherBody->
getHitActor() )
301 if ( actor !=
nullptr )
382 virtual void debugDraw(
const glm::mat4& worldTransform)
const;
Base class for collision shape components.
btCollisionShape * getShape() const
Gets the current collision shape.
void dispatchOverlapEnd(Components::Collision *other)
Dispatches overlap end hooks and callbacks.
std::uint64_t CollisionCallbackHandle
Opaque handle for an overlap callback subscription.
void setCollisionProfileByName(const std::string &profileName)
Sets the collision profile by registered profile name.
virtual void onCollisionStay(Components::Collision *other)
Called every frame while colliding with another object.
void setIsTrigger(bool trigger)
Sets whether this collision is a trigger (overlap only, no physics response).
static void setDebugDrawEnabled(bool enabled)
Enable or disable debug drawing for all collision components.
std::vector< CallbackSubscription > overlapBeginCallbacks_
std::vector< CallbackSubscription > overlapEndCallbacks_
Physics::CollisionHandle collisionHandle_
Runtime handle assigned by the physics engine.
static constexpr const char * ComponentName
Component type name used by engine tools.
void dispatchCollisionEnd(Components::Collision *other)
Dispatches collision end hooks.
static bool debugDrawEnabled_
Global collision debug draw toggle.
virtual void debugDraw(const glm::mat4 &worldTransform) const
Draws debug visualization of the collision shape.
bool drawImGui() override
Draws the base logic component ImGui controls.
void markDirty()
Marks the shape as needing rebuild. Call after changing shape properties (halfExtents,...
void removeOverlapCallback(CollisionCallbackHandle handle)
Removes an overlap callback registered with Collision::onOverlapBegin() or Collision::onOverlapEnd().
void setLocalRotation(const glm::quat &rotation)
Sets the local rotation relative to the body.
void endPlay() override
Clears callbacks, unregisters from the physics body, and destroys the Bullet shape.
glm::vec3 getLocalOffset() const
Gets the local position offset.
btCollisionShape * shape_
Current Bullet shape owned by this component.
void dispatchCollisionStay(Components::Collision *other)
Dispatches collision stay hooks.
CollisionCallbackHandle onOverlapBegin(Callback &&callback)
Registers a typed overlap-begin callback.
Components::PhysicsBody * bodyComponent_
Physics body this collision is registered with.
std::string debugName_
Debug display name.
void setCollisionProfile(ProfileEnum profile)
Sets the collision profile from an enum registered with the active collision profile registry.
virtual void onOverlapStay(Components::Collision *other)
Called every frame while overlapping another collision component.
bool isTrigger_
Legacy trigger flag retained for compatibility.
glm::quat localRotation_
Local rotation relative to the owning body.
void setCollisionHandle(Physics::CollisionHandle handle)
Sets the runtime collision handle assigned by the physics engine.
CollisionCallbackHandle addOverlapEndCallback(std::function< void(Components::Collision *)> callback)
glm::vec3 localOffset_
Local position offset relative to the owning body.
void setLocalOffset(const glm::vec3 &offset)
Sets the local position offset relative to the body.
const std::string & getDebugName() const
Gets the debug display name for this collision component.
std::uint64_t debugColorSeed_
Stable seed for random debug color selection.
virtual void destroyShape()
Destroys the current shape.
void setCollisionProfile(Physics::CollisionProfileHandle profile)
Sets the collision profile handle used for filtering and response lookup.
void setDebugColorSeed(std::uint64_t seed)
Sets a stable seed used for random debug color selection.
bool hasDebugColorSeed_
True when debugColorSeed_ was explicitly set.
void dispatchOverlapStay(Components::Collision *other)
Dispatches overlap stay hooks.
void beginPlay() override
Creates the Bullet shape and registers this component with a same-entity physics body.
Physics::CollisionProfileHandle collisionProfile_
Explicit collision profile override.
void dispatchOverlapBegin(Components::Collision *other)
Dispatches overlap begin hooks and callbacks.
glm::mat4 getLocalTransform() const
Gets the local transform matrix.
Components::PhysicsBody * getBodyComponent() const
Gets the physics body component this collision is registered with.
void setDebugName(std::string name)
Sets the debug display name for this collision component.
Physics::CollisionProfileHandle getCollisionProfile() const
Gets the effective collision profile handle.
void dispatchCollisionBegin(Components::Collision *other)
Dispatches collision begin hooks.
virtual void onOverlapBegin(Components::Collision *other)
Called when an overlap with another collision component begins.
virtual void onCollisionBegin(Components::Collision *other)
Called when a collision with another object begins.
bool isTrigger() const
Checks if this collision is a trigger.
static bool isDebugDrawEnabled()
Check if debug drawing is enabled globally.
entt::entity entity_
ECS entity associated with this component.
void rebuild()
Rebuilds the shape and notifies PhysicsBodyComponent.
~Collision() override
Clears callback subscriptions and destroys the current Bullet shape.
CollisionCallbackHandle onOverlapEnd(Callback &&callback)
Registers a typed overlap-end callback.
CollisionCallbackHandle nextCallbackHandle_
bool isDirty_
True when the shape needs rebuild.
virtual void onOverlapEnd(Components::Collision *other)
Called when an overlap with another collision component ends.
Collision(Engine::Entities::Scene *scene, entt::entity entity)
Constructs a CollisionComponent.
glm::quat getLocalRotation() const
Gets the local rotation.
virtual btCollisionShape * createShape()=0
Creates the Bullet collision shape.
CollisionCallbackHandle addOverlapBeginCallback(std::function< void(Components::Collision *)> callback)
Physics::CollisionHandle getCollisionHandle() const
Gets the runtime collision handle assigned by the physics engine.
void unregisterFromBody()
static constexpr bool IsUnique
Multiple collision components can exist on one entity.
virtual void onCollisionEnd(Components::Collision *other)
Called when a collision with another object ends.
glm::vec4 getDebugDrawColor(const glm::vec4 &fallbackColor) const
Gets the color used by debug drawing.
Logic(Entities::Scene *owningScene)
Constructs a logic component owned by a scene.
Component that manages a physics rigid body for an entity.
Entities::Actor * getHitActor() const
Gets the actor owning this physics body when the owning entity is an actor.
Owns scene entities, actor lifetime, and the scene graph root.
Registers collision profile names, enum mappings, and pair responses.
CollisionProfileRegistry * getActiveCollisionProfileRegistry()
Returns the process-wide active collision profile registry.
std::function< void(Components::Collision *)> callback
CollisionCallbackHandle handle
Runtime handle for a registered collision component.
Registry handle for a collision profile name.