Browse Source

Make Fixture creation API more lovely

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
b36ff409aa

+ 0 - 10
src/modules/physics/box2d/Body.cpp

@@ -383,16 +383,6 @@ namespace box2d
 	{
 		return world;
 	}
-	
-	Fixture * Body::createFixture(Shape * shape, float density)
-	{
-		return new Fixture(this, shape, density);
-	}
-	
-	void Body::destroyFixture(Fixture * fixture)
-	{
-		fixture->release();
-	}
 
 	b2Vec2 Body::getVector(lua_State * L)
 	{

+ 0 - 4
src/modules/physics/box2d/Body.h

@@ -373,10 +373,6 @@ namespace box2d
 		* Get the World this Body resides in.
 		*/
 		World * getWorld() const;
-		
-		Fixture * createFixture(Shape * shape, float density);
-		
-		void destroyFixture(Fixture * fixture);
 	private:
 
 		/**

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

@@ -203,6 +203,11 @@ namespace box2d
 		return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
 	}
 	
+	Fixture * Physics::newFixture(Body * body, Shape * shape, float density)
+	{
+		return new Fixture(body, shape, density);
+	}
+	
 	void Physics::setMeter(int meter)
 	{
 		Physics::meter = meter;

+ 47 - 39
src/modules/physics/box2d/Physics.h

@@ -250,74 +250,82 @@ namespace box2d
 		RopeJoint * newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
 		
 		/**
-		 * Sets the number of pixels in one meter.
-		 * @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
-		 **/
+		* Creates a new Fixture attaching shape to body.
+		* @param body The body to attach the Fixture to.
+		* @param shape The shape to attach to the Fixture,
+		* @param density The density of the Fixture.
+		**/
+		
+		Fixture * newFixture(Body * body, Shape * shape, float density);
+		
+		/**
+		* Sets the number of pixels in one meter.
+		* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
+		**/
 		static void setMeter(int meter);
 		
 		/**
-		 * Gets the number of pixels in one meter.
-		 * @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
-		 **/
+		* Gets the number of pixels in one meter.
+		* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
+		**/
 		static int getMeter();
 		
 		/**
-		 * Scales a value down according to the current meter in pixels.
-		 * @param f The unscaled input value.
-		 **/
+		* Scales a value down according to the current meter in pixels.
+		* @param f The unscaled input value.
+		**/
 		static float scaleDown(float f);
 		
 		/**
-		 * Scales a value up according to the current meter in pixels.
-		 * @param f The unscaled input value.
-		 **/
+		* Scales a value up according to the current meter in pixels.
+		* @param f The unscaled input value.
+		**/
 		static float scaleUp(float f);
 		
 		/**
-		 * Scales a point down according to the current meter
-		 * in pixels, for instance x = x0/meter, y = x0/meter.
-		 * @param x The x-coordinate of the point to scale.
-		 * @param y The y-coordinate of the point to scale.
-		 **/
+		* Scales a point down according to the current meter
+		* in pixels, for instance x = x0/meter, y = x0/meter.
+		* @param x The x-coordinate of the point to scale.
+		* @param y The y-coordinate of the point to scale.
+		**/
 		static void scaleDown(float & x, float & y);
 		
 		/**
-		 * Scales a point up according to the current meter
-		 * in pixels, for instance x = x0/meter, y = x0/meter.
-		 * @param x The x-coordinate of the point to scale.
-		 * @param y The y-coordinate of the point to scale.
-		 **/
+		* Scales a point up according to the current meter
+		* in pixels, for instance x = x0/meter, y = x0/meter.
+		* @param x The x-coordinate of the point to scale.
+		* @param y The y-coordinate of the point to scale.
+		**/
 		static void scaleUp(float & x, float & y);
 		
 		/**
-		 * Scales a b2Vec2 down according to the current meter in pixels.
-		 * @param v The unscaled input vector.
-		 * @return The scaled vector.
-		 **/
+		* Scales a b2Vec2 down according to the current meter in pixels.
+		* @param v The unscaled input vector.
+		* @return The scaled vector.
+		**/
 		static b2Vec2 scaleDown(const b2Vec2 & v);
 		
 		/**
-		 * Scales a b2Vec up according to the current meter in pixels.
-		 * @param v The unscaled input vector.
-		 * @return The scaled vector.
-		 **/
+		* Scales a b2Vec up according to the current meter in pixels.
+		* @param v The unscaled input vector.
+		* @return The scaled vector.
+		**/
 		static b2Vec2 scaleUp(const b2Vec2 & v);
 		
 		/**
-		 * Scales a b2AABB down according to the current meter in pixels.
-		 * @param v The unscaled input AABB.
-		 * @return The scaled AABB.
-		 **/
+		* Scales a b2AABB down according to the current meter in pixels.
+		* @param v The unscaled input AABB.
+		* @return The scaled AABB.
+		**/
 		static b2AABB scaleDown(const b2AABB & aabb);
 		
 		/**
-		 * Scales a b2AABB up according to the current meter in pixels.
-		 * @param v The unscaled input AABB.
-		 * @return The scaled AABB.
-		 **/
+		* Scales a b2AABB up according to the current meter in pixels.
+		* @param v The unscaled input AABB.
+		* @return The scaled AABB.
+		**/
 		static b2AABB scaleUp(const b2AABB & aabb);
 
-
 	}; // Physics
 
 } // box2d

+ 0 - 20
src/modules/physics/box2d/wrap_Body.cpp

@@ -499,24 +499,6 @@ namespace box2d
 		luax_pushboolean(L, b);
 		return 1;
 	}
-	
-	int w_Body_createFixture(lua_State * L)
-	{
-		Body * t = luax_checkbody(L, 1);
-		Shape * s = luax_checktype<Shape>(L, 2, "Shape", PHYSICS_SHAPE_T);
-		float d = (float)luaL_checknumber(L, 3);
-		Fixture * f = t->createFixture(s, d);
-		luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)f);
-		return 1;
-	}
-	
-	int w_Body_destroyFixture(lua_State * L)
-	{
-		Body * t = luax_checkbody(L, 1);
-		Fixture * f = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
-		t->destroyFixture(f);
-		return 0;
-	}
 
 	int w_Body_destroy(lua_State * L)
 	{
@@ -579,8 +561,6 @@ namespace box2d
 		{ "setAwake", w_Body_setAwake },
 		{ "setFixedRotation", w_Body_setFixedRotation },
 		{ "isFixedRotation", w_Body_isFixedRotation },
-		{ "createFixture", w_Body_createFixture },
-		{ "destroyFixture", w_Body_destroyFixture },
 		{ "destroy", w_Body_destroy },
 		{ 0, 0 }
 	};

+ 0 - 2
src/modules/physics/box2d/wrap_Body.h

@@ -82,8 +82,6 @@ namespace box2d
 	int w_Body_setAwake(lua_State * L);
 	int w_Body_setFixedRotation(lua_State * L);
 	int w_Body_isFixedRotation(lua_State * L);
-	int w_Body_createFixture(lua_State * L);
-	int w_Body_destroyFixture(lua_State * L);
 	int w_Body_destroy(lua_State * L);
 	int luaopen_body(lua_State * L);
 

+ 11 - 0
src/modules/physics/box2d/wrap_Physics.cpp

@@ -54,6 +54,16 @@ namespace box2d
 		luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
 		return 1;
 	}
+	
+	int w_newFixture(lua_State * L)
+	{
+		Body * body = luax_checkbody(L, 1);
+		Shape * shape = luax_checkshape(L, 2);
+		float density = (float)luaL_checknumber(L, 3);
+		Fixture * fixture = instance->newFixture(body, shape, density);
+		luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture);
+		return 1;
+	}
 
 	int w_newCircleShape(lua_State * L)
 	{
@@ -279,6 +289,7 @@ namespace box2d
 	static const luaL_Reg functions[] = {
 		{ "newWorld", w_newWorld },
 		{ "newBody", w_newBody },
+		{ "newFixture", w_newFixture },
 		{ "newCircleShape", w_newCircleShape },
 		{ "newRectangleShape", w_newRectangleShape },
 		{ "newPolygonShape", w_newPolygonShape },

+ 1 - 0
src/modules/physics/box2d/wrap_Physics.h

@@ -53,6 +53,7 @@ namespace box2d
 {
 	int w_newWorld(lua_State * L);
 	int w_newBody(lua_State * L);
+	int w_newFixture(lua_State * L);
 	int w_newCircleShape(lua_State * L);
 	int w_newRectangleShape(lua_State * L);
 	int w_newPolygonShape(lua_State * L);