Moved friction and player strength to Level.xml.
This commit is contained in:
parent
36c42123b8
commit
76b6be0beb
@ -166,3 +166,8 @@
|
||||
<skydome>
|
||||
<texture>skydome.png</texture>
|
||||
</skydome>
|
||||
|
||||
<physics>
|
||||
<friction>0.9</friction>
|
||||
<strength>100.0</strength>
|
||||
</physics>
|
||||
|
@ -39,7 +39,7 @@ Converter::Converter(std::string level){
|
||||
doc->LoadFile(charXmlFile);
|
||||
if (doc->ErrorID()!=0){
|
||||
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;
|
||||
lightAttributes.push_back(doc->NewElement("xOffset"));
|
||||
lightAttributes.push_back(doc->NewElement("yOffset"));
|
||||
@ -85,16 +85,27 @@ Converter::Converter(std::string level){
|
||||
for(int i=0;i<7;i++){
|
||||
directionalLight->InsertEndChild(lightAttributes[i]);
|
||||
}
|
||||
doc->InsertEndChild(ambientLight);
|
||||
doc->InsertEndChild(fogColour);
|
||||
doc->InsertEndChild(directionalLight);
|
||||
|
||||
//Create global skydome Element
|
||||
XMLElement* skydome = doc->NewElement("skydome");
|
||||
XMLElement* skydomeTexture = doc->NewElement("texture");
|
||||
skydomeTexture->SetText("skydome.png");
|
||||
skydome->InsertEndChild(skydomeTexture);
|
||||
|
||||
doc->InsertEndChild(ambientLight);
|
||||
doc->InsertEndChild(fogColour);
|
||||
doc->InsertEndChild(directionalLight);
|
||||
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{
|
||||
dst << src.rdbuf();
|
||||
XMLElement* thisComposition = doc->FirstChildElement("composition");
|
||||
|
19
level.cc
19
level.cc
@ -69,6 +69,13 @@ void Level::load() {
|
||||
printf("Could not open ObjectSetupXml!\n");
|
||||
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
|
||||
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
|
||||
const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText();
|
||||
@ -208,7 +215,7 @@ void Level::load() {
|
||||
if (physicType.compare("Player") == 0){
|
||||
float 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){
|
||||
float width, height, length;
|
||||
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);
|
||||
}
|
||||
|
||||
float str = 100;
|
||||
|
||||
if(wPressed){
|
||||
physics.rollForward(camera.getVector(),str);
|
||||
physics.rollForward(camera.getVector(),strength);
|
||||
}
|
||||
if(aPressed) {
|
||||
physics.rollLeft(camera.getVector(),str);
|
||||
physics.rollLeft(camera.getVector(),strength);
|
||||
}
|
||||
if(sPressed) {
|
||||
physics.rollBack(camera.getVector(),str);
|
||||
physics.rollBack(camera.getVector(),strength);
|
||||
}
|
||||
if(dPressed){
|
||||
physics.rollRight(camera.getVector(),str);
|
||||
physics.rollRight(camera.getVector(),strength);
|
||||
}
|
||||
|
||||
physics.takeUpdateStep(runTime);
|
||||
|
1
level.hh
1
level.hh
@ -46,6 +46,7 @@ class Level {
|
||||
Camera camera;
|
||||
Terrain terrain;
|
||||
float skydomeSize;
|
||||
float strength;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -104,7 +104,7 @@ void Physics::addStaticGroundPlane()
|
||||
|
||||
|
||||
//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)
|
||||
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);
|
||||
|
||||
info.m_friction = 0.9;
|
||||
info.m_friction = friction;
|
||||
|
||||
playerBall = new btRigidBody(info);
|
||||
|
||||
|
@ -59,7 +59,7 @@ class Physics {
|
||||
void addTriangleMeshBody(Entity entity, std::string path, float mass, float dampningL, float dampningA,unsigned indice);
|
||||
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 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 addBox(float width, float height, float length, Entity entity, float mass, unsigned indice); //this is used to ensuer that the system is synchronized
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user