aboutsummaryrefslogtreecommitdiff
path: root/src/shared/lua_api/phys/bphysmodel.cpp
diff options
context:
space:
mode:
authorAlexander <alex@cogarr.net>2020-06-02 08:54:14 -0400
committerAlexander <alex@cogarr.net>2020-06-02 08:54:14 -0400
commitececf2c8624f4d95d9413686839f7fa6e5bb5044 (patch)
treed276a9b7bec1706113f7a59b721fc3c1495cfcbd /src/shared/lua_api/phys/bphysmodel.cpp
parent355589a9100c7d08fdc4094ad32eb9852c88fcc4 (diff)
downloadbrokengine-ececf2c8624f4d95d9413686839f7fa6e5bb5044.tar.gz
brokengine-ececf2c8624f4d95d9413686839f7fa6e5bb5044.tar.bz2
brokengine-ececf2c8624f4d95d9413686839f7fa6e5bb5044.zip
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.
Diffstat (limited to 'src/shared/lua_api/phys/bphysmodel.cpp')
-rw-r--r--src/shared/lua_api/phys/bphysmodel.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp
index 0515922..d56adb5 100644
--- a/src/shared/lua_api/phys/bphysmodel.cpp
+++ b/src/shared/lua_api/phys/bphysmodel.cpp
@@ -27,7 +27,7 @@ extern std::list<btRigidBody*> Objects;
//TODO: This will break in the future, see github.com/syoyo/tinyobjloader-c/issues/16
//"physicfile",mass[,position][,lookat] :: ud_rigidbody
void makebphysmodel(lua_State *L){
- printf("making bphysmodel\n");
+ //printf("making bphysmodel\n");
int nargs = lua_gettop(L);
double lx,ly,lz;
double x,y,z;
@@ -39,7 +39,7 @@ void makebphysmodel(lua_State *L){
//"physicsfile",{position}
popvector3d(L,&x,&y,&z);
}
- printf("got arguments for bphysmodel\n");
+ //printf("got arguments for bphysmodel\n");
//"physicsfile"
double mass = lua_tonumber(L,-1);
@@ -56,14 +56,14 @@ void makebphysmodel(lua_State *L){
FILE *objfile = fopen(ppath,"rb");
fseek(objfile,0,SEEK_END);
data_len = ftell(objfile);
- printf("model data is %d long\n",(int)data_len);
+ //printf("model data is %d long\n",(int)data_len);
fseek(objfile,0,SEEK_SET);
char *objdata = (char*)malloc(sizeof(char)*data_len);
fread(objdata, sizeof(char), data_len, objfile);
fclose(objfile);
- printf("About to tinyobj_parse_obj\n");
+ //printf("About to tinyobj_parse_obj\n");
int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE);
- printf("Finished parsing tinyobj\n");
+ //printf("Finished parsing tinyobj\n");
if(err != TINYOBJ_SUCCESS){
printf("Tinyobj failed to load model:%s\n",ppath);
}
@@ -82,7 +82,7 @@ void makebphysmodel(lua_State *L){
float v3 = vs[2];
vertexes[i] = btVector3(v1,v2,v3);
}
- printf("Finished finding or adding vertexes\n");
+ //printf("Finished finding or adding vertexes\n");
for(size_t i = 0; i < attrib.num_faces - 1; i+= 3){ //0 - y to num_faces - 1
tinyobj_vertex_index_t i1,i2,i3;
i1 = attrib.faces[i];
@@ -93,30 +93,30 @@ void makebphysmodel(lua_State *L){
v2 = vertexes[i2.v_idx];
v3 = vertexes[i3.v_idx];
trimesh->addTriangle(vertexes[i1.v_idx],vertexes[i2.v_idx],vertexes[i3.v_idx],true);//Some triangles are "the wrong way round",
- trimesh->addTriangle(vertexes[i3.v_idx],vertexes[i2.v_idx],vertexes[i1.v_idx],true);//double-side all triangles
+ //trimesh->addTriangle(vertexes[i3.v_idx],vertexes[i2.v_idx],vertexes[i1.v_idx],true);//double-side all triangles
}
- printf("Finished adding triangle indicies\n");
- printf("Done building trimesh\n");
+ //printf("Finished adding triangle indicies\n");
+ //printf("Done building trimesh\n");
btGImpactShapeInterface *shape = new btGImpactMeshShape(trimesh);
shape->updateBound();
//btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true);
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(x,y,z));
- printf("Created default motion shape\n");
+ //printf("Created default motion shape\n");
btDefaultMotionState *ms = new btDefaultMotionState(tr);
btVector3 li;
shape->calculateLocalInertia(mass, li);
btRigidBody *rb = new btRigidBody(mass,ms,shape,li);
World->addRigidBody(rb);
Objects.push_back(rb);
- printf("Rigid body finished\n");
+ //printf("Rigid body finished\n");
lua_pushlightuserdata(L,rb);//ud_rigidbody
}
//newbphysmodel("graphicfile","physicfile",mass[,position][,lookat]) :: ud_rigidbody
static int newbphysmodel(lua_State* L){
- printf("Creating bphysmodel\n");
+ //printf("Creating bphysmodel\n");
int nargs = lua_gettop(L);
double lx,ly,lz;
double x,y,z;
@@ -143,11 +143,11 @@ static int newbphysmodel(lua_State* L){
lua_pushnumber(L,mass);//"phys_path",double_mass
pushvector3d(L,x,y,z);//"phys_path",double_mass,{position}
pushvector3d(L,lx,ly,lz);//"phys_path",double_mass,{position},{lookat}
- printf("Starting makeing bphysmodel\n");
+ //printf("Starting makeing bphysmodel\n");
makebphysmodel(L);//ud_rigidbody
- printf("Done making bphysmodel\n");
+ //printf("Done making bphysmodel\n");
btRigidBody *rb = (btRigidBody*)lua_touserdata(L,-1);
- printf("bphysnode, createing the physics body\n");
+ //printf("bphysnode, createing the physics body\n");
//Create the lua representation
lua_newtable(L);//{}
@@ -156,7 +156,7 @@ static int newbphysmodel(lua_State* L){
lua_pushstring(L,"rigidbody");//{collider=ud_rigidbody},"rigidbody"
lua_setfield(L,-2,"type");//{rb}
- printf("Added collider to lua rep.\n");
+ //printf("Added collider to lua rep.\n");
//Add it to the global list of colliders
lua_getglobal(L,"phys");//{rb},{phys}
@@ -166,13 +166,13 @@ static int newbphysmodel(lua_State* L){
lua_settable(L,-3);//{rb},{phys},{phys.colliders}
lua_pop(L,2);//{rb}
- printf("Added collider to phys.colliders\n");
+ //printf("Added collider to phys.colliders\n");
//lua_pushlightuserdata(L,node);
//lua_setfield(L,-2,"node");
luaL_getmetatable(L,"phys.physmodel");
lua_setmetatable(L,-2);
- printf("finished creating the lua representation\n");
+ //printf("finished creating the lua representation\n");
return 1;
}