Added addPlayer analog to addSphere and added a check to make sure incice stay synchronized (possibly dangerous but needs to be tested)

This commit is contained in:
Jasper 2014-11-14 16:23:14 +01:00
parent 6c0c973305
commit 3eb406efd1
2 changed files with 38 additions and 4 deletions

View File

@ -70,14 +70,42 @@ void addTerrain(int width, int length, float** heightData)
}
void addSphere(float rad, float x, float y, float z, float mass, int indice) //TODO add indice check
void addPlayer(float rad, float x, float y, float z, float mass, unsigned indice)
{
if(bodies.size() != indice)
throw std::invalid_argument( "Bodies out of Sync" );
btSphereShape* sphere = new btSphereShape(rad);
btVector3 inertia(0,0,0);
if(mass == 0.0)
if(mass != 0.0)
{
sphere->calculateLocalInertia((btScalar)mass,inertia);
}
else
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(x,y,z)));
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
playerBall = new btRigidBody(info);
world->addRigidBody(playerBall);
bodies.push_back(playerBall);
if(bodies.size() == indice)
throw std::invalid_argument( "Bodies out of Sync" );
}
void addSphere(float rad, float x, float y, float z, float mass, unsigned indice)
{
if(bodies.size() != indice)
throw std::invalid_argument( "Bodies out of Sync" );
btSphereShape* sphere = new btSphereShape(rad);
btVector3 inertia(0,0,0);
if(mass != 0.0)
{
sphere->calculateLocalInertia((btScalar)mass,inertia);
}
@ -91,6 +119,11 @@ void addSphere(float rad, float x, float y, float z, float mass, int indice) //T
world->addRigidBody(body);
bodies.push_back(body);
if(bodies.size() == indice)
throw std::invalid_argument( "Bodies out of Sync" );
}
glm::vec3 getPos(int i)

View File

@ -40,7 +40,8 @@ class Physics {
glm::mat4 getRotation(int i);
void rollForward(glm::mat3 rotCamera);
void addTerrain(int width, int length, float** heightData);
void addSphere(float rad, float x, float y, float z, float mass, int indice);
void addPlayer(float rad, float x, float y, float z, float mass, unsigned indice);
void addSphere(float rad, float x, float y, float z, float mass, unsigned indice);
private:
btRigidBody* playerBody;