From 1eff849ad34d69815ad68f9c88d2ea94c178d5e0 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 21 Aug 2017 20:35:36 +0100 Subject: Testing out doxygen on github --- include/YAGE/Math/matrix.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 860a250c..9f7e005f 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -31,7 +31,7 @@ namespace yage { template class Matrix; -/** \internal Namespace for internal details. +/** @internal Namespace for internal details. * * Detail Namespace * ================ @@ -40,7 +40,7 @@ class Matrix; */ namespace detail { -/** \internal Internal Row class used by the Matrix class to return the +/** @internal Internal Row class used by the Matrix class to return the * internal data structure of the Matrix. * * Row -- cgit From 6a8bc8a624e2c7777d57c3363dfe8c8dadeff84f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 21 Aug 2017 20:38:54 +0100 Subject: Highlight didn't work --- include/YAGE/Math/matrix.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 9f7e005f..860a250c 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -31,7 +31,7 @@ namespace yage { template class Matrix; -/** @internal Namespace for internal details. +/** \internal Namespace for internal details. * * Detail Namespace * ================ @@ -40,7 +40,7 @@ class Matrix; */ namespace detail { -/** @internal Internal Row class used by the Matrix class to return the +/** \internal Internal Row class used by the Matrix class to return the * internal data structure of the Matrix. * * Row -- cgit From 4b95a1ac4265e2f51bf78969ce259f0f8b91fd91 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 21 Aug 2017 20:55:02 +0100 Subject: Adding documentation to matrix class --- include/YAGE/Math/matrix.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 860a250c..52536c17 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -121,14 +121,15 @@ public: return colMatrix; } - // iterator support for begin + /// iterator support for begin typename std::vector::iterator begin() { return data_.begin(); } - // iterator support for end + /// iterator support for end typename std::vector::iterator end() { return data_.end(); } - // prints out the matrix, but can also be implemented by other classes to - // print data differently + /** prints out the matrix, but can also be implemented by other classes to + * print data differently + */ virtual std::string toString() const { std::stringstream ss; ss << '['; -- cgit From 56b5466f014d9f7c3662544713bd53670cd8e32f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 23 Aug 2017 20:33:34 +0100 Subject: Applied modernize rules and fixed build. Applied clang-tidy modernize rules and fixed the CMakeLists.txt file so that it also linked against the SDL2 library. --- include/YAGE/Physics/body.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index fab28fc1..efeedb64 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -46,7 +46,7 @@ public: protected: // protected constructor to initialize member variables - Body(const Vector2d& position = Vector2d(0, 0), double mass = 1, const Vector2d& velocity = Vector2d(0, 0), bool gravity = false); + Body(Vector2d position = Vector2d(0, 0), double mass = 1, Vector2d velocity = Vector2d(0, 0), bool gravity = false); }; } // namespace yage -- cgit From bc982b84ec3e1085c440e4d5ea1de597aee63565 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 23 Aug 2017 20:44:42 +0100 Subject: Applied more fixes on headers. Passed all headers through clang-tidy and modernize rules. --- include/YAGE/Math/matrix.hpp | 4 ++-- include/YAGE/Physics/particlebody.hpp | 4 ++-- include/YAGE/Physics/rectanglecollider.hpp | 4 ++-- include/YAGE/vertex.hpp | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 52536c17..999d4274 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -273,7 +273,7 @@ public: const Type& operator[](int col) const { return this->data_[col]; } - virtual std::string toString() const { + std::string toString() const override override override { std::stringstream ss; ss << "["; for (std::size_t i = 0; i < this->data_.size() - 1; ++i) { @@ -311,7 +311,7 @@ public: }; /// Definition of a 2D vector. -typedef Vector2 Vector2d; +using Vector2d = Vector2; /** Namespace containing functions that operate on matrices. */ namespace matrix { diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp index ff8b3b85..7894e301 100644 --- a/include/YAGE/Physics/particlebody.hpp +++ b/include/YAGE/Physics/particlebody.hpp @@ -22,8 +22,8 @@ public: bool gravity = true); // apply a force to the rigid body - virtual void applyForce(const Vector2d& force); - virtual void update(); + void applyForce(const Vector2d& force) override override; + void update() override override; }; } // yage diff --git a/include/YAGE/Physics/rectanglecollider.hpp b/include/YAGE/Physics/rectanglecollider.hpp index 7f9dd7f7..b66664a0 100644 --- a/include/YAGE/Physics/rectanglecollider.hpp +++ b/include/YAGE/Physics/rectanglecollider.hpp @@ -19,8 +19,8 @@ class RectangleCollider : public Collider { public: RectangleCollider(const glm::vec2& position, const glm::vec2& size); - virtual bool collides(const Collider& collider) const; - virtual bool inside(const glm::vec2& point) const; + bool collides(const Collider& collider) const override; + bool inside(const glm::vec2& point) const override; }; } // yage diff --git a/include/YAGE/vertex.hpp b/include/YAGE/vertex.hpp index d3355b11..1026253e 100644 --- a/include/YAGE/vertex.hpp +++ b/include/YAGE/vertex.hpp @@ -17,7 +17,7 @@ struct Position { float x; float y; - Position() {} + Position() = default; Position(float x_, float y_) : x(x_), y(y_) {} }; @@ -28,7 +28,7 @@ struct Color { GLubyte b; GLubyte a; - Color() {} + Color() = default; Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) : r(r_), g(g_), b(b_), a(a_) {} @@ -38,7 +38,7 @@ struct UV { float u; float v; - UV() {} + UV() = default; UV(float u_, float v_) : u(u_), v(v_) {} }; @@ -48,7 +48,7 @@ struct Vertex { Color color; UV uv; - Vertex() {} + Vertex() = default; Vertex(const Position& position_, const Color& color_, const UV& uv_) : position(position_), color(color_), uv(uv_) {} -- cgit From b4d99eb15e6337c22c011acaca25b0ce8e946e3d Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 23 Aug 2017 23:08:52 +0100 Subject: Improving settings and chaning \ to @. --- include/YAGE/Math/matrix.hpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 999d4274..866b46e2 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -6,15 +6,17 @@ * ---------------------------------------------------------------------------- */ -/** \file matrix.hpp Templated matrix class - * - * Matrix - * ====== - * - * This is a very general matrix class that can then be inherited by - * vectors and other similar data structures to minimize code - * density. - */ +/// @file + +/** Templated matrix class + * + * Matrix + * ====== + * + * This is a very general matrix class that can then be inherited by + * vectors and other similar data structures to minimize code + * density. + */ #ifndef YAGE_MATH_MATRIX_HPP #define YAGE_MATH_MATRIX_HPP @@ -31,7 +33,7 @@ namespace yage { template class Matrix; -/** \internal Namespace for internal details. +/** @internal Namespace for internal details. * * Detail Namespace * ================ @@ -40,7 +42,7 @@ class Matrix; */ namespace detail { -/** \internal Internal Row class used by the Matrix class to return the +/** @internal Internal Row class used by the Matrix class to return the * internal data structure of the Matrix. * * Row -- cgit From 2dbcbe3575134b3c6267b1a396b57080067ed9da Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 23 Aug 2017 23:19:43 +0100 Subject: Fixed autofix issues. --- include/YAGE/Math/matrix.hpp | 2 +- include/YAGE/Physics/particlebody.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 866b46e2..e4583290 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -275,7 +275,7 @@ public: const Type& operator[](int col) const { return this->data_[col]; } - std::string toString() const override override override { + std::string toString() const override { std::stringstream ss; ss << "["; for (std::size_t i = 0; i < this->data_.size() - 1; ++i) { diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp index 7894e301..fd07512f 100644 --- a/include/YAGE/Physics/particlebody.hpp +++ b/include/YAGE/Physics/particlebody.hpp @@ -22,8 +22,8 @@ public: bool gravity = true); // apply a force to the rigid body - void applyForce(const Vector2d& force) override override; - void update() override override; + void applyForce(const Vector2d& force) override; + void update() override; }; } // yage -- cgit From 5403490b941f7c031bf1aafdb91b1098f69edbf2 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 24 Aug 2017 00:21:07 +0100 Subject: Running clang-format over everything. Edited formatting and ran it over all the files. --- include/YAGE/Math/matrix.hpp | 180 +++++++++++++++++------------ include/YAGE/Physics/README.org | 44 +++---- include/YAGE/Physics/body.hpp | 51 ++++---- include/YAGE/Physics/collider.hpp | 18 +-- include/YAGE/Physics/collisionbody.hpp | 8 +- include/YAGE/Physics/particlebody.hpp | 21 ++-- include/YAGE/Physics/rectanglecollider.hpp | 14 ++- include/YAGE/Physics/rigidbody.hpp | 12 +- include/YAGE/camera2d.hpp | 12 +- include/YAGE/glslprogram.hpp | 26 +++-- include/YAGE/imageloader.hpp | 10 +- include/YAGE/inputmanager.hpp | 1 - include/YAGE/iomanager.hpp | 6 +- include/YAGE/picopng.hpp | 10 +- include/YAGE/resourcemanager.hpp | 10 +- include/YAGE/sprite.hpp | 18 +-- include/YAGE/spritebatch.hpp | 35 +++--- include/YAGE/texture.hpp | 5 +- include/YAGE/texturecache.hpp | 10 +- include/YAGE/vertex.hpp | 24 ++-- include/YAGE/window.hpp | 20 ++-- include/YAGE/yage.hpp | 4 +- 22 files changed, 311 insertions(+), 228 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index e4583290..249edcc7 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -28,10 +28,10 @@ #include #include -namespace yage { +namespace yage +{ -template -class Matrix; +template class Matrix; /** @internal Namespace for internal details. * @@ -40,7 +40,8 @@ class Matrix; * * This is the namespace used for implementation detail. */ -namespace detail { +namespace detail +{ /** @internal Internal Row class used by the Matrix class to return the * internal data structure of the Matrix. @@ -50,27 +51,31 @@ namespace detail { * * Internal Row class to return a value in the row of the matrix. */ -template -class Row { +template class Row +{ private: - Matrix* parent_; + Matrix *parent_; int index_; public: - Row(Matrix* parent, int index) - : parent_(parent), index_(index) {} + Row(Matrix *parent, int index) + : parent_(parent), index_(index) + { + } - Type& operator[](int col) { + Type &operator[](int col) + { // the index is the y-position of the element in the matrix return parent_->data_[index_ * Cols + col]; } - const Type& operator[](int col) const { + const Type &operator[](int col) const + { return parent_->data_[index_ * Cols + col]; } }; -} // detail +} // detail /** Base Matrix class used by other similar classes. * @@ -80,8 +85,8 @@ public: * This is the base matrix class that can be used by all the other matrix * like data structures. */ -template -class Matrix { +template class Matrix +{ // friended with the row class so that it can access protected member data friend class detail::Row; @@ -92,7 +97,7 @@ protected: public: /// Initializes the size of the data_ vector Matrix() : data_(Rows * Cols) {} - Matrix(const std::vector& data) : data_(data) {} + Matrix(const std::vector &data) : data_(data) {} /// Returns the row size of the Matrix int rowSize() const { return Rows; } @@ -102,11 +107,12 @@ public: /** Return the row specified row as a Matrix with only one row * - * \param[in] row Row number to be returned + * @param row Row number to be returned * * Returns the row that is specified by the row variables. */ - Matrix<1, Cols, Type> getRow(int row) const { + Matrix<1, Cols, Type> getRow(int row) const + { Matrix<1, Cols, Type> rowMatrix; for (int i = 0; i < Cols; ++i) { rowMatrix[0][i] = data_[row][i]; @@ -115,7 +121,8 @@ public: } // returns the column in a column matrix - Matrix getCol(int col) const { + Matrix getCol(int col) const + { Matrix colMatrix; for (int i = 0; i < Rows; ++i) { colMatrix[i][0] = data_[i][col]; @@ -130,9 +137,10 @@ public: typename std::vector::iterator end() { return data_.end(); } /** prints out the matrix, but can also be implemented by other classes to - * print data differently - */ - virtual std::string toString() const { + * print data differently + */ + virtual std::string toString() const + { std::stringstream ss; ss << '['; for (int i = 0; i < Rows - 1; ++i) { @@ -150,17 +158,20 @@ public: return ss.str(); } - detail::Row operator[](int row) { + detail::Row operator[](int row) + { return detail::Row(this, row); } - detail::Row operator[](int row) const { - // TODO got to fix this - return detail::Row((Matrix*)this, + detail::Row operator[](int row) const + { + // @todo got to fix this + return detail::Row((Matrix *)this, row); } - Matrix& operator+=(const Matrix& rhs) { + Matrix &operator+=(const Matrix &rhs) + { std::vector out; out.reserve(data_.size()); std::transform(data_.begin(), data_.end(), rhs.data_.begin(), @@ -170,7 +181,8 @@ public: return *this; } - Matrix& operator-=(const Matrix& rhs) { + Matrix &operator-=(const Matrix &rhs) + { std::vector out; out.reserve(data_.size()); std::transform(data_.begin(), data_.end(), rhs.begin(), @@ -182,100 +194,121 @@ public: }; template -Matrix operator+(Matrix lhs, const Matrix& rhs) { +Matrix operator+(Matrix lhs, const Matrix &rhs) +{ lhs += rhs; return lhs; } template -Matrix operator-(Matrix lhs, const Matrix& rhs) { +Matrix operator-(Matrix lhs, const Matrix &rhs) +{ lhs -= rhs; return lhs; } template -Matrix operator+(Matrix lhs, const T& rhs) { - for (auto& data : lhs) { +Matrix operator+(Matrix lhs, const T &rhs) +{ + for (auto &data : lhs) { data += rhs; } return lhs; } template -Matrix operator+(const T& lhs, Matrix rhs) { - for (auto& data : rhs) { +Matrix operator+(const T &lhs, Matrix rhs) +{ + for (auto &data : rhs) { data += lhs; } return rhs; } template -Matrix operator-(Matrix lhs, const T& rhs) { - for (auto& data : lhs) { +Matrix operator-(Matrix lhs, const T &rhs) +{ + for (auto &data : lhs) { data -= rhs; } return lhs; } template -Matrix operator-(const T& lhs, Matrix rhs) { - for (auto& data : rhs) { +Matrix operator-(const T &lhs, Matrix rhs) +{ + for (auto &data : rhs) { data = lhs - data; } return rhs; } template -Matrix operator*(Matrix lhs, const T& rhs) { - for (auto& data : lhs) { +Matrix operator*(Matrix lhs, const T &rhs) +{ + for (auto &data : lhs) { data *= rhs; } return lhs; } template -Matrix operator*(const T& lhs, Matrix rhs) { - for (auto& data : rhs) { +Matrix operator*(const T &lhs, Matrix rhs) +{ + for (auto &data : rhs) { data *= lhs; } return rhs; } template -Matrix operator/(Matrix lhs, const T& rhs) { - for (auto& data : lhs) { +Matrix operator/(Matrix lhs, const T &rhs) +{ + for (auto &data : lhs) { data /= rhs; } return lhs; } template -bool operator==(const Matrix& lhs, const Matrix& rhs) { - for (int i = 0; i < M; ++i) - for (int j = 0; j < N; ++j) - if (lhs[i][j] != rhs[i][j]) return false; +bool operator==(const Matrix &lhs, const Matrix &rhs) +{ + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + if (lhs[i][j] != rhs[i][j]) { + return false; + } + } + } return true; } template -std::ostream& operator<<(std::ostream& os, const Matrix& mat) { +std::ostream &operator<<(std::ostream &os, const Matrix &mat) +{ return os << mat.toString(); } template -class Vector : public Matrix { +class Vector : public Matrix +{ public: Vector() : Matrix() {} - Vector(const Matrix& other) - : Matrix(other) {} - Vector(const std::vector& data) - : Matrix(data) {} + Vector(const Matrix &other) + : Matrix(other) + { + } + Vector(const std::vector &data) + : Matrix(data) + { + } - Type& operator[](int col) { return this->data_[col]; } + Type &operator[](int col) { return this->data_[col]; } - const Type& operator[](int col) const { return this->data_[col]; } + const Type &operator[](int col) const { return this->data_[col]; } - std::string toString() const override { + std::string toString() const override + { std::stringstream ss; ss << "["; for (std::size_t i = 0; i < this->data_.size() - 1; ++i) { @@ -290,40 +323,43 @@ public: * * Two dimensional vector class. */ -template -class Vector2 : public Vector<2, Type> { +template class Vector2 : public Vector<2, Type> +{ public: Vector2() : Vector<2, Type>() {} - Vector2(const std::vector& data) : Vector<2, Type>(data) {} + Vector2(const std::vector &data) : Vector<2, Type>(data) {} - Vector2(Type x, Type y) { + Vector2(Type x, Type y) + { this->data_[0] = x; this->data_[1] = y; } - Vector2(const Matrix<2, 1, Type>& other) : Vector<2, Type>(other) {} + Vector2(const Matrix<2, 1, Type> &other) : Vector<2, Type>(other) {} - Type& x() { return this->data_[0]; } + Type &x() { return this->data_[0]; } - const Type& x() const { return this->data_[0]; } + const Type &x() const { return this->data_[0]; } - Type& y() { return this->data_[1]; } + Type &y() { return this->data_[1]; } - const Type& y() const { return this->data_[1]; } + const Type &y() const { return this->data_[1]; } }; /// Definition of a 2D vector. using Vector2d = Vector2; /** Namespace containing functions that operate on matrices. */ -namespace matrix { +namespace matrix +{ /** Transposes a matrix and returns the result * * \param[in] m input matrix. */ template -Matrix transpose(const Matrix& m) { +Matrix transpose(const Matrix &m) +{ Matrix trans; for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { @@ -338,7 +374,8 @@ Matrix transpose(const Matrix& m) { * \param[in] m1,m2 Input matrices. */ template -T dot(const Matrix& m1, const Matrix& m2) { +T dot(const Matrix &m1, const Matrix &m2) +{ T sum = 0; for (int i = 0; i < R; ++i) { sum += m1[i][0] * m2[i][0]; @@ -353,7 +390,8 @@ T dot(const Matrix& m1, const Matrix& m2) { * Requires the two matrices to be compatible with multiplication. */ template -Matrix multiply(const Matrix& m1, const Matrix& m2) { +Matrix multiply(const Matrix &m1, const Matrix &m2) +{ if (N != P) { throw std::runtime_error( "Matrices don't have the right dimensions for multiplication"); @@ -370,8 +408,8 @@ Matrix multiply(const Matrix& m1, const Matrix& m2) { return res; } -} // matrix +} // matrix -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/README.org b/include/YAGE/Physics/README.org index 0a2a5066..0620cc93 100644 --- a/include/YAGE/Physics/README.org +++ b/include/YAGE/Physics/README.org @@ -1,23 +1,27 @@ -#+TITLE: README -#+DATE: <2017-04-17 Mon> -#+AUTHOR: -#+EMAIL: yannherklotz@yann-arch -#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline -#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t -#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t -#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t -#+CREATOR: Emacs 25.1.1 (Org mode 8.2.10) -#+DESCRIPTION: -#+EXCLUDE_TAGS: noexport -#+KEYWORDS: -#+LANGUAGE: en -#+SELECT_TAGS: export +#+ TITLE : README +#+ DATE : <2017 - 04 - 17 Mon> +#+ AUTHOR: +#+ EMAIL : yannherklotz @yann - arch +#+ OPTIONS : ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline +#+ OPTIONS : author : t c : nil creator : comment d : (not"LOGBOOK") date : t +#+ OPTIONS : e : t email : nil f : t inline : t num : t p : nil pri : nil stat : t +#+ OPTIONS : tags : t tasks : t tex : t timestamp : t toc : t todo : t | : t +#+ CREATOR : Emacs 25.1.1(Org mode 8.2.10) +#+ DESCRIPTION: +#+ EXCLUDE_TAGS : noexport +#+ KEYWORDS: +#+ LANGUAGE : en +#+ SELECT_TAGS : export -* Physics Engine +*Physics Engine -** Acceleration, speed and position + **Acceleration, + speed and position - I have a = dv/dt; v=dp/dt; - - I am going to use the second order runga kutta method with a=0, b=1, alpha=1/2 and beta=1/2 - + I have a = dv / dt; +v = dp / dt; + +I am going to use the second order runga kutta method with a = 0, b = 1, + alpha = + 1 / 2 and beta = + 1 / 2 diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index efeedb64..c67d2b12 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -11,43 +11,46 @@ #include "Math/matrix.hpp" -namespace yage { -class Body { +namespace yage +{ +class Body +{ public: - // gravity constant - static const double GRAVITY; + // gravity constant + static const double GRAVITY; protected: - // center of mass of the object - Vector2d position_ = Vector2d(0, 0); + // center of mass of the object + Vector2d position_ = Vector2d(0, 0); - // mass of the object - double mass_ = 1; + // mass of the object + double mass_ = 1; - // current velocity of the object - Vector2d velocity_ = Vector2d(0, 0); + // current velocity of the object + Vector2d velocity_ = Vector2d(0, 0); - // boolean that defines if gravity can act on the object - bool gravity_ = true; + // boolean that defines if gravity can act on the object + bool gravity_ = true; - // current acceleration - Vector2d acceleration_ = Vector2d(0, 0); + // current acceleration + Vector2d acceleration_ = Vector2d(0, 0); - // force acting on the body - Vector2d force_ = Vector2d(0, 0); + // force acting on the body + Vector2d force_ = Vector2d(0, 0); public: - // apply force to the object and update the velocity - virtual void applyForce(const Vector2d& force) = 0; - virtual void update() = 0; + // apply force to the object and update the velocity + virtual void applyForce(const Vector2d &force) = 0; + virtual void update() = 0; - double xPosition() const; - double yPosition() const; + double xPosition() const; + double yPosition() const; protected: - // protected constructor to initialize member variables - Body(Vector2d position = Vector2d(0, 0), double mass = 1, Vector2d velocity = Vector2d(0, 0), bool gravity = false); + // protected constructor to initialize member variables + Body(Vector2d position = Vector2d(0, 0), double mass = 1, + Vector2d velocity = Vector2d(0, 0), bool gravity = false); }; -} // namespace yage +} // namespace yage #endif diff --git a/include/YAGE/Physics/collider.hpp b/include/YAGE/Physics/collider.hpp index 92b90de2..7b4ff060 100644 --- a/include/YAGE/Physics/collider.hpp +++ b/include/YAGE/Physics/collider.hpp @@ -11,11 +11,13 @@ #include -namespace yage { +namespace yage +{ // The Collider class helps collision detection by providing a general shape // for different shapes to have their own collision algorithms. -class Collider { +class Collider +{ protected: // position of the object glm::vec2 position_; @@ -24,16 +26,18 @@ protected: glm::vec2 size_; public: - Collider(const glm::vec2& position, const glm::vec2& size) - : position_(position), size_(size) {} + Collider(const glm::vec2 &position, const glm::vec2 &size) + : position_(position), size_(size) + { + } // function that checks if two colliders are colliding - virtual bool collides(const Collider& collider) const = 0; + virtual bool collides(const Collider &collider) const = 0; // function that returns if a point is inside the shape - virtual bool inside(const glm::vec2& point) const = 0; + virtual bool inside(const glm::vec2 &point) const = 0; }; -} // namespace yage +} // namespace yage #endif diff --git a/include/YAGE/Physics/collisionbody.hpp b/include/YAGE/Physics/collisionbody.hpp index 5ddacacd..b7403e81 100644 --- a/include/YAGE/Physics/collisionbody.hpp +++ b/include/YAGE/Physics/collisionbody.hpp @@ -11,16 +11,18 @@ #include "Physics/body.hpp" -namespace yage { +namespace yage +{ // a collision body will be a body that is static and not affected by gravity, // with infinite mass -class CollisionBody : public Body { +class CollisionBody : public Body +{ public: CollisionBody(); virtual ~CollisionBody(); }; -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp index fd07512f..a3091773 100644 --- a/include/YAGE/Physics/particlebody.hpp +++ b/include/YAGE/Physics/particlebody.hpp @@ -6,26 +6,27 @@ * ---------------------------------------------------------------------------- */ -#ifndef YAGE_PARTICLE_BODY_HPP -#define YAGE_PARTICLE_BODY_HPP +#ifndef YAGE_PHYSICS_PARTICLE_BODY_HPP +#define YAGE_PHYSICS_PARTICLE_BODY_HPP #include "Math/matrix.hpp" +#include "Physics/body.hpp" -#include "body.hpp" +namespace yage +{ -namespace yage { - -class ParticleBody : public Body { +class ParticleBody : public Body +{ public: - ParticleBody(const Vector2d& position = Vector2d(0, 0), double mass = 1, - const Vector2d& velocity = Vector2d(0, 0), + ParticleBody(const Vector2d &position = Vector2d(0, 0), double mass = 1, + const Vector2d &velocity = Vector2d(0, 0), bool gravity = true); // apply a force to the rigid body - void applyForce(const Vector2d& force) override; + void applyForce(const Vector2d &force) override; void update() override; }; -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/rectanglecollider.hpp b/include/YAGE/Physics/rectanglecollider.hpp index b66664a0..ba1d8384 100644 --- a/include/YAGE/Physics/rectanglecollider.hpp +++ b/include/YAGE/Physics/rectanglecollider.hpp @@ -13,16 +13,18 @@ #include -namespace yage { +namespace yage +{ -class RectangleCollider : public Collider { +class RectangleCollider : public Collider +{ public: - RectangleCollider(const glm::vec2& position, const glm::vec2& size); + RectangleCollider(const glm::vec2 &position, const glm::vec2 &size); - bool collides(const Collider& collider) const override; - bool inside(const glm::vec2& point) const override; + bool collides(const Collider &collider) const override; + bool inside(const glm::vec2 &point) const override; }; -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/rigidbody.hpp b/include/YAGE/Physics/rigidbody.hpp index fd19dc7c..6fc969f5 100644 --- a/include/YAGE/Physics/rigidbody.hpp +++ b/include/YAGE/Physics/rigidbody.hpp @@ -13,14 +13,16 @@ #include "particlebody.hpp" -namespace yage { +namespace yage +{ -class RigidBody : public ParticleBody { +class RigidBody : public ParticleBody +{ public: - RigidBody(const Vector2d& position = Vector2d(0, 0), double mass = 1, - const Vector2d& velocity = Vector2d(0, 0), bool gravity = true); + RigidBody(const Vector2d &position = Vector2d(0, 0), double mass = 1, + const Vector2d &velocity = Vector2d(0, 0), bool gravity = true); }; -} // yage +} // yage #endif diff --git a/include/YAGE/camera2d.hpp b/include/YAGE/camera2d.hpp index e5e4e651..89f2f35c 100644 --- a/include/YAGE/camera2d.hpp +++ b/include/YAGE/camera2d.hpp @@ -14,9 +14,11 @@ #include #include -namespace yage { +namespace yage +{ -class Camera2D { +class Camera2D +{ private: bool matrix_needs_update_ = true; float scale_ = 1; @@ -28,11 +30,11 @@ public: Camera2D(int screen_width = 1280, int screen_height = 720); // update camera location - void update(GlslProgram& program); + void update(GlslProgram &program); // camera movement - void move(const glm::vec2& direction); + void move(const glm::vec2 &direction); }; -} // yage +} // yage #endif diff --git a/include/YAGE/glslprogram.hpp b/include/YAGE/glslprogram.hpp index fd97c3a0..eaa19c52 100644 --- a/include/YAGE/glslprogram.hpp +++ b/include/YAGE/glslprogram.hpp @@ -13,9 +13,11 @@ #include -namespace yage { +namespace yage +{ -class GlslProgram { +class GlslProgram +{ private: /// compiled shader program id GLuint program_id_ = 0; @@ -24,27 +26,27 @@ private: int attribute_index_ = 0; /// compiles one shader - void compileShader(const GLuint& shader, const std::string& file_path); + void compileShader(const GLuint &shader, const std::string &file_path); public: GlslProgram() = default; - GlslProgram(const GlslProgram&) = delete; - GlslProgram(GlslProgram&&) = delete; + GlslProgram(const GlslProgram &) = delete; + GlslProgram(GlslProgram &&) = delete; ~GlslProgram(); - GlslProgram& operator=(const GlslProgram&) = delete; - GlslProgram& operator=(GlslProgram&&) = delete; + GlslProgram &operator=(const GlslProgram &) = delete; + GlslProgram &operator=(GlslProgram &&) = delete; /// compiles vertex and fragment shader - void compileShaders(const std::string& vertex_shader_path, - const std::string& fragment_shader_path); + void compileShaders(const std::string &vertex_shader_path, + const std::string &fragment_shader_path); void linkShaders(); - void addAttribute(const std::string& attribute_name); - GLint getUniformLocation(const std::string& uniform_name); + void addAttribute(const std::string &attribute_name); + GLint getUniformLocation(const std::string &uniform_name); void use(); void unuse(); }; -} // yage +} // yage #endif diff --git a/include/YAGE/imageloader.hpp b/include/YAGE/imageloader.hpp index 90425cab..a9c00c4b 100644 --- a/include/YAGE/imageloader.hpp +++ b/include/YAGE/imageloader.hpp @@ -13,13 +13,15 @@ #include -namespace yage { +namespace yage +{ -class ImageLoader { +class ImageLoader +{ public: - static Texture loadPng(const std::string& file_path); + static Texture loadPng(const std::string &file_path); }; -} // yage +} // yage #endif diff --git a/include/YAGE/inputmanager.hpp b/include/YAGE/inputmanager.hpp index f8a0c710..0d5c65e7 100644 --- a/include/YAGE/inputmanager.hpp +++ b/include/YAGE/inputmanager.hpp @@ -24,6 +24,5 @@ public: void keyReleased(unsigned key); bool isKeyPressed(unsigned key) const; }; - } #endif diff --git a/include/YAGE/iomanager.hpp b/include/YAGE/iomanager.hpp index 3b1f5278..35f77e43 100644 --- a/include/YAGE/iomanager.hpp +++ b/include/YAGE/iomanager.hpp @@ -12,9 +12,11 @@ #include #include -namespace yage { +namespace yage +{ -class IoManager { +class IoManager +{ public: static bool readFileToBuffer(const std::string &file_path, std::vector &buffer); diff --git a/include/YAGE/picopng.hpp b/include/YAGE/picopng.hpp index b1318da0..ded8ffa1 100644 --- a/include/YAGE/picopng.hpp +++ b/include/YAGE/picopng.hpp @@ -6,17 +6,15 @@ * ---------------------------------------------------------------------------- */ -#include #include +#include namespace yage { extern int decodePNG(std::vector &out_image, - unsigned long &image_width, - unsigned long &image_height, - const unsigned char *in_png, - size_t in_size, - bool convert_to_rgba32 = true); + unsigned long &image_width, unsigned long &image_height, + const unsigned char *in_png, size_t in_size, + bool convert_to_rgba32 = true); } // yage diff --git a/include/YAGE/resourcemanager.hpp b/include/YAGE/resourcemanager.hpp index 3d824d61..38587dfc 100644 --- a/include/YAGE/resourcemanager.hpp +++ b/include/YAGE/resourcemanager.hpp @@ -14,16 +14,18 @@ #include -namespace yage { +namespace yage +{ -class ResourceManager { +class ResourceManager +{ private: static TextureCache texture_cache_; public: - static Texture getTexture(const std::string& texture_path); + static Texture getTexture(const std::string &texture_path); }; -} // yage +} // yage #endif diff --git a/include/YAGE/sprite.hpp b/include/YAGE/sprite.hpp index 969d0a67..4b5f2489 100644 --- a/include/YAGE/sprite.hpp +++ b/include/YAGE/sprite.hpp @@ -15,9 +15,11 @@ #include -namespace yage { +namespace yage +{ -class Sprite { +class Sprite +{ private: float x_; float y_; @@ -28,18 +30,18 @@ private: public: Sprite(); - Sprite(const Sprite&) = delete; - Sprite(Sprite&&) = delete; + Sprite(const Sprite &) = delete; + Sprite(Sprite &&) = delete; ~Sprite(); - Sprite& operator=(const Sprite&) = delete; - Sprite& operator=(Sprite&&) = delete; + Sprite &operator=(const Sprite &) = delete; + Sprite &operator=(Sprite &&) = delete; void init(float x, float y, float width, float height, - const std::string& texture_path); + const std::string &texture_path); void draw(); }; -} // yage +} // yage #endif diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index d47672ef..add58b43 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -16,13 +16,15 @@ #include -namespace yage { +namespace yage +{ class SpriteBatch; /** Glyph with information of the texture. */ -class Glyph { +class Glyph +{ private: GLuint texture_; float depth_; @@ -32,9 +34,9 @@ private: Vertex bottom_left_; public: - Glyph(GLuint texture, float depth, const Vertex& top_left, - const Vertex& top_right, const Vertex& bottom_right, - const Vertex& bottom_left); + Glyph(GLuint texture, float depth, const Vertex &top_left, + const Vertex &top_right, const Vertex &bottom_right, + const Vertex &bottom_left); GLuint texture() const { return texture_; } float depth() const { return depth_; } @@ -44,8 +46,10 @@ public: Vertex bottom_left() const { return bottom_left_; } }; -class RenderBatch { +class RenderBatch +{ friend SpriteBatch; + private: GLsizei num_vertices_; GLint offset_; @@ -59,7 +63,8 @@ public: GLuint texture() const { return texture_; } }; -class SpriteBatch { +class SpriteBatch +{ public: static const int NUM_VERTICES = 6; @@ -67,25 +72,25 @@ private: GLuint vbo_ = 0; GLuint vao_ = 0; std::vector glyphs_; - std::vector glyph_ptrs_; + std::vector glyph_ptrs_; std::vector render_batches_; public: SpriteBatch(); - SpriteBatch(const SpriteBatch&) = delete; - SpriteBatch(SpriteBatch&&) = delete; + SpriteBatch(const SpriteBatch &) = delete; + SpriteBatch(SpriteBatch &&) = delete; ~SpriteBatch(); - SpriteBatch& operator=(const SpriteBatch&) = delete; - SpriteBatch& operator=(SpriteBatch&&) = delete; + SpriteBatch &operator=(const SpriteBatch &) = delete; + SpriteBatch &operator=(SpriteBatch &&) = delete; // initialize vaos and vbos void init(); void begin(); void end(); // adds a sprite to the sprite batch to be rendered later - void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect, - GLuint texture, const Color& color, float depth); + void draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, + GLuint texture, const Color &color, float depth); // render the batch void render(); @@ -95,6 +100,6 @@ private: void sortGlyphs(); }; -} // namespace yage +} // namespace yage #endif diff --git a/include/YAGE/texture.hpp b/include/YAGE/texture.hpp index 65f3f651..b5fe7acd 100644 --- a/include/YAGE/texture.hpp +++ b/include/YAGE/texture.hpp @@ -11,7 +11,8 @@ #include -namespace yage { +namespace yage +{ struct Texture { GLuint id; @@ -19,6 +20,6 @@ struct Texture { int height; }; -} // yage +} // yage #endif diff --git a/include/YAGE/texturecache.hpp b/include/YAGE/texturecache.hpp index 0de5c12a..9765b919 100644 --- a/include/YAGE/texturecache.hpp +++ b/include/YAGE/texturecache.hpp @@ -13,18 +13,20 @@ #include -namespace yage { +namespace yage +{ -class TextureCache { +class TextureCache +{ private: std::unordered_map texture_map_; public: TextureCache(); - Texture getTexture(const std::string& texture_path); + Texture getTexture(const std::string &texture_path); }; -} // yage +} // yage #endif diff --git a/include/YAGE/vertex.hpp b/include/YAGE/vertex.hpp index 1026253e..9201393b 100644 --- a/include/YAGE/vertex.hpp +++ b/include/YAGE/vertex.hpp @@ -11,7 +11,8 @@ #include -namespace yage { +namespace yage +{ struct Position { float x; @@ -31,7 +32,9 @@ struct Color { Color() = default; Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) - : r(r_), g(g_), b(b_), a(a_) {} + : r(r_), g(g_), b(b_), a(a_) + { + } }; struct UV { @@ -50,27 +53,32 @@ struct Vertex { Vertex() = default; - Vertex(const Position& position_, const Color& color_, const UV& uv_) - : position(position_), color(color_), uv(uv_) {} + Vertex(const Position &position_, const Color &color_, const UV &uv_) + : position(position_), color(color_), uv(uv_) + { + } - void setPosition(float x, float y) { + void setPosition(float x, float y) + { position.x = x; position.y = y; } - void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) { + void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { color.r = r; color.g = g; color.b = b; color.a = a; } - void setUv(float u, float v) { + void setUv(float u, float v) + { uv.u = u; uv.v = v; } }; -} // yage +} // yage #endif diff --git a/include/YAGE/window.hpp b/include/YAGE/window.hpp index c2003a94..51b217f8 100644 --- a/include/YAGE/window.hpp +++ b/include/YAGE/window.hpp @@ -13,7 +13,8 @@ #include -namespace yage { +namespace yage +{ // window flags that can change it's appearance enum WindowFlags : unsigned { @@ -24,23 +25,24 @@ enum WindowFlags : unsigned { }; // window wrapper around SDL_Window pointer -class Window { +class Window +{ private: /// window handle - SDL_Window* window_ = nullptr; + SDL_Window *window_ = nullptr; public: Window(); - Window(const Window&) = delete; - Window(Window&&) = delete; + Window(const Window &) = delete; + Window(Window &&) = delete; /// destroys the window handle ~Window(); - Window& operator=(const Window&) = delete; - Window& operator=(Window&&) = delete; + Window &operator=(const Window &) = delete; + Window &operator=(Window &&) = delete; /// create the window, initialize the handle and update the width and height - void create(const std::string& window_name, int width, int height, + void create(const std::string &window_name, int width, int height, unsigned flags = WindowFlags::SHOWN); /// swap the buffer void swapBuffer(); @@ -48,6 +50,6 @@ public: void clearBuffer(); }; -} // namespace yage +} // namespace yage #endif diff --git a/include/YAGE/yage.hpp b/include/YAGE/yage.hpp index 31289d64..b426eed9 100644 --- a/include/YAGE/yage.hpp +++ b/include/YAGE/yage.hpp @@ -25,11 +25,11 @@ #include -namespace yage { +namespace yage +{ bool init() { return SDL_Init(SDL_INIT_VIDEO); } void quit() { SDL_Quit(); } - }; #endif -- cgit