From 6ee8af58e311a644c072e47386ea1ebbcba2bae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 13 Feb 2015 12:47:34 +0100 Subject: [PATCH] Made it possible again to move the camera upwards. --- physics.cc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/physics.cc b/physics.cc index a1cf635..95a2482 100644 --- a/physics.cc +++ b/physics.cc @@ -41,16 +41,17 @@ void Physics::takeUpdateStep(float timeDiff) allPositionConstraints[i].body->applyCentralForce(dir*allPositionConstraints[i].strength); //apply a foce upon the object pushing it towards the constraint position } } - - - btVector3 position = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); //gets a vector from the player to the camera - position.normalize(); - position *= 5; - position += playerBall->getCenterOfMassPosition(); //is the position 5 units away from the player in the direction of the camera - - position.setY(playerBall->getCenterOfMassPosition().getY() + 1); - - + + + btVector3 position = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); //gets a vector from the player to the camera + position.normalize(); + position *= 5; + position += playerBall->getCenterOfMassPosition(); //is the position 5 units away from the player in the direction of the camera + + //prevent the camera from being dragged along on the ground + if (position.getY() < playerBall->getCenterOfMassPosition().getY() + 1) + position.setY(playerBall->getCenterOfMassPosition().getY() + 1); + btVector3 dir = cameraBody->getCenterOfMassPosition() - position; float str = cameraBody->getInvMass()*50 * dir.length(); cameraBody->applyCentralForce(-dir*str);//scale the force by camera mass @@ -355,7 +356,7 @@ glm::vec3 Physics::getCameraPosition() return save; } -glm::vec3 Physics::getCameraToPlayer()//returns a glm::vec3 the goes from the player to the camera +glm::vec3 Physics::getCameraToPlayer()//returns a glm::vec3 the goes from the camera to the player { btVector3 origin = playerBall->getCenterOfMassPosition() - cameraBody->getCenterOfMassPosition(); glm::vec3 save(origin.getX(),origin.getY(),origin.getZ());