Shape:getMask; Shape:setMask;

This commit is contained in:
bjorn 2017-05-16 14:26:38 -06:00
parent 81dfba071c
commit 09db32f6b4
3 changed files with 37 additions and 0 deletions

View File

@ -135,3 +135,30 @@ int l_lovrShapeSetCategory(lua_State* L) {
lovrShapeSetCategory(shape, category);
return 0;
}
int l_lovrShapeGetMask(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
uint32_t mask = lovrShapeGetMask(shape);
int count = 0;
for (int i = 0; i < 32; i++) {
if (mask & (1 << i)) {
lua_pushinteger(L, i + 1);
count++;
}
}
return count;
}
int l_lovrShapeSetMask(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
uint32_t mask = 0;
for (int i = 2; i <= lua_gettop(L); i++) {
mask |= (1 << luaL_checkinteger(L, i));
}
lovrShapeSetMask(shape, ~mask);
return 0;
}

View File

@ -333,3 +333,11 @@ uint32_t lovrShapeGetCategory(Shape* shape) {
void lovrShapeSetCategory(Shape* shape, uint32_t category) {
dGeomSetCategoryBits(shape->id, category);
}
uint32_t lovrShapeGetMask(Shape* shape) {
return dGeomGetCollideBits(shape->id);
}
void lovrShapeSetMask(Shape* shape, uint32_t mask) {
dGeomSetCollideBits(shape->id, mask);
}

View File

@ -89,3 +89,5 @@ void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, flo
void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z);
uint32_t lovrShapeGetCategory(Shape* shape);
void lovrShapeSetCategory(Shape* shape, uint32_t category);
uint32_t lovrShapeGetMask(Shape* shape);
void lovrShapeSetMask(Shape* shape, uint32_t mask);