prepared camera, level and physics for the new camera

This commit is contained in:
Jasper 2015-01-19 16:51:35 +01:00
parent 4e0fe3bee2
commit 93e5c33dfd
5 changed files with 42 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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){

View File

@ -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()

View File

@ -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;};