Class representing a physics system. More...
#include <PhysicsSystem.hpp>
Classes | |
| struct | InterpCache |
Public Member Functions | |
| PhysicsSystem (vex::Registry ®istry) | |
| Constructor, initializes physics system. | |
| ~PhysicsSystem () | |
| Destructor, simply calls shutdown(). | |
| void | setDebugRenderer (JPH::DebugRenderer *renderer) |
| Sets the debug renderer for the physics system. | |
| void | drawDebug (bool drawConstraints=true, bool drawWireframe=true) |
| Draws debug information for the physics system. | |
| bool | init (size_t maxBodies=1024) |
| Initializes jolts physics system. | |
| void | shutdown () |
| clears all physics objects | |
| void | update (float deltaTime) |
| Updates physics, it is technically fixed time but needs delta to track if required time already passed. | |
| void | SyncBodies () |
| Scans registry for PhysicsComponents without bodies and creates them. | |
| void | SetGravityVector (const glm::vec3 &gravity) |
| Allows for updating gravity. | |
| void | SetGravityFactor (JPH::BodyID bodyId, float gravityFactor) |
| Allows for updating gravity factor per object. | |
| void | SetFriction (JPH::BodyID bodyId, float friction) |
| Allows for updating friction. | |
| float | GetFriction (JPH::BodyID bodyId) |
| Allows for getting friction. | |
| void | SetBounciness (JPH::BodyID bodyId, float bounciness) |
| Allows for updating bounciness. | |
| float | GetBounciness (JPH::BodyID bodyId) |
| Allows for getting bounciness. | |
| void | SetLinearVelocity (JPH::BodyID bodyId, const glm::vec3 &velocity) |
| Allows for updating linear velocity. | |
| glm::vec3 | GetLinearVelocity (JPH::BodyID bodyId) |
| Allows for getting linear velocity. | |
| glm::vec3 | GetVelocityAtPosition (JPH::BodyID bodyId, const glm::vec3 &point) |
| Gets the velocity of a specific point on the body (in World Space). | |
| void | AddLinearVelocity (JPH::BodyID bodyId, const glm::vec3 &velocity) |
| Allows for adding to linear velocity. | |
| void | SetAngularVelocity (JPH::BodyID bodyId, const glm::vec3 &velocity) |
| Allows for setting angular velocity. | |
| glm::vec3 | GetAngularVelocity (JPH::BodyID bodyId) |
| Allows for getting angular velocity. | |
| void | AddAngularVelocity (JPH::BodyID bodyId, const glm::vec3 &velocity) |
| Allows for adding to angular velocity. | |
| void | AddTorque (JPH::BodyID bodyId, const glm::vec3 &torque) |
| Applies torque to the body, it is reset next physics tick. | |
| void | AddForce (JPH::BodyID bodyId, const glm::vec3 &force) |
| Applies force at the mass center of the body, it is reset next physics tick. | |
| void | AddForceAtPosition (JPH::BodyID bodyId, const glm::vec3 &force, const glm::vec3 &position) |
| Applies force at the given position of the body, it is reset next physics tick. | |
| void | AddImpulse (JPH::BodyID bodyId, const glm::vec3 &impulse) |
| Applies impulse at the mass center of the body, it is reset next physics tick. | |
| void | AddImpulseAtPosition (JPH::BodyID bodyId, const glm::vec3 &impulse, const glm::vec3 &position) |
| Applies impulse at the given position of the body, it is reset next physics tick. | |
| void | AddAngularImpulse (JPH::BodyID bodyId, const glm::vec3 &impulse) |
| Applies angular impulse at the mass center of the body, it is reset next physics tick. | |
| void | SetBodyActive (JPH::BodyID bodyId, bool active) |
| Allows for setting body active state. | |
| bool | GetBodyActive (JPH::BodyID bodyId) |
| Allows for getting body active state. | |
| std::optional< JPH::BodyID > | CreateBodyForEntity (vex::Entity e, vex::Registry &r, PhysicsComponent &pc) |
| Allows to recreate physics body at runtime. | |
| std::optional< JPH::BodyID > | RecreateBodyForEntity (vex::Entity e, PhysicsComponent &pc) |
| Allows to recreate physics body at runtime. | |
| void | DestroyBodyForEntity (PhysicsComponent &pc) |
| Destroys a physics body. | |
| bool | raycast (const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance, RaycastHit &hit) |
| Performs a raycast in the physics world. | |
| int | GetCollisionSteps () |
| Allows for getting collision steps (collision accuracy). | |
| void | setCollisionSteps (int steps) |
| Allows for setting collision steps (collision accuracy). | |
| void | setEnableSmoothing (bool enable) |
| Allows for enabling/disabling smoothing. | |
| glm::vec3 | GetPhysicsPosition (JPH::BodyID bodyId) |
| Retrieves the physics position of a body. | |
| glm::quat | GetPhysicsRotation (JPH::BodyID bodyId) |
| Retrieves the physics rotation of a body. | |
| PhysicsComponent & | getPhysicsComponentByBodyId (JPH::BodyID id) |
| vex::Entity | getEntityByBodyId (JPH::BodyID id) |
Private Member Functions | |
| void | SyncBodyToTransform (vex::Entity e, vex::Registry &r, const JPH::BodyID &id, float alpha=1.0f) |
| void | onPhysicsComponentDestroy (vex::Registry ®, vex::Entity e) |
| void | InitializeCharacter (vex::Entity e, CharacterComponent &cc) |
| void | WeldVertices (const std::vector< glm::vec3 > &inVerts, const std::vector< uint32_t > &inIndices, JPH::VertexList &outVerts, JPH::IndexedTriangleList &outTris) |
| Helper to weld vertices based on position ONLY (ignoring UVs/Normals which split render meshes). | |
Static Private Member Functions | |
| static JPH::Quat | EulerToQuat (const glm::vec3 &eulerDeg) |
| static glm::vec3 | QuatToEuler (const JPH::Quat &q) |
Private Attributes | |
| int | collisionSteps = 3 |
| bool | enableSmoothing = true |
| JPH::TempAllocatorImpl * | m_tempAllocator = nullptr |
| JPH::JobSystem * | m_jobSystem = nullptr |
| JPH::PhysicsSystem * | m_physicsSystem = nullptr |
| JPH::DebugRenderer * | m_debugRenderer = nullptr |
| vex::Registry & | m_registry |
| BPLayerInterfaceImpl | m_bpInterface |
| ObjectVsBroadPhaseLayerFilterImpl | m_objVsBpFilter |
| ObjectLayerPairFilterImpl | m_objLayerPairFilter |
| std::unique_ptr< MyActivationListener > | m_activationListener |
| std::unique_ptr< JPH::ContactListener > | m_contactListener |
| std::unordered_map< JPH::BodyID, vex::Entity, BodyIDHasher > | m_bodyToEntity |
| std::unordered_map< JPH::BodyID, InterpCache, BodyIDHasher > | m_interpCache |
| float | m_fixedDt = 1.0f / 60.0f |
| float | m_accumulator = 0.0f |
Friends | |
| class | MyContactListener |
Class representing a physics system.
Definition at line 299 of file PhysicsSystem.hpp.
|
inline |
Constructor, initializes physics system.
| vex::Registry& | registry The registry to use for entity-component system. |
Definition at line 303 of file PhysicsSystem.hpp.
| vex::PhysicsSystem::~PhysicsSystem | ( | ) |
Destructor, simply calls shutdown().
Definition at line 78 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddAngularImpulse | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | impulse ) |
Applies angular impulse at the mass center of the body, it is reset next physics tick.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& impulse The impulse to apply. |
Definition at line 694 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddAngularVelocity | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | velocity ) |
Allows for adding to angular velocity.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& velocity The velocity to add. |
Definition at line 668 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddForce | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | force ) |
Applies force at the mass center of the body, it is reset next physics tick.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& force The force to apply. |
Definition at line 678 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddForceAtPosition | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | force, | ||
| const glm::vec3 & | position ) |
Applies force at the given position of the body, it is reset next physics tick.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& force The force to apply. |
| const | glm::vec3& position The position to apply the force at. |
Definition at line 682 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddImpulse | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | impulse ) |
Applies impulse at the mass center of the body, it is reset next physics tick.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& impulse The impulse to apply. |
Definition at line 686 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddImpulseAtPosition | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | impulse, | ||
| const glm::vec3 & | position ) |
Applies impulse at the given position of the body, it is reset next physics tick.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& impulse The impulse to apply. |
| const | glm::vec3& position The position to apply the impulse at. |
Definition at line 690 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddLinearVelocity | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | velocity ) |
Allows for adding to linear velocity.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& velocity The velocity to add. |
Definition at line 653 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::AddTorque | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | torque ) |
Applies torque to the body, it is reset next physics tick.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& torque The torque to apply. |
Definition at line 674 of file PhysicsSystem.cpp.
| std::optional< JPH::BodyID > vex::PhysicsSystem::CreateBodyForEntity | ( | vex::Entity | e, |
| vex::Registry & | r, | ||
| PhysicsComponent & | pc ) |
Allows to recreate physics body at runtime.
| vex::Entity | e The entity to create the body for. |
| vex::Registry& | r The registry to get the entity data from. |
| PhysicsComponent& | pc The physics component to update. |
Definition at line 330 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::DestroyBodyForEntity | ( | PhysicsComponent & | pc | ) |
Destroys a physics body.
| PhysicsComponent& | pc The physics component to update. |
Definition at line 495 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::drawDebug | ( | bool | drawConstraints = true, |
| bool | drawWireframe = true ) |
Draws debug information for the physics system.
| bool | drawConstraints Whether to draw constraints. |
| bool | drawWireframe Whether to draw wireframe. |
Definition at line 118 of file PhysicsSystem.cpp.
|
staticprivate |
Definition at line 512 of file PhysicsSystem.cpp.
| glm::vec3 vex::PhysicsSystem::GetAngularVelocity | ( | JPH::BodyID | bodyId | ) |
Allows for getting angular velocity.
| JPH::BodyID | bodyId The ID of the body to get. |
Definition at line 663 of file PhysicsSystem.cpp.
| bool vex::PhysicsSystem::GetBodyActive | ( | JPH::BodyID | bodyId | ) |
Allows for getting body active state.
| JPH::BodyID | bodyId The ID of the body to update. |
Definition at line 703 of file PhysicsSystem.cpp.
| float vex::PhysicsSystem::GetBounciness | ( | JPH::BodyID | bodyId | ) |
Allows for getting bounciness.
| JPH::BodyID | bodyId The ID of the body to get. |
Definition at line 634 of file PhysicsSystem.cpp.
|
inline |
Allows for getting collision steps (collision accuracy).
Definition at line 464 of file PhysicsSystem.hpp.
| vex::Entity vex::PhysicsSystem::getEntityByBodyId | ( | JPH::BodyID | id | ) |
Definition at line 573 of file PhysicsSystem.cpp.
| float vex::PhysicsSystem::GetFriction | ( | JPH::BodyID | bodyId | ) |
Allows for getting friction.
| JPH::BodyID | bodyId The ID of the body to get. |
Definition at line 624 of file PhysicsSystem.cpp.
| glm::vec3 vex::PhysicsSystem::GetLinearVelocity | ( | JPH::BodyID | bodyId | ) |
Allows for getting linear velocity.
| JPH::BodyID | bodyId The ID of the body to get. |
Definition at line 642 of file PhysicsSystem.cpp.
| PhysicsComponent & vex::PhysicsSystem::getPhysicsComponentByBodyId | ( | JPH::BodyID | id | ) |
Definition at line 564 of file PhysicsSystem.cpp.
| glm::vec3 vex::PhysicsSystem::GetPhysicsPosition | ( | JPH::BodyID | bodyId | ) |
Retrieves the physics position of a body.
| JPH::BodyID | bodyId - the body ID to retrieve the position for |
Definition at line 707 of file PhysicsSystem.cpp.
| glm::quat vex::PhysicsSystem::GetPhysicsRotation | ( | JPH::BodyID | bodyId | ) |
Retrieves the physics rotation of a body.
| JPH::BodyID | bodyId - the body ID to retrieve the rotation for |
Definition at line 713 of file PhysicsSystem.cpp.
| glm::vec3 vex::PhysicsSystem::GetVelocityAtPosition | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | point ) |
Gets the velocity of a specific point on the body (in World Space).
| JPH::BodyID | bodyId The ID of the body to get. |
| const | glm::vec3& point The point on the body to get the velocity at. |
Definition at line 647 of file PhysicsSystem.cpp.
| bool vex::PhysicsSystem::init | ( | size_t | maxBodies = 1024 | ) |
Initializes jolts physics system.
| size_t | maxBodies The maximum number of bodies to support. |
Definition at line 34 of file PhysicsSystem.cpp.
|
private |
Definition at line 163 of file PhysicsSystem.cpp.
|
private |
Definition at line 505 of file PhysicsSystem.cpp.
|
staticprivate |
Definition at line 518 of file PhysicsSystem.cpp.
| bool vex::PhysicsSystem::raycast | ( | const glm::vec3 & | origin, |
| const glm::vec3 & | direction, | ||
| float | maxDistance, | ||
| RaycastHit & | hit ) |
Performs a raycast in the physics world.
| const | glm::vec3& origin The origin of the ray. |
| const | glm::vec3& direction The direction of the ray. |
| float | maxDistance The maximum distance to check. |
| RaycastHit& | hit The hit information. |
Definition at line 598 of file PhysicsSystem.cpp.
| std::optional< JPH::BodyID > vex::PhysicsSystem::RecreateBodyForEntity | ( | vex::Entity | e, |
| PhysicsComponent & | pc ) |
Allows to recreate physics body at runtime.
| vex::Entity | e The entity to create the body for. |
| PhysicsComponent& | pc The physics component to update. |
Definition at line 490 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::SetAngularVelocity | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | velocity ) |
Allows for setting angular velocity.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& velocity The velocity to set. |
Definition at line 659 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::SetBodyActive | ( | JPH::BodyID | bodyId, |
| bool | active ) |
Allows for setting body active state.
| JPH::BodyID | bodyId The ID of the body to update. |
| bool | active The active state to set. |
Definition at line 698 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::SetBounciness | ( | JPH::BodyID | bodyId, |
| float | bounciness ) |
Allows for updating bounciness.
| JPH::BodyID | bodyId The ID of the body to update. |
| float | bounciness The new bounciness value. |
Definition at line 628 of file PhysicsSystem.cpp.
|
inline |
Allows for setting collision steps (collision accuracy).
| int | steps - number of collision steps |
Definition at line 468 of file PhysicsSystem.hpp.
| void vex::PhysicsSystem::setDebugRenderer | ( | JPH::DebugRenderer * | renderer | ) |
Sets the debug renderer for the physics system.
| JPH::DebugRenderer* | renderer The debug renderer to use. |
Definition at line 114 of file PhysicsSystem.cpp.
|
inline |
Allows for enabling/disabling smoothing.
| bool | enable - true to enable smoothing, false to disable |
Definition at line 472 of file PhysicsSystem.hpp.
| void vex::PhysicsSystem::SetFriction | ( | JPH::BodyID | bodyId, |
| float | friction ) |
Allows for updating friction.
| JPH::BodyID | bodyId The ID of the body to update. |
| float | friction The new friction value. |
Definition at line 618 of file PhysicsSystem.cpp.
|
inline |
Allows for updating gravity factor per object.
| JPH::BodyID | bodyId The ID of the body to update. |
| float | gravityFactor The new gravity factor. |
Definition at line 340 of file PhysicsSystem.hpp.
|
inline |
Allows for updating gravity.
| const | glm::vec3& gravity The new gravity vector. |
Definition at line 333 of file PhysicsSystem.hpp.
| void vex::PhysicsSystem::SetLinearVelocity | ( | JPH::BodyID | bodyId, |
| const glm::vec3 & | velocity ) |
Allows for updating linear velocity.
| JPH::BodyID | bodyId The ID of the body to update. |
| const | glm::vec3& velocity The new linear velocity. |
Definition at line 638 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::shutdown | ( | ) |
clears all physics objects
Definition at line 82 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::SyncBodies | ( | ) |
Scans registry for PhysicsComponents without bodies and creates them.
Definition at line 140 of file PhysicsSystem.cpp.
|
private |
Definition at line 523 of file PhysicsSystem.cpp.
| void vex::PhysicsSystem::update | ( | float | deltaTime | ) |
Updates physics, it is technically fixed time but needs delta to track if required time already passed.
| float | deltaTime The time elapsed since the last update. |
Definition at line 183 of file PhysicsSystem.cpp.
|
private |
Helper to weld vertices based on position ONLY (ignoring UVs/Normals which split render meshes).
| const | std::vector<glm::vec3>& inVerts - the input vertices |
| const | std::vector<uint32_t>& inIndices - the input indices |
| JPH::VertexList& | outVerts - the output vertices |
| JPH::IndexedTriangleList& | outTris - the output triangles |
Definition at line 287 of file PhysicsSystem.cpp.
|
friend |
Definition at line 495 of file PhysicsSystem.hpp.
|
private |
Definition at line 497 of file PhysicsSystem.hpp.
|
private |
Definition at line 498 of file PhysicsSystem.hpp.
|
private |
Definition at line 527 of file PhysicsSystem.hpp.
|
private |
Definition at line 510 of file PhysicsSystem.hpp.
|
private |
Definition at line 513 of file PhysicsSystem.hpp.
|
private |
Definition at line 507 of file PhysicsSystem.hpp.
|
private |
Definition at line 511 of file PhysicsSystem.hpp.
|
private |
Definition at line 503 of file PhysicsSystem.hpp.
|
private |
Definition at line 526 of file PhysicsSystem.hpp.
|
private |
Definition at line 524 of file PhysicsSystem.hpp.
|
private |
Definition at line 501 of file PhysicsSystem.hpp.
|
private |
Definition at line 509 of file PhysicsSystem.hpp.
|
private |
Definition at line 508 of file PhysicsSystem.hpp.
|
private |
Definition at line 502 of file PhysicsSystem.hpp.
|
private |
Definition at line 505 of file PhysicsSystem.hpp.
|
private |
Definition at line 500 of file PhysicsSystem.hpp.