Implemented simple triggers.
This commit is contained in:
parent
c593d93ef0
commit
b26d904023
79
level.cc
79
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));
|
||||||
@ -221,8 +221,7 @@ void Level::load() {
|
|||||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
||||||
std::string bulletModelPath = modelPath.substr(0, modelPath.length()-3);
|
std::string bulletModelPath = modelPath.substr(0, modelPath.length()-3);
|
||||||
bulletModelPath += "bullet";
|
bulletModelPath += "bullet";
|
||||||
//this->physics.addRigidBodyFromFile(*object, mass, dampningL, dampningA, bulletModelPath, physicObjects.size());
|
this->physics.addTriangleMeshBody(*object, modelPath, mass, dampningL, dampningA, physicObjects.size());
|
||||||
this->physics.addBox(1, 1, 1, *object, mass, physicObjects.size());
|
|
||||||
} else{
|
} else{
|
||||||
printf("XMLError: Not a valid physicType.\n");
|
printf("XMLError: Not a valid physicType.\n");
|
||||||
}
|
}
|
||||||
@ -282,35 +281,65 @@ 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)
|
//add player (//TODO remove this as soon as we have a levelSetup with a player)
|
||||||
Model marbleModel = Model("marbleSmooth.obj", 0.75f);
|
/*Model marbleModel = Model("marbleSmooth.obj", 0.75f);
|
||||||
Material marbleMaterial = Material("Marbletexture.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
Material marbleMaterial = Material("Marbletexture.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
||||||
Object* object = new Object(marbleModel, marbleMaterial, glm::vec3(2.0f, 10.0f, 2.0f),
|
Object* object = new Object(marbleModel, marbleMaterial, glm::vec3(240.0f, 30.0f, -240.0f),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f));
|
glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
physicObjects.push_back(object);
|
physicObjects.push_back(object);
|
||||||
this->physics.addPlayer(1.25f,*object,8.0f,physicObjects.size());
|
this->physics.addPlayer(1.25f,*object,8.0f,physicObjects.size());
|
||||||
cameraCenter = object;
|
cameraCenter = object;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||||
@ -363,6 +392,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() {
|
||||||
@ -396,3 +429,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;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#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;
|
||||||
@ -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