Now passing the Lua State to the physics, so that Lua can directly access physics functions.
This commit is contained in:
parent
d936d1f269
commit
72d1009007
@ -1,10 +1,14 @@
|
|||||||
function trigger(objectToChange)
|
function trigger(objectToChange)
|
||||||
if(not this_level) then
|
if(not level) then
|
||||||
print("No level found!")
|
print("No level found in Lua!")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
a = this_level:getObjectCount()
|
if(not physics) then
|
||||||
|
print("No physics found in Lua!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
a = level:getObjectCount()
|
||||||
rand = math.random(0, a - 1)
|
rand = math.random(0, a - 1)
|
||||||
this_level:deleteObject(rand)
|
level:deleteObject(rand)
|
||||||
print("Triggered from Lua!")
|
print("Triggered from Lua!")
|
||||||
end
|
end
|
||||||
|
8
level.cc
8
level.cc
@ -57,19 +57,19 @@ void Level::load() {
|
|||||||
// Create a new lua state
|
// Create a new lua state
|
||||||
L = luaL_newstate();
|
L = luaL_newstate();
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
//Expose the class Level and its functions
|
//Expose the class Level and its functions to Lua
|
||||||
luabridge::getGlobalNamespace(L)
|
luabridge::getGlobalNamespace(L)
|
||||||
.beginClass<Level>("Level")
|
.beginClass<Level>("Level")
|
||||||
.addFunction("deleteObject", &Level::deleteObject)
|
.addFunction("deleteObject", &Level::deleteObject)
|
||||||
.addFunction("getObjectCount", &Level::getObjectCount)
|
.addFunction("getObjectCount", &Level::getObjectCount)
|
||||||
.endClass();
|
.endClass();
|
||||||
//Push the level as a global variable
|
//Push the level to Lua as a global variable
|
||||||
luabridge::push(L, this);
|
luabridge::push(L, this);
|
||||||
lua_setglobal(L, "this_level");
|
lua_setglobal(L, "level");
|
||||||
|
|
||||||
|
|
||||||
this->physics = Physics();
|
this->physics = Physics();
|
||||||
this->physics.init();
|
this->physics.init(L);
|
||||||
|
|
||||||
// currently hard coded should later read this stuff out of a file
|
// currently hard coded should later read this stuff out of a file
|
||||||
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
|
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
|
||||||
|
12
physics.cc
12
physics.cc
@ -8,15 +8,23 @@ Physics::Physics() {
|
|||||||
Physics::~Physics() {
|
Physics::~Physics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::init()
|
void Physics::init(lua_State* L)
|
||||||
{
|
{
|
||||||
colConfig = new btDefaultCollisionConfiguration();
|
colConfig = new btDefaultCollisionConfiguration();
|
||||||
dispatcher = new btCollisionDispatcher(colConfig);
|
dispatcher = new btCollisionDispatcher(colConfig);
|
||||||
broadphase = new btDbvtBroadphase();
|
broadphase = new btDbvtBroadphase();
|
||||||
solver = new btSequentialImpulseConstraintSolver();
|
solver = new btSequentialImpulseConstraintSolver();
|
||||||
world = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,colConfig);
|
world = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,colConfig);
|
||||||
|
|
||||||
world->setGravity(btVector3(0,-10,-0));
|
world->setGravity(btVector3(0,-10,-0));
|
||||||
|
|
||||||
|
//Expose the class Physics and its functions
|
||||||
|
luabridge::getGlobalNamespace(L)
|
||||||
|
.beginClass<Physics>("Physics")
|
||||||
|
//.addFunction("", &Physics::)
|
||||||
|
.endClass();
|
||||||
|
//Push the physics to Lua as a global variable
|
||||||
|
luabridge::push(L, this);
|
||||||
|
lua_setglobal(L, "physics");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::takeUpdateStep(float timeDiff)
|
void Physics::takeUpdateStep(float timeDiff)
|
||||||
|
@ -7,6 +7,13 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "extern/lua/src/lua.h"
|
||||||
|
#include "extern/lua/src/lualib.h"
|
||||||
|
#include "extern/lua/src/lauxlib.h"
|
||||||
|
}
|
||||||
|
#include "extern/luabridge/LuaBridge.h"
|
||||||
|
|
||||||
#include "entity.hh"
|
#include "entity.hh"
|
||||||
|
|
||||||
#include "extern/bullet/src/BulletDynamics/Dynamics/btRigidBody.h"
|
#include "extern/bullet/src/BulletDynamics/Dynamics/btRigidBody.h"
|
||||||
@ -44,7 +51,7 @@ class Physics {
|
|||||||
public:
|
public:
|
||||||
Physics();
|
Physics();
|
||||||
~Physics();
|
~Physics();
|
||||||
void init();
|
void init(lua_State* L);
|
||||||
void takeUpdateStep(float timeDiff); //must be used in level.update to proagate the physics
|
void takeUpdateStep(float timeDiff); //must be used in level.update to proagate the physics
|
||||||
void rollForward(glm::vec3 camPos, float strength); //self explainitory
|
void rollForward(glm::vec3 camPos, float strength); //self explainitory
|
||||||
void rollLeft(glm::vec3 camPos, float strength);
|
void rollLeft(glm::vec3 camPos, float strength);
|
||||||
|
Loading…
Reference in New Issue
Block a user