Merge branch 'master' of github.com:Faerbit/swp

This commit is contained in:
Steffen Fündgens 2015-01-16 16:52:11 +01:00
commit cba7d170da
14 changed files with 2495 additions and 986 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

View File

@ -1,52 +0,0 @@
<ambientLight>
<rColour>1.0</rColour>
<gColour>1.0</gColour>
<bColour>1.0</bColour>
</ambientLight>
<fogColour>
<rColour>0.10</rColour>
<gColour>0.14</gColour>
<bColour>0.14</bColour>
<alpha>1.0</alpha>
</fogColour>
<directionalLight>
<xOffset>-1.0</xOffset>
<yOffset>1.5</yOffset>
<zOffset>1.0</zOffset>
<rColour>1.0</rColour>
<gColour>1.0</gColour>
<bColour>0.9</bColour>
<intensity>0.2</intensity>
</directionalLight>
<skydome>
<texture>skydome.png</texture>
</skydome>
<trigger>
<name>bla</name>
<xPosition>15.0</xPosition>
<yPosition>14.0</yPosition>
<zPosition>0.0</zPosition>
<distance>4.0</distance>
<isBiggerThan>false</isBiggerThan>
<idGreen>1</idGreen>
<idBlue>100</idBlue>
<objectNum>0</objectNum>
<functionPointer>0</functionPointer>
</trigger>
<trigger>
<name>-</name>
<xPosition>0.0</xPosition>
<yPosition>0.0</yPosition>
<zPosition>0.0</zPosition>
<distance>1.0</distance>
<isBiggerThan>false</isBiggerThan>
<idGreen>0</idGreen>
<idBlue>0</idBlue>
<objectNum>0</objectNum>
<functionPointer>-</functionPointer>
</trigger>

View File

@ -1,4 +1,4 @@
<!-- Marble --> <!-- Marble -->
<composition> <composition>
<typeID>20</typeID> <typeID>20</typeID>
<object> <object>
@ -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>
@ -123,6 +123,19 @@
</object> </object>
</composition> </composition>
<!-- Static Block -->
<composition>
<typeID>140</typeID>
<object>
<modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>10.0</yOffset>
<zOffset>2.0</zOffset>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
</composition>
@ -136,7 +149,7 @@
<shininess>3.0</shininess> <shininess>3.0</shininess>
<physicType>Player</physicType> <physicType>Player</physicType>
<radius>1.5</radius> <radius>1.5</radius>
<dampningL>0.1</dampningL> <dampningL>0.2 </dampningL>
<dampningA>0.7</dampningA> <dampningA>0.7</dampningA>
</objectData> </objectData>
@ -149,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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 B

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

View File

@ -81,7 +81,7 @@ void Level::load() {
Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f); Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f);
//Create object //Create object
Object* terrainObject = new Object(terrainModel, terrainMaterial, Object* terrainObject = new Object(terrainModel, terrainMaterial,
glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()), glm::vec3(-0.5*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
glm::vec3(0.0f, 0.0f, 0.0f)); glm::vec3(0.0f, 0.0f, 0.0f));
objects.push_back(terrainObject); objects.push_back(terrainObject);

View File

@ -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()
{ {

View File

@ -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; //

View File

@ -22,7 +22,7 @@ void Terrain::load() {
for(unsigned int rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap for(unsigned int rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap
this->heightmap[rowNum] = new float[this->heightmapWidth]; this->heightmap[rowNum] = new float[this->heightmapWidth];
for(unsigned int columnNum = 0; columnNum < this->heightmapWidth; columnNum++){ for(unsigned int columnNum = 0; columnNum < this->heightmapWidth; columnNum++){
this->heightmap[rowNum][columnNum] = (float)(image[(rowNum*heightmapWidth+columnNum)*4]) / 8; //<--heightmap is scaled here this->heightmap[rowNum][columnNum] = (float)(image[(rowNum*heightmapWidth+columnNum)*4]) / 6; //<--heightmap is scaled here
} }
} }