mirror of https://github.com/bjornbytes/lovr.git
Shape:getCategory; Shape:setCategory;
This commit is contained in:
parent
73ec387545
commit
81dfba071c
|
@ -108,3 +108,30 @@ int l_lovrShapeSetOrientation(lua_State* L) {
|
|||
lovrShapeSetOrientation(shape, angle, x, y, z);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrShapeGetCategory(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
uint32_t category = lovrShapeGetCategory(shape);
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (category & (1 << i)) {
|
||||
lua_pushinteger(L, i + 1);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int l_lovrShapeSetCategory(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
uint32_t category = 0;
|
||||
|
||||
for (int i = 2; i <= lua_gettop(L); i++) {
|
||||
category |= (1 << luaL_checkinteger(L, i));
|
||||
}
|
||||
|
||||
lovrShapeSetCategory(shape, category);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -325,3 +325,11 @@ void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float
|
|||
float axis[3] = { x, y, z };
|
||||
dGeomSetOffsetQuaternion(shape->id, quat_fromAngleAxis(quaternion, angle, axis));
|
||||
}
|
||||
|
||||
uint32_t lovrShapeGetCategory(Shape* shape) {
|
||||
return dGeomGetCategoryBits(shape->id);
|
||||
}
|
||||
|
||||
void lovrShapeSetCategory(Shape* shape, uint32_t category) {
|
||||
dGeomSetCategoryBits(shape->id, category);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "util.h"
|
||||
#include <stdint.h>
|
||||
#include <ode/ode.h>
|
||||
|
||||
typedef enum {
|
||||
|
@ -86,3 +87,5 @@ void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z);
|
|||
void lovrShapeSetPosition(Shape* shape, float x, float y, float z);
|
||||
void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z);
|
||||
void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z);
|
||||
uint32_t lovrShapeGetCategory(Shape* shape);
|
||||
void lovrShapeSetCategory(Shape* shape, uint32_t category);
|
||||
|
|
Loading…
Reference in New Issue