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_WHEEL_JOINT_H |
22 | #define LOVE_PHYSICS_BOX2D_WHEEL_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 | * WheelJoints provide two degrees of freedom: translation |
36 | * along a defined axis and rotation in the plane. Designed |
37 | * for vehicle suspensions. |
38 | **/ |
39 | class WheelJoint : public Joint |
40 | { |
41 | public: |
42 | |
43 | static love::Type type; |
44 | |
45 | /** |
46 | * Creates a new WheelJoint connecting body1 and body2. |
47 | **/ |
48 | WheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); |
49 | |
50 | virtual ~WheelJoint(); |
51 | |
52 | /** |
53 | * Get the current joint translation, usually in meters. |
54 | **/ |
55 | float getJointTranslation() const; |
56 | |
57 | /** |
58 | * Get the current joint translation speed, usually in meters per second. |
59 | **/ |
60 | float getJointSpeed() const; |
61 | |
62 | /** |
63 | * Enable/disable the joint motor. |
64 | **/ |
65 | void setMotorEnabled(bool enable); |
66 | |
67 | /** |
68 | * Checks whether the motor is enabled. |
69 | **/ |
70 | bool isMotorEnabled() const; |
71 | |
72 | /** |
73 | * Set the motor speed, usually in meters per second. |
74 | **/ |
75 | void setMotorSpeed(float speed); |
76 | |
77 | /** |
78 | * Get the motor speed, usually in meters per second. |
79 | **/ |
80 | float getMotorSpeed() const; |
81 | |
82 | /** |
83 | * Set the maximum motor torque, usually in N. |
84 | **/ |
85 | void setMaxMotorTorque(float torque); |
86 | |
87 | /** |
88 | * Get the maximum motor torque, usually in N. |
89 | **/ |
90 | float getMaxMotorTorque() const; |
91 | |
92 | /** |
93 | * Get the current motor torque, usually in N. |
94 | * @param inv_dt The inverse time step. |
95 | **/ |
96 | float getMotorTorque(float inv_dt) const; |
97 | |
98 | /** |
99 | * Set the spring frequency, in hertz. Setting the frequency to 0 |
100 | * disables the spring. |
101 | **/ |
102 | void setSpringFrequency(float hz); |
103 | |
104 | /** |
105 | * Get the spring frequency, in hertz. |
106 | **/ |
107 | float getSpringFrequency() const; |
108 | |
109 | /** |
110 | * Set the spring damping ratio. |
111 | **/ |
112 | void setSpringDampingRatio(float ratio); |
113 | |
114 | /** |
115 | * Get the spring damping ratio. |
116 | **/ |
117 | float getSpringDampingRatio() const; |
118 | |
119 | /** |
120 | * Gets the axis unit vector, relative to body1. |
121 | * @returns The X component of the axis unit vector. |
122 | * @returns The Y component of the axis unit vector. |
123 | **/ |
124 | int getAxis(lua_State *L); |
125 | |
126 | private: |
127 | |
128 | // The Box2D wheel joint object. |
129 | b2WheelJoint *joint; |
130 | }; |
131 | |
132 | } // box2d |
133 | } // physics |
134 | } // love |
135 | |
136 | #endif // LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H |
137 | |