From 9a30593f13aae104ccd6a2b87d494454014d8096 Mon Sep 17 00:00:00 2001 From: Conni Bilham Date: Tue, 5 Mar 2024 01:59:27 +0000 Subject: [PATCH] Update DebugBox.cpp Remove some includes that arent needed, and tidy up some general code HandleKeyboard in Camera.h now allows moving in multiple directions at the same time --- CMakeLists.txt | 16 +-- Scenes/main_scene.cpp | 49 ++++----- Scenes/main_scene.h | 3 +- Scenes/orth_scene.cpp | 22 ++-- include/Camera.h | 16 +-- include/Entity_t.h | 13 ++- include/Vector.h | 43 ++++++++ include/vector.h | 50 --------- src/DebugRendering/DebugBox.cpp | 9 +- src/Entity_t.cpp | 41 ++++--- src/PhysicsEngine.cpp | 16 +-- src/Vector.cpp | 98 +++++++++++++++++ src/logging.cpp | 46 ++++---- src/vector.cpp | 187 -------------------------------- 14 files changed, 262 insertions(+), 347 deletions(-) create mode 100644 include/Vector.h delete mode 100644 include/vector.h create mode 100644 src/Vector.cpp delete mode 100644 src/vector.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 818188a..fd0cbe1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,16 +14,16 @@ set(SOURCE_FILES src/window.cpp include/Window.h - src/Shader.cpp include/Shader.h - src/logging.cpp include/logging.h - src/vector.cpp include/vector.h + src/Shader.cpp include/Shader.h + src/logging.cpp include/logging.h + src/Vector.cpp include/Vector.h src/Entity_t.cpp include/Entity_t.h - src/Camera.cpp include/Camera.h - src/Storage.cpp include/Storage.h - src/Scene.cpp include/Scene.h + src/Camera.cpp include/Camera.h + src/Storage.cpp include/Storage.h + src/Scene.cpp include/Scene.h - src/PhysicsEngine.cpp include/PhysicsEngine.h - Scenes/main_scene.cpp Scenes/main_scene.h + src/PhysicsEngine.cpp include/PhysicsEngine.h + Scenes/main_scene.cpp Scenes/main_scene.h Scenes/orth_scene.cpp Scenes/orth_scene.h diff --git a/Scenes/main_scene.cpp b/Scenes/main_scene.cpp index 28abb37..223cc8e 100644 --- a/Scenes/main_scene.cpp +++ b/Scenes/main_scene.cpp @@ -3,13 +3,14 @@ // #include "main_scene.h" -#include "logging.h" -#include "glm.hpp" -#include "gtc/matrix_transform.hpp" -#include "Camera.h" -#include "glad/glad.h" #include "../include/PhysicsEngine.h" +#include "Camera.h" #include "DebugRendering/DebugBox.h" +#include "Window.h" +#include "glad/glad.h" +#include "glm.hpp" +#include "gtc/matrix_transform.hpp" +#include "logging.h" void main_scene::Init(Camera *camera) { logging::verbose("main_scene::init()"); @@ -21,23 +22,23 @@ void main_scene::Init(Camera *camera) { shaders.push_back(new Shader("shaders/debug_line_vertex.glsl", "shaders/debug_line.frag")); // spawn entities at random positions -// int max_r = 100; -// int count = 100000; -// for (int i = 0; i < count; i++) { -// auto entity = new Entity_t(shaders[0], -// glm::vec3(rand() % max_r - max_r / 2, rand() % max_r - max_r / 2, rand() % max_r - max_r / 2), -// glm::vec3(0.0f), -// glm::vec3(0.5f)); -// entity->physics.engine = new PhysicsEngine(entity); -// entity->physics.enabled = i % 10; -// entity_list.push_back(entity); -// } + // int max_r = 100; + // int count = 100000; + // for (int i = 0; i < count; i++) { + // auto entity = new Entity_t(shaders[0], + // glm::vec3(rand() % max_r - max_r / 2, rand() % max_r - max_r / 2, rand() % max_r - max_r / 2), + // glm::vec3(0.0f), + // glm::vec3(0.5f)); + // entity->physics.engine = new PhysicsEngine(entity); + // entity->physics.enabled = i % 10; + // entity_list.push_back(entity); + // } auto entity = new Entity_t(shaders[0], glm::vec3(0, 0, 0), glm::vec3(0.0f), glm::vec3(0.5f)); entity->physics.engine = new PhysicsEngine(entity); - entity->physics.enabled = 0; + entity->physics.enabled = true; entity_list.push_back(entity); @@ -50,13 +51,13 @@ void main_scene::Init(Camera *camera) { void main_scene::Update(double deltaTime) { // create transformations - glm::mat4 view = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first - glm::mat4 projection = camera->getProjectionMatrix(storage->window.width, storage->window.height); + glm::mat4 view = glm::mat4(1.0f);// make sure to initialize matrix to identity matrix first + glm::mat4 projection = camera->getProjectionMatrix(storage->window.width, storage->window.height); view *= camera->view_matrix(); - for (auto &entity : entity_list) { + for (auto &entity: entity_list) { // First we want to apply physics e.g. gravity etc { entity->physics.engine->ApplyPhysics(deltaTime); @@ -67,15 +68,15 @@ void main_scene::Update(double deltaTime) { { entity->timer += deltaTime; if (entity->timer > 2) { -// entity->position.y = (rand() % 200) / 10; + // entity->position.y = (rand() % 200) / 10; entity->timer = 0; } } // This is where im simulating a collision system clamping all blocks to have their center be above y 0 { -// if (entity->position.y < 0) -// entity->position.y = 0; + if (entity->position.y < 0) + entity->position.y = 0; } // entity->scale += glm::vec3(0.0f, 0.0f, 0.1f); @@ -89,8 +90,6 @@ void main_scene::Update(double deltaTime) { this->draw_debug(); } -void main_scene::WindowResize(int width, int height) { - void main_scene::HandleMouseMovement(float xoffset, float yoffset) { const float pitch_max = 89; if (camera->pitch < -pitch_max) { diff --git a/Scenes/main_scene.h b/Scenes/main_scene.h index 312183e..f4e6dae 100644 --- a/Scenes/main_scene.h +++ b/Scenes/main_scene.h @@ -15,9 +15,8 @@ class main_scene : public Scene { public: void Init(Camera *camera) override; void Update(double deltaTime) override; - void WindowResize(int width, int height) override; void HandleMouseMovement(float xoffset, float yoffset) override; }; -#endif //INC_2D_ENGINE_MAIN_SCENE_H +#endif//INC_2D_ENGINE_MAIN_SCENE_H diff --git a/Scenes/orth_scene.cpp b/Scenes/orth_scene.cpp index 472454f..fae00b0 100644 --- a/Scenes/orth_scene.cpp +++ b/Scenes/orth_scene.cpp @@ -3,15 +3,15 @@ // #include "orth_scene.h" -#include "logging.h" -#include "glm.hpp" -#include "gtc/matrix_transform.hpp" #include "Camera.h" -#include "glad/glad.h" -#include "PhysicsEngine.h" #include "CollisionEngine.h" -#include "DebugRendering.h" #include "DebugRendering/DebugBox.h" +#include "DebugRendering/DebugLine.h" +#include "PhysicsEngine.h" +#include "glad/glad.h" +#include "glm.hpp" +#include "gtc/matrix_transform.hpp" +#include "logging.h" static DebugBox *box; void orth_scene::Init(Camera *camera) { @@ -44,12 +44,12 @@ void orth_scene::Init(Camera *camera) { } void orth_scene::Update(double deltaTime) { -// std::cout << "orth_scene::update()" << std::endl; + // std::cout << "orth_scene::update()" << std::endl; // create transformations - glm::mat4 view = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first - glm::mat4 projection = glm::mat4(1.0f); + glm::mat4 view = glm::mat4(1.0f);// make sure to initialize matrix to identity matrix first + glm::mat4 projection = glm::mat4(1.0f); projection = glm::ortho((storage->window.width / 2.0f), -(storage->window.width / 2.0f), -(storage->window.height / 2.0f), (storage->window.height / 2.0f), @@ -80,7 +80,7 @@ void orth_scene::Update(double deltaTime) { entity->position.y = -(storage->window.height / 2); } -// entity->scale = glm::vec3(camera->fov * 7, 2.1f, 2.1f); + // entity->scale = glm::vec3(camera->fov * 7, 2.1f, 2.1f); // And now im finally drawing the frame, if drew the frame // before the collision we would see the blocks jittering and "glitching" up and down above y 0 @@ -91,7 +91,7 @@ void orth_scene::Update(double deltaTime) { // Render UI Elements { -// shaders[1]->apply(); + // shaders[1]->apply(); draw_debug(); } } diff --git a/include/Camera.h b/include/Camera.h index 3dda026..105b647 100644 --- a/include/Camera.h +++ b/include/Camera.h @@ -11,12 +11,11 @@ #define DEFAULT_SENSITIVITY 0.1f #define DEFAULT_ZOOM 45.0f +#include "Vector.h" #include "glm.hpp" #include "gtc/matrix_transform.hpp" #include "gtc/type_ptr.hpp" #include "logging.h" -#include "vec3.hpp" - #include @@ -79,18 +78,21 @@ class Camera { void HandleKeyboard(CameraMovement direction, double delta_time, bool sprinting = false) { float velocity = this->movement_speed * delta_time * (sprinting ? this->sprint_speed : 1.); + glm::vec3 move_by = glm::vec3(0.0f, 0.0f, 0.0f); if (direction == FORWARD) { - position += front * velocity; + glm::vec3 t = front * velocity; + move_by += t; } if (direction == BACKWARD) { - position -= front * velocity; + move_by -= (front * velocity); } if (direction == LEFT) { - position -= right * velocity; + move_by -= (right * velocity); } if (direction == RIGHT) { - position += right * velocity; + move_by += (right * velocity); } + this->position += move_by; } void HandleMouseMovement(float x_offset, float y_offset) { @@ -143,7 +145,7 @@ class Camera { // front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); this->front = glm::normalize(front); - this->right = glm::normalize(glm::cross(this->front, this->global_up)); + this->right = glm::normalize(glm::cross(this->global_up, this->front)); this->up = glm::normalize(glm::cross(this->right, this->front)); } }; diff --git a/include/Entity_t.h b/include/Entity_t.h index f36934c..ae62dd7 100644 --- a/include/Entity_t.h +++ b/include/Entity_t.h @@ -6,14 +6,15 @@ #define INC_2D_ENGINE_ENTITY_T_H -#include "vec3.hpp" #include "glad/glad.h" #include "glm.hpp" #include "gtc/matrix_transform.hpp" #include "logging.h" +#include "vec3.hpp" //#include "PhysicsEngine.h" #include "Shader.h" +#include "Vector.h" class PhysicsEngine; class Entity_t { @@ -22,20 +23,20 @@ class Entity_t { public: double timer; - Shader* shader; + Shader *shader; class Physics { public: bool enabled = false; - PhysicsEngine* engine; + PhysicsEngine *engine; } physics; glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 rotation = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f); - Entity_t(Shader* shader); - Entity_t(Shader* shader, glm::vec3 position, glm::vec3 rotation, glm::vec3 scale); + Entity_t(Shader *shader); + Entity_t(Shader *shader, glm::vec3 position, glm::vec3 rotation, glm::vec3 scale); ~Entity_t(); @@ -47,4 +48,4 @@ class Entity_t { }; -#endif //INC_2D_ENGINE_ENTITY_T_H +#endif//INC_2D_ENGINE_ENTITY_T_H diff --git a/include/Vector.h b/include/Vector.h new file mode 100644 index 0000000..18667a2 --- /dev/null +++ b/include/Vector.h @@ -0,0 +1,43 @@ +// +// Created by Conni Bilham on 10/07/2023. +// + +#ifndef INC_2D_ENGINE_VECTOR_H +#define INC_2D_ENGINE_VECTOR_H + +class Vector { + +public: + double x, y, z; + + Vector(double x, double y, double z); + Vector(double x, double y); + Vector(double x); + Vector(); + + template + Vector operator+(T &other); + + template + Vector operator-(T &other); + + template + Vector operator*(const T &other) const; + + template + Vector operator/(T &other); + + + bool operator==(const Vector &other); + bool operator!=(const Vector &other); + + double magnitude(); + Vector normalize(); + double dot(const Vector &other); + Vector cross(const Vector &other); + + Vector direction(Vector &other); +}; + + +#endif//INC_2D_ENGINE_VECTOR_H diff --git a/include/vector.h b/include/vector.h deleted file mode 100644 index fcc288f..0000000 --- a/include/vector.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// Created by Conni Bilham on 10/07/2023. -// - -#ifndef INC_2D_ENGINE_VECTOR_H -#define INC_2D_ENGINE_VECTOR_H - -class vector { - -public: - double x, y, z; - - vector(double x, double y, double z); - vector(double x, double y); - vector(double x); - vector(); - - vector operator+(const vector& other) const; - vector operator-(const vector& other) const; - vector operator*(const vector& other) const; - vector operator/(const vector& other) const; - - vector operator+(const double& other); - vector operator-(const double& other); - vector operator*(const double& other); - vector operator/(const double& other); - - vector operator+=(const vector& other); - vector operator-=(const vector& other); - vector operator*=(const vector& other); - vector operator/=(const vector& other); - - vector operator+=(const double& other); - vector operator-=(const double& other); - vector operator*=(const double& other); - vector operator/=(const double& other); - - bool operator==(const vector& other); - bool operator!=(const vector& other); - - double magnitude(); - vector normalize(); - double dot(const vector& other); - vector cross(const vector& other); - - vector direction(const vector& other); -}; - - -#endif //INC_2D_ENGINE_VECTOR_H diff --git a/src/DebugRendering/DebugBox.cpp b/src/DebugRendering/DebugBox.cpp index 1e0df9b..bf317bd 100644 --- a/src/DebugRendering/DebugBox.cpp +++ b/src/DebugRendering/DebugBox.cpp @@ -2,7 +2,6 @@ // Created by Conni Bilham on 28/08/2023. // -#include #include "DebugRendering/DebugBox.h" #include "glad/glad.h" @@ -24,8 +23,7 @@ void DebugBox::load() { start.x, start.y, 0.0f, end.x, start.y, 0.0f, end.x, end.y, 0.0f, - start.x, end.y, 0.0f - }; + start.x, end.y, 0.0f}; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); @@ -38,7 +36,7 @@ void DebugBox::load() { glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // Set vertex attributes - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*) nullptr); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *) nullptr); glEnableVertexAttribArray(0); // Unbind VBO @@ -56,8 +54,7 @@ void DebugBox::draw() { start.x, start.y, 0.0f, end.x, start.y, 0.0f, end.x, end.y, 0.0f, - start.x, end.y, 0.0f - }; + start.x, end.y, 0.0f}; // Bind VBO glBindBuffer(GL_ARRAY_BUFFER, VBO); diff --git a/src/Entity_t.cpp b/src/Entity_t.cpp index 6c0856c..56a47e1 100644 --- a/src/Entity_t.cpp +++ b/src/Entity_t.cpp @@ -5,7 +5,7 @@ #include "Entity_t.h" -Entity_t::Entity_t(Shader* shader) { +Entity_t::Entity_t(Shader *shader) { this->shader = shader; load(); } @@ -15,7 +15,7 @@ Entity_t::~Entity_t() { glDeleteBuffers(1, &VBO); } -Entity_t::Entity_t(Shader* shader, glm::vec3 position, glm::vec3 rotation, glm::vec3 scale) { +Entity_t::Entity_t(Shader *shader, glm::vec3 position, glm::vec3 rotation, glm::vec3 scale) { this->shader = shader; this->position = position; @@ -71,15 +71,15 @@ void Entity_t::load() { }; // unsigned int indices[] = { // note that we start from 0! -// 0, 1, 3, // first triangle -// 1, 2, 3 // second triangle -// }; + // 0, 1, 3, // first triangle + // 1, 2, 3 // second triangle + // }; glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); -// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glGenBuffers(1, &VBO); @@ -87,7 +87,7 @@ void Entity_t::load() { glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)nullptr); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *) nullptr); glEnableVertexAttribArray(0); // color attribute @@ -97,22 +97,23 @@ void Entity_t::load() { glBindVertexArray(0); // // Set vertex attribute pointers -// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); -// glEnableVertexAttribArray(0); + // glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); + // glEnableVertexAttribArray(0); -// glUseProgram(shader_program_id); -// glBindVertexArray(VAO); + // glUseProgram(shader_program_id); + // glBindVertexArray(VAO); } void Entity_t::draw() { // Apply shader -// glUseProgram(shader->id); + // glUseProgram(shader->id); glBindVertexArray(VAO); glm::mat4 model = glm::mat4(1.0f); model = glm::translate(model, position); - if(rotation.x != 0 || rotation.y != 0 || rotation.z != 0) { + if (rotation.x != 0 || rotation.y != 0 || rotation.z != 0) { auto normalized = glm::normalize(rotation); + model = glm::rotate(model, glm::radians(glm::length(rotation)), normalized); } model = glm::scale(model, scale); @@ -122,7 +123,19 @@ void Entity_t::draw() { glDrawArrays(GL_TRIANGLES, 0, 36); - + // auto cnt = 0; + // for (int x = 0; x < 230; ++x) { + // for (int y = 0; y < 80; ++y) { + // for (int z = 0; z < 35; ++z) { + // ++cnt; + // glm::vec3 offset = glm::vec3(x, y, z); + // glUniform3fv(glGetUniformLocation(shader->id, "offset"), 1, &offset[0]); + // glDrawArrays(GL_TRIANGLES, 0, 36); + // } + // } + // } + // logging::debug("Entity_t::draw() - instancing " + std::to_string(cnt) + " cubes"); + glBindVertexArray(0); } void Entity_t::init() { diff --git a/src/PhysicsEngine.cpp b/src/PhysicsEngine.cpp index e364515..f77abc6 100644 --- a/src/PhysicsEngine.cpp +++ b/src/PhysicsEngine.cpp @@ -11,22 +11,22 @@ PhysicsEngine::PhysicsEngine(Entity_t *entity) { } void PhysicsEngine::ApplyPhysics(double deltaTime) { -// logging::verbose("PhysicsEngine::ApplyPhysics()"); + // logging::verbose("PhysicsEngine::ApplyPhysics()"); - auto* acceleration = &this->entity->physics.engine->acceleration; - auto* velocity = &this->entity->physics.engine->velocity; - if(!this->entity->physics.enabled) + auto *acceleration = &this->entity->physics.engine->acceleration; + auto *velocity = &this->entity->physics.engine->velocity; + if (!this->entity->physics.enabled) return; acceleration->y = G; // Hate this but glm::vec3 doesn't have operators setup correctly - velocity->x += acceleration->x * (float)deltaTime; - velocity->y += acceleration->y * (float)deltaTime; - velocity->z += acceleration->z * (float)deltaTime; + velocity->x += acceleration->x * (float) deltaTime; + velocity->y += acceleration->y * (float) deltaTime; + velocity->z += acceleration->z * (float) deltaTime; // Hate this but glm::vec3 doesn't have operators setup correctly this->entity->position.x += velocity->x; this->entity->position.y += velocity->y; this->entity->position.z += velocity->z; -} \ No newline at end of file +} diff --git a/src/Vector.cpp b/src/Vector.cpp new file mode 100644 index 0000000..bac9bf1 --- /dev/null +++ b/src/Vector.cpp @@ -0,0 +1,98 @@ +// +// Created by Conni Bilham on 10/07/2023. +// + +#include "Vector.h" +#include + +Vector::Vector(double x, double y, double z) { + this->x = x; + this->y = y; + this->z = z; +} + +Vector::Vector(double x, double y) { + this->x = x; + this->y = y; + this->z = 0; +} + +Vector::Vector(double x) { + this->x = x; + this->y = 0; + this->z = 0; +} + +Vector::Vector() { + this->x = 0; + this->y = 0; + this->z = 0; +} + +template +Vector Vector::operator+(T &other) { + return { + this->x + other.x, + this->y + other.y, + this->z + other.z}; +} + +template +Vector Vector::operator-(T &other) { + return { + this->x - other.x, + this->y - other.y, + this->z - other.z}; +} + +template +Vector Vector::operator*(const T &other) const { + return { + this->x * other.x, + this->y * other.y, + this->z * other.z}; +} + +template +Vector Vector::operator/(T &other) { + return { + this->x / other.x, + this->y / other.y, + this->z / other.z}; +} + + +bool Vector::operator==(const Vector &other) { + return this->x == other.x && this->y == other.y && this->z == other.z; +} + +bool Vector::operator!=(const Vector &other) { + return this->x != other.x || this->y != other.y || this->z != other.z; +} + +double Vector::magnitude() { + return sqrt(pow(this->x, 2) + pow(this->y, 2) + pow(this->z, 2)); +} + +Vector Vector::normalize() { + double mag = this->magnitude(); + return { + this->x / mag, + this->y / mag, + this->z / mag}; +} + +double Vector::dot(const Vector &other) { + return this->x * other.x + this->y * other.y + this->z * other.z; +} + +Vector Vector::cross(const Vector &other) { + return { + this->y * other.z - this->z * other.y, + this->z * other.x - this->x * other.z, + this->x * other.y - this->y * other.x}; +} + +Vector Vector::direction(Vector &other) { + return (other - *this); +} diff --git a/src/logging.cpp b/src/logging.cpp index 6a8bd23..4ace4fd 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -2,44 +2,44 @@ // Created by Conni Bilham on 10/07/2023. // -#define RESET "\033[0m" -#define BLACK "\033[30m" /* Black */ -#define RED "\033[31m" /* Red */ -#define GREEN "\033[32m" /* Green */ -#define YELLOW "\033[33m" /* Yellow */ -#define BLUE "\033[34m" /* Blue */ -#define MAGENTA "\033[35m" /* Magenta */ -#define CYAN "\033[36m" /* Cyan */ -#define WHITE "\033[37m" /* White */ -#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ -#define BOLDRED "\033[1m\033[31m" /* Bold Red */ -#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ -#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ -#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ -#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ -#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ -#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ -#include #include "../include/logging.h" +#include -void logging::log(const std::string& message) { +void logging::log(const std::string &message) { auto c_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::cout << BOLDWHITE << "[" << std::put_time(std::localtime(&c_time), "%F %T") << "] " << RESET << message << std::endl; } -void logging::info(const std::string& message) { +void logging::info(const std::string &message) { log(GREEN + std::string("INFO: ") + RESET + message); } -void logging::verbose(const std::string& message) { +void logging::verbose(const std::string &message) { log(MAGENTA + std::string("VERBOSE: ") + RESET + message); } -void logging::error(const std::string& message) { +void logging::error(const std::string &message) { log(RED + std::string("ERROR: ") + RESET + message); } -void logging::debug(const std::string& message) { +void logging::debug(const std::string &message) { log(BLUE + std::string("DEBUG: ") + RESET + message); } \ No newline at end of file diff --git a/src/vector.cpp b/src/vector.cpp deleted file mode 100644 index 0f46c81..0000000 --- a/src/vector.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// -// Created by Conni Bilham on 10/07/2023. -// - -#include -#include "vector.h" - -vector::vector(double x, double y, double z) { - this->x = x; - this->y = y; - this->z = z; -} - -vector::vector(double x, double y) { - this->x = x; - this->y = y; - this->z = 0; -} - -vector::vector(double x) { - this->x = x; - this->y = 0; - this->z = 0; -} - -vector::vector() { - this->x = 0; - this->y = 0; - this->z = 0; -} - -vector vector::operator+(const vector& other) const { - return { - this->x + other.x, - this->y + other.y, - this->z + other.z - }; -} - -vector vector::operator-(const vector& other) const { - return { - this->x - other.x, - this->y - other.y, - this->z - other.z - }; -} - -vector vector::operator*(const vector& other) const { - return { - this->x * other.x, - this->y * other.y, - this->z * other.z - }; -} - -vector vector::operator/(const vector& other) const { - return { - this->x / other.x, - this->y / other.y, - this->z / other.z - }; -} - -vector vector::operator+(const double& other) { - return { - this->x + other, - this->y + other, - this->z + other - }; -} - -vector vector::operator-(const double& other) { - return { - this->x - other, - this->y - other, - this->z - other - }; -} - -vector vector::operator*(const double& other) { - return { - this->x * other, - this->y * other, - this->z * other - }; -} - -vector vector::operator/(const double& other) { - return { - this->x / other, - this->y / other, - this->z / other - }; -} - -vector vector::operator+=(const vector& other) { - this->x += other.x; - this->y += other.y; - this->z += other.z; - return *this; -} - -vector vector::operator-=(const vector& other) { - this->x -= other.x; - this->y -= other.y; - this->z -= other.z; - return *this; -} - -vector vector::operator*=(const vector& other) { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - return *this; -} - -vector vector::operator/=(const vector& other) { - this->x /= other.x; - this->y /= other.y; - this->z /= other.z; - return *this; -} - -vector vector::operator+=(const double& other) { - this->x += other; - this->y += other; - this->z += other; - return *this; -} - -vector vector::operator-=(const double& other) { - this->x -= other; - this->y -= other; - this->z -= other; - return *this; -} - -vector vector::operator*=(const double& other) { - this->x *= other; - this->y *= other; - this->z *= other; - return *this; -} - -vector vector::operator/=(const double& other) { - this->x /= other; - this->y /= other; - this->z /= other; - return *this; -} - -bool vector::operator==(const vector& other) { - return this->x == other.x && this->y == other.y && this->z == other.z; -} - -bool vector::operator!=(const vector& other) { - return this->x != other.x || this->y != other.y || this->z != other.z; -} - -double vector::magnitude() { - return sqrt(pow(this->x, 2) + pow(this->y, 2) + pow(this->z, 2)); -} - -vector vector::normalize() { - double mag = this->magnitude(); - return { - this->x / mag, - this->y / mag, - this->z / mag - }; -} - -double vector::dot(const vector& other) { - return this->x * other.x + this->y * other.y + this->z * other.z; -} - -vector vector::cross(const vector& other) { - return { - this->y * other.z - this->z * other.y, - this->z * other.x - this->x * other.z, - this->x * other.y - this->y * other.x - }; -} - -vector vector::direction(const vector& other) { - return (other - *this).normalize(); -} \ No newline at end of file