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