[ADDED] rotating bounding boxes
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include "../entities/entity.h"
|
#include "../entities/entity.h"
|
||||||
|
|
||||||
@@ -15,6 +16,18 @@ namespace collision
|
|||||||
{
|
{
|
||||||
glm::vec3 center_pos;
|
glm::vec3 center_pos;
|
||||||
glm::vec3 size;
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "../renderEngine/obj_loader.h"
|
#include "../renderEngine/obj_loader.h"
|
||||||
#include "../renderEngine/Loader.h"
|
#include "../renderEngine/Loader.h"
|
||||||
#include "../toolbox/toolbox.h"
|
#include "../toolbox/toolbox.h"
|
||||||
|
#include "collision_entity.h"
|
||||||
|
|
||||||
namespace entities
|
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));
|
furniture.push_front(std::make_shared<Entity>(house_model, position, glm::vec3(0, y_rotation, 0), HOUSE_SIZE));
|
||||||
|
|
||||||
// Add furniture
|
// Add furniture
|
||||||
models::TexturedModel couch = GetFurnitureModel(FurnitureType::COUCH);
|
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));
|
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;
|
return furniture;
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/main.cpp
11
src/main.cpp
@@ -12,6 +12,7 @@
|
|||||||
#include <opencv2/videoio.hpp>
|
#include <opencv2/videoio.hpp>
|
||||||
#include <opencv2/video.hpp>
|
#include <opencv2/video.hpp>
|
||||||
|
|
||||||
|
#include "collision/collision.h"
|
||||||
#include "gui/gui_interactable.h"
|
#include "gui/gui_interactable.h"
|
||||||
#include "models/model.h"
|
#include "models/model.h"
|
||||||
#include "renderEngine/loader.h"
|
#include "renderEngine/loader.h"
|
||||||
@@ -36,6 +37,16 @@ scene::Scene* current_scene;
|
|||||||
|
|
||||||
int main(void)
|
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
|
#pragma region OPENGL_SETTINGS
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
throw "Could not inditialize glwf";
|
throw "Could not inditialize glwf";
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ namespace scene
|
|||||||
|
|
||||||
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
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;
|
return_value = scene::Scenes::STOP;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user