Merge branch 'master' of https://github.com/Faerbit/swp
This commit is contained in:
commit
b5937ce772
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@
|
|||||||
<modelPath>block.obj</modelPath>
|
<modelPath>block.obj</modelPath>
|
||||||
<xOffset>0.0</xOffset>
|
<xOffset>0.0</xOffset>
|
||||||
<yOffset>1.0</yOffset>
|
<yOffset>1.0</yOffset>
|
||||||
<zOffset>2.0</zOffset>
|
<zOffset>0.0</zOffset>
|
||||||
<scale>1.5</scale>
|
<scale>1.5</scale>
|
||||||
<mass>25.0</mass>
|
<mass>25.0</mass>
|
||||||
</object>
|
</object>
|
||||||
@ -162,7 +162,7 @@
|
|||||||
<shininess>2.0</shininess>
|
<shininess>2.0</shininess>
|
||||||
<physicType>Box</physicType>
|
<physicType>Box</physicType>
|
||||||
<width>5.0</width>
|
<width>5.0</width>
|
||||||
<height>6.0</height>
|
<height>3</height>
|
||||||
<length>1.8</length>
|
<length>1.8</length>
|
||||||
<dampningL>0.8</dampningL>
|
<dampningL>0.8</dampningL>
|
||||||
<dampningA>0.9</dampningA>
|
<dampningA>0.9</dampningA>
|
||||||
|
54
physics.cc
54
physics.cc
@ -30,6 +30,35 @@ void Physics::init(lua_State* L)
|
|||||||
void Physics::takeUpdateStep(float timeDiff)
|
void Physics::takeUpdateStep(float timeDiff)
|
||||||
{
|
{
|
||||||
world->stepSimulation(timeDiff);
|
world->stepSimulation(timeDiff);
|
||||||
|
for(unsigned i = 0; i < allPositionConstraints.size();i++)
|
||||||
|
{
|
||||||
|
if(allPositionConstraints[i].position != allPositionConstraints[i].body->getCenterOfMassPosition())
|
||||||
|
{
|
||||||
|
btVector3 dir = allPositionConstraints[i].body->getCenterOfMassPosition() - allPositionConstraints[i].position;
|
||||||
|
allPositionConstraints[i].body->applyCentralForce(dir*allPositionConstraints[i].strength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Physics::removePositionConstraint(int bodyIndice)
|
||||||
|
{
|
||||||
|
for(unsigned i = 0; i < allPositionConstraints.size();i++)
|
||||||
|
{
|
||||||
|
if(allPositionConstraints[i].body == bodies[i] )
|
||||||
|
{
|
||||||
|
allPositionConstraints.erase(allPositionConstraints.begin()+i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Physics::addPositionConstraint(int bodyIndice, float strength, glm::vec3 position)
|
||||||
|
{
|
||||||
|
positionConstraint cons;
|
||||||
|
cons.body = bodies[bodyIndice];
|
||||||
|
cons.strength = strength;
|
||||||
|
cons.position = btVector3(position.x,position.y,position.z);
|
||||||
|
allPositionConstraints.push_back(cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TERRAIN SUBSET
|
//TERRAIN SUBSET
|
||||||
@ -45,6 +74,7 @@ void Physics::addTerrainTriangles(int width, int length, float** heightData)
|
|||||||
btVector3 v2(i,heightData[j+1][i],j+1);
|
btVector3 v2(i,heightData[j+1][i],j+1);
|
||||||
|
|
||||||
trimesh->addTriangle(v0,v1,v2);
|
trimesh->addTriangle(v0,v1,v2);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i = 1; i < width;i++)
|
for(int i = 1; i < width;i++)
|
||||||
@ -100,17 +130,6 @@ void Physics::addTerrain(int width, int length, float** heightData)
|
|||||||
world->addRigidBody(terrainBody, COL_TERRAIN, COL_TERRAIN | COL_OBJECTS);
|
world->addRigidBody(terrainBody, COL_TERRAIN, COL_TERRAIN | COL_OBJECTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::addStaticGroundPlane()
|
|
||||||
{
|
|
||||||
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 0);
|
|
||||||
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
|
|
||||||
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
|
|
||||||
staticGroundBody = new btRigidBody(groundRigidBodyCI);
|
|
||||||
|
|
||||||
world->addRigidBody(staticGroundBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//players and objects
|
//players and objects
|
||||||
void Physics::addPlayer(float friction, float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice)
|
void Physics::addPlayer(float friction, float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice)
|
||||||
{
|
{
|
||||||
@ -129,6 +148,7 @@ void Physics::addPlayer(float friction, float rad, Entity entity, float mass, fl
|
|||||||
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
|
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
|
||||||
|
|
||||||
info.m_friction = friction;
|
info.m_friction = friction;
|
||||||
|
info.m_restitution = 0.0f;
|
||||||
|
|
||||||
playerBall = new btRigidBody(info);
|
playerBall = new btRigidBody(info);
|
||||||
|
|
||||||
@ -389,6 +409,18 @@ void Physics::rollRight(glm::vec3 camPos,float strength)
|
|||||||
playerBall->applyTorque(-pos);
|
playerBall->applyTorque(-pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//not used right now
|
||||||
|
|
||||||
|
void Physics::addStaticGroundPlane()
|
||||||
|
{
|
||||||
|
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 0);
|
||||||
|
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
|
||||||
|
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
|
||||||
|
staticGroundBody = new btRigidBody(groundRigidBodyCI);
|
||||||
|
|
||||||
|
world->addRigidBody(staticGroundBody);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void kill()
|
void kill()
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,10 @@ class Physics {
|
|||||||
void addPlayer(float friction, float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //use these AFTER physicObjects.push_back(object)! if mass == 0 then the object is unmoveable
|
void addPlayer(float friction, float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //use these AFTER physicObjects.push_back(object)! if mass == 0 then the object is unmoveable
|
||||||
void addSphere(float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //The Indice should be set to physicObjects.size()
|
void addSphere(float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //The Indice should be set to physicObjects.size()
|
||||||
void addBox(float width, float height, float length, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //this is used to ensuer that the system is synchronized
|
void addBox(float width, float height, float length, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //this is used to ensuer that the system is synchronized
|
||||||
|
void addPositionConstraint(int bodyIndice, float strength, glm::vec3 position);
|
||||||
|
void removePositionConstraint(int bodyIndice);
|
||||||
|
|
||||||
|
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
btRigidBody* playerBall; //allows for easier access to the ball
|
btRigidBody* playerBall; //allows for easier access to the ball
|
||||||
@ -76,6 +80,7 @@ class Physics {
|
|||||||
btRigidBody* cameraBody;
|
btRigidBody* cameraBody;
|
||||||
std::vector<btRigidBody*> bodies; //list of all bodies. bodies are also in world, but save again to ease cleaning up process.
|
std::vector<btRigidBody*> bodies; //list of all bodies. bodies are also in world, but save again to ease cleaning up process.
|
||||||
btRigidBody* staticGroundBody;
|
btRigidBody* staticGroundBody;
|
||||||
|
std::vector<positionConstraint> allPositionConstraints;
|
||||||
|
|
||||||
btDynamicsWorld* world; //contains physical attributes of the world.
|
btDynamicsWorld* world; //contains physical attributes of the world.
|
||||||
btDispatcher* dispatcher; //
|
btDispatcher* dispatcher; //
|
||||||
|
Loading…
Reference in New Issue
Block a user