From 760a7c9d866e2ea23f0a09aaf21ef551d1660d91 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 13 Feb 2015 17:47:21 +0100 Subject: [PATCH] changed hight of camera and added camera move methode in physics --- physics.cc | 11 ++++++++--- physics.hh | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/physics.cc b/physics.cc index 992f602..0f11b4e 100644 --- a/physics.cc +++ b/physics.cc @@ -48,8 +48,8 @@ void Physics::takeUpdateStep(float timeDiff) position += playerBall->getCenterOfMassPosition(); //is the position cameraDistance 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); + if (position.getY() < playerBall->getCenterOfMassPosition().getY() + cameraDistance/2) + position.setY(playerBall->getCenterOfMassPosition().getY() + cameraDistance/2); btVector3 dir = cameraBody->getCenterOfMassPosition() - position; float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass @@ -478,11 +478,16 @@ void Physics::addStaticGroundPlane() -void Physics::forceMove(glm::vec3 newPosition, unsigned indice) +void Physics::forceMove(glm::vec3 newPosition, unsigned indice)//ugly, but needed for reset { bodies[indice]->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z))); } +void Physics::forceMoveCamera(glm::vec3 newPosition) +{ + cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z))); +} + void Physics::kill() //delete dynamically allocated memory { if (world == NULL) { diff --git a/physics.hh b/physics.hh index a3ff19d..6026ea7 100644 --- a/physics.hh +++ b/physics.hh @@ -69,6 +69,7 @@ class Physics { void kill(); void addButtonFrame(Entity entity); void forceMove(glm::vec3 newPosition, unsigned indice); + void forceMoveCamera(glm::vec3 newPosition); struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};