Moved friction and player strength to Level.xml.

This commit is contained in:
Steffen Fündgens 2015-01-06 13:14:30 +01:00
parent 6bec8fc01d
commit 3560957d67
6 changed files with 37 additions and 15 deletions

View File

@ -166,3 +166,8 @@
<skydome> <skydome>
<texture>skydome.png</texture> <texture>skydome.png</texture>
</skydome> </skydome>
<physics>
<friction>0.9</friction>
<strength>100.0</strength>
</physics>

View File

@ -39,7 +39,7 @@ Converter::Converter(std::string level){
doc->LoadFile(charXmlFile); doc->LoadFile(charXmlFile);
if (doc->ErrorID()!=0){ if (doc->ErrorID()!=0){
printf("Could not open xml, creating new xml.\n"); printf("Could not open xml, creating new xml.\n");
//Create all global Elements with Dummy-Values //Create all global Lightingparameters with Dummy-Values
std::vector<XMLElement*> lightAttributes; std::vector<XMLElement*> lightAttributes;
lightAttributes.push_back(doc->NewElement("xOffset")); lightAttributes.push_back(doc->NewElement("xOffset"));
lightAttributes.push_back(doc->NewElement("yOffset")); lightAttributes.push_back(doc->NewElement("yOffset"));
@ -85,16 +85,27 @@ Converter::Converter(std::string level){
for(int i=0;i<7;i++){ for(int i=0;i<7;i++){
directionalLight->InsertEndChild(lightAttributes[i]); directionalLight->InsertEndChild(lightAttributes[i]);
} }
doc->InsertEndChild(ambientLight);
doc->InsertEndChild(fogColour);
doc->InsertEndChild(directionalLight);
//Create global skydome Element
XMLElement* skydome = doc->NewElement("skydome"); XMLElement* skydome = doc->NewElement("skydome");
XMLElement* skydomeTexture = doc->NewElement("texture"); XMLElement* skydomeTexture = doc->NewElement("texture");
skydomeTexture->SetText("skydome.png"); skydomeTexture->SetText("skydome.png");
skydome->InsertEndChild(skydomeTexture); skydome->InsertEndChild(skydomeTexture);
doc->InsertEndChild(ambientLight);
doc->InsertEndChild(fogColour);
doc->InsertEndChild(directionalLight);
doc->InsertEndChild(skydome); doc->InsertEndChild(skydome);
//Create global physics parameters
XMLElement* physics = doc->NewElement("physics");
XMLElement* friction = doc->NewElement("friction");
XMLElement* strength = doc->NewElement("strength");
friction->SetText("0.9");
strength->SetText("100.0");
physics->InsertEndChild(friction);
physics->InsertEndChild(strength);
doc->InsertEndChild(physics);
}else{ }else{
dst << src.rdbuf(); dst << src.rdbuf();
XMLElement* thisComposition = doc->FirstChildElement("composition"); XMLElement* thisComposition = doc->FirstChildElement("composition");

View File

@ -69,6 +69,13 @@ void Level::load() {
printf("Could not open ObjectSetupXml!\n"); printf("Could not open ObjectSetupXml!\n");
exit(-1); exit(-1);
} }
//load global physic parameter
float friction;
XMLElement* physicsElement = doc->FirstChildElement("physics");
errorCheck(physicsElement->FirstChildElement("strength")->QueryFloatText(&strength));
errorCheck(physicsElement->FirstChildElement("friction")->QueryFloatText(&friction));
//load the skydome //load the skydome
XMLElement* skydomeElement = doc->FirstChildElement("skydome"); XMLElement* skydomeElement = doc->FirstChildElement("skydome");
const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText(); const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText();
@ -208,7 +215,7 @@ void Level::load() {
if (physicType.compare("Player") == 0){ if (physicType.compare("Player") == 0){
float radius; float radius;
errorCheck(objectData->FirstChildElement("radius")->QueryFloatText(&radius)); errorCheck(objectData->FirstChildElement("radius")->QueryFloatText(&radius));
this->physics.addPlayer(radius, *object, mass, physicObjects.size()); this->physics.addPlayer(friction, radius, *object, mass, physicObjects.size());
}else if (physicType.compare("Box") == 0){ }else if (physicType.compare("Box") == 0){
float width, height, length; float width, height, length;
errorCheck(objectData->FirstChildElement("width")->QueryFloatText(&width)); errorCheck(objectData->FirstChildElement("width")->QueryFloatText(&width));
@ -359,19 +366,17 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
camera.updateRotation(mouseDelta/100.0f); camera.updateRotation(mouseDelta/100.0f);
} }
float str = 100;
if(wPressed){ if(wPressed){
physics.rollForward(camera.getVector(),str); physics.rollForward(camera.getVector(),strength);
} }
if(aPressed) { if(aPressed) {
physics.rollLeft(camera.getVector(),str); physics.rollLeft(camera.getVector(),strength);
} }
if(sPressed) { if(sPressed) {
physics.rollBack(camera.getVector(),str); physics.rollBack(camera.getVector(),strength);
} }
if(dPressed){ if(dPressed){
physics.rollRight(camera.getVector(),str); physics.rollRight(camera.getVector(),strength);
} }
physics.takeUpdateStep(runTime); physics.takeUpdateStep(runTime);

View File

@ -46,6 +46,7 @@ class Level {
Camera camera; Camera camera;
Terrain terrain; Terrain terrain;
float skydomeSize; float skydomeSize;
float strength;
}; };
#endif #endif

View File

@ -104,7 +104,7 @@ void Physics::addStaticGroundPlane()
//players and objects //players and objects
void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice) void Physics::addPlayer(float friction, float rad, Entity entity, float mass, unsigned indice)
{ {
if(bodies.size() == indice) if(bodies.size() == indice)
throw std::invalid_argument( "Bodies out of Sync" ); throw std::invalid_argument( "Bodies out of Sync" );
@ -120,7 +120,7 @@ void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice)
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia); btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
info.m_friction = 0.9; info.m_friction = friction;
playerBall = new btRigidBody(info); playerBall = new btRigidBody(info);

View File

@ -59,7 +59,7 @@ class Physics {
void addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA,unsigned indice); void addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA,unsigned indice);
void addTerrain(int width, int length, float** heightData); void addTerrain(int width, int length, float** heightData);
void addTerrainTriangles(int width, int length, float** heightData); //add the terrain as a trimesh instead of a heightmap void addTerrainTriangles(int width, int length, float** heightData); //add the terrain as a trimesh instead of a heightmap
void addPlayer(float rad, Entity entity, float mass, 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, 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, unsigned indice); //The Indice should be set to physicObjects.size() void addSphere(float rad, Entity entity, float mass, unsigned indice); //The Indice should be set to physicObjects.size()
void addBox(float width, float height, float length, Entity entity, float mass, unsigned indice); //this is used to ensuer that the system is synchronized void addBox(float width, float height, float length, Entity entity, float mass, unsigned indice); //this is used to ensuer that the system is synchronized