CollisionComponent Class
Defines collision layer membership and interaction masks for a GameObject. More...
Declaration
Public Constructors Index
| CollisionComponent (uint32_t layerId, bool isCollisionReporter=true, uint32_t solidCollisionMask=0, uint32_t triggerCollisionMask=0) | |
|
Constructs a CollisionComponent with a layer ID. More... | |
| CollisionComponent (const CollisionComponent &other) | |
|
Copy constructor. More... | |
| CollisionComponent (CollisionComponent &&) noexcept=default | |
Public Operators Index
| CollisionComponent & | operator= (const CollisionComponent &)=default |
| CollisionComponent & | operator= (CollisionComponent &&) noexcept=default |
Public Member Functions Index
| bool | isEnabled () const noexcept |
|
Checks whether this component is enabled. More... | |
| void | enable () noexcept |
|
Enables this component. More... | |
| void | disable () noexcept |
|
Disables this component. More... | |
| void | setIsCollisionReporter (bool isCollisionReporter) |
|
Sets whether this component should report collision events. More... | |
| void | setHitPolicy (const helios::engine::modules::physics::collision::types::HitPolicy hitPolicy) |
|
Sets the hit policy for collision detection. More... | |
| helios::engine::modules::physics::collision::types::HitPolicy | hitPolicy () const noexcept |
|
Returns the current hit policy. More... | |
| bool | isCollisionReporter () const noexcept |
|
Returns whether this component can emit collision events. More... | |
| CollisionComponent & | setSolidCollisionMask (const uint32_t solidCollisionMask) noexcept |
|
Sets the solid collision mask. More... | |
| CollisionComponent & | setTriggerCollisionMask (const uint32_t triggerCollisionMask) noexcept |
|
Sets the trigger collision mask. More... | |
| uint32_t | solidCollisionMask () const noexcept |
|
Returns the solid collision mask. More... | |
| uint32_t | triggerCollisionMask () const noexcept |
|
Returns the trigger collision mask. More... | |
| unsigned int | layerId () const noexcept |
|
Returns the collision layer ID. More... | |
| CollisionComponent & | addSolidCollisionBehavior (const helios::engine::modules::physics::collision::types::CollisionBehavior collisionBehavior, const uint32_t otherLayerId) noexcept |
|
Adds a solid collision behavior for a specific layer. More... | |
| helios::engine::modules::physics::collision::types::CollisionBehavior | solidCollisionBehavior (uint32_t otherLayerId) const noexcept |
|
Returns the solid collision behavior for a specific layer. More... | |
| helios::engine::modules::physics::collision::types::CollisionBehavior | triggerCollisionBehavior (uint32_t otherLayerId) const noexcept |
|
Returns the trigger collision behavior for a specific layer. More... | |
| CollisionComponent & | addTriggerCollisionBehavior (const helios::engine::modules::physics::collision::types::CollisionBehavior collisionBehavior, const uint32_t otherLayerId) noexcept |
|
Adds a trigger collision behavior for a specific layer. More... | |
Private Member Attributes Index
| size_t | CollisionBehaviorSize = helios::engine::modules::physics::collision::types::CollisionBehaviorItemSize |
| uint32_t | layerId_ {} |
|
The collision layer this component belongs to. More... | |
| uint32_t | triggerCollisionMask_ {} |
|
Bitmask specifying layers that generate trigger collisions. More... | |
| uint32_t | solidCollisionMask_ {} |
|
Bitmask specifying layers that generate solid collisions. More... | |
| bool | isCollisionReporter_ = true |
|
Flag indicating whether this component can report collision events. More... | |
| std::array< uint32_t, helios::engine::modules::physics::collision::types::CollisionBehaviorItemSize > | solidCollisionBehavior_ {} |
|
Per-behavior layer masks for solid collisions. More... | |
| std::array< uint32_t, helios::engine::modules::physics::collision::types::CollisionBehaviorItemSize > | triggerCollisionBehavior_ {} |
|
Per-behavior layer masks for trigger collisions. More... | |
| helios::engine::modules::physics::collision::types::HitPolicy | hitPolicy_ = types::HitPolicy::OneHit |
|
Controls how many collisions are reported per frame. More... | |
| bool | isEnabled_ = true |
|
Whether this component is enabled. More... | |
Description
Defines collision layer membership and interaction masks for a GameObject.
CollisionComponent enables layer-based collision filtering by assigning each entity to a specific layer and defining which other layers it can interact with. Two separate bitmasks control trigger (non-physical) or solid (physical) collision generation.
Trigger collisions are asymmetric: entity A can detect entity B without B detecting A. Solid collisions should be treated symmetrically by the collision system.
The collision reporter flag controls whether this entity can emit collision events. Non-reporter entities participate in collision detection but do not generate events.
Example usage: ```cpp constexpr uint32_t LAYER_PLAYER = 1 << 0; constexpr uint32_t LAYER_ENEMY = 1 << 1; constexpr uint32_t LAYER_BULLET = 1 << 2;
auto& collision = gameObject.add<CollisionComponent>(LAYER_PLAYER); collision.setTriggerCollisionMask(LAYER_ENEMY | LAYER_BULLET); collision.setSolidCollisionMask(LAYER_ENEMY); ```
Definition at line 46 of file CollisionComponent.ixx.
Public Constructors
CollisionComponent()
| inline explicit |
Constructs a CollisionComponent with a layer ID.
- Parameters
-
layerId The collision layer this entity belongs to.
isCollisionReporter Whether this entity can emit collision events.
solidCollisionMask Initial bitmask for solid collisions.
triggerCollisionMask Initial bitmask for trigger collisions.
Definition at line 150 of file CollisionComponent.ixx.
References isCollisionReporter, layerId, solidCollisionMask and triggerCollisionMask.
Referenced by addSolidCollisionBehavior, addTriggerCollisionBehavior, CollisionComponent, CollisionComponent, operator=, operator=, setSolidCollisionMask and setTriggerCollisionMask.
CollisionComponent()
| inline |
Copy constructor.
Creates a deep copy of the collision component, preserving layer ID, masks, and all behavior configurations.
- Parameters
-
other The component to copy from.
Definition at line 166 of file CollisionComponent.ixx.
Reference CollisionComponent.
CollisionComponent()
| noexcept default |
Definition at line 177 of file CollisionComponent.ixx.
Reference CollisionComponent.
Public Operators
operator=()
| default |
Definition at line 176 of file CollisionComponent.ixx.
Reference CollisionComponent.
operator=()
| noexcept default |
Definition at line 178 of file CollisionComponent.ixx.
Reference CollisionComponent.
Public Member Functions
addSolidCollisionBehavior()
| inline noexcept |
Adds a solid collision behavior for a specific layer.
Associates a collision behavior with a target layer for solid collisions. If a behavior was previously set for the same layer, it is replaced.
- Parameters
-
collisionBehavior The behavior to apply on collision.
otherLayerId The layer ID to associate the behavior with.
- Returns
Reference to this component for method chaining.
Definition at line 288 of file CollisionComponent.ixx.
Reference CollisionComponent.
addTriggerCollisionBehavior()
| inline noexcept |
Adds a trigger collision behavior for a specific layer.
Associates a collision behavior with a target layer for trigger collisions. If a behavior was previously set for the same layer, it is replaced.
- Parameters
-
collisionBehavior The behavior to apply on collision.
otherLayerId The layer ID to associate the behavior with.
- Returns
Reference to this component for method chaining.
Definition at line 374 of file CollisionComponent.ixx.
Reference CollisionComponent.
disable()
| inline noexcept |
Disables this component.
Definition at line 138 of file CollisionComponent.ixx.
enable()
| inline noexcept |
Enables this component.
Definition at line 131 of file CollisionComponent.ixx.
hitPolicy()
| inline nodiscard noexcept |
Returns the current hit policy.
- Returns
The configured HitPolicy for this component.
- See Also
HitPolicy
Definition at line 213 of file CollisionComponent.ixx.
Referenced by setHitPolicy and helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::solveCell.
isCollisionReporter()
| inline nodiscard noexcept |
Returns whether this component can emit collision events.
- Returns
True if collision events can be generated, false otherwise.
Definition at line 222 of file CollisionComponent.ixx.
Referenced by CollisionComponent and setIsCollisionReporter.
isEnabled()
| inline nodiscard noexcept |
Checks whether this component is enabled.
- Returns
True if enabled, false otherwise.
Definition at line 124 of file CollisionComponent.ixx.
Referenced by helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::update.
layerId()
| inline nodiscard noexcept |
Returns the collision layer ID.
- Returns
The layer this entity belongs to.
Definition at line 273 of file CollisionComponent.ixx.
Referenced by CollisionComponent.
setHitPolicy()
| inline |
Sets the hit policy for collision detection.
Controls how many collision events this entity can receive per frame:
- `OneHit`: Only the first collision is reported (default)
- `All`: All collisions are reported
- Parameters
-
hitPolicy The hit policy to apply.
- See Also
HitPolicy
Definition at line 202 of file CollisionComponent.ixx.
Reference hitPolicy.
setIsCollisionReporter()
| inline |
Sets whether this component should report collision events.
- Parameters
-
isCollisionReporter True to enable event reporting, false to disable.
Definition at line 186 of file CollisionComponent.ixx.
References isCollisionReporter and setIsCollisionReporter.
Referenced by setIsCollisionReporter.
setSolidCollisionMask()
| inline noexcept |
Sets the solid collision mask.
- Parameters
-
solidCollisionMask Bitmask of layers to generate solid collisions with.
- Returns
Reference to this component for method chaining.
Definition at line 233 of file CollisionComponent.ixx.
References CollisionComponent and solidCollisionMask.
setTriggerCollisionMask()
| inline noexcept |
Sets the trigger collision mask.
- Parameters
-
triggerCollisionMask Bitmask of layers to generate trigger collisions with.
- Returns
Reference to this component for method chaining.
Definition at line 245 of file CollisionComponent.ixx.
References CollisionComponent and triggerCollisionMask.
solidCollisionBehavior()
| inline nodiscard noexcept |
Returns the solid collision behavior for a specific layer.
Looks up the configured behavior for collisions with the specified layer. Returns `CollisionBehavior::None` if no solid collision mask is set for the layer.
- Parameters
-
otherLayerId The layer ID to query.
- Returns
The collision behavior for the specified layer.
Definition at line 318 of file CollisionComponent.ixx.
solidCollisionMask()
| inline nodiscard noexcept |
Returns the solid collision mask.
- Returns
Bitmask of layers this entity generates solid collisions with.
Definition at line 255 of file CollisionComponent.ixx.
Referenced by CollisionComponent, setSolidCollisionMask and helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::update.
triggerCollisionBehavior()
| inline nodiscard noexcept |
Returns the trigger collision behavior for a specific layer.
Looks up the configured behavior for trigger collisions with the specified layer. Returns `CollisionBehavior::None` if no trigger collision mask is set for the layer.
- Parameters
-
otherLayerId The layer ID to query.
- Returns
The collision behavior for the specified layer.
Definition at line 346 of file CollisionComponent.ixx.
triggerCollisionMask()
| inline nodiscard noexcept |
Returns the trigger collision mask.
- Returns
Bitmask of layers this entity generates trigger collisions with.
Definition at line 264 of file CollisionComponent.ixx.
Referenced by CollisionComponent, setTriggerCollisionMask and helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::update.
Private Member Attributes
CollisionBehaviorSize
|
Definition at line 48 of file CollisionComponent.ixx.
hitPolicy_
|
Controls how many collisions are reported per frame.
Defaults to `OneHit`, reporting only the first collision. Set to `All` for multi-target collision detection.
- See Also
HitPolicy
Definition at line 110 of file CollisionComponent.ixx.
isCollisionReporter_
|
Flag indicating whether this component can report collision events.
Definition at line 74 of file CollisionComponent.ixx.
isEnabled_
|
Whether this component is enabled.
Definition at line 115 of file CollisionComponent.ixx.
layerId_
|
The collision layer this component belongs to.
Definition at line 53 of file CollisionComponent.ixx.
solidCollisionBehavior_
|
Per-behavior layer masks for solid collisions.
Each array index corresponds to a CollisionBehavior enum value. The bitmask at each index indicates which layers trigger that behavior for solid collisions.
Definition at line 88 of file CollisionComponent.ixx.
solidCollisionMask_
|
Bitmask specifying layers that generate solid collisions.
Solid collision should be symmetric and in the calling API treated as such: `(maskB & thisLayerId) != 0 && (thisMask & layerBId) != 0`
Definition at line 69 of file CollisionComponent.ixx.
triggerCollisionBehavior_
|
Per-behavior layer masks for trigger collisions.
Each array index corresponds to a CollisionBehavior enum value. The bitmask at each index indicates which layers trigger that behavior for trigger collisions.
Definition at line 100 of file CollisionComponent.ixx.
triggerCollisionMask_
|
Bitmask specifying layers that generate trigger collisions.
Trigger collision masks may be asymmetric, i.e. a component B must not know about the existence of another layerId.
Definition at line 61 of file CollisionComponent.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.