Add type to Body constructor (defaults to "static")

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-24 02:15:46 -04:00
parent 5f4b4c8838
commit 8592b98525
5 changed files with 15 additions and 9 deletions
+2 -1
View File
@@ -33,13 +33,14 @@ namespace physics
{
namespace box2d
{
Body::Body(World * world, b2Vec2 p)
Body::Body(World * world, b2Vec2 p, Body::Type type)
: world(world)
{
world->retain();
b2BodyDef def;
def.position = Physics::scaleDown(p);
body = world->world->CreateBody(&def);
this->setType(type);
}
Body::~Body()
+1 -1
View File
@@ -75,7 +75,7 @@ namespace box2d
/**
* Create a Body at position p.
**/
Body(World * world, b2Vec2 p);
Body(World * world, b2Vec2 p, Type type);
virtual ~Body();
+4 -4
View File
@@ -47,14 +47,14 @@ namespace box2d
return new World(b2Vec2(gx, gy), sleep);
}
Body * Physics::newBody(World * world, float x, float y)
Body * Physics::newBody(World * world, float x, float y, Body::Type type)
{
return new Body(world, b2Vec2(x, y));
return new Body(world, b2Vec2(x, y), type);
}
Body * Physics::newBody(World * world)
Body * Physics::newBody(World * world, Body::Type type)
{
return new Body(world, b2Vec2(0, 0));
return new Body(world, b2Vec2(0, 0), type);
}
CircleShape * Physics::newCircleShape(float radius)
+4 -2
View File
@@ -81,14 +81,16 @@ namespace box2d
* @param world The world to create the Body in.
* @param x The position along the x-axis.
* @param x The position along the y-axis.
* @param type The type of body to create.
**/
Body * newBody(World * world, float x, float y);
Body * newBody(World * world, float x, float y, Body::Type type);
/**
* Creates a new Body at (0, 0)
* @param world The world to create the Body in.
* @param type The type of Body to create.
**/
Body * newBody(World * world);
Body * newBody(World * world, Body::Type type);
/**
* Creates a new CircleShape at (0, 0).
+4 -1
View File
@@ -47,7 +47,10 @@ namespace box2d
World * world = luax_checktype<World>(L, 1, "World", PHYSICS_WORLD_T);
float x = (float)luaL_optnumber(L, 2, 0.0);
float y = (float)luaL_optnumber(L, 3, 0.0);
Body * body = instance->newBody(world, x, y);
const char * type = luaL_optstring(L, 4, "static");
Body::Type bodyType;
Body::getConstant(type, bodyType);
Body * body = instance->newBody(world, x, y, bodyType);
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
return 1;
}