From 2b0be77ac959c702760612e43b75b08e26a9b7f7 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 15 Mar 2015 11:20:06 +0100 Subject: [PATCH] Removing code duplication. --- game/physics.cc | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/game/physics.cc b/game/physics.cc index 5a97cfd..4edaa74 100644 --- a/game/physics.cc +++ b/game/physics.cc @@ -23,20 +23,18 @@ void Physics::init(std::string geometryPath) //prepares bullet by creating all i void Physics::takeUpdateStep(float timeDiff) { + for(unsigned i = 0; i < allPositionConstraints.size();i++) //this handles the spring constraints + { + if(allPositionConstraints[i].position != allPositionConstraints[i].body->getCenterOfMassPosition()) //if constraint != position of the body because otherwise dir = 0 + { + btVector3 dir = allPositionConstraints[i].position - allPositionConstraints[i].body->getCenterOfMassPosition(); + dir = dir*allPositionConstraints[i].strength - allPositionConstraints[i].body->getLinearVelocity() + *allPositionConstraints[i].body->getLinearVelocity().length(); + allPositionConstraints[i].body->applyCentralForce(dir*allPositionConstraints[i].strength); //apply a foce upon the object pushing it towards the constraint position + } + } if(simulationActive) { - - for(unsigned i = 0; i < allPositionConstraints.size();i++) //this handles the spring constraints - { - if(allPositionConstraints[i].position != allPositionConstraints[i].body->getCenterOfMassPosition()) //if constraint != position of the body because otherwise dir = 0 - { - btVector3 dir = allPositionConstraints[i].position - allPositionConstraints[i].body->getCenterOfMassPosition(); - dir = dir*allPositionConstraints[i].strength - allPositionConstraints[i].body->getLinearVelocity() - *allPositionConstraints[i].body->getLinearVelocity().length(); - allPositionConstraints[i].body->applyCentralForce(dir*allPositionConstraints[i].strength); //apply a foce upon the object pushing it towards the constraint position - } - } - if(endgame) { currentDirection = playerBall->getCenterOfMassPosition(); @@ -64,23 +62,10 @@ void Physics::takeUpdateStep(float timeDiff) cameraBody->applyCentralForce(currentForce*1.0/force); } - - world->stepSimulation(timeDiff); } else { - for(unsigned i = 0; i < allPositionConstraints.size();i++) //this handles the spring constraints - { - if(allPositionConstraints[i].position != allPositionConstraints[i].body->getCenterOfMassPosition()) //if constraint != position of the body because otherwise dir = 0 - { - btVector3 dir = allPositionConstraints[i].position - allPositionConstraints[i].body->getCenterOfMassPosition(); - dir = dir*allPositionConstraints[i].strength - allPositionConstraints[i].body->getLinearVelocity() - *allPositionConstraints[i].body->getLinearVelocity().length(); - allPositionConstraints[i].body->applyCentralForce(dir*allPositionConstraints[i].strength); //apply a foce upon the object pushing it towards the constraint position - } - } - btVector3 camPos = cameraBody->getCenterOfMassPosition(); if(sinking) {