载入中...
搜索中...
未找到
Joint2D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Result.h"
6
7#include <array>
8#include <memory>
9
10class b2Joint;
11namespace eve::physics {
12class World;
13class Body;
14
17
20 float x = 0, y = 0;
21};
22
39
48
59public:
62 std::string getKind() const;
64 int getBodyAId() const;
66 int getBodyBId() const;
73 World *getWorld() const { return world_; }
75 void setCollideConnected(bool collide);
77 bool getCollideConnected() const;
78
80 void setDistanceLength(float lengthPixels);
82 float getDistanceLength() const;
84 void setDistanceSpring(float frequencyHz, float dampingRatio);
86 float getDistanceFrequency() const;
88 float getDistanceDampingRatio() const;
89
91 void setRevoluteLimits(bool enabled, float lower, float upper);
93 void setRevoluteMotor(bool enabled, float speed, float maxTorque);
95 float getRevoluteAngle() const;
97 float getRevoluteSpeed() const;
99 float getRevoluteMotorTorque() const;
100
102 void setPrismaticLimits(bool enabled, float lowerPixels, float upperPixels);
104 void setPrismaticMotor(bool enabled, float speedPixels, float maxForcePixels);
106 float getPrismaticTranslation() const;
108 float getPrismaticSpeed() const;
109
111 void setWeldSpring(float frequencyHz, float dampingRatio);
113 float getWeldFrequency() const;
115 float getWeldDampingRatio() const;
116
118 void setWheelSpring(float frequencyHz, float dampingRatio);
120 void setWheelMotor(bool enabled, float speed, float maxTorque);
122 float getWheelTranslation() const;
124 float getWheelSpeed() const;
125
127 void setMotorLinearOffset(float xPixels, float yPixels);
129 void setMotorAngularOffset(float radians);
131 void setMotorLimits(float maxForcePixels, float maxTorque);
133 float getMotorLinearOffsetX() const;
135 float getMotorLinearOffsetY() const;
137 float getMotorAngularOffset() const;
138
140 void setGearRatio(float ratio);
142 float getGearRatio() const;
149 Joint2D* getGearJoint1() const;
156 Joint2D* getGearJoint2() const;
157
158
160 b2Joint *raw() const { return joint_; }
162 void destroy();
164 ~Joint2D();
165 Joint2D(const Joint2D&) = delete;
166 Joint2D& operator=(const Joint2D&) = delete;
167
171 [[nodiscard]] static Result<std::unique_ptr<Joint2D>> create(World& world, Body& a, Body& b,
177 [[nodiscard]] static Result<std::unique_ptr<Joint2D>> createGear(World& world, Joint2D& first, Joint2D& second,
178 float ratio);
180 [[nodiscard]] bool isValid() const noexcept;
182 [[nodiscard]] PhysicsJointHandle runtimeHandle() const noexcept { return handle_; }
184 [[nodiscard]] int getId() const noexcept { return id_; }
186 [[nodiscard]] Joint2DKind kind() const noexcept { return kind_; }
191 [[nodiscard]] Result<void> setMotor(bool enabled, float speed, float maximumForce);
195 [[nodiscard]] Result<void> setLimits(bool enabled, float lower, float upper);
199 [[nodiscard]] Result<Joint2DState> sample(float dt) const;
203 [[nodiscard]] Result<void> destroyChecked();
204
205private:
206 friend class Body;
207 friend class Mechanism2D;
208 void requireKind(Kind expected, const char *operation) const;
209 friend class World;
210 friend struct WorldSnapshotAccess;
211 friend struct PhysicsJointLink;
212 Joint2D(World& world, b2Joint& joint, Joint2DKind kind, PhysicsJointHandle handle);
213 void release();
214 void invalidate() noexcept;
215 int id_ = 0;
216 // Immutable constructor inputs for backend constants without public getters.
217 std::array<float, 12> gearReferencePoses_{};
218 JointPoint2D pulleyLocalA_, pulleyLocalB_;
219 World* world_ = nullptr;
220 b2Joint* joint_ = nullptr;
221 Joint2DKind kind_;
222 PhysicsJointHandle handle_;
223 PhysicsJointHandle firstSource_ = PhysicsJointHandle::invalid();
224 PhysicsJointHandle secondSource_ = PhysicsJointHandle::invalid();
225};
226} // namespace eve::physics
ActionParameterOperation operation
#define EVENGINE_API_WORLD
Definition Export.h:109
std::int32_t second
std::int32_t first
void(* destroy)(void *)
float ratio
float dampingRatio
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
OceanWakeSettings settings
double dt
Process-local, generation-qualified handles owned by the physics domain.
PrimitiveHandle handle
Move-only, checked operation results for the common layer.
std::string kind
Move-only operation result carrying either a value or Status.
Definition Result.h:176
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFi...
Definition Body.h:21
Owning planar joint wrapper observing World-owned backend state. @ownership Caller/VM owns factory wr...
Definition Joint2D.h:58
int getId() const noexcept
World-local persistent topology id, retained after invalidation; not a runtime handle.
Definition Joint2D.h:184
b2Joint * raw() const
Internal borrowed solver joint; valid only while this wrapper is valid.
Definition Joint2D.h:160
Joint2DKind kind() const noexcept
Constraint kind, unchanged after invalidation.
Definition Joint2D.h:186
World * getWorld() const
Owning world, or null after joint destruction.
Definition Joint2D.h:73
Joint2D & operator=(const Joint2D &)=delete
Joint2D(const Joint2D &)=delete
Composed 2D mechanical assembly owned by a World.
Definition Mechanism2D.h:25
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity,...
Definition World.h:44
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
Joint2DKind
Closed set of planar mechanical constraints. Gear couples two existing joints.
Definition Joint2D.h:16
bool enabled
Validated-at-creation joint parameters; all lengths are meters, angles radians.
Definition Joint2D.h:30
Owning solver observation. Coordinate is angle/radians or translation/meters by kind.
Definition Joint2D.h:41
float coordinate
Distance length, revolute angle, prismatic/wheel translation, or gear ratio.
Definition Joint2D.h:45
float secondaryCoordinate
Pulley segment B; coordinate is pulley segment A.
Definition Joint2D.h:46
JointPoint2D reactionForce
Definition Joint2D.h:43
Owning world-space point/direction in SI (meters), not pixel coordinates.
Definition Joint2D.h:19