Merge branch 'master' of https://github.com/Faerbit/swp
This commit is contained in:
commit
dfe83042b5
48
physics.cc
48
physics.cc
@ -24,6 +24,8 @@ void Physics::init(std::string geometryPath) //prepares bullet by creating all i
|
|||||||
|
|
||||||
void Physics::takeUpdateStep(float timeDiff)
|
void Physics::takeUpdateStep(float timeDiff)
|
||||||
{
|
{
|
||||||
|
if(simulationActive)
|
||||||
|
{
|
||||||
counter++;
|
counter++;
|
||||||
if(counter<1)
|
if(counter<1)
|
||||||
{
|
{
|
||||||
@ -65,6 +67,36 @@ void Physics::takeUpdateStep(float timeDiff)
|
|||||||
cameraBody->setLinearVelocity(position*20);
|
cameraBody->setLinearVelocity(position*20);
|
||||||
}
|
}
|
||||||
world->stepSimulation(timeDiff);
|
world->stepSimulation(timeDiff);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(sinking)
|
||||||
|
{
|
||||||
|
btVector3 currentPos = playerBall->getCenterOfMassPosition();
|
||||||
|
currentPos -= btVector3(0,0.003f,0);
|
||||||
|
playerBall->setCenterOfMassTransform(btTransform(playerBall->getOrientation(),currentPos));
|
||||||
|
if(playerBall->getCenterOfMassPosition().y() < resetHight - 3)
|
||||||
|
{
|
||||||
|
playerBall->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(startPosition.x(),startPosition.y() - 3,startPosition.z())));
|
||||||
|
playerBall->setLinearVelocity(btVector3(0,0,0));
|
||||||
|
playerBall->setAngularVelocity(btVector3(0,0,0));
|
||||||
|
forceMoveCamera(startPosition + btVector3(currentDirection.x()*cameraDistance,currentDirection.y()*cameraDistance,currentDirection.z()*cameraDistance));
|
||||||
|
sinking = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
btVector3 currentPos = playerBall->getCenterOfMassPosition();
|
||||||
|
currentPos += btVector3(0,0.009f,0);
|
||||||
|
playerBall->setCenterOfMassTransform(btTransform(playerBall->getOrientation(),currentPos));
|
||||||
|
|
||||||
|
if(playerBall->getCenterOfMassPosition().y() >= startPosition.y() + 1)
|
||||||
|
{
|
||||||
|
sinking = true;
|
||||||
|
simulationActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::removePositionConstraint(int bodyIndice) //remover function for deleting all pos constraints on one body
|
void Physics::removePositionConstraint(int bodyIndice) //remover function for deleting all pos constraints on one body
|
||||||
@ -105,6 +137,8 @@ void Physics::addPlayer(float friction, float rad, Entity entity, float mass, fl
|
|||||||
|
|
||||||
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(glmQuat.x,glmQuat.y,glmQuat.z,glmQuat.w),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z))); //next we define the motionstate, wich describes the innital position and rotation
|
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(glmQuat.x,glmQuat.y,glmQuat.z,glmQuat.w),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z))); //next we define the motionstate, wich describes the innital position and rotation
|
||||||
|
|
||||||
|
startPosition =btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z);
|
||||||
|
|
||||||
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia); //next we process all data for the rigid body into info
|
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia); //next we process all data for the rigid body into info
|
||||||
|
|
||||||
info.m_friction = friction*2; //here we modify the friction and restitution (bounciness) of the object
|
info.m_friction = friction*2; //here we modify the friction and restitution (bounciness) of the object
|
||||||
@ -578,18 +612,22 @@ void Physics::forceMove(glm::vec3 newPosition, unsigned indice)//ugly, but neede
|
|||||||
{
|
{
|
||||||
bodies[indice]->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
|
bodies[indice]->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
|
||||||
bodies[indice]->setLinearVelocity(btVector3(0,0,0));
|
bodies[indice]->setLinearVelocity(btVector3(0,0,0));
|
||||||
|
bodies[indice]->setAngularVelocity(btVector3(0,0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::forcePlayer(glm::vec3 newPosition)//ugly, but needed for reset
|
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)));
|
if(!simulationActive)
|
||||||
playerBall->setLinearVelocity(btVector3(0,0,0));
|
return;
|
||||||
forceMoveCamera(newPosition + glm::vec3(currentDirection.x()*cameraDistance,currentDirection.y()*cameraDistance,currentDirection.z()*cameraDistance));
|
simulationActive = false;
|
||||||
|
resetHight = playerBall->getCenterOfMassPosition().y();
|
||||||
|
|
||||||
|
startPosition = btVector3(newPosition.x,newPosition.y,newPosition.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::forceMoveCamera(glm::vec3 newPosition)
|
void Physics::forceMoveCamera(btVector3 newPosition)
|
||||||
{
|
{
|
||||||
cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
|
cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),newPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::kill() //delete dynamically allocated memory
|
void Physics::kill() //delete dynamically allocated memory
|
||||||
|
@ -72,7 +72,7 @@ class Physics {
|
|||||||
void kill();
|
void kill();
|
||||||
void addButtonFrame(Entity entity);
|
void addButtonFrame(Entity entity);
|
||||||
void forceMove(glm::vec3 newPosition, unsigned indice);
|
void forceMove(glm::vec3 newPosition, unsigned indice);
|
||||||
void forceMoveCamera(glm::vec3 newPosition);
|
void forceMoveCamera(btVector3 newPosition);
|
||||||
void addConvexBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling, bool rotate);
|
void addConvexBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling, bool rotate);
|
||||||
void prepareCollisionDetection();
|
void prepareCollisionDetection();
|
||||||
bool playerWithGround();
|
bool playerWithGround();
|
||||||
@ -82,6 +82,10 @@ class Physics {
|
|||||||
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
btVector3 startPosition = btVector3(0,0,0);
|
||||||
|
float resetHight = 0;
|
||||||
|
bool simulationActive = true;
|
||||||
|
bool sinking = true;
|
||||||
btVector3 currentDirection = btVector3(1,1,1);
|
btVector3 currentDirection = btVector3(1,1,1);
|
||||||
btRigidBody* playerBall; //allows for easier access to the ball
|
btRigidBody* playerBall; //allows for easier access to the ball
|
||||||
btRigidBody* terrainBody; //duh
|
btRigidBody* terrainBody; //duh
|
||||||
|
Loading…
Reference in New Issue
Block a user