1 /**
2 * Copyright (c) 2006-2011 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_JOINT_H
22 #define LOVE_PHYSICS_BOX2D_JOINT_H
23 
24 // LOVE
25 #include <common/runtime.h>
26 #include <physics/Joint.h>
27 
28 // Box2D
29 #include "Include/Box2D.h"
30 
31 namespace love
32 {
33 namespace physics
34 {
35 namespace box2d
36 {
37 	// Forward declarations.
38 	class Body;
39 	class World;
40 
41 	/**
42 	* A Joint acts as positioning constraints on Bodies.
43 	* A Joint can be used to prevent Bodies from going to
44 	* far apart, or coming too close together.
45 	**/
46 	class Joint : public love::physics::Joint
47 	{
48 		friend class GearJoint;
49 
50 	private:
51 
52 		// A Joint must be destroyed *before* the bodies it acts upon,
53 		// and the world they reside in. We therefore need refs
54 		// parents and associations to prevent wrong destruction order.
55 		Body * body1, * body2;
56 
57 
58 		// The Box2D joint object.
59 		b2Joint * joint;
60 
61 	protected:
62 		World * world;
63 
64 	public:
65 
66 		/**
67 		* This constructor will connect one end of the joint to body1,
68 		* and the other one to the default ground body.
69 		*
70 		* This constructor is mainly used by MouseJoint.
71 		**/
72 		Joint(Body * body1);
73 
74 		/**
75 		* Create a joint between body1 and body2.
76 		**/
77 		Joint(Body * body1, Body * body2);
78 
79 		virtual ~Joint();
80 
81 		/**
82 		* Gets the type of joint.
83 		**/
84 		Type getType() const;
85 
86 		/**
87 		* Gets the anchor positions of the Joint in world
88 		* coordinates. This is useful for debugdrawing the joint.
89 		**/
90 		int getAnchors(lua_State * L);
91 
92 		/**
93 		* Gets the reaction force on body2 at the joint anchor.
94 		**/
95 		int getReactionForce(lua_State * L);
96 
97 		/**
98 		* Gets the reaction torque on body2.
99 		**/
100 		float getReactionTorque();
101 
102 		/**
103 		* Sets whether connected bodies should collide
104 		* or not. Default is false.
105 		**/
106 		void setCollideConnected(bool collide);
107 
108 		/**
109 		* Gets whether connected bodies should collide
110 		* or not.
111 		**/
112 		bool getCollideConnected() const;
113 
114 	protected:
115 
116 		/**
117 		* Joints require pointers to a Box2D joint objects at
118 		* different polymorphic levels, which is why these function
119 		* were created.
120 		**/
121 
122 		/**
123 		* Creates a Joint, and ensures that the parent class
124 		* gets a copy of the pointer.
125 		**/
126 		b2Joint * createJoint(b2JointDef * def);
127 
128 		/**
129 		* Destroys the joint. This function was created just to
130 		* get some cinsistency.
131 		**/
132 		void destroyJoint(b2Joint * joint);
133 	};
134 
135 } // box2d
136 } // physics
137 } // love
138 
139 #endif // LOVE_PHYSICS_BOX2D_JOINT_H
140