Body:getPosition; Body:setPosition;

This commit is contained in:
bjorn 2017-05-15 23:10:17 -06:00
parent f4d4664318
commit eca490adfd
3 changed files with 34 additions and 0 deletions

View File

@ -1,6 +1,27 @@
#include "api/lovr.h"
#include "physics/physics.h"
int l_lovrBodyGetPosition(lua_State* L) {
Body* body = luax_checktype(L, 1, Body);
float x, y, z;
lovrBodyGetPosition(body, &x, &y, &z);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 3;
}
int l_lovrBodySetPosition(lua_State* L) {
Body* body = luax_checktype(L, 1, Body);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
lovrBodySetPosition(body, x, y, z);
return 0;
}
const luaL_Reg lovrBody[] = {
{ "getPosition", l_lovrBodyGetPosition },
{ "setPosition", l_lovrBodySetPosition },
{ NULL, NULL }
};

View File

@ -93,3 +93,14 @@ void lovrBodyDestroy(const Ref* ref) {
dBodyDestroy(body->id);
free(body);
}
void lovrBodyGetPosition(Body* body, float* x, float* y, float* z) {
const dReal* position = dBodyGetPosition(body->id);
*x = position[0];
*y = position[1];
*z = position[2];
}
void lovrBodySetPosition(Body* body, float x, float y, float z) {
dBodySetPosition(body->id, x, y, z);
}

View File

@ -29,3 +29,5 @@ void lovrWorldUpdate(World* world, float dt);
Body* lovrBodyCreate();
void lovrBodyDestroy(const Ref* ref);
void lovrBodyGetPosition(Body* body, float* x, float* y, float* z);
void lovrBodySetPosition(Body* body, float x, float y, float z);