mirror of https://github.com/bjornbytes/lovr.git
Shape:getAABB;
This commit is contained in:
parent
f3df7aa114
commit
876a8406b1
|
@ -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 }
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue