|
Axmol 3.0.0-89d6d9a
|
An PhysicsWorld2D object simulates collisions and other physical properties. More...
Public Member Functions | |
| bool | isGlobalEventEnabled (ContactEventBits events) const |
| Check whether specific collision events are globally enabled in this physics world. | |
| void | setGlobalEventEnabled (ContactEventBits events, bool enabled) |
| Enable or disable specific collision events globally in this physics world. | |
| void | setPreSolveCallback (PreSolveCallback cb) |
| Set the PreSolve callback for the 2D physics world. | |
| void | rayCast (RayCastHitCallback2D func, const Ray2D &ray, void *data=nullptr) |
| Searches for physics shapes that intersects the ray. | |
| void | overlapBox (PhysicsQueryCallback2D func, const Rect &rect, void *data) |
| f Enumerates all physics shapes whose bounding box overlaps the specified rectangle. | |
| Collider2D * | overlapBox (const Rect &rect) const |
| Returns the nearest physics shape whose bounding box overlaps the specified rectangle. | |
| Vector< Collider2D * > | overlapBoxAll (const Rect &rect) const |
| Returns all physics shapes whose bounding box overlaps the specified rectangle. | |
| void | overlapPoint (PhysicsQueryCallback2D func, const Vec2 &point, void *data) |
| Enumerates all physics shapes that contain the specified point. | |
| Collider2D * | overlapPoint (const Vec2 &point) const |
| Returns the nearest physics shape that contains the specified point. | |
| Vector< Collider2D * > | overlapPointAll (const Vec2 &point) const |
| Returns all physics shapes that contain the specified point. | |
| Scene * | getScene () const |
| Get a scene contain this physics world. | |
| Vec2 | getGravity () const |
| Get the gravity value of this physics world. | |
| void | setGravity (const Vec2 &gravity) |
| set the gravity value of this physics world. | |
| void | setSpeed (float speed) |
| Set the speed of this physics world. | |
| float | getSpeed () |
| Get the speed of this physics world. | |
| void | setSubsteps (int steps) |
| set the number of substeps in an update of the physics world. | |
| int | getSubsteps () const |
| Get the number of substeps of this physics world. | |
| void | setPreUpdateCallback (const std::function< void()> &callback) |
| set the callback which invoked before update of each object in physics world. | |
| void | setPostUpdateCallback (const std::function< void()> &callback) |
| set the callback which invoked after update of each object in physics world. | |
| 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. | |
An PhysicsWorld2D object simulates collisions and other physical properties.
You do not create PhysicsWorld2D objects directly; instead, you can get it from an Scene object.
| bool isGlobalEventEnabled | ( | ContactEventBits | events | ) | const |
Check whether specific collision events are globally enabled in this physics world.
This method verifies if the given event bits are allowed by the world's global event mask. Even if a collider enables these events locally, they will only take effect if the world also permits them.
| events | Collision event bits to check. |
| 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.
| events | Collision event bits to modify. |
| enabled | True to enable the specified events globally, false to disable them. |
| void setPreSolveCallback | ( | PreSolveCallback | cb | ) |
Set the PreSolve callback for the 2D physics world.
The PreSolve callback is invoked before constraint resolution, allowing the user to decide whether a contact should be accepted or rejected. This mimics Box2D-style PreSolve behavior.
| cb | User-provided callback function with signature: bool(const ContactInfo2D&)
|
| void rayCast | ( | RayCastHitCallback2D | func, |
| const Ray2D & | ray, | ||
| void * | data = nullptr ) |
Searches for physics shapes that intersects the ray.
Query this physics world along the line segment from start to end.
| void overlapBox | ( | PhysicsQueryCallback2D | func, |
| const Rect & | rect, | ||
| void * | data ) |
f Enumerates all physics shapes whose bounding box overlaps the specified rectangle.
Queries the physics world for shapes intersecting the given rect. For each overlapping shape, the provided callback function is invoked.
| func | Callback function executed for each overlapping shape. |
| rect | Rectangle region (x, y, width, height) used for overlap testing. |
| data | User-defined data passed to the callback. |
| Collider2D * overlapBox | ( | const Rect & | rect | ) | const |
Returns the nearest physics shape whose bounding box overlaps the specified rectangle.
Queries the physics world at the given rect and finds the closest shape that intersects it. If no shape overlaps the rect, nullptr is returned.
| rect | Rectangle region (x, y, width, height) used for overlap testing. |
| Vector< Collider2D * > overlapBoxAll | ( | const Rect & | rect | ) | const |
Returns all physics shapes whose bounding box overlaps the specified rectangle.
Queries the physics world and collects every shape intersecting the given rect into a vector.
| rect | Rectangle region (x, y, width, height) used for overlap testing. |
| void overlapPoint | ( | PhysicsQueryCallback2D | func, |
| const Vec2 & | point, | ||
| void * | data ) |
Enumerates all physics shapes that contain the specified point.
Queries the physics world for shapes covering the given point. For each shape that contains the point, the provided callback function is invoked.
| func | Callback function executed for each shape containing the point. |
| point | Position of the point to test. |
| data | User-defined data passed to the callback. |
| Collider2D * overlapPoint | ( | const Vec2 & | point | ) | const |
Returns the nearest physics shape that contains the specified point.
Queries the physics world at the given point and finds the closest shape that covers it. If no shape contains the point, nullptr is returned.
| point | Position of the point to test. |
| Vector< Collider2D * > overlapPointAll | ( | const Vec2 & | point | ) | const |
Returns all physics shapes that contain the specified point.
Queries the physics world and collects every shape covering the given point into a vector.
| point | Position of the point to test. |
|
inline |
Get a scene contain this physics world.
| void setGravity | ( | const Vec2 & | gravity | ) |
set the gravity value of this physics world.
| gravity | A gravity value of this physics world. |
|
inline |
Set the speed of this physics world.
| speed | A float number. Speed is the rate at which the simulation executes. default value is 1.0. |
|
inline |
Get the speed of this physics world.
| void setSubsteps | ( | int | steps | ) |
set the number of substeps in an update of the physics world.
One physics update will be divided into several substeps to increase its accuracy.
| steps | An integer number, default value is 1. |
|
inline |
Get the number of substeps of this physics world.
|
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.
| autoStep | A bool object, default value is true. |
|
inline |
Get the auto step of this physics world.
| 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.
| delta | The time step (in seconds) to simulate. |