From 4c16cca26bdae09525c04665b536da98beb4c76f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 26 May 2017 23:43:10 +0100 Subject: Creating matrix --- .dir-locals.el | 18 ----- CMakeLists.txt | 19 ++---- include/YAGE/Math/matrix.hpp | 32 +++++++++ include/YAGE/Math/vector.hpp | 151 ----------------------------------------- include/YAGE/Math/vector2d.hpp | 20 ------ test/double_size.cpp | 11 --- test/matrix_test.cpp | 13 ++++ test/vector2d_test.cpp | 15 ---- 8 files changed, 51 insertions(+), 228 deletions(-) create mode 100644 include/YAGE/Math/matrix.hpp delete mode 100644 include/YAGE/Math/vector.hpp delete mode 100644 include/YAGE/Math/vector2d.hpp delete mode 100644 test/double_size.cpp create mode 100644 test/matrix_test.cpp delete mode 100644 test/vector2d_test.cpp diff --git a/.dir-locals.el b/.dir-locals.el index 58153f52..4afe10c5 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,34 +1,16 @@ ((nil . ((company-clang-arguments . ("-I../include/YAGE/" "-I../../include/YAGE/" "-I../../../include/YAGE/" - "-I../include/YAGE/Physics/" - "-I../../include/YAGE/Physics/" - "-I../../../include/YAGE/Physics/" - "-I../include/YAGE/Math/" - "-I../../include/YAGE/Math/" - "-I../../../include/YAGE/Math/" "-I/usr/include/" "-I/usr/include/SDL2/")) (company-c-headers-path-user . ("../include/YAGE/" "../../include/YAGE/" "../../../include/YAGE/" - "../include/YAGE/Physics/" - "../../include/YAGE/Physics/" - "../../../include/YAGE/Physics/" - "../include/YAGE/Math/" - "../../include/YAGE/Math/" - "../../../include/YAGE/Math/" "/usr/include/" "/usr/include/SDL2/")) (flycheck-clang-include-path . ("../include/YAGE/" "../../include/YAGE/" "../../../include/YAGE/" - "../include/YAGE/Physics/" - "../../include/YAGE/Physics/" - "../../../include/YAGE/Physics/" - "../include/YAGE/Math/" - "../../include/YAGE/Math/" - "../../../include/YAGE/Math/" "/usr/include/" "/usr/include/SDL2/"))))) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2309db4a..d30bc4ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ set(YAGE_SOURCES ${PROJECT_SOURCE_DIR}/src/spritebatch.cpp ${PROJECT_SOURCE_DIR}/src/sprite.cpp ${PROJECT_SOURCE_DIR}/src/texturecache.cpp - ${PROJECT_SOURCE_DIR}/src/vector2d.cpp +# ${PROJECT_SOURCE_DIR}/src/vector2d.cpp ${PROJECT_SOURCE_DIR}/src/window.cpp) @@ -64,21 +64,14 @@ target_link_libraries(rigid_body_test ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES}) -add_executable(double_size - ${YAGE_TEST_DIR}/double_size.cpp) -target_link_libraries(double_size - ${YAGE_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARIES}) - -add_executable(vector2d_test - ${YAGE_TEST_DIR}/vector2d_test.cpp) -target_link_libraries(vector2d_test +add_executable(matrix_test + ${YAGE_TEST_DIR}/matrix_test.cpp) +target_link_libraries(matrix_test ${YAGE_LIBRARIES} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES}) +# enable tests enable_testing() add_test(RigidBodyTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rigid_body_test) -add_test(DoubleSize ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/double_size) -add_test(Vector2DTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/double_size) +add_test(MatrixTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/matrix_test) diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp new file mode 100644 index 00000000..b6807c09 --- /dev/null +++ b/include/YAGE/Math/matrix.hpp @@ -0,0 +1,32 @@ +#ifndef YAGE_MATH_MATRIX_HPP +#define YAGE_MATH_MATRIX_HPP + +namespace yage +{ + +template class Matrix +{ +private: + Type x[Cols][Rows]; + +public: + Matrix() + { + for(int i=0; i -#include - -namespace yage -{ - -class Vector -{ -protected: - std::vector members_; - -public: - Vector()=delete; - virtual ~Vector() {} - - inline long double &operator[](std::size_t index) - { - return members_[index]; - } - - inline const long double &operator[](std::size_t index) const - { - return members_[index]; - } - - inline Vector operator=(Vector other) - { - this->members_=other.members_; - return *this; - } - - inline Vector &operator+() - { - return *this; - } - - inline Vector &operator-() - { - for(auto &i : members_) - { - i=-i; - } - return *this; - } - - inline Vector &operator+=(const Vector &other) - { - for(std::size_t i=0; i mem; - for(auto i : members_) - { - mem.emplace_back(i+other); - } - return Vector(mem); - } - - inline Vector operator-(long double other) const - { - std::vector mem; - for(auto i : members_) - { - mem.emplace_back(i-other); - } - return Vector(mem); - } - - inline Vector operator*(long double other) const - { - std::vector mem; - for(auto i : members_) - { - mem.emplace_back(i*other); - } - return Vector(mem); - } - - inline Vector operator/(long double other) const - { - std::vector mem; - for(auto i : members_) - { - mem.emplace_back(i/other); - } - return Vector(mem); - } - - friend inline std::ostream &operator<<(std::ostream &os, const Vector &object) - { - os<<"("; - for(std::size_t i=0; i &members) : members_(members) {} -}; - -} // yage - -#endif diff --git a/include/YAGE/Math/vector2d.hpp b/include/YAGE/Math/vector2d.hpp deleted file mode 100644 index 1a6d2856..00000000 --- a/include/YAGE/Math/vector2d.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef YAGE_MATH_VECTOR2D_HPP -#define YAGE_MATH_VECTOR2D_HPP - -#include "vector.hpp" - -namespace yage -{ - -class Vector2D : public Vector -{ -public: - Vector2D(long double x=0.L, long double y=0.L); - - long double getX() const; - long double getY() const; -}; - -} // yage - -#endif diff --git a/test/double_size.cpp b/test/double_size.cpp deleted file mode 100644 index 25c7cef7..00000000 --- a/test/double_size.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int main() -{ - std::cout<<"Size of double: "< 8) - return 0; - return 1; -} diff --git a/test/matrix_test.cpp b/test/matrix_test.cpp new file mode 100644 index 00000000..8f09ad38 --- /dev/null +++ b/test/matrix_test.cpp @@ -0,0 +1,13 @@ +#include "Math/matrix.hpp" + +#include + +int main() +{ + yage::Matrix matrix; + + int x=matrix.get(5, 2); + + std::cout<<"at: "< - -int main() -{ - yage::Vector2D v; - yage::Vector2D v2(1, 5); - - v=v2+2; - - std::cout<