Browse Source

Added backwards compatible frequency/dampingRatio functions. Added new stiffness/damping functions.

Garrett Brown 5 years ago
parent
commit
a16640c89c

+ 30 - 2
src/modules/physics/box2d/DistanceJoint.cpp

@@ -56,9 +56,37 @@ float DistanceJoint::getLength() const
 	return Physics::scaleUp(joint->GetLength());
 	return Physics::scaleUp(joint->GetLength());
 }
 }
 
 
-void DistanceJoint::setStiffness(float hz)
+void DistanceJoint::setFrequency(float hz)
 {
 {
-	joint->SetStiffness(hz);
+	float stiffness, damping;
+	b2LinearStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
+	joint->SetStiffness(stiffness);
+}
+
+float DistanceJoint::getFrequency() const
+{
+	float frequency, ratio;
+	Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return frequency;
+}
+
+void DistanceJoint::setDampingRatio(float ratio)
+{
+	float stiffness, damping;
+	b2LinearStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
+	joint->SetDamping(damping);
+}
+
+float DistanceJoint::getDampingRatio() const
+{
+	float frequency, ratio;
+	Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return ratio;
+}
+
+void DistanceJoint::setStiffness(float k)
+{
+	joint->SetStiffness(k);
 }
 }
 
 
 float DistanceJoint::getStiffness() const
 float DistanceJoint::getStiffness() const

+ 26 - 8
src/modules/physics/box2d/DistanceJoint.h

@@ -57,24 +57,42 @@ public:
 	float getLength() const;
 	float getLength() const;
 
 
 	/**
 	/**
-	 * Sets the response speed.
+	 * Sets the response speed. Independent of mass
 	 **/
 	 **/
-	void setStiffness(float hz);
+	void setFrequency(float hz);
 
 
 	/**
 	/**
-	 * Gets the response speed.
+	 * Gets the response speed. Independent of mass
+	 **/
+	float getFrequency() const;
+
+	/**
+	 * Set the spring damping ratio. Independent of mass
+	 **/
+	void setDampingRatio(float ratio);
+
+	/**
+	 * Get the spring damping ratio. Independent of mass
+	 **/
+	float getDampingRatio() const;
+
+	/**
+	 * Sets the response speed. Dependent of mass
+	 **/
+	void setStiffness(float k);
+
+	/**
+	 * Gets the response speed. Dependent of mass
 	 **/
 	 **/
 	float getStiffness() const;
 	float getStiffness() const;
 
 
 	/**
 	/**
-	 * Sets the damping ratio.
-	 * 0 = no damping, 1 = critical damping.
+	 * Set the spring damping. Dependent of mass
 	 **/
 	 **/
-	void setDamping(float d);
+	void setDamping(float ratio);
 
 
 	/**
 	/**
-	 * Gets the damping ratio.
-	 * 0 = no damping, 1 = critical damping.
+	 * Get the spring damping. Dependent of mass
 	 **/
 	 **/
 	float getDamping() const;
 	float getDamping() const;
 
 

+ 36 - 2
src/modules/physics/box2d/MouseJoint.cpp

@@ -78,7 +78,7 @@ float MouseJoint::getMaxForce() const
 	return Physics::scaleUp(joint->GetMaxForce());
 	return Physics::scaleUp(joint->GetMaxForce());
 }
 }
 
 
-void MouseJoint::setStiffness(float hz)
+void MouseJoint::setFrequency(float hz)
 {
 {
 	// This is kind of a crappy check. The Stiffness is used in an internal
 	// This is kind of a crappy check. The Stiffness is used in an internal
 	// box2d calculation whose result must be > FLT_EPSILON, but other variables
 	// box2d calculation whose result must be > FLT_EPSILON, but other variables
@@ -86,7 +86,41 @@ void MouseJoint::setStiffness(float hz)
 	if (hz <= FLT_EPSILON * 2)
 	if (hz <= FLT_EPSILON * 2)
 		throw love::Exception("MouseJoint Stiffness must be a positive number.");
 		throw love::Exception("MouseJoint Stiffness must be a positive number.");
 
 
-	joint->SetStiffness(hz);
+	float stiffness, damping;
+	b2LinearStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
+	joint->SetStiffness(stiffness);
+}
+
+float MouseJoint::getFrequency() const
+{
+	float frequency, ratio;
+	Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return frequency;
+}
+
+void MouseJoint::setDampingRatio(float ratio)
+{
+	float stiffness, damping;
+	b2LinearStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
+	joint->SetDamping(damping);
+}
+
+float MouseJoint::getDampingRatio() const
+{
+	float frequency, ratio;
+	Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return ratio;
+}
+
+void MouseJoint::setStiffness(float k)
+{
+	// This is kind of a crappy check. The Stiffness is used in an internal
+	// box2d calculation whose result must be > FLT_EPSILON, but other variables
+	// go into that calculation...
+	if (k <= FLT_EPSILON * 2)
+		throw love::Exception("MouseJoint Stiffness must be a positive number.");
+
+	joint->SetStiffness(k);
 }
 }
 
 
 float MouseJoint::getStiffness() const
 float MouseJoint::getStiffness() const

+ 26 - 8
src/modules/physics/box2d/MouseJoint.h

@@ -76,24 +76,42 @@ public:
 	float getMaxForce() const;
 	float getMaxForce() const;
 
 
 	/**
 	/**
-	 * Sets the response speed.
+	 * Sets the response speed. Independent of mass
 	 **/
 	 **/
-	void setStiffness(float hz);
+	void setFrequency(float hz);
 
 
 	/**
 	/**
-	 * Gets the response speed.
+	 * Gets the response speed. Independent of mass
+	 **/
+	float getFrequency() const;
+
+	/**
+	 * Set the spring damping ratio. Independent of mass
+	 **/
+	void setDampingRatio(float ratio);
+
+	/**
+	 * Get the spring damping ratio. Independent of mass
+	 **/
+	float getDampingRatio() const;
+
+	/**
+	 * Sets the response speed. Dependent of mass
+	 **/
+	void setStiffness(float k);
+
+	/**
+	 * Gets the response speed. Dependent of mass
 	 **/
 	 **/
 	float getStiffness() const;
 	float getStiffness() const;
 
 
 	/**
 	/**
-	 * Sets the damping ratio.
-	 * 0 = no damping, 1 = critical damping.
+	 * Set the spring damping. Dependent of mass
 	 **/
 	 **/
-	void setDamping(float d);
+	void setDamping(float ratio);
 
 
 	/**
 	/**
-	 * Gets the damping ratio.
-	 * 0 = no damping, 1 = critical damping.
+	 * Get the spring damping. Dependent of mass
 	 **/
 	 **/
 	float getDamping() const;
 	float getDamping() const;
 
 

+ 60 - 0
src/modules/physics/box2d/Physics.cpp

@@ -395,6 +395,66 @@ b2AABB Physics::scaleUp(const b2AABB &aabb)
 	return t;
 	return t;
 }
 }
 
 
+void Physics::b2LinearFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB)
+{
+	float massA = bodyA->GetMass();
+	float massB = bodyB->GetMass();
+	float mass;
+	if (massA > 0.0f && massB > 0.0f)
+	{
+		mass = massA * massB / (massA + massB);
+	}
+	else if (massA > 0.0f)
+	{
+		mass = massA;
+	}
+	else
+	{
+		mass = massB;
+	}
+
+	if (mass == 0.0f || stiffness <= 0.0f)
+	{
+		frequency = 0.0f;
+		ratio = 0.0f;
+		return;
+	};
+
+	float omega = b2Sqrt(stiffness / mass);
+	frequency = omega / (2.0f * b2_pi);
+	ratio = damping / (mass * 2.0f * omega);
+}
+
+void Physics::b2AngularFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB)
+{
+	float IA = bodyA->GetInertia();
+	float IB = bodyB->GetInertia();
+	float I;
+	if (IA > 0.0f && IB > 0.0f)
+	{
+		I = IA * IB / (IA + IB);
+	}
+	else if (IA > 0.0f)
+	{
+		I = IA;
+	}
+	else
+	{
+		I = IB;
+	}
+
+	if (I == 0.0f || stiffness <= 0.0f)
+	{
+		frequency = 0.0f;
+		ratio = 0.0f;
+		return;
+	};
+
+	float omega = b2Sqrt(stiffness / I);
+	frequency = omega / (2.0f * b2_pi);
+	ratio = damping / (I * 2.0f * omega);
+}
+
 } // box2d
 } // box2d
 } // physics
 } // physics
 } // love
 } // love

+ 23 - 1
src/modules/physics/box2d/Physics.h

@@ -354,7 +354,29 @@ public:
 	 * @param aabb The unscaled input AABB.
 	 * @param aabb The unscaled input AABB.
 	 * @return The scaled AABB.
 	 * @return The scaled AABB.
 	 **/
 	 **/
-	static b2AABB scaleUp(const b2AABB &aabb);
+	static b2AABB scaleUp(const b2AABB& aabb);
+
+	/**
+	 * Calculates linear frequency and damping radio from stiffness and damping
+	 * @param frequency The output frequency
+	 * @param ratio The output damping ratio
+	 * @param stiffness The joint stiffness
+	 * @param damping The joint damping
+	 * @param bodyA The bodyA of the joint
+	 * @param bodyB The bodyB of the joint
+	 **/
+	static void b2LinearFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB);
+
+	/**
+	 * Calculates angular frequency and damping radio from stiffness and damping
+	 * @param frequency The output frequency
+	 * @param ratio The output damping ratio
+	 * @param stiffness The joint stiffness
+	 * @param damping The joint damping
+	 * @param bodyA The bodyA of the joint
+	 * @param bodyB The bodyB of the joint
+	 **/
+	static void b2AngularFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB);
 
 
 private:
 private:
 
 

+ 30 - 2
src/modules/physics/box2d/WeldJoint.cpp

@@ -66,9 +66,37 @@ void WeldJoint::init(b2WeldJointDef &def, Body *body1, Body *body2, float xA, fl
 	def.collideConnected = collideConnected;
 	def.collideConnected = collideConnected;
 }
 }
 
 
-void WeldJoint::setStiffness(float hz)
+void WeldJoint::setFrequency(float hz)
 {
 {
-	joint->SetStiffness(hz);
+	float stiffness, damping;
+	b2LinearStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
+	joint->SetStiffness(stiffness);
+}
+
+float WeldJoint::getFrequency() const
+{
+	float frequency, ratio;
+	Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return frequency;
+}
+
+void WeldJoint::setDampingRatio(float ratio)
+{
+	float stiffness, damping;
+	b2LinearStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
+	joint->SetDamping(damping);
+}
+
+float WeldJoint::getDampingRatio() const
+{
+	float frequency, ratio;
+	Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return ratio;
+}
+
+void WeldJoint::setStiffness(float k)
+{
+	joint->SetStiffness(k);
 }
 }
 
 
 float WeldJoint::getStiffness() const
 float WeldJoint::getStiffness() const

+ 26 - 8
src/modules/physics/box2d/WeldJoint.h

@@ -50,24 +50,42 @@ public:
 	virtual ~WeldJoint();
 	virtual ~WeldJoint();
 
 
 	/**
 	/**
-	 * Sets the response speed.
+	 * Sets the response speed. Independent of mass
 	 **/
 	 **/
-	void setStiffness(float hz);
+	void setFrequency(float hz);
 
 
 	/**
 	/**
-	 * Gets the response speed.
+	 * Gets the response speed. Independent of mass
+	 **/
+	float getFrequency() const;
+
+	/**
+	 * Set the spring damping ratio. Independent of mass
+	 **/
+	void setDampingRatio(float ratio);
+
+	/**
+	 * Get the spring damping ratio. Independent of mass
+	 **/
+	float getDampingRatio() const;
+
+	/**
+	 * Sets the response speed. Dependent of mass
+	 **/
+	void setStiffness(float k);
+
+	/**
+	 * Gets the response speed. Dependent of mass
 	 **/
 	 **/
 	float getStiffness() const;
 	float getStiffness() const;
 
 
 	/**
 	/**
-	 * Sets the damping ratio.
-	 * 0 = no damping, 1 = critical damping.
+	 * Set the spring damping. Dependent of mass
 	 **/
 	 **/
-	void setDamping(float d);
+	void setDamping(float ratio);
 
 
 	/**
 	/**
-	 * Gets the damping ratio.
-	 * 0 = no damping, 1 = critical damping.
+	 * Get the spring damping. Dependent of mass
 	 **/
 	 **/
 	float getDamping() const;
 	float getDamping() const;
 
 

+ 30 - 2
src/modules/physics/box2d/WheelJoint.cpp

@@ -95,9 +95,37 @@ float WheelJoint::getMotorTorque(float inv_dt) const
 	return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
 	return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
 }
 }
 
 
-void WheelJoint::setStiffness(float hz)
+void WheelJoint::setFrequency(float hz)
 {
 {
-	joint->SetStiffness(hz);
+	float stiffness, damping;
+	b2AngularStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
+	joint->SetStiffness(stiffness);
+}
+
+float WheelJoint::getFrequency() const
+{
+	float frequency, ratio;
+	Physics::b2AngularFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return frequency;
+}
+
+void WheelJoint::setDampingRatio(float ratio)
+{
+	float stiffness, damping;
+	b2AngularStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
+	joint->SetDamping(damping);
+}
+
+float WheelJoint::getDampingRatio() const
+{
+	float frequency, ratio;
+	Physics::b2AngularFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
+	return ratio;
+}
+
+void WheelJoint::setStiffness(float k)
+{
+	joint->SetStiffness(k);
 }
 }
 
 
 float WheelJoint::getStiffness() const
 float WheelJoint::getStiffness() const

+ 25 - 6
src/modules/physics/box2d/WheelJoint.h

@@ -96,23 +96,42 @@ public:
 	float getMotorTorque(float inv_dt) const;
 	float getMotorTorque(float inv_dt) const;
 
 
 	/**
 	/**
-	 * Set the spring frequency, in hertz. Setting the frequency to 0
-	 * disables the spring.
+	 * Sets the response speed. Independent of mass
 	 **/
 	 **/
-	void setStiffness(float hz);
+	void setFrequency(float hz);
 
 
 	/**
 	/**
-	 * Get the spring frequency, in hertz.
+	 * Gets the response speed. Independent of mass
+	 **/
+	float getFrequency() const;
+
+	/**
+	 * Set the spring damping ratio. Independent of mass
+	 **/
+	void setDampingRatio(float ratio);
+
+	/**
+	 * Get the spring damping ratio. Independent of mass
+	 **/
+	float getDampingRatio() const;
+
+	/**
+	 * Sets the response speed. Dependent of mass
+	 **/
+	void setStiffness(float k);
+
+	/**
+	 * Gets the response speed. Dependent of mass
 	 **/
 	 **/
 	float getStiffness() const;
 	float getStiffness() const;
 
 
 	/**
 	/**
-	 * Set the spring damping ratio.
+	 * Set the spring damping. Dependent of mass
 	 **/
 	 **/
 	void setDamping(float ratio);
 	void setDamping(float ratio);
 
 
 	/**
 	/**
-	 * Get the spring damping ratio.
+	 * Get the spring damping. Dependent of mass
 	 **/
 	 **/
 	float getDamping() const;
 	float getDamping() const;
 
 

+ 37 - 3
src/modules/physics/box2d/wrap_DistanceJoint.cpp

@@ -54,14 +54,14 @@ int w_DistanceJoint_setFrequency(lua_State *L)
 {
 {
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	t->setStiffness(arg1);
+	t->setFrequency(arg1);
 	return 0;
 	return 0;
 }
 }
 
 
 int w_DistanceJoint_getFrequency(lua_State *L)
 int w_DistanceJoint_getFrequency(lua_State *L)
 {
 {
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
-	lua_pushnumber(L, t->getStiffness());
+	lua_pushnumber(L, t->getFrequency());
 	return 1;
 	return 1;
 }
 }
 
 
@@ -69,11 +69,41 @@ int w_DistanceJoint_setDampingRatio(lua_State *L)
 {
 {
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	t->setDamping(arg1);
+	t->setDampingRatio(arg1);
 	return 0;
 	return 0;
 }
 }
 
 
 int w_DistanceJoint_getDampingRatio(lua_State *L)
 int w_DistanceJoint_getDampingRatio(lua_State *L)
+{
+	DistanceJoint *t = luax_checkdistancejoint(L, 1);
+	lua_pushnumber(L, t->getDampingRatio());
+	return 1;
+}
+
+int w_DistanceJoint_setStiffness(lua_State *L)
+{
+	DistanceJoint *t = luax_checkdistancejoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setStiffness(arg1);
+	return 0;
+}
+
+int w_DistanceJoint_getStiffness(lua_State *L)
+{
+	DistanceJoint *t = luax_checkdistancejoint(L, 1);
+	lua_pushnumber(L, t->getStiffness());
+	return 1;
+}
+
+int w_DistanceJoint_setDamping(lua_State *L)
+{
+	DistanceJoint *t = luax_checkdistancejoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setDamping(arg1);
+	return 0;
+}
+
+int w_DistanceJoint_getDamping(lua_State *L)
 {
 {
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	DistanceJoint *t = luax_checkdistancejoint(L, 1);
 	lua_pushnumber(L, t->getDamping());
 	lua_pushnumber(L, t->getDamping());
@@ -88,6 +118,10 @@ static const luaL_Reg w_DistanceJoint_functions[] =
 	{ "getFrequency", w_DistanceJoint_getFrequency },
 	{ "getFrequency", w_DistanceJoint_getFrequency },
 	{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
 	{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
 	{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
 	{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
+	{ "setStiffness", w_DistanceJoint_setStiffness },
+	{ "getStiffness", w_DistanceJoint_getStiffness },
+	{ "setDamping", w_DistanceJoint_setDamping },
+	{ "getDamping", w_DistanceJoint_getDamping },
 	{ 0, 0 }
 	{ 0, 0 }
 };
 };
 
 

+ 37 - 3
src/modules/physics/box2d/wrap_MouseJoint.cpp

@@ -70,14 +70,14 @@ int w_MouseJoint_setFrequency(lua_State *L)
 {
 {
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	luax_catchexcept(L, [&]() { t->setStiffness(arg1); });
+	luax_catchexcept(L, [&]() { t->setFrequency(arg1); });
 	return 0;
 	return 0;
 }
 }
 
 
 int w_MouseJoint_getFrequency(lua_State *L)
 int w_MouseJoint_getFrequency(lua_State *L)
 {
 {
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	MouseJoint *t = luax_checkmousejoint(L, 1);
-	lua_pushnumber(L, t->getStiffness());
+	lua_pushnumber(L, t->getFrequency());
 	return 1;
 	return 1;
 }
 }
 
 
@@ -85,11 +85,41 @@ int w_MouseJoint_setDampingRatio(lua_State *L)
 {
 {
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	t->setDamping(arg1);
+	t->setDampingRatio(arg1);
 	return 0;
 	return 0;
 }
 }
 
 
 int w_MouseJoint_getDampingRatio(lua_State *L)
 int w_MouseJoint_getDampingRatio(lua_State *L)
+{
+	MouseJoint *t = luax_checkmousejoint(L, 1);
+	lua_pushnumber(L, t->getDampingRatio());
+	return 1;
+}
+
+int w_MouseJoint_setStiffness(lua_State *L)
+{
+	MouseJoint *t = luax_checkmousejoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	luax_catchexcept(L, [&]() { t->setStiffness(arg1); });
+	return 0;
+}
+
+int w_MouseJoint_getStiffness(lua_State *L)
+{
+	MouseJoint *t = luax_checkmousejoint(L, 1);
+	lua_pushnumber(L, t->getStiffness());
+	return 1;
+}
+
+int w_MouseJoint_setDamping(lua_State *L)
+{
+	MouseJoint *t = luax_checkmousejoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setDamping(arg1);
+	return 0;
+}
+
+int w_MouseJoint_getDamping(lua_State *L)
 {
 {
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	MouseJoint *t = luax_checkmousejoint(L, 1);
 	lua_pushnumber(L, t->getDamping());
 	lua_pushnumber(L, t->getDamping());
@@ -106,6 +136,10 @@ static const luaL_Reg w_MouseJoint_functions[] =
 	{ "getFrequency", w_MouseJoint_getFrequency },
 	{ "getFrequency", w_MouseJoint_getFrequency },
 	{ "setDampingRatio", w_MouseJoint_setDampingRatio },
 	{ "setDampingRatio", w_MouseJoint_setDampingRatio },
 	{ "getDampingRatio", w_MouseJoint_getDampingRatio },
 	{ "getDampingRatio", w_MouseJoint_getDampingRatio },
+	{ "setStiffness", w_MouseJoint_setStiffness },
+	{ "getStiffness", w_MouseJoint_getStiffness },
+	{ "setDamping", w_MouseJoint_setDamping },
+	{ "getDamping", w_MouseJoint_getDamping },
 	{ 0, 0 }
 	{ 0, 0 }
 };
 };
 
 

+ 37 - 3
src/modules/physics/box2d/wrap_WeldJoint.cpp

@@ -39,14 +39,14 @@ int w_WeldJoint_setFrequency(lua_State *L)
 {
 {
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	t->setStiffness(arg1);
+	t->setFrequency(arg1);
 	return 0;
 	return 0;
 }
 }
 
 
 int w_WeldJoint_getFrequency(lua_State *L)
 int w_WeldJoint_getFrequency(lua_State *L)
 {
 {
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	WeldJoint *t = luax_checkweldjoint(L, 1);
-	lua_pushnumber(L, t->getStiffness());
+	lua_pushnumber(L, t->getFrequency());
 	return 1;
 	return 1;
 }
 }
 
 
@@ -54,11 +54,41 @@ int w_WeldJoint_setDampingRatio(lua_State *L)
 {
 {
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
-	t->setDamping(arg1);
+	t->setDampingRatio(arg1);
 	return 0;
 	return 0;
 }
 }
 
 
 int w_WeldJoint_getDampingRatio(lua_State *L)
 int w_WeldJoint_getDampingRatio(lua_State *L)
+{
+	WeldJoint *t = luax_checkweldjoint(L, 1);
+	lua_pushnumber(L, t->getDampingRatio());
+	return 1;
+}
+
+int w_WeldJoint_setStiffness(lua_State *L)
+{
+	WeldJoint *t = luax_checkweldjoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setStiffness(arg1);
+	return 0;
+}
+
+int w_WeldJoint_getStiffness(lua_State *L)
+{
+	WeldJoint *t = luax_checkweldjoint(L, 1);
+	lua_pushnumber(L, t->getStiffness());
+	return 1;
+}
+
+int w_WeldJoint_setDamping(lua_State *L)
+{
+	WeldJoint *t = luax_checkweldjoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setDamping(arg1);
+	return 0;
+}
+
+int w_WeldJoint_getDamping(lua_State *L)
 {
 {
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	WeldJoint *t = luax_checkweldjoint(L, 1);
 	lua_pushnumber(L, t->getDamping());
 	lua_pushnumber(L, t->getDamping());
@@ -78,6 +108,10 @@ static const luaL_Reg w_WeldJoint_functions[] =
 	{ "getFrequency", w_WeldJoint_getFrequency },
 	{ "getFrequency", w_WeldJoint_getFrequency },
 	{ "setDampingRatio", w_WeldJoint_setDampingRatio },
 	{ "setDampingRatio", w_WeldJoint_setDampingRatio },
 	{ "getDampingRatio", w_WeldJoint_getDampingRatio },
 	{ "getDampingRatio", w_WeldJoint_getDampingRatio },
+	{ "setStiffness", w_WeldJoint_setStiffness },
+	{ "getStiffness", w_WeldJoint_getStiffness },
+	{ "setDamping", w_WeldJoint_setDamping },
+	{ "getDamping", w_WeldJoint_getDamping },
 	{ "getReferenceAngle", w_WeldJoint_getReferenceAngle },
 	{ "getReferenceAngle", w_WeldJoint_getReferenceAngle },
 	{ 0, 0 }
 	{ 0, 0 }
 };
 };

+ 50 - 8
src/modules/physics/box2d/wrap_WheelJoint.cpp

@@ -102,7 +102,37 @@ int w_WheelJoint_getMotorTorque(lua_State *L)
 	return 1;
 	return 1;
 }
 }
 
 
-int w_WheelJoint_setSpringFrequency(lua_State *L)
+int w_WheelJoint_setFrequency(lua_State *L)
+{
+	WheelJoint *t = luax_checkwheeljoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setFrequency(arg1);
+	return 0;
+}
+
+int w_WheelJoint_getFrequency(lua_State *L)
+{
+	WheelJoint *t = luax_checkwheeljoint(L, 1);
+	lua_pushnumber(L, t->getFrequency());
+	return 1;
+}
+
+int w_WheelJoint_setDampingRatio(lua_State *L)
+{
+	WheelJoint *t = luax_checkwheeljoint(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	t->setDampingRatio(arg1);
+	return 0;
+}
+
+int w_WheelJoint_getDampingRatio(lua_State *L)
+{
+	WheelJoint *t = luax_checkwheeljoint(L, 1);
+	lua_pushnumber(L, t->getDampingRatio());
+	return 1;
+}
+
+int w_WheelJoint_setStiffness(lua_State *L)
 {
 {
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
@@ -110,14 +140,14 @@ int w_WheelJoint_setSpringFrequency(lua_State *L)
 	return 0;
 	return 0;
 }
 }
 
 
-int w_WheelJoint_getSpringFrequency(lua_State *L)
+int w_WheelJoint_getStiffness(lua_State *L)
 {
 {
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	lua_pushnumber(L, t->getStiffness());
 	lua_pushnumber(L, t->getStiffness());
 	return 1;
 	return 1;
 }
 }
 
 
-int w_WheelJoint_setSpringDampingRatio(lua_State *L)
+int w_WheelJoint_setDamping(lua_State *L)
 {
 {
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
 	float arg1 = (float)luaL_checknumber(L, 2);
@@ -125,7 +155,7 @@ int w_WheelJoint_setSpringDampingRatio(lua_State *L)
 	return 0;
 	return 0;
 }
 }
 
 
-int w_WheelJoint_getSpringDampingRatio(lua_State *L)
+int w_WheelJoint_getDamping(lua_State *L)
 {
 {
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	WheelJoint *t = luax_checkwheeljoint(L, 1);
 	lua_pushnumber(L, t->getDamping());
 	lua_pushnumber(L, t->getDamping());
@@ -150,10 +180,22 @@ static const luaL_Reg w_WheelJoint_functions[] =
 	{ "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
 	{ "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
 	{ "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
 	{ "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
 	{ "getMotorTorque", w_WheelJoint_getMotorTorque },
 	{ "getMotorTorque", w_WheelJoint_getMotorTorque },
-	{ "setSpringFrequency", w_WheelJoint_setSpringFrequency },
-	{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
-	{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
-	{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
+	{ "setSpringFrequency", w_WheelJoint_setFrequency },
+	{ "getSpringFrequency", w_WheelJoint_getFrequency },
+	{ "setSpringDampingRatio", w_WheelJoint_setDampingRatio },
+	{ "getSpringDampingRatio", w_WheelJoint_getDampingRatio },
+	{ "setSpringStiffness", w_WheelJoint_setStiffness },
+	{ "getSpringStiffness", w_WheelJoint_getStiffness },
+	{ "setSpringDamping", w_WheelJoint_setDamping },
+	{ "getSpringDamping", w_WheelJoint_getDamping },
+	{ "setFrequency", w_WheelJoint_setFrequency },
+	{ "getFrequency", w_WheelJoint_getFrequency },
+	{ "setDampingRatio", w_WheelJoint_setDampingRatio },
+	{ "getDampingRatio", w_WheelJoint_getDampingRatio },
+	{ "setStiffness", w_WheelJoint_setStiffness },
+	{ "getStiffness", w_WheelJoint_getStiffness },
+	{ "setDamping", w_WheelJoint_setDamping },
+	{ "getDamping", w_WheelJoint_getDamping },
 	{ "getAxis", w_WheelJoint_getAxis },
 	{ "getAxis", w_WheelJoint_getAxis },
 	{ 0, 0 }
 	{ 0, 0 }
 };
 };