mirror of https://github.com/bjornbytes/lovr.git
Body;
This commit is contained in:
parent
c06a13f124
commit
f4d4664318
|
@ -16,6 +16,7 @@ int l_lovrTimerInit(lua_State* L);
|
||||||
extern const luaL_Reg lovrAudio[];
|
extern const luaL_Reg lovrAudio[];
|
||||||
extern const luaL_Reg lovrController[];
|
extern const luaL_Reg lovrController[];
|
||||||
extern const luaL_Reg lovrBlob[];
|
extern const luaL_Reg lovrBlob[];
|
||||||
|
extern const luaL_Reg lovrBody[];
|
||||||
extern const luaL_Reg lovrEvent[];
|
extern const luaL_Reg lovrEvent[];
|
||||||
extern const luaL_Reg lovrFilesystem[];
|
extern const luaL_Reg lovrFilesystem[];
|
||||||
extern const luaL_Reg lovrFont[];
|
extern const luaL_Reg lovrFont[];
|
||||||
|
|
|
@ -5,6 +5,7 @@ int l_lovrPhysicsInit(lua_State* L) {
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luaL_register(L, NULL, lovrPhysics);
|
luaL_register(L, NULL, lovrPhysics);
|
||||||
luax_registertype(L, "World", lovrWorld);
|
luax_registertype(L, "World", lovrWorld);
|
||||||
|
luax_registertype(L, "Body", lovrBody);
|
||||||
lovrPhysicsInit();
|
lovrPhysicsInit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +15,14 @@ int l_lovrPhysicsNewWorld(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrPhysicsNewBody(lua_State* L) {
|
||||||
|
World* world = luax_checktype(L, 1, World);
|
||||||
|
luax_pushtype(L, Body, lovrBodyCreate(world));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg lovrPhysics[] = {
|
const luaL_Reg lovrPhysics[] = {
|
||||||
{ "newWorld", l_lovrPhysicsNewWorld },
|
{ "newWorld", l_lovrPhysicsNewWorld },
|
||||||
|
{ "newBody", l_lovrPhysicsNewBody },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "api/lovr.h"
|
||||||
|
#include "physics/physics.h"
|
||||||
|
|
||||||
|
const luaL_Reg lovrBody[] = {
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
|
@ -73,3 +73,23 @@ void lovrWorldSetSleepingAllowed(World* world, int allowed) {
|
||||||
void lovrWorldUpdate(World* world, float dt) {
|
void lovrWorldUpdate(World* world, float dt) {
|
||||||
dWorldQuickStep(world->id, dt);
|
dWorldQuickStep(world->id, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Body* lovrBodyCreate(World* world) {
|
||||||
|
if (!world) {
|
||||||
|
error("No world specified");
|
||||||
|
}
|
||||||
|
|
||||||
|
Body* body = lovrAlloc(sizeof(Body), lovrBodyDestroy);
|
||||||
|
if (!body) return NULL;
|
||||||
|
|
||||||
|
body->id = dBodyCreate(world->id);
|
||||||
|
body->world = world;
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrBodyDestroy(const Ref* ref) {
|
||||||
|
Body* body = containerof(ref, Body);
|
||||||
|
dBodyDestroy(body->id);
|
||||||
|
free(body);
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,12 @@ typedef struct {
|
||||||
dWorldID id;
|
dWorldID id;
|
||||||
} World;
|
} World;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Ref ref;
|
||||||
|
dBodyID id;
|
||||||
|
World* world;
|
||||||
|
} Body;
|
||||||
|
|
||||||
void lovrPhysicsInit();
|
void lovrPhysicsInit();
|
||||||
void lovrPhysicsDestroy();
|
void lovrPhysicsDestroy();
|
||||||
|
|
||||||
|
@ -20,3 +26,6 @@ void lovrWorldSetAngularDamping(World* world, float damping, float threshold);
|
||||||
int lovrWorldIsSleepingAllowed(World* world);
|
int lovrWorldIsSleepingAllowed(World* world);
|
||||||
void lovrWorldSetSleepingAllowed(World* world, int allowed);
|
void lovrWorldSetSleepingAllowed(World* world, int allowed);
|
||||||
void lovrWorldUpdate(World* world, float dt);
|
void lovrWorldUpdate(World* world, float dt);
|
||||||
|
|
||||||
|
Body* lovrBodyCreate();
|
||||||
|
void lovrBodyDestroy(const Ref* ref);
|
||||||
|
|
Loading…
Reference in New Issue