prepareing modified camera in physics
This commit is contained in:
parent
25c6c6b6e1
commit
393e29c083
1
level.cc
1
level.cc
@ -434,6 +434,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, 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wPressed){
|
if(wPressed){
|
||||||
|
34
physics.cc
34
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
|
/*- cameraBody->getCenterOfMassPosition(); // gives vector from player to camera
|
||||||
position.normalize();
|
position.normalize();
|
||||||
position *=5;
|
position *=5;
|
||||||
@ -40,6 +48,7 @@ void Physics::takeUpdateStep(float timeDiff)
|
|||||||
btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
|
btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
|
||||||
cameraBody->applyCentralForce(dir);
|
cameraBody->applyCentralForce(dir);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::removePositionConstraint(int bodyIndice)
|
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);
|
playerBall->setSleepingThresholds(0,0);
|
||||||
if(bodies.size() != indice)
|
if(bodies.size() != indice)
|
||||||
throw std::invalid_argument( "Bodies out of Sync" );
|
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)
|
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);
|
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),btVector3(0,0,0)));
|
||||||
@ -371,10 +381,10 @@ void Physics::addCamera(float rad, float distance)
|
|||||||
cameraBody->setSleepingThresholds(0,0);
|
cameraBody->setSleepingThresholds(0,0);
|
||||||
|
|
||||||
|
|
||||||
btVector3 pivotInA(5,0,0);
|
/*btVector3 pivotInA(5,0,0);
|
||||||
btVector3 pivotInB(-5, 0, 0);
|
btVector3 pivotInB(-5, 0, 0);
|
||||||
btDistanceConstraint* pdc = new btDistanceConstraint(*cameraBody,*playerBall,pivotInA,pivotInB, distance);
|
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;
|
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)
|
void Physics::rollForward(glm::vec3 camPos,float strength)
|
||||||
{
|
{
|
||||||
btVector3 pos(camPos.x,0,camPos.z);
|
btVector3 pos(camPos.x,0,camPos.z);
|
||||||
|
@ -54,7 +54,8 @@ 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 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();
|
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);
|
void addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice);
|
||||||
|
Loading…
Reference in New Issue
Block a user