#include #include #include #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #include #include #include #include #include #include #include #include "models/model.h" #include "renderEngine/loader.h" #include "renderEngine/obj_loader.h" #include "renderEngine/renderer.h" #include "shaders/static_shader.h" #include "toolbox/toolbox.h" #include "computervision/MenuTest.h" #include "computervision/ObjectDetection.h" #pragma comment(lib, "glfw3.lib") #pragma comment(lib, "glew32s.lib") #pragma comment(lib, "opengl32.lib") static double UpdateDelta(); static GLFWwindow* window; int chosen_item = 0; int main(void) { #pragma region OPENGL_SETTINGS if (!glfwInit()) throw "Could not inditialize glwf"; window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGT, "SDBA", NULL, NULL); if (!window) { glfwTerminate(); throw "Could not initialize glwf"; } glfwMakeContextCurrent(window); glewInit(); glGetError(); #pragma endregion glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE) glfwSetWindowShouldClose(window, true); }); models::RawModel raw_model = LoadObjModel("res/Tree.obj"); models::ModelTexture texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") }; models::TexturedModel model = { raw_model, texture }; entities::Entity entity(model, glm::vec3(0, -5, -20), glm::vec3(0, 0, 0), 1); shaders::StaticShader shader; shader.Init(); render_engine::renderer::Init(shader); entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); // create object detection object instance computervision::ObjectDetection objDetect; // set up object detection //objDetect.setup(); cv::Mat cameraFrame; // Main game loop while (!glfwWindowShouldClose(window)) { // Update const double delta = UpdateDelta(); entity.IncreaseRotation(glm::vec3(0, 1, 0)); camera.Move(window); // Render render_engine::renderer::Prepare(); shader.Start(); shader.LoadViewMatrix(camera); render_engine::renderer::Render(entity, shader); cameraFrame = objDetect.readCamera(); ////////////////////////// KIMS SHIT //////////////////////////////////// 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); glfwPollEvents(); } // Clean up shader.CleanUp(); render_engine::loader::CleanUp(); glfwTerminate(); return 0; } static double UpdateDelta() { double current_time = glfwGetTime(); static double last_frame_time = current_time; double delt_time = current_time - last_frame_time; last_frame_time = current_time; return delt_time; }