1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 12:33:52 +00:00

World:getLinearDamping; World:setLinearDamping;

This commit is contained in:
bjorn 2017-05-15 23:05:48 -06:00
parent 053ccb18bc
commit b840fb0a44
3 changed files with 31 additions and 0 deletions

View file

@ -20,6 +20,23 @@ int l_lovrWorldSetGravity(lua_State* L) {
return 0; return 0;
} }
int l_lovrWorldGetLinearDamping(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float damping, threshold;
lovrWorldGetLinearDamping(world, &damping, &threshold);
lua_pushnumber(L, damping);
lua_pushnumber(L, threshold);
return 2;
}
int l_lovrWorldSetLinearDamping(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01);
lovrWorldSetLinearDamping(world, damping, threshold);
return 0;
}
int l_lovrWorldUpdate(lua_State* L) { int l_lovrWorldUpdate(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float dt = luaL_checknumber(L, 2); float dt = luaL_checknumber(L, 2);
@ -30,6 +47,8 @@ int l_lovrWorldUpdate(lua_State* L) {
const luaL_Reg lovrWorld[] = { const luaL_Reg lovrWorld[] = {
{ "getGravity", l_lovrWorldGetGravity }, { "getGravity", l_lovrWorldGetGravity },
{ "setGravity", l_lovrWorldSetGravity }, { "setGravity", l_lovrWorldSetGravity },
{ "getLinearDamping", l_lovrWorldGetLinearDamping },
{ "setLinearDamping", l_lovrWorldSetLinearDamping },
{ "update", l_lovrWorldUpdate }, { "update", l_lovrWorldUpdate },
{ NULL, NULL } { NULL, NULL }
}; };

View file

@ -42,6 +42,16 @@ void lovrWorldSetGravity(World* world, float x, float y, float z) {
dWorldSetGravity(world->id, x, y, z); dWorldSetGravity(world->id, x, y, z);
} }
void lovrWorldGetLinearDamping(World* world, float* damping, float* threshold) {
*damping = dWorldGetLinearDamping(world->id);
*threshold = dWorldGetLinearDampingThreshold(world->id);
}
void lovrWorldSetLinearDamping(World* world, float damping, float threshold) {
dWorldSetLinearDamping(world->id, damping);
dWorldSetLinearDampingThreshold(world->id, threshold);
}
void lovrWorldUpdate(World* world, float dt) { void lovrWorldUpdate(World* world, float dt) {
dWorldQuickStep(world->id, dt); dWorldQuickStep(world->id, dt);
} }

View file

@ -13,4 +13,6 @@ World* lovrWorldCreate();
void lovrWorldDestroy(const Ref* ref); void lovrWorldDestroy(const Ref* ref);
void lovrWorldGetGravity(World* world, float* x, float* y, float* z); void lovrWorldGetGravity(World* world, float* x, float* y, float* z);
void lovrWorldSetGravity(World* world, float x, float y, float z); void lovrWorldSetGravity(World* world, float x, float y, float z);
void lovrWorldGetLinearDamping(World* world, float* damping, float* threshold);
void lovrWorldSetLinearDamping(World* world, float damping, float threshold);
void lovrWorldUpdate(World* world, float dt); void lovrWorldUpdate(World* world, float dt);