载入中...
搜索中...
未找到
Joint3D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6
7#include <box3d/id.h>
8
9#include <string>
10
11namespace eve::physics {
12
13class Body3D;
14class World3D;
15
18public:
24 enum class Kind { Distance, Revolute, Prismatic, Spherical, Wheel, Weld, Motor, Parallel, Filter };
25
27 Joint3D(World3D *world, Body3D *bodyA, Body3D *bodyB, b3JointId jointId, PhysicsJointHandle runtimeHandle,
28 Kind kind, int id);
29 ~Joint3D();
30
31 Joint3D(const Joint3D &) = delete;
32 Joint3D &operator=(const Joint3D &) = delete;
33
35 int getId() const { return id_; }
37 [[nodiscard]] PhysicsJointHandle runtimeHandle() const noexcept { return runtimeHandle_; }
39 std::string getKind() const;
41 int getBodyAId() const;
43 int getBodyBId() const;
45 [[nodiscard]] World3D *getWorld() const noexcept { return world_; }
47 void setCollideConnected(bool collide);
49 bool getCollideConnected() const;
51 void setForceThreshold(float threshold);
53 float getForceThreshold() const;
55 void setTorqueThreshold(float threshold);
57 float getTorqueThreshold() const;
58
60 float getConstraintForceX() const;
62 float getConstraintForceY() const;
64 float getConstraintForceZ() const;
66 float getConstraintTorqueX() const;
68 float getConstraintTorqueY() const;
70 float getConstraintTorqueZ() const;
72 float getLinearSeparation() const;
74 float getAngularSeparation() const;
75
77 void setDistanceLength(float length);
79 float getDistanceLength() const;
81 float getDistanceCurrentLength() const;
83 void setDistanceSpring(bool enabled, float hertz, float dampingRatio);
85 void setDistanceLimits(bool enabled, float minimum, float maximum);
87 void setDistanceMotor(bool enabled, float speed, float maxForce);
88
90 void setRevoluteSpring(bool enabled, float targetAngle, float hertz, float dampingRatio);
92 void setRevoluteLimits(bool enabled, float lower, float upper);
94 void setRevoluteMotor(bool enabled, float speed, float maxTorque);
96 float getRevoluteAngle() const;
98 float getRevoluteMotorTorque() const;
99
101 void setPrismaticSpring(bool enabled, float targetTranslation, float hertz,
102 float dampingRatio);
104 void setPrismaticLimits(bool enabled, float lower, float upper);
106 void setPrismaticMotor(bool enabled, float speed, float maxForce);
108 float getPrismaticTranslation() const;
110 float getPrismaticSpeed() const;
112 float getPrismaticMotorForce() const;
113
115 void setSphericalConeLimit(bool enabled, float angle);
117 void setSphericalTwistLimits(bool enabled, float lower, float upper);
119 void setSphericalMotor(bool enabled, float velocityX, float velocityY, float velocityZ,
120 float maxTorque);
122 float getSphericalConeAngle() const;
124 float getSphericalTwistAngle() const;
125
127 void setWheelSuspension(bool enabled, float hertz, float dampingRatio);
129 void setWheelSuspensionLimits(bool enabled, float lower, float upper);
131 void setWheelSpinMotor(bool enabled, float speed, float maxTorque);
133 void setWheelSteering(bool enabled, float targetAngle, float hertz, float dampingRatio,
134 float maxTorque);
136 void setWheelSteeringLimits(bool enabled, float lower, float upper);
138 float getWheelSpinSpeed() const;
140 float getWheelSpinTorque() const;
142 float getWheelSteeringAngle() const;
144 float getWheelSteeringTorque() const;
145
147 void setWeldLinearSpring(float hertz, float dampingRatio);
149 void setWeldAngularSpring(float hertz, float dampingRatio);
151 float getWeldLinearHertz() const;
153 float getWeldLinearDampingRatio() const;
155 float getWeldAngularHertz() const;
157 float getWeldAngularDampingRatio() const;
158
160 void setMotorLinearVelocity(float vx, float vy, float vz);
162 void setMotorAngularVelocity(float wx, float wy, float wz);
164 void setMotorVelocityLimits(float maxForce, float maxTorque);
166 void setMotorLinearSpring(float hertz, float dampingRatio, float maxForce);
168 void setMotorAngularSpring(float hertz, float dampingRatio, float maxTorque);
170 float getMotorLinearVelocityX() const;
172 float getMotorLinearVelocityY() const;
174 float getMotorLinearVelocityZ() const;
176 float getMotorAngularVelocityX() const;
178 float getMotorAngularVelocityY() const;
180 float getMotorAngularVelocityZ() const;
181
183 void setParallelSpring(float hertz, float dampingRatio, float maxTorque);
185 float getParallelHertz() const;
187 float getParallelDampingRatio() const;
189 float getParallelMaxTorque() const;
190
192 void destroy();
194 bool isValid() const;
196 void invalidate();
198 b3JointId raw() const { return jointId_; }
199
200private:
201 friend struct WorldSnapshotAccess;
202 friend class Body3D;
203 friend class World3D;
204 void requireKind(Kind expected, const char *operation) const;
205
206 World3D *world_ = nullptr;
207 Body3D *bodyA_ = nullptr;
208 Body3D *bodyB_ = nullptr;
209 b3JointId jointId_{};
210 PhysicsJointHandle runtimeHandle_ = PhysicsJointHandle::invalid();
211 Kind kind_ = Kind::Distance;
212 int id_ = 0;
213};
214
215} // namespace eve::physics
ActionParameterOperation operation
float length
Definition CaveMesh.cpp:94
#define EVENGINE_API_WORLD
Definition Export.h:109
float maximum[3]
float minimum[3]
void(* destroy)(void *)
TokenKind kind
World3D * world
Process-local, generation-qualified handles owned by the physics domain.
float vz
float wz
float wx
float vy
float vx
float angle
float wy
3D rigid body (Box3D) in meter-space coordinates (+Y up by convention). Owned by a World3D; create pr...
Definition Body3D.h:24
Script-facing Box3D joint owned by a World3D.
Definition Joint3D.h:17
float getConstraintForceX() const
Current world-space constraint force X in newtons.
float getConstraintForceY() const
Current world-space constraint force Y in newtons.
Kind
Supported joint geometry.
Definition Joint3D.h:24
Joint3D(const Joint3D &)=delete
PhysicsJointHandle runtimeHandle() const noexcept
Process-local generation-qualified handle owned by World3D.
Definition Joint3D.h:37
float getConstraintTorqueZ() const
Current world-space constraint torque Z in newton-metres.
b3JointId raw() const
Internal raw Box3D identifier.
Definition Joint3D.h:198
int getId() const
Stable world-local identifier.
Definition Joint3D.h:35
float getConstraintTorqueX() const
Current world-space constraint torque X in newton-metres.
float getConstraintForceZ() const
Current world-space constraint force Z in newtons.
float getConstraintTorqueY() const
Current world-space constraint torque Y in newton-metres.
World3D * getWorld() const noexcept
Owning world, or null after joint destruction.
Definition Joint3D.h:45
Joint3D & operator=(const Joint3D &)=delete
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
bool enabled