From d4fe5e1ae14786c1cce55c4c8611123d37394e4e Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 13 Feb 2015 17:22:01 +0100 Subject: [PATCH] added move system and modified the camera for less bobidity --- physics.cc | 24 ++++++++++++++++++++---- physics.hh | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/physics.cc b/physics.cc index 60a28b6..992f602 100644 --- a/physics.cc +++ b/physics.cc @@ -42,18 +42,28 @@ void Physics::takeUpdateStep(float timeDiff) } - btVector3 position = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); //gets a vector from the player to the camera + btVector3 position = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); //gets a vector from the player to the camera position.normalize(); position *= cameraDistance; 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); btVector3 dir = cameraBody->getCenterOfMassPosition() - position; float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass - cameraBody->applyCentralForce(-dir*str); //scale the force by camera mass + + + /*if(dir.length() > -0.1f && dir.length() < 0.1f) + { + cameraBody->setLinearVelocity(btVector3(0,0,0)); + world->stepSimulation(timeDiff); + return; + }*/ + + cameraBody->setLinearVelocity(btVector3(0,0,0)); + cameraBody->applyCentralForce(-dir*str*10) ; //scale the force by camera mass counter=0; float speed = cameraBody->getLinearVelocity().length(); if(speed>20.0f) @@ -408,7 +418,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis change.normalize(); //normalize so that the distance between camera and body does not matter change *= (mouseMovement.y); //we start with left/right movement because this needs to be calculated via a crossproduct, and the up down value would alter that change = btCross(btVector3(0,1,0),change); - change.setY(mouseMovement.x/5); //scaleing because otherwise oup/down much stronger then left right + change.setY(mouseMovement.x); //scaleing because otherwise oup/down much stronger then left right change *= strength / cameraBody->getInvMass(); cameraBody->applyCentralForce(change); @@ -467,6 +477,12 @@ void Physics::addStaticGroundPlane() } //not needed anymoer, but still good for debugging + +void Physics::forceMove(glm::vec3 newPosition, unsigned indice) +{ + bodies[indice]->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 fb36d78..a3ff19d 100644 --- a/physics.hh +++ b/physics.hh @@ -68,6 +68,7 @@ class Physics { glm::vec3 getCameraToPlayer(); void kill(); void addButtonFrame(Entity entity); + void forceMove(glm::vec3 newPosition, unsigned indice); struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};