//===================================================================// //==================Main Method=====================================// //==================================================================// int main() { //===================================================================// //==================Things you need to start with====================// //==================================================================// glfwInit(); Window testWindow(500, 50, 800, 600, "testWindow"); glfwMakeContextCurrent(testWindow.getWindow()); cam.setCenter(glm::vec4(0.0, 10.0, 20.0, 1.0)); cam.setName("StrategyCam"); cam.setKeySpeed(2.0); cam.setNearFar(0.0001, 100); glfwSetKeyCallback(testWindow.getWindow(), key_callback); glfwSetScrollCallback(testWindow.getWindow(), mouseScroll_callback); glewInit(); OpenGL3Context context; Renderer renderer(context); //===================================================================// //==================Shaders for your program========================// //==================================================================// VertexShader vs(loadShaderSource(SHADERS_PATH + std::string("/TextureShader3D/TextureShader3D.vert"))); FragmentShader fs(loadShaderSource(SHADERS_PATH + std::string("/TextureShader3D/TextureShader3D.frag"))); ShaderProgram shader(vs, fs); //===================================================================// //==================A Graph for the AI-Unit=========================// //==================================================================// glm::vec3 posFood(10.0, 0.0, -5.0); glm::vec3 posSpawn(10.0, 0.0, 60.0); Graph<AStarNode, AStarAlgorithm> testGraph; // testGraph.setExampleGraph2(posSpawn, posFood, geko.getPosition()); //===================================================================// //==================A Decision-Tree for the AI-Unit==================// //==================================================================// DecisionTree defaultTree; defaultTree.setAntTreeAggressiv(); //===================================================================// //==================Object declarations - Geometry, Texture, Node=== // //==========================Object: AI==============================// Teapot teaAnt; Texture texPlayer((char*)RESOURCES_PATH "/Snake.jpg"); SoundFileHandler sfh = SoundFileHandler(1000); //AStarNode defaultASNode("Default"); //AI ant_Flick(&defaultTree, &defaultASNode, &aiNode); AI ant_Flick; //ant_Flick.setAntAfraid(); /*ant_Flick.setGraph(&testGraph); ant_Flick.setPosition(posSpawn); ant_Flick.setPosHome(testGraph.searchNode("Spawn"));*/ //ant_Flick.addFoodNodes(testGraph.searchNode("Food")); AntMesh ant; Node aiNode("Flick"); aiNode.addGeometry(&ant); aiNode.addTexture(&texPlayer); // aiNode.addScale(0.3, 0.3, 0.3); //aiNode.addTranslation(ant_Flick.getPosition().x, ant_Flick.getPosition().y, ant_Flick.getPosition().z); aiNode.setObject(&ant_Flick); //aiNode.setSoundHandler(&sfh); // aiNode.setSourceName("Ameise1", RESOURCES_PATH "/Sound/Footsteps.wav"); //===================================================================// //==================Object declarations - Geometry, Texture, Node=== // //==========================Object: Player===========================// Teapot teaPlayer; Texture texCV((char*)RESOURCES_PATH "/cv_logo.bmp"); GekoMesh gekoMesh; geko.setExp(0.0); geko.setLevelThreshold(100.0); geko.setLevel(0); Node playerNode("Player"); playerNode.addGeometry(&gekoMesh); playerNode.setObject(&geko); playerNode.addTexture(&texCV); // playerNode.addScale(0.5, 0.5, 0.5); // playerNode.addTranslation(20.0, 0.0, 20.0); geko.setSoundHandler(&sfh); geko.setSourceName(MOVESOUND, "SpielerFootsteps", RESOURCES_PATH "/Sound/rascheln.wav"); geko.setSourceName(BACKGROUNDMUSIC, "Hintergrund", RESOURCES_PATH "/Sound/jingle2.wav"); geko.setSourceName(FIGHTSOUND, "Kampfsound", RESOURCES_PATH "/Sound/Cookies kurz.wav"); geko.setSourceName(EATSOUND, "Essen", RESOURCES_PATH "/Sound/Munching.wav"); geko.setSourceName(QUESTSOUND, "Quest", RESOURCES_PATH "/Sound/jingle.wav"); geko.setSourceName(ITEMSOUND, "Item", RESOURCES_PATH "/Sound/itempickup.wav"); sfh.disableLooping("Essen"); sfh.disableLooping("Kampfsound"); sfh.disableLooping("Quest"); sfh.disableLooping("Item"); sfh.generateSource("Feuer",posFood, RESOURCES_PATH "/Sound/Feuer kurz.wav"); playerNode.setCamera(&cam); // ============================================================== // == Items ===================================================== // ============================================================== /*Item cookie(1); cookie.setName("Cookie"); cookie.setTypeId(ItemType::COOKIE); Item cookie2(2); cookie.setName("Cookie"); cookie.setTypeId(ItemType::COOKIE); Item branch(3); branch.setName("Branch"); branch.setTypeId(ItemType::BRANCH); */ //===================================================================// //==================Object declarations - Geometry, Texture, Node=== // //==========================Object: Tree===========================// TreeMesh tree; glm::vec3 trees[5] = { glm::vec3(16.0, 0.0, 76.0), glm::vec3(23.0, 0.0, 74.0), glm::vec3(21.5, 0.0, 78.5), glm::vec3(15.0, 0.0, 81.5), glm::vec3(27.5, 0.0, 88.5), }; StaticObject treeStatic; treeStatic.setTree(); // treeStatic.setObjectType(ObjectType::TREE); Node treeNode("Tree"); treeNode.addGeometry(&tree); treeNode.setObject(&treeStatic); //treeNode.addScale(10.0, 10.0, 10.0); treeNode.addTranslation(trees[0]); treeNode.getBoundingSphere()->radius = 3.0; StaticObject treeStatic2; treeStatic2.setTree(); Node treeNode2("Tree2"); treeNode2.addGeometry(&tree); treeNode2.setObject(&treeStatic2); treeNode2.addTranslation(trees[1]); treeNode2.getBoundingSphere()->radius = 3.0; StaticObject treeStatic3; treeStatic3.setTree(); Node treeNode3("Tree3"); treeNode3.addGeometry(&tree); treeNode3.setObject(&treeStatic3); treeNode3.addTranslation(trees[2]); treeNode3.getBoundingSphere()->radius = 3.0; StaticObject treeStatic4; treeStatic4.setTree(); Node treeNode4("Tree4"); treeNode4.addGeometry(&tree); treeNode4.setObject(&treeStatic4); treeNode4.addTranslation(trees[3]); treeNode4.getBoundingSphere()->radius = 3.0; StaticObject treeStatic5; treeStatic5.setTree(); Node treeNode5("Tree5"); treeNode5.addGeometry(&tree); treeNode5.setObject(&treeStatic5); treeNode5.addTranslation(trees[4]); treeNode5.getBoundingSphere()->radius = 3.0; //treeStatic.getInventory()->addItem(&cookie, 25); //treeStatic.getInventory()->addItem(&branch, 10); //===================================================================// //==================Object declarations - Geometry, Texture, Node=== // //==========================Object: Plane===========================// Plane terrain; Texture terrainTex((char*)RESOURCES_PATH "/Grass.jpg"); Node terrainNode("Plane"); terrainNode.addGeometry(&terrain); terrainNode.addTexture(&terrainTex); terrainNode.addTranslation(0.0, -0.75, 0.0); terrainNode.addRotation(90.0f, glm::vec3(1.0, 0.0, 0.0)); terrainNode.addScale(100.0, 100.0, 100.0); //===================================================================// //==================Setting up the Level and Scene==================// //==================================================================// Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); //==================Add Camera to Scene============================// testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->setActiveCamera("StrategyCam"); //==================Set Input-Maps and activate one================// iH.setAllInputMaps(*(testScene.getScenegraph()->getActiveCamera())); iH.changeActiveInputMap("Strategy"); //==================Add Objects to the Scene=======================// //==================Update the Bounding-Sphere 1st time============// testScene.getScenegraph()->getRootNode()->addChildrenNode(&aiNode); testScene.getScenegraph()->getRootNode()->addChildrenNode(&playerNode); testScene.getScenegraph()->getRootNode()->addChildrenNode(&terrainNode); testScene.getScenegraph()->getRootNode()->addChildrenNode(&treeNode); testScene.getScenegraph()->getRootNode()->addChildrenNode(&treeNode2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&treeNode3); testScene.getScenegraph()->getRootNode()->addChildrenNode(&treeNode4); testScene.getScenegraph()->getRootNode()->addChildrenNode(&treeNode5); // ============================================================== // == Questsystem ==================================================== // ============================================================== //QuestHandler questhandler; //testLevel.getQuestHandler()->getGraph()->setExampleGraph(); Quest questCollect(1); questCollect.setActive(true); Goal_Collect goalCollect(1); Goal_Collect goalCollect3(3); questCollect.addGoal(&goalCollect); questCollect.addGoal(&goalCollect3); ExpReward expReward(1); expReward.setExp(100); questCollect.addReward(&expReward); Quest questCollect2(2); questCollect2.setActive(true); Goal_Collect goalCollect2(2); questCollect2.addGoal(&goalCollect2); questCollect2.addReward(&expReward); goalCollect.setGoalCount(50); goalCollect2.setGoalCount(50); goalCollect3.setGoalCount(50); goalCollect.setItemType(ItemType::BRANCH); goalCollect2.setItemType(ItemType::BRANCH); goalCollect3.setItemType(ItemType::COOKIE); testLevel.getQuestHandler()->addQuest(&questCollect); testLevel.getQuestHandler()->addQuest(&questCollect2); //===================================================================// //==================Setting up the Collision=========================// //==================================================================// CollisionTest collision; collision.collectNodes(testScene.getScenegraph()->getRootNode()); //===================================================================// //==================Setting up the Observers========================// //==================================================================// ObjectObserver aiObserver(&testLevel); SoundObserver soundAIObserver(&testLevel); ant_Flick.addObserver(&aiObserver); ant_Flick.addObserver(&soundAIObserver); ObjectObserver playerObserver(&testLevel); SoundObserver soundPlayerObserver(&testLevel); geko.addObserver(&playerObserver); geko.addObserver(&soundPlayerObserver); CollisionObserver colObserver(&testLevel); collision.addObserver(&colObserver); collision.addObserver(&soundPlayerObserver); GravityObserver gravityObserver(&testLevel); collision.addObserver(&gravityObserver); QuestObserver questObserver(&testLevel); questCollect.addObserver(&questObserver); questCollect2.addObserver(&questObserver); questCollect.addObserver(&soundPlayerObserver); questCollect2.addObserver(&soundPlayerObserver); goalCollect.addObserver(&questObserver); goalCollect2.addObserver(&questObserver); goalCollect3.addObserver(&questObserver); testLevel.getFightSystem()->addObserver(&questObserver); //===================================================================// //==================Setting up the Gravity===========================// //==================================================================// Gravity gravity; playerNode.addGravity(&gravity); aiNode.addGravity(&gravity); //===================================================================// //==================The Render-Loop==================================// //==================================================================// float lastTime = glfwGetTime(); Node* tmp = testLevel.getActiveScene()->getScenegraph()->searchNode("Plane"); tmp->getNodeName(); sfh.updateListenerPosition(glm::vec3(10.0, 3.0, -5.0)); sfh.playSource("Feuer"); sfh.playSource("Hintergrund"); sfh.setGain("Hintergrund", 0.5f); while (!glfwWindowShouldClose(testWindow.getWindow())) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float currentTime = glfwGetTime(); float deltaTime = currentTime - lastTime; lastTime = currentTime; mouse_callback(testWindow.getWindow()); //===================================================================// //==================Update your Objects per Frame here =============// //==================================================================// collision.update(); //ant_Flick.updateState(); ant_Flick.update(); //===================================================================// //==================Input and update for the Player==================// //==================================================================// playKey_callback(testWindow.getWindow()); //geko.update(deltaTime); //===================================================================// //==================Render your Objects==============================// //==================================================================// glEnable(GL_DEPTH_TEST); shader.bind(); shader.sendMat4("viewMatrix", cam.getViewMatrix()); shader.sendMat4("projectionMatrix", cam.getProjectionMatrix()); testScene.render(shader); shader.unbind(); glfwSwapBuffers(testWindow.getWindow()); glfwPollEvents(); } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }
int main() { Player geko("Geko", glm::vec3(10.0, 10.0, 10.0)); // Start Konifguration - Window, Context, Camera and Callbacks // glfwInit(); Window testWindow(500, 50, 800, 600, "testWindow"); glfwMakeContextCurrent(testWindow.getWindow()); cam.setKeySpeed(2.0); cam.setNearFar(0.01, 100); //Callback for Camera and Player glfwSetKeyCallback(testWindow.getWindow(), key_callback); glewInit(); // Shader and Renderer Initialization // //Shader for Objects VertexShader vs(loadShaderSource(SHADERS_PATH + std::string("/Vertex-Shaders/TextureShader3D.vert"))); FragmentShader fs(loadShaderSource(SHADERS_PATH + std::string("/Fragment-Shaders/TextureShader3D.frag"))); ShaderProgram shader(vs, fs); //Shader for a Skybox VertexShader vsSkybox(loadShaderSource(SHADERS_PATH + std::string("/SkyboxShader/SkyboxShader.vert"))); FragmentShader fsSkybox(loadShaderSource(SHADERS_PATH + std::string("/SkyboxShader/SkyboxShader.frag"))); ShaderProgram shaderSkybox(vsSkybox, fsSkybox); //Renderer with context OpenGL3Context context; Renderer renderer(context); //Level and Scene Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); //Add Camera to scenegraph testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->getCamera("PlayerViewCam"); testScene.getScenegraph()->setActiveCamera("PlayerViewCam"); //Set all InputMaps and set one InputMap active iH.setAllInputMaps(*(testScene.getScenegraph()->getActiveCamera())); iH.changeActiveInputMap("Object"); iH.getActiveInputMap()->update(geko); // ============================================================== // == Object (ant, afraid) ====================================== // ============================================================== Teapot teaAnt; Texture texCV((char*)RESOURCES_PATH "/cv_logo.bmp"); //AntMesh antMesh; //Node aiNodeFlick("Flick"); //aiNodeFlick.addGeometry(&teaAnt); //aiNodeFlick.addTexture(&texCV); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&aiNodeFlick); //AI ant_Flick; //ant_Flick.setAntAfraid(); //aiNodeFlick.ssetObject(&ant_Flick); // ============================================================== // == Object (ant, aggressiv) =================================== // ============================================================== AntMesh antMesh; //Node aiNodeFlack("Flack"); //aiNodeFlack.addGeometry(&teaAnt); //aiNodeFlack.addGeometry(&antMesh); //aiNodeFlack.addTexture(&texCV); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&aiNodeFlack); //AI ant_Flack; //ant_Flack.setAntAggressiv(); //aiNodeFlack.setObject(&ant_Flack); // ============================================================== // == Object (Tree) ============================================= // ============================================================== Texture texBrick((char*)RESOURCES_PATH "/brick.bmp"); //TreeMesh treeMesh; Teapot teaTree; TreeMesh treeMesh; Node treeNode("CookieTree"); StaticObject tree; tree.setTree(); treeNode.setObject(&tree); treeNode.addTexture(&texCV); treeNode.addGeometry(&treeMesh); glm::vec3 posFood(10.0, 0.0, -5.0); treeNode.addTranslation(posFood); treeNode.getBoundingSphere()->radius = 2.0; testScene.getScenegraph()->getRootNode()->addChildrenNode(&treeNode); // ============================================================== // == Player ==================================================== // ============================================================== Teapot teaPlayer; GekoMesh gekomesh; // Texture texBrick((char*)RESOURCES_PATH "/brick.bmp"); Node playerNode("Player"); playerNode.addTexture(&texBrick); playerNode.setObject(&geko); //playerNode.addGeometry(&teaPlayer); playerNode.addGeometry(&gekomesh); playerNode.setCamera(&cam); geko.setPosition(glm::vec3(10.0, 0.0, 10.0)); //Add the node to the Scene testScene.getScenegraph()->getRootNode()->addChildrenNode(&playerNode); // ============================================================== // == Questsystem ==================================================== // ============================================================== //QuestHandler questhandler; Quest questCollect(1); questCollect.setActive(true); Goal_Collect goalCollect(1); Goal_Collect goalCollect3(3); questCollect.addGoal(&goalCollect); questCollect.addGoal(&goalCollect3); Quest questCollect2(2); questCollect2.setActive(true); Goal_Collect goalCollect2(2); questCollect2.addGoal(&goalCollect2); goalCollect.setGoalCount(50); goalCollect2.setGoalCount(50); goalCollect3.setGoalCount(50); goalCollect.setItemType(ItemType::BRANCH); goalCollect2.setItemType(ItemType::BRANCH); goalCollect3.setItemType(ItemType::COOKIE); testLevel.getQuestHandler()->addQuest(&questCollect); testLevel.getQuestHandler()->addQuest(&questCollect2); /*questhandler.addQuest(&questCollect); questhandler.addQuest(&questCollect2);*/ //std::cout << "GRÖßE DES QUESTHANDLERS : " << questhandler.getQuests().size() << std::endl; // ============================================================== // == Collision, FightSystem===================================== // ============================================================== // Bounding Box creation for the objects and collision test // CollisionTest collision; FightSystem fight; //===================================================================// //==================Setting up the Observers========================// //==================================================================// ObjectObserver aiObserver(&testLevel); //ant_Flick.addObserver(&aiObserver); //ant_Flack.addObserver(&aiObserver); ObjectObserver playerObserver(&testLevel); geko.addObserver(&playerObserver); CollisionObserver colObserver(&testLevel); collision.addObserver(&colObserver); GravityObserver gravityObserver(&testLevel); collision.addObserver(&gravityObserver); SoundObserver soundObserver(&testLevel); // ============================================================== // == Object (Anthome) ========================================== // ============================================================== //TreeMesh treeMesh; AntHomeMesh homeMesh; Node homeNode("AntHome"); StaticObject home; //home.setTree(); homeNode.setObject(&home); homeNode.addTexture(&texBrick); homeNode.addGeometry(&homeMesh); glm::vec3 posHome(1.0, 0.0, 1.0); homeNode.addTranslation(posHome); homeNode.getBoundingSphere()->radius = 0.5; testScene.getScenegraph()->getRootNode()->addChildrenNode(&homeNode); glm::vec3 posFood2(10.0, 0.0, -5.0); glm::vec3 posSpawn(3.0, 0.0, 3.0); glm::vec3 posDefaultPlayer(0.0, 0.0, 0.0); DecisionTree *aggressivedecisionTree = new DecisionTree(); aggressivedecisionTree->setAntTreeAggressiv(); DecisionTree *afraidDecisionTree = new DecisionTree(); afraidDecisionTree->setAntTreeAfraid(); Graph<AStarNode, AStarAlgorithm>* antAggressiveGraph = new Graph<AStarNode, AStarAlgorithm>(); antAggressiveGraph->setExampleAntAfraid(posSpawn, posFood2, posDefaultPlayer); Graph<AStarNode, AStarAlgorithm>* antAfraidGraph = new Graph<AStarNode, AStarAlgorithm>(); antAfraidGraph->setExampleAntAfraid(posSpawn, posFood, posDefaultPlayer); //AntHome antHome(posSpawn, antMesh, &texCV, &texCV, aggressivedecisionTree, antAggressiveGraph, afraidDecisionTree, antAfraidGraph); ////antHome.generateGuards(5, &aiObserver); //antHome.generateWorkers(1, &aiObserver); SoundFileHandler sfh(1000); AntHome antHome(posSpawn, &sfh, antMesh, &soundObserver, &playerObserver, &texCV, &texCV, aggressivedecisionTree, antAggressiveGraph, afraidDecisionTree, antAfraidGraph); antHome.generateWorkers(5, testScene.getScenegraph()->getRootNode()); antHome.addAntsToSceneGraph(testScene.getScenegraph()->getRootNode()); collision.collectNodes(testScene.getScenegraph()->getRootNode()); float lastTime = glfwGetTime(); int i = 0; while (!glfwWindowShouldClose(testWindow.getWindow())) { i++; if (i == 30){ i++; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float currentTime = glfwGetTime(); float deltaTime = currentTime - lastTime; lastTime = currentTime; collision.update(); antHome.updateAnts(); antHome.printPosWorkers(); /* ant_Flick.update(); ant_Flack.update();*/ geko.update(); geko.setDeltaTime(currentTime); renderer.renderScene(testScene, testWindow); } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }