Merge branch 'master' of github.com:Faerbit/swp
Conflicts: level.cc
This commit is contained in:
commit
8072fd1cbb
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,4 +5,4 @@ CMakeLists.txt.user
|
|||||||
*.cbp
|
*.cbp
|
||||||
*~
|
*~
|
||||||
*.zip
|
*.zip
|
||||||
|
*.db
|
||||||
|
@ -110,7 +110,7 @@
|
|||||||
|
|
||||||
<objectData>
|
<objectData>
|
||||||
<modelPath>marbleSmooth.obj</modelPath>
|
<modelPath>marbleSmooth.obj</modelPath>
|
||||||
<texturePath>MarbleTexture.png</texturePath>
|
<texturePath>Marbletexture.png</texturePath>
|
||||||
<ambientFactor>0.1</ambientFactor>
|
<ambientFactor>0.1</ambientFactor>
|
||||||
<diffuseFactor>0.5</diffuseFactor>
|
<diffuseFactor>0.5</diffuseFactor>
|
||||||
<specularFactor>0.5</specularFactor>
|
<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()
|
void Application::init()
|
||||||
{
|
{
|
||||||
// choose Level TODO: Choose this in a menu
|
// choose Level TODO: Choose this in a menu
|
||||||
this->level = Level("0");
|
this->level = Level("1");
|
||||||
// Don't change this!
|
// Don't change this!
|
||||||
ignoredMouseUpdates = 0;
|
ignoredMouseUpdates = 0;
|
||||||
cameraLock = true;
|
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);
|
directionalLight = Light(glm::vec3(xOffset,yOffset,zOffset), glm::vec3(rColour,gColour,bColour), intensity);
|
||||||
|
|
||||||
//load Objects
|
//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();
|
XMLDocument* compositions = new XMLDocument();
|
||||||
const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml";
|
const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml";
|
||||||
compositions->LoadFile(compositionsFile);
|
compositions->LoadFile(compositionsFile);
|
||||||
@ -186,7 +186,7 @@ void Level::load() {
|
|||||||
Object* object = new Object(model, material, objectPosition, compRot);
|
Object* object = new Object(model, material, objectPosition, compRot);
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
//create an identifier for this 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;
|
objectIdentifier[0] = objects.size()-1;
|
||||||
int idGreen, idBlue;
|
int idGreen, idBlue;
|
||||||
errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
||||||
@ -219,9 +219,7 @@ void Level::load() {
|
|||||||
float dampningL, dampningA;
|
float dampningL, dampningA;
|
||||||
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
||||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
||||||
std::string bulletModelPath = modelPath.substr(0, modelPath.length()-3);
|
this->physics.addTriangleMeshBody(*object, modelPath, mass, dampningL, dampningA, physicObjects.size());
|
||||||
bulletModelPath += "bullet";
|
|
||||||
this->physics.addTriangleMeshBody(*object,modelPath,mass,0.5,0.5,physicObjects.size());
|
|
||||||
} else{
|
} else{
|
||||||
printf("XMLError: Not a valid physicType.\n");
|
printf("XMLError: Not a valid physicType.\n");
|
||||||
}
|
}
|
||||||
@ -281,35 +279,55 @@ void Level::load() {
|
|||||||
std::string name = charName;
|
std::string name = charName;
|
||||||
if (name.compare("-") != 0){
|
if (name.compare("-") != 0){
|
||||||
float xPos, yPos, zPos, distance;
|
float xPos, yPos, zPos, distance;
|
||||||
std::vector<float> position;
|
glm::vec3 position;
|
||||||
bool isBigger;
|
bool isBigger;
|
||||||
int idGreen, idBlue, objectNum;
|
int idGreen, idBlue, objectNum, functionPointer_int;
|
||||||
errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos));
|
errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos));
|
||||||
errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos));
|
errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos));
|
||||||
errorCheck(xmlTrigger->FirstChildElement("zPosition")->QueryFloatText(&zPos));
|
errorCheck(xmlTrigger->FirstChildElement("zPosition")->QueryFloatText(&zPos));
|
||||||
errorCheck(xmlTrigger->FirstChildElement("distance")->QueryFloatText(&distance));
|
errorCheck(xmlTrigger->FirstChildElement("distance")->QueryFloatText(&distance));
|
||||||
position.push_back(xPos);
|
position = glm::vec3(xPos, yPos, zPos);
|
||||||
position.push_back(yPos);
|
|
||||||
position.push_back(zPos);
|
|
||||||
errorCheck(xmlTrigger->FirstChildElement("isBiggerThan")->QueryBoolText(&isBigger));
|
errorCheck(xmlTrigger->FirstChildElement("isBiggerThan")->QueryBoolText(&isBigger));
|
||||||
errorCheck(xmlTrigger->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
errorCheck(xmlTrigger->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
||||||
errorCheck(xmlTrigger->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
errorCheck(xmlTrigger->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
||||||
errorCheck(xmlTrigger->FirstChildElement("objectNum")->QueryIntText(&objectNum));
|
errorCheck(xmlTrigger->FirstChildElement("objectNum")->QueryIntText(&objectNum));
|
||||||
//TODO find the object
|
Object* object=0;
|
||||||
//Trigger trigger = Trigger::Trigger(position, distance, isBigger, Object* object, void (*functionPointer)());
|
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
||||||
//triggers.push_back(trigger);
|
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,
|
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,
|
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
||||||
0.0f, cameraCenter->getPosition().z));
|
0.0f, cameraCenter->getPosition().z));
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i<triggers.size(); i++) {
|
||||||
|
triggers.at(i).triggerUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Level::getAmbientLight() {
|
glm::vec3 Level::getAmbientLight() {
|
||||||
@ -395,3 +417,19 @@ glm::vec3 Level::getCameraPosition() {
|
|||||||
void Level::setSkydomeSize(float size) {
|
void Level::setSkydomeSize(float size) {
|
||||||
skydomeSize = 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::vec3 getCameraPosition();
|
||||||
glm::vec4 getFogColour();
|
glm::vec4 getFogColour();
|
||||||
void setSkydomeSize(float size);
|
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:
|
private:
|
||||||
void errorCheck(tinyxml2::XMLError error);
|
void errorCheck(tinyxml2::XMLError error);
|
||||||
std::string levelNum;
|
std::string levelNum;
|
||||||
|
11
trigger.cc
11
trigger.cc
@ -1,11 +1,11 @@
|
|||||||
#include "trigger.hh"
|
#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->position=position;
|
||||||
this->distance=distance;
|
this->distance=distance;
|
||||||
this->isBigger=isBigger;
|
this->isBigger=isBigger;
|
||||||
this->object=object;
|
this->object=object;
|
||||||
this->functionPointer=functionPointer;
|
this->functionPointer = functionPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Trigger::Trigger(){
|
Trigger::Trigger(){
|
||||||
@ -15,5 +15,10 @@ Trigger::~Trigger(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Trigger::triggerUpdate(){
|
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 {
|
class Trigger {
|
||||||
public:
|
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();
|
||||||
~Trigger();
|
~Trigger();
|
||||||
void triggerUpdate();
|
void triggerUpdate();
|
||||||
private:
|
private:
|
||||||
std::vector<float> position;
|
glm::vec3 position;
|
||||||
float distance;
|
float distance;
|
||||||
bool isBigger;
|
bool isBigger;
|
||||||
Object* object;
|
Object* object;
|
||||||
|
Loading…
Reference in New Issue
Block a user