diff --git a/level.cc b/level.cc index 97e1ad7..7efa3fe 100644 --- a/level.cc +++ b/level.cc @@ -434,6 +434,7 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre else { mouseDelta.x = -mouseDelta.x; camera.updateRotation(mouseDelta/100.0f); + physics.updateCameraPos(mouseDelta, 0.01f); } if(wPressed){ diff --git a/physics.cc b/physics.cc index c93c7aa..75486c5 100644 --- a/physics.cc +++ b/physics.cc @@ -30,7 +30,15 @@ void Physics::takeUpdateStep(float timeDiff) } } - + btVector3 position = playerBall->getCenterOfMassPosition() ; + position.normalize(); + position *=5; + position += playerBall->getCenterOfMassPosition(); //is the position 5 units away from the player in the direction of the camera + + + btVector3 dir = cameraBody->getCenterOfMassPosition() - position; + cameraBody->applyCentralForce(dir); + /*- cameraBody->getCenterOfMassPosition(); // gives vector from player to camera position.normalize(); position *=5; @@ -40,6 +48,7 @@ void Physics::takeUpdateStep(float timeDiff) btVector3 dir = cameraBody->getCenterOfMassPosition() - position; cameraBody->applyCentralForce(dir); */ + } void Physics::removePositionConstraint(int bodyIndice) @@ -162,7 +171,8 @@ void Physics::addPlayer(float friction, float rad, Entity entity, float mass, fl playerBall->setSleepingThresholds(0,0); if(bodies.size() != indice) throw std::invalid_argument( "Bodies out of Sync" ); - + + addCamera(); } void Physics::addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA,unsigned indice) @@ -353,9 +363,9 @@ void Physics::addTriangleMeshBody(Entity entity, float mass, float dampningL, fl }*/ -void Physics::addCamera(float rad, float distance) +void Physics::addCamera() { - btSphereShape* sphere = new btSphereShape(rad); + btSphereShape* sphere = new btSphereShape(0.5f); btVector3 inertia(0,0,0); btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0))); @@ -371,10 +381,10 @@ void Physics::addCamera(float rad, float distance) cameraBody->setSleepingThresholds(0,0); - btVector3 pivotInA(5,0,0); + /*btVector3 pivotInA(5,0,0); btVector3 pivotInB(-5, 0, 0); btDistanceConstraint* pdc = new btDistanceConstraint(*cameraBody,*playerBall,pivotInA,pivotInB, distance); - world->addConstraint(pdc); + world->addConstraint(pdc);*/ } @@ -404,6 +414,18 @@ glm::mat4 Physics::getRotation(int i) return matrix; } +void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength) +{ + btVector3 change = playerBall->getCenterOfMassPosition()-cameraBody->getCenterOfMassPosition();; + change.setY(0); + change.normalize(); + change *= mouseMovement.x; + change = btCross(btVector3(0,1,0),change); + change.setY(mouseMovement.y); + change*=strength; + +} + void Physics::rollForward(glm::vec3 camPos,float strength) { btVector3 pos(camPos.x,0,camPos.z); diff --git a/physics.hh b/physics.hh index 51574eb..7abced2 100644 --- a/physics.hh +++ b/physics.hh @@ -54,7 +54,8 @@ class Physics { glm::vec3 getPos(int i); glm::mat4 getRotation(int i); void addStaticGroundPlane(); - void addCamera(float rad, float distance); //Do NOT impliment before Player has been created; + void addCamera(); //Do NOT impliment before Player has been created; + void updateCameraPos(glm::vec2 mouseMovement, float strength); glm::vec3 getCameraPosition(); void addRigidBodyFromFile(Entity entity, float mass, float dampningL, float dampningA, std::string modelLocation, unsigned indice); void addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice);