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 #include "MouseJoint.h"
22 
23 // Module
24 #include "Body.h"
25 #include "World.h"
26 
27 namespace love
28 {
29 namespace physics
30 {
31 namespace box2d
32 {
MouseJoint(Body * body1,float x,float y)33 	MouseJoint::MouseJoint(Body * body1, float x, float y)
34 		: Joint(body1), joint(NULL)
35 	{
36 		b2MouseJointDef def;
37 
38 		def.body1 = body1->world->world->GetGroundBody();
39 		def.body2 = body1->body;
40 		def.maxForce = 1000.0f * body1->body->GetMass();
41 		def.target = body1->world->scaleDown(b2Vec2(x,y));
42 		joint = (b2MouseJoint*)createJoint(&def);
43 	}
44 
~MouseJoint()45 	MouseJoint::~MouseJoint()
46 	{
47 		destroyJoint(joint);
48 		joint = 0;
49 	}
50 
setTarget(float x,float y)51 	void MouseJoint::setTarget(float x, float y)
52 	{
53 		joint->SetTarget(world->scaleDown(b2Vec2(x, y)));
54 	}
55 
getTarget(lua_State * L)56 	int MouseJoint::getTarget(lua_State * L)
57 	{
58 		lua_pushnumber(L, world->scaleUp(joint->m_target.x));
59 		lua_pushnumber(L, world->scaleUp(joint->m_target.y));
60 		return 2;
61 	}
62 
setMaxForce(float force)63 	void MouseJoint::setMaxForce(float force)
64 	{
65 		joint->m_maxForce = force;
66 	}
67 
getMaxForce() const68 	float MouseJoint::getMaxForce() const
69 	{
70 		return joint->m_maxForce;
71 	}
72 
73 } // box2d
74 } // physics
75 } // love
76