diff --git a/src/api/types/world.c b/src/api/types/world.c index 86f4ad44..fb0bd87c 100644 --- a/src/api/types/world.c +++ b/src/api/types/world.c @@ -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; diff --git a/src/physics/physics.c b/src/physics/physics.c index 42a32136..f45b9018 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -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; } diff --git a/src/physics/physics.h b/src/physics/physics.h index 8d5b4c9c..ee82089f 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -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);