[ADDED] rotating bounding boxes

This commit is contained in:
Menno
2021-06-08 12:22:54 +02:00
parent aa9c6a0fbb
commit 625965ed1b
4 changed files with 31 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <iostream>
#include <glm/gtc/matrix_transform.hpp>
#include "../entities/entity.h"
@@ -15,6 +16,18 @@ namespace collision
{
glm::vec3 center_pos;
glm::vec3 size;
void SetRotation(float angle)
{
double sinTheta = glm::sin(glm::radians(angle));
double cosTheta = glm::cos(glm::radians(angle));
float x = size.x * cosTheta + size.z * sinTheta;
float z = size.z * cosTheta - size.x * sinTheta;
size.x = x < 0 ? -x : x;
size.z = z < 0 ? -z : z;
}
};
/*

View File

@@ -6,6 +6,7 @@
#include "../renderEngine/obj_loader.h"
#include "../renderEngine/Loader.h"
#include "../toolbox/toolbox.h"
#include "collision_entity.h"
namespace entities
{
@@ -27,8 +28,11 @@ namespace entities
furniture.push_front(std::make_shared<Entity>(house_model, position, glm::vec3(0, y_rotation, 0), HOUSE_SIZE));
// Add furniture
models::TexturedModel couch = GetFurnitureModel(FurnitureType::COUCH);
furniture.push_back(std::make_shared<Entity>(couch, glm::vec3(position.x, position.y + 20, position.z + 10), glm::vec3(0, 0, 0), HOUSE_SIZE));
models::TexturedModel couch = GetFurnitureModel(FurnitureType::COUCH);
glm::vec3 couchPos = glm::vec3(position.x, position.y + 20, position.z + 10);
collision::Box couchBox = { couchPos, couch.raw_model.model_size };
couchBox.SetRotation(90);
furniture.push_back(std::make_shared<CollisionEntity>(couch, couchPos, glm::vec3(0, 0, 0), HOUSE_SIZE, couchBox));
return furniture;
}

View File

@@ -12,6 +12,7 @@
#include <opencv2/videoio.hpp>
#include <opencv2/video.hpp>
#include "collision/collision.h"
#include "gui/gui_interactable.h"
#include "models/model.h"
#include "renderEngine/loader.h"
@@ -36,6 +37,16 @@ scene::Scene* current_scene;
int main(void)
{
collision::Box box = { glm::vec3(0, 0, 0), glm::vec3(5, 2, 10) };
box.SetRotation(180);
std::cout << box.size.x << std::endl;
std::cout << box.size.y << std::endl;
std::cout << box.size.z << std::endl;
return 0;
#pragma region OPENGL_SETTINGS
if (!glfwInit())
throw "Could not inditialize glwf";

View File

@@ -162,7 +162,7 @@ namespace scene
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
return_value = scene::Scenes::STOP;
}