From ececf2c8624f4d95d9413686839f7fa6e5bb5044 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 2 Jun 2020 08:54:14 -0400 Subject: Add a shape cast Add a raycast like function, which can cast shapes. phys.shapecast(), along with a shape structure needed to call this function. --- src/shared/lua_api/phys/bshape.cpp | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/shared/lua_api/phys/bshape.cpp (limited to 'src/shared/lua_api/phys/bshape.cpp') diff --git a/src/shared/lua_api/phys/bshape.cpp b/src/shared/lua_api/phys/bshape.cpp new file mode 100644 index 0000000..5533b42 --- /dev/null +++ b/src/shared/lua_api/phys/bshape.cpp @@ -0,0 +1,52 @@ +extern "C" { + #include + #include + #include +} +#include +#include +#include + +extern btDiscreteDynamicsWorld* World; + +//phys.newboxshape({ax,ay,az}) +static int newboxshape(lua_State* L){ + double ax,ay,az; + popvector3d(L,&ax,&ay,&az); + ax *= 0.5; + ay *= 0.5; + az *= 0.5; + btBoxShape *bs = new btBoxShape(btVector3(ax,ay,az)); + printf("Created shape: %p\n",(void*)bs); + lua_newtable(L);//{} + lua_pushlightuserdata(L,bs);//{},ud_bs + lua_setfield(L,-2,"shape");//{} + luaL_getmetatable(L,"phys.shape");//{},{m_shape} + lua_setmetatable(L,-2);//{} + + return 1; +} + +static const luaL_reg bshape_f[] = { + {"newboxshape", newboxshape}, + {0,0}, +}; + +static const luaL_reg bshape_m[] = { + {0,0}, +}; + +int bshape_register(lua_State* L){ + + luaL_newmetatable(L, "phys.shape");//{m_physshape} + lua_newtable(L);//{m_physshape},{} + luaL_register(L,NULL,bshape_m); + lua_setfield(L,-2,"__index");//{m_physshape} + lua_pop(L,1);// + + lua_getglobal(L,"phys");//{} + luaL_register(L,NULL,bshape_f);//{} + lua_pop(L,1);// + + return 0; +} -- cgit v1.2.3-70-g09d2