Commits

Bill Meltsner committed f6086d5

Added RopeJoint

Comments (0)

Files changed (9)

platform/macosx/love.xcodeproj/project.pbxproj

 		A9BD60741226C988007DEC63 /* Framebuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9BD60701226C988007DEC63 /* Framebuffer.cpp */; };
 		A9BD60751226C988007DEC63 /* wrap_Framebuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9BD60721226C988007DEC63 /* wrap_Framebuffer.cpp */; };
 		A9CF0E8610B9EB1000E6F37E /* utf8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9CF0E8510B9EB1000E6F37E /* utf8.cpp */; };
+		A9D1D20214224E1300A8BC2F /* RopeJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9D1D20114224E1300A8BC2F /* RopeJoint.cpp */; };
+		A9D1D2041422578C00A8BC2F /* wrap_RopeJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9D1D2031422578A00A8BC2F /* wrap_RopeJoint.cpp */; };
 		A9D307EA106635C3004FEDF8 /* physfs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9D307E9106635C3004FEDF8 /* physfs.framework */; };
 		A9D307F2106635D3004FEDF8 /* physfs.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9D307E9106635C3004FEDF8 /* physfs.framework */; };
 		A9DEC1C11046EFA70049C70C /* Love.icns in Resources */ = {isa = PBXBuildFile; fileRef = A9DEC1BF1046EFA60049C70C /* Love.icns */; };
 		A9BFAA851137C1CE005FE0AD /* ThreadModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadModule.h; sourceTree = "<group>"; };
 		A9CF0E8410B9EB1000E6F37E /* utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utf8.h; sourceTree = "<group>"; };
 		A9CF0E8510B9EB1000E6F37E /* utf8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utf8.cpp; sourceTree = "<group>"; };
+		A9D1D20014224DFF00A8BC2F /* RopeJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RopeJoint.h; sourceTree = "<group>"; };
+		A9D1D20114224E1300A8BC2F /* RopeJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RopeJoint.cpp; sourceTree = "<group>"; };
+		A9D1D2031422578A00A8BC2F /* wrap_RopeJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_RopeJoint.cpp; sourceTree = "<group>"; };
+		A9D1D2051422579500A8BC2F /* wrap_RopeJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_RopeJoint.h; sourceTree = "<group>"; };
 		A9D307E9106635C3004FEDF8 /* physfs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = physfs.framework; path = /Library/Frameworks/physfs.framework; sourceTree = "<absolute>"; };
 		A9DEC1BF1046EFA60049C70C /* Love.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = Love.icns; path = icons/Love.icns; sourceTree = "<group>"; };
 		A9DEC1C01046EFA70049C70C /* LoveDocument.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = LoveDocument.icns; path = icons/LoveDocument.icns; sourceTree = "<group>"; };
 				A93E6B0310420AC8007D418B /* PrismaticJoint.h */,
 				A93E6B0410420AC8007D418B /* PulleyJoint.cpp */,
 				A93E6B0510420AC8007D418B /* PulleyJoint.h */,
+				A9D1D20114224E1300A8BC2F /* RopeJoint.cpp */,
+				A9D1D20014224DFF00A8BC2F /* RopeJoint.h */,
 				A93E6B0610420AC8007D418B /* RevoluteJoint.cpp */,
 				A93E6B0710420AC8007D418B /* RevoluteJoint.h */,
 				A93E6B0810420AC8007D418B /* Shape.cpp */,
 				A93E6B6510420ACA007D418B /* wrap_PulleyJoint.h */,
 				A93E6B6610420ACA007D418B /* wrap_RevoluteJoint.cpp */,
 				A93E6B6710420ACA007D418B /* wrap_RevoluteJoint.h */,
+				A9D1D2031422578A00A8BC2F /* wrap_RopeJoint.cpp */,
+				A9D1D2051422579500A8BC2F /* wrap_RopeJoint.h */,
 				A93E6B6810420ACA007D418B /* wrap_Shape.cpp */,
 				A93E6B6910420ACA007D418B /* wrap_Shape.h */,
 				A96F41811412AFB70067FE9A /* wrap_WeldJoint.cpp */,
 				A96F418C1412B3AD0067FE9A /* WheelJoint.cpp in Sources */,
 				A96F41A41412C91F0067FE9A /* EdgeShape.cpp in Sources */,
 				A96F41A71412C92B0067FE9A /* wrap_EdgeShape.cpp in Sources */,
+				A9D1D20214224E1300A8BC2F /* RopeJoint.cpp in Sources */,
+				A9D1D2041422578C00A8BC2F /* wrap_RopeJoint.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

src/modules/physics/box2d/Physics.cpp

 	{
 		return new WheelJoint(body1, body2, x, y, ax, ay);
 	}
+	
+	RopeJoint * Physics::newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength)
+	{
+		return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength);
+	}
 
 } // box2d
 } // physics

src/modules/physics/box2d/Physics.h

 #include "FrictionJoint.h"
 #include "WeldJoint.h"
 #include "WheelJoint.h"
+#include "RopeJoint.h"
 
 namespace love
 {
 		* @param ay The y-component of the world-axis.
 		**/
 		WheelJoint * newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay);
+		
+		/**
+		* Creates a new RopeJoint connecting body1 with body2.
+		* @param x1 Anchor1 along the x-axis. (Local coordinates)
+		* @param y1 Anchor1 along the y-axis. (Local coordinates)
+		* @param x2 Anchor2 along the x-axis. (Local coordinates)
+		* @param y2 Anchor2 along the y-axis. (Local coordinates)
+		* @param maxLength The maximum distance for the bodies.
+		**/
+		RopeJoint * newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength);
 
 
 	}; // Physics

src/modules/physics/box2d/RopeJoint.cpp

+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#include "RopeJoint.h"
+
+// Module
+#include "Body.h"
+#include "World.h"
+
+namespace love
+{
+namespace physics
+{
+namespace box2d
+{
+	RopeJoint::RopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength)
+		: Joint(body1, body2), joint(NULL)
+	{
+		b2RopeJointDef def;
+		def.bodyA = body1->body;
+		def.bodyB = body2->body;
+		def.localAnchorA = world->scaleDown(b2Vec2(x1,y1));
+		def.localAnchorB = world->scaleDown(b2Vec2(x2,y2));
+		def.maxLength = world->scaleDown(maxLength);
+		joint = (b2RopeJoint*)createJoint(&def);
+	}
+
+	RopeJoint::~RopeJoint()
+	{
+		destroyJoint(joint);
+		joint = 0;
+	}
+
+	float RopeJoint::getMaxLength() const
+	{
+		return world->scaleUp(joint->GetMaxLength());
+	}
+
+
+} // box2d
+} // physics
+} // love

src/modules/physics/box2d/RopeJoint.h

+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
+#define LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
+
+// Module
+#include "Joint.h"
+
+namespace love
+{
+namespace physics
+{
+namespace box2d
+{
+	/**
+	* The RopeJoint enforces a maximum distance between two points 
+	* on two bodies. It has no other effect.
+	**/
+	class RopeJoint : public Joint
+	{
+	private:
+		// The Box2D RopeJoint object.
+		b2RopeJoint * joint;
+	public:
+
+		/**
+		* Creates a RopeJoint connecting body1 to body2. 
+		**/
+		RopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength);
+		
+		virtual ~RopeJoint();
+		
+		/**
+		* Gets the maximum length of the rope.
+		**/
+		float getMaxLength() const;
+		
+	};
+
+} // box2d
+} // physics
+} // love
+
+#endif // LOVE_PHYSICS_BOX2D_ROPE_JOINT_H

src/modules/physics/box2d/wrap_Physics.cpp

 		luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void*)j);
 		return 1;
 	}
+	
+	int w_newRopeJoint(lua_State * L)
+	{
+		Body * body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
+		Body * body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
+		float x1 = (float)luaL_checknumber(L, 3);
+		float y1 = (float)luaL_checknumber(L, 4);
+		float x2 = (float)luaL_checknumber(L, 5);
+		float y2 = (float)luaL_checknumber(L, 6);
+		float maxLength = (float)luaL_checknumber(L, 7);
+		RopeJoint * j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength);
+		luax_newtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, (void*)j);
+		return 1;
+	}
 
 	// List of functions to wrap.
 	static const luaL_Reg functions[] = {
 		{ "newFrictionJoint", w_newFrictionJoint },
 		{ "newWeldJoint", w_newWeldJoint },
 		{ "newWheelJoint", w_newWheelJoint },
+		{ "newRopeJoint", w_newRopeJoint },
 		{ 0, 0 },
 	};
 
 		luaopen_gearjoint,
 		luaopen_frictionjoint,
 		luaopen_weldjoint,
+		luaopen_wheeljoint,
+		luaopen_ropejoint,
 		0
 	};
 

src/modules/physics/box2d/wrap_Physics.h

 #include "wrap_FrictionJoint.h"
 #include "wrap_WeldJoint.h"
 #include "wrap_WheelJoint.h"
+#include "wrap_RopeJoint.h"
 
 namespace love
 {
 	int w_newFrictionJoint(lua_State * L);
 	int w_newWeldJoint(lua_State * L);
 	int w_newWheelJoint(lua_State * L);
+	int w_newRopeJoint(lua_State * L);
 	extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L);
 
 } // box2d

src/modules/physics/box2d/wrap_RopeJoint.cpp

+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#include "wrap_RopeJoint.h"
+
+namespace love
+{
+namespace physics
+{
+namespace box2d
+{
+	RopeJoint * luax_checkropejoint(lua_State * L, int idx)
+	{
+		return luax_checktype<RopeJoint>(L, idx, "RopeJoint", PHYSICS_ROPE_JOINT_T);
+	}
+
+	int w_RopeJoint_getMaxLength(lua_State * L)
+	{
+		RopeJoint * t = luax_checkropejoint(L, 1);
+		lua_pushnumber(L, t->getMaxLength());
+		return 1;
+	}
+
+	static const luaL_Reg functions[] = {
+		{ "getMaxLength", w_RopeJoint_getMaxLength },
+		// From Joint.
+		{ "getType", w_Joint_getType },
+		{ "getAnchors", w_Joint_getAnchors },
+		{ "getReactionForce", w_Joint_getReactionForce },
+		{ "getReactionTorque", w_Joint_getReactionTorque },
+		{ "getCollideConnected", w_Joint_getCollideConnected },
+		{ "destroy", w_Joint_destroy },
+		{ 0, 0 }
+	};
+
+	int luaopen_ropejoint(lua_State * L)
+	{
+		return luax_register_type(L, "RopeJoint", functions);
+	}
+
+} // box2d
+} // physics
+} // love

src/modules/physics/box2d/wrap_RopeJoint.h

+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
+#define LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
+
+// LOVE
+#include <common/runtime.h>
+#include "wrap_Joint.h"
+#include "RopeJoint.h"
+
+namespace love
+{
+namespace physics
+{
+namespace box2d
+{
+	RopeJoint * luax_checkropejoint(lua_State * L, int idx);
+	int w_RopeJoint_getMaxLength(lua_State * L);
+	int luaopen_ropejoint(lua_State * L);
+
+} // box2d
+} // physics
+} // love
+
+#endif // LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H