aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/lua_api/common.c25
-rw-r--r--src/shared/lua_api/common.h1
-rw-r--r--src/shared/lua_api/load_phys.cpp8
-rw-r--r--src/shared/lua_api/load_phys.hpp7
-rw-r--r--src/shared/lua_api/phys/bgame.cpp13
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp21
-rw-r--r--src/shared/phys/physcommon.cpp8
7 files changed, 65 insertions, 18 deletions
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c
index 50eb850..9a8baca 100644
--- a/src/shared/lua_api/common.c
+++ b/src/shared/lua_api/common.c
@@ -86,6 +86,31 @@ int pushvector2i(lua_State* L, long a, long b){
return 1;
}
+int popvector4i(lua_State* L,long* a,long* b,long* c, long* d){
+ lua_pushinteger(L,1);//{v4},1
+ lua_gettable(L,-2);//{v4},v4[1]
+ *a = lua_tointeger(L,-1);//{v4},v4[1]
+ lua_pop(L,1);//{v4}
+
+ lua_pushinteger(L,2);//{v4},2
+ lua_gettable(L,-2);//{v4},v4[2]
+ *b = lua_tointeger(L,-1);//{v4},v4[2]
+ lua_pop(L,1);//{v4}
+
+ lua_pushinteger(L,3);//{v4},3
+ lua_gettable(L,-2);//{v4},v4[3]
+ *c = lua_tointeger(L,-1);//{v4},v4[3]
+ lua_pop(L,1);//{v4}
+
+ lua_pushinteger(L,4);//{v4},3
+ lua_gettable(L,-2);//{v4},v4[3]
+ *d = lua_tointeger(L,-1);//{v4},v4[3]
+ lua_pop(L,1);//{v4}
+
+ lua_pop(L,1);//
+ return 0;
+}
+
int popvector3i(lua_State* L,long* a,long* b,long* c){//{v3}
lua_pushinteger(L,1);//{v3},1
lua_gettable(L,-2);//{v3},v3[1]
diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h
index 9260706..c2e067d 100644
--- a/src/shared/lua_api/common.h
+++ b/src/shared/lua_api/common.h
@@ -11,6 +11,7 @@ int pushvector3i(lua_State*,long,long,long);
int pushvector3d(lua_State*,double,double,double);
int pushvector2i(lua_State*,long,long);
+int popvector4i(lua_State*,long*,long*,long*,long*);
int popvector3i(lua_State*,long*,long*,long*);
int popvector3d(lua_State*,double*,double*,double*);
int popvector2i(lua_State*,long*,long*);
diff --git a/src/shared/lua_api/load_phys.cpp b/src/shared/lua_api/load_phys.cpp
index c91396c..14a27ea 100644
--- a/src/shared/lua_api/load_phys.cpp
+++ b/src/shared/lua_api/load_phys.cpp
@@ -1,6 +1,8 @@
-#include "load_phys.hpp"
-
+#include "./load_phys.hpp"
+#include "./phys/bphysbox.hpp"
void loadPhysLibs(lua_State* L){
-
+ lua_newtable(L);//{}
+ lua_setglobal(L,"phys");
+ bphysbox_register(L);
}
diff --git a/src/shared/lua_api/load_phys.hpp b/src/shared/lua_api/load_phys.hpp
index 5e05642..6f9e9a9 100644
--- a/src/shared/lua_api/load_phys.hpp
+++ b/src/shared/lua_api/load_phys.hpp
@@ -3,12 +3,5 @@ extern "C" {
#include <lauxlib.h>
#include <lualib.h>
}
-#include "load_core.hpp"
-
-struct EntityPhysics : EntityMass{
- btTransform* transform;
- btRigidBody* rigidbody;
- btCollisionShape* shape;
-}EntityPhysics;
void loadPhysLibs(lua_State* L);
diff --git a/src/shared/lua_api/phys/bgame.cpp b/src/shared/lua_api/phys/bgame.cpp
new file mode 100644
index 0000000..b755787
--- /dev/null
+++ b/src/shared/lua_api/phys/bgame.cpp
@@ -0,0 +1,13 @@
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+#include <btBulletDynamicsCommon.h>
+
+extern btDiscreteDynamicsWorld* World;
+
+void registergravity(lua_State* L){
+
+}
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index 3036cf9..78f1c45 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -45,25 +45,34 @@ void makenewbphysbox(lua_State* L){
btVector3 pos = btVector3(px,py,pz);
// Set the initial position of the object
- btTransform transform;
- transform.setIdentity();
- transform.setOrigin(pos);
+ btTransform transform = btTransform(btQuaternion(0,0,0,1),pos);
+ //transform.setIdentity();
+ //transform.setOrigin(pos);
// Give it a default MotionState
btDefaultMotionState* motionstate = new btDefaultMotionState(transform);
-
+ if(!motionstate){
+ printf("No motionstate\n");
+ }
// Create the shape
btCollisionShape* shape = new btBoxShape(vshape);
+ if(!shape){
+ printf("no shape\n");
+ }
// Add mass
- btVector3 localinertia;
+ btVector3 localinertia = btVector3(0,0,0);
shape->calculateLocalInertia(mass, localinertia);
// Create the rigid body object
btRigidBody* rigidbody = new btRigidBody(mass, motionstate, shape, localinertia);
+ if(!rigidbody){
+ printf("No rigidbody\n");
+ }
// Add it to the world
World->addRigidBody(rigidbody);
+ printf("Added rigid body to world: %p\n",World);
Objects.push_back(rigidbody);
lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
@@ -114,6 +123,7 @@ static int bphyssetpos(lua_State *L){//self,{v3 pos}
bt.setOrigin(to);
ms->setWorldTransform(bt);
i->activate();
+
lua_pop(L,1);//
return 0;
}
@@ -139,6 +149,7 @@ static const luaL_reg bphysbox_m[] = {
};
void bphysbox_register(lua_State* L){//
+ printf("Registered bphysbox\n");
luaL_newmetatable(L, "phys.physbox");//{phys.physbox}
lua_newtable(L);//{phys.physbox},{}
diff --git a/src/shared/phys/physcommon.cpp b/src/shared/phys/physcommon.cpp
index c15274d..4f506bb 100644
--- a/src/shared/phys/physcommon.cpp
+++ b/src/shared/phys/physcommon.cpp
@@ -32,7 +32,7 @@ btCollisionDispatcher* Dispatcher;
btSequentialImpulseConstraintSolver* Solver;
void phys_genesis(){
- BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
+ BroadPhase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000));
printf("Broadphase\n");
CollisionConfiguration = new btDefaultCollisionConfiguration();
printf("Collision config\n");
@@ -42,6 +42,8 @@ void phys_genesis(){
printf("Solver\n");
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
printf("Physics world init ok.\n");
+ World->setGravity(btVector3(0,-10,0));
+ printf("Created physics world: %p\n",World);
}
void phys_shutdown(void(*f)(btRigidBody*)){
@@ -65,7 +67,7 @@ void phys_shutdown(void(*f)(btRigidBody*)){
// Runs the physics simulation.
// - TDeltaTime tells the simulation how much time has passed since the last frame so the simulation can run independently of the frame rate. Optionally pass in an argument that will be called on every rigidbody in the world
void UpdatePhysics(double TDeltaTime, void(*f)(btRigidBody*)) {
- World->stepSimulation(TDeltaTime * 0.02f, 60);
+ World->stepSimulation(TDeltaTime * 0.2f, 60);
if(f){
// Relay the object's orientation to irrlicht
for(std::list<btRigidBody *>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
@@ -78,7 +80,7 @@ high_resolution_clock::time_point t1 = high_resolution_clock::now();
void gameloop_phys(void(*f)(btRigidBody*)){
high_resolution_clock::time_point now = high_resolution_clock::now();
duration<double> delta = now-t1;
- double steps = delta.count() * 100;
+ double steps = delta.count() * 10;
UpdatePhysics(steps,f);
t1 = now;
}