World:getGravity; World:setGravity;

This commit is contained in:
bjorn 2017-05-15 23:03:01 -06:00
parent 70bc90154b
commit 3c8f4bd63b
3 changed files with 35 additions and 0 deletions

View File

@ -1,6 +1,27 @@
#include "api/lovr.h"
#include "physics/physics.h"
int l_lovrWorldGetGravity(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x, y, z;
lovrWorldGetGravity(world, &x, &y, &z);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 3;
}
int l_lovrWorldSetGravity(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
lovrWorldSetGravity(world, x, y, z);
return 0;
}
const luaL_Reg lovrWorld[] = {
{ "getGravity", l_lovrWorldGetGravity },
{ "setGravity", l_lovrWorldSetGravity },
{ NULL, NULL }
};

View File

@ -29,3 +29,15 @@ void lovrWorldDestroy(const Ref* ref) {
dWorldDestroy(world->id);
free(world);
}
void lovrWorldGetGravity(World* world, float* x, float* y, float* z) {
dReal gravity[3];
dWorldGetGravity(world->id, gravity);
*x = gravity[0];
*y = gravity[1];
*z = gravity[2];
}
void lovrWorldSetGravity(World* world, float x, float y, float z) {
dWorldSetGravity(world->id, x, y, z);
}

View File

@ -11,3 +11,5 @@ void lovrPhysicsDestroy();
World* lovrWorldCreate();
void lovrWorldDestroy(const Ref* ref);
void lovrWorldGetGravity(World* world, float* x, float* y, float* z);
void lovrWorldSetGravity(World* world, float x, float y, float z);