Open 3D Engine AzFramework API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AzPhysics::Scene Class Referenceabstract

Interface of a Physics Scene. More...

#include <PhysicsScene.h>

Public Member Functions

 AZ_RTTI (Scene, "{52BD8163-BDC4-4B09-ABB2-11DD1F601FFD}")
 
 Scene (const SceneConfiguration &config)
 
const AZ::Crc32 & GetId () const
 
virtual void StartSimulation (float deltatime)=0
 
virtual void FinishSimulation ()=0
 
virtual void SetEnabled (bool enable)=0
 
virtual bool IsEnabled () const =0
 
virtual const SceneConfigurationGetConfiguration () const =0
 
virtual void UpdateConfiguration (const SceneConfiguration &config)=0
 
virtual SimulatedBodyHandle AddSimulatedBody (const SimulatedBodyConfiguration *simulatedBodyConfig)=0
 
virtual SimulatedBodyHandleList AddSimulatedBodies (const SimulatedBodyConfigurationList &simulatedBodyConfigs)=0
 
virtual SimulatedBodyGetSimulatedBodyFromHandle (SimulatedBodyHandle bodyHandle)=0
 
virtual SimulatedBodyList GetSimulatedBodiesFromHandle (const SimulatedBodyHandleList &bodyHandles)=0
 
virtual void RemoveSimulatedBody (SimulatedBodyHandle &bodyHandle)=0
 
virtual void RemoveSimulatedBodies (SimulatedBodyHandleList &bodyHandles)=0
 
virtual void EnableSimulationOfBody (SimulatedBodyHandle bodyHandle)=0
 
virtual void DisableSimulationOfBody (SimulatedBodyHandle bodyHandle)=0
 
virtual JointHandle AddJoint (const JointConfiguration *jointConfig, SimulatedBodyHandle parentBody, SimulatedBodyHandle childBody)=0
 
virtual JointGetJointFromHandle (JointHandle jointHandle)=0
 
virtual void RemoveJoint (JointHandle jointHandle)=0
 
virtual SceneQueryHits QueryScene (const SceneQueryRequest *request)=0
 
virtual bool QueryScene (const SceneQueryRequest *request, SceneQueryHits &result)=0
 
virtual SceneQueryHitsList QuerySceneBatch (const SceneQueryRequests &requests)=0
 
virtual bool QuerySceneAsync (SceneQuery::AsyncRequestId requestId, const SceneQueryRequest *request, SceneQuery::AsyncCallback callback)=0
 
virtual bool QuerySceneAsyncBatch (SceneQuery::AsyncRequestId requestId, const SceneQueryRequests &requests, SceneQuery::AsyncBatchCallback callback)=0
 
virtual void SuppressCollisionEvents (const SimulatedBodyHandle &bodyHandleA, const SimulatedBodyHandle &bodyHandleB)=0
 
virtual void UnsuppressCollisionEvents (const SimulatedBodyHandle &bodyHandleA, const SimulatedBodyHandle &bodyHandleB)=0
 
virtual void SetGravity (const AZ::Vector3 &gravity)=0
 
virtual AZ::Vector3 GetGravity () const =0
 
virtual void * GetNativePointer () const =0
 
void RegisterSceneConfigurationChangedEventHandler (SceneEvents::OnSceneConfigurationChanged::Handler &handler)
 
void RegisterSimulationBodyAddedHandler (SceneEvents::OnSimulationBodyAdded::Handler &handler)
 
void RegisterSimulationBodyRemovedHandler (SceneEvents::OnSimulationBodyRemoved::Handler &handler)
 
void RegisterSimulationBodySimulationEnabledHandler (SceneEvents::OnSimulationBodySimulationEnabled::Handler &handler)
 
void RegisterSimulationBodySimulationDisabledHandler (SceneEvents::OnSimulationBodySimulationDisabled::Handler &handler)
 
void RegisterSceneSimulationStartHandler (SceneEvents::OnSceneSimulationStartHandler &handler)
 
void RegisterSceneSimulationFinishHandler (SceneEvents::OnSceneSimulationFinishHandler &handler)
 
void RegisterSceneActiveSimulatedBodiesHandler (SceneEvents::OnSceneActiveSimulatedBodiesEvent::Handler &handler)
 
void RegisterSceneCollisionEventHandler (SceneEvents::OnSceneCollisionsEvent::Handler &handler)
 
void RegisterSceneTriggersEventHandler (SceneEvents::OnSceneTriggersEvent::Handler &handler)
 
void RegisterSceneGravityChangedEvent (SceneEvents::OnSceneGravityChangedEvent::Handler &handler)
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 

Public Attributes

 AZ_CLASS_ALLOCATOR_DECL
 

Protected Attributes

SceneEvents::OnSceneConfigurationChanged m_configChangeEvent
 
SceneEvents::OnSimulationBodyAdded m_simulatedBodyAddedEvent
 
SceneEvents::OnSimulationBodyRemoved m_simulatedBodyRemovedEvent
 
SceneEvents::OnSimulationBodySimulationEnabled m_simulatedBodySimulationEnabledEvent
 
SceneEvents::OnSimulationBodySimulationDisabled m_simulatedBodySimulationDisabledEvent
 
SceneEvents::OnSceneSimulationStartEvent m_sceneSimulationStartEvent
 
SceneEvents::OnSceneSimulationFinishEvent m_sceneSimulationFinishEvent
 
SceneEvents::OnSceneActiveSimulatedBodiesEvent m_sceneActiveSimulatedBodies
 
SceneEvents::OnSceneCollisionsEvent m_sceneCollisionEvent
 
SceneEvents::OnSceneTriggersEvent m_sceneTriggerEvent
 
SceneEvents::OnSceneGravityChangedEvent m_sceneGravityChangedEvent
 

Detailed Description

Interface of a Physics Scene.

Member Function Documentation

◆ AddJoint()

virtual JointHandle AzPhysics::Scene::AddJoint ( const JointConfiguration jointConfig,
SimulatedBodyHandle  parentBody,
SimulatedBodyHandle  childBody 
)
pure virtual

Add a joint to the Scene.

Parameters
jointConfigThe config of the joint.
parentBodyThe parent body of the joint.
childBodyThe child body of the joint
Returns
Returns a handle to the created joint. Will return AzPhyiscs::InvalidJointHandle if it fails.

◆ AddSimulatedBodies()

virtual SimulatedBodyHandleList AzPhysics::Scene::AddSimulatedBodies ( const SimulatedBodyConfigurationList &  simulatedBodyConfigs)
pure virtual

Add a set of simulated bodied to the Scene.

Parameters
simulatedBodyConfigsThe list of simulated body configs.
Returns
Returns a list of handles to the created Simulated bodies. Will be in the same order as supplied in simulatedBodyConfigs. If one fails, that index will be set to AzPhyiscs::InvalidSimulatedBodyHandle.

◆ AddSimulatedBody()

virtual SimulatedBodyHandle AzPhysics::Scene::AddSimulatedBody ( const SimulatedBodyConfiguration simulatedBodyConfig)
pure virtual

Add a simulated body to the Scene.

Parameters
simulatedBodyConfigThe config of the simulated body.
Returns
Returns a handle to the created Simulated body. Will return AzPhyiscs::InvalidSimulatedBodyHandle if it fails.

◆ EnableSimulationOfBody()

virtual void AzPhysics::Scene::EnableSimulationOfBody ( SimulatedBodyHandle  bodyHandle)
pure virtual

Enable / Disable simulation of the requested body. By default all bodies added are enabled. Disabling simulation the body will no longer be affected by any forces, collisions, or found with scene queries.

Parameters
bodyHandleThe handle of the simulated body to enable / disable.

◆ FinishSimulation()

virtual void AzPhysics::Scene::FinishSimulation ( )
pure virtual

Complete the simulation process. As an example, this is a good place to wait for any work to complete that was triggered in StartSimulation, or swap buffers if double buffering.

◆ GetConfiguration()

virtual const SceneConfiguration & AzPhysics::Scene::GetConfiguration ( ) const
pure virtual

Accessor to the Scenes Configuration.

Returns
Return the currently used SceneConfiguration.

◆ GetGravity()

virtual AZ::Vector3 AzPhysics::Scene::GetGravity ( ) const
pure virtual

Get the Gravity of the Scene.

Returns
A Vector3 of the gravity used in the Scene.

◆ GetId()

const AZ::Crc32 & AzPhysics::Scene::GetId ( ) const

Get the Id of the Scene.

Returns
The Crc32 of the scene.

◆ GetJointFromHandle()

virtual Joint * AzPhysics::Scene::GetJointFromHandle ( JointHandle  jointHandle)
pure virtual

Get the Raw pointer to the requested joint.

Parameters
jointHandleA handle to the joint to retrieve the raw pointer.
Returns
A raw pointer to the Joint body. If the either handle is invalid this will return null.

◆ GetNativePointer()

virtual void * AzPhysics::Scene::GetNativePointer ( ) const
pure virtual

Get the native pointer for a scene. Should be used with caution as it allows direct access to the lower level physics simulation.

Returns
A pointer to the underlying implementation of a scene if there is one.

◆ GetSimulatedBodiesFromHandle()

virtual SimulatedBodyList AzPhysics::Scene::GetSimulatedBodiesFromHandle ( const SimulatedBodyHandleList &  bodyHandles)
pure virtual

Get the Raw pointer to the set of requested simulated bodies.

Parameters
bodyHandlesA list of simulated body handles to retrieve the raw pointers for.
Returns
A list of raw pointers to the Simulated bodies requested. If a simulated body handle is invalid, that index in the list will be null.

◆ GetSimulatedBodyFromHandle()

virtual SimulatedBody * AzPhysics::Scene::GetSimulatedBodyFromHandle ( SimulatedBodyHandle  bodyHandle)
pure virtual

Get the Raw pointer to the requested simulated body.

Parameters
bodyHandleA handle to the simulated body to retrieve the raw pointer for.
Returns
A raw pointer to the Simulated body. If the handle is invalid this will return null.

◆ IsEnabled()

virtual bool AzPhysics::Scene::IsEnabled ( ) const
pure virtual

Check if this Scene is currently Enabled.

Returns
When true the Scene is enabled and will execute its simulation tick when StartSimulation is called. When false, StartSimulation will not execute.

◆ QueryScene() [1/2]

virtual SceneQueryHits AzPhysics::Scene::QueryScene ( const SceneQueryRequest request)
pure virtual

Make a blocking query into the scene.

Parameters
requestThe request to make. Should be one of RayCastRequest || ShapeCastRequest || OverlapRequest
Returns
Returns a structure that contains a list of Hits. Depending on flags set in the request, this may only contain 1 result.

◆ QueryScene() [2/2]

virtual bool AzPhysics::Scene::QueryScene ( const SceneQueryRequest request,
SceneQueryHits result 
)
pure virtual

Make a blocking query into the scene.

Parameters
requestThe request to make. Should be one of RayCastRequest || ShapeCastRequest || OverlapRequest
resultA structure that contains a list of Hits. Depending on flags set in the request, this may only contain 1 result.
Returns
Returns true if there is at least one hit.

◆ QuerySceneAsync()

virtual bool AzPhysics::Scene::QuerySceneAsync ( SceneQuery::AsyncRequestId  requestId,
const SceneQueryRequest request,
SceneQuery::AsyncCallback  callback 
)
pure virtual

Make a non-blocking query into the scene.

Parameters
requestIdA user defined valid to identify the request when the callback is called.
requestThe request to make. Should be one of RayCastRequest || ShapeCastRequest || OverlapRequest
callbackThe callback to trigger when the request is complete.
Returns
Returns if the request was queued successfully. If returns false, the callback will never be called.

◆ QuerySceneAsyncBatch()

virtual bool AzPhysics::Scene::QuerySceneAsyncBatch ( SceneQuery::AsyncRequestId  requestId,
const SceneQueryRequests &  requests,
SceneQuery::AsyncBatchCallback  callback 
)
pure virtual

Make a non-blocking query into the scene.

Parameters
requestIdA user defined valid to identify the request when the callback is called.
requestsA list of requests to make. Each entry should be one of RayCastRequest || ShapeCastRequest || OverlapRequest
callbackThe callback to trigger when all the request are complete.
Returns
Returns If the request was queued successfully. If returns false, the callback will never be called.

◆ QuerySceneBatch()

virtual SceneQueryHitsList AzPhysics::Scene::QuerySceneBatch ( const SceneQueryRequests &  requests)
pure virtual

Make many blocking queries into the scene.

Parameters
requestsA list of requests to make. Each entry should be one of RayCastRequest || ShapeCastRequest || OverlapRequest
Returns
Returns a list of SceneQueryHits. Will be in the same order as supplied in SceneQueryRequests.

◆ RegisterSceneActiveSimulatedBodiesHandler()

void AzPhysics::Scene::RegisterSceneActiveSimulatedBodiesHandler ( SceneEvents::OnSceneActiveSimulatedBodiesEvent::Handler &  handler)
inline

Register a handler to receive an event with a list of SimulatedBodyHandles that updated this scene tick.

Note
This will fire after the OnSceneSimulationStartEvent and before the OnSceneSimulationFinishEvent when SceneConfiguration::m_enableActiveActors is true.
Parameters
handlerThe handler to receive the event.

◆ RegisterSceneCollisionEventHandler()

void AzPhysics::Scene::RegisterSceneCollisionEventHandler ( SceneEvents::OnSceneCollisionsEvent::Handler &  handler)
inline

Register a handler to receive all collision events in the scene.

Parameters
handlerThe handler to receive the event.

◆ RegisterSceneConfigurationChangedEventHandler()

void AzPhysics::Scene::RegisterSceneConfigurationChangedEventHandler ( SceneEvents::OnSceneConfigurationChanged::Handler &  handler)
inline

Register a handler to receive an event when the SceneConfiguration changes.

Parameters
handlerThe handler to receive the event.

◆ RegisterSceneGravityChangedEvent()

void AzPhysics::Scene::RegisterSceneGravityChangedEvent ( SceneEvents::OnSceneGravityChangedEvent::Handler &  handler)
inline

Register a handler to receive a notification when the Scene's gravity has changed.

Parameters
handlerThe handler to receive the event.

◆ RegisterSceneSimulationFinishHandler()

void AzPhysics::Scene::RegisterSceneSimulationFinishHandler ( SceneEvents::OnSceneSimulationFinishHandler &  handler)
inline

Register a handler to receive an event when Scene::FinishSimulation is called.

Note
This may fire multiple times per frame.
Parameters
handlerThe handler to receive the event.

◆ RegisterSceneSimulationStartHandler()

void AzPhysics::Scene::RegisterSceneSimulationStartHandler ( SceneEvents::OnSceneSimulationStartHandler &  handler)
inline

Register a handler to receive an event when Scene::StartSimulation is called.

Note
This may fire multiple times per frame.
Parameters
handlerThe handler to receive the event.

◆ RegisterSceneTriggersEventHandler()

void AzPhysics::Scene::RegisterSceneTriggersEventHandler ( SceneEvents::OnSceneTriggersEvent::Handler &  handler)
inline

Register a handler to receive all trigger events in the scene.

Parameters
handlerThe handler to receive the event.

◆ RegisterSimulationBodyAddedHandler()

void AzPhysics::Scene::RegisterSimulationBodyAddedHandler ( SceneEvents::OnSimulationBodyAdded::Handler &  handler)
inline

Register a handler to receive an event when a Simulated body is added to the Scene.

Parameters
handlerThe handler to receive the event.

◆ RegisterSimulationBodyRemovedHandler()

void AzPhysics::Scene::RegisterSimulationBodyRemovedHandler ( SceneEvents::OnSimulationBodyRemoved::Handler &  handler)
inline

Register a handler to receive an event when a Simulated body is removed from the Scene.

Parameters
handlerThe handler to receive the event.

◆ RegisterSimulationBodySimulationDisabledHandler()

void AzPhysics::Scene::RegisterSimulationBodySimulationDisabledHandler ( SceneEvents::OnSimulationBodySimulationDisabled::Handler &  handler)
inline

Register a handler to receive an event when a Simulated body has its simulation disabled in the Scene.

Parameters
handlerThe handler to receive the event.

◆ RegisterSimulationBodySimulationEnabledHandler()

void AzPhysics::Scene::RegisterSimulationBodySimulationEnabledHandler ( SceneEvents::OnSimulationBodySimulationEnabled::Handler &  handler)
inline

Register a handler to receive an event when a Simulated body has its simulation enabled in the Scene. This will only trigger if the simulated body was disabled, when first added to a scene SceneEvents::OnAnySimulationBodyCreated will trigger instead.

Parameters
handlerThe handler to receive the event.

◆ RemoveJoint()

virtual void AzPhysics::Scene::RemoveJoint ( JointHandle  jointHandle)
pure virtual

Remove a joint from the Scene.

Parameters
jointHandleA handle to the joint being removed.

◆ RemoveSimulatedBodies()

virtual void AzPhysics::Scene::RemoveSimulatedBodies ( SimulatedBodyHandleList &  bodyHandles)
pure virtual

Remove a list of simulated bodies from the Scene.

Parameters
bodyHandlesA list of simulated body handles to be removed. All handles will be set to AzPhysics::InvalidSimulatedBodyHandle as they're no longer valid.

◆ RemoveSimulatedBody()

virtual void AzPhysics::Scene::RemoveSimulatedBody ( SimulatedBodyHandle &  bodyHandle)
pure virtual

Remove a simulated body from the Scene.

Parameters
bodyHandleA handle to the simulated body being removed. This will be set to AzPhysics::InvalidSimulatedBodyHandle as they're no longer valid.

◆ SetEnabled()

virtual void AzPhysics::Scene::SetEnabled ( bool  enable)
pure virtual

Enable or Disable this Scene's Simulation tick. Default is Enabled.

Parameters
enableWhen true the Scene will execute its simulation tick when StartSimulation is called. When false, StartSimulation will not execute.

◆ SetGravity()

virtual void AzPhysics::Scene::SetGravity ( const AZ::Vector3 &  gravity)
pure virtual

Set the Gravity of the Scene. @Param The new gravity vector to be used in the Scene

◆ StartSimulation()

virtual void AzPhysics::Scene::StartSimulation ( float  deltatime)
pure virtual

Start the simulation process. As an example, this is a good place to trigger and queue any long running work in separate threads.

Parameters
deltatimeThe time in seconds to run the simulation for.

◆ SuppressCollisionEvents()

virtual void AzPhysics::Scene::SuppressCollisionEvents ( const SimulatedBodyHandle &  bodyHandleA,
const SimulatedBodyHandle &  bodyHandleB 
)
pure virtual

Registers a pair of simulated bodies for which collisions should be suppressed. Making multiple requests with the same pair result are dropped. To remove the suppression call UnsuppressCollisionEvents with the pair. The order of the bodies do not matter, {body0, body1} collision pair is equal to {body1, body0}.

Parameters
bodyHandleAA handle to a simulated body.
bodyHandleBA handle to a simulated body.

◆ UnsuppressCollisionEvents()

virtual void AzPhysics::Scene::UnsuppressCollisionEvents ( const SimulatedBodyHandle &  bodyHandleA,
const SimulatedBodyHandle &  bodyHandleB 
)
pure virtual

Unregisters a pair of simulated bodies for which collisions should be suppressed. Making multiple requests with the same pair result are dropped. To add a suppression call SuppressCollisionEvents with the pair. The order of the bodies do not matter, {body0, body1} collision pair is equal to {body1, body0}.

Parameters
bodyHandleAA handle to a simulated body.
bodyHandleBA handle to a simulated body.

◆ UpdateConfiguration()

virtual void AzPhysics::Scene::UpdateConfiguration ( const SceneConfiguration config)
pure virtual

Update the SceneConfiguration.

Parameters
configThe new configuration to apply.

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