Mergebranch jasper into develop #5
BIN
res/background_grey.png
Normal file
|
After Width: | Height: | Size: 294 KiB |
BIN
res/menu_item_calibrate1.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
res/menu_item_calibrate1_click.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
res/menu_item_calibrate1_hover.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
res/menu_item_quit1.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
res/menu_item_quit1_click.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
res/menu_item_quit1_hover.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
res/menu_item_start.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
res/menu_item_start1.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
res/menu_item_start1_click.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
res/menu_item_start1_hover.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
25
src/computervision/MenuTest.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "MenuTest.h"
|
||||
#include <iostream>
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
18
src/computervision/MenuTest.h
Normal file
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "gui_interactable.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#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(); }
|
||||
|
||||
20
src/main.cpp
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "stb_image.h"
|
||||
#include <ostream>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
@@ -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!!!
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -48,8 +48,13 @@ namespace scene
|
||||
std::vector<computervision::HandDetectRegion> 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)
|
||||
{
|
||||
|
||||
@@ -1,22 +1,100 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#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::Entity> 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<entities::Light> 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<gui::GuiTexture*> guis;
|
||||
//pause_guis is a list of components that will be rendered when the game is paused.
|
||||
std::vector<gui::GuiTexture*> 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;
|
||||
};
|
||||
}
|
||||
|
||||
7
src/scenes/scene.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "scene.h"
|
||||
|
||||
scene::Scene::~Scene()
|
||||
{
|
||||
std::cout << "Main scene class gone!" << std::endl;
|
||||
}
|
||||
@@ -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) {};
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,39 +1,200 @@
|
||||
#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <map>
|
||||
#include "startup_Scene.h"
|
||||
#include <iostream>
|
||||
#include <opencv2/core/mat.hpp>
|
||||
|
||||
#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 <iostream>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace scene
|
||||
{
|
||||
computervision::ObjectDetection objDetect;
|
||||
shaders::GuiShader* gui_shader1;
|
||||
std::vector<gui::GuiTexture*> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
#include <map>
|
||||
#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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
//
|
||||
|
||||
/*
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
<ClCompile Include="src\computervision\calibration\HandCalibrator.cpp" />
|
||||
<ClCompile Include="src\computervision\HandDetectRegion.cpp" />
|
||||
<ClCompile Include="src\scenes\in_Game_Scene.cpp" />
|
||||
<ClCompile Include="src\computervision\FaceDetector.cpp" />
|
||||
<ClCompile Include="src\computervision\MenuTest.cpp" />
|
||||
<ClCompile Include="src\computervision\async\async_arm_detection.cpp" />
|
||||
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
|
||||
<ClCompile Include="src\computervision\OpenPoseVideo.cpp" />
|
||||
@@ -39,6 +41,7 @@
|
||||
<ClCompile Include="src\renderEngine\loader.cpp" />
|
||||
<ClCompile Include="src\renderEngine\obj_loader.cpp" />
|
||||
<ClCompile Include="src\renderEngine\renderer.cpp" />
|
||||
<ClCompile Include="src\scenes\scene.cpp" />
|
||||
<ClCompile Include="src\shaders\gui_shader.cpp" />
|
||||
<ClCompile Include="src\shaders\shader_program.cpp" />
|
||||
<ClCompile Include="src\shaders\entity_shader.cpp" />
|
||||
@@ -59,6 +62,7 @@
|
||||
<ClInclude Include="src\computervision\async\StaticCameraInstance.h" />
|
||||
<ClInclude Include="src\computervision\FingerCount.h" />
|
||||
<ClInclude Include="src\computervision\BackgroundRemover.h" />
|
||||
<ClInclude Include="src\computervision\MenuTest.h" />
|
||||
<ClInclude Include="src\computervision\OpenPoseVideo.h" />
|
||||
<ClInclude Include="src\computervision\SkinDetector.h" />
|
||||
<ClInclude Include="src\computervision\ObjectDetection.h" />
|
||||
|
||||
@@ -86,6 +86,10 @@
|
||||
<ClCompile Include="src\computervision\BackgroundRemover.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\computervision\MenuTest.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\scenes\scene.cpp">
|
||||
<ClCompile Include="src\entities\house_generator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -169,6 +173,9 @@
|
||||
<ClInclude Include="src\toolbox\Timer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\computervision\MenuTest.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\entities\house_generator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
||||