RavEngine
Loading...
Searching...
No Matches
RavEngine::PhysicsSolver Class Reference
Inheritance diagram for RavEngine::PhysicsSolver:
[legend]
Collaboration diagram for RavEngine::PhysicsSolver:
[legend]

Classes

struct  OverlapHit
 
struct  PhysicsTransform
 
struct  RaycastHit
 

Public Member Functions

void DeallocatePhysx ()
 
 PhysicsSolver (World *world)
 
void Spawn (PhysicsBodyComponent &)
 
void Destroy (PhysicsBodyComponent &)
 
void Tick (float deltaTime)
 
bool Raycast (const vector3 &origin, const vector3 &direction, decimalType maxDistance, RaycastHit &out_hit)
 
bool BoxOverlap (const vector3 &origin, const quaternion &rotation, const vector3 &half_ext, OverlapHit &out_hit)
 
bool SphereOverlap (const vector3 &origin, decimalType radius, OverlapHit &out_hit)
 
bool CapsuleOverlap (const vector3 &origin, const quaternion &rotation, decimalType radius, decimalType halfheight, OverlapHit &out_hit)
 

Static Public Member Functions

static void ReleaseStatics ()
 

Public Attributes

World * owner = nullptr
 
physx::PxScene * scene
 

Static Public Attributes

static physx::PxPhysics * phys
 
static physx::PxPvd * pvd
 
static physx::PxCooking * cooking
 

Protected Member Functions

void setupFiltering (physx::PxRigidActor *actor, physx::PxU32 filterGroup, physx::PxU32 filterMask)
 
virtual void onConstraintBreak (physx::PxConstraintInfo *constraints, physx::PxU32 count) override
 This is called when a breakable constraint breaks.
 
virtual void onWake (physx::PxActor **actors, physx::PxU32 count) override
 This is called with the actors which have just been woken up.
 
virtual void onSleep (physx::PxActor **actors, physx::PxU32 count) override
 This is called with the actors which have just been put to sleep.
 
virtual void onContact (const physx::PxContactPairHeader &pairHeader, const physx::PxContactPair *pairs, physx::PxU32 nbPairs) override
 This is called when certain contact events occur.
 
virtual void onTrigger (physx::PxTriggerPair *pairs, physx::PxU32 count) override
 This is called with the current trigger pair events.
 
virtual void onAdvance (const physx::PxRigidBody *const *bodyBuffer, const physx::PxTransform *poseBuffer, const physx::PxU32 count) override
 Provides early access to the new pose of moving rigid bodies.
 
bool generic_overlap (const PhysicsTransform &transform, const physx::PxGeometry &geo, OverlapHit &out_hit)
 

Static Protected Attributes

static physx::PxDefaultErrorCallback gDefaultErrorCallback
 
static physx::PxDefaultAllocator gDefaultAllocatorCallback
 
static physx::PxFoundation * foundation
 
static constexpr float max_step_time = 1.f/30
 

Friends

class World
 
class PhysicsBodyComponent
 

Member Function Documentation

◆ BoxOverlap()

bool RavEngine::PhysicsSolver::BoxOverlap ( const vector3 &  origin,
const quaternion &  rotation,
const vector3 &  half_ext,
OverlapHit &  out_hit 
)

Perform a box overlap

Parameters
originthe center point of the box overlap
rotationthe rotation of the box
half_extthe distance from the origin to the corner for each axis
out_hitthe cast results to write the data into
Returns
true if the box overlap found data, false otherwise

◆ CapsuleOverlap()

bool RavEngine::PhysicsSolver::CapsuleOverlap ( const vector3 &  origin,
const quaternion &  rotation,
decimalType  radius,
decimalType  halfheight,
OverlapHit &  out_hit 
)

Perform a capsule overlap

Parameters
originthe center of the capsule
rotationthe rotation of the capsule
halfHeightthe distance from the center of the capsule to a pole
out_hitthe destination to write the results into
Returns
true if the capsule overlap found data

◆ Destroy()

void PhysicsSolver::Destroy ( PhysicsBodyComponent &  body)

Remove the entity from the physics system. This does NOT destroy it in the World.

Parameters
ethe entity to remove

◆ generic_overlap()

bool RavEngine::PhysicsSolver::generic_overlap ( const PhysicsTransform &  transform,
const physx::PxGeometry &  geo,
OverlapHit &  out_hit 
)
protected

Generic version of overlap

Parameters
transformthe transform to pass
geothe geometry for the it
out_hitthe destination to write the results

◆ onAdvance()

virtual void RavEngine::PhysicsSolver::onAdvance ( const physx::PxRigidBody *const *  bodyBuffer,
const physx::PxTransform *  poseBuffer,
const physx::PxU32  count 
)
inlineoverrideprotectedvirtual

Provides early access to the new pose of moving rigid bodies.

When this call occurs, rigid bodies having the #PxRigidBodyFlag::eENABLE_POSE_INTEGRATION_PREVIEW flag set, were moved by the simulation and their new poses can be accessed through the provided buffers.

Note
The provided buffers are valid and can be read until the next call to #PxScene::simulate() or #PxScene::collide().
This callback gets triggered while the simulation is running. If the provided rigid body references are used to read properties of the object, then the callback has to guarantee no other thread is writing to the same body at the same time.
The code in this callback should be lightweight as it can block the simulation, that is, the #PxScene::fetchResults() call.
Parameters
[in]bodyBufferThe rigid bodies that moved and requested early pose reporting.
[in]poseBufferThe integrated rigid body poses of the bodies listed in bodyBuffer.
[in]countThe number of entries in the provided buffers.
See also
PxScene.setSimulationEventCallback() PxSceneDesc.simulationEventCallback PxRigidBodyFlag::eENABLE_POSE_INTEGRATION_PREVIEW

Implements physx::PxSimulationEventCallback.

◆ onConstraintBreak()

virtual void RavEngine::PhysicsSolver::onConstraintBreak ( physx::PxConstraintInfo *  constraints,
physx::PxU32  count 
)
inlineoverrideprotectedvirtual

This is called when a breakable constraint breaks.

Note
The user should not release the constraint shader inside this call!
No event will get reported if the constraint breaks but gets deleted while the time step is still being simulated.
Parameters
[in]constraints- The constraints which have been broken.
[in]count- The number of constraints
See also
PxConstraint PxConstraintDesc.linearBreakForce PxConstraintDesc.angularBreakForce

Implements physx::PxSimulationEventCallback.

◆ onContact()

void PhysicsSolver::onContact ( const physx::PxContactPairHeader &  pairHeader,
const physx::PxContactPair *  pairs,
physx::PxU32  nbPairs 
)
overrideprotectedvirtual

This is called when certain contact events occur.

The method will be called for a pair of actors if one of the colliding shape pairs requested contact notification. You request which events are reported using the filter shader/callback mechanism (see #PxSimulationFilterShader, #PxSimulationFilterCallback, #PxPairFlag).

Do not keep references to the passed objects, as they will be invalid after this function returns.

Parameters
[in]pairHeaderInformation on the two actors whose shapes triggered a contact report.
[in]pairsThe contact pairs of two actors for which contact reports have been requested. See #PxContactPair.
[in]nbPairsThe number of provided contact pairs.
See also
PxScene.setSimulationEventCallback() PxSceneDesc.simulationEventCallback PxContactPair PxPairFlag PxSimulationFilterShader PxSimulationFilterCallback

Implements physx::PxSimulationEventCallback.

◆ onSleep()

virtual void RavEngine::PhysicsSolver::onSleep ( physx::PxActor **  actors,
physx::PxU32  count 
)
inlineoverrideprotectedvirtual

This is called with the actors which have just been put to sleep.

Note
Only supported by rigid bodies yet.
Only called on actors for which the PxActorFlag eSEND_SLEEP_NOTIFIES has been set.
Only the latest sleep state transition happening between fetchResults() of the previous frame and fetchResults() of the current frame will get reported. For example, let us assume actor A is asleep, then A->wakeUp() gets called, then later A->putToSleep() gets called. At the next simulate/fetchResults() step only an onSleep() event will get triggered because that was the last transition (assuming the simulation does not wake the actor up).
If an actor gets newly added to a scene with properties such that it is asleep and the sleep state does not get changed by the user or simulation, then an onSleep() event will get sent at the next simulate/fetchResults() step.
Parameters
[in]actors- The actors which have just been put to sleep.
[in]count- The number of actors
See also
PxScene.setSimulationEventCallback() PxSceneDesc.simulationEventCallback PxActorFlag PxActor.setActorFlag()

Implements physx::PxSimulationEventCallback.

◆ onTrigger()

void PhysicsSolver::onTrigger ( physx::PxTriggerPair *  pairs,
physx::PxU32  count 
)
overrideprotectedvirtual

This is called with the current trigger pair events.

Shapes which have been marked as triggers using PxShapeFlag::eTRIGGER_SHAPE will send events according to the pair flag specification in the filter shader (see #PxPairFlag, #PxSimulationFilterShader).

Note
Trigger shapes will no longer send notification events for interactions with other trigger shapes.
Parameters
[in]pairs- The trigger pair events.
[in]count- The number of trigger pair events.
See also
PxScene.setSimulationEventCallback() PxSceneDesc.simulationEventCallback PxPairFlag PxSimulationFilterShader PxShapeFlag PxShape.setFlag()

Implements physx::PxSimulationEventCallback.

◆ onWake()

virtual void RavEngine::PhysicsSolver::onWake ( physx::PxActor **  actors,
physx::PxU32  count 
)
inlineoverrideprotectedvirtual

This is called with the actors which have just been woken up.

Note
Only supported by rigid bodies yet.
Only called on actors for which the PxActorFlag eSEND_SLEEP_NOTIFIES has been set.
Only the latest sleep state transition happening between fetchResults() of the previous frame and fetchResults() of the current frame will get reported. For example, let us assume actor A is awake, then A->putToSleep() gets called, then later A->wakeUp() gets called. At the next simulate/fetchResults() step only an onWake() event will get triggered because that was the last transition.
If an actor gets newly added to a scene with properties such that it is awake and the sleep state does not get changed by the user or simulation, then an onWake() event will get sent at the next simulate/fetchResults() step.
Parameters
[in]actors- The actors which just woke up.
[in]count- The number of actors
See also
PxScene.setSimulationEventCallback() PxSceneDesc.simulationEventCallback PxActorFlag PxActor.setActorFlag()

Implements physx::PxSimulationEventCallback.

◆ Raycast()

bool RavEngine::PhysicsSolver::Raycast ( const vector3 &  origin,
const vector3 &  direction,
decimalType  maxDistance,
RaycastHit &  out_hit 
)

Perform a raycast in the scene.

Parameters
originthe starting point of the vector
directionthe direction to continue the vector
maxDistancethe distance to continue the cast
out_hitthe RaycastHit to write the data into
Returns
true if the Raycast hit, false otherwise

◆ Spawn()

void PhysicsSolver::Spawn ( PhysicsBodyComponent &  actor)

Make the physics system aware of an object

Parameters
ethe entity to add

◆ SphereOverlap()

bool RavEngine::PhysicsSolver::SphereOverlap ( const vector3 &  origin,
decimalType  radius,
OverlapHit &  out_hit 
)

Perform a sphere overlap

Parameters
originthe center point of the sphere overlap
radiusradius of the sphere
out_hitwhere to write the results
Returns
true if the overlap found data

◆ Tick()

void PhysicsSolver::Tick ( float  scaleFactor)

Run the appropriate number of physics time steps given a frame rate scale

Parameters
deltaTimethe scale factor to apply

The documentation for this class was generated from the following files: