From 93e5c33dfd8eae1a741b8ab7fe709f94d65e2bc6 Mon Sep 17 00:00:00 2001 From: Jasper Date: Mon, 19 Jan 2015 16:51:35 +0100 Subject: [PATCH] prepared camera, level and physics for the new camera --- camera.cc | 21 +++++++++++++++++++++ camera.hh | 7 +++++++ level.cc | 3 +++ physics.cc | 12 ++++++++++-- physics.hh | 1 + 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/camera.cc b/camera.cc index 109ff7a..631e3bf 100644 --- a/camera.cc +++ b/camera.cc @@ -60,6 +60,27 @@ void Camera:: updateDistance(float distance) { updatePosition(); } +void Camera::setPosition(glm::vec3 pos) +{ + position = pos; +} + +glm::vec3 Camera::getPosition() +{ + return position; +} + +void Camera::setDirection(glm::vec3 dir) +{ + direction = dir; +} + +glm::vec3 Camera::getDirection() +{ + return direction; +} + + void Camera::updatePosition() { glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, distance, 0.0f); // rotate vector diff --git a/camera.hh b/camera.hh index 70337cc..71b6b86 100644 --- a/camera.hh +++ b/camera.hh @@ -15,11 +15,18 @@ class Camera { void setRotation(glm::vec2 rotation); void updateRotation(glm::vec2 rotation); //adds to current rotation glm::vec3 getVector(); + void setPosition(glm::vec3 pos); + glm::vec3 getPosition(); + void setDirection(glm::vec3 dir); + glm::vec3 getDirection(); + private: void updatePosition(); float distance; glm::vec2 rotation; glm::vec3 vector; + glm::vec3 position; + glm::vec3 direction; }; #endif diff --git a/level.cc b/level.cc index 7efa3fe..2c65496 100644 --- a/level.cc +++ b/level.cc @@ -435,6 +435,9 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre mouseDelta.x = -mouseDelta.x; camera.updateRotation(mouseDelta/100.0f); physics.updateCameraPos(mouseDelta, 0.01f); + + camera.setPosition(physics.getCameraPosition()); + camera.setDirection(physics.getCameraToPlayer()); } if(wPressed){ diff --git a/physics.cc b/physics.cc index 75486c5..6e3ffed 100644 --- a/physics.cc +++ b/physics.cc @@ -368,13 +368,13 @@ void Physics::addCamera() 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))); + btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),playerBall->getCenterOfMassPosition()+btVector3(5,5,5))); btRigidBody::btRigidBodyConstructionInfo info(1/(playerBall->getInvMass()/100),motion,sphere,inertia); cameraBody = new btRigidBody(info); - cameraBody->setDamping(0.9f,1.0f); + cameraBody->setDamping(0.95f,1.0f); world->addRigidBody(cameraBody,COL_OBJECTS, objectsPhysicsCollision); @@ -396,6 +396,13 @@ glm::vec3 Physics::getCameraPosition() return save; } +glm::vec3 Physics::getCameraToPlayer() +{ + btVector3 origin = playerBall->getCenterOfMassPosition() - cameraBody->getCenterOfMassPosition(); + glm::vec3 save(origin.getX(),origin.getY(),origin.getZ()); + return save; +} + glm::vec3 Physics::getPos(int i) { btVector3 origin = bodies[i]->getCenterOfMassPosition(); @@ -460,6 +467,7 @@ void Physics::rollRight(glm::vec3 camPos,float strength) playerBall->applyTorque(-pos); } + //not used right now void Physics::addStaticGroundPlane() diff --git a/physics.hh b/physics.hh index 7abced2..54b1e59 100644 --- a/physics.hh +++ b/physics.hh @@ -67,6 +67,7 @@ class Physics { void addPositionConstraint(int bodyIndice, float strength, glm::vec3 position); void removePositionConstraint(int bodyIndice); void addButton(float radius, float height, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); + glm::vec3 getCameraToPlayer(); struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};