aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.dir-locals.el18
-rw-r--r--CMakeLists.txt19
-rw-r--r--include/YAGE/Math/matrix.hpp32
-rw-r--r--include/YAGE/Math/vector.hpp151
-rw-r--r--include/YAGE/Math/vector2d.hpp20
-rw-r--r--test/double_size.cpp11
-rw-r--r--test/matrix_test.cpp13
-rw-r--r--test/vector2d_test.cpp15
8 files changed, 51 insertions, 228 deletions
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<typename Type, int Cols, int Rows> class Matrix
+{
+private:
+ Type x[Cols][Rows];
+
+public:
+ Matrix()
+ {
+ for(int i=0; i<Cols; ++i)
+ {
+ for(int j=0; j<Rows; ++j)
+ {
+ x[i][j]=5;
+ }
+ }
+ }
+
+ Type get(int i, int j) const
+ {
+ return x[i][j];
+ }
+};
+
+} // yage
+
+#endif
diff --git a/include/YAGE/Math/vector.hpp b/include/YAGE/Math/vector.hpp
deleted file mode 100644
index 5f3161df..00000000
--- a/include/YAGE/Math/vector.hpp
+++ /dev/null
@@ -1,151 +0,0 @@
-#ifndef YAGE_MATH_VECTOR_HPP
-#define YAGE_MATH_VECTOR_HPP
-
-#include <ostream>
-#include <vector>
-
-namespace yage
-{
-
-class Vector
-{
-protected:
- std::vector<long double> 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<members_.size(); ++i)
- {
- members_[i]+=other[i];
- }
- return *this;
- }
-
- inline Vector &operator-=(const Vector &other)
- {
- for(std::size_t i=0; i<members_.size(); ++i)
- {
- members_[i]-=other[i];
- }
- return *this;
- }
-
- inline Vector &operator*=(const Vector &other)
- {
- for(std::size_t i=0; i<members_.size(); ++i)
- {
- members_[i]*=other[i];
- }
- return *this;
- }
-
- inline Vector operator+(Vector other) const
- {
- Vector v(members_);
- return v+=other;
- }
-
- inline Vector operator-(const Vector &other) const
- {
- Vector v(members_);
- return v-=other;
- }
-
- inline Vector operator*(const Vector &other) const
- {
- Vector v(members_);
- return v*=other;
- }
-
- inline Vector operator+(long double other) const
- {
- std::vector<long double> mem;
- for(auto i : members_)
- {
- mem.emplace_back(i+other);
- }
- return Vector(mem);
- }
-
- inline Vector operator-(long double other) const
- {
- std::vector<long double> mem;
- for(auto i : members_)
- {
- mem.emplace_back(i-other);
- }
- return Vector(mem);
- }
-
- inline Vector operator*(long double other) const
- {
- std::vector<long double> mem;
- for(auto i : members_)
- {
- mem.emplace_back(i*other);
- }
- return Vector(mem);
- }
-
- inline Vector operator/(long double other) const
- {
- std::vector<long double> 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<object.members_.size()-1; ++i)
- {
- os<<object.members_[i]<<", ";
- }
- os<<object.members_[object.members_.size()-1]<<")";
- return os;
- }
-
-protected:
- Vector(const std::vector<long double> &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 <iostream>
-
-int main()
-{
- std::cout<<"Size of double: "<<sizeof(double)<<'\n';
- std::cout<<"Size of long double: "<<sizeof(long double)<<'\n';
-
- if(sizeof(long 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 <iostream>
+
+int main()
+{
+ yage::Matrix<double, 10, 10> matrix;
+
+ int x=matrix.get(5, 2);
+
+ std::cout<<"at: "<<x<<'\n';
+ return 0;
+}
diff --git a/test/vector2d_test.cpp b/test/vector2d_test.cpp
deleted file mode 100644
index 2eb00de4..00000000
--- a/test/vector2d_test.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "vector2d.hpp"
-
-#include <iostream>
-
-int main()
-{
- yage::Vector2D v;
- yage::Vector2D v2(1, 5);
-
- v=v2+2;
-
- std::cout<<v<<'\n';
-
- return 0;
-}