Created a moveObject function in the Level class.

This commit is contained in:
Steffen 2015-01-17 13:30:33 +01:00
parent f496532126
commit 04df8bd22f
3 changed files with 9 additions and 3 deletions

View File

@ -62,6 +62,7 @@ void Level::load() {
.beginClass<Level>("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);
}

View File

@ -32,6 +32,7 @@ class Level {
std::vector<Object*>* 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;

View File

@ -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);
}