Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
PhysXJoints.cpp File Reference

Joints for the PhysX backend, on the Jolt module's terms. More...

#include "./PhysXWorld.hpp"
#include "../physics3d/Physics3DBindings.hpp"
#include <algorithm>
#include <cmath>
Include dependency graph for PhysXJoints.cpp:

Go to the source code of this file.

Classes

struct  Body
 What the module knows about a body beyond what PhysX holds. More...
struct  Joint
struct  World

Enumerations

enum class  JointKind

Functions

uint32_t physics3d_addSwingTwistJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, float px, float py, float pz, float ax, float ay, float az, float nx, float ny, float nz, float normalHalf, float planeHalf, float twistMin, float twistMax, int collideConnected)
 Both frames coincide at creation, so limits are relative to the authored pose.
uint32_t physics3d_addSixDOFJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, float px, float py, float pz, float ax, float ay, float az, float nx, float ny, float nz, int translationMotion, int rotationMotion, float lx, float ly, float lz, float hx, float hy, float hz, float rx, float ry, float rz, float sx, float sy, float sz, int collideConnected)
 Axis motion is packed as two bits per axis: 0 locked, 1 limited, 2 free.
void physics3d_setAdvancedJointMotor (uint32_t entity, int enable, float vx, float vy, float vz, float wx, float wy, float wz, float maxForce, float maxTorque)
 Live velocity/force changes do not rebuild the joint or reset its zero pose.
uint32_t physics3d_addPointJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, float px, float py, float pz, int collideConnected)
 A shared point, free to turn on all three axes — a chain link, a ragdoll limb.
uint32_t physics3d_addHingeJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, float px, float py, float pz, float ax, float ay, float az, int enableLimit, float lowerAngle, float upperAngle, int enableMotor, float motorSpeed, float maxTorque, int collideConnected)
uint32_t physics3d_addSliderJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, float px, float py, float pz, float ax, float ay, float az, int enableLimit, float lower, float upper, int enableMotor, float motorSpeed, float maxForce, int collideConnected)
 One axis of travel — a lift, a piston, a sliding door.
uint32_t physics3d_addDistanceJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, float ax, float ay, float az, float bx, float by, float bz, float minLength, float maxLength, float frequency, float damping, int collideConnected)
uint32_t physics3d_addFixedJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB, int collideConnected)
 No freedom at all: the two move as one, until something breaks them apart.
void physics3d_removeJoint (uint32_t entity, uint32_t bodyA, uint32_t bodyB)
void physics3d_setJointMotor (uint32_t entity, int enable, float speed)
 Drive an existing hinge or slider from gameplay, without rebuilding the joint.
void physics3d_setJointLimits (uint32_t entity, int enable, float lower, float upper)
void physics3d_setJointMotorLimit (uint32_t entity, float limit)
void physics3d_setDistanceJoint (uint32_t entity, float minLength, float maxLength, float frequency, float damping)
int physics3d_jointForce (uint32_t entity)
float physics3d_jointValue (uint32_t entity)

Detailed Description

Joints for the PhysX backend, on the Jolt module's terms.

Anchors and axes arrive in world space, taken when the joint is made, and both bodies get the same frame, so every limit's zero is the authored pose — the same rule the Jolt module follows. A slider is a D6 joint here rather than a prismatic one, because a prismatic joint has no motor; swing-twist and six-axis joints are D6, a configurable joint.

"Do not collide connected" is PhysX's own default for every joint, so the assemblies the Jolt module keeps are not needed.

Author
ESEngine Team
Date
2026

Definition in file PhysXJoints.cpp.

Enumeration Type Documentation

◆ JointKind

enum class esengine::physics3d_physx::JointKind : uint8_t
strong

Which PxJoint an entity's component made, so a motor or a reading knows what it is holding without RTTI.

Definition at line 84 of file PhysXWorld.hpp.

Function Documentation

◆ physics3d_addDistanceJoint()

uint32_t physics3d_addDistanceJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
float ax,
float ay,
float az,
float bx,
float by,
float bz,
float minLength,
float maxLength,
float frequency,
float damping,
int collideConnected )

A distance kept between two points — a rope (max only), a rod (min = max), or a spring when a frequency is given.

Definition at line 328 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Distance, and esengine::physics3d_physx::physics().

◆ physics3d_addFixedJoint()

uint32_t physics3d_addFixedJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
int collideConnected )

No freedom at all: the two move as one, until something breaks them apart.

Definition at line 343 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Fixed, and esengine::physics3d_physx::physics().

◆ physics3d_addHingeJoint()

uint32_t physics3d_addHingeJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
float px,
float py,
float pz,
float ax,
float ay,
float az,
int enableLimit,
float lowerAngle,
float upperAngle,
int enableMotor,
float motorSpeed,
float maxTorque,
int collideConnected )

One axis of rotation, optionally limited and optionally driven — a door, a lever, a wheel with a motor.

Definition at line 279 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Hinge, and esengine::physics3d_physx::physics().

◆ physics3d_addPointJoint()

uint32_t physics3d_addPointJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
float px,
float py,
float pz,
int collideConnected )

A shared point, free to turn on all three axes — a chain link, a ragdoll limb.

Definition at line 268 of file PhysXJoints.cpp.

References esengine::physics3d_physx::physics(), and esengine::physics3d_physx::Point.

◆ physics3d_addSixDOFJoint()

uint32_t physics3d_addSixDOFJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
float px,
float py,
float pz,
float ax,
float ay,
float az,
float nx,
float ny,
float nz,
int translationMotion,
int rotationMotion,
float lx,
float ly,
float lz,
float hx,
float hy,
float hz,
float rx,
float ry,
float rz,
float sx,
float sy,
float sz,
int collideConnected )

Axis motion is packed as two bits per axis: 0 locked, 1 limited, 2 free.

Definition at line 197 of file PhysXJoints.cpp.

References esengine::physics3d_physx::SixDOF.

◆ physics3d_addSliderJoint()

uint32_t physics3d_addSliderJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
float px,
float py,
float pz,
float ax,
float ay,
float az,
int enableLimit,
float lower,
float upper,
int enableMotor,
float motorSpeed,
float maxForce,
int collideConnected )

One axis of travel — a lift, a piston, a sliding door.

Definition at line 307 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Slider.

◆ physics3d_addSwingTwistJoint()

uint32_t physics3d_addSwingTwistJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB,
float px,
float py,
float pz,
float ax,
float ay,
float az,
float nx,
float ny,
float nz,
float normalHalf,
float planeHalf,
float twistMin,
float twistMax,
int collideConnected )

Both frames coincide at creation, so limits are relative to the authored pose.

Definition at line 171 of file PhysXJoints.cpp.

References esengine::physics3d_physx::SwingTwist.

◆ physics3d_jointForce()

int physics3d_jointForce ( uint32_t entity)

Definition at line 424 of file PhysXJoints.cpp.

◆ physics3d_jointValue()

float physics3d_jointValue ( uint32_t entity)

What the joint is at right now — a hinge's angle, a slider's travel — so a game can watch a door swing without integrating it a second time.

Definition at line 435 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Hinge, and esengine::physics3d_physx::Slider.

◆ physics3d_removeJoint()

void physics3d_removeJoint ( uint32_t entity,
uint32_t bodyA,
uint32_t bodyB )

Definition at line 354 of file PhysXJoints.cpp.

◆ physics3d_setAdvancedJointMotor()

void physics3d_setAdvancedJointMotor ( uint32_t entity,
int enable,
float vx,
float vy,
float vz,
float wx,
float wy,
float wz,
float maxForce,
float maxTorque )

Live velocity/force changes do not rebuild the joint or reset its zero pose.

Definition at line 240 of file PhysXJoints.cpp.

References esengine::physics3d_physx::SixDOF, and esengine::physics3d_physx::SwingTwist.

◆ physics3d_setDistanceJoint()

void physics3d_setDistanceJoint ( uint32_t entity,
float minLength,
float maxLength,
float frequency,
float damping )

Definition at line 415 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Distance, and wakeEnds().

◆ physics3d_setJointLimits()

void physics3d_setJointLimits ( uint32_t entity,
int enable,
float lower,
float upper )

◆ physics3d_setJointMotor()

void physics3d_setJointMotor ( uint32_t entity,
int enable,
float speed )

Drive an existing hinge or slider from gameplay, without rebuilding the joint.

Definition at line 363 of file PhysXJoints.cpp.

References esengine::physics3d_physx::Hinge, and esengine::physics3d_physx::Slider.

◆ physics3d_setJointMotorLimit()

void physics3d_setJointMotorLimit ( uint32_t entity,
float limit )