From 3e78b4f4bb5b3493765b4c3a4a6bcdcf5132e2d9 Mon Sep 17 00:00:00 2001 From: Steffen Date: Sat, 17 Jan 2015 13:30:33 +0100 Subject: [PATCH] Created a moveObject function in the Level class. --- level.cc | 7 ++++++- level.hh | 1 + physics.cc | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/level.cc b/level.cc index 19d5d53..adba222 100644 --- a/level.cc +++ b/level.cc @@ -62,6 +62,7 @@ void Level::load() { .beginClass("Level") .addFunction("deleteObject", &Level::deleteObject) .addFunction("getObjectCount", &Level::getObjectCount) + .addFunction("moveObject", &Level::moveObject) .endClass(); //Push the level to Lua as a global variable luabridge::push(L, this); @@ -493,7 +494,11 @@ int Level::getObjectCount(){ return objects.size(); } - +void Level::moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos){ + glm::vec3 position = glm::vec3(xPos, yPos, zPos); + physics.removePositionConstraint(objectIndex); + physics.addPositionConstraint(objectIndex, strength, position); +} diff --git a/level.hh b/level.hh index ea48d0e..495c2c5 100644 --- a/level.hh +++ b/level.hh @@ -32,6 +32,7 @@ class Level { std::vector* getObjects(); void deleteObject(int objectIndex); int getObjectCount(); + void moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos); private: void errorCheck(tinyxml2::XMLError error); std::string levelNum; diff --git a/physics.cc b/physics.cc index 7e4d166..793b621 100644 --- a/physics.cc +++ b/physics.cc @@ -34,9 +34,9 @@ void Physics::takeUpdateStep(float timeDiff) void Physics::removePositionConstraint(int bodyIndice) { - for(unsigned i = 0; i < allPositionConstraints.size();i++) + for(unsigned i = 0; i < allPositionConstraints.size(); i++) { - if(allPositionConstraints[i].body == bodies[i] ) + if(allPositionConstraints[i].body == bodies[bodyIndice]) { allPositionConstraints.erase(allPositionConstraints.begin()+i); }