diff --git a/src/api/types/shapes.c b/src/api/types/shapes.c index f68dbb7e..6f369c34 100644 --- a/src/api/types/shapes.c +++ b/src/api/types/shapes.c @@ -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 } }; diff --git a/src/physics/physics.c b/src/physics/physics.c index b8a7737b..340962f2 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -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; diff --git a/src/physics/physics.h b/src/physics/physics.h index 50d7ad41..9730c9e6 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -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);