|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
The PhysX backend's world, bodies, characters, queries and readback. More...
#include "./PhysXWorld.hpp"#include "../physics3d/Physics3DBindings.hpp"#include <algorithm>#include <cmath>#include <cstring>#include <limits>
Go to the source code of this file.
Classes | |
| struct | Character |
Namespaces | |
| namespace | esengine |
| namespace | esengine::physics3d_physx |
Functions | |
| World & | esengine::physics3d_physx::world () |
| PxPhysics & | esengine::physics3d_physx::physics () |
| PxMaterial * | esengine::physics3d_physx::defaultMaterial () |
| Friction 0.6, no bounce: the default physics material. | |
| void | physics3d_init (float gx, float gy, float gz, uint32_t) |
| void | physics3d_shutdown () |
| int | physics3d_isReady () |
| void | physics3d_setLayerMask (uint32_t layer, uint32_t mask) |
| Declares which layers layer layer collides with. | |
| void | physics3d_setSolver (int velocityIterations, int positionIterations, int allowSleep, float bounceThreshold) |
| void | physics3d_step (float dt, int collisionSteps) |
| Advance the world, then refill the transform buffer with every active body. | |
| void | physics3d_optimize () |
| uint32_t | physics3d_addCompound (uint32_t entity, uintptr_t partsPtr, uint32_t count, float px, float py, float pz, float qx, float qy, float qz, float qw, int motion, float gravityScale, float linearDamping, float angularDamping, int fixedRotation, uint32_t layer, int continuous, float friction, float restitution, int isSensor, float mass) |
| uint32_t | physics3d_addBox (uint32_t entity, float hx, float hy, float hz, float px, float py, float pz, float qx, float qy, float qz, float qw, int motion, float gravityScale, float linearDamping, float angularDamping, int fixedRotation, uint32_t layer, int continuous, float friction, float restitution, int isSensor, float cx, float cy, float cz) |
| uint32_t | physics3d_addSphere (uint32_t entity, float radius, float px, float py, float pz, float qx, float qy, float qz, float qw, int motion, float gravityScale, float linearDamping, float angularDamping, int fixedRotation, uint32_t layer, int continuous, float friction, float restitution, int isSensor, float cx, float cy, float cz) |
| uint32_t | physics3d_addCapsule (uint32_t entity, float radius, float halfHeight, float px, float py, float pz, float qx, float qy, float qz, float qw, int motion, float gravityScale, float linearDamping, float angularDamping, int fixedRotation, uint32_t layer, int continuous, float friction, float restitution, int isSensor, float cx, float cy, float cz) |
| uint32_t | physics3d_addMeshBody (uint32_t entity, uintptr_t vertexPtr, uint32_t vertexCount, uintptr_t indexPtr, uint32_t indexCount, float px, float py, float pz, float qx, float qy, float qz, float qw, uint32_t layer, float friction, float restitution) |
| Registers imported geometry as a collider. | |
| uint32_t | physics3d_addConvexBody (uint32_t entity, uintptr_t vertexPtr, uint32_t vertexCount, float px, float py, float pz, float qx, float qy, float qz, float qw, int motion, float gravityScale, float linearDamping, float angularDamping, int fixedRotation, uint32_t layer, int continuous, float friction, float restitution, int isSensor) |
| Registers the convex hull of imported geometry as a collider. | |
| void | physics3d_removeBody (uint32_t bodyId) |
| void | physics3d_setTransform (uint32_t bodyId, float px, float py, float pz, float qx, float qy, float qz, float qw) |
| void | physics3d_setMass (uint32_t bodyId, float mass) |
| void | physics3d_setLinearVelocity (uint32_t bodyId, float vx, float vy, float vz) |
| int | physics3d_getBodyState (uint32_t bodyId) |
| int | physics3d_getBodyDynamics (uint32_t bodyId) |
| int | physics3d_getBodyMassData (uint32_t bodyId) |
| void | physics3d_addForce (uint32_t bodyId, float fx, float fy, float fz, float px, float py, float pz) |
| void | physics3d_addImpulse (uint32_t bodyId, float ix, float iy, float iz, float px, float py, float pz) |
| void | physics3d_addAngularImpulse (uint32_t bodyId, float ix, float iy, float iz) |
| void | physics3d_setAngularVelocity (uint32_t bodyId, float wx, float wy, float wz) |
| void | physics3d_setGravity (float gx, float gy, float gz) |
| void | physics3d_setAwake (uint32_t bodyId, int awake) |
| int | physics3d_isAwake (uint32_t bodyId) |
| void | physics3d_addTorque (uint32_t bodyId, float tx, float ty, float tz) |
| A torque of (tx, ty, tz) newton metres, over the next step. | |
| uintptr_t | physics3d_transforms () |
| size_t | physics3d_transformsBytes () |
| uintptr_t | physics3d_characterHits () |
| size_t | physics3d_characterHitsBytes () |
| uintptr_t | physics3d_contactEnterMasses () |
| size_t | physics3d_contactEnterMassesBytes () |
| uintptr_t | physics3d_contactEnterSpeeds () |
| size_t | physics3d_contactEnterSpeedsBytes () |
| uintptr_t | physics3d_contactEnters () |
| size_t | physics3d_contactEntersBytes () |
| uintptr_t | physics3d_contactExits () |
| size_t | physics3d_contactExitsBytes () |
| uintptr_t | physics3d_sensorEnters () |
| size_t | physics3d_sensorEntersBytes () |
| uintptr_t | physics3d_sensorExits () |
| size_t | physics3d_sensorExitsBytes () |
| uintptr_t | physics3d_queryResult () |
| size_t | physics3d_queryResultBytes () |
The PhysX backend's world, bodies, characters, queries and readback.
Every entry point here answers what its Jolt twin answers, in the same buffer layouts (Physics3DBindings.hpp is included so a signature that drifts is a compile error). Where the two engines genuinely differ the choice follows the usual defaults of this solver: trigger volumes report character controllers, and a character stops rising when it hits a ceiling.
Definition in file PhysXModuleEntry.cpp.
| void physics3d_addAngularImpulse | ( | uint32_t | bodyId, |
| float | ix, | ||
| float | iy, | ||
| float | iz ) |
Definition at line 740 of file PhysXModuleEntry.cpp.
| uint32_t physics3d_addBox | ( | uint32_t | entity, |
| float | hx, | ||
| float | hy, | ||
| float | hz, | ||
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw, | ||
| int | motion, | ||
| float | gravityScale, | ||
| float | linearDamping, | ||
| float | angularDamping, | ||
| int | fixedRotation, | ||
| uint32_t | layer, | ||
| int | continuous, | ||
| float | friction, | ||
| float | restitution, | ||
| int | isSensor, | ||
| float | cx, | ||
| float | cy, | ||
| float | cz ) |
Definition at line 516 of file PhysXModuleEntry.cpp.
| uint32_t physics3d_addCapsule | ( | uint32_t | entity, |
| float | radius, | ||
| float | halfHeight, | ||
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw, | ||
| int | motion, | ||
| float | gravityScale, | ||
| float | linearDamping, | ||
| float | angularDamping, | ||
| int | fixedRotation, | ||
| uint32_t | layer, | ||
| int | continuous, | ||
| float | friction, | ||
| float | restitution, | ||
| int | isSensor, | ||
| float | cx, | ||
| float | cy, | ||
| float | cz ) |
halfHeight is the cylinder half-height, so the capsule is 2*halfHeight + 2*radius tall — the same convention CapsuleCollider2D uses in 2D.
Definition at line 546 of file PhysXModuleEntry.cpp.
| uint32_t physics3d_addCompound | ( | uint32_t | entity, |
| uintptr_t | partsPtr, | ||
| uint32_t | count, | ||
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw, | ||
| int | motion, | ||
| float | gravityScale, | ||
| float | linearDamping, | ||
| float | angularDamping, | ||
| int | fixedRotation, | ||
| uint32_t | layer, | ||
| int | continuous, | ||
| float | friction, | ||
| float | restitution, | ||
| int | isSensor, | ||
| float | mass ) |
Each primitive is 11 floats: kind, dimensions.xyz, offset.xyz, rotation.xyzw. The compound remains ONE body, so children cannot separate under gravity.
Definition at line 462 of file PhysXModuleEntry.cpp.
References physics3d_removeBody().
| uint32_t physics3d_addConvexBody | ( | uint32_t | entity, |
| uintptr_t | vertexPtr, | ||
| uint32_t | vertexCount, | ||
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw, | ||
| int | motion, | ||
| float | gravityScale, | ||
| float | linearDamping, | ||
| float | angularDamping, | ||
| int | fixedRotation, | ||
| uint32_t | layer, | ||
| int | continuous, | ||
| float | friction, | ||
| float | restitution, | ||
| int | isSensor ) |
Registers the convex hull of imported geometry as a collider.
The hull is what makes imported geometry usable as a DYNAMIC body: Jolt cannot give a triangle soup an inertia tensor, so a mesh collider is scenery whatever its RigidBody3D says.
| vertexPtr | vertexCount * 3 floats, in metres, in the body's own space. |
Definition at line 593 of file PhysXModuleEntry.cpp.
| void physics3d_addForce | ( | uint32_t | bodyId, |
| float | fx, | ||
| float | fy, | ||
| float | fz, | ||
| float | px, | ||
| float | py, | ||
| float | pz ) |
A force of (fx, fy, fz) newtons at the world point (px, py, pz), over the next step. It turns the body as well as pushing it, by as much as the point is off the centre of mass; and it wakes a body that has gone to sleep.
Definition at line 721 of file PhysXModuleEntry.cpp.
| void physics3d_addImpulse | ( | uint32_t | bodyId, |
| float | ix, | ||
| float | iy, | ||
| float | iz, | ||
| float | px, | ||
| float | py, | ||
| float | pz ) |
Definition at line 730 of file PhysXModuleEntry.cpp.
| uint32_t physics3d_addMeshBody | ( | uint32_t | entity, |
| uintptr_t | vertexPtr, | ||
| uint32_t | vertexCount, | ||
| uintptr_t | indexPtr, | ||
| uint32_t | indexCount, | ||
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw, | ||
| uint32_t | layer, | ||
| float | friction, | ||
| float | restitution ) |
Registers imported geometry as a collider.
Triangles rather than a shape: the .esmesh format belongs to the asset layer, which hands over positions it has already extracted and scaled. A mesh collider is always STATIC — Jolt cannot give a triangle soup an inertia tensor, so there is nothing for a solver to push.
| vertexPtr | vertexCount * 3 floats, in metres, in the body's own space. |
| indexPtr | indexCount uint32 indices; must be a triangle list. |
Definition at line 562 of file PhysXModuleEntry.cpp.
| uint32_t physics3d_addSphere | ( | uint32_t | entity, |
| float | radius, | ||
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw, | ||
| int | motion, | ||
| float | gravityScale, | ||
| float | linearDamping, | ||
| float | angularDamping, | ||
| int | fixedRotation, | ||
| uint32_t | layer, | ||
| int | continuous, | ||
| float | friction, | ||
| float | restitution, | ||
| int | isSensor, | ||
| float | cx, | ||
| float | cy, | ||
| float | cz ) |
Definition at line 531 of file PhysXModuleEntry.cpp.
| void physics3d_addTorque | ( | uint32_t | bodyId, |
| float | tx, | ||
| float | ty, | ||
| float | tz ) |
A torque of (tx, ty, tz) newton metres, over the next step.
Definition at line 774 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_characterHits | ( | ) |
Definition at line 787 of file PhysXModuleEntry.cpp.
| size_t physics3d_characterHitsBytes | ( | ) |
Definition at line 789 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_contactEnterMasses | ( | ) |
Definition at line 791 of file PhysXModuleEntry.cpp.
| size_t physics3d_contactEnterMassesBytes | ( | ) |
Definition at line 793 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_contactEnters | ( | ) |
Definition at line 799 of file PhysXModuleEntry.cpp.
| size_t physics3d_contactEntersBytes | ( | ) |
Definition at line 801 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_contactEnterSpeeds | ( | ) |
Definition at line 795 of file PhysXModuleEntry.cpp.
| size_t physics3d_contactEnterSpeedsBytes | ( | ) |
Definition at line 797 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_contactExits | ( | ) |
Definition at line 803 of file PhysXModuleEntry.cpp.
| size_t physics3d_contactExitsBytes | ( | ) |
Definition at line 805 of file PhysXModuleEntry.cpp.
| int physics3d_getBodyDynamics | ( | uint32_t | bodyId | ) |
Writes (mass, wx,wy,wz) into the query buffer: the body's mass in kilograms and its angular velocity in radians a second, world space. 0 when the body is gone or does not move (a static or kinematic body has no mass to push).
Definition at line 683 of file PhysXModuleEntry.cpp.
| int physics3d_getBodyMassData | ( | uint32_t | bodyId | ) |
Definition at line 694 of file PhysXModuleEntry.cpp.
| int physics3d_getBodyState | ( | uint32_t | bodyId | ) |
Writes (px,py,pz, qx,qy,qz,qw, vx,vy,vz) into the query buffer; 0 when the body is gone. One body's state, for a caller that wants it outside the step readback.
Definition at line 670 of file PhysXModuleEntry.cpp.
References esengine::physics3d_physx::Body::actor, and esengine::physics3d_physx::Body::kinematicVelocity.
| void physics3d_init | ( | float | gx, |
| float | gy, | ||
| float | gz, | ||
| uint32_t | maxBodies ) |
Definition at line 346 of file PhysXModuleEntry.cpp.
| int physics3d_isAwake | ( | uint32_t | bodyId | ) |
Definition at line 767 of file PhysXModuleEntry.cpp.
| int physics3d_isReady | ( | ) |
Definition at line 400 of file PhysXModuleEntry.cpp.
| void physics3d_optimize | ( | ) |
Rebuild the broad-phase tree. Worth calling once after the static geometry of a level is in, and never per frame.
Definition at line 455 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_queryResult | ( | ) |
Definition at line 815 of file PhysXModuleEntry.cpp.
| size_t physics3d_queryResultBytes | ( | ) |
Definition at line 817 of file PhysXModuleEntry.cpp.
| void physics3d_removeBody | ( | uint32_t | bodyId | ) |
Definition at line 621 of file PhysXModuleEntry.cpp.
Referenced by physics3d_addCompound().
| uintptr_t physics3d_sensorEnters | ( | ) |
Definition at line 807 of file PhysXModuleEntry.cpp.
| size_t physics3d_sensorEntersBytes | ( | ) |
Definition at line 809 of file PhysXModuleEntry.cpp.
| uintptr_t physics3d_sensorExits | ( | ) |
Definition at line 811 of file PhysXModuleEntry.cpp.
| size_t physics3d_sensorExitsBytes | ( | ) |
Definition at line 813 of file PhysXModuleEntry.cpp.
| void physics3d_setAngularVelocity | ( | uint32_t | bodyId, |
| float | wx, | ||
| float | wy, | ||
| float | wz ) |
Definition at line 747 of file PhysXModuleEntry.cpp.
| void physics3d_setAwake | ( | uint32_t | bodyId, |
| int | awake ) |
Definition at line 760 of file PhysXModuleEntry.cpp.
| void physics3d_setGravity | ( | float | gx, |
| float | gy, | ||
| float | gz ) |
Definition at line 754 of file PhysXModuleEntry.cpp.
| void physics3d_setLayerMask | ( | uint32_t | layer, |
| uint32_t | mask ) |
Declares which layers layer layer collides with.
Both sides must agree, so a body only meets another when each names the other — one of them saying no is enough to keep them apart. Set before bodies are registered: an ObjectLayer is fixed at creation.
Definition at line 403 of file PhysXModuleEntry.cpp.
References esengine::physics3d::Layers::COUNT, esengine::physics3d_physx::LAYER_COUNT, esengine::physics3d::layerMatrix(), and esengine::physics3d::LayerMatrix::masks.
| void physics3d_setLinearVelocity | ( | uint32_t | bodyId, |
| float | vx, | ||
| float | vy, | ||
| float | vz ) |
Definition at line 654 of file PhysXModuleEntry.cpp.
References esengine::physics3d_physx::Body::actor, esengine::physics3d_physx::Body::hasKinematicVelocity, and esengine::physics3d_physx::Body::kinematicVelocity.
| void physics3d_setMass | ( | uint32_t | bodyId, |
| float | mass ) |
Definition at line 645 of file PhysXModuleEntry.cpp.
References esengine::physics3d_physx::Body::actor.
| void physics3d_setSolver | ( | int | velocityIterations, |
| int | positionIterations, | ||
| int | allowSleep, | ||
| float | bounceThreshold ) |
The project's solver settings. Each value <= 0 keeps the backend's own default (Jolt's for Jolt, the usual ones for PhysX); allowSleep is 0 or 1. After init, before bodies.
Definition at line 408 of file PhysXModuleEntry.cpp.
| void physics3d_setTransform | ( | uint32_t | bodyId, |
| float | px, | ||
| float | py, | ||
| float | pz, | ||
| float | qx, | ||
| float | qy, | ||
| float | qz, | ||
| float | qw ) |
Definition at line 631 of file PhysXModuleEntry.cpp.
References esengine::physics3d_physx::Body::actor.
| void physics3d_shutdown | ( | ) |
Definition at line 376 of file PhysXModuleEntry.cpp.
| void physics3d_step | ( | float | dt, |
| int | collisionSteps ) |
Advance the world, then refill the transform buffer with every active body.
Definition at line 417 of file PhysXModuleEntry.cpp.
References esengine::physics3d_physx::Body::character.
| uintptr_t physics3d_transforms | ( | ) |
Definition at line 783 of file PhysXModuleEntry.cpp.
| size_t physics3d_transformsBytes | ( | ) |
Definition at line 785 of file PhysXModuleEntry.cpp.