mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Make Fixture creation API more lovely
--HG-- branch : box2d-update
This commit is contained in:
@@ -384,16 +384,6 @@ namespace box2d
|
|||||||
return world;
|
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)
|
b2Vec2 Body::getVector(lua_State * L)
|
||||||
{
|
{
|
||||||
love::luax_assert_argc(L, 2, 2);
|
love::luax_assert_argc(L, 2, 2);
|
||||||
|
|||||||
@@ -373,10 +373,6 @@ namespace box2d
|
|||||||
* Get the World this Body resides in.
|
* Get the World this Body resides in.
|
||||||
*/
|
*/
|
||||||
World * getWorld() const;
|
World * getWorld() const;
|
||||||
|
|
||||||
Fixture * createFixture(Shape * shape, float density);
|
|
||||||
|
|
||||||
void destroyFixture(Fixture * fixture);
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -203,6 +203,11 @@ namespace box2d
|
|||||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
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)
|
void Physics::setMeter(int meter)
|
||||||
{
|
{
|
||||||
Physics::meter = meter;
|
Physics::meter = meter;
|
||||||
|
|||||||
@@ -250,74 +250,82 @@ namespace box2d
|
|||||||
RopeJoint * newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
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.
|
* Creates a new Fixture attaching shape to body.
|
||||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
* @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);
|
static void setMeter(int meter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of pixels in one meter.
|
* Gets the number of pixels in one meter.
|
||||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||||
**/
|
**/
|
||||||
static int getMeter();
|
static int getMeter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a value down according to the current meter in pixels.
|
* Scales a value down according to the current meter in pixels.
|
||||||
* @param f The unscaled input value.
|
* @param f The unscaled input value.
|
||||||
**/
|
**/
|
||||||
static float scaleDown(float f);
|
static float scaleDown(float f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a value up according to the current meter in pixels.
|
* Scales a value up according to the current meter in pixels.
|
||||||
* @param f The unscaled input value.
|
* @param f The unscaled input value.
|
||||||
**/
|
**/
|
||||||
static float scaleUp(float f);
|
static float scaleUp(float f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a point down according to the current meter
|
* Scales a point down according to the current meter
|
||||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||||
* @param x The x-coordinate of the point to scale.
|
* @param x The x-coordinate of the point to scale.
|
||||||
* @param y The y-coordinate of the point to scale.
|
* @param y The y-coordinate of the point to scale.
|
||||||
**/
|
**/
|
||||||
static void scaleDown(float & x, float & y);
|
static void scaleDown(float & x, float & y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a point up according to the current meter
|
* Scales a point up according to the current meter
|
||||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||||
* @param x The x-coordinate of the point to scale.
|
* @param x The x-coordinate of the point to scale.
|
||||||
* @param y The y-coordinate of the point to scale.
|
* @param y The y-coordinate of the point to scale.
|
||||||
**/
|
**/
|
||||||
static void scaleUp(float & x, float & y);
|
static void scaleUp(float & x, float & y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a b2Vec2 down according to the current meter in pixels.
|
* Scales a b2Vec2 down according to the current meter in pixels.
|
||||||
* @param v The unscaled input vector.
|
* @param v The unscaled input vector.
|
||||||
* @return The scaled vector.
|
* @return The scaled vector.
|
||||||
**/
|
**/
|
||||||
static b2Vec2 scaleDown(const b2Vec2 & v);
|
static b2Vec2 scaleDown(const b2Vec2 & v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a b2Vec up according to the current meter in pixels.
|
* Scales a b2Vec up according to the current meter in pixels.
|
||||||
* @param v The unscaled input vector.
|
* @param v The unscaled input vector.
|
||||||
* @return The scaled vector.
|
* @return The scaled vector.
|
||||||
**/
|
**/
|
||||||
static b2Vec2 scaleUp(const b2Vec2 & v);
|
static b2Vec2 scaleUp(const b2Vec2 & v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a b2AABB down according to the current meter in pixels.
|
* Scales a b2AABB down according to the current meter in pixels.
|
||||||
* @param v The unscaled input AABB.
|
* @param v The unscaled input AABB.
|
||||||
* @return The scaled AABB.
|
* @return The scaled AABB.
|
||||||
**/
|
**/
|
||||||
static b2AABB scaleDown(const b2AABB & aabb);
|
static b2AABB scaleDown(const b2AABB & aabb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scales a b2AABB up according to the current meter in pixels.
|
* Scales a b2AABB up according to the current meter in pixels.
|
||||||
* @param v The unscaled input AABB.
|
* @param v The unscaled input AABB.
|
||||||
* @return The scaled AABB.
|
* @return The scaled AABB.
|
||||||
**/
|
**/
|
||||||
static b2AABB scaleUp(const b2AABB & aabb);
|
static b2AABB scaleUp(const b2AABB & aabb);
|
||||||
|
|
||||||
|
|
||||||
}; // Physics
|
}; // Physics
|
||||||
|
|
||||||
} // box2d
|
} // box2d
|
||||||
|
|||||||
@@ -500,24 +500,6 @@ namespace box2d
|
|||||||
return 1;
|
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)
|
int w_Body_destroy(lua_State * L)
|
||||||
{
|
{
|
||||||
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
||||||
@@ -579,8 +561,6 @@ namespace box2d
|
|||||||
{ "setAwake", w_Body_setAwake },
|
{ "setAwake", w_Body_setAwake },
|
||||||
{ "setFixedRotation", w_Body_setFixedRotation },
|
{ "setFixedRotation", w_Body_setFixedRotation },
|
||||||
{ "isFixedRotation", w_Body_isFixedRotation },
|
{ "isFixedRotation", w_Body_isFixedRotation },
|
||||||
{ "createFixture", w_Body_createFixture },
|
|
||||||
{ "destroyFixture", w_Body_destroyFixture },
|
|
||||||
{ "destroy", w_Body_destroy },
|
{ "destroy", w_Body_destroy },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ namespace box2d
|
|||||||
int w_Body_setAwake(lua_State * L);
|
int w_Body_setAwake(lua_State * L);
|
||||||
int w_Body_setFixedRotation(lua_State * L);
|
int w_Body_setFixedRotation(lua_State * L);
|
||||||
int w_Body_isFixedRotation(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 w_Body_destroy(lua_State * L);
|
||||||
int luaopen_body(lua_State * L);
|
int luaopen_body(lua_State * L);
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ namespace box2d
|
|||||||
return 1;
|
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)
|
int w_newCircleShape(lua_State * L)
|
||||||
{
|
{
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
@@ -279,6 +289,7 @@ namespace box2d
|
|||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
{ "newWorld", w_newWorld },
|
{ "newWorld", w_newWorld },
|
||||||
{ "newBody", w_newBody },
|
{ "newBody", w_newBody },
|
||||||
|
{ "newFixture", w_newFixture },
|
||||||
{ "newCircleShape", w_newCircleShape },
|
{ "newCircleShape", w_newCircleShape },
|
||||||
{ "newRectangleShape", w_newRectangleShape },
|
{ "newRectangleShape", w_newRectangleShape },
|
||||||
{ "newPolygonShape", w_newPolygonShape },
|
{ "newPolygonShape", w_newPolygonShape },
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace box2d
|
|||||||
{
|
{
|
||||||
int w_newWorld(lua_State * L);
|
int w_newWorld(lua_State * L);
|
||||||
int w_newBody(lua_State * L);
|
int w_newBody(lua_State * L);
|
||||||
|
int w_newFixture(lua_State * L);
|
||||||
int w_newCircleShape(lua_State * L);
|
int w_newCircleShape(lua_State * L);
|
||||||
int w_newRectangleShape(lua_State * L);
|
int w_newRectangleShape(lua_State * L);
|
||||||
int w_newPolygonShape(lua_State * L);
|
int w_newPolygonShape(lua_State * L);
|
||||||
|
|||||||
Reference in New Issue
Block a user