mirror of https://github.com/bjornbytes/lovr.git
Collider constructor accepts position;
This commit is contained in:
parent
011b669892
commit
827c92cc38
|
@ -37,27 +37,36 @@ static void raycastCallback(Shape* shape, float x, float y, float z, float nx, f
|
|||
|
||||
int l_lovrWorldNewCollider(lua_State* L) {
|
||||
World* world = luax_checktype(L, 1, World);
|
||||
Collider* collider = lovrColliderCreate(world);
|
||||
float x = luaL_optnumber(L, 2, 0);
|
||||
float y = luaL_optnumber(L, 3, 0);
|
||||
float z = luaL_optnumber(L, 4, 0);
|
||||
Collider* collider = lovrColliderCreate(world, x, y, z);
|
||||
luax_pushtype(L, Collider, collider);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrWorldNewBoxCollider(lua_State* L) {
|
||||
World* world = luax_checktype(L, 1, World);
|
||||
float x = luaL_optnumber(L, 2, 1.f);
|
||||
float y = luaL_optnumber(L, 3, x);
|
||||
float z = luaL_optnumber(L, 4, x);
|
||||
Collider* collider = lovrColliderCreate(world);
|
||||
lovrColliderAddShape(collider, lovrBoxShapeCreate(x, y, z));
|
||||
float x = luaL_optnumber(L, 2, 0);
|
||||
float y = luaL_optnumber(L, 3, 0);
|
||||
float z = luaL_optnumber(L, 4, 0);
|
||||
float sx = luaL_optnumber(L, 5, 1.f);
|
||||
float sy = luaL_optnumber(L, 6, sx);
|
||||
float sz = luaL_optnumber(L, 7, sx);
|
||||
Collider* collider = lovrColliderCreate(world, x, y, z);
|
||||
lovrColliderAddShape(collider, lovrBoxShapeCreate(sx, sy, sz));
|
||||
luax_pushtype(L, Collider, collider);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrWorldNewCapsuleCollider(lua_State* L) {
|
||||
World* world = luax_checktype(L, 1, World);
|
||||
float radius = luaL_optnumber(L, 2, 1.f);
|
||||
float length = luaL_optnumber(L, 3, 1.f);
|
||||
Collider* collider = lovrColliderCreate(world);
|
||||
float x = luaL_optnumber(L, 2, 0);
|
||||
float y = luaL_optnumber(L, 3, 0);
|
||||
float z = luaL_optnumber(L, 4, 0);
|
||||
float radius = luaL_optnumber(L, 5, 1.f);
|
||||
float length = luaL_optnumber(L, 6, 1.f);
|
||||
Collider* collider = lovrColliderCreate(world, x, y, z);
|
||||
lovrColliderAddShape(collider, lovrCapsuleShapeCreate(radius, length));
|
||||
luax_pushtype(L, Collider, collider);
|
||||
return 1;
|
||||
|
@ -65,9 +74,12 @@ int l_lovrWorldNewCapsuleCollider(lua_State* L) {
|
|||
|
||||
int l_lovrWorldNewCylinderCollider(lua_State* L) {
|
||||
World* world = luax_checktype(L, 1, World);
|
||||
float radius = luaL_optnumber(L, 2, 1.f);
|
||||
float length = luaL_optnumber(L, 3, 1.f);
|
||||
Collider* collider = lovrColliderCreate(world);
|
||||
float x = luaL_optnumber(L, 2, 0);
|
||||
float y = luaL_optnumber(L, 3, 0);
|
||||
float z = luaL_optnumber(L, 4, 0);
|
||||
float radius = luaL_optnumber(L, 5, 1.f);
|
||||
float length = luaL_optnumber(L, 6, 1.f);
|
||||
Collider* collider = lovrColliderCreate(world, x, y, z);
|
||||
lovrColliderAddShape(collider, lovrCylinderShapeCreate(radius, length));
|
||||
luax_pushtype(L, Collider, collider);
|
||||
return 1;
|
||||
|
@ -75,8 +87,11 @@ int l_lovrWorldNewCylinderCollider(lua_State* L) {
|
|||
|
||||
int l_lovrWorldNewSphereCollider(lua_State* L) {
|
||||
World* world = luax_checktype(L, 1, World);
|
||||
float radius = luaL_optnumber(L, 2, 1.f);
|
||||
Collider* collider = lovrColliderCreate(world);
|
||||
float x = luaL_optnumber(L, 2, 0);
|
||||
float y = luaL_optnumber(L, 3, 0);
|
||||
float z = luaL_optnumber(L, 4, 0);
|
||||
float radius = luaL_optnumber(L, 5, 1.f);
|
||||
Collider* collider = lovrColliderCreate(world, x, y, z);
|
||||
lovrColliderAddShape(collider, lovrSphereShapeCreate(radius));
|
||||
luax_pushtype(L, Collider, collider);
|
||||
return 1;
|
||||
|
|
|
@ -257,7 +257,7 @@ int lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const cha
|
|||
return (world->masks[*index1] & (1 << *index2)) && (world->masks[*index2] & (1 << *index1));
|
||||
}
|
||||
|
||||
Collider* lovrColliderCreate(World* world) {
|
||||
Collider* lovrColliderCreate(World* world, float x, float y, float z) {
|
||||
if (!world) {
|
||||
error("No world specified");
|
||||
}
|
||||
|
@ -274,6 +274,8 @@ Collider* lovrColliderCreate(World* world) {
|
|||
vec_init(&collider->shapes);
|
||||
vec_init(&collider->joints);
|
||||
|
||||
lovrColliderSetPosition(collider, x, y, z);
|
||||
|
||||
return collider;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ int lovrWorldDisableCollisionBetween(World* world, const char* tag1, const char*
|
|||
int lovrWorldEnableCollisionBetween(World* world, const char* tag1, const char* tag2);
|
||||
int lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const char* tag);
|
||||
|
||||
Collider* lovrColliderCreate();
|
||||
Collider* lovrColliderCreate(World* world, float x, float y, float z);
|
||||
void lovrColliderDestroy(const Ref* ref);
|
||||
void lovrColliderDestroyData(Collider* collider);
|
||||
World* lovrColliderGetWorld(Collider* collider);
|
||||
|
|
Loading…
Reference in New Issue