| 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_MOUSE_JOINT_H |
| 22 | #define LOVE_PHYSICS_BOX2D_MOUSE_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 | * The MouseJoint is a joint type that |
| 36 | * is suitable for controlling objects with the mouse. |
| 37 | * |
| 38 | * One end is anchored in the dynamic body, and the other id |
| 39 | * anchor to a static ground body. The anchor offset can then be |
| 40 | * moved to the current mouse position. |
| 41 | **/ |
| 42 | class MouseJoint : public Joint |
| 43 | { |
| 44 | public: |
| 45 | |
| 46 | static love::Type type; |
| 47 | |
| 48 | /** |
| 49 | * Creates a MouseJoint which connects body1 to the target point. |
| 50 | **/ |
| 51 | MouseJoint(Body *body1, float x, float y); |
| 52 | |
| 53 | virtual ~MouseJoint(); |
| 54 | |
| 55 | /** |
| 56 | * Sets the target of anchor2. (You usually want |
| 57 | * to set this to the current mouse.) |
| 58 | **/ |
| 59 | void setTarget(float x, float y); |
| 60 | |
| 61 | /** |
| 62 | * Gets the current anchor2 target. |
| 63 | **/ |
| 64 | int getTarget(lua_State *L); |
| 65 | |
| 66 | /** |
| 67 | * Sets the maximum constraint force that can be exerted |
| 68 | * to move the candidate body. |
| 69 | **/ |
| 70 | void setMaxForce(float force); |
| 71 | |
| 72 | /** |
| 73 | * Gets the maximum constraint force that can be exerted |
| 74 | * to move the candidate body. |
| 75 | **/ |
| 76 | float getMaxForce() const; |
| 77 | |
| 78 | /** |
| 79 | * Sets the response speed. |
| 80 | **/ |
| 81 | void setFrequency(float hz); |
| 82 | |
| 83 | /** |
| 84 | * Gets the response speed. |
| 85 | **/ |
| 86 | float getFrequency() const; |
| 87 | |
| 88 | /** |
| 89 | * Sets the damping ratio. |
| 90 | * 0 = no damping, 1 = critical damping. |
| 91 | **/ |
| 92 | void setDampingRatio(float d); |
| 93 | |
| 94 | /** |
| 95 | * Gets the damping ratio. |
| 96 | * 0 = no damping, 1 = critical damping. |
| 97 | **/ |
| 98 | float getDampingRatio() const; |
| 99 | |
| 100 | virtual Body *getBodyA() const; |
| 101 | virtual Body *getBodyB() const; |
| 102 | |
| 103 | private: |
| 104 | // The Box2D MouseJoint object. |
| 105 | b2MouseJoint *joint; |
| 106 | }; |
| 107 | |
| 108 | } // box2d |
| 109 | } // physics |
| 110 | } // love |
| 111 | |
| 112 | |
| 113 | #endif // LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H |
| 114 | |