1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H |
22 | #define LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H |
23 | |
24 | // Module |
25 | #include "Joint.h" |
26 | |
27 | namespace love |
28 | { |
29 | namespace physics |
30 | { |
31 | namespace box2d |
32 | { |
33 | |
34 | /** |
35 | * A RevoluteJoint allows two bodies relative rotation |
36 | * around a single point. |
37 | **/ |
38 | class RevoluteJoint : public Joint |
39 | { |
40 | public: |
41 | |
42 | static love::Type type; |
43 | |
44 | /** |
45 | * Creates a new RevoluteJoint connecting body1 and body2. |
46 | **/ |
47 | RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected); |
48 | |
49 | RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected, float referenceAngle); |
50 | |
51 | virtual ~RevoluteJoint(); |
52 | |
53 | /** |
54 | * Get the current joint angle in degrees. |
55 | **/ |
56 | float getJointAngle() const; |
57 | |
58 | /** |
59 | * Get the current joint angle speed in degrees per second. |
60 | **/ |
61 | float getJointSpeed() const; |
62 | |
63 | /** |
64 | * Enable/disable the joint motor. |
65 | **/ |
66 | void setMotorEnabled(bool enable); |
67 | |
68 | /** |
69 | * Checks whether the motor is enabled. |
70 | **/ |
71 | bool isMotorEnabled() const; |
72 | |
73 | /** |
74 | * Set the maximum motor torque, usually in N-m. |
75 | **/ |
76 | void setMaxMotorTorque(float torque); |
77 | |
78 | /** |
79 | * Sets the motor speed in radians per second. |
80 | **/ |
81 | void setMotorSpeed(float speed); |
82 | |
83 | /** |
84 | * Gets the motor speed in radians per second. |
85 | **/ |
86 | float getMotorSpeed() const; |
87 | |
88 | /** |
89 | * Get the current motor torque, usually in N-m. |
90 | * @param inv_dt The inverse timestep. |
91 | **/ |
92 | float getMotorTorque(float inv_dt) const; |
93 | |
94 | /** |
95 | * Get the maximum motor torque, usually in N-m. |
96 | **/ |
97 | float getMaxMotorTorque() const; |
98 | |
99 | /** |
100 | * Enable/disable the joint limit. |
101 | **/ |
102 | void setLimitsEnabled(bool enable); |
103 | |
104 | /** |
105 | * Checks whether limits are enabled. |
106 | **/ |
107 | bool areLimitsEnabled() const; |
108 | |
109 | /** |
110 | * Sets the upper limit in degrees. |
111 | **/ |
112 | void setUpperLimit(float limit); |
113 | |
114 | /** |
115 | * Sets the lower limit in degrees. |
116 | **/ |
117 | void setLowerLimit(float limit); |
118 | |
119 | /** |
120 | * Sets the limits in degrees. |
121 | **/ |
122 | void setLimits(float lower, float upper); |
123 | |
124 | /** |
125 | * Gets the lower limit in degrees. |
126 | **/ |
127 | float getLowerLimit() const; |
128 | |
129 | /** |
130 | * Gets the upper limit in degrees. |
131 | **/ |
132 | float getUpperLimit() const; |
133 | |
134 | /** |
135 | * Gets the limits in degrees. |
136 | * @returns The lower limit. |
137 | * @returns The upper limit. |
138 | **/ |
139 | int getLimits(lua_State *L); |
140 | |
141 | /** |
142 | * Gets the reference angle. |
143 | **/ |
144 | float getReferenceAngle() const; |
145 | |
146 | private: |
147 | |
148 | // The Box2D revolute joint object. |
149 | b2RevoluteJoint *joint; |
150 | |
151 | void init(b2RevoluteJointDef &def, Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected); |
152 | }; |
153 | |
154 | } // box2d |
155 | } // physics |
156 | } // love |
157 | |
158 | #endif // LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H |
159 | |