Shape:getPosition; Shape:setPosition;

This commit is contained in:
bjorn 2017-05-16 12:46:15 -06:00
parent a70edfe2a5
commit 327022461e
3 changed files with 32 additions and 0 deletions

View File

@ -68,3 +68,22 @@ int l_lovrShapeSetUserData(lua_State* L) {
lovrShapeSetUserData(shape, (void*) ref);
return 0;
}
int l_lovrShapeGetPosition(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
float x, y, z;
lovrShapeGetPosition(shape, &x, &y, &z);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 3;
}
int l_lovrShapeSetPosition(lua_State* L) {
Shape* shape = luax_checktypeof(L, 1, Shape);
float x = luaL_checknumber(L, 1);
float y = luaL_checknumber(L, 2);
float z = luaL_checknumber(L, 3);
lovrShapeSetPosition(shape, x, y, z);
return 0;
}

View File

@ -303,3 +303,14 @@ void* lovrShapeGetUserData(Shape* shape) {
void lovrShapeSetUserData(Shape* shape, void* data) {
dGeomSetData(shape->id, data);
}
void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z) {
const dReal* position = dGeomGetOffsetPosition(shape->id);
*x = position[0];
*y = position[1];
*z = position[2];
}
void lovrShapeSetPosition(Shape* shape, float x, float y, float z) {
dGeomSetOffsetPosition(shape->id, x, y, z);
}

View File

@ -82,3 +82,5 @@ int lovrShapeIsEnabled(Shape* shape);
void lovrShapeSetEnabled(Shape* shape, int enabled);
void* lovrShapeGetUserData(Shape* shape);
void lovrShapeSetUserData(Shape* shape, void* data);
void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z);
void lovrShapeSetPosition(Shape* shape, float x, float y, float z);