载入中...
搜索中...
未找到
JoltJoint.h
浏览该文件的文档.
1#pragma once
2// Jolt requires its platform header before any other native header.
3#include <Jolt/Jolt.h>
4
5// Provider implementation dependencies.
6#include <Jolt/Physics/Constraints/SixDOFConstraint.h>
10namespace eve::physics::jolt {
11struct JointState {
12 std::weak_ptr<State> world;
13 std::weak_ptr<BodyState> a, b;
14 JPH::Ref<JPH::TwoBodyConstraint> native;
15 JPH::Ref<JPH::SixDOFConstraint> velocity;
16 JPH::Vec3 worldLinearVelocity = JPH::Vec3::sZero(), worldAngularVelocity = JPH::Vec3::sZero();
20 Joint3D* owner = nullptr;
21 bool alive = true, collide = false;
22 float length = 0, forceThreshold = FLT_MAX, torqueThreshold = FLT_MAX;
23};
25class JointBackend final : public IJointBackend3D {
26public:
27 std::shared_ptr<JointState> joint;
28 explicit JointBackend(std::shared_ptr<JointState> value) : joint(std::move(value)) {}
29 ~JointBackend() override;
30 void bindOwner(Joint3D&) noexcept override;
31 bool isValid() const noexcept override;
32 void destroy() noexcept override;
33 void invalidate() noexcept override;
34 eve::Result<JointFrames3D> localFrames() const override;
35 eve::Result<void> setCollideConnected(bool collide) override;
36 eve::Result<bool> getCollideConnected() const override;
37 eve::Result<void> setForceThreshold(float threshold) override;
38 eve::Result<float> getForceThreshold() const override;
39 eve::Result<void> setTorqueThreshold(float threshold) override;
40 eve::Result<float> getTorqueThreshold() const override;
41 eve::Result<float> getConstraintForceX() const override;
42 eve::Result<float> getConstraintForceY() const override;
43 eve::Result<float> getConstraintForceZ() const override;
44 eve::Result<float> getConstraintTorqueX() const override;
45 eve::Result<float> getConstraintTorqueY() const override;
46 eve::Result<float> getConstraintTorqueZ() const override;
47 eve::Result<float> getLinearSeparation() const override;
48 eve::Result<float> getAngularSeparation() const override;
49 eve::Result<void> setDistanceLength(float length) override;
50 eve::Result<float> getDistanceLength() const override;
51 eve::Result<float> getDistanceCurrentLength() const override;
52 eve::Result<void> setDistanceSpring(bool enabled, float hertz, float dampingRatio) override;
53 eve::Result<void> setDistanceLimits(bool enabled, float minimum, float maximum) override;
54 eve::Result<void> setDistanceMotor(bool enabled, float speed, float maxForce) override;
55 eve::Result<void> setRevoluteSpring(bool enabled, float targetAngle, float hertz, float dampingRatio) override;
56 eve::Result<void> setRevoluteLimits(bool enabled, float lower, float upper) override;
57 eve::Result<void> setRevoluteMotor(bool enabled, float speed, float maxTorque) override;
58 eve::Result<float> getRevoluteAngle() const override;
59 eve::Result<float> getRevoluteMotorTorque() const override;
60 eve::Result<void> setPrismaticSpring(bool enabled, float targetTranslation, float hertz,
61 float dampingRatio) override;
62 eve::Result<void> setPrismaticLimits(bool enabled, float lower, float upper) override;
63 eve::Result<void> setPrismaticMotor(bool enabled, float speed, float maxForce) override;
64 eve::Result<float> getPrismaticTranslation() const override;
65 eve::Result<float> getPrismaticSpeed() const override;
66 eve::Result<float> getPrismaticMotorForce() const override;
67 eve::Result<void> setSphericalConeLimit(bool enabled, float angle) override;
68 eve::Result<void> setSphericalTwistLimits(bool enabled, float lower, float upper) override;
69 eve::Result<void> setSphericalMotor(bool enabled, float velocityX, float velocityY, float velocityZ,
70 float maxTorque) override;
71 eve::Result<float> getSphericalConeAngle() const override;
72 eve::Result<float> getSphericalTwistAngle() const override;
73 eve::Result<void> setWheelSuspension(bool enabled, float hertz, float dampingRatio) override;
74 eve::Result<void> setWheelSuspensionLimits(bool enabled, float lower, float upper) override;
75 eve::Result<void> setWheelSpinMotor(bool enabled, float speed, float maxTorque) override;
76 eve::Result<void> setWheelSteering(bool enabled, float targetAngle, float hertz, float dampingRatio,
77 float maxTorque) override;
78 eve::Result<void> setWheelSteeringLimits(bool enabled, float lower, float upper) override;
79 eve::Result<float> getWheelSpinSpeed() const override;
80 eve::Result<float> getWheelSpinTorque() const override;
81 eve::Result<float> getWheelSteeringAngle() const override;
82 eve::Result<float> getWheelSteeringTorque() const override;
83 eve::Result<void> setWeldLinearSpring(float hertz, float dampingRatio) override;
84 eve::Result<void> setWeldAngularSpring(float hertz, float dampingRatio) override;
85 eve::Result<float> getWeldLinearHertz() const override;
86 eve::Result<float> getWeldLinearDampingRatio() const override;
87 eve::Result<float> getWeldAngularHertz() const override;
88 eve::Result<float> getWeldAngularDampingRatio() const override;
89 eve::Result<void> setMotorLinearVelocity(float vx, float vy, float vz) override;
90 eve::Result<void> setMotorAngularVelocity(float wx, float wy, float wz) override;
91 eve::Result<void> setMotorVelocityLimits(float maxForce, float maxTorque) override;
92 eve::Result<void> setMotorLinearSpring(float hertz, float dampingRatio, float maxForce) override;
93 eve::Result<void> setMotorAngularSpring(float hertz, float dampingRatio, float maxTorque) override;
94 eve::Result<float> getMotorLinearVelocityX() const override;
95 eve::Result<float> getMotorLinearVelocityY() const override;
96 eve::Result<float> getMotorLinearVelocityZ() const override;
97 eve::Result<float> getMotorAngularVelocityX() const override;
98 eve::Result<float> getMotorAngularVelocityY() const override;
99 eve::Result<float> getMotorAngularVelocityZ() const override;
100 eve::Result<void> setParallelSpring(float hertz, float dampingRatio, float maxTorque) override;
101 eve::Result<float> getParallelHertz() const override;
102 eve::Result<float> getParallelDampingRatio() const override;
103 eve::Result<float> getParallelMaxTorque() const override;
104
105private:
106 [[nodiscard]] eve::Result<void> wakeBodies() const;
107 [[nodiscard]] eve::Result<void> requireKind(JointKind3D) const;
108 JPH::SixDOFConstraint& six() const;
109 JPH::SixDOFConstraint& drive() const;
110 JPH::RMat44 frame(bool second) const;
111 JPH::Vec3 force(bool torque) const;
112};
114JPH::uint64 pairKey(JPH::BodyID, JPH::BodyID);
116void notifyJointShapeChanged(State&, JPH::BodyID, JPH::Vec3Arg);
117} // namespace eve::physics::jolt
ForceVector force
ForceVector torque
float maxForce
float maximum[3]
float minimum[3]
std::int32_t second
float dampingRatio
float length
ssq::Object frame
Object::Ptr value
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Solver-independent control of one constraint, owned exclusively by its Joint3D facade....
Script-facing joint owned by a World3D. Legacy scalar/void methods adapt the checked backend contract...
Definition Joint3D.h:27
Sole facade provider; parent invalidation removes the native constraint before either body dies.
Definition JoltJoint.h:25
eve::Result< float > getWeldLinearDampingRatio() const override
getWeldLinearDampingRatio; see the class lifetime, validation and failure contract.
eve::Result< void > setForceThreshold(float threshold) override
setForceThreshold; see the class lifetime, validation and failure contract.
eve::Result< float > getConstraintTorqueX() const override
getConstraintTorqueX; see the class lifetime, validation and failure contract.
eve::Result< float > getWheelSpinTorque() const override
getWheelSpinTorque; see the class lifetime, validation and failure contract.
eve::Result< bool > getCollideConnected() const override
getCollideConnected; see the class lifetime, validation and failure contract.
Definition JoltJoint.cpp:84
eve::Result< float > getTorqueThreshold() const override
getTorqueThreshold; see the class lifetime, validation and failure contract.
std::shared_ptr< JointState > joint
Definition JoltJoint.h:27
eve::Result< void > setSphericalTwistLimits(bool enabled, float lower, float upper) override
setSphericalTwistLimits; see the class lifetime, validation and failure contract.
eve::Result< void > setWheelSpinMotor(bool enabled, float speed, float maxTorque) override
setWheelSpinMotor; see the class lifetime, validation and failure contract.
eve::Result< void > setDistanceLength(float length) override
setDistanceLength; see the class lifetime, validation and failure contract.
eve::Result< void > setRevoluteMotor(bool enabled, float speed, float maxTorque) override
setRevoluteMotor; see the class lifetime, validation and failure contract.
eve::Result< float > getMotorAngularVelocityX() const override
getMotorAngularVelocityX; see the class lifetime, validation and failure contract.
eve::Result< void > setPrismaticMotor(bool enabled, float speed, float maxForce) override
setPrismaticMotor; see the class lifetime, validation and failure contract.
eve::Result< void > setMotorLinearSpring(float hertz, float dampingRatio, float maxForce) override
setMotorLinearSpring; see the class lifetime, validation and failure contract.
eve::Result< float > getConstraintForceZ() const override
getConstraintForceZ; see the class lifetime, validation and failure contract.
eve::Result< void > setRevoluteSpring(bool enabled, float targetAngle, float hertz, float dampingRatio) override
setRevoluteSpring; see the class lifetime, validation and failure contract.
eve::Result< float > getSphericalConeAngle() const override
getSphericalConeAngle; see the class lifetime, validation and failure contract.
eve::Result< float > getAngularSeparation() const override
getAngularSeparation; see the class lifetime, validation and failure contract.
eve::Result< void > setMotorLinearVelocity(float vx, float vy, float vz) override
setMotorLinearVelocity; see the class lifetime, validation and failure contract.
void destroy() noexcept override
Idempotently destroys the constraint; no failure or callbacks.
Definition JoltJoint.cpp:21
eve::Result< void > setSphericalConeLimit(bool enabled, float angle) override
setSphericalConeLimit; see the class lifetime, validation and failure contract.
eve::Result< float > getMotorAngularVelocityZ() const override
getMotorAngularVelocityZ; see the class lifetime, validation and failure contract.
eve::Result< JointFrames3D > localFrames() const override
localFrames; see the class lifetime, validation and failure contract.
Definition JoltJoint.cpp:60
eve::Result< float > getDistanceLength() const override
getDistanceLength; see the class lifetime, validation and failure contract.
eve::Result< float > getWeldAngularDampingRatio() const override
getWeldAngularDampingRatio; see the class lifetime, validation and failure contract.
void invalidate() noexcept override
Detaches before the parent destroys its constraints; no failure or callbacks.
Definition JoltJoint.cpp:20
eve::Result< void > setTorqueThreshold(float threshold) override
setTorqueThreshold; see the class lifetime, validation and failure contract.
eve::Result< float > getPrismaticTranslation() const override
getPrismaticTranslation; see the class lifetime, validation and failure contract.
eve::Result< float > getConstraintForceX() const override
getConstraintForceX; see the class lifetime, validation and failure contract.
eve::Result< float > getWheelSteeringAngle() const override
getWheelSteeringAngle; see the class lifetime, validation and failure contract.
eve::Result< float > getParallelDampingRatio() const override
getParallelDampingRatio; see the class lifetime, validation and failure contract.
eve::Result< void > setDistanceSpring(bool enabled, float hertz, float dampingRatio) override
setDistanceSpring; see the class lifetime, validation and failure contract.
eve::Result< void > setPrismaticSpring(bool enabled, float targetTranslation, float hertz, float dampingRatio) override
setPrismaticSpring; see the class lifetime, validation and failure contract.
eve::Result< void > setDistanceMotor(bool enabled, float speed, float maxForce) override
setDistanceMotor; see the class lifetime, validation and failure contract.
eve::Result< float > getSphericalTwistAngle() const override
getSphericalTwistAngle; see the class lifetime, validation and failure contract.
eve::Result< void > setCollideConnected(bool collide) override
setCollideConnected; see the class lifetime, validation and failure contract.
Definition JoltJoint.cpp:64
eve::Result< float > getPrismaticMotorForce() const override
getPrismaticMotorForce; see the class lifetime, validation and failure contract.
eve::Result< float > getDistanceCurrentLength() const override
getDistanceCurrentLength; see the class lifetime, validation and failure contract.
eve::Result< void > setDistanceLimits(bool enabled, float minimum, float maximum) override
setDistanceLimits; see the class lifetime, validation and failure contract.
bool isValid() const noexcept override
Whether the native constraint is still alive.
Definition JoltJoint.cpp:14
eve::Result< void > setPrismaticLimits(bool enabled, float lower, float upper) override
setPrismaticLimits; see the class lifetime, validation and failure contract.
eve::Result< float > getWheelSteeringTorque() const override
getWheelSteeringTorque; see the class lifetime, validation and failure contract.
JointBackend(std::shared_ptr< JointState > value)
Definition JoltJoint.h:28
eve::Result< void > setWeldAngularSpring(float hertz, float dampingRatio) override
setWeldAngularSpring; see the class lifetime, validation and failure contract.
eve::Result< void > setWheelSteeringLimits(bool enabled, float lower, float upper) override
setWheelSteeringLimits; see the class lifetime, validation and failure contract.
eve::Result< float > getConstraintTorqueY() const override
getConstraintTorqueY; see the class lifetime, validation and failure contract.
eve::Result< float > getParallelMaxTorque() const override
getParallelMaxTorque; see the class lifetime, validation and failure contract.
eve::Result< void > setWheelSuspensionLimits(bool enabled, float lower, float upper) override
setWheelSuspensionLimits; see the class lifetime, validation and failure contract.
eve::Result< void > setParallelSpring(float hertz, float dampingRatio, float maxTorque) override
setParallelSpring; see the class lifetime, validation and failure contract.
eve::Result< float > getMotorLinearVelocityZ() const override
getMotorLinearVelocityZ; see the class lifetime, validation and failure contract.
eve::Result< void > setWheelSuspension(bool enabled, float hertz, float dampingRatio) override
setWheelSuspension; see the class lifetime, validation and failure contract.
eve::Result< float > getRevoluteMotorTorque() const override
getRevoluteMotorTorque; see the class lifetime, validation and failure contract.
eve::Result< float > getWheelSpinSpeed() const override
getWheelSpinSpeed; see the class lifetime, validation and failure contract.
eve::Result< void > setWheelSteering(bool enabled, float targetAngle, float hertz, float dampingRatio, float maxTorque) override
setWheelSteering; see the class lifetime, validation and failure contract.
eve::Result< float > getRevoluteAngle() const override
getRevoluteAngle; see the class lifetime, validation and failure contract.
eve::Result< float > getForceThreshold() const override
getForceThreshold; see the class lifetime, validation and failure contract.
eve::Result< float > getMotorAngularVelocityY() const override
getMotorAngularVelocityY; see the class lifetime, validation and failure contract.
eve::Result< float > getLinearSeparation() const override
getLinearSeparation; see the class lifetime, validation and failure contract.
eve::Result< void > setMotorVelocityLimits(float maxForce, float maxTorque) override
setMotorVelocityLimits; see the class lifetime, validation and failure contract.
eve::Result< float > getMotorLinearVelocityX() const override
getMotorLinearVelocityX; see the class lifetime, validation and failure contract.
eve::Result< void > setRevoluteLimits(bool enabled, float lower, float upper) override
setRevoluteLimits; see the class lifetime, validation and failure contract.
eve::Result< float > getConstraintForceY() const override
getConstraintForceY; see the class lifetime, validation and failure contract.
eve::Result< void > setSphericalMotor(bool enabled, float velocityX, float velocityY, float velocityZ, float maxTorque) override
setSphericalMotor; see the class lifetime, validation and failure contract.
eve::Result< float > getWeldAngularHertz() const override
getWeldAngularHertz; see the class lifetime, validation and failure contract.
eve::Result< float > getMotorLinearVelocityY() const override
getMotorLinearVelocityY; see the class lifetime, validation and failure contract.
eve::Result< float > getConstraintTorqueZ() const override
getConstraintTorqueZ; see the class lifetime, validation and failure contract.
eve::Result< float > getParallelHertz() const override
getParallelHertz; see the class lifetime, validation and failure contract.
eve::Result< void > setMotorAngularVelocity(float wx, float wy, float wz) override
setMotorAngularVelocity; see the class lifetime, validation and failure contract.
eve::Result< void > setMotorAngularSpring(float hertz, float dampingRatio, float maxTorque) override
setMotorAngularSpring; see the class lifetime, validation and failure contract.
void bindOwner(Joint3D &) noexcept override
Binds its exclusive facade owner for internal attribution, on the simulation thread....
Definition JoltJoint.cpp:13
eve::Result< float > getPrismaticSpeed() const override
getPrismaticSpeed; see the class lifetime, validation and failure contract.
eve::Result< float > getWeldLinearHertz() const override
getWeldLinearHertz; see the class lifetime, validation and failure contract.
eve::Result< void > setWeldLinearSpring(float hertz, float dampingRatio) override
setWeldLinearSpring; see the class lifetime, validation and failure contract.
void notifyJointShapeChanged(State &state, JPH::BodyID id, JPH::Vec3Arg delta)
Recomputes constraint COM offsets after a successful native shape replacement.
JPH::uint64 pairKey(JPH::BodyID a, JPH::BodyID b)
Counts suppression references for one native pair; sequence numbers prevent reuse aliases.
Definition JoltJoint.cpp:8
JointKind3D
Stable constraint kinds; numeric values are used by stress events.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
bool enabled
Owning joint frames: local XYZ position followed by quaternion XYZW for each body.
std::weak_ptr< BodyState > a
Definition JoltJoint.h:13
std::weak_ptr< BodyState > b
Definition JoltJoint.h:13
JPH::Ref< JPH::TwoBodyConstraint > native
Definition JoltJoint.h:14
JPH::Ref< JPH::SixDOFConstraint > velocity
Definition JoltJoint.h:15
std::weak_ptr< State > world
Definition JoltJoint.h:12