载入中...
搜索中...
未找到
Mechanism2D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include <string>
5
6namespace eve::physics {
7
8class Body;
9class Joint2D;
10class World;
11
26public:
28 enum class Kind { CrankSlider, Shaft, Ratchet };
29
30 Mechanism2D(const Mechanism2D &) = delete;
31 Mechanism2D &operator=(const Mechanism2D &) = delete;
32
34 int getId() const { return id_; }
36 std::string getKind() const;
43 World *getWorld() const { return world_; }
45 bool isValid() const;
46
53 Joint2D *getDriveJoint() const { return drive_; }
60 Joint2D *getCrankPinJoint() const { return crankPin_; }
67 Joint2D *getSliderPinJoint() const { return sliderPin_; }
74 Joint2D *getSliderJoint() const { return slider_; }
75
77 float getDriveAngle() const;
79 float getSliderTranslation() const;
81 float getSpinSpeed() const;
82
88 void setDrive(float speed, float maxTorque);
90 void clearDrive();
92 bool isDriveEnabled() const { return driveEnabled_; }
93
95 void setRatchetDirection(int direction);
97 int getRatchetDirection() const { return ratchetDirection_; }
99 void setRatchetEngagementTorque(float torque);
101 float getRatchetEngagementTorque() const { return engagementTorque_; }
102
104 void destroy();
106 void invalidate();
108 void syncBeforeStep();
109
110 ~Mechanism2D();
111
112private:
113 friend class World;
114
115 Mechanism2D(World *world, Kind kind, int id, Joint2D *drive, Joint2D *crankPin, Joint2D *sliderPin,
116 Joint2D *slider, int ratchetDirection, float engagementTorque);
117
118 void requireKind(Kind expected, const char *operation) const;
119 float axisSpinSpeed() const;
120
121 World *world_ = nullptr;
122 Kind kind_ = Kind::Shaft;
123 int id_ = 0;
124 Joint2D *drive_ = nullptr;
125 Joint2D *crankPin_ = nullptr;
126 Joint2D *sliderPin_ = nullptr;
127 Joint2D *slider_ = nullptr;
128 bool driveEnabled_ = false;
129 float driveSpeed_ = 0.f;
130 float driveMaxTorque_ = 0.f;
131 int ratchetDirection_ = 1;
132 float engagementTorque_ = 0.f;
133};
134
135} // namespace eve::physics
ActionParameterOperation operation
#define EVENGINE_API_WORLD
Definition Export.h:109
void(* destroy)(void *)
TokenKind kind
World3D * world
RoadLaneDirection direction
Script-facing Box2D joint owned by a World.
Definition Joint2D.h:21
Composed 2D mechanical assembly owned by a World.
Definition Mechanism2D.h:25
Joint2D * getSliderJoint() const
Frame-to-slider prismatic, or null for shaft/ratchet.
Definition Mechanism2D.h:74
float getRatchetEngagementTorque() const
Current ratchet engagement torque in newton-metres.
int getRatchetDirection() const
Current ratchet freewheel direction (+1 or -1).
Definition Mechanism2D.h:97
Joint2D * getDriveJoint() const
Primary revolute (crank / shaft / ratchet wheel).
Definition Mechanism2D.h:53
int getId() const
Stable world-local identifier.
Definition Mechanism2D.h:34
Mechanism2D & operator=(const Mechanism2D &)=delete
Joint2D * getCrankPinJoint() const
Crank-to-rod revolute, or null for shaft/ratchet.
Definition Mechanism2D.h:60
Joint2D * getSliderPinJoint() const
Rod-to-slider revolute, or null for shaft/ratchet.
Definition Mechanism2D.h:67
Mechanism2D(const Mechanism2D &)=delete
bool isDriveEnabled() const
Whether a continuous drive motor is configured.
Definition Mechanism2D.h:92
World * getWorld() const
Owning world, or null after invalidation.
Definition Mechanism2D.h:43
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