diff --git a/src/api/types/shapes.c b/src/api/types/shapes.c index 3d53bd29..e8a4e866 100644 --- a/src/api/types/shapes.c +++ b/src/api/types/shapes.c @@ -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; +} diff --git a/src/physics/physics.c b/src/physics/physics.c index 2d583f95..46ced2a1 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -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); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index 6f219a8e..9fb3ebf5 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -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);