diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ebd9f..ae77dfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ add_executable(tests_opengl src/DataHandling/Texture.h src/DataHandling/Model3D.cpp src/DataHandling/Model3D.h - src/types.h + src/Vectors.h src/KeyStateManager.cpp src/KeyStateManager.h) diff --git a/src/DataHandling/Model3D.h b/src/DataHandling/Model3D.h index 43010c5..94474a5 100644 --- a/src/DataHandling/Model3D.h +++ b/src/DataHandling/Model3D.h @@ -10,7 +10,7 @@ #include #include "GL/glut.h" -#include "types.h" +#include "Vectors.h" #include "Texture.h" class Model3D { diff --git a/src/KeyStateManager.h b/src/KeyStateManager.h index f7aedbd..6ab15ca 100644 --- a/src/KeyStateManager.h +++ b/src/KeyStateManager.h @@ -8,7 +8,7 @@ #include #include -#include "types.h" +#include "Vectors.h" /// Handles the key and mouse events from glut and keep their status up to date. diff --git a/src/types.h b/src/Vectors.h similarity index 78% rename from src/types.h rename to src/Vectors.h index a47d514..e9c5a5b 100644 --- a/src/types.h +++ b/src/Vectors.h @@ -2,10 +2,11 @@ // Created by trotfunky on 30/09/2019. // -#ifndef TESTS_OPENGL_TYPES_H -#define TESTS_OPENGL_TYPES_H +#ifndef TESTS_OPENGL_VECTORS_H +#define TESTS_OPENGL_VECTORS_H #include +#include /// Group of coordinates with the input operator overloaded. /// \tparam T Content of the vector @@ -15,6 +16,32 @@ struct CoordinatesVector { T coordinates[N]; + /// Computes the euclidean norm of the vector. + /// \return The magnitude. + double magnitude() + { + // TODO : Save magnitude if the vector has not been modified. + double sum_of_squares = 0; + for (unsigned int i = 0;i::value,void>::type + normalize() + { + double norm = magnitude(); + for (unsigned int i = 0;i typename std::enable_if::value,CoordinatesVector>::type @@ -67,6 +94,7 @@ struct CoordinatesVector } }; +// Define some specializations to add x,y,z references to the coordinates. template struct Vec2 : public CoordinatesVector @@ -133,4 +161,4 @@ typedef Vec3 Vec3i; typedef Vec3 Vec3f; -#endif //TESTS_OPENGL_TYPES_H +#endif //TESTS_OPENGL_VECTORS_H