diff --git a/src/api/types/shapes.c b/src/api/types/shapes.c index 9406471f..cd6e88f5 100644 --- a/src/api/types/shapes.c +++ b/src/api/types/shapes.c @@ -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; +} diff --git a/src/physics/physics.c b/src/physics/physics.c index 0abf2393..a7fc4dfc 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -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); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index 55b767be..46959d60 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -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);