aboutsummaryrefslogtreecommitdiffstats
path: root/include/YAGE
diff options
context:
space:
mode:
Diffstat (limited to 'include/YAGE')
-rw-r--r--include/YAGE/Math/matrix.hpp211
-rw-r--r--include/YAGE/Physics/README.org44
-rw-r--r--include/YAGE/Physics/body.hpp51
-rw-r--r--include/YAGE/Physics/collider.hpp18
-rw-r--r--include/YAGE/Physics/collisionbody.hpp8
-rw-r--r--include/YAGE/Physics/particlebody.hpp23
-rw-r--r--include/YAGE/Physics/rectanglecollider.hpp14
-rw-r--r--include/YAGE/Physics/rigidbody.hpp12
-rw-r--r--include/YAGE/camera2d.hpp12
-rw-r--r--include/YAGE/glslprogram.hpp26
-rw-r--r--include/YAGE/imageloader.hpp10
-rw-r--r--include/YAGE/inputmanager.hpp1
-rw-r--r--include/YAGE/iomanager.hpp6
-rw-r--r--include/YAGE/picopng.hpp10
-rw-r--r--include/YAGE/resourcemanager.hpp10
-rw-r--r--include/YAGE/sprite.hpp18
-rw-r--r--include/YAGE/spritebatch.hpp35
-rw-r--r--include/YAGE/texture.hpp5
-rw-r--r--include/YAGE/texturecache.hpp10
-rw-r--r--include/YAGE/vertex.hpp32
-rw-r--r--include/YAGE/window.hpp20
-rw-r--r--include/YAGE/yage.hpp4
22 files changed, 333 insertions, 247 deletions
diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp
index 860a250c..249edcc7 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
@@ -26,21 +28,22 @@
#include <string>
#include <vector>
-namespace yage {
+namespace yage
+{
-template <int Rows, int Cols, class Type>
-class Matrix;
+template <int Rows, int Cols, class Type> class Matrix;
-/** \internal Namespace for internal details.
+/** @internal Namespace for internal details.
*
* Detail Namespace
* ================
*
* 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 Internal Row class used by the Matrix class to return the
* internal data structure of the Matrix.
*
* Row
@@ -48,27 +51,31 @@ namespace detail {
*
* Internal Row class to return a value in the row of the matrix.
*/
-template <int Rows, int Cols, class Type>
-class Row {
+template <int Rows, int Cols, class Type> class Row
+{
private:
- Matrix<Rows, Cols, Type>* parent_;
+ Matrix<Rows, Cols, Type> *parent_;
int index_;
public:
- Row<Rows, Cols, Type>(Matrix<Rows, Cols, Type>* parent, int index)
- : parent_(parent), index_(index) {}
+ Row<Rows, Cols, Type>(Matrix<Rows, Cols, Type> *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.
*
@@ -78,8 +85,8 @@ public:
* This is the base matrix class that can be used by all the other matrix
* like data structures.
*/
-template <int Rows = 4, int Cols = 4, class Type = double>
-class Matrix {
+template <int Rows = 4, int Cols = 4, class Type = double> class Matrix
+{
// friended with the row class so that it can access protected member data
friend class detail::Row<Rows, Cols, Type>;
@@ -90,7 +97,7 @@ protected:
public:
/// Initializes the size of the data_ vector
Matrix<Rows, Cols, Type>() : data_(Rows * Cols) {}
- Matrix<Rows, Cols, Type>(const std::vector<Type>& data) : data_(data) {}
+ Matrix<Rows, Cols, Type>(const std::vector<Type> &data) : data_(data) {}
/// Returns the row size of the Matrix
int rowSize() const { return Rows; }
@@ -100,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];
@@ -113,7 +121,8 @@ public:
}
// returns the column in a column matrix
- Matrix<Rows, 1, Type> getCol(int col) const {
+ Matrix<Rows, 1, Type> getCol(int col) const
+ {
Matrix<Rows, 1, Type> colMatrix;
for (int i = 0; i < Rows; ++i) {
colMatrix[i][0] = data_[i][col];
@@ -121,15 +130,17 @@ public:
return colMatrix;
}
- // iterator support for begin
+ /// iterator support for begin
typename std::vector<Type>::iterator begin() { return data_.begin(); }
- // iterator support for end
+ /// iterator support for end
typename std::vector<Type>::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 {
+ /** 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 << '[';
for (int i = 0; i < Rows - 1; ++i) {
@@ -147,17 +158,20 @@ public:
return ss.str();
}
- detail::Row<Rows, Cols, Type> operator[](int row) {
+ detail::Row<Rows, Cols, Type> operator[](int row)
+ {
return detail::Row<Rows, Cols, Type>(this, row);
}
- detail::Row<Rows, Cols, Type> operator[](int row) const {
- // TODO got to fix this
- return detail::Row<Rows, Cols, Type>((Matrix<Rows, Cols, Type>*)this,
+ detail::Row<Rows, Cols, Type> operator[](int row) const
+ {
+ // @todo got to fix this
+ return detail::Row<Rows, Cols, Type>((Matrix<Rows, Cols, Type> *)this,
row);
}
- Matrix<Rows, Cols, Type>& operator+=(const Matrix<Rows, Cols, Type>& rhs) {
+ Matrix<Rows, Cols, Type> &operator+=(const Matrix<Rows, Cols, Type> &rhs)
+ {
std::vector<Type> out;
out.reserve(data_.size());
std::transform(data_.begin(), data_.end(), rhs.data_.begin(),
@@ -167,7 +181,8 @@ public:
return *this;
}
- Matrix<Rows, Cols, Type>& operator-=(const Matrix<Rows, Cols, Type>& rhs) {
+ Matrix<Rows, Cols, Type> &operator-=(const Matrix<Rows, Cols, Type> &rhs)
+ {
std::vector<Type> out;
out.reserve(data_.size());
std::transform(data_.begin(), data_.end(), rhs.begin(),
@@ -179,100 +194,121 @@ public:
};
template <int M, int N, class T>
-Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const Matrix<M, N, T>& rhs) {
+Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const Matrix<M, N, T> &rhs)
+{
lhs += rhs;
return lhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const Matrix<M, N, T>& rhs) {
+Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const Matrix<M, N, T> &rhs)
+{
lhs -= rhs;
return lhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const T& rhs) {
- for (auto& data : lhs) {
+Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const T &rhs)
+{
+ for (auto &data : lhs) {
data += rhs;
}
return lhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator+(const T& lhs, Matrix<M, N, T> rhs) {
- for (auto& data : rhs) {
+Matrix<M, N, T> operator+(const T &lhs, Matrix<M, N, T> rhs)
+{
+ for (auto &data : rhs) {
data += lhs;
}
return rhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const T& rhs) {
- for (auto& data : lhs) {
+Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const T &rhs)
+{
+ for (auto &data : lhs) {
data -= rhs;
}
return lhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator-(const T& lhs, Matrix<M, N, T> rhs) {
- for (auto& data : rhs) {
+Matrix<M, N, T> operator-(const T &lhs, Matrix<M, N, T> rhs)
+{
+ for (auto &data : rhs) {
data = lhs - data;
}
return rhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator*(Matrix<M, N, T> lhs, const T& rhs) {
- for (auto& data : lhs) {
+Matrix<M, N, T> operator*(Matrix<M, N, T> lhs, const T &rhs)
+{
+ for (auto &data : lhs) {
data *= rhs;
}
return lhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator*(const T& lhs, Matrix<M, N, T> rhs) {
- for (auto& data : rhs) {
+Matrix<M, N, T> operator*(const T &lhs, Matrix<M, N, T> rhs)
+{
+ for (auto &data : rhs) {
data *= lhs;
}
return rhs;
}
template <int M, int N, class T>
-Matrix<M, N, T> operator/(Matrix<M, N, T> lhs, const T& rhs) {
- for (auto& data : lhs) {
+Matrix<M, N, T> operator/(Matrix<M, N, T> lhs, const T &rhs)
+{
+ for (auto &data : lhs) {
data /= rhs;
}
return lhs;
}
template <int M, int N, class T>
-bool operator==(const Matrix<M, N, T>& lhs, const Matrix<M, N, T>& 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<M, N, T> &lhs, const Matrix<M, N, T> &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 <int M, int N, class T>
-std::ostream& operator<<(std::ostream& os, const Matrix<M, N, T>& mat) {
+std::ostream &operator<<(std::ostream &os, const Matrix<M, N, T> &mat)
+{
return os << mat.toString();
}
template <int Rows = 2, class Type = double>
-class Vector : public Matrix<Rows, 1, Type> {
+class Vector : public Matrix<Rows, 1, Type>
+{
public:
Vector<Rows, Type>() : Matrix<Rows, 1, Type>() {}
- Vector<Rows, Type>(const Matrix<Rows, 1, Type>& other)
- : Matrix<Rows, 1, Type>(other) {}
- Vector<Rows, Type>(const std::vector<Type>& data)
- : Matrix<Rows, 1, Type>(data) {}
+ Vector<Rows, Type>(const Matrix<Rows, 1, Type> &other)
+ : Matrix<Rows, 1, Type>(other)
+ {
+ }
+ Vector<Rows, Type>(const std::vector<Type> &data)
+ : Matrix<Rows, 1, Type>(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]; }
- virtual std::string toString() const {
+ std::string toString() const override
+ {
std::stringstream ss;
ss << "[";
for (std::size_t i = 0; i < this->data_.size() - 1; ++i) {
@@ -287,40 +323,43 @@ public:
*
* Two dimensional vector class.
*/
-template <class Type = double>
-class Vector2 : public Vector<2, Type> {
+template <class Type = double> class Vector2 : public Vector<2, Type>
+{
public:
Vector2<Type>() : Vector<2, Type>() {}
- Vector2<Type>(const std::vector<Type>& data) : Vector<2, Type>(data) {}
+ Vector2<Type>(const std::vector<Type> &data) : Vector<2, Type>(data) {}
- Vector2<Type>(Type x, Type y) {
+ Vector2<Type>(Type x, Type y)
+ {
this->data_[0] = x;
this->data_[1] = y;
}
- Vector2<Type>(const Matrix<2, 1, Type>& other) : Vector<2, Type>(other) {}
+ Vector2<Type>(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.
-typedef Vector2<double> Vector2d;
+using Vector2d = Vector2<double>;
/** Namespace containing functions that operate on matrices. */
-namespace matrix {
+namespace matrix
+{
/** Transposes a matrix and returns the result
*
* \param[in] m input matrix.
*/
template <int M, int N, class T>
-Matrix<N, M, T> transpose(const Matrix<M, N, T>& m) {
+Matrix<N, M, T> transpose(const Matrix<M, N, T> &m)
+{
Matrix<N, M, T> trans;
for (int i = 0; i < M; ++i) {
for (int j = 0; j < N; ++j) {
@@ -335,7 +374,8 @@ Matrix<N, M, T> transpose(const Matrix<M, N, T>& m) {
* \param[in] m1,m2 Input matrices.
*/
template <int R, class T>
-T dot(const Matrix<R, 1, T>& m1, const Matrix<R, 1, T>& m2) {
+T dot(const Matrix<R, 1, T> &m1, const Matrix<R, 1, T> &m2)
+{
T sum = 0;
for (int i = 0; i < R; ++i) {
sum += m1[i][0] * m2[i][0];
@@ -350,7 +390,8 @@ T dot(const Matrix<R, 1, T>& m1, const Matrix<R, 1, T>& m2) {
* Requires the two matrices to be compatible with multiplication.
*/
template <int M, int N, int P, int Q, class T>
-Matrix<M, Q, T> multiply(const Matrix<M, N, T>& m1, const Matrix<P, Q, T>& m2) {
+Matrix<M, Q, T> multiply(const Matrix<M, N, T> &m1, const Matrix<P, Q, T> &m2)
+{
if (N != P) {
throw std::runtime_error(
"Matrices don't have the right dimensions for multiplication");
@@ -367,8 +408,8 @@ Matrix<M, Q, T> multiply(const Matrix<M, N, T>& m1, const Matrix<P, Q, T>& 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 fab28fc1..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(const Vector2d& position = Vector2d(0, 0), double mass = 1, const 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 <glm/glm.hpp>
-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 ff8b3b85..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
- virtual void applyForce(const Vector2d& force);
- virtual void update();
+ 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 7f9dd7f7..ba1d8384 100644
--- a/include/YAGE/Physics/rectanglecollider.hpp
+++ b/include/YAGE/Physics/rectanglecollider.hpp
@@ -13,16 +13,18 @@
#include <glm/glm.hpp>
-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);
- 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
+} // 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 <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
-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 <string>
-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 <string>
-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 <string>
#include <vector>
-namespace yage {
+namespace yage
+{
-class IoManager {
+class IoManager
+{
public:
static bool readFileToBuffer(const std::string &file_path,
std::vector<unsigned char> &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 <vector>
#include <cstdlib>
+#include <vector>
namespace yage
{
extern int decodePNG(std::vector<unsigned char> &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 <string>
-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 <string>
-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 <vector>
-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<Glyph> glyphs_;
- std::vector<Glyph*> glyph_ptrs_;
+ std::vector<Glyph *> glyph_ptrs_;
std::vector<RenderBatch> 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 <GL/glew.h>
-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 <unordered_map>
-namespace yage {
+namespace yage
+{
-class TextureCache {
+class TextureCache
+{
private:
std::unordered_map<std::string, Texture> 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 d3355b11..9201393b 100644
--- a/include/YAGE/vertex.hpp
+++ b/include/YAGE/vertex.hpp
@@ -11,13 +11,14 @@
#include <GL/glew.h>
-namespace yage {
+namespace yage
+{
struct Position {
float x;
float y;
- Position() {}
+ Position() = default;
Position(float x_, float y_) : x(x_), y(y_) {}
};
@@ -28,17 +29,19 @@ 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_) {}
+ : r(r_), g(g_), b(b_), a(a_)
+ {
+ }
};
struct UV {
float u;
float v;
- UV() {}
+ UV() = default;
UV(float u_, float v_) : u(u_), v(v_) {}
};
@@ -48,29 +51,34 @@ 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_) {}
+ 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 <string>
-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 <stdexcept>
-namespace yage {
+namespace yage
+{
bool init() { return SDL_Init(SDL_INIT_VIDEO); }
void quit() { SDL_Quit(); }
-
};
#endif