载入中...
搜索中...
未找到
Joint2D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
5
6#include <string>
7
8class b2Joint;
9
10namespace eve::physics {
11
12class Body;
13class World;
14
22public:
27 enum class Kind { Distance, Revolute, Prismatic, Weld, Wheel, Motor, Gear };
28
30 Joint2D(World *world, Body *bodyA, Body *bodyB, b2Joint *joint, PhysicsJointHandle runtimeHandle,
31 Kind kind, int id);
32 ~Joint2D();
33
34 Joint2D(const Joint2D &) = delete;
35 Joint2D &operator=(const Joint2D &) = delete;
36
38 int getId() const { return id_; }
40 PhysicsJointHandle runtimeHandle() const { return runtimeHandle_; }
42 std::string getKind() const;
44 int getBodyAId() const;
46 int getBodyBId() const;
53 World *getWorld() const { return world_; }
55 void setCollideConnected(bool collide);
57 bool getCollideConnected() const;
58
60 void setDistanceLength(float lengthPixels);
62 float getDistanceLength() const;
64 void setDistanceSpring(float frequencyHz, float dampingRatio);
66 float getDistanceFrequency() const;
68 float getDistanceDampingRatio() const;
69
71 void setRevoluteLimits(bool enabled, float lower, float upper);
73 void setRevoluteMotor(bool enabled, float speed, float maxTorque);
75 float getRevoluteAngle() const;
77 float getRevoluteSpeed() const;
79 float getRevoluteMotorTorque() const;
80
82 void setPrismaticLimits(bool enabled, float lowerPixels, float upperPixels);
84 void setPrismaticMotor(bool enabled, float speedPixels, float maxForcePixels);
86 float getPrismaticTranslation() const;
88 float getPrismaticSpeed() const;
89
91 void setWeldSpring(float frequencyHz, float dampingRatio);
93 float getWeldFrequency() const;
95 float getWeldDampingRatio() const;
96
98 void setWheelSpring(float frequencyHz, float dampingRatio);
100 void setWheelMotor(bool enabled, float speed, float maxTorque);
102 float getWheelTranslation() const;
104 float getWheelSpeed() const;
105
107 void setMotorLinearOffset(float xPixels, float yPixels);
109 void setMotorAngularOffset(float radians);
111 void setMotorLimits(float maxForcePixels, float maxTorque);
113 float getMotorLinearOffsetX() const;
115 float getMotorLinearOffsetY() const;
117 float getMotorAngularOffset() const;
118
120 void setGearRatio(float ratio);
122 float getGearRatio() const;
129 Joint2D *getGearJoint1() const { return gearJoint1_; }
136 Joint2D *getGearJoint2() const { return gearJoint2_; }
137
139 void destroy();
141 bool isValid() const;
143 void invalidate();
145 b2Joint *raw() const { return joint_; }
146
147private:
148 friend class Body;
149 friend class World;
150 friend class Mechanism2D;
151 void requireKind(Kind expected, const char *operation) const;
152 void setGearMembers(Joint2D *joint1, Joint2D *joint2);
153
154 World *world_ = nullptr;
155 Body *bodyA_ = nullptr;
156 Body *bodyB_ = nullptr;
157 b2Joint *joint_ = nullptr;
158 PhysicsJointHandle runtimeHandle_ = PhysicsJointHandle::invalid();
159 Kind kind_ = Kind::Distance;
160 int id_ = 0;
161 Joint2D *gearJoint1_ = nullptr;
162 Joint2D *gearJoint2_ = nullptr;
163};
164
165} // namespace eve::physics
ActionParameterOperation operation
#define EVENGINE_API_WORLD
Definition Export.h:109
void(* destroy)(void *)
TokenKind kind
World3D * world
Process-local, generation-qualified handles owned by the physics domain.
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFi...
Definition Body.h:21
Script-facing Box2D joint owned by a World.
Definition Joint2D.h:21
Joint2D * getGearJoint1() const
First joint linked by a gear, or null.
Definition Joint2D.h:129
b2Joint * raw() const
Internal raw Box2D joint.
Definition Joint2D.h:145
Joint2D * getGearJoint2() const
Second joint linked by a gear, or null.
Definition Joint2D.h:136
Kind
Supported joint geometry.
Definition Joint2D.h:27
World * getWorld() const
Owning world, or null after joint destruction.
Definition Joint2D.h:53
Joint2D & operator=(const Joint2D &)=delete
PhysicsJointHandle runtimeHandle() const
Process-local generation-qualified handle owned by World.
Definition Joint2D.h:40
int getId() const
Stable world-local identifier.
Definition Joint2D.h:38
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:41
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
bool enabled