|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
Component that manages a physics rigid body for an entity. More...
#include <PhysicsBodyComponent.h>
Public Member Functions | |
| PhysicsBody (Entities::Scene *scene, entt::entity entity, std::shared_ptr< Entities::SceneNode > sceneNode) | |
| Constructs a PhysicsBodyComponent. | |
| ~PhysicsBody () 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. | |
| void | setMass (float mass) |
| Sets the mass of the rigid body. | |
| float | getMass () const |
| Gets the mass of the rigid body. | |
| void | setFriction (float friction) |
| Sets the friction coefficient. | |
| float | getFriction () const |
| Gets the friction coefficient. | |
| void | setRestitution (float restitution) |
| Sets the restitution (bounciness). | |
| float | getRestitution () const |
| Gets the restitution. | |
| void | setKinematic (bool kinematic) |
| Sets whether the body is kinematic. Kinematic bodies are moved by code, not physics. | |
| bool | isKinematic () const |
| Checks if the body is kinematic. | |
| void | setStatic (bool isStatic) |
| Sets whether the body is static (immovable). | |
| bool | isStatic () const |
| Checks if the body is static. | |
| void | teleport (const glm::vec3 &position) |
| Teleports the body to a new position. | |
| void | teleport (const glm::vec3 &position, const glm::quat &rotation) |
| Teleports the body to a new position and rotation. | |
| void | setLinearVelocity (const glm::vec3 &velocity) |
| Sets the linear velocity. | |
| glm::vec3 | getLinearVelocity () const |
| Gets the linear velocity. | |
| void | setAngularVelocity (const glm::vec3 &velocity) |
| Sets the angular velocity. | |
| glm::vec3 | getAngularVelocity () const |
| Gets the angular velocity. | |
| void | registerCollision (Components::Collision *collision) |
| Registers a collision component with this body. Called by CollisionComponent::beginPlay(). | |
| void | unregisterCollision (Components::Collision *collision) |
| Unregisters a collision component from this body. Called by CollisionComponent::endPlay(). | |
| void | markShapeDirty () |
| Marks the collision shape as needing rebuild. Called when a collision component's shape changes. | |
| void | rebuildIfDirty () |
| Rebuilds the collision shape if dirty. | |
| btRigidBody * | getRigidBody () const |
| Gets the Bullet rigid body. | |
| btDiscreteDynamicsWorld * | getDynamicsWorld () const |
| Gets the Bullet dynamics world. | |
| void | processCollisions () |
| Processes collision events and dispatches callbacks. Called after physics step. | |
| void | debugDraw () const |
| Draws debug visualization of all collision shapes. | |
| Public Member Functions inherited from Engine::Components::Logic | |
| Logic (Entities::Scene *owningScene) | |
| virtual | ~Logic ()=default |
| virtual std::string | getComponentName () const |
| Gets the component type name for debugging/UI. | |
| virtual void | tick (double deltaTime) |
| Called every frame if ticking is enabled. | |
| bool | hasBegunPlay () const |
| 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 bool | IsUnique = true |
| static constexpr const char * | ComponentName = "PhysicsBody" |
| 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 Member Functions | |
| void | rebuildCollisionShape () |
| void | createRigidBody () |
| void | destroyRigidBody () |
| void | updateEcsComponent () |
| Core::PhysicsEngine * | getPhysicsEngine () const |
Private Attributes | |
| entt::entity | entity_ |
| std::weak_ptr< Entities::SceneNode > | sceneNode_ |
| std::vector< Components::Collision * > | collisions_ |
| btCompoundShape * | compoundShape_ = nullptr |
| btRigidBody * | rigidBody_ = nullptr |
| float | mass_ = 1.0f |
| float | friction_ = 0.5f |
| float | restitution_ = 0.0f |
| bool | isKinematic_ = false |
| bool | isStatic_ = false |
| bool | shapeDirty_ = true |
| bool | isInitialized_ = false |
| std::set< Components::Collision * > | previousCollisions_ |
Additional Inherited Members | |
| 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. | |
Component that manages a physics rigid body for an entity.
PhysicsBodyComponent is unique per entity and manages the Bullet rigid body. CollisionComponents register with this component to define collision shapes. When multiple collision shapes exist, they are combined into a compound shape.
Definition at line 36 of file PhysicsBodyComponent.h.
| Engine::Components::PhysicsBody::PhysicsBody | ( | Entities::Scene * | scene, |
| entt::entity | entity, | ||
| std::shared_ptr< Entities::SceneNode > | sceneNode ) |
Constructs a PhysicsBodyComponent.
| scene | The owning scene. |
| entity | The ECS entity associated with this component. |
| sceneNode | The scene node for transform access. |
|
override |
|
overridevirtual |
Called when the component is added to the scene or the game starts.
Reimplemented from Engine::Components::Logic.
|
private |
| void Engine::Components::PhysicsBody::debugDraw | ( | ) | const |
Draws debug visualization of all collision shapes.
Iterates through registered CollisionComponents and calls their debugDraw(). Uses the current world transform from the SceneNode.
|
private |
|
overridevirtual |
Called when the component is removed or the game ends.
Reimplemented from Engine::Components::Logic.
|
nodiscard |
Gets the angular velocity.
|
nodiscard |
Gets the Bullet dynamics world.
|
inlinenodiscard |
Gets the friction coefficient.
Definition at line 81 of file PhysicsBodyComponent.h.
References friction_.
|
nodiscard |
Gets the linear velocity.
|
inlinenodiscard |
Gets the mass of the rigid body.
Definition at line 69 of file PhysicsBodyComponent.h.
References mass_.
|
nodiscardprivate |
|
inlinenodiscard |
Gets the restitution.
Definition at line 93 of file PhysicsBodyComponent.h.
References restitution_.
|
inlinenodiscard |
Gets the Bullet rigid body.
Definition at line 194 of file PhysicsBodyComponent.h.
References rigidBody_.
|
inlinenodiscard |
Checks if the body is kinematic.
Definition at line 106 of file PhysicsBodyComponent.h.
References isKinematic_.
|
inlinenodiscard |
Checks if the body is static.
Definition at line 118 of file PhysicsBodyComponent.h.
References isStatic_.
Referenced by setStatic().
| void Engine::Components::PhysicsBody::markShapeDirty | ( | ) |
Marks the collision shape as needing rebuild. Called when a collision component's shape changes.
| void Engine::Components::PhysicsBody::processCollisions | ( | ) |
Processes collision events and dispatches callbacks. Called after physics step.
|
private |
| void Engine::Components::PhysicsBody::rebuildIfDirty | ( | ) |
Rebuilds the collision shape if dirty.
| void Engine::Components::PhysicsBody::registerCollision | ( | Components::Collision * | collision | ) |
Registers a collision component with this body. Called by CollisionComponent::beginPlay().
| collision | The collision component to register. |
| void Engine::Components::PhysicsBody::setAngularVelocity | ( | const glm::vec3 & | velocity | ) |
Sets the angular velocity.
| velocity | Angular velocity in rad/s. |
| void Engine::Components::PhysicsBody::setFriction | ( | float | friction | ) |
Sets the friction coefficient.
| friction | Friction value (0.0 = ice, 0.5 = wood, 1.0 = high friction). |
| void Engine::Components::PhysicsBody::setKinematic | ( | bool | kinematic | ) |
Sets whether the body is kinematic. Kinematic bodies are moved by code, not physics.
| kinematic | True for kinematic, false for dynamic. |
| void Engine::Components::PhysicsBody::setLinearVelocity | ( | const glm::vec3 & | velocity | ) |
Sets the linear velocity.
| velocity | Velocity in m/s. |
| void Engine::Components::PhysicsBody::setMass | ( | float | mass | ) |
Sets the mass of the rigid body.
| mass | Mass in kilograms. 0 = static object. |
| void Engine::Components::PhysicsBody::setRestitution | ( | float | restitution | ) |
Sets the restitution (bounciness).
| restitution | 0.0 = no bounce, 1.0 = full energy preserved. |
| void Engine::Components::PhysicsBody::setStatic | ( | bool | isStatic | ) |
Sets whether the body is static (immovable).
| isStatic | True for static, false for dynamic. |
References isStatic().
| void Engine::Components::PhysicsBody::teleport | ( | const glm::vec3 & | position | ) |
Teleports the body to a new position.
| position | New world position. |
| void Engine::Components::PhysicsBody::teleport | ( | const glm::vec3 & | position, |
| const glm::quat & | rotation ) |
Teleports the body to a new position and rotation.
| position | New world position. |
| rotation | New world rotation. |
| void Engine::Components::PhysicsBody::unregisterCollision | ( | Components::Collision * | collision | ) |
Unregisters a collision component from this body. Called by CollisionComponent::endPlay().
| collision | The collision component to unregister. |
|
private |
|
private |
Definition at line 234 of file PhysicsBodyComponent.h.
|
staticconstexpr |
Definition at line 39 of file PhysicsBodyComponent.h.
|
private |
Definition at line 235 of file PhysicsBodyComponent.h.
|
private |
Definition at line 231 of file PhysicsBodyComponent.h.
|
private |
Definition at line 239 of file PhysicsBodyComponent.h.
Referenced by getFriction().
|
private |
Definition at line 244 of file PhysicsBodyComponent.h.
|
private |
Definition at line 241 of file PhysicsBodyComponent.h.
Referenced by isKinematic().
|
private |
Definition at line 242 of file PhysicsBodyComponent.h.
Referenced by isStatic().
|
staticconstexpr |
Definition at line 38 of file PhysicsBodyComponent.h.
|
private |
Definition at line 238 of file PhysicsBodyComponent.h.
Referenced by getMass().
|
private |
Definition at line 247 of file PhysicsBodyComponent.h.
|
private |
Definition at line 240 of file PhysicsBodyComponent.h.
Referenced by getRestitution().
|
private |
Definition at line 236 of file PhysicsBodyComponent.h.
Referenced by getRigidBody().
|
private |
Definition at line 232 of file PhysicsBodyComponent.h.
|
private |
Definition at line 243 of file PhysicsBodyComponent.h.