Classes¶
PhysicsJolt
Brief descriptions¶
Detailed information¶
physics::jolt::JoltPhysicsWorld¶
engine/core/modules/physicsJolt/include/nau/physics/jolt/jolt_physics_world.h
-
class JoltPhysicsWorld : public nau::physics::IPhysicsWorld, public JPH::ContactListener¶
Implements nau::physics::IPhysicsWorld interface utilizing Jolt physics engine.
Public Functions
-
JoltPhysicsWorld()¶
Default constructor.
Initializes all associated Jolt objects.
-
~JoltPhysicsWorld()¶
Destructor.
Deallocates all memory.
-
virtual void tick(float dt) override¶
Advances physics simulation for a single frame.
- Parameters:
dt – [in] Delta time.
-
virtual nau::Ptr<IPhysicsBody> createBody(Uid originSceneObjectUid, const PhysicsBodyCreationData &creationData) override¶
Creates a physical body and places it in the physical world.
- Parameters:
originObject – [in] Scene object to attach the body to.
creationData – [in] Keeps physical properties of the body assigned on its creation
- Returns:
A pointer to the created physical body.
-
virtual void setChannelsCollidable(CollisionChannel channelA, CollisionChannel channelB, bool collidable = true) override¶
Allows or forbids contacts between to collision channels.
See CollisionChannel for more information
Note
Implementations should support commutativity, i.e. calling
setChannelsCollidable(a, b, true)
has to have similar effects to callingsetChannelsCollidable(b, a, true)
.- Parameters:
channelA, channelB – [in] Channels to modify.
collidable – [in] Indicates whether the contact benween channelA and channelB should be allowed.
-
virtual void resetChannelsCollisionSettings() override¶
Clears all channels collision settings made by setChannelsCollidable(). Inter-channel collision settings of underlying physics system msut be reverted to the default state.
-
virtual void setContactListener(nau::Ptr<IPhysicsContactListener> listener) override¶
Assign a contact listener that is to receive messages about contacts between bodies in the physical world.
- Parameters:
listener – [in] A pointer to the object to use as a listener.
-
virtual void OnContactAdded(const JPH::Body &body1, const JPH::Body &body2, const JPH::ContactManifold &manifold, JPH::ContactSettings &settings) override¶
Called when a contact between two bodies begins.
- Parameters:
body1, body2 – [in] Keep information about the contacting bodies.
manifold – [in] Describes contact surface.
settings – [inout] May be used to modify contact constraints.
-
virtual void OnContactPersisted(const JPH::Body &body1, const JPH::Body &body2, const JPH::ContactManifold &manifold, JPH::ContactSettings &settings) override¶
Called each frame while two bodies continue contacting.
- Parameters:
body1, body2 – [in] Keep information about the contacting bodies.
manifold – [in] Describes contact surface.
settings – [inout] May be used to modify contact constraints.
-
virtual void OnContactRemoved(const JPH::SubShapeIDPair &subShapePair) override¶
Called when a contact between two bodies ceases.
- Parameters:
subShapePair – [in] Keeps information about the bodies that stopped contacting.
-
JPH::BodyInterface &getBodyInterface() const¶
Provides access to the body interface.
This interface allows to to create / remove bodies and to change their properties.
- Returns:
A refernce to the body interface.
-
virtual IPhysicsMaterial::Ptr createMaterial(eastl::string_view name, eastl::optional<TFloat> friction = eastl::nullopt, eastl::optional<TFloat> restitution = eastl::nullopt) override¶
Creates and registers a physical material.
- Parameters:
name – [in] Name to register the material under.
friction – [in] Degree of how the body resists being dragged. It has to be between 0.0 (no friction) and 1.0 (the body will stick to the surface and stay immobile). You can pass
eastl::nullopt
if you don’t want the material to override body default friction.restitution – [in] Degree of body tougheness on collision. It has to be between 0.0 (completely inelastic collision response) and 1.0 (completely elastic collision response). You can pass
eastl::nullopt
if you don’t want the material to override body default restitution.
- Returns:
A pointer to the created material.
-
virtual eastl::optional<RayCastResult> castRay(const nau::physics::RayCastQuery &query) const override¶
Allows to cast a ray between to points and check if it hits any physical bodies.
- Parameters:
query – [in] Raycasting properties.
- Returns:
Hit data or
eastl::nullopt
is no hit has occurred.
-
virtual async::Task<eastl::vector<RayCastResult>> castRaysAsync(eastl::vector<physics::RayCastQuery> queries) const override¶
-
virtual void drawDebug(nau::DebugRenderSystem &dr) override¶
Performs physics debug drawing.
Note
Calling this effectively renders each physics body center of mass and collider outline given that their debug rendering is enabled (see nau::physics::jolt::JoltPhysicsBody::setDebugDrawEnabled).
- Parameters:
dr – [in] Debug renderer that is responsible for physics debug drawing.
-
virtual void setGravity(const nau::math::vec3 &gravity) override¶
-
virtual void syncSceneState() override¶
Private Types
Private Members
-
eastl::unique_ptr<JPH::ObjectLayerPairFilterTable> m_layerPairFilter¶
-
eastl::unique_ptr<JPH::BroadPhaseLayerInterfaceTable> m_broadPhaseLayerInterface¶
< Responsible for turning on or off collision between channels (layers).
-
eastl::unique_ptr<JPH::ObjectVsBroadPhaseLayerFilter> m_objectOverBroadPhaseFilter¶
-
eastl::unique_ptr<JoltBodyDrawFilterImpl> m_bodyDrawFilter¶
-
eastl::unique_ptr<DebugRendererImp> m_joltDebugRender¶
< Responsible for deciding whether to draw a body or not within a debug draw call.
-
eastl::unique_ptr<JPH::PhysicsSystem> m_joltPhysicsSystem¶
< Performs physics debug drawing.
-
eastl::unique_ptr<JPH::TempAllocatorImpl> m_joltTempAllocator¶
-
eastl::unique_ptr<JPH::JobSystem> m_joltJobSystem¶
-
IPhysicsContactListener::Ptr m_engineContactListener¶
-
IPhysicsMaterial::Ptr m_engineDefaultMaterial¶
-
int m_collisionStepsCount = 1¶
-
JPH::Mutex m_bodiesInContactGuard¶
< Indicates granularity of collision detection stage within a physical world tick.
-
eastl::map<eastl::pair<JPH::BodyID, JPH::BodyID>, ContactData> m_bodiesInContact¶
Maps a pairs of Jolt ids of contacting bodies to the corresponding ContactData object.
We keep track bodies that are currently in contact by ourselves, for Jolt system contact listener provide only bodyIDs of removed contacts. See JPH::ContactListener::OnContactRemoved for details.
-
eastl::vector<InternalContactManifoldEntry> m_contactsData¶
Private Static Functions
-
static eastl::tuple<float, float, const JoltPhysicsMaterial*> getFrictionAndRestitution(const JPH::Body &body, const JPH::SubShapeID &subShapeID)¶
Retrieves friction, restitution and physical material of the body.
- Parameters:
body – [in] Physical body to which the collision shape is attached.
subShapeID – [in] Index of the collision shape.
- Returns:
A tuple, containing friction, restitution and physical material of the collison shape.
-
static void handleBodiesContact(const JPH::Body &body1, const JPH::Body &body2, const JPH::ContactManifold &manifold, JPH::ContactSettings &settings)¶
When called on contact, fills JPH::ContactSettings object with proper values.
- Parameters:
body1, body2 – [in] Contacting bodies
manifold – [in] Describes contact surface.
settings – [out] Output contact settings.
-
static eastl::vector<nau::math::vec3> calculateContactPoints(const JPH::ContactManifold &manifold)¶
Extracts contact points from the JPH::ContactManifold object.
- Parameters:
manifold – [in] Object to extract the points from.
- Returns:
A vector of contact points.
-
static void debugDrawLine(const nau::math::Point3 &pos0, const nau::math::Point3 &pos1, const nau::math::Color4 &color, float time)¶
Sends a line segment to rendering.
- Parameters:
pos0, pos1 – [in] Segment tips.
color – [in] Color to apply to the line.
time – [in] Duration for which the line should remain on screen.
-
struct ContactData¶
Public Members
-
const JoltPhysicsBody *body1 = nullptr¶
-
const JoltPhysicsBody *body2 = nullptr¶
-
eastl::set<JPH::SubShapeIDPair> contacts¶
-
const JoltPhysicsBody *body1 = nullptr¶
-
struct InternalContactManifold¶
-
struct InternalContactManifoldEntry¶
Public Members
-
InternalContactManifold object1¶
-
InternalContactManifold object2¶
-
eastl::vector<math::vec3> collisionWorldPoints¶
-
InternalContactManifold object1¶
-
JoltPhysicsWorld()¶