diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 381b3cf..9009cbc 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -60,8 +60,8 @@ namespace computervision imshow("camera", cameraFrame); imshow("output", frameOut); - imshow("foreground", foreground); - imshow("handMask", handMask); + //imshow("foreground", foreground); + //imshow("handMask", handMask); imshow("handDetection", fingerCountDebug); int key = waitKey(1); diff --git a/src/gui/gui_element.h b/src/gui/gui_element.h index ea7afd0..9887c68 100644 --- a/src/gui/gui_element.h +++ b/src/gui/gui_element.h @@ -17,7 +17,6 @@ namespace gui * position = The center position of the gui * scale = The size (scale) of the gui */ - struct GuiTexture { int texture; @@ -27,10 +26,9 @@ namespace gui 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..6e939eb 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,6 +43,35 @@ 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; diff --git a/src/gui/gui_interactable.h b/src/gui/gui_interactable.h index 5743728..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 diff --git a/src/main.cpp b/src/main.cpp index 69aa61a..7300b1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,9 +25,6 @@ #include "scenes/in_Game_Scene.h" #include "scenes/startup_Scene.h" -#include "computervision/MenuTest.h" -#include "computervision/ObjectDetection.h" - #pragma comment(lib, "glfw3.lib") #pragma comment(lib, "glew32s.lib") #pragma comment(lib, "opengl32.lib") @@ -35,7 +32,7 @@ static double UpdateDelta(); static GLFWwindow* window; -int chosen_item = 0; + scene::Scene* current_scene; int main(void) @@ -43,7 +40,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(); @@ -69,8 +66,7 @@ int main(void) bool window_open = true; - computervision::ObjectDetection objDetect; - cv::Mat cameraFrame; + // Main game loop while (!glfwWindowShouldClose(window) && window_open) @@ -100,56 +96,6 @@ int main(void) break; } - - ////////////////////////// KIMS SHIT //////////////////////////////////// - cameraFrame = objDetect.readCamera(); - computervision::MenuTest menu_test; - - //Get hand state from camera - bool hand_detection = objDetect.detectHand(cameraFrame); - - if (hand_detection) - { - std::cout << "hand is opened" << std::endl; - - //Loop through menu items - chosen_item = menu_test.GetMenuItem(true); - - //For debug only, to see if chosen item is selected properly when hand is opened - std::cout << "chosen item: " << chosen_item << std::endl; - - } - else if (!hand_detection) - { - //for debug only, to see if the chosen item is selected properly when hand is closed - std::cout << "hand is closed" << std::endl; - //std::cout << "item to start: " << chosen_item << std::endl; - - //TODO link chosen item to the correct game states - switch (chosen_item) - { - case 1: - //Game state 0 - std::cout << "in case: " << chosen_item << std::endl; - break; - case 2: - //Game state 1 - std::cout << "in case: " << chosen_item << std::endl; - break; - case 3: - //Game state 2 - std::cout << "in case: " << chosen_item << std::endl; - break; - case 4: - //Game state 3 - std::cout << "in case: " << chosen_item << std::endl; - default: - break; - } - } - - ///////////////////////// END OF KIMS SHIT /////////////////////////////// - // Finish up //shader.Stop(); glfwSwapBuffers(window); diff --git a/src/renderEngine/Renderer.cpp b/src/renderEngine/Renderer.cpp index a91a5ec..9fa1135 100644 --- a/src/renderEngine/Renderer.cpp +++ b/src/renderEngine/Renderer.cpp @@ -26,7 +26,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/startup_Scene.cpp b/src/scenes/startup_Scene.cpp index 21e891c..bdec1e2 100644 --- a/src/scenes/startup_Scene.cpp +++ b/src/scenes/startup_Scene.cpp @@ -3,6 +3,8 @@ #include #include "startup_Scene.h" #include +#include + #include "../models/model.h" #include "../renderEngine/loader.h" #include "../renderEngine/obj_loader.h" @@ -10,6 +12,9 @@ #include "../shaders/entity_shader.h" #include "../gui/gui_interactable.h" #include "../toolbox/toolbox.h" +#include "../computervision/MenuTest.h" +#include "../computervision/ObjectDetection.h" + @@ -18,6 +23,9 @@ namespace scene shaders::GuiShader* gui_shader1; std::vector guis1; + float item_number = 0; + + Startup_Scene::Startup_Scene() { shaders::EntityShader shader; shader.Init(); @@ -29,12 +37,42 @@ namespace scene } gui::Button* ConvertGuiTextureToButton(gui::GuiTexture* texture) { - if (texture->GetType() == gui::GuiType::BUTTON) { - return (gui::Button*)texture; - } - else { - return NULL; + if (texture != NULL) + if (texture->GetType() == gui::GuiType::BUTTON) { + + gui::Button* button = (gui::Button*)texture; + std::cout << button->clicked_texture << std::endl; + 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) @@ -46,6 +84,7 @@ namespace scene button_start.SetOnClickAction([]() { std::cout << "Clicked on button: Start!" << std::endl; + }); guis1.push_back(&button_start); @@ -55,6 +94,7 @@ namespace scene button_calibrate.SetOnClickAction([]() { std::cout << "Clicked on button: Calibrate!" << std::endl; + }); guis1.push_back(&button_calibrate); @@ -67,6 +107,10 @@ namespace scene }); guis1.push_back(&button_quit); + computervision::ObjectDetection objDetect; + cv::Mat cameraFrame; + gui::GuiTexture* chosen_item = NULL; + while (return_value == scene::Scenes::STARTUP) { render(); @@ -77,7 +121,75 @@ namespace scene new_button->Update(window); } - + ////////////////////////// KIMS SHIT //////////////////////////////////// + cameraFrame = objDetect.readCamera(); + //computervision::MenuTest menu_test; + + //Get hand state from camera + bool hand_detection = objDetect.detectHand(cameraFrame); + + if (hand_detection) + { + std::cout << "hand is opened" << std::endl; + + //Loop through menu items + chosen_item = GetMenuItem(true); + + //For debug only, to see if chosen item is selected properly when hand is opened + std::cout << "chosen item: " << chosen_item << std::endl; + + gui::Button* new_button = ConvertGuiTextureToButton(chosen_item); + if (new_button != NULL) { + //Set hover texture of button selected + 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; + + glfwSetCursorPos(window, x_pos, y_pos); + std::cout << "Cursor pos: " << x_pos << "::" << y_pos << std::endl; + } + } + else if (!hand_detection) + { + //for debug only, to see if the chosen item is selected properly when hand is closed + std::cout << "hand is closed" << std::endl; + //std::cout << "item to start: " << chosen_item << std::endl; + /* + //TODO link chosen item to the correct game states + switch (chosen_item) + { + case 1: + //Game state 0 + std::cout << "in case: " << chosen_item << std::endl; + break; + case 2: + //Game state 1 + std::cout << "in case: " << chosen_item << std::endl; + break; + case 3: + //Game state 2 + std::cout << "in case: " << chosen_item << std::endl; + break; + case 4: + //Game state 3 + std::cout << "in case: " << chosen_item << std::endl; + default: + break; + } + */ + //Click on button selected in guis1 + + chosen_item = GetMenuItem(false); + + std::cout << chosen_item->texture << std::endl; + gui::Button* new_button = ConvertGuiTextureToButton(chosen_item); + if (new_button != NULL) { + //Run function click + new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT); + } + } + + ///////////////////////// END OF KIMS SHIT /////////////////////////////// + glfwSwapBuffers(window); glfwPollEvents(); } diff --git a/src/toolbox/toolbox.h b/src/toolbox/toolbox.h index f8bcef6..26a4d54 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) // /*