Merge branch 'master' of github.com:Faerbit/swp
Conflicts: level.cc
This commit is contained in:
commit
ebb7045753
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,4 +5,4 @@ CMakeLists.txt.user
|
||||
*.cbp
|
||||
*~
|
||||
*.zip
|
||||
|
||||
*.db
|
||||
|
@ -110,7 +110,7 @@
|
||||
|
||||
<objectData>
|
||||
<modelPath>marbleSmooth.obj</modelPath>
|
||||
<texturePath>MarbleTexture.png</texturePath>
|
||||
<texturePath>Marbletexture.png</texturePath>
|
||||
<ambientFactor>0.1</ambientFactor>
|
||||
<diffuseFactor>0.5</diffuseFactor>
|
||||
<specularFactor>0.5</specularFactor>
|
||||
|
94
Levels/ObjectSetups/Level1.xml
Normal file
94
Levels/ObjectSetups/Level1.xml
Normal file
@ -0,0 +1,94 @@
|
||||
<!--composition>
|
||||
<scale>1.0</scale>
|
||||
<xRot>0.0</xRot>
|
||||
<yRot>0.0</yRot>
|
||||
<zRot>0.0</zRot>
|
||||
<manualPos>false</manualPos>
|
||||
<xPos>-0.500000</xPos>
|
||||
<yOffset>0.0</yOffset>
|
||||
<zPos>1.500000</zPos>
|
||||
<idGreen>1</idGreen>
|
||||
<idBlue>5</idBlue>
|
||||
<typeID>80</typeID>
|
||||
</composition-->
|
||||
|
||||
<composition>
|
||||
<scale>1.0</scale>
|
||||
<xRot>0.0</xRot>
|
||||
<yRot>0.0</yRot>
|
||||
<zRot>0.0</zRot>
|
||||
<manualPos>false</manualPos>
|
||||
<xPos>0.000000</xPos>
|
||||
<yOffset>30.0</yOffset>
|
||||
<zPos>0.000000</zPos>
|
||||
<idGreen>1</idGreen>
|
||||
<idBlue>100</idBlue>
|
||||
<typeID>20</typeID>
|
||||
</composition>
|
||||
|
||||
<!--composition>
|
||||
<scale>1.0</scale>
|
||||
<xRot>0.0</xRot>
|
||||
<yRot>0.0</yRot>
|
||||
<zRot>0.0</zRot>
|
||||
<manualPos>false</manualPos>
|
||||
<xPos>-2.500000</xPos>
|
||||
<yOffset>0.0</yOffset>
|
||||
<zPos>-1.500000</zPos>
|
||||
<idGreen>1</idGreen>
|
||||
<idBlue>3</idBlue>
|
||||
<typeID>99</typeID>
|
||||
</composition-->
|
||||
|
||||
<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>5.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>
|
@ -8,7 +8,7 @@ Application::Application() {
|
||||
void Application::init()
|
||||
{
|
||||
// choose Level TODO: Choose this in a menu
|
||||
this->level = Level("0");
|
||||
this->level = Level("1");
|
||||
// Don't change this!
|
||||
ignoredMouseUpdates = 0;
|
||||
cameraLock = true;
|
||||
|
84
level.cc
84
level.cc
@ -107,7 +107,7 @@ void Level::load() {
|
||||
directionalLight = Light(glm::vec3(xOffset,yOffset,zOffset), glm::vec3(rColour,gColour,bColour), intensity);
|
||||
|
||||
//load Objects
|
||||
std::vector<int*> objectIdentifiers; //The first entry is the index in objects, the others are idGreen, idBlue and objectNum.
|
||||
std::vector<std::vector<int>> objectIdentifiers = std::vector<std::vector<int>>(); //The first entry is the index in objects, the others are idGreen, idBlue and objectNum.
|
||||
XMLDocument* compositions = new XMLDocument();
|
||||
const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml";
|
||||
compositions->LoadFile(compositionsFile);
|
||||
@ -186,7 +186,7 @@ void Level::load() {
|
||||
Object* object = new Object(model, material, objectPosition, compRot);
|
||||
objects.push_back(object);
|
||||
//create an identifier for this object
|
||||
int* objectIdentifier = new int[4];
|
||||
std::vector<int> objectIdentifier = std::vector<int>(4);
|
||||
objectIdentifier[0] = objects.size()-1;
|
||||
int idGreen, idBlue;
|
||||
errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
||||
@ -219,9 +219,7 @@ void Level::load() {
|
||||
float dampningL, dampningA;
|
||||
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
||||
std::string bulletModelPath = modelPath.substr(0, modelPath.length()-3);
|
||||
bulletModelPath += "bullet";
|
||||
this->physics.addTriangleMeshBody(*object,modelPath,mass,0.5,0.5,physicObjects.size());
|
||||
this->physics.addTriangleMeshBody(*object, modelPath, mass, dampningL, dampningA, physicObjects.size());
|
||||
} else{
|
||||
printf("XMLError: Not a valid physicType.\n");
|
||||
}
|
||||
@ -281,35 +279,55 @@ void Level::load() {
|
||||
std::string name = charName;
|
||||
if (name.compare("-") != 0){
|
||||
float xPos, yPos, zPos, distance;
|
||||
std::vector<float> position;
|
||||
glm::vec3 position;
|
||||
bool isBigger;
|
||||
int idGreen, idBlue, objectNum;
|
||||
int idGreen, idBlue, objectNum, functionPointer_int;
|
||||
errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos));
|
||||
errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos));
|
||||
errorCheck(xmlTrigger->FirstChildElement("zPosition")->QueryFloatText(&zPos));
|
||||
errorCheck(xmlTrigger->FirstChildElement("distance")->QueryFloatText(&distance));
|
||||
position.push_back(xPos);
|
||||
position.push_back(yPos);
|
||||
position.push_back(zPos);
|
||||
position = glm::vec3(xPos, yPos, zPos);
|
||||
errorCheck(xmlTrigger->FirstChildElement("isBiggerThan")->QueryBoolText(&isBigger));
|
||||
errorCheck(xmlTrigger->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
||||
errorCheck(xmlTrigger->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
||||
errorCheck(xmlTrigger->FirstChildElement("objectNum")->QueryIntText(&objectNum));
|
||||
//TODO find the object
|
||||
//Trigger trigger = Trigger::Trigger(position, distance, isBigger, Object* object, void (*functionPointer)());
|
||||
//triggers.push_back(trigger);
|
||||
Object* object=0;
|
||||
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
||||
printf("objectIdentifiers: %d, %d, %d, %d\n", objectIdentifiers[i][0], objectIdentifiers[i][1], objectIdentifiers[i][2], objectIdentifiers[i][3]);
|
||||
if (objectIdentifiers[i][1]==idGreen && objectIdentifiers[i][2]==idBlue && objectIdentifiers[i][3]==objectNum){
|
||||
object = objects[objectIdentifiers[i][0]];
|
||||
}
|
||||
}
|
||||
errorCheck(xmlTrigger->FirstChildElement("functionPointer")->QueryIntText(&functionPointer_int));
|
||||
void (*functionPointer)() = NULL;
|
||||
switch(functionPointer_int) {
|
||||
case 0:
|
||||
functionPointer = &trigger_function_0;
|
||||
break;
|
||||
case 1:
|
||||
functionPointer = &trigger_function_1;
|
||||
break;
|
||||
case 2:
|
||||
functionPointer = &trigger_function_2;
|
||||
break;
|
||||
case 3:
|
||||
functionPointer = &trigger_function_3;
|
||||
break;
|
||||
case 4:
|
||||
functionPointer = &trigger_function_4;
|
||||
break;
|
||||
default:
|
||||
printf("Trigger function could not be found.");
|
||||
}
|
||||
if (object != 0) {
|
||||
Trigger trigger = Trigger(position, distance, isBigger, object, functionPointer);
|
||||
triggers.push_back(trigger);
|
||||
}
|
||||
else {
|
||||
printf("Trigger object not found.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add player (//TODO remove this as soon as we have a levelSetup with a player)
|
||||
Model marbleModel = Model("marbleSmooth.obj", 0.75f);
|
||||
Material marbleMaterial = Material("Marbletexture.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
||||
Object* object = new Object(marbleModel, marbleMaterial, glm::vec3(2.0f, 20.0f, 2.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
objects.push_back(object);
|
||||
physicObjects.push_back(object);
|
||||
this->physics.addPlayer(1.25f,*object,8.0f,physicObjects.size());
|
||||
cameraCenter = object;
|
||||
}
|
||||
|
||||
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||
@ -362,6 +380,10 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
|
||||
|
||||
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
||||
0.0f, cameraCenter->getPosition().z));
|
||||
|
||||
for(unsigned int i = 0; i<triggers.size(); i++) {
|
||||
triggers.at(i).triggerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 Level::getAmbientLight() {
|
||||
@ -395,3 +417,19 @@ glm::vec3 Level::getCameraPosition() {
|
||||
void Level::setSkydomeSize(float size) {
|
||||
skydomeSize = size;
|
||||
}
|
||||
|
||||
void Level::trigger_function_0() {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void Level::trigger_function_1() {
|
||||
}
|
||||
|
||||
void Level::trigger_function_2() {
|
||||
}
|
||||
|
||||
void Level::trigger_function_3() {
|
||||
}
|
||||
|
||||
void Level::trigger_function_4() {
|
||||
}
|
||||
|
5
level.hh
5
level.hh
@ -29,6 +29,11 @@ class Level {
|
||||
glm::vec3 getCameraPosition();
|
||||
glm::vec4 getFogColour();
|
||||
void setSkydomeSize(float size);
|
||||
static void trigger_function_0();
|
||||
static void trigger_function_1();
|
||||
static void trigger_function_2();
|
||||
static void trigger_function_3();
|
||||
static void trigger_function_4();
|
||||
private:
|
||||
void errorCheck(tinyxml2::XMLError error);
|
||||
std::string levelNum;
|
||||
|
11
trigger.cc
11
trigger.cc
@ -1,11 +1,11 @@
|
||||
#include "trigger.hh"
|
||||
|
||||
Trigger::Trigger(std::vector<float> position, float distance, bool isBigger, Object* object, void (*functionPointer)()) {
|
||||
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)()) {
|
||||
this->position=position;
|
||||
this->distance=distance;
|
||||
this->isBigger=isBigger;
|
||||
this->object=object;
|
||||
this->functionPointer=functionPointer;
|
||||
this->functionPointer = functionPointer;
|
||||
}
|
||||
|
||||
Trigger::Trigger(){
|
||||
@ -15,5 +15,10 @@ Trigger::~Trigger(){
|
||||
}
|
||||
|
||||
void Trigger::triggerUpdate(){
|
||||
|
||||
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
||||
(*functionPointer)();
|
||||
}
|
||||
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
||||
(*functionPointer)();
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
|
||||
class Trigger {
|
||||
public:
|
||||
Trigger(std::vector<float> position, float distance, bool isBigger, Object* object, void (*functionPointer)());
|
||||
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)());
|
||||
Trigger();
|
||||
~Trigger();
|
||||
void triggerUpdate();
|
||||
private:
|
||||
std::vector<float> position;
|
||||
glm::vec3 position;
|
||||
float distance;
|
||||
bool isBigger;
|
||||
Object* object;
|
||||
|
Loading…
Reference in New Issue
Block a user