diff --git a/res/background_grey.png b/res/background_grey.png new file mode 100644 index 0000000..d32155f Binary files /dev/null and b/res/background_grey.png differ diff --git a/res/menu_item_calibrate1.png b/res/menu_item_calibrate1.png new file mode 100644 index 0000000..98f68ff Binary files /dev/null and b/res/menu_item_calibrate1.png differ diff --git a/res/menu_item_calibrate1_click.png b/res/menu_item_calibrate1_click.png new file mode 100644 index 0000000..0825e14 Binary files /dev/null and b/res/menu_item_calibrate1_click.png differ diff --git a/res/menu_item_calibrate1_hover.png b/res/menu_item_calibrate1_hover.png new file mode 100644 index 0000000..c3d2583 Binary files /dev/null and b/res/menu_item_calibrate1_hover.png differ diff --git a/res/menu_item_quit1.png b/res/menu_item_quit1.png new file mode 100644 index 0000000..7b974b4 Binary files /dev/null and b/res/menu_item_quit1.png differ diff --git a/res/menu_item_quit1_click.png b/res/menu_item_quit1_click.png new file mode 100644 index 0000000..8b45519 Binary files /dev/null and b/res/menu_item_quit1_click.png differ diff --git a/res/menu_item_quit1_hover.png b/res/menu_item_quit1_hover.png new file mode 100644 index 0000000..21d25b1 Binary files /dev/null and b/res/menu_item_quit1_hover.png differ diff --git a/res/menu_item_start.png b/res/menu_item_start.png new file mode 100644 index 0000000..41a0a26 Binary files /dev/null and b/res/menu_item_start.png differ diff --git a/res/menu_item_start1.png b/res/menu_item_start1.png new file mode 100644 index 0000000..dd400c6 Binary files /dev/null and b/res/menu_item_start1.png differ diff --git a/res/menu_item_start1_click.png b/res/menu_item_start1_click.png new file mode 100644 index 0000000..cc2cc06 Binary files /dev/null and b/res/menu_item_start1_click.png differ diff --git a/res/menu_item_start1_hover.png b/res/menu_item_start1_hover.png new file mode 100644 index 0000000..4fcfae3 Binary files /dev/null and b/res/menu_item_start1_hover.png differ diff --git a/src/computervision/MenuTest.cpp b/src/computervision/MenuTest.cpp new file mode 100644 index 0000000..c5b90d1 --- /dev/null +++ b/src/computervision/MenuTest.cpp @@ -0,0 +1,25 @@ +#include "MenuTest.h" +#include + +namespace computervision +{ + int menu_item_array[4] = { 1, 2, 3, 4 }; + float item_number = 0; + + MenuTest::MenuTest(void) { + + } + + int MenuTest::GetMenuItem(bool hand_state) { + item_number += 0.20f; + + + int temp_item_number = item_number; + //If temp_item_number is equal to the size of the array, set item_number bac to zero to loop through the array again + if (temp_item_number == sizeof(menu_item_array) / sizeof(menu_item_array[0])) { + item_number = 0; + } + + return menu_item_array[temp_item_number]; + } +} \ No newline at end of file diff --git a/src/computervision/MenuTest.h b/src/computervision/MenuTest.h new file mode 100644 index 0000000..951a0a9 --- /dev/null +++ b/src/computervision/MenuTest.h @@ -0,0 +1,18 @@ + +namespace computervision +{ + class MenuTest { + public: + /** + * @brief Constructor for the class MenuTest, loads in array with menu items + * + */ + MenuTest(void); + /** + * @brief Returns the itemnumber in an array + * + * @param input_bool is either true or false, depending on the recognized hand gesture + */ + int GetMenuItem(bool input_bool); + }; +} \ No newline at end of file diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 829953c..155512e 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -69,8 +69,6 @@ namespace computervision hand_calibrator.DrawHandCalibrationText(camera_frame); imshow("camera", camera_frame); - - /*imshow("output", frame_out); imshow("foreground", foreground); imshow("handMask", handMask); diff --git a/src/gui/gui_element.h b/src/gui/gui_element.h index 9643674..9887c68 100644 --- a/src/gui/gui_element.h +++ b/src/gui/gui_element.h @@ -5,6 +5,11 @@ namespace gui { + //Represents the type of the entitie + enum class GuiType{ + LABEL, BUTTON + }; + /* * Structure for representing a gui item to display on the screen * @@ -18,9 +23,12 @@ namespace gui glm::vec2 position; glm::vec2 scale; + virtual GuiType GetType() { + return GuiType::LABEL; + } GuiTexture(int texture, glm::vec2 position, glm::vec2 scale): texture(texture), position(position), scale(scale) { - scale.x /= (WINDOW_WIDTH / WINDOW_HEIGT); + scale.x /= (WINDOW_WIDTH / WINDOW_HEIGHT); } }; } diff --git a/src/gui/gui_interactable.cpp b/src/gui/gui_interactable.cpp index 4681554..65cf6f5 100644 --- a/src/gui/gui_interactable.cpp +++ b/src/gui/gui_interactable.cpp @@ -2,6 +2,8 @@ #include #include "gui_interactable.h" +#include + namespace gui { InteractableGui::InteractableGui(int default_texture, glm::vec2 position, glm::vec2 scale) @@ -41,14 +43,47 @@ namespace gui } } + void InteractableGui::ForceClick( int mouseButton) + { + if(mouseButton == GLFW_MOUSE_BUTTON_LEFT) + { + if (clicked_texture != 0) + { + texture = clicked_texture; + } + else + { + texture = default_texture; + } + + if (!is_clicking) + { + OnClick(); + is_clicking = true; + } + } + else + { + if (is_clicking) + { + is_clicking = false; + } + } + + } + bool InteractableGui::IsHoveringAbove(GLFWwindow* window) { double x_pos, y_pos; glfwGetCursorPos(window, &x_pos, &y_pos); + //std::cout << "Cursor pos in method: " << x_pos <<"::" << y_pos << std::endl; const float x_rel = (x_pos / SCALED_WIDTH / DEFAULT_WIDTH) * 2.0f - 1.0f; const float y_rel = -((y_pos / SCALED_HEIGHT / DEFAULT_HEIGHT) * 2.0f - 1.0f); + //std::cout << "x_rel And y_rel in method: " << x_rel << "::" << y_rel << std::endl; + + if (x_rel >= minXY.x && x_rel <= maxXY.x && y_rel >= minXY.y && y_rel <= maxXY.y) { diff --git a/src/gui/gui_interactable.h b/src/gui/gui_interactable.h index 2957e7b..e9055c2 100644 --- a/src/gui/gui_interactable.h +++ b/src/gui/gui_interactable.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "../toolbox/toolbox.h" #include "gui_element.h" @@ -32,6 +33,14 @@ namespace gui */ void Update(GLFWwindow* window); + /* + * @brief: Call this function when you want to perform a mouseclick + * + * @param mousebutton: mouseButton you want to perform the click on + */ + void ForceClick(int mouseButton); + + /* * @brief: This function gets called when the InteractabeGui is clicked */ @@ -50,7 +59,10 @@ namespace gui /* * @brief: This function sets the texture of the InteractableGUI for when the InteractableGUI is clicked */ - void SetClickedTexture(int texture) { clicked_texture = texture; } + void SetClickedTexture(int texture) + { + clicked_texture = texture; + } /* * @brief: This function sets the texture of the InteractableGUI for when the mouse is hovering above the InteractableGUI @@ -104,6 +116,10 @@ namespace gui */ void SetOnExitAction(void (*fun)()) { on_exit_action = fun; } + GuiType GetType() override { + return GuiType::BUTTON; + } + protected: void OnClick() override { if (on_click_action != nullptr) on_click_action(); } void OnEnter() override { if (on_enter_action != nullptr) on_enter_action(); } diff --git a/src/main.cpp b/src/main.cpp index c93af64..fe1c2c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,8 @@ #include "stb_image.h" #include +#include +#include #include #include @@ -38,6 +40,8 @@ static double UpdateDelta(); +static GLFWwindow* window; + scene::Scene* current_scene; static GLFWwindow* window; @@ -58,7 +62,7 @@ int main(void) #pragma region OPENGL_SETTINGS if (!glfwInit()) throw "Could not inditialize glwf"; - window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGT, "SDBA", NULL, NULL); + window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SDBA", NULL, NULL); if (!window) { glfwTerminate(); @@ -81,8 +85,11 @@ int main(void) current_scene->onKey(window, key, scancode, action, mods); }); - + bool window_open = true; + + + // Main game loop while (!glfwWindowShouldClose(window) && window_open) { @@ -101,14 +108,21 @@ int main(void) current_scene = new scene::Startup_Scene(); break; + case scene::Scenes::INGAME: current_scene = new scene::In_Game_Scene(); break; - + default: std::cout << "Wrong return value!!! ->" << std::endl; break; } + + // Finish up + //shader.Stop(); + glfwSwapBuffers(window); + glfwPollEvents(); + } // Clean up -> preventing memory leaks!!! diff --git a/src/renderEngine/Renderer.cpp b/src/renderEngine/Renderer.cpp index 984860f..f135200 100644 --- a/src/renderEngine/Renderer.cpp +++ b/src/renderEngine/Renderer.cpp @@ -25,7 +25,7 @@ namespace render_engine glCullFace(GL_BACK); const glm::mat4 projectionMatrix = - glm::perspective(glm::radians(FOV), (WINDOW_WIDTH / WINDOW_HEIGT), NEAR_PLANE, FAR_PLANE); + glm::perspective(glm::radians(FOV), (WINDOW_WIDTH / WINDOW_HEIGHT), NEAR_PLANE, FAR_PLANE); // Load the projectionmatrix into the shader shader.Start(); diff --git a/src/scenes/in_Game_Scene.cpp b/src/scenes/in_Game_Scene.cpp index d546762..738ec28 100644 --- a/src/scenes/in_Game_Scene.cpp +++ b/src/scenes/in_Game_Scene.cpp @@ -48,8 +48,13 @@ namespace scene std::vector regions; computervision::HandDetectRegion reg_left("left", 0, 0, 150, 150), reg_right("right", 0, 0, 150, 150), reg_up("up", 0, 0, 150, 150); + /** + * sets up the first things when the objects has been made + */ In_Game_Scene::In_Game_Scene() { + camera = new entities::Camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); + shader = new shaders::EntityShader; shader->Init(); render_engine::renderer::Init(*shader); @@ -70,12 +75,18 @@ namespace scene box.center_pos = pos; return box; } - + /** + * deletes certain veriables when the object will be deleted, prevents memory leaks + */ In_Game_Scene::~In_Game_Scene() { - delete house_generator; + delete camera; + delete shader; + delete gui_shader; + delete house_generator; } + /** * @brief loads a new chunk in front of the camera, and deletes the chunk behind the camera. * @@ -113,8 +124,9 @@ namespace scene furniture_count_old = furniture_count -1; } - - + /** + * starts the game scene, calls the render and update methods in a while loop + */ scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window) { texture = { render_engine::loader::LoadTexture("res/Texture.png") }; @@ -139,7 +151,7 @@ namespace scene lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f))); // GUI stuff - gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(0.25f, 0.25f)); + gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(1, 1)); button.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png")); button.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png")); button.SetOnClickAction([]() @@ -149,11 +161,54 @@ namespace scene guis.push_back(&button); + //guis for the pause menu + gui::GuiTexture background(render_engine::loader::LoadTexture("res/background_grey.png"), glm::vec2(0, 0), glm::vec2(1, 1)); + pause_guis.push_back(&background); + + gui::Button pause_button_resume(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0, 0), glm::vec2(0.25f, 0.25f)); + pause_button_resume.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png")); + pause_button_resume.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png")); + pause_button_resume.SetOnClickAction([]() + { + std::cout << "I got clicked on the resume button!" << std::endl; + }); + pause_guis.push_back(&pause_button_resume); + + gui::Button pause_button_quit(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.3f, 0.0f), glm::vec2(0.25f, 0.25f)); + pause_button_quit.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png")); + pause_button_quit.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png")); + pause_button_quit.SetOnClickAction([]() + { + std::cout << "I got clicked on the quit button!" << std::endl; + }); + pause_guis.push_back(&pause_button_quit); + + + //the scene loop, this while loop represent the scene while (return_value == scene::Scenes::INGAME) { - update(window); - button.Update(window); - render(); + //checks the current game state, so it can render the correct models for each state + switch (game_state) + { + /*case scene::Game_State::IDLE: + break;*/ + + case scene::Game_State::PAUSED: + render(); + render_pause_menu(); + break; + + case scene::Game_State::RUNNING: + update(window); + button.Update(window); + render(); + break; + + default: + std::cout << "Game state unknown" << std::endl; + break; + } + glfwSwapBuffers(window); glfwPollEvents(); @@ -164,11 +219,14 @@ namespace scene return return_value; } + /** + * renders the game models + */ void scene::In_Game_Scene::render() { // Render render_engine::renderer::Prepare(); - + //starts the shader and begins to render shader->Start(); shader->LoadSkyColor(render_engine::renderer::SKY_COLOR); shader->LoadLightsDeque(lights); @@ -182,12 +240,13 @@ namespace scene render_engine::renderer::Render(*main_character, *shader); // Render GUI items - render_engine::renderer::Render(guis, *gui_shader); + //render_engine::renderer::Render(guis, *gui_shader); // Stop rendering the entities shader->Stop(); } + //updates certain variables void scene::In_Game_Scene::update(GLFWwindow* window) { //camera.Move(window); @@ -216,6 +275,7 @@ namespace scene update_hand_detection(); } + //manages the key input in the game scene void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) @@ -223,6 +283,14 @@ namespace scene cv::destroyWindow("camera"); return_value = scene::Scenes::STOP; } + if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) + { + game_state = scene::Game_State::PAUSED; + } + if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) + { + game_state = scene::Game_State::RUNNING; + } if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS) { diff --git a/src/scenes/in_Game_Scene.h b/src/scenes/in_Game_Scene.h index e4dea16..590b057 100644 --- a/src/scenes/in_Game_Scene.h +++ b/src/scenes/in_Game_Scene.h @@ -1,22 +1,100 @@ #pragma once +#include +#include +#include #include "scene.h" +#include "../gui/gui_interactable.h" +#include "../models/model.h" +#include "../renderEngine/loader.h" +#include "../renderEngine/obj_loader.h" +#include "../renderEngine/renderer.h" +#include "../shaders/entity_shader.h" +#include "../toolbox/toolbox.h" + namespace scene { + /** + * This enum is for managing the game scene state. + * for example: when pressed on a specific button, the game will be in a paused state and nothing about the player or the speed of the game will be updated + * and the pause screen will show up. + **/ + enum class Game_State + { + //IDLE, + RUNNING, + PAUSED + }; + class In_Game_Scene : public scene::Scene { private: + //return_value is an enum that is necessary for the scene switching. Whenever this changes, the scene will change to a different scene. scene::Scenes return_value = scene::Scenes::INGAME; + //game_state is an enum that keeps track of the current game state. For example: is the game running(thus the user is playing the game) of is the game paused. + scene::Game_State game_state = scene::Game_State::RUNNING; + + //entities_to_render is a list of entities, those entities will be rendered in the 3D environment. + std::vector entities_to_render; + //lights is a lost of light points in the game, for example the sun or it can be used to attach light effects to lamps. + std::vector lights; + + models::RawModel raw_model; + models::ModelTexture texture; + //the shader that is used for rendering the models. + shaders::EntityShader* shader; + //the gui_shader is used of rendering the gui models (for example the pause buttons). + shaders::GuiShader* gui_shader; + //camera is the camera view of the game scene, this camera will be behind the main character. + entities::Camera *camera; + //guis is a list of all the gui components that needs to be load in the scene. + std::vector guis; + //pause_guis is a list of components that will be rendered when the game is paused. + std::vector pause_guis; + + /** + * @brief renders the objects/gui models + * @param + * @return void + */ + void render_pause_menu(); void update_hand_detection(); public: In_Game_Scene(); ~In_Game_Scene(); + /** + * @brief the method start is the start of the scene where a while loop runs, this runs the scene. + * @param window the main window of the application + * @return Scene value that indicates in which scene the application is + */ Scenes start(GLFWwindow* window) override; + + /** + * @brief this method renders the models for the game scene + * @param + * @return void + */ void render() override; + + /** + * @brief this method updates the models/variables for the game scene + * @param window the main window of the application + * @return void + */ void update(GLFWwindow* window) override; + + /** + * @brief this method updates the models/variables for the game scene + * @param window the main window of the application + * @param key this is the keycode on which key has been pressed + * @param scancode - + * @param action- + * @param mods - + * @return void + */ void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override; }; } diff --git a/src/scenes/scene.cpp b/src/scenes/scene.cpp new file mode 100644 index 0000000..12f4435 --- /dev/null +++ b/src/scenes/scene.cpp @@ -0,0 +1,7 @@ +#include +#include "scene.h" + +scene::Scene::~Scene() +{ + std::cout << "Main scene class gone!" << std::endl; +} diff --git a/src/scenes/scene.h b/src/scenes/scene.h index a4d07bd..4db2fe5 100644 --- a/src/scenes/scene.h +++ b/src/scenes/scene.h @@ -6,6 +6,9 @@ namespace scene { + /** + * this enum represents the scenes in the game, those wil help to keep track in which scene the game is. + */ enum class Scenes { STARTUP, @@ -18,14 +21,40 @@ namespace scene { class Scene { public: + virtual ~Scene() = 0; + + /** + * @brief the method start is the start of a scene where a while loop runs, this runs the scene. + * @param window the main window of the application + * @return Scene value that indicates in which scene the application is + */ virtual Scenes start(GLFWwindow* window) = 0; + + /** + * @brief this method renders the models for a scene + * @param + * @return void + */ virtual void render() = 0; + + /** + * @brief this method updates the models/variables for a scene + * @param window the main window of the application + * @return void + */ virtual void update(GLFWwindow* window) = 0; + + /** + * @brief this method updates the models/variables for a scene + * @param window the main window of the application + * @param key this is the keycode on which key has been pressed + * @param scancode - + * @param action- + * @param mods - + * @return void + */ virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {}; - }; - - } diff --git a/src/scenes/startup_Scene.cpp b/src/scenes/startup_Scene.cpp index a492c18..33f7d5e 100644 --- a/src/scenes/startup_Scene.cpp +++ b/src/scenes/startup_Scene.cpp @@ -1,39 +1,200 @@ +#include #include #include #include #include "startup_Scene.h" +#include +#include + +#include "../models/model.h" +#include "../renderEngine/loader.h" +#include "../renderEngine/obj_loader.h" +#include "../renderEngine/renderer.h" +#include "../shaders/entity_shader.h" +#include "../gui/gui_interactable.h" +#include "../toolbox/toolbox.h" +#include "../computervision/MenuTest.h" #include "../computervision/ObjectDetection.h" #include "../computervision/HandDetectRegion.h" -#include + + + namespace scene { - computervision::ObjectDetection objDetect; + shaders::GuiShader* gui_shader1; + std::vector guis1; + computervision::ObjectDetection objDetect; + + float item_number = 0; + + bool hand_mode = false; + + Startup_Scene::Startup_Scene() { + shaders::EntityShader shader; + shader.Init(); + render_engine::renderer::Init(shader); + shader.CleanUp(); + + gui_shader1 = new shaders::GuiShader(); + gui_shader1->Init(); + } + + gui::Button* ConvertGuiTextureToButton(gui::GuiTexture* texture) { + if (texture != NULL) + if (texture->GetType() == gui::GuiType::BUTTON) { + + gui::Button* button = (gui::Button*)texture; + return button; + } + else { + return NULL; + } + } + + /*gui::InteractableGui* ConvertGuiTextureToInteractableGui(gui::GuiTexture* texture) { + if (texture != NULL) + if (texture->GetType() == gui::GuiType::BUTTON) { + return (gui::InteractableGui*)texture; + } + else { + return NULL; + } + + }*/ + + gui::GuiTexture* GetMenuItem(bool hand_state) { + if(hand_state) + item_number += 0.20f; + + int temp_item_number = item_number; + + //If temp_item_number is equal to the size of the array, set item_number bac to zero to loop through the array again + if (temp_item_number == guis1.size()) { + item_number = 0; + temp_item_number = 0; + } + std::cout << guis1[temp_item_number]->texture << std::endl; + return guis1[temp_item_number]; + } + scene::Scenes scene::Startup_Scene::start(GLFWwindow *window) { + // GUI stuff + gui::Button button_start(render_engine::loader::LoadTexture("res/menu_item_start1.png"), glm::vec2(0.0f, 0.6f), glm::vec2(0.25f, 0.25f)); + button_start.SetHoverTexture(render_engine::loader::LoadTexture("res/menu_item_start1_hover.png")); + button_start.SetClickedTexture(render_engine::loader::LoadTexture("res/menu_item_start1_click.png")); + button_start.SetOnClickAction([]() + { + std::cout << "Clicked on button: Start!" << std::endl; + + }); + guis1.push_back(&button_start); + + gui::Button button_calibrate(render_engine::loader::LoadTexture("res/menu_item_calibrate1.png"), glm::vec2(0.0f, 0.0f), glm::vec2(0.25f, 0.25f)); + button_calibrate.SetHoverTexture(render_engine::loader::LoadTexture("res/menu_item_calibrate1_hover.png")); + button_calibrate.SetClickedTexture(render_engine::loader::LoadTexture("res/menu_item_calibrate1_click.png")); + button_calibrate.SetOnClickAction([]() + { + std::cout << "Clicked on button: Calibrate!" << std::endl; + + }); + guis1.push_back(&button_calibrate); + + gui::Button button_quit(render_engine::loader::LoadTexture("res/menu_item_quit1.png"), glm::vec2(0.0f, -0.6f), glm::vec2(0.25f, 0.25f)); + button_quit.SetHoverTexture(render_engine::loader::LoadTexture("res/menu_item_quit1_hover.png")); + button_quit.SetClickedTexture(render_engine::loader::LoadTexture("res/menu_item_quit1_click.png")); + button_quit.SetOnClickAction([]() + { + std::cout << "Clicked on button: Quit!" << std::endl; + }); + guis1.push_back(&button_quit); + + computervision::ObjectDetection objDetect; + cv::Mat cameraFrame; + gui::GuiTexture* chosen_item = NULL; //This is the selected menu_item + bool hand_closed = false; //Flag to prevent multiple button presses + while (return_value == scene::Scenes::STARTUP) { render(); update(window); + + if (hand_mode) { + cameraFrame = objDetect.readCamera(); + + //Get hand state from camera + bool hand_detection = objDetect.detectHand(cameraFrame); + + if (hand_detection) + { + hand_closed = false; + std::cout << "hand is opened" << std::endl; + + //Loop through menu items + chosen_item = GetMenuItem(true); + + gui::Button* new_button = ConvertGuiTextureToButton(chosen_item); + if (new_button != NULL) { + const float x_pos = (chosen_item->position.x + 1.0) * WINDOW_WIDTH / 2; + const float y_pos = (1.0 - chosen_item->position.y) * WINDOW_HEIGHT / 2; + + //Set cursor to location of selected menu_item + glfwSetCursorPos(window, x_pos, y_pos); + } + } + else if (!hand_detection) + { + std::cout << "hand is closed" << std::endl; + + //Gets selected menu_item + chosen_item = GetMenuItem(false); + gui::Button* new_button = ConvertGuiTextureToButton(chosen_item); + + if (new_button != NULL && !hand_closed) { + //Run function click + new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT); + hand_closed = true; + } + } + } glfwSwapBuffers(window); glfwPollEvents(); } - + gui_shader1->CleanUp(); + render_engine::loader::CleanUp(); return return_value; } + /** + * renders the models in the start-up scene + */ void scene::Startup_Scene::render() { + render_engine::renderer::Prepare(); + // Render GUI items + render_engine::renderer::Render(guis1, *gui_shader1); } + /** + * updates the variables for the start-up scene + */ void scene::Startup_Scene::update(GLFWwindow* window) { + for (gui::GuiTexture* button : guis1) { + gui::Button* new_button = ConvertGuiTextureToButton(button); + if (new_button != NULL) + new_button->Update(window); + } bool hand_present; objDetect.DetectHand(objDetect.ReadCamera(),hand_present); } + /** + * manages the key input in the start-up scene + */ void scene::Startup_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods) { if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) @@ -41,5 +202,8 @@ namespace scene return_value = scene::Scenes::INGAME; cv::destroyWindow("camera"); } + else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { + hand_mode = !hand_mode; + } } } diff --git a/src/scenes/startup_Scene.h b/src/scenes/startup_Scene.h index 277a750..b38fb39 100644 --- a/src/scenes/startup_Scene.h +++ b/src/scenes/startup_Scene.h @@ -1,6 +1,6 @@ #pragma once #include "scene.h" -#include +#include "../gui/gui_element.h" namespace scene { @@ -9,12 +9,46 @@ namespace scene class Startup_Scene : public scene::Scene { private: + //return_value is an enum that is necessary for the scene switching. Whenever this changes, the scene will change to a different scene. scene::Scenes return_value = scene::Scenes::STARTUP; public: + /** + * @brief Constructor of the class Startup_Scene + * + */ + Startup_Scene(); + + /** + * @brief + * + * @param window + * @return + */ Scenes start(GLFWwindow* window) override; + + /** + * @brief + * + */ void render() override; + + /** + * @brief This method updates all the components on the window + * + * @param window Window it updates + */ void update(GLFWwindow* window) override; + + /** + * @brief Listener for key events + * + * @param window Window it listens to for key events + * @param key Key of event that is activated + * @param scancode Code of Key + * @param action + * @param mods + */ void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override; }; } diff --git a/src/toolbox/toolbox.h b/src/toolbox/toolbox.h index 49de76e..cc5d5b9 100644 --- a/src/toolbox/toolbox.h +++ b/src/toolbox/toolbox.h @@ -11,10 +11,10 @@ namespace toolbox // Change these macros to change the window size #define WINDOW_WIDTH 1400.0f - #define WINDOW_HEIGT 800.0f + #define WINDOW_HEIGHT 800.0f #define SCALED_WIDTH (WINDOW_WIDTH/DEFAULT_WIDTH) - #define SCALED_HEIGHT (WINDOW_HEIGT/DEFAULT_HEIGHT) + #define SCALED_HEIGHT (WINDOW_HEIGHT/DEFAULT_HEIGHT) // /* diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 9d54ea8..e94f7ca 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -25,6 +25,8 @@ + + @@ -39,6 +41,7 @@ + @@ -59,6 +62,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index 6f20dba..95623e9 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -86,6 +86,10 @@ Source Files + + Source Files + + Source Files @@ -169,6 +173,9 @@ Header Files + + Header Files + Header Files