prepared camera, level and physics for the new camera
This commit is contained in:
parent
4e0fe3bee2
commit
93e5c33dfd
21
camera.cc
21
camera.cc
@ -60,6 +60,27 @@ void Camera:: updateDistance(float distance) {
|
|||||||
updatePosition();
|
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() {
|
void Camera::updatePosition() {
|
||||||
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, distance, 0.0f);
|
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, distance, 0.0f);
|
||||||
// rotate vector
|
// rotate vector
|
||||||
|
@ -15,11 +15,18 @@ class Camera {
|
|||||||
void setRotation(glm::vec2 rotation);
|
void setRotation(glm::vec2 rotation);
|
||||||
void updateRotation(glm::vec2 rotation); //adds to current rotation
|
void updateRotation(glm::vec2 rotation); //adds to current rotation
|
||||||
glm::vec3 getVector();
|
glm::vec3 getVector();
|
||||||
|
void setPosition(glm::vec3 pos);
|
||||||
|
glm::vec3 getPosition();
|
||||||
|
void setDirection(glm::vec3 dir);
|
||||||
|
glm::vec3 getDirection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
float distance;
|
float distance;
|
||||||
glm::vec2 rotation;
|
glm::vec2 rotation;
|
||||||
glm::vec3 vector;
|
glm::vec3 vector;
|
||||||
|
glm::vec3 position;
|
||||||
|
glm::vec3 direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
3
level.cc
3
level.cc
@ -435,6 +435,9 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
|
|||||||
mouseDelta.x = -mouseDelta.x;
|
mouseDelta.x = -mouseDelta.x;
|
||||||
camera.updateRotation(mouseDelta/100.0f);
|
camera.updateRotation(mouseDelta/100.0f);
|
||||||
physics.updateCameraPos(mouseDelta, 0.01f);
|
physics.updateCameraPos(mouseDelta, 0.01f);
|
||||||
|
|
||||||
|
camera.setPosition(physics.getCameraPosition());
|
||||||
|
camera.setDirection(physics.getCameraToPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wPressed){
|
if(wPressed){
|
||||||
|
12
physics.cc
12
physics.cc
@ -368,13 +368,13 @@ void Physics::addCamera()
|
|||||||
btSphereShape* sphere = new btSphereShape(0.5f);
|
btSphereShape* sphere = new btSphereShape(0.5f);
|
||||||
|
|
||||||
btVector3 inertia(0,0,0);
|
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);
|
btRigidBody::btRigidBodyConstructionInfo info(1/(playerBall->getInvMass()/100),motion,sphere,inertia);
|
||||||
|
|
||||||
cameraBody = new btRigidBody(info);
|
cameraBody = new btRigidBody(info);
|
||||||
|
|
||||||
cameraBody->setDamping(0.9f,1.0f);
|
cameraBody->setDamping(0.95f,1.0f);
|
||||||
|
|
||||||
world->addRigidBody(cameraBody,COL_OBJECTS, objectsPhysicsCollision);
|
world->addRigidBody(cameraBody,COL_OBJECTS, objectsPhysicsCollision);
|
||||||
|
|
||||||
@ -396,6 +396,13 @@ glm::vec3 Physics::getCameraPosition()
|
|||||||
return save;
|
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)
|
glm::vec3 Physics::getPos(int i)
|
||||||
{
|
{
|
||||||
btVector3 origin = bodies[i]->getCenterOfMassPosition();
|
btVector3 origin = bodies[i]->getCenterOfMassPosition();
|
||||||
@ -460,6 +467,7 @@ void Physics::rollRight(glm::vec3 camPos,float strength)
|
|||||||
playerBall->applyTorque(-pos);
|
playerBall->applyTorque(-pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//not used right now
|
//not used right now
|
||||||
|
|
||||||
void Physics::addStaticGroundPlane()
|
void Physics::addStaticGroundPlane()
|
||||||
|
@ -67,6 +67,7 @@ class Physics {
|
|||||||
void addPositionConstraint(int bodyIndice, float strength, glm::vec3 position);
|
void addPositionConstraint(int bodyIndice, float strength, glm::vec3 position);
|
||||||
void removePositionConstraint(int bodyIndice);
|
void removePositionConstraint(int bodyIndice);
|
||||||
void addButton(float radius, float height, Entity entity, float mass, float dampningL, float dampningA, unsigned indice);
|
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;};
|
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user