aboutsummaryrefslogtreecommitdiff
path: root/src/shared/lua_api/phys
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/lua_api/phys')
-rw-r--r--src/shared/lua_api/phys/bcollider.cpp7
-rw-r--r--src/shared/lua_api/phys/bghostobject.cpp15
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp2
-rw-r--r--src/shared/lua_api/phys/bphysgeneric.cpp15
-rw-r--r--src/shared/lua_api/phys/bphysmodel.cpp19
5 files changed, 41 insertions, 17 deletions
diff --git a/src/shared/lua_api/phys/bcollider.cpp b/src/shared/lua_api/phys/bcollider.cpp
index 91c34fd..caefd3e 100644
--- a/src/shared/lua_api/phys/bcollider.cpp
+++ b/src/shared/lua_api/phys/bcollider.cpp
@@ -1,3 +1,10 @@
+/*
+A wrapper for the btCollisionObject class.
+Most of the methods that bullet exposes for the btCollisionObject are wrapped
+here, any subclass of btCollisionObject should register methods defined
+here in it's metatable's __index.
+*/
+
extern "C" {
#include <lua.h>
#include <lauxlib.h>
diff --git a/src/shared/lua_api/phys/bghostobject.cpp b/src/shared/lua_api/phys/bghostobject.cpp
index 63f790c..5657b5f 100644
--- a/src/shared/lua_api/phys/bghostobject.cpp
+++ b/src/shared/lua_api/phys/bghostobject.cpp
@@ -109,7 +109,7 @@ int bghostconvexsweep(lua_State *L){
btVector3 hw, hn;
hw = cb->m_hitPointWorld;
hn = cb->m_hitNormalWorld;
- btCollisionObject *co = cb->m_hitCollisionObject;
+ const btCollisionObject *co = cb->m_hitCollisionObject;
lua_newtable(L);//{}
lua_pushboolean(L,cb->hasHit() ? 1 : 0);
@@ -118,12 +118,17 @@ int bghostconvexsweep(lua_State *L){
lua_setfield(L,-2,"pos");
pushvector3d(L,hn.x(),hn.y(),hn.z());
lua_setfield(L,-2,"normal");
+
lua_getglobal(L,"phys");//{},{phys}
lua_getfield(L,-1,"colliders");//{},{phys},{phys.colliders}
- lua_pushlightuserdata(L,co);//{},{phys},{phys.colliders},ud_collisionobject
- lua_gettable(L,-2);//{},{phys},{phys.colliders},ud_collisionobject,{rb} or nil
- lua_setfield(L,-5,"what");//{},{phys},{phys.colliders},ud_collisionobject
- lua_pop(L,3);//{}
+ lua_pushlightuserdata(L,(void*)co);//{},{phys},{phys.colliders},ud_collisionobject
+ lua_gettable(L,-2);//{},{phys},{phys.colliders},{rb} or nil
+ if(lua_isnil(L,-1)){
+ lua_pop(L,3);//{}
+ }else{
+ lua_setfield(L,-4,"what");//{},{phys},{phys.colliders}
+ lua_pop(L,2);//{}
+ }
delete cb;
return 1;
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index 569f3f9..66f112d 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -107,7 +107,7 @@ int newbphysbox(lua_State* L){
//Set it's metatable
luaL_getmetatable(L, "phys.physbox");//{},{phys.physbox}
lua_setmetatable(L, -2);//{}
-
+
return 1;
}
diff --git a/src/shared/lua_api/phys/bphysgeneric.cpp b/src/shared/lua_api/phys/bphysgeneric.cpp
index 4500ce0..eed9112 100644
--- a/src/shared/lua_api/phys/bphysgeneric.cpp
+++ b/src/shared/lua_api/phys/bphysgeneric.cpp
@@ -8,11 +8,6 @@ extern "C" {
#include <shared/lua_api/common.hpp>
#include <shared/phys/physcommon.hpp>
-/***
-@module phys
-*/
-
-
/*Physics things from lua have the form of:
{
type = "rigidbody"
@@ -243,6 +238,7 @@ int applyimpulse(lua_State *L){
popvector3d(L,&x,&y,&z);
btRigidBody *r = popRigidBody(L);
r->applyImpulse(btVector3(x,y,z),btVector3(ox,oy,oz));
+ r->activate();
return 0;
}
@@ -265,6 +261,14 @@ int setrotation(lua_State *L){
return 0;
}
+//rigidbody:getmass() :: number
+int getmass(lua_State *L){
+ btRigidBody *r = popRigidBody(L);
+ double m = r->getMass();
+ lua_pushnumber(L,m);
+ return 1;
+}
+
/*
@@ -310,6 +314,7 @@ extern const luaL_reg brigidbody_m[] = {
{"setangfactor", setangfactor},
{"setflags", setflags},
{"setrotation", setrotation},
+ {"getmass", getmass},
//{"testcontact", testcontact},
{NULL, NULL}
};
diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp
index 0c8e3bf..375d68b 100644
--- a/src/shared/lua_api/phys/bphysmodel.cpp
+++ b/src/shared/lua_api/phys/bphysmodel.cpp
@@ -24,6 +24,10 @@ extern "C" {
extern btDiscreteDynamicsWorld* World;
extern std::list<btRigidBody*> Objects;
+//btRigidBody* load_obj(tinyobj_attrib_t attrib, tinyobj_shape_t *shapes, size_t num){
+ //btTriangleMesh *trimesh = new btTriangleMesh();
+//}
+
//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){
@@ -67,6 +71,9 @@ void makebphysmodel(lua_State *L){
if(err != TINYOBJ_SUCCESS){
printf("Tinyobj failed to load model:%s\n",ppath);
}
+ //for(size_t s = 0; s < meshcount; s++){
+ //btRigidBody *rb = load_obj(attrib,shapes,s);
+ //}
//u32 meshcount = pmesh->getMeshBufferCount();
//__mingw_printf("attrib.num_vertices: %u\n",attrib.num_vertices);
//__mingw_printf("attrib.num_faces: %u\n",attrib.num_faces);
@@ -81,7 +88,7 @@ void makebphysmodel(lua_State *L){
float v2 = vs[1];
float v3 = vs[2];
vertexes[i] = btVector3(v1,v2,v3);
- printf("Adding vertex %lld at (%f,%f,%f)\n",i,v1,v2,v3);
+ //printf("Adding vertex %lld at (%f,%f,%f)\n",i,v1,v2,v3);
}
//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
@@ -94,14 +101,14 @@ 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],false);//Some triangles are "the wrong way round",
- printf("Adding triangle:(%d,%d,%d)\n",i1.v_idx,i2.v_idx,i3.v_idx);
- //trimesh->addTriangle(vertexes[i3.v_idx],vertexes[i2.v_idx],vertexes[i1.v_idx],true);//double-side all triangles
+ //printf("Adding triangle:(%d,%d,%d)\n",i1.v_idx,i2.v_idx,i3.v_idx);
+ 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");
- //btGImpactShapeInterface *shape = new btGImpactMeshShape(trimesh);
- btConvexTriangleMeshShape *shape = new btConvexTriangleMeshShape(trimesh);
- //shape->updateBound();
+ //btConvexTriangleMeshShape *shape = new btConvexTriangleMeshShape(trimesh);
+ btGImpactShapeInterface *shape = new btGImpactMeshShape(trimesh);
+ shape->updateBound();
//btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true);
btTransform tr;
tr.setIdentity();