added playermove
This commit is contained in:
parent
6f0e0997e3
commit
5dd03ef9e6
30
physics.cc
30
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;i<numManifods;i++)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
bool Physics::playerWithGround()
|
||||
{
|
||||
return playerTerrainCol;
|
||||
}
|
||||
|
||||
bool Physics::playerWithObject()
|
||||
{
|
||||
return playerObjectColision;
|
||||
}
|
||||
|
||||
void Physics::addCamera() //Camera Creator automatically called when player is created
|
||||
{
|
||||
btSphereShape* sphere = new btSphereShape(0.2f); //we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects
|
||||
@ -496,7 +516,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis
|
||||
currentDirection = compare;
|
||||
}
|
||||
|
||||
currentDirection = currentDirection.rotate(btVector3(0,1,0),mouseMovement.y/100);
|
||||
currentDirection = currentDirection.rotate(btVector3(0,1,0),-mouseMovement.y/100);
|
||||
currentDirection.normalize();
|
||||
}
|
||||
|
||||
@ -557,6 +577,14 @@ void Physics::addStaticGroundPlane()
|
||||
void Physics::forceMove(glm::vec3 newPosition, unsigned indice)//ugly, but needed for reset
|
||||
{
|
||||
bodies[indice]->setCenterOfMassTransform(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)
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user