Removing code duplication.

This commit is contained in:
Faerbit 2015-03-15 11:20:06 +01:00
parent 85d08d81d2
commit 2b0be77ac9

View File

@ -23,20 +23,18 @@ void Physics::init(std::string geometryPath) //prepares bullet by creating all i
void Physics::takeUpdateStep(float timeDiff) 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) 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) if(endgame)
{ {
currentDirection = playerBall->getCenterOfMassPosition(); currentDirection = playerBall->getCenterOfMassPosition();
@ -64,23 +62,10 @@ void Physics::takeUpdateStep(float timeDiff)
cameraBody->applyCentralForce(currentForce*1.0/force); cameraBody->applyCentralForce(currentForce*1.0/force);
} }
world->stepSimulation(timeDiff); world->stepSimulation(timeDiff);
} }
else 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(); btVector3 camPos = cameraBody->getCenterOfMassPosition();
if(sinking) if(sinking)
{ {