more joint updates to better match the API

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-07-02 11:46:42 -05:00
parent b4fae893fd
commit b3434997bf
15 changed files with 122 additions and 40 deletions
+5
View File
@@ -111,6 +111,11 @@ namespace box2d
if (joint != NULL) if (joint != NULL)
world->world->DestroyJoint(joint); world->world->DestroyJoint(joint);
} }
bool Joint::isActive() const
{
return joint->IsActive();
}
} // box2d } // box2d
} // physics } // physics
+2
View File
@@ -98,6 +98,8 @@ namespace box2d
* Gets the reaction torque on body2. * Gets the reaction torque on body2.
**/ **/
float getReactionTorque(float dt); float getReactionTorque(float dt);
bool isActive() const;
protected: protected:
+20
View File
@@ -69,6 +69,26 @@ namespace box2d
{ {
return joint->GetMaxForce(); return joint->GetMaxForce();
} }
void MouseJoint::setFrequency(float hz)
{
joint->SetFrequency(hz);
}
float MouseJoint::getFrequency() const
{
return joint->GetFrequency();
}
void MouseJoint::setDampingRatio(float d)
{
joint->SetDampingRatio(d);
}
float MouseJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
}
} // box2d } // box2d
} // physics } // physics
+22
View File
@@ -74,6 +74,28 @@ namespace box2d
* to move the candidate body. * to move the candidate body.
**/ **/
float getMaxForce() const; float getMaxForce() const;
/**
* 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
+3 -3
View File
@@ -63,7 +63,7 @@ namespace box2d
/** /**
* Enable/disable the joint motor. * Enable/disable the joint motor.
**/ **/
void setMotorEnabled(bool motor); void enableMotor(bool motor);
/** /**
* Checks whether the motor is enabled. * Checks whether the motor is enabled.
@@ -93,12 +93,12 @@ namespace box2d
/** /**
* Enable/disable the joint limit. * Enable/disable the joint limit.
**/ **/
void setLimitsEnabled(bool limit); void enableLimit(bool limit);
/** /**
* Checks whether limits are enabled. * Checks whether limits are enabled.
**/ **/
bool isLimitsEnabled() const; bool isLimitEnabled() const;
/** /**
* Sets the upper limit, usually in meters. * Sets the upper limit, usually in meters.
-5
View File
@@ -66,11 +66,6 @@ namespace box2d
**/ **/
float getLength2() const; float getLength2() const;
/**
* Sets the pulley ratio.
**/
void setRatio(float ratio);
/** /**
* Gets the pulley ratio. * Gets the pulley ratio.
**/ **/
+3 -3
View File
@@ -56,7 +56,7 @@ namespace box2d
return joint->GetJointSpeed(); return joint->GetJointSpeed();
} }
void RevoluteJoint::setMotorEnabled(bool motor) void RevoluteJoint::enableMotor(bool motor)
{ {
return joint->EnableMotor(motor); return joint->EnableMotor(motor);
} }
@@ -86,12 +86,12 @@ namespace box2d
return joint->GetMotorTorque(); return joint->GetMotorTorque();
} }
void RevoluteJoint::setLimitsEnabled(bool limit) void RevoluteJoint::enableLimit(bool limit)
{ {
joint->EnableLimit(limit); joint->EnableLimit(limit);
} }
bool RevoluteJoint::isLimitsEnabled() const bool RevoluteJoint::isLimitEnabled() const
{ {
return joint->IsLimitEnabled(); return joint->IsLimitEnabled();
} }
+3 -3
View File
@@ -63,7 +63,7 @@ namespace box2d
/** /**
* Enable/disable the joint motor. * Enable/disable the joint motor.
**/ **/
void setMotorEnabled(bool motor); void enableMotor(bool motor);
/** /**
* Checks whether the motor is enabled. * Checks whether the motor is enabled.
@@ -93,12 +93,12 @@ namespace box2d
/** /**
* Enable/disable the joint limit. * Enable/disable the joint limit.
**/ **/
void setLimitsEnabled(bool limit); void enableLimit(bool limit);
/** /**
* Checks whether limits are enabled. * Checks whether limits are enabled.
**/ **/
bool isLimitsEnabled() const; bool isLimitEnabled() const;
/** /**
* Sets the upper limit in degrees. * Sets the upper limit in degrees.
@@ -81,8 +81,8 @@ namespace box2d
{ "getLength", w_DistanceJoint_getLength }, { "getLength", w_DistanceJoint_getLength },
{ "setFrequency", w_DistanceJoint_setFrequency }, { "setFrequency", w_DistanceJoint_setFrequency },
{ "getFrequency", w_DistanceJoint_getFrequency }, { "getFrequency", w_DistanceJoint_getFrequency },
{ "setDamping", w_DistanceJoint_setDampingRatio }, { "setDampingRatio", w_DistanceJoint_setDampingRatio },
{ "getDamping", w_DistanceJoint_getDampingRatio }, { "getDampingRatio", w_DistanceJoint_getDampingRatio },
// From Joint. // From Joint.
{ "getType", w_Joint_getType }, { "getType", w_Joint_getType },
{ "getAnchors", w_Joint_getAnchors }, { "getAnchors", w_Joint_getAnchors },
@@ -61,12 +61,46 @@ namespace box2d
lua_pushnumber(L, t->getMaxForce()); lua_pushnumber(L, t->getMaxForce());
return 1; return 1;
} }
int w_MouseJoint_setFrequency(lua_State * L)
{
MouseJoint * t = luax_checkmousejoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setFrequency(arg1);
return 0;
}
int w_MouseJoint_getFrequency(lua_State * L)
{
MouseJoint * t = luax_checkmousejoint(L, 1);
lua_pushnumber(L, t->getFrequency());
return 1;
}
int w_MouseJoint_setDampingRatio(lua_State * L)
{
MouseJoint * t = luax_checkmousejoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setDampingRatio(arg1);
return 0;
}
int w_MouseJoint_getDampingRatio(lua_State * L)
{
MouseJoint * t = luax_checkmousejoint(L, 1);
lua_pushnumber(L, t->getDampingRatio());
return 1;
}
static const luaL_Reg functions[] = { static const luaL_Reg functions[] = {
{ "setTarget", w_MouseJoint_setTarget }, { "setTarget", w_MouseJoint_setTarget },
{ "getTarget", w_MouseJoint_getTarget }, { "getTarget", w_MouseJoint_getTarget },
{ "setMaxForce", w_MouseJoint_setMaxForce }, { "setMaxForce", w_MouseJoint_setMaxForce },
{ "getMaxForce", w_MouseJoint_getMaxForce }, { "getMaxForce", w_MouseJoint_getMaxForce },
{ "setFrequency", w_MouseJoint_setFrequency },
{ "getFrequency", w_MouseJoint_getFrequency },
{ "setDampingRatio", w_MouseJoint_setDampingRatio },
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
// From Joint. // From Joint.
{ "getType", w_Joint_getType }, { "getType", w_Joint_getType },
{ "getAnchors", w_Joint_getAnchors }, { "getAnchors", w_Joint_getAnchors },
@@ -37,6 +37,10 @@ namespace box2d
int w_MouseJoint_getTarget(lua_State * L); int w_MouseJoint_getTarget(lua_State * L);
int w_MouseJoint_setMaxForce(lua_State * L); int w_MouseJoint_setMaxForce(lua_State * L);
int w_MouseJoint_getMaxForce(lua_State * L); int w_MouseJoint_getMaxForce(lua_State * L);
int w_MouseJoint_setFrequency(lua_State * L);
int w_MouseJoint_getFrequency(lua_State * L);
int w_MouseJoint_setDampingRatio(lua_State * L);
int w_MouseJoint_getDampingRatio(lua_State * L);
int luaopen_mousejoint(lua_State * L); int luaopen_mousejoint(lua_State * L);
} // box2d } // box2d
@@ -45,11 +45,11 @@ namespace box2d
return 1; return 1;
} }
int w_PrismaticJoint_setMotorEnabled(lua_State * L) int w_PrismaticJoint_enableMotor(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
bool arg1 = luax_toboolean(L, 2); bool arg1 = luax_toboolean(L, 2);
t->setMotorEnabled(arg1); t->enableMotor(arg1);
return 0; return 0;
} }
@@ -90,18 +90,18 @@ namespace box2d
return 1; return 1;
} }
int w_PrismaticJoint_setLimitsEnabled(lua_State * L) int w_PrismaticJoint_enableLimit(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
bool arg1 = luax_toboolean(L, 2); bool arg1 = luax_toboolean(L, 2);
t->setLimitsEnabled(arg1); t->enableLimit(arg1);
return 0; return 0;
} }
int w_PrismaticJoint_isLimitsEnabled(lua_State * L) int w_PrismaticJoint_isLimitEnabled(lua_State * L)
{ {
PrismaticJoint * t = luax_checkprismaticjoint(L, 1); PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
luax_pushboolean(L, t->isLimitsEnabled()); luax_pushboolean(L, t->isLimitEnabled());
return 1; return 1;
} }
@@ -154,14 +154,14 @@ namespace box2d
static const luaL_Reg functions[] = { static const luaL_Reg functions[] = {
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation }, { "getJointTranslation", w_PrismaticJoint_getJointTranslation },
{ "getJointSpeed", w_PrismaticJoint_getJointSpeed }, { "getJointSpeed", w_PrismaticJoint_getJointSpeed },
{ "setMotorEnabled", w_PrismaticJoint_setMotorEnabled }, { "enableMotor", w_PrismaticJoint_enableMotor },
{ "isMotorEnabled", w_PrismaticJoint_isMotorEnabled }, { "isMotorEnabled", w_PrismaticJoint_isMotorEnabled },
{ "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce }, { "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce },
{ "setMotorSpeed", w_PrismaticJoint_setMotorSpeed }, { "setMotorSpeed", w_PrismaticJoint_setMotorSpeed },
{ "getMotorSpeed", w_PrismaticJoint_getMotorSpeed }, { "getMotorSpeed", w_PrismaticJoint_getMotorSpeed },
{ "getMotorForce", w_PrismaticJoint_getMotorForce }, { "getMotorForce", w_PrismaticJoint_getMotorForce },
{ "setLimitsEnabled", w_PrismaticJoint_setLimitsEnabled }, { "enableLimit", w_PrismaticJoint_enableLimit },
{ "isLimitsEnabled", w_PrismaticJoint_isLimitsEnabled }, { "isLimitEnabled", w_PrismaticJoint_isLimitEnabled },
{ "setUpperLimit", w_PrismaticJoint_setUpperLimit }, { "setUpperLimit", w_PrismaticJoint_setUpperLimit },
{ "setLowerLimit", w_PrismaticJoint_setLowerLimit }, { "setLowerLimit", w_PrismaticJoint_setLowerLimit },
{ "setLimits", w_PrismaticJoint_setLimits }, { "setLimits", w_PrismaticJoint_setLimits },
@@ -35,14 +35,14 @@ namespace box2d
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx); PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx);
int w_PrismaticJoint_getJointTranslation(lua_State * L); int w_PrismaticJoint_getJointTranslation(lua_State * L);
int w_PrismaticJoint_getJointSpeed(lua_State * L); int w_PrismaticJoint_getJointSpeed(lua_State * L);
int w_PrismaticJoint_setMotorEnabled(lua_State * L); int w_PrismaticJoint_enableMotor(lua_State * L);
int w_PrismaticJoint_isMotorEnabled(lua_State * L); int w_PrismaticJoint_isMotorEnabled(lua_State * L);
int w_PrismaticJoint_setMaxMotorForce(lua_State * L); int w_PrismaticJoint_setMaxMotorForce(lua_State * L);
int w_PrismaticJoint_setMotorSpeed(lua_State * L); int w_PrismaticJoint_setMotorSpeed(lua_State * L);
int w_PrismaticJoint_getMotorSpeed(lua_State * L); int w_PrismaticJoint_getMotorSpeed(lua_State * L);
int w_PrismaticJoint_getMotorForce(lua_State * L); int w_PrismaticJoint_getMotorForce(lua_State * L);
int w_PrismaticJoint_setLimitsEnabled(lua_State * L); int w_PrismaticJoint_enableLimit(lua_State * L);
int w_PrismaticJoint_isLimitsEnabled(lua_State * L); int w_PrismaticJoint_isLimitEnabled(lua_State * L);
int w_PrismaticJoint_setUpperLimit(lua_State * L); int w_PrismaticJoint_setUpperLimit(lua_State * L);
int w_PrismaticJoint_setLowerLimit(lua_State * L); int w_PrismaticJoint_setLowerLimit(lua_State * L);
int w_PrismaticJoint_setLimits(lua_State * L); int w_PrismaticJoint_setLimits(lua_State * L);
@@ -45,11 +45,11 @@ namespace box2d
return 1; return 1;
} }
int w_RevoluteJoint_setMotorEnabled(lua_State * L) int w_RevoluteJoint_enableMotor(lua_State * L)
{ {
RevoluteJoint * t = luax_checkrevolutejoint(L, 1); RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
bool arg1 = luax_toboolean(L, 2); bool arg1 = luax_toboolean(L, 2);
t->setMotorEnabled(arg1); t->enableMotor(arg1);
return 0; return 0;
} }
@@ -90,18 +90,18 @@ namespace box2d
return 1; return 1;
} }
int w_RevoluteJoint_setLimitsEnabled(lua_State * L) int w_RevoluteJoint_enableLimit(lua_State * L)
{ {
RevoluteJoint * t = luax_checkrevolutejoint(L, 1); RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
bool arg1 = luax_toboolean(L, 2); bool arg1 = luax_toboolean(L, 2);
t->setLimitsEnabled(arg1); t->enableLimit(arg1);
return 0; return 0;
} }
int w_RevoluteJoint_isLimitsEnabled(lua_State * L) int w_RevoluteJoint_isLimitEnabled(lua_State * L)
{ {
RevoluteJoint * t = luax_checkrevolutejoint(L, 1); RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
luax_pushboolean(L, t->isLimitsEnabled()); luax_pushboolean(L, t->isLimitEnabled());
return 1; return 1;
} }
@@ -154,14 +154,14 @@ namespace box2d
static const luaL_Reg functions[] = { static const luaL_Reg functions[] = {
{ "getJointAngle", w_RevoluteJoint_getJointAngle }, { "getJointAngle", w_RevoluteJoint_getJointAngle },
{ "getJointSpeed", w_RevoluteJoint_getJointSpeed }, { "getJointSpeed", w_RevoluteJoint_getJointSpeed },
{ "setMotorEnabled", w_RevoluteJoint_setMotorEnabled }, { "enableMotor", w_RevoluteJoint_enableMotor },
{ "isMotorEnabled", w_RevoluteJoint_isMotorEnabled }, { "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
{ "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque }, { "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
{ "setMotorSpeed", w_RevoluteJoint_setMotorSpeed }, { "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
{ "getMotorSpeed", w_RevoluteJoint_getMotorSpeed }, { "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
{ "getMotorTorque", w_RevoluteJoint_getMotorTorque }, { "getMotorTorque", w_RevoluteJoint_getMotorTorque },
{ "setLimitsEnabled", w_RevoluteJoint_setLimitsEnabled }, { "enableLimit", w_RevoluteJoint_enableLimit },
{ "isLimitsEnabled", w_RevoluteJoint_isLimitsEnabled }, { "isLimitEnabled", w_RevoluteJoint_isLimitEnabled },
{ "setUpperLimit", w_RevoluteJoint_setUpperLimit }, { "setUpperLimit", w_RevoluteJoint_setUpperLimit },
{ "setLowerLimit", w_RevoluteJoint_setLowerLimit }, { "setLowerLimit", w_RevoluteJoint_setLowerLimit },
{ "setLimits", w_RevoluteJoint_setLimits }, { "setLimits", w_RevoluteJoint_setLimits },
@@ -35,14 +35,14 @@ namespace box2d
RevoluteJoint * luax_checkrevolutejoint(lua_State * L, int idx); RevoluteJoint * luax_checkrevolutejoint(lua_State * L, int idx);
int w_RevoluteJoint_getJointAngle(lua_State * L); int w_RevoluteJoint_getJointAngle(lua_State * L);
int w_RevoluteJoint_getJointSpeed(lua_State * L); int w_RevoluteJoint_getJointSpeed(lua_State * L);
int w_RevoluteJoint_setMotorEnabled(lua_State * L); int w_RevoluteJoint_enableMotor(lua_State * L);
int w_RevoluteJoint_isMotorEnabled(lua_State * L); int w_RevoluteJoint_isMotorEnabled(lua_State * L);
int w_RevoluteJoint_setMaxMotorTorque(lua_State * L); int w_RevoluteJoint_setMaxMotorTorque(lua_State * L);
int w_RevoluteJoint_setMotorSpeed(lua_State * L); int w_RevoluteJoint_setMotorSpeed(lua_State * L);
int w_RevoluteJoint_getMotorSpeed(lua_State * L); int w_RevoluteJoint_getMotorSpeed(lua_State * L);
int w_RevoluteJoint_getMotorTorque(lua_State * L); int w_RevoluteJoint_getMotorTorque(lua_State * L);
int w_RevoluteJoint_setLimitsEnabled(lua_State * L); int w_RevoluteJoint_enableLimit(lua_State * L);
int w_RevoluteJoint_isLimitsEnabled(lua_State * L); int w_RevoluteJoint_isLimitEnabled(lua_State * L);
int w_RevoluteJoint_setUpperLimit(lua_State * L); int w_RevoluteJoint_setUpperLimit(lua_State * L);
int w_RevoluteJoint_setLowerLimit(lua_State * L); int w_RevoluteJoint_setLowerLimit(lua_State * L);
int w_RevoluteJoint_setLimits(lua_State * L); int w_RevoluteJoint_setLimits(lua_State * L);