Compare commits

...

5 Commits

Author SHA1 Message Date
DESKTOP-EBR7IVA\kimve
a65f3391f7 [Add] Pointsystem works 2021-06-11 15:32:06 +02:00
DESKTOP-EBR7IVA\kimve
9b1bea3eec Merge branch 'feature/number-from-images' into feature/game_logic/point_system
* feature/number-from-images:
  [ADD] convert number to digits
2021-06-11 12:32:03 +02:00
DESKTOP-EBR7IVA\kimve
8c1191c131 [ADD] start of number display 2021-06-11 12:31:33 +02:00
DESKTOP-EBR7IVA\kimve
63c6ec8a0c Merge branch 'develop' of https://github.com/SemvdH/SDBA into develop
* 'develop' of https://github.com/SemvdH/SDBA:
  [FIX] pointer
  [FIX] in game scene
  [FIX] in game scene
2021-06-11 11:15:24 +02:00
DESKTOP-EBR7IVA\kimve
04c6f52e64 Merge branch 'develop' of https://github.com/SemvdH/SDBA into develop
* 'develop' of https://github.com/SemvdH/SDBA: (58 commits)
  [ADD] character falls when it hits a tree
  [ADD] start game scene fingers
  [ADD] added all the models to the project
  [ADD] static skin treshold
  [ADD] made collision work
  [ADD] better info on camera
  [ADD] up left and right detection regions
  [ADD] basic point system based on amount of entities in chunk (house entitie excluded)
  [ADD] furniture
  [ADD] hand detection type enum
  [ADD] multiple hand detection squares
  [ADDED] rotating bounding boxes
  [FIX] renamed uses of main_character to MainCharacter in in_Game_secene
  [ADD] start of multiple squares
  [ADD] added comments to startup_scene.h
  [ADD] comments to camera and toolbox
  [ADD] Commented main_character h and cpp files
  [ADD] added a on/off for hand detection in menu
  [ADD] contour of hand in calibration screen
  [ADD] made camera follow the character with lerp
  ...
2021-06-11 10:31:34 +02:00
6 changed files with 183 additions and 103 deletions

View File

@@ -109,6 +109,88 @@ namespace render_engine
glDrawArrays(GL_TRIANGLE_STRIP, 0, quad.vertex_count); glDrawArrays(GL_TRIANGLE_STRIP, 0, quad.vertex_count);
} }
// Enable depth test again
glEnable(GL_DEPTH_TEST);
// Disable alpha blending
glDisable(GL_BLEND);
// Disable the VBO and VAO
glDisableVertexAttribArray(0);
glBindVertexArray(0);
shader.Stop();
}
void Render(std::vector<std::shared_ptr<gui::GuiTexture>>& guis, shaders::GuiShader& shader)
{
shader.Start();
// Enable the VAO and the positions VBO
glBindVertexArray(quad.vao_id);
glEnableVertexAttribArray(0);
// Enable alpha blending (for transparency in the texture)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Disable depth testing to textures with transparency can overlap
glDisable(GL_DEPTH_TEST);
// Render each gui to the screen
for (std::shared_ptr<gui::GuiTexture> gui : guis)
{
// Bind the texture of the gui to the shader
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gui->texture);
glm::mat4 matrix = toolbox::CreateModelMatrix(gui->position, gui->scale);
shader.LoadModelMatrix(matrix);
glDrawArrays(GL_TRIANGLE_STRIP, 0, quad.vertex_count);
std::cout << "in render method, gui x value: " << gui.get()->scale.x << std::endl;
}
// Enable depth test again
glEnable(GL_DEPTH_TEST);
// Disable alpha blending
glDisable(GL_BLEND);
// Disable the VBO and VAO
glDisableVertexAttribArray(0);
glBindVertexArray(0);
shader.Stop();
}
void Render(std::shared_ptr<gui::GuiTexture>& gui, shaders::GuiShader& shader)
{
shader.Start();
// Enable the VAO and the positions VBO
glBindVertexArray(quad.vao_id);
glEnableVertexAttribArray(0);
// Enable alpha blending (for transparency in the texture)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Disable depth testing to textures with transparency can overlap
glDisable(GL_DEPTH_TEST);
// Render each gui to the screen
// Bind the texture of the gui to the shader
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gui->texture);
glm::mat4 matrix = toolbox::CreateModelMatrix(gui->position, gui->scale);
shader.LoadModelMatrix(matrix);
glDrawArrays(GL_TRIANGLE_STRIP, 0, quad.vertex_count);
// Enable depth test again // Enable depth test again
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

View File

@@ -40,5 +40,22 @@ namespace render_engine
@param shade: The shader the GUI textures need to be rendered with @param shade: The shader the GUI textures need to be rendered with
*/ */
void Render(std::vector<gui::GuiTexture*>& guis, shaders::GuiShader& shader); void Render(std::vector<gui::GuiTexture*>& guis, shaders::GuiShader& shader);
/*
* @brief: renders guis elements from a shared pointer vector
*
* @param guis: List with GUI textures to render
* @param sahde: The shader to use
*/
void Render(std::vector<std::shared_ptr<gui::GuiTexture>>& guis, shaders::GuiShader& shader);
/*
* @brief renders 1 gui element.
*
* @param gui: the texture to render
* @param shader: the shader to use
*/
void Render(std::shared_ptr<gui::GuiTexture>& gui, shaders::GuiShader& shader);
} }
} }

View File

@@ -21,12 +21,12 @@
#include <opencv2/core/base.hpp> #include <opencv2/core/base.hpp>
#include "../computervision/HandDetectRegion.h" #include "../computervision/HandDetectRegion.h"
#include "../computervision/ObjectDetection.h" #include "../computervision/ObjectDetection.h"
#include <string>
#define MAX_MODEL_DEQUE_SIZE 6 // max amount of models to load at the same time #define MAX_MODEL_DEQUE_SIZE 6 // max amount of models to load at the same time
#define UPCOMING_MODEL_AMOUNT 4 // how much models should be loaded in front of us #define UPCOMING_MODEL_AMOUNT 4 // how much models should be loaded in front of us
namespace scene namespace scene
{ {
std::shared_ptr<entities::MainCharacter>main_character; std::shared_ptr<entities::MainCharacter>main_character;
@@ -39,6 +39,7 @@ namespace scene
shaders::EntityShader* shader; shaders::EntityShader* shader;
shaders::GuiShader* gui_shader; shaders::GuiShader* gui_shader;
std::vector<gui::GuiTexture*> guis; std::vector<gui::GuiTexture*> guis;
std::vector<std::shared_ptr<gui::GuiTexture>> score_textures;
int furniture_count_old; int furniture_count_old;
int score; int score;
@@ -60,7 +61,26 @@ namespace scene
gui_shader = new shaders::GuiShader(); gui_shader = new shaders::GuiShader();
gui_shader->Init(); gui_shader->Init();
score = 0; score = 0;
for (int i = 0; i <= 9; i++)
{
std::shared_ptr<gui::GuiTexture> score_pointer;
std::string texture_path = "res/";
texture_path += std::to_string(i);
texture_path += ".png";
score_pointer = std::make_unique<gui::GuiTexture>(render_engine::loader::LoadTexture(texture_path), glm::vec2(-0.9f, 0.8f), glm::vec2(0.07, 0.15));
score_textures.push_back(score_pointer);
std::cout << "Add to score_pointer: " << texture_path << std::endl;
} }
std::cout << "Size textures: " << score_textures.size() << std::endl;
}
/** /**
* temporary!!!! * temporary!!!!
* just to make some bounding boxes * just to make some bounding boxes
@@ -241,13 +261,14 @@ namespace scene
// Stop rendering the entities // Stop rendering the entities
shader->Stop(); shader->Stop();
DrawScore(score);
} }
//updates certain variables //updates certain variables
void scene::In_Game_Scene::update(GLFWwindow* window) void scene::In_Game_Scene::update(GLFWwindow* window)
{ {
//camera.Move(window); //camera.Move(window);
main_character->Move(window); main_character->Move(window);
//std::cout << "x get: " << movement.x << "\ny get: " << movement.y << "\nz get: " << movement.z << "\n"; //std::cout << "x get: " << movement.x << "\ny get: " << movement.y << "\nz get: " << movement.z << "\n";
@@ -263,22 +284,16 @@ namespace scene
load_chunk(model_pos + UPCOMING_MODEL_AMOUNT); load_chunk(model_pos + UPCOMING_MODEL_AMOUNT);
score += furniture_count_old; score += furniture_count_old;
std::cout << "Score: " << score << std::endl; std::cout << "Score: " << score << std::endl;
std::cout << "Funriture_count_old in model (house excluded): " << furniture_count_old << std::endl; std::cout << "Furniture_count_old in model (house excluded): " << furniture_count_old << std::endl;
} }
// remember the position at which the new model was added // remember the position at which the new model was added
last_model_pos = model_pos; last_model_pos = model_pos;
collision::CheckCollisions(collision_entities); collision::CheckCollisions(collision_entities);
update_hand_detection(); update_hand_detection();
std::vector<int> res;
toolbox::GetDigitsFromNumber(1234567890, res);
std::cout << "number 1234567890 in digits: " << std::endl;
for (int i : res)
{
std::cout << i << " , ";
}
std::cout << std::endl;
} }
//manages the key input in the game scene //manages the key input in the game scene
@@ -329,4 +344,22 @@ namespace scene
{ {
render_engine::renderer::Render(pause_guis, *gui_shader); render_engine::renderer::Render(pause_guis, *gui_shader);
} }
void In_Game_Scene::DrawScore(int score)
{
std::vector<int> digits;
score_guis.clear();
toolbox::GetDigitsFromNumber(score, digits);
std::cout << "Digits size: " << digits.size() << std::endl;
for (int i = digits.size()-1; i >= 0; i--)
{
std::cout << "Digit in digits: " << i << std::endl;
score_textures[digits[i]].get()->position.x = 0.15 * i -0.9;
render_engine::renderer::Render(score_textures[digits[i]], *gui_shader);
}
}
} }

View File

@@ -11,6 +11,9 @@
#include "../renderEngine/renderer.h" #include "../renderEngine/renderer.h"
#include "../shaders/entity_shader.h" #include "../shaders/entity_shader.h"
#include "../toolbox/toolbox.h" #include "../toolbox/toolbox.h"
#include <opencv2/core/base.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
namespace scene namespace scene
@@ -54,7 +57,7 @@ namespace scene
//pause_guis is a list of components that will be rendered when the game is paused. //pause_guis is a list of components that will be rendered when the game is paused.
std::vector<gui::GuiTexture*> pause_guis; std::vector<gui::GuiTexture*> pause_guis;
std::vector<gui::GuiTexture*> score_guis; std::vector<std::shared_ptr<gui::GuiTexture>> score_guis;
/** /**
* @brief renders the objects/gui models * @brief renders the objects/gui models
@@ -99,6 +102,9 @@ namespace scene
* @return void * @return void
*/ */
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override; void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override;
void DrawScore(int score);
}; };
} }

View File

@@ -1,6 +1,6 @@
#include <ctime> #include <ctime>
#include "toolbox.h" #include "toolbox.h"
#include <iostream>
namespace toolbox namespace toolbox
{ {
glm::mat4 CreateModelMatrix(glm::vec2 translation, glm::vec2 scale) glm::mat4 CreateModelMatrix(glm::vec2 translation, glm::vec2 scale)

View File

@@ -24,6 +24,10 @@
<ClCompile Include="src\scenes\startup_Scene.cpp" /> <ClCompile Include="src\scenes\startup_Scene.cpp" />
<ClCompile Include="src\computervision\calibration\HandCalibrator.cpp" /> <ClCompile Include="src\computervision\calibration\HandCalibrator.cpp" />
<ClCompile Include="src\computervision\HandDetectRegion.cpp" /> <ClCompile Include="src\computervision\HandDetectRegion.cpp" />
<ClCompile Include="src\entities\main_character.cpp" />
<ClCompile Include="src\entities\house_generator.cpp" />
<ClCompile Include="src\computervision\MenuTest.cpp" />
<ClCompile Include="src\scenes\scene.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\entities\Camera.cpp"> <ClCompile Include="src\entities\Camera.cpp">
@@ -83,98 +87,8 @@
<ClCompile Include="src\computervision\BackgroundRemover.cpp"> <ClCompile Include="src\computervision\BackgroundRemover.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\computervision\MenuTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\scenes\scene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\entities\house_generator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\entities\Camera.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\entities\Entity.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\models\Model.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\renderEngine\Loader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\renderEngine\Renderer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\stb_image.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\shaders\shader_program.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\renderEngine\obj_loader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\toolbox\toolbox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\entities\light.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\shaders\entity_shader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\shaders\gui_shader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\gui\gui_element.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\gui\gui_interactable.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\scene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\in_Game_Scene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\startup_Scene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\entities\collision_entity.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\collision\collision.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\collision\collision_handler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\computervision\ObjectDetection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\computervision\SkinDetector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\computervision\FingerCount.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\computervision\BackgroundRemover.h">
<Filter>Header Files</Filter>
</ClInclude>
<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>
<ClInclude Include="src\collision\collision.h" /> <ClInclude Include="src\collision\collision.h" />
<ClInclude Include="src\collision\collision_handler.h" /> <ClInclude Include="src\collision\collision_handler.h" />
<ClInclude Include="src\scenes\in_Game_Scene.h" /> <ClInclude Include="src\scenes\in_Game_Scene.h" />
@@ -206,6 +120,34 @@
<ClInclude Include="src\computervision\calibration\HandCalibrator.h" /> <ClInclude Include="src\computervision\calibration\HandCalibrator.h" />
<ClInclude Include="src\computervision\HandDetectRegion.h" /> <ClInclude Include="src\computervision\HandDetectRegion.h" />
<ClInclude Include="src\computervision\calibration\StaticSkinTreshold.h" /> <ClInclude Include="src\computervision\calibration\StaticSkinTreshold.h" />
<ClInclude Include="src\collision\collision.h" />
<ClInclude Include="src\collision\collision_handler.h" />
<ClInclude Include="src\entities\main_character.h" />
<ClInclude Include="src\entities\house_generator.h" />
<ClInclude Include="src\scenes\in_Game_Scene.h" />
<ClInclude Include="src\scenes\scene.h" />
<ClInclude Include="src\computervision\FingerCount.h" />
<ClInclude Include="src\computervision\BackgroundRemover.h" />
<ClInclude Include="src\computervision\MenuTest.h" />
<ClInclude Include="src\computervision\SkinDetector.h" />
<ClInclude Include="src\computervision\ObjectDetection.h" />
<ClInclude Include="src\entities\camera.h" />
<ClInclude Include="src\entities\collision_entity.h" />
<ClInclude Include="src\entities\entity.h" />
<ClInclude Include="src\entities\light.h" />
<ClInclude Include="src\gui\gui_element.h" />
<ClInclude Include="src\gui\gui_interactable.h" />
<ClInclude Include="src\models\model.h" />
<ClInclude Include="src\renderEngine\loader.h" />
<ClInclude Include="src\renderEngine\obj_loader.h" />
<ClInclude Include="src\renderEngine\renderer.h" />
<ClInclude Include="src\shaders\gui_shader.h" />
<ClInclude Include="src\shaders\shader_program.h" />
<ClInclude Include="src\shaders\entity_shader.h" />
<ClInclude Include="src\stb_image.h" />
<ClInclude Include="src\toolbox\Timer.h" />
<ClInclude Include="src\toolbox\toolbox.h" />
<ClInclude Include="src\scenes\startup_Scene.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" /> <Xml Include="res\haarcascade_frontalface_alt.xml" />