mirror of
https://github.com/love2d/love.git
synced 2026-08-19 04:06:17 +02:00
Add EdgeShape:getPoints()
--HG-- branch : box2d-update
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
// Module
|
// Module
|
||||||
#include "Body.h"
|
#include "Body.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
#include "Physics.h"
|
||||||
|
|
||||||
#include <common/Memoizer.h>
|
#include <common/Memoizer.h>
|
||||||
|
|
||||||
@@ -44,6 +45,19 @@ namespace box2d
|
|||||||
shape = NULL;
|
shape = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EdgeShape::getPoints(lua_State * L)
|
||||||
|
{
|
||||||
|
b2EdgeShape * e = (b2EdgeShape *)shape;
|
||||||
|
b2Vec2 v1 = Physics::scaleUp(e->m_vertex1);
|
||||||
|
b2Vec2 v2 = Physics::scaleUp(e->m_vertex2);
|
||||||
|
lua_pushnumber(L, v1.x);
|
||||||
|
lua_pushnumber(L, v1.y);
|
||||||
|
lua_pushnumber(L, v2.x);
|
||||||
|
lua_pushnumber(L, v2.y);
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // box2d
|
} // box2d
|
||||||
} // physics
|
} // physics
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ namespace box2d
|
|||||||
EdgeShape(b2EdgeShape * e);
|
EdgeShape(b2EdgeShape * e);
|
||||||
|
|
||||||
virtual ~EdgeShape();
|
virtual ~EdgeShape();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the transformed points of the edge shape.
|
||||||
|
* This function is useful for debug drawing and such.
|
||||||
|
*
|
||||||
|
* The result can be directly passed into love.graphics.line().
|
||||||
|
**/
|
||||||
|
int getPoints(lua_State * L);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // box2d
|
} // box2d
|
||||||
|
|||||||
@@ -31,7 +31,15 @@ namespace box2d
|
|||||||
return luax_checktype<EdgeShape>(L, idx, "EdgeShape", PHYSICS_EDGE_SHAPE_T);
|
return luax_checktype<EdgeShape>(L, idx, "EdgeShape", PHYSICS_EDGE_SHAPE_T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_EdgeShape_getPoints(lua_State * L)
|
||||||
|
{
|
||||||
|
EdgeShape * t = luax_checkedgeshape(L, 1);
|
||||||
|
lua_remove(L, 1);
|
||||||
|
return t->getPoints(L);
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
|
{ "getPoints", w_EdgeShape_getPoints },
|
||||||
// From Shape.
|
// From Shape.
|
||||||
{ "getType", w_Shape_getType },
|
{ "getType", w_Shape_getType },
|
||||||
{ "getRadius", w_Shape_getRadius },
|
{ "getRadius", w_Shape_getRadius },
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
EdgeShape * luax_checkedgeshape(lua_State * L, int idx);
|
EdgeShape * luax_checkedgeshape(lua_State * L, int idx);
|
||||||
|
int w_EdgeShape_getPoints(lua_State * L);
|
||||||
int luaopen_edgeshape(lua_State * L);
|
int luaopen_edgeshape(lua_State * L);
|
||||||
|
|
||||||
} // box2d
|
} // box2d
|
||||||
|
|||||||
Reference in New Issue
Block a user