diff --git a/physics.cc b/physics.cc index 24f681f..ed6c952 100644 --- a/physics.cc +++ b/physics.cc @@ -414,6 +414,26 @@ void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, f throw std::invalid_argument( "Bodies out of Sync" ); } +void Physics::prepareCollisionDetection() +{ + playerTerrainCol = playerObjectColision = false; + int numManifods = world->getDispatcher()->getNumManifolds(); + + for (int i=0;isetCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z))); + bodies[indice]->setLinearVelocity(btVector3(0,0,0)); +} + +void Physics::forcePlayer(glm::vec3 newPosition)//ugly, but needed for reset +{ + playerBall->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z))); + playerBall->setLinearVelocity(btVector3(0,0,0)); + forceMoveCamera(newPosition + glm::vec3(currentDirection.x()*cameraDistance,currentDirection.y()*cameraDistance,currentDirection.z()*cameraDistance)); } void Physics::forceMoveCamera(glm::vec3 newPosition) diff --git a/physics.hh b/physics.hh index d8f287e..de2be9c 100644 --- a/physics.hh +++ b/physics.hh @@ -74,6 +74,10 @@ class Physics { void forceMove(glm::vec3 newPosition, unsigned indice); void forceMoveCamera(glm::vec3 newPosition); void addConvexBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling, bool rotate); + void prepareCollisionDetection(); + bool playerWithGround(); + bool playerWithObject(); + void forcePlayer(glm::vec3 newPosition); struct positionConstraint{btRigidBody* body; float strength; btVector3 position;}; @@ -98,6 +102,8 @@ class Physics { int counter = 0; std::string geometryPath; float cameraDistance = 5; //distance of the camera to the player. + bool playerTerrainCol = false; + bool playerObjectColision = false; }; enum collisionTypes{