Browse Source

Update WeldJoint for new soft constraint options

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
a956f9b0c1

+ 20 - 0
src/modules/physics/box2d/WeldJoint.cpp

@@ -47,6 +47,26 @@ namespace box2d
 		destroyJoint(joint);
 		destroyJoint(joint);
 		joint = 0;
 		joint = 0;
 	}
 	}
+	
+	void WeldJoint::setFrequency(float hz)
+	{
+		joint->SetFrequency(hz);
+	}
+
+	float WeldJoint::getFrequency() const
+	{
+		return joint->GetFrequency();
+	}
+
+	void WeldJoint::setDampingRatio(float d)
+	{
+		joint->SetDampingRatio(d);
+	}
+
+	float WeldJoint::getDampingRatio() const
+	{
+		return joint->GetDampingRatio();
+	}
 
 
 } // box2d
 } // box2d
 } // physics
 } // physics

+ 22 - 0
src/modules/physics/box2d/WeldJoint.h

@@ -49,6 +49,28 @@ namespace box2d
 		
 		
 		virtual ~WeldJoint();
 		virtual ~WeldJoint();
 
 
+		/**
+		* Sets the response speed.
+		**/
+		void setFrequency(float hz);
+
+		/**
+		* Gets the response speed.
+		**/
+		float getFrequency() const;
+
+		/**
+		* Sets the damping ratio.
+		* 0 = no damping, 1 = critical damping.
+		**/
+		void setDampingRatio(float d);
+
+		/**
+		* Gets the damping ratio.
+		* 0 = no damping, 1 = critical damping.
+		**/
+		float getDampingRatio() const;
+
 	};
 	};
 
 
 } // box2d
 } // box2d

+ 34 - 0
src/modules/physics/box2d/wrap_WeldJoint.cpp

@@ -31,7 +31,41 @@ namespace box2d
 		return luax_checktype<WeldJoint>(L, idx, "WeldJoint", PHYSICS_WELD_JOINT_T);
 		return luax_checktype<WeldJoint>(L, idx, "WeldJoint", PHYSICS_WELD_JOINT_T);
 	}
 	}
 	
 	
+	int w_WeldJoint_setFrequency(lua_State * L)
+	{
+		WeldJoint * t = luax_checkweldjoint(L, 1);
+		float arg1 = (float)luaL_checknumber(L, 2);
+		t->setFrequency(arg1);
+		return 0;
+	}
+
+	int w_WeldJoint_getFrequency(lua_State * L)
+	{
+		WeldJoint * t = luax_checkweldjoint(L, 1);
+		lua_pushnumber(L, t->getFrequency());
+		return 1;
+	}
+
+	int w_WeldJoint_setDampingRatio(lua_State * L)
+	{
+		WeldJoint * t = luax_checkweldjoint(L, 1);
+		float arg1 = (float)luaL_checknumber(L, 2);
+		t->setDampingRatio(arg1);
+		return 0;
+	}
+
+	int w_WeldJoint_getDampingRatio(lua_State * L)
+	{
+		WeldJoint * t = luax_checkweldjoint(L, 1);
+		lua_pushnumber(L, t->getDampingRatio());
+		return 1;
+	}
+	
 	static const luaL_Reg functions[] = {
 	static const luaL_Reg functions[] = {
+		{ "setFrequency", w_WeldJoint_setFrequency },
+		{ "getFrequency", w_WeldJoint_getFrequency },
+		{ "setDampingRatio", w_WeldJoint_setDampingRatio },
+		{ "getDampingRatio", w_WeldJoint_getDampingRatio },
 		// From Joint.
 		// From Joint.
 		{ "getType", w_Joint_getType },
 		{ "getType", w_Joint_getType },
 		{ "getAnchors", w_Joint_getAnchors },
 		{ "getAnchors", w_Joint_getAnchors },

+ 6 - 0
src/modules/physics/box2d/wrap_WeldJoint.h

@@ -33,6 +33,12 @@ namespace physics
 namespace box2d
 namespace box2d
 {
 {
 	WeldJoint * luax_checkweldjoint(lua_State * L, int idx);
 	WeldJoint * luax_checkweldjoint(lua_State * L, int idx);
+	
+	int w_WeldJoint_setFrequency(lua_State * L);
+	int w_WeldJoint_getFrequency(lua_State * L);
+	int w_WeldJoint_setDampingRatio(lua_State * L);
+	int w_WeldJoint_getDampingRatio(lua_State * L);
+	
 	int luaopen_weldjoint(lua_State * L);
 	int luaopen_weldjoint(lua_State * L);
 
 
 } // box2d
 } // box2d