Merge branch 'feature/game_logic/collisionFix' into feature/game_logic/game_over
* feature/game_logic/collisionFix: [FIXED] collisions [WIP] collision fixing # Conflicts: # src/scenes/game_Over_Scene.cpp # src/scenes/in_Game_Scene.cpp
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace collision
|
||||
{
|
||||
void CheckCollisions(std::vector<std::shared_ptr<entities::CollisionEntity>> entities)
|
||||
void CheckCollisions(std::vector<std::shared_ptr<entities::CollisionEntity>>& entities)
|
||||
{
|
||||
if (entities.size() < 2) { return; }
|
||||
if (entities.size() == 2)
|
||||
@@ -15,7 +15,7 @@ namespace collision
|
||||
entities[1]->OnCollide(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < entities.size() - 2; i++)
|
||||
{
|
||||
std::shared_ptr<entities::CollisionEntity> entity = entities[i];
|
||||
|
||||
@@ -13,5 +13,5 @@ namespace collision
|
||||
*
|
||||
* @param entities: A list with all the collision entities.
|
||||
*/
|
||||
void CheckCollisions(std::vector<std::shared_ptr<entities::CollisionEntity>> entities);
|
||||
void CheckCollisions(std::vector<std::shared_ptr<entities::CollisionEntity>>& entities);
|
||||
}
|
||||
@@ -40,7 +40,10 @@ namespace entities
|
||||
|
||||
const glm::vec3 size = bounding_box.size;
|
||||
|
||||
min_xyz = bounding_box.center_pos;
|
||||
max_xyz = glm::vec3(min_xyz.x + size.x, min_xyz.y + size.y, min_xyz.z + size.z);
|
||||
min_xyz = { bounding_box.center_pos.x - (0.5 * size.x), bounding_box.center_pos.y, bounding_box.center_pos.z - (0.5 * size.z) };
|
||||
max_xyz = { bounding_box.center_pos.x + (0.5 * size.x), bounding_box.center_pos.y + size.y, bounding_box.center_pos.z + (0.5 * size.z) };
|
||||
|
||||
// min_xyz = bounding_box.center_pos;
|
||||
// max_xyz = { bounding_box.center_pos.x + size.x, bounding_box.center_pos.y + size.y, bounding_box.center_pos.z + size.z };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace entities
|
||||
void SetCollisionBehaviour(std::function<void(const collision::Collision&)> function)
|
||||
{ if (function != nullptr) { on_collide = function; } }
|
||||
|
||||
protected:
|
||||
public:
|
||||
|
||||
/*
|
||||
* @brief: This method moves the collision to the center of the entity
|
||||
|
||||
@@ -20,75 +20,75 @@ namespace entities
|
||||
GenerateFurnitureModels();
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<Entity>> HouseGenerator::GenerateHouse(const glm::vec3& position, float y_rotation)
|
||||
std::deque<std::shared_ptr<CollisionEntity>> HouseGenerator::GenerateHouse(const glm::vec3& position, float y_rotation)
|
||||
{
|
||||
std::deque<std::shared_ptr<Entity>> furniture;
|
||||
std::deque<std::shared_ptr<CollisionEntity>> furniture;
|
||||
|
||||
// Add house
|
||||
furniture.push_front(std::make_shared<Entity>(house_model, position, glm::vec3(0, y_rotation, 0), HOUSE_SIZE));
|
||||
collision::Box house_box = { position, glm::vec3(0,0,0) };
|
||||
furniture.push_front(std::make_shared<CollisionEntity>(house_model, position, glm::vec3(0, y_rotation, 0), HOUSE_SIZE, house_box));
|
||||
|
||||
for(int i = 0; i<toolbox::Random(1,4);i++)
|
||||
{
|
||||
FurnitureType type = FurnitureType(toolbox::Random(0, furniture_models.size() - 1));
|
||||
models::TexturedModel model = GetFurnitureModel(type);
|
||||
glm::vec3 model_pos = glm::vec3(position.x, position.y, position.z);
|
||||
collision::Box model_box = { model_pos, model.raw_model.model_size };
|
||||
model_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, model_box));
|
||||
//furniture_collision.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, model_box));
|
||||
|
||||
}
|
||||
for(int i = 0; i<toolbox::Random(1,4);i++)
|
||||
{
|
||||
FurnitureType type = FurnitureType(toolbox::Random(0, furniture_models.size() - 1));
|
||||
models::TexturedModel model = GetFurnitureModel(type);
|
||||
glm::vec3 model_pos = glm::vec3(position.x, position.y, position.z);
|
||||
collision::Box model_box = { model_pos, model.raw_model.model_size };
|
||||
model_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, model_box));
|
||||
|
||||
}
|
||||
|
||||
//furniture_collision.pop_front();
|
||||
|
||||
/*
|
||||
// Add furniture
|
||||
models::TexturedModel couch = GetFurnitureModel(FurnitureType::COUCH);
|
||||
glm::vec3 couch_pos = glm::vec3(position.x + 200, position.y, position.z + 10);
|
||||
collision::Box couch_box = { couch_pos, couch.raw_model.model_size };
|
||||
couch_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(couch, couch_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, couch_box));
|
||||
|
||||
models::TexturedModel table = GetFurnitureModel(FurnitureType::TABLE);
|
||||
glm::vec3 table_pos = glm::vec3(position.x - 30, position.y, position.z);
|
||||
collision::Box table_box = { table_pos, table.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(table, table_pos, glm::vec3(0, 0, 0), HOUSE_SIZE * 1.3, table_box));
|
||||
|
||||
models::TexturedModel chair = GetFurnitureModel(FurnitureType::CHAIR);
|
||||
glm::vec3 chair_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box chair_box = { chair_pos, chair.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(chair, chair_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, chair_box));
|
||||
|
||||
models::TexturedModel plant = GetFurnitureModel(FurnitureType::PLANT);
|
||||
glm::vec3 plant_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box plant_box = { plant_pos, plant.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(plant, plant_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, plant_box));
|
||||
|
||||
models::TexturedModel guitar = GetFurnitureModel(FurnitureType::GUITAR);
|
||||
glm::vec3 guitar_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box guitar_box = { guitar_pos, guitar.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(guitar, guitar_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, guitar_box));
|
||||
|
||||
models::TexturedModel bookshelf = GetFurnitureModel(FurnitureType::BOOKSHELF);
|
||||
glm::vec3 bookshelf_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box bookshelf_box = { bookshelf_pos, bookshelf.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(bookshelf, bookshelf_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, bookshelf_box));
|
||||
|
||||
models::TexturedModel lamp = GetFurnitureModel(FurnitureType::LAMP);
|
||||
glm::vec3 lamp_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box lamp_box = { lamp_pos, lamp.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(lamp, lamp_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, lamp_box));
|
||||
|
||||
models::TexturedModel ceiling_object = GetFurnitureModel(FurnitureType::CEILING_OBJECTS);
|
||||
glm::vec3 ceiling_object_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box ceiling_object_box = { ceiling_object_pos, ceiling_object.raw_model.model_size };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(ceiling_object, ceiling_object_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, ceiling_object_box));
|
||||
// Add furniture
|
||||
models::TexturedModel couch = GetFurnitureModel(FurnitureType::COUCH);
|
||||
glm::vec3 couch_pos = glm::vec3(position.x + 200, position.y, position.z + 10);
|
||||
collision::Box couch_box = { couch_pos, couch.raw_model.model_size * (HOUSE_SIZE) };
|
||||
couch_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(couch, couch_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, couch_box));
|
||||
|
||||
models::TexturedModel table = GetFurnitureModel(FurnitureType::TABLE);
|
||||
glm::vec3 table_pos = glm::vec3(position.x - 30, position.y, position.z);
|
||||
collision::Box table_box = { table_pos, table.raw_model.model_size * ((HOUSE_SIZE) * 1.3f) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(table, table_pos, glm::vec3(0, 0, 0), HOUSE_SIZE * 1.3, table_box));
|
||||
|
||||
models::TexturedModel chair = GetFurnitureModel(FurnitureType::CHAIR);
|
||||
glm::vec3 chair_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box chair_box = { chair_pos, chair.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(chair, chair_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, chair_box));
|
||||
|
||||
models::TexturedModel plant = GetFurnitureModel(FurnitureType::PLANT);
|
||||
glm::vec3 plant_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box plant_box = { plant_pos, plant.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(plant, plant_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, plant_box));
|
||||
|
||||
models::TexturedModel guitar = GetFurnitureModel(FurnitureType::GUITAR);
|
||||
glm::vec3 guitar_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box guitar_box = { guitar_pos, guitar.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(guitar, guitar_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, guitar_box));
|
||||
|
||||
models::TexturedModel bookshelf = GetFurnitureModel(FurnitureType::BOOKSHELF);
|
||||
glm::vec3 bookshelf_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box bookshelf_box = { bookshelf_pos, bookshelf.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(bookshelf, bookshelf_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, bookshelf_box));
|
||||
|
||||
models::TexturedModel lamp = GetFurnitureModel(FurnitureType::LAMP);
|
||||
glm::vec3 lamp_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box lamp_box = { lamp_pos, lamp.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(lamp, lamp_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, lamp_box));
|
||||
|
||||
models::TexturedModel ceiling_object = GetFurnitureModel(FurnitureType::CEILING_OBJECTS);
|
||||
glm::vec3 ceiling_object_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box ceiling_object_box = { ceiling_object_pos, ceiling_object.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(ceiling_object, ceiling_object_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, ceiling_object_box));
|
||||
|
||||
models::TexturedModel misc = GetFurnitureModel(FurnitureType::MISC);
|
||||
glm::vec3 misc_pos = glm::vec3(position.x - 50, position.y, position.z + 220);
|
||||
collision::Box misc_box = { misc_pos, misc.raw_model.model_size };
|
||||
glm::vec3 misc_pos = glm::vec3(position.x - 50, position.y - 10, position.z + 220);
|
||||
collision::Box misc_box = { misc_pos, misc.raw_model.model_size * (HOUSE_SIZE) };
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(misc, misc_pos, glm::vec3(0, 0, 0), HOUSE_SIZE, misc_box));
|
||||
*/
|
||||
|
||||
return furniture;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <map>
|
||||
#include "../models/Model.h"
|
||||
#include "../collision/collision.h"
|
||||
#include "collision_entity.h"
|
||||
|
||||
namespace entities
|
||||
{
|
||||
@@ -44,7 +45,7 @@ namespace entities
|
||||
*
|
||||
* @return: A list with all the entities of the generated house (the furniture)
|
||||
*/
|
||||
std::deque<std::shared_ptr<Entity>> GenerateHouse(const glm::vec3& position, float y_rotation);
|
||||
std::deque<std::shared_ptr<CollisionEntity>> GenerateHouse(const glm::vec3& position, float y_rotation);
|
||||
|
||||
/*
|
||||
* @brief: Returns the depth of the house (chunk)
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace entities
|
||||
void MainCharacter::Move(GLFWwindow* window)
|
||||
{
|
||||
if (is_playing) {
|
||||
movement_speed = -0.5f; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||
movement_speed = -2.0f; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||
down_speed = -1.0f; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED
|
||||
side_speed = 0; //Side speed adjustment
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ int main(void)
|
||||
#pragma endregion
|
||||
|
||||
//TODO change back to 0, only to show how score is visible on end screen
|
||||
score = 30;
|
||||
score = 0;
|
||||
current_scene = new scene::Startup_Scene();
|
||||
|
||||
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
@@ -143,4 +143,4 @@ static double UpdateDelta()
|
||||
double delt_time = current_time - last_frame_time;
|
||||
last_frame_time = current_time;
|
||||
return delt_time;
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace scene
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
{
|
||||
return_value = scene::Scenes::STARTUP;
|
||||
//return_value = scene::Scenes::STARTUP;
|
||||
cv::destroyWindow("camera");
|
||||
}
|
||||
else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
|
||||
|
||||
@@ -129,14 +129,16 @@ namespace scene
|
||||
for (int i = 0; i < furniture_count; i++)
|
||||
{
|
||||
house_models.pop_front();
|
||||
collision_entities.pop_back();
|
||||
}
|
||||
}
|
||||
int z_offset = model_pos * (house_generator->GetHouseDepth()); // how much "in the distance" we should load the model
|
||||
|
||||
std::deque<std::shared_ptr<entities::Entity>> furniture = house_generator->GenerateHouse(glm::vec3(0, -75, -50 - z_offset), 90);
|
||||
std::deque<std::shared_ptr<entities::CollisionEntity>> furniture = house_generator->GenerateHouse(glm::vec3(0, -75, -50 - z_offset), 90);
|
||||
furniture_count = furniture.size();
|
||||
|
||||
house_models.insert(house_models.end(), furniture.begin(), furniture.end());
|
||||
collision_entities.insert(collision_entities.end(), furniture.begin(), furniture.end());
|
||||
std::cout << "funriture_count in load chunk (house included): " << furniture_count << std::endl;
|
||||
furniture_count_old = furniture_count - 1;
|
||||
|
||||
@@ -155,7 +157,7 @@ namespace scene
|
||||
raw_model_char = render_engine::LoadObjModel("res/beeTwo.obj");
|
||||
models::TexturedModel model_char = { raw_model_char, texture };
|
||||
collision::Box char_box = create_bounding_box(raw_model_char.model_size, glm::vec3(0, 0, 0), 1);
|
||||
main_character = std::make_shared<entities::MainCharacter>(model_char, glm::vec3(0, -50, -100), glm::vec3(0, 90, 0), 5, char_box);
|
||||
main_character = std::make_shared<entities::MainCharacter>(model_char, glm::vec3(0, 50, -100), glm::vec3(0, 90, 0), 5, char_box);
|
||||
collision_entities.push_back(main_character);
|
||||
house_generator = new entities::HouseGenerator();
|
||||
// load the first few house models
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace scene {
|
||||
|
||||
class Scene
|
||||
{
|
||||
static int END_SCORE;
|
||||
public:
|
||||
virtual ~Scene() = 0;
|
||||
|
||||
@@ -55,13 +54,6 @@ namespace scene {
|
||||
* @return void
|
||||
*/
|
||||
virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {};
|
||||
|
||||
static void SetEndScore(int score) {
|
||||
END_SCORE = score;
|
||||
}
|
||||
|
||||
static int GetEndScore() {
|
||||
return END_SCORE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace scene
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
{
|
||||
return_value = scene::Scenes::GAMEOVER;
|
||||
return_value = scene::Scenes::INGAME;
|
||||
cv::destroyWindow("camera");
|
||||
}
|
||||
else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
|
||||
|
||||
Reference in New Issue
Block a user