Shape:getAABB;

This commit is contained in:
bjorn 2017-05-24 17:47:59 -07:00
parent f3df7aa114
commit 876a8406b1
3 changed files with 21 additions and 5 deletions

View File

@ -160,12 +160,12 @@ int l_lovrShapeSetMask(lua_State* L) {
return 0;
}
int l_lovrShapeComputeMass(lua_State* L) {
int l_lovrShapeGetMass(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
float density = luaL_checknumber(L, 2);
float cx, cy, cz, mass;
float inertia[6];
lovrShapeComputeMass(shape, density, &cx, &cy, &cz, &mass, inertia);
lovrShapeGetMass(shape, density, &cx, &cy, &cz, &mass, inertia);
lua_pushnumber(L, cx);
lua_pushnumber(L, cy);
lua_pushnumber(L, cz);
@ -178,6 +178,16 @@ int l_lovrShapeComputeMass(lua_State* L) {
return 5;
}
int l_lovrShapeGetAABB(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
float aabb[6];
lovrShapeGetAABB(shape, aabb);
for (int i = 0; i < 6; i++) {
lua_pushnumber(L, aabb[i]);
}
return 6;
}
const luaL_Reg lovrShape[] = {
{ "destroy", l_lovrShapeDestroy },
{ "getType", l_lovrShapeGetType },
@ -194,7 +204,8 @@ const luaL_Reg lovrShape[] = {
{ "setCategory", l_lovrShapeSetCategory },
{ "getMask", l_lovrShapeGetMask },
{ "setMask", l_lovrShapeSetMask },
{ "computeMass", l_lovrShapeComputeMass },
{ "getMass", l_lovrShapeGetMass },
{ "getAABB", l_lovrShapeGetAABB },
{ NULL, NULL }
};

View File

@ -578,7 +578,7 @@ void lovrShapeSetMask(Shape* shape, uint32_t mask) {
dGeomSetCollideBits(shape->id, mask);
}
void lovrShapeComputeMass(Shape* shape, float density, float* cx, float* cy, float* cz, float* mass, float inertia[6]) {
void lovrShapeGetMass(Shape* shape, float density, float* cx, float* cy, float* cz, float* mass, float inertia[6]) {
dMass m;
dMassSetZero(&m);
switch (shape->type) {
@ -630,6 +630,10 @@ void lovrShapeComputeMass(Shape* shape, float density, float* cx, float* cy, flo
inertia[5] = m.I[9];
}
void lovrShapeGetAABB(Shape* shape, float aabb[6]) {
dGeomGetAABB(shape->id, aabb);
}
SphereShape* lovrSphereShapeCreate(float radius) {
SphereShape* sphere = lovrAlloc(sizeof(SphereShape), lovrShapeDestroy);
if (!sphere) return NULL;

View File

@ -148,7 +148,8 @@ uint32_t lovrShapeGetCategory(Shape* shape);
void lovrShapeSetCategory(Shape* shape, uint32_t category);
uint32_t lovrShapeGetMask(Shape* shape);
void lovrShapeSetMask(Shape* shape, uint32_t mask);
void lovrShapeComputeMass(Shape* shape, float density, float* cx, float* cy, float* cz, float* mass, float inertia[6]);
void lovrShapeGetMass(Shape* shape, float density, float* cx, float* cy, float* cz, float* mass, float inertia[6]);
void lovrShapeGetAABB(Shape* shape, float aabb[6]);
SphereShape* lovrSphereShapeCreate(float radius);
float lovrSphereShapeGetRadius(SphereShape* sphere);