Reenabled zooming with the mouse wheel.

This commit is contained in:
Steffen Fündgens 2015-02-13 15:20:32 +01:00
parent e91d045a37
commit d55bb3465c
4 changed files with 12 additions and 11 deletions

View File

@ -7,7 +7,7 @@ Camera::Camera(glm::vec2 rotation, float distance) {
Camera::Camera() { Camera::Camera() {
rotation = glm::vec2(0.0f, 0.0f); rotation = glm::vec2(0.0f, 0.0f);
distance = 1.0f; distance = 5.0f;
} }
Camera::~Camera() { Camera::~Camera() {

View File

@ -64,7 +64,7 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
else { else {
mouseDelta.x = -mouseDelta.x; mouseDelta.x = -mouseDelta.x;
camera.updateRotation(mouseDelta/100.0f); camera.updateRotation(mouseDelta/100.0f);
physics.updateCameraPos(mouseDelta, 50); physics.updateCameraPos(mouseDelta, 50, camera.getDistance());
camera.setPosition(physics.getCameraPosition()); camera.setPosition(physics.getCameraPosition());
camera.setDirection(physics.getCameraToPlayer()); camera.setDirection(physics.getCameraToPlayer());

View File

@ -25,11 +25,11 @@ void Physics::init(std::string geometryPath) //prepares bullet by creating all i
void Physics::takeUpdateStep(float timeDiff) void Physics::takeUpdateStep(float timeDiff)
{ {
counter++; counter++;
if(counter<1) /*if(counter<1)
{ {
world->stepSimulation(timeDiff); //allows the world to be simmulated correctly indipendant of the timedifferences between frames world->stepSimulation(timeDiff); //allows the world to be simmulated correctly indipendant of the timedifferences between frames
return; return;
} }*/
for(unsigned i = 0; i < allPositionConstraints.size();i++) //this handles the spring constraints for(unsigned i = 0; i < allPositionConstraints.size();i++) //this handles the spring constraints
{ {
@ -44,8 +44,8 @@ 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.normalize();
position *= 5; position *= cameraDistance;
position += playerBall->getCenterOfMassPosition(); //is the position 5 units away from the player in the direction of the camera 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 //prevent the camera from being dragged along on the ground
if (position.getY() < playerBall->getCenterOfMassPosition().getY() + 1) if (position.getY() < playerBall->getCenterOfMassPosition().getY() + 1)
@ -58,7 +58,6 @@ void Physics::takeUpdateStep(float timeDiff)
float speed = cameraBody->getLinearVelocity().length(); float speed = cameraBody->getLinearVelocity().length();
if(speed>20.0f) if(speed>20.0f)
{ {
printf("%f , %f \n", speed, position.length());
position = cameraBody->getLinearVelocity(); position = cameraBody->getLinearVelocity();
position.normalize(); position.normalize();
cameraBody->setLinearVelocity(position*20); cameraBody->setLinearVelocity(position*20);
@ -267,7 +266,7 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(glmQuat.x,glmQuat.y,glmQuat.z,glmQuat.w),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z))); btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(glmQuat.x,glmQuat.y,glmQuat.z,glmQuat.w),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z)));
btVector3 inertia(0,0,0); btVector3 inertia(0,0,0);
if(mass != 0.0) if(mass != 0.0 && rotate) //&& rotate lets certain objects get inertia (0,0,0) (not rotateable)
{ {
box->calculateLocalInertia((btScalar)mass,inertia); box->calculateLocalInertia((btScalar)mass,inertia);
} }
@ -326,7 +325,7 @@ void Physics::addCamera() //Camera Creator automatically called when player is c
btVector3 direction(1,1,1); btVector3 direction(1,1,1);
direction.normalize(); direction.normalize();
direction*=5; //create a offset of lenth 5 so we have a stable camera at the beginning direction*=cameraDistance; //create a offset of length 5 so we have a stable camera at the beginning
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),playerBall->getCenterOfMassPosition()+direction)); btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),playerBall->getCenterOfMassPosition()+direction));
btRigidBody::btRigidBodyConstructionInfo info(0.001,motion,sphere,inertia); btRigidBody::btRigidBodyConstructionInfo info(0.001,motion,sphere,inertia);
@ -377,8 +376,9 @@ glm::mat4 Physics::getRotation(int i)
} }
//these are used to apply a force to the camera body according to the movement of the mouse //these are used to apply a force to the camera body according to the movement of the mouse
void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength) void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float distance)
{ {
this->cameraDistance = distance;
//note: in mouseMovement x and y are flipped in contrast to bullet //note: in mouseMovement x and y are flipped in contrast to bullet
btVector3 change = playerBall->getCenterOfMassPosition()-cameraBody->getCenterOfMassPosition(); btVector3 change = playerBall->getCenterOfMassPosition()-cameraBody->getCenterOfMassPosition();
change.setY(0); change.setY(0);

View File

@ -54,7 +54,7 @@ class Physics {
glm::vec3 getPos(int i); glm::vec3 getPos(int i);
glm::mat4 getRotation(int i); glm::mat4 getRotation(int i);
void addStaticGroundPlane(); void addStaticGroundPlane();
void updateCameraPos(glm::vec2 mouseMovement, float strength); void updateCameraPos(glm::vec2 mouseMovement, float strength, float distance);
glm::vec3 getCameraPosition(); glm::vec3 getCameraPosition();
void addRigidBodyFromFile(Entity entity, float mass, float dampningL, float dampningA, std::string modelLocation, unsigned indice); 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, float scaling,bool rotate); void addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling,bool rotate);
@ -90,6 +90,7 @@ class Physics {
int terrainPhysicsCollision = 2; int terrainPhysicsCollision = 2;
int counter = 0; int counter = 0;
std::string geometryPath; std::string geometryPath;
float cameraDistance = 5; //distance of the camera to the player.
}; };
enum collisionTypes{ enum collisionTypes{