World no longer has an explicit size

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-23 16:27:59 -04:00
parent a956f9b0c1
commit 4980797afc
5 changed files with 24 additions and 39 deletions
+3 -5
View File
@@ -39,12 +39,10 @@ namespace box2d
return "love.physics.box2d"; return "love.physics.box2d";
} }
World * Physics::newWorld(float lx, float ly, float ux, float uy, float gx, float gy, bool sleep, int meter) World * Physics::newWorld(float gx, float gy, bool sleep, int meter)
{ {
b2AABB aabb; Physics::setMeter(meter);
aabb.lowerBound.Set(lx, ly); return new World(b2Vec2(gx, gy), sleep);
aabb.upperBound.Set(ux, uy);
return new World(aabb, b2Vec2(gx, gy), sleep, meter);
} }
Body * Physics::newBody(World * world, float x, float y, float mass, float i) Body * Physics::newBody(World * world, float x, float y, float mass, float i)
+6 -5
View File
@@ -58,21 +58,22 @@ namespace box2d
public: public:
/**
* 30 pixels in one meter by default.
**/
static const int DEFAULT_METER = 30;
// Implements Module. // Implements Module.
const char * getName() const; const char * getName() const;
/** /**
* Creates a new World. * Creates a new World.
* @param lx Lower bound on the x-axis.
* @param ly Lower bound on the y-axis.
* @param ux Upper bound on the x-axis.
* @param uy Upper bound on the y-axis.
* @param gx Gravity along x-axis. * @param gx Gravity along x-axis.
* @param gy Gravity along y-axis. * @param gy Gravity along y-axis.
* @param sleep Whether the World allows sleep. * @param sleep Whether the World allows sleep.
* @param meter The scale in px/m. * @param meter The scale in px/m.
**/ **/
World * newWorld(float lx, float ly, float ux, float uy, float gx, float gy, bool sleep, int meter); World * newWorld(float gx, float gy, bool sleep, int meter);
/** /**
* Creates a new Body at the specified position. * Creates a new Body at the specified position.
+6 -6
View File
@@ -96,19 +96,19 @@ namespace box2d
} }
World::World(b2AABB aabb) World::World()
: world(NULL), meter(DEFAULT_METER) : world(NULL)
{ {
world = new b2World(Physics::scaleDown(aabb), b2Vec2(0,0), true); world = new b2World(b2Vec2(0,0), true);
world->SetContactListener(this); world->SetContactListener(this);
b2BodyDef def; b2BodyDef def;
groundBody = world->CreateBody(def); groundBody = world->CreateBody(def);
} }
World::World(b2AABB aabb, b2Vec2 gravity, bool sleep, int meter) World::World(b2Vec2 gravity, bool sleep)
: world(NULL), meter(meter) : world(NULL)
{ {
world = new b2World(Physics::scaleDown(aabb), Physics::scaleDown(gravity), sleep); world = new b2World(Physics::scaleDown(gravity), sleep);
world->SetContactListener(this); world->SetContactListener(this);
} }
+4 -11
View File
@@ -87,25 +87,18 @@ namespace box2d
public: public:
/** /**
* 30 pixels in one meter by default. * Creates a new world.
**/ **/
static const int DEFAULT_METER = 30; World();
/** /**
* Creates a new world with the given bounding box. * Creates a new world with the given gravity
* @param aabb The bounding box.
**/
World(b2AABB aabb);
/**
* Creates a new world with the given bounding box, gravity
* and whether or not the bodies should sleep when appropriate. * and whether or not the bodies should sleep when appropriate.
* @param aabb The bounding box.
* @param gravity The gravity of the World. * @param gravity The gravity of the World.
* @param sleep True if the bodies should be able to sleep, * @param sleep True if the bodies should be able to sleep,
* false otherwise. * false otherwise.
**/ **/
World(b2AABB aabb, b2Vec2 gravity, bool sleep, int meter = DEFAULT_METER); World(b2Vec2 gravity, bool sleep);
virtual ~World(); virtual ~World();
+5 -12
View File
@@ -31,19 +31,12 @@ namespace box2d
int w_newWorld(lua_State * L) int w_newWorld(lua_State * L)
{ {
if (lua_gettop(L) < 4) float gx = (float)luaL_optnumber(L, 1, 0);
return luaL_error(L, "Incorrect number of parameters"); float gy = (float)luaL_optnumber(L, 2, 0);
bool sleep = luax_optboolean(L, 3, true);
int meter = (int)luaL_optnumber(L, 4, Physics::DEFAULT_METER);
float lx = (float)luaL_checknumber(L, 1); World * w = instance->newWorld(gx, gy, sleep, meter);
float ly = (float)luaL_checknumber(L, 2);
float ux = (float)luaL_checknumber(L, 3);
float uy = (float)luaL_checknumber(L, 4);
float gx = (float)luaL_optnumber(L, 5, 0);
float gy = (float)luaL_optnumber(L, 6, 0);
bool sleep = luax_optboolean(L, 7, true);
int meter = (int)luaL_optnumber(L, 8, World::DEFAULT_METER);
World * w = instance->newWorld(lx, ly, ux, uy, gx, gy, sleep, meter);
luax_newtype(L, "World", PHYSICS_WORLD_T, (void*)w); luax_newtype(L, "World", PHYSICS_WORLD_T, (void*)w);
return 1; return 1;