Axmol 3.0.0-89d6d9a
Loading...
Searching...
No Matches
PhysicsWorld3D Class Reference

The physics information container for Axmol 3D physics components. More...

#include <PhysicsWorld3D.h>

Inherits Object.

Classes

struct  HitResult
 Result data returned by ray casts and sweep tests. More...

Public Member Functions

JPH::PhysicsSystem & internalHandle ()
 Returns the native Jolt physics system.
const JPH::PhysicsSystem & internalHandle () const
 Returns the native Jolt physics system.
Scene * getScene () const
 Returns the scene that owns this physics world.
void setPreSolveCallback (PreSolveCallback cb)
 Set the PreSolve callback for the 3D physics world.
void setGravity (const Vec3 &gravity)
 Sets gravity for the physics world.
Vec3 getGravity () const
 Gets the current world gravity.
void setAutoStep (bool autoStep)
 To control the step of physics.
bool isAutoStep ()
 Get the auto step of this physics world.
void stepSimulation (float delta)
 Advances the physics simulation by one step.
void setDebugDrawEnabled (bool enableDebugDraw)
 Enables or disables debug drawing for this world.
bool isDebugDrawEnabled () const
 Returns whether debug drawing is enabled.
void debugDraw (const ax::SceneRenderState &state)
 Renders debug physics geometry.
bool rayCast (const ax::Vec3 &startPos, const ax::Vec3 &endPos, HitResult *result)
 Casts a ray through the physics world.
bool sweepTest (Collider3D *collider, const ax::Mat4 &startTransform, const ax::Mat4 &endTransform, HitResult *result)
 Performs a swept shape cast on all objects in the PhysicsWorld3D.
 PhysicsWorld3D ()
 Constructs an uninitialized 3D physics world.
 ~PhysicsWorld3D () override
 Destroys the world and releases native physics resources.
void setGlobalEventEnabled (ContactEventBits events, bool enabled)
 Enable or disable specific collision events globally in this physics world.
bool isGlobalEventEnabled (ContactEventBits events) const
 Returns whether all requested collision event bits are globally enabled.
Public Member Functions inherited from Object
void retain ()
 Retains the ownership.
void release ()
 Releases the ownership immediately.
Object * autorelease ()
 Releases the ownership sometime soon automatically.
unsigned int getReferenceCount () const
 Returns the Object's current reference count.
uint64_t getObjectID () const noexcept
 Returns the process-local diagnostic identifier assigned at construction.
virtual ~Object ()
 Destructor.

Static Public Member Functions

static PhysicsWorld3D * obtain (Scene *scene)
 Obtains the 3D physics world associated with a scene.
static void release (PhysicsWorld3D *world)
 Releases a world obtained through obtain().

Detailed Description

The physics information container for Axmol 3D physics components.

Member Function Documentation

◆ obtain()

PhysicsWorld3D * obtain ( Scene * scene)
static

Obtains the 3D physics world associated with a scene.

Parameters
sceneScene that owns the physics world.
Returns
An autoreleased PhysicsWorld3D object.

◆ release()

void release ( PhysicsWorld3D * world)
static

Releases a world obtained through obtain().

Parameters
worldPhysics world to release. Passing nullptr is allowed.

◆ internalHandle() [1/2]

JPH::PhysicsSystem & internalHandle ( )
inline

Returns the native Jolt physics system.

Returns
Mutable native physics system reference.

◆ internalHandle() [2/2]

const JPH::PhysicsSystem & internalHandle ( ) const
inline

Returns the native Jolt physics system.

Returns
Const native physics system reference.

◆ getScene()

Scene * getScene ( ) const
inline

Returns the scene that owns this physics world.

Returns
Owning scene, or nullptr before initialization.

◆ setPreSolveCallback()

void setPreSolveCallback ( PreSolveCallback cb)

Set the PreSolve callback for the 3D physics world.

The PreSolve callback is invoked during JoltPhysics contact validation (OnContactValidate), allowing the user to decide whether a contact should be accepted or rejected. The callback runs inside the JobSystem worker threads and must return immediately.

Parameters
cbUser-provided callback function with signature: bool(const ContactInfo3D&)
  • Return true to accept the contact.
  • Return false to reject the contact.
Warning
PreSolve callbacks execute in a multithreaded context:
  • Do not access non-thread-safe shared data.
  • Do not block or wait on the main thread.
  • Execution order of multiple callbacks is not guaranteed, which may lead to non-deterministic behavior.
Note
If no callback is set, all contacts are accepted by default.

◆ setGravity()

void setGravity ( const Vec3 & gravity)

Sets gravity for the physics world.

Parameters
gravityGravity vector in world units per second squared.

◆ getGravity()

Vec3 getGravity ( ) const

Gets the current world gravity.

Returns
Gravity vector in world units per second squared.

◆ setAutoStep()

void setAutoStep ( bool autoStep)
inline

To control the step of physics.

If you want control it by yourself( fixed-timestep for example ), you can set this to false and call step by yourself.

Attention
If you set auto step to false, you need to control the time step by yourself.
Parameters
autoStepA bool object, default value is true.

◆ isAutoStep()

bool isAutoStep ( )
inline

Get the auto step of this physics world.

Returns
A bool object.

◆ stepSimulation()

void stepSimulation ( float delta)

Advances the physics simulation by one step.

By default, the physics world runs with auto-step enabled, and this function is called automatically each frame. If you disable auto-step via setAutoStep(false), you must call this function manually to update the simulation.

Parameters
deltaThe time step (in seconds) to simulate.

◆ setDebugDrawEnabled()

void setDebugDrawEnabled ( bool enableDebugDraw)

Enables or disables debug drawing for this world.

Parameters
enableDebugDrawTrue to enable debug rendering.

◆ isDebugDrawEnabled()

bool isDebugDrawEnabled ( ) const

Returns whether debug drawing is enabled.

Returns
True when debug drawing is enabled.

◆ debugDraw()

void debugDraw ( const ax::SceneRenderState & state)

Renders debug physics geometry.

Parameters
RendererRenderer used by the owning scene.
Note
This is called automatically by Scene.

◆ rayCast()

bool rayCast ( const ax::Vec3 & startPos,
const ax::Vec3 & endPos,
HitResult * result )

Casts a ray through the physics world.

Parameters
startPosThe start position of ray.
endPosThe end position of ray.
resultOutput hit result, or nullptr to only test for any hit.
Returns
True if the ray intersects a physics actor.

◆ sweepTest()

bool sweepTest ( Collider3D * collider,
const ax::Mat4 & startTransform,
const ax::Mat4 & endTransform,
HitResult * result )

Performs a swept shape cast on all objects in the PhysicsWorld3D.

Parameters
colliderCollider shape to sweep.
startTransformWorld transform at the start of the sweep.
endTransformWorld transform at the end of the sweep.
resultOutput hit result, or nullptr to only test for any hit.
Returns
True if the swept collider intersects a physics actor.

◆ setGlobalEventEnabled()

void setGlobalEventEnabled ( ContactEventBits events,
bool enabled )

Enable or disable specific collision events globally in this physics world.

This modifies the world's global event mask by turning on or off the specified event bits. Colliders can only generate these events if they are enabled both locally and globally.

Note
This setting should be applied before any rigid-body components are added to nodes, because global event state cannot be changed at runtime once rigidbodies are active. By default, all global collision events are disabled (mask = 0).
Parameters
eventsCollision event bits to modify.
enabledTrue to enable the specified events globally, false to disable them.

◆ isGlobalEventEnabled()

bool isGlobalEventEnabled ( ContactEventBits events) const

Returns whether all requested collision event bits are globally enabled.

Parameters
eventsCollision event bits to test.
Returns
True when the specified event bits are enabled globally.

The documentation for this class was generated from the following file:
  • PhysicsWorld3D.h