updating the Joints

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-03-13 13:16:02 -04:00
parent be146c5f61
commit b4fae893fd
20 changed files with 50 additions and 205 deletions
+6 -6
View File
@@ -46,32 +46,32 @@ namespace box2d
void DistanceJoint::setLength(float length)
{
joint->m_length = world->scaleDown(length);
joint->SetLength(world->scaleDown(length));
}
float DistanceJoint::getLength() const
{
return world->scaleUp(joint->m_length);
return world->scaleUp(joint->GetLength());
}
void DistanceJoint::setFrequency(float hz)
{
joint->m_frequencyHz = hz;
joint->SetFrequency(hz);
}
float DistanceJoint::getFrequency() const
{
return joint->m_frequencyHz;
return joint->GetFrequency();
}
void DistanceJoint::setDampingRatio(float d)
{
joint->m_dampingRatio = d;
joint->SetDampingRatio(d);
}
float DistanceJoint::getDampingRatio() const
{
return joint->m_dampingRatio;
return joint->GetDampingRatio();
}
+4 -4
View File
@@ -36,8 +36,8 @@ namespace box2d
b2GearJointDef def;
def.joint1 = joint1->joint;
def.joint2 = joint2->joint;
def.body1 = joint1->body2->body;
def.body2 = joint2->body2->body;
def.bodyA = joint1->body2->body;
def.bodyB = joint2->body2->body;
def.ratio = ratio;
joint = (b2GearJoint*)createJoint(&def);
@@ -51,12 +51,12 @@ namespace box2d
void GearJoint::setRatio(float ratio)
{
joint->m_ratio = ratio;
joint->SetRatio(ratio);
}
float GearJoint::getRatio() const
{
return joint->m_ratio;
return joint->GetRatio();
}
} // box2d
+8 -17
View File
@@ -79,34 +79,25 @@ namespace box2d
int Joint::getAnchors(lua_State * L)
{
lua_pushnumber(L, world->scaleUp(joint->GetAnchor1().x));
lua_pushnumber(L, world->scaleUp(joint->GetAnchor1().y));
lua_pushnumber(L, world->scaleUp(joint->GetAnchor2().x));
lua_pushnumber(L, world->scaleUp(joint->GetAnchor2().y));
lua_pushnumber(L, world->scaleUp(joint->GetAnchorA().x));
lua_pushnumber(L, world->scaleUp(joint->GetAnchorA().y));
lua_pushnumber(L, world->scaleUp(joint->GetAnchorB().x));
lua_pushnumber(L, world->scaleUp(joint->GetAnchorB().y));
return 4;
}
int Joint::getReactionForce(lua_State * L)
{
b2Vec2 v = joint->GetReactionForce();
float dt = (float)luaL_checknumber(L, 2);
b2Vec2 v = joint->GetReactionForce(dt);
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;
}
float Joint::getReactionTorque()
float Joint::getReactionTorque(float dt)
{
return joint->GetReactionTorque();
}
void Joint::setCollideConnected(bool collide)
{
joint->m_collideConnected = collide;
}
bool Joint::getCollideConnected() const
{
return joint->m_collideConnected;
return joint->GetReactionTorque(dt);
}
b2Joint * Joint::createJoint(b2JointDef * def)
+1 -13
View File
@@ -97,19 +97,7 @@ namespace box2d
/**
* Gets the reaction torque on body2.
**/
float getReactionTorque();
/**
* Sets whether connected bodies should collide
* or not. Default is false.
**/
void setCollideConnected(bool collide);
/**
* Gets whether connected bodies should collide
* or not.
**/
bool getCollideConnected() const;
float getReactionTorque(float dt);
protected:
+6 -6
View File
@@ -35,8 +35,8 @@ namespace box2d
{
b2MouseJointDef def;
def.body1 = body1->world->world->GetGroundBody();
def.body2 = body1->body;
def.bodyA = body1->world->getGroundBody();
def.bodyB = body1->body;
def.maxForce = 1000.0f * body1->body->GetMass();
def.target = body1->world->scaleDown(b2Vec2(x,y));
joint = (b2MouseJoint*)createJoint(&def);
@@ -55,19 +55,19 @@ namespace box2d
int MouseJoint::getTarget(lua_State * L)
{
lua_pushnumber(L, world->scaleUp(joint->m_target.x));
lua_pushnumber(L, world->scaleUp(joint->m_target.y));
lua_pushnumber(L, world->scaleUp(joint->GetTarget().x));
lua_pushnumber(L, world->scaleUp(joint->GetTarget().y));
return 2;
}
void MouseJoint::setMaxForce(float force)
{
joint->m_maxForce = force;
joint->SetMaxForce(force);
}
float MouseJoint::getMaxForce() const
{
return joint->m_maxForce;
return joint->GetMaxForce();
}
} // box2d
+1 -1
View File
@@ -131,7 +131,7 @@ namespace box2d
if(count < 3)
return luaL_error(L, "Polygon degenerated to less than three points.");
b2vec2 vecs[] = new b2vec2[count];
b2Vec2 vecs[] = new b2vec2[count];
for (int i = 0; i < count; i++) {
vecs[i].Set(convex_hull[i].x, convex_hull[i].y);
+1 -6
View File
@@ -72,12 +72,7 @@ namespace box2d
{
joint->SetMaxMotorForce(force);
}
float PrismaticJoint::getMaxMotorForce() const
{
return joint->m_maxMotorForce;
}
void PrismaticJoint::setMotorSpeed(float speed)
{
joint->SetMotorSpeed(speed);
@@ -75,11 +75,6 @@ namespace box2d
**/
void setMaxMotorForce(float force);
/**
* Get the current motor force, usually in N.
**/
float getMaxMotorForce() const;
/**
* Set the motor speed, usually in meters per second.
**/
+5 -46
View File
@@ -48,49 +48,13 @@ namespace box2d
int PulleyJoint::getGroundAnchors(lua_State * L)
{
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchor1().x));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchor1().y));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchor2().x));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchor2().y));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchorA().x));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchorA().y));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchorB().x));
lua_pushnumber(L, world->scaleUp(joint->GetGroundAnchorB().y));
return 4;
}
void PulleyJoint::setMaxLengths(float maxlength1, float maxlength2)
{
// Apply Box2D's maximum lengths too. They know better.
if (maxlength1 > 0)
{
joint->m_maxLength1 = b2Min(world->scaleDown(maxlength1), joint->m_constant - joint->m_ratio * b2_minPulleyLength);
}
if (maxlength2 > 0)
{
joint->m_maxLength2 = b2Min(world->scaleDown(maxlength2), (joint->m_constant - b2_minPulleyLength) / joint->m_ratio);
}
}
int PulleyJoint::getMaxLengths(lua_State * L)
{
lua_pushnumber(L, world->scaleUp(joint->m_maxLength1));
lua_pushnumber(L, world->scaleUp(joint->m_maxLength2));
return 2;
}
void PulleyJoint::setConstant(float constant)
{
joint->m_constant = world->scaleDown(constant);
// Update the max lengths, as does Box2D
joint->m_maxLength1 = joint->m_constant - joint->m_ratio * b2_minPulleyLength;
joint->m_maxLength2 = (joint->m_constant - b2_minPulleyLength) / joint->m_ratio;
}
float PulleyJoint::getConstant() const
{
return world->scaleUp(joint->m_constant);
}
float PulleyJoint::getLength1() const
{
return world->scaleUp(joint->GetLength1());
@@ -101,14 +65,9 @@ namespace box2d
return world->scaleUp(joint->GetLength2());
}
void PulleyJoint::setRatio(float ratio)
{
joint->m_ratio = ratio;
}
float PulleyJoint::getRatio() const
{
return joint->m_ratio;
return joint->GetRatio();
}
} // box2d
-23
View File
@@ -56,29 +56,6 @@ namespace box2d
**/
int getGroundAnchors(lua_State * L);
/**
* Sets the max rope lengths (a value of zero keeps it
* unchanged). Beware that Box2D also imposes a maximum,
* so the smallest of these is actually set.
**/
void setMaxLengths(float maxlength1, float maxlength2);
/**
* Gets the max rope lengths.
**/
int getMaxLengths(lua_State * L);
/**
* Sets the total length of the rope and updates the
* MaxLengths values accordingly.
**/
void setConstant(float length);
/**
* Gets the total length of the rope.
**/
float getConstant() const;
/**
* Gets the current length of the segment attached to body1.
**/
+1 -6
View File
@@ -70,12 +70,7 @@ namespace box2d
{
joint->SetMaxMotorTorque(torque);
}
float RevoluteJoint::getMaxMotorTorque() const
{
return joint->m_maxMotorTorque;
}
void RevoluteJoint::setMotorSpeed(float speed)
{
joint->SetMotorSpeed(speed);
@@ -75,11 +75,6 @@ namespace box2d
**/
void setMaxMotorTorque(float torque);
/**
* Gets the maximum motor torque, usually in N-m.
**/
float getMaxMotorTorque() const;
/**
* Sets the motor speed in degrees per second.
**/
+8
View File
@@ -100,6 +100,8 @@ namespace box2d
{
world = new b2World(scaleDown(aabb), b2Vec2(0,0), true);
world->SetContactListener(this);
b2BodyDef def;
groundBody = world->CreateBody(def);
}
World::World(b2AABB aabb, b2Vec2 gravity, bool sleep, int meter)
@@ -111,6 +113,7 @@ namespace box2d
World::~World()
{
world->DestroyBody(groundBody);
delete world;
}
@@ -272,6 +275,11 @@ namespace box2d
t.upperBound = scaleUp(aabb.upperBound);
return t;
}
b2Body * World::getGroundBody()
{
return groundBody;
}
} // box2d
} // physics
+9
View File
@@ -77,6 +77,9 @@ namespace box2d
// Pointer to the Box2D world.
b2World * world;
// Ground body
b2Body * groundBody;
// Contact callbacks.
ContactCallback add, persist, remove, result;
@@ -241,6 +244,12 @@ namespace box2d
* @return The scaled AABB.
**/
b2AABB scaleUp(const b2AABB & aabb);
/**
* Gets the ground body.
* @return The ground body.
**/
b2Body * getGroundBody();
};
@@ -68,13 +68,6 @@ namespace box2d
return 0;
}
int w_PrismaticJoint_getMaxMotorForce(lua_State * L)
{
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
lua_pushnumber(L, t->getMaxMotorForce());
return 1;
}
int w_PrismaticJoint_setMotorSpeed(lua_State * L)
{
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
@@ -164,7 +157,6 @@ namespace box2d
{ "setMotorEnabled", w_PrismaticJoint_setMotorEnabled },
{ "isMotorEnabled", w_PrismaticJoint_isMotorEnabled },
{ "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce },
{ "getMaxMotorForce", w_PrismaticJoint_getMaxMotorForce },
{ "setMotorSpeed", w_PrismaticJoint_setMotorSpeed },
{ "getMotorSpeed", w_PrismaticJoint_getMotorSpeed },
{ "getMotorForce", w_PrismaticJoint_getMotorForce },
@@ -38,7 +38,6 @@ namespace box2d
int w_PrismaticJoint_setMotorEnabled(lua_State * L);
int w_PrismaticJoint_isMotorEnabled(lua_State * L);
int w_PrismaticJoint_setMaxMotorForce(lua_State * L);
int w_PrismaticJoint_getMaxMotorForce(lua_State * L);
int w_PrismaticJoint_setMotorSpeed(lua_State * L);
int w_PrismaticJoint_getMotorSpeed(lua_State * L);
int w_PrismaticJoint_getMotorForce(lua_State * L);
@@ -37,37 +37,6 @@ namespace box2d
lua_remove(L, 1);
return t->getGroundAnchors(L);
}
int w_PulleyJoint_setMaxLengths(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
float arg1 = (float)luaL_optnumber(L, 2, 0.0);
float arg2 = (float)luaL_optnumber(L, 3, 0.0);
t->setMaxLengths(arg1, arg2);
return 0;
}
int w_PulleyJoint_getMaxLengths(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
lua_remove(L, 1);
return t->getMaxLengths(L);
}
int w_PulleyJoint_setConstant(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setConstant(arg1);
return 0;
}
int w_PulleyJoint_getConstant(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
lua_pushnumber(L, t->getConstant());
return 1;
}
int w_PulleyJoint_getLength1(lua_State * L)
{
@@ -83,14 +52,6 @@ namespace box2d
return 1;
}
int w_PulleyJoint_setRatio(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setRatio(arg1);
return 0;
}
int w_PulleyJoint_getRatio(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
@@ -100,13 +61,8 @@ namespace box2d
static const luaL_Reg functions[] = {
{ "getGroundAnchors", w_PulleyJoint_getGroundAnchors },
{ "setMaxLengths", w_PulleyJoint_setMaxLengths },
{ "getMaxLengths", w_PulleyJoint_getMaxLengths },
{ "setConstant", w_PulleyJoint_setConstant },
{ "getConstant", w_PulleyJoint_getConstant },
{ "getLength1", w_PulleyJoint_getLength1 },
{ "getLength2", w_PulleyJoint_getLength2 },
{ "setRatio", w_PulleyJoint_setRatio },
{ "getRatio", w_PulleyJoint_getRatio },
// From Joint.
{ "getType", w_Joint_getType },
@@ -34,13 +34,8 @@ namespace box2d
{
PulleyJoint * luax_checkpulleyjoint(lua_State * L, int idx);
int w_PulleyJoint_getGroundAnchors(lua_State * L);
int w_PulleyJoint_setMaxLengths(lua_State * L);
int w_PulleyJoint_getMaxLengths(lua_State * L);
int w_PulleyJoint_setConstant(lua_State * L);
int w_PulleyJoint_getConstant(lua_State * L);
int w_PulleyJoint_getLength1(lua_State * L);
int w_PulleyJoint_getLength2(lua_State * L);
int w_PulleyJoint_setRatio(lua_State * L);
int w_PulleyJoint_getRatio(lua_State * L);
int luaopen_pulleyjoint(lua_State * L);
@@ -68,13 +68,6 @@ namespace box2d
return 0;
}
int w_RevoluteJoint_getMaxMotorTorque(lua_State * L)
{
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
lua_pushnumber(L, t->getMaxMotorTorque());
return 1;
}
int w_RevoluteJoint_setMotorSpeed(lua_State * L)
{
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
@@ -164,7 +157,6 @@ namespace box2d
{ "setMotorEnabled", w_RevoluteJoint_setMotorEnabled },
{ "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
{ "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
{ "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque },
{ "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
{ "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
{ "getMotorTorque", w_RevoluteJoint_getMotorTorque },
@@ -38,7 +38,6 @@ namespace box2d
int w_RevoluteJoint_setMotorEnabled(lua_State * L);
int w_RevoluteJoint_isMotorEnabled(lua_State * L);
int w_RevoluteJoint_setMaxMotorTorque(lua_State * L);
int w_RevoluteJoint_getMaxMotorTorque(lua_State * L);
int w_RevoluteJoint_setMotorSpeed(lua_State * L);
int w_RevoluteJoint_getMotorSpeed(lua_State * L);
int w_RevoluteJoint_getMotorTorque(lua_State * L);