| 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_PRISMATIC_JOINT_H |
| 22 | #define LOVE_PHYSICS_BOX2D_PRISMATIC_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 | * PrismaticJoints allow shapes to move in relation to eachother |
| 36 | * along a defined axis. |
| 37 | **/ |
| 38 | class PrismaticJoint : public Joint |
| 39 | { |
| 40 | public: |
| 41 | |
| 42 | static love::Type type; |
| 43 | |
| 44 | /** |
| 45 | * Creates a new PrismaticJoint connecting body1 and body2. |
| 46 | **/ |
| 47 | PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); |
| 48 | |
| 49 | PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected, float referenceAngle); |
| 50 | |
| 51 | virtual ~PrismaticJoint(); |
| 52 | |
| 53 | /** |
| 54 | * Get the current joint translation, usually in meters. |
| 55 | **/ |
| 56 | float getJointTranslation() const; |
| 57 | |
| 58 | /** |
| 59 | * Get the current joint translation speed, usually in meters 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 force, usually in N. |
| 75 | **/ |
| 76 | void setMaxMotorForce(float force); |
| 77 | |
| 78 | /** |
| 79 | * Set the motor speed, usually in meters per second. |
| 80 | **/ |
| 81 | void setMotorSpeed(float speed); |
| 82 | |
| 83 | /** |
| 84 | * Get the motor speed, usually in meters per second. |
| 85 | **/ |
| 86 | float getMotorSpeed() const; |
| 87 | |
| 88 | /** |
| 89 | * Get the current motor force, usually in N. |
| 90 | * @param inv_dt The inverse time step. |
| 91 | **/ |
| 92 | float getMotorForce(float inv_dt) const; |
| 93 | |
| 94 | /** |
| 95 | * Get the maximum motor force, usually in N. |
| 96 | **/ |
| 97 | float getMaxMotorForce() const; |
| 98 | |
| 99 | /** |
| 100 | * Enable/disable the joint limits. |
| 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, usually in meters. |
| 111 | **/ |
| 112 | void setUpperLimit(float limit); |
| 113 | |
| 114 | /** |
| 115 | * Sets the lower limit, usually in meters. |
| 116 | **/ |
| 117 | void setLowerLimit(float limit); |
| 118 | |
| 119 | /** |
| 120 | * Sets the limits, usually in meters. |
| 121 | **/ |
| 122 | void setLimits(float lower, float upper); |
| 123 | |
| 124 | /** |
| 125 | * Gets the lower limit, usually in meters. |
| 126 | **/ |
| 127 | float getLowerLimit() const; |
| 128 | |
| 129 | /** |
| 130 | * Gets the upper limit, usually in meters. |
| 131 | **/ |
| 132 | float getUpperLimit() const; |
| 133 | |
| 134 | /** |
| 135 | * Gets the limits, usually in meters. |
| 136 | * @returns The upper limit. |
| 137 | * @returns The lower limit. |
| 138 | **/ |
| 139 | int getLimits(lua_State *L); |
| 140 | |
| 141 | /** |
| 142 | * Gets the axis unit vector, relative to body1. |
| 143 | * @returns The X component of the axis unit vector. |
| 144 | * @returns The Y component of the axis unit vector. |
| 145 | **/ |
| 146 | int getAxis(lua_State *L); |
| 147 | |
| 148 | /** |
| 149 | * Gets the reference angle. |
| 150 | **/ |
| 151 | float getReferenceAngle() const; |
| 152 | |
| 153 | private: |
| 154 | |
| 155 | // The Box2D prismatic joint object. |
| 156 | b2PrismaticJoint *joint; |
| 157 | |
| 158 | void init(b2PrismaticJointDef &def, Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); |
| 159 | }; |
| 160 | |
| 161 | } // box2d |
| 162 | } // physics |
| 163 | } // love |
| 164 | |
| 165 | #endif // LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H |
| 166 | |