From a992108e5b6383450a147a0a0ef54576dca5bd95 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 2 Sep 2017 10:31:42 +0100 Subject: Adding .h file extension to be more consistent. --- CMakeLists.txt | 25 +- include/YAGE/Math/math.h | 14 + include/YAGE/Math/math.hpp | 14 - include/YAGE/Math/matrix.h | 424 +++++++++++++++++++++++++++++ include/YAGE/Math/matrix.hpp | 423 ---------------------------- include/YAGE/Physics/body.h | 56 ++++ include/YAGE/Physics/body.hpp | 56 ---- include/YAGE/Physics/collider.h | 43 +++ include/YAGE/Physics/collider.hpp | 43 --- include/YAGE/Physics/collisionbody.h | 28 ++ include/YAGE/Physics/collisionbody.hpp | 28 -- include/YAGE/Physics/particlebody.h | 32 +++ include/YAGE/Physics/particlebody.hpp | 32 --- include/YAGE/Physics/physics.h | 19 ++ include/YAGE/Physics/physics.hpp | 19 -- include/YAGE/Physics/rectanglecollider.h | 30 ++ include/YAGE/Physics/rectanglecollider.hpp | 30 -- include/YAGE/Physics/rigidbody.h | 28 ++ include/YAGE/Physics/rigidbody.hpp | 28 -- include/YAGE/camera2d.h | 40 +++ include/YAGE/camera2d.hpp | 40 --- include/YAGE/glslprogram.h | 52 ++++ include/YAGE/glslprogram.hpp | 52 ---- include/YAGE/imageloader.h | 27 ++ include/YAGE/imageloader.hpp | 27 -- include/YAGE/inputmanager.h | 28 ++ include/YAGE/inputmanager.hpp | 28 -- include/YAGE/iomanager.h | 27 ++ include/YAGE/iomanager.hpp | 27 -- include/YAGE/picopng.h | 20 ++ include/YAGE/picopng.hpp | 20 -- include/YAGE/resourcemanager.h | 31 +++ include/YAGE/resourcemanager.hpp | 31 --- include/YAGE/sprite.h | 47 ++++ include/YAGE/sprite.hpp | 47 ---- include/YAGE/spritebatch.h | 105 +++++++ include/YAGE/spritebatch.hpp | 105 ------- include/YAGE/texture.h | 25 ++ include/YAGE/texture.hpp | 25 -- include/YAGE/texturecache.h | 32 +++ include/YAGE/texturecache.hpp | 32 --- include/YAGE/vertex.h | 84 ++++++ include/YAGE/vertex.hpp | 84 ------ include/YAGE/window.h | 55 ++++ include/YAGE/window.hpp | 55 ---- include/YAGE/yage.h | 63 +++++ include/YAGE/yage.hpp | 63 ----- src/camera2d.cpp | 6 +- 48 files changed, 1323 insertions(+), 1327 deletions(-) create mode 100644 include/YAGE/Math/math.h delete mode 100644 include/YAGE/Math/math.hpp create mode 100644 include/YAGE/Math/matrix.h delete mode 100644 include/YAGE/Math/matrix.hpp create mode 100644 include/YAGE/Physics/body.h delete mode 100644 include/YAGE/Physics/body.hpp create mode 100644 include/YAGE/Physics/collider.h delete mode 100644 include/YAGE/Physics/collider.hpp create mode 100644 include/YAGE/Physics/collisionbody.h delete mode 100644 include/YAGE/Physics/collisionbody.hpp create mode 100644 include/YAGE/Physics/particlebody.h delete mode 100644 include/YAGE/Physics/particlebody.hpp create mode 100644 include/YAGE/Physics/physics.h delete mode 100644 include/YAGE/Physics/physics.hpp create mode 100644 include/YAGE/Physics/rectanglecollider.h delete mode 100644 include/YAGE/Physics/rectanglecollider.hpp create mode 100644 include/YAGE/Physics/rigidbody.h delete mode 100644 include/YAGE/Physics/rigidbody.hpp create mode 100644 include/YAGE/camera2d.h delete mode 100644 include/YAGE/camera2d.hpp create mode 100644 include/YAGE/glslprogram.h delete mode 100644 include/YAGE/glslprogram.hpp create mode 100644 include/YAGE/imageloader.h delete mode 100644 include/YAGE/imageloader.hpp create mode 100644 include/YAGE/inputmanager.h delete mode 100644 include/YAGE/inputmanager.hpp create mode 100644 include/YAGE/iomanager.h delete mode 100644 include/YAGE/iomanager.hpp create mode 100644 include/YAGE/picopng.h delete mode 100644 include/YAGE/picopng.hpp create mode 100644 include/YAGE/resourcemanager.h delete mode 100644 include/YAGE/resourcemanager.hpp create mode 100644 include/YAGE/sprite.h delete mode 100644 include/YAGE/sprite.hpp create mode 100644 include/YAGE/spritebatch.h delete mode 100644 include/YAGE/spritebatch.hpp create mode 100644 include/YAGE/texture.h delete mode 100644 include/YAGE/texture.hpp create mode 100644 include/YAGE/texturecache.h delete mode 100644 include/YAGE/texturecache.hpp create mode 100644 include/YAGE/vertex.h delete mode 100644 include/YAGE/vertex.hpp create mode 100644 include/YAGE/window.h delete mode 100644 include/YAGE/window.hpp create mode 100644 include/YAGE/yage.h delete mode 100644 include/YAGE/yage.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b512a59e..8c0f48ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,18 +84,13 @@ message("${YAGE_LIB_DEP_L}") enable_testing() set(SIMULATION_RUNS 1000) -add_executable(yagetest ${YAGE_TEST_DIR}/yagetest.cpp) -target_link_libraries(yagetest gtest_main ${YAGE_LIB_DEP_L}) -add_test(NAME YageTest COMMAND yagetest --gtest_repeat=10 --gtest_break_on_failure) - -add_executable(matrixtest ${YAGE_TEST_DIR}/matrixtest.cpp) -target_link_libraries(matrixtest gtest_main ${YAGE_LIB_DEP_L}) -add_test(NAME MatrixTest COMMAND matrixtest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) - -add_executable(particlebodytest ${YAGE_TEST_DIR}/particlebodytest.cpp) -target_link_libraries(particlebodytest gtest_main ${YAGE_LIB_DEP_L}) -add_test(NAME ParticleBodyTest COMMAND particlebodytest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) - -add_executable(windowtest ${YAGE_TEST_DIR}/windowtest.cpp) -target_link_libraries(windowtest gtest_main ${YAGE_LIB_DEP_L}) -add_test(NAME WindowTest COMMAND windowtest --gtest_repeat=${SIMULATION_RUNS} --gtest_break_on_failure) +function(make_test test_name cycles) + add_executable(${test_name} ${YAGE_TEST_DIR}/${test_name}.cpp) + target_link_libraries(${test_name} gtest_main ${YAGE_LIB_DEP_L}) + add_test(NAME ${test_name} COMMAND ${test_name} --gtest_repeat=${cycles} --gtest_break_on_failure) +endfunction(make_test) + +make_test(yagetest 10) +make_test(matrixtest ${SIMULATION_RUNS}) +make_test(particlebodytest ${SIMULATION_RUNS}) +make_test(windowtest ${SIMULATION_RUNS}) diff --git a/include/YAGE/Math/math.h b/include/YAGE/Math/math.h new file mode 100644 index 00000000..b587cf9f --- /dev/null +++ b/include/YAGE/Math/math.h @@ -0,0 +1,14 @@ +/* ---------------------------------------------------------------------------- + * math.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_MATH_HPP +#define YAGE_MATH_HPP + +#include "matrix.hpp" + +#endif diff --git a/include/YAGE/Math/math.hpp b/include/YAGE/Math/math.hpp deleted file mode 100644 index b587cf9f..00000000 --- a/include/YAGE/Math/math.hpp +++ /dev/null @@ -1,14 +0,0 @@ -/* ---------------------------------------------------------------------------- - * math.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_MATH_HPP -#define YAGE_MATH_HPP - -#include "matrix.hpp" - -#endif diff --git a/include/YAGE/Math/matrix.h b/include/YAGE/Math/matrix.h new file mode 100644 index 00000000..aa78954e --- /dev/null +++ b/include/YAGE/Math/matrix.h @@ -0,0 +1,424 @@ +/* ---------------------------------------------------------------------------- + * matrix.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +/** @file + */ + +#ifndef YAGE_MATH_MATRIX_HPP +#define YAGE_MATH_MATRIX_HPP + +#include +#include +#include +#include +#include +#include + +namespace yage +{ + +template +class Matrix; + +/** @internal Namespace for internal details. + * + * Detail Namespace + * ================ + * + * This is the namespace used for implementation detail. + */ +namespace detail +{ + +/** @internal Internal Row class used by the Matrix class to return the + * internal data structure of the Matrix. + * + * Row + * === + * + * Internal Row class to return a value in the row of the matrix. + */ +template +class Row +{ +private: + Matrix *parent_; + int index_; + +public: + Row(Matrix *parent, int index) + : parent_(parent), index_(index) + { + } + + 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 + { + return parent_->data_[index_ * Cols + col]; + } +}; + +} // namespace detail + +/** Base Matrix class used by other similar classes. + */ +template +class Matrix +{ + // friended with the row class so that it can access protected member data. + friend class detail::Row; + +protected: + /// Vector containing the data of the matrix. + std::vector data_; + +public: + /// Initializes the size of the data_ vector. + Matrix() : data_(Rows * Cols) {} + Matrix(const std::vector &data) : data_(data) {} + + /// Returns the row size of the Matrix. + int rowSize() const { return Rows; } + + /// Returns the column size of the Matrix. + int colSize() const { return Cols; } + + /** Return the row specified row as a Matrix with only one row. + * + * @param row Row number to be returned. + * @return The row that is specified by the row variables. + */ + 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]; + } + return rowMatrix; + } + + /** Get a specific column in a column vector. + * + * @param col Column number to be returned. + * @return Column Matrix of the selected column. + */ + Matrix getCol(int col) const + { + Matrix colMatrix; + for (int i = 0; i < Rows; ++i) { + colMatrix[i][0] = data_[i][col]; + } + return colMatrix; + } + + /** Iterator support for the start. + * + * @return Iterator pointing to the start of the data. + */ + typename std::vector::iterator begin() { return data_.begin(); } + + /** Iterator support for the end. + * + * @return Iterator pointing to the end of the data. + */ + typename std::vector::iterator end() { return data_.end(); } + + /** Prints out the matrix, but can also be implemented by other classes to + * print data differently. + * + * @bug When printing certain matrices, it omits a row or column. Still + * need to determine under which conditions. + */ + virtual std::string toString() const + { + std::stringstream ss; + ss << '['; + for (int i = 0; i < Rows - 1; ++i) { + ss << '['; + for (int j = 0; j < Cols - 1; ++j) { + ss << data_[i * Cols + j] << ' '; + } + ss << data_[(Rows - 1) * Cols + Cols - 1] << "],"; + } + ss << '['; + for (int j = 0; j < Cols - 1; ++j) { + ss << data_[(Rows - 1) * Cols + j] << ' '; + } + ss << data_[(Rows - 1) * Cols + Cols - 1] << "]]"; + return ss.str(); + } + + detail::Row operator[](int row) + { + return detail::Row(this, row); + } + + detail::Row operator[](int row) const + { + return detail::Row((Matrix *)this, + row); + } + + Matrix &operator+=(const Matrix &rhs) + { + std::vector out; + out.reserve(data_.size()); + std::transform(data_.begin(), data_.end(), rhs.data_.begin(), + std::back_inserter(out), + [](Type a, Type b) { return a + b; }); + data_ = std::move(out); + return *this; + } + + Matrix &operator-=(const Matrix &rhs) + { + std::vector out; + out.reserve(data_.size()); + std::transform(data_.begin(), data_.end(), rhs.begin(), + std::back_inserter(out), + [](Type a, Type b) { return a - b; }); + data_ = std::move(out); + return *this; + } +}; + +template +Matrix operator+(Matrix lhs, const Matrix &rhs) +{ + lhs += rhs; + return lhs; +} + +template +Matrix operator-(Matrix lhs, const Matrix &rhs) +{ + lhs -= rhs; + return lhs; +} + +template +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) { + data += lhs; + } + return rhs; +} + +template +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) { + data = lhs - data; + } + return rhs; +} + +template +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) { + data *= lhs; + } + return rhs; +} + +template +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; + } + } + } + return true; +} + +template +std::ostream &operator<<(std::ostream &os, const Matrix &mat) +{ + return os << mat.toString(); +} + +template +class Vector : public Matrix +{ +public: + Vector() : Matrix() {} + Vector(const Matrix &other) + : Matrix(other) + { + } + + Vector(const std::vector &data) + : Matrix(data) + { + } + + Type &operator[](int col) { return this->data_[col]; } + + const Type &operator[](int col) const { return this->data_[col]; } + + std::string toString() const override + { + std::stringstream ss; + ss << "["; + for (std::size_t i = 0; i < this->data_.size() - 1; ++i) { + ss << this->data_[i] << " "; + } + ss << this->data_[this->data_.size() - 1] << "]"; + return ss.str(); + } +}; + +/** 2D Vector class. + * + * Two dimensional vector class. + */ +template +class Vector2 : public Vector<2, Type> +{ +public: + Vector2() : Vector<2, Type>() {} + Vector2(const std::vector &data) : Vector<2, Type>(data) {} + + Vector2(Type x, Type y) + { + this->data_[0] = x; + this->data_[1] = y; + } + + Vector2(const Matrix<2, 1, Type> &other) : Vector<2, Type>(other) {} + + Type &x() { return this->data_[0]; } + + const Type &x() const { return this->data_[0]; } + + Type &y() { 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. + * + * Implementations defined here are meant to operate on anything that inherits + * from the base Matrix class. + */ +namespace matrix +{ + +/** Transposes a matrix and returns the result + * + * @param m input matrix. + */ +template +Matrix transpose(const Matrix &m) +{ + Matrix trans; + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + trans[j][i] = m[i][j]; + } + } + return trans; +} + +/** Returns the dot product between two vectors + * + * @param m1,m2 Input matrices. + */ +template +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]; + } + return sum; +} + +/** Multiplies two matrices together. + * + * @param m1,m2 Matrix inputs + * + * Requires the two matrices to be compatible with multiplication. + */ +template +Matrix multiply(const Matrix &m1, const Matrix &m2) +{ + /// @todo Think if this should be a static_assert. + if (N != P) { + throw std::runtime_error( + "Matrices don't have the right dimensions for multiplication"); + } + + Matrix res; + + /// Performs multiplication by getting the rows and columns, transposing + /// one of them and then doting the result. + for (int i = 0; i < M; ++i) { + for (int j = 0; j < Q; ++j) { + res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j)); + } + } + + return res; +} + +} // namespace matrix + +} // namespace yage + +#endif diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp deleted file mode 100644 index 5d9e5d0f..00000000 --- a/include/YAGE/Math/matrix.hpp +++ /dev/null @@ -1,423 +0,0 @@ -/* ---------------------------------------------------------------------------- - * matrix.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -/// @file - -#ifndef YAGE_MATH_MATRIX_HPP -#define YAGE_MATH_MATRIX_HPP - -#include -#include -#include -#include -#include -#include - -namespace yage -{ - -template -class Matrix; - -/** @internal Namespace for internal details. - * - * Detail Namespace - * ================ - * - * This is the namespace used for implementation detail. - */ -namespace detail -{ - -/** @internal Internal Row class used by the Matrix class to return the - * internal data structure of the Matrix. - * - * Row - * === - * - * Internal Row class to return a value in the row of the matrix. - */ -template -class Row -{ -private: - Matrix *parent_; - int index_; - -public: - Row(Matrix *parent, int index) - : parent_(parent), index_(index) - { - } - - 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 - { - return parent_->data_[index_ * Cols + col]; - } -}; - -} // namespace detail - -/** Base Matrix class used by other similar classes. - */ -template -class Matrix -{ - // friended with the row class so that it can access protected member data. - friend class detail::Row; - -protected: - /// Vector containing the data of the matrix. - std::vector data_; - -public: - /// Initializes the size of the data_ vector. - Matrix() : data_(Rows * Cols) {} - Matrix(const std::vector &data) : data_(data) {} - - /// Returns the row size of the Matrix. - int rowSize() const { return Rows; } - - /// Returns the column size of the Matrix. - int colSize() const { return Cols; } - - /** Return the row specified row as a Matrix with only one row. - * - * @param row Row number to be returned. - * @return The row that is specified by the row variables. - */ - 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]; - } - return rowMatrix; - } - - /** Get a specific column in a column vector. - * - * @param col Column number to be returned. - * @return Column Matrix of the selected column. - */ - Matrix getCol(int col) const - { - Matrix colMatrix; - for (int i = 0; i < Rows; ++i) { - colMatrix[i][0] = data_[i][col]; - } - return colMatrix; - } - - /** Iterator support for the start. - * - * @return Iterator pointing to the start of the data. - */ - typename std::vector::iterator begin() { return data_.begin(); } - - /** Iterator support for the end. - * - * @return Iterator pointing to the end of the data. - */ - typename std::vector::iterator end() { return data_.end(); } - - /** Prints out the matrix, but can also be implemented by other classes to - * print data differently. - * - * @bug When printing certain matrices, it omits a row or column. Still - * need to determine under which conditions. - */ - virtual std::string toString() const - { - std::stringstream ss; - ss << '['; - for (int i = 0; i < Rows - 1; ++i) { - ss << '['; - for (int j = 0; j < Cols - 1; ++j) { - ss << data_[i * Cols + j] << ' '; - } - ss << data_[(Rows - 1) * Cols + Cols - 1] << "],"; - } - ss << '['; - for (int j = 0; j < Cols - 1; ++j) { - ss << data_[(Rows - 1) * Cols + j] << ' '; - } - ss << data_[(Rows - 1) * Cols + Cols - 1] << "]]"; - return ss.str(); - } - - detail::Row operator[](int row) - { - return detail::Row(this, row); - } - - detail::Row operator[](int row) const - { - return detail::Row((Matrix *)this, - row); - } - - Matrix &operator+=(const Matrix &rhs) - { - std::vector out; - out.reserve(data_.size()); - std::transform(data_.begin(), data_.end(), rhs.data_.begin(), - std::back_inserter(out), - [](Type a, Type b) { return a + b; }); - data_ = std::move(out); - return *this; - } - - Matrix &operator-=(const Matrix &rhs) - { - std::vector out; - out.reserve(data_.size()); - std::transform(data_.begin(), data_.end(), rhs.begin(), - std::back_inserter(out), - [](Type a, Type b) { return a - b; }); - data_ = std::move(out); - return *this; - } -}; - -template -Matrix operator+(Matrix lhs, const Matrix &rhs) -{ - lhs += rhs; - return lhs; -} - -template -Matrix operator-(Matrix lhs, const Matrix &rhs) -{ - lhs -= rhs; - return lhs; -} - -template -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) { - data += lhs; - } - return rhs; -} - -template -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) { - data = lhs - data; - } - return rhs; -} - -template -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) { - data *= lhs; - } - return rhs; -} - -template -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; - } - } - } - return true; -} - -template -std::ostream &operator<<(std::ostream &os, const Matrix &mat) -{ - return os << mat.toString(); -} - -template -class Vector : public Matrix -{ -public: - Vector() : Matrix() {} - Vector(const Matrix &other) - : Matrix(other) - { - } - - Vector(const std::vector &data) - : Matrix(data) - { - } - - Type &operator[](int col) { return this->data_[col]; } - - const Type &operator[](int col) const { return this->data_[col]; } - - std::string toString() const override - { - std::stringstream ss; - ss << "["; - for (std::size_t i = 0; i < this->data_.size() - 1; ++i) { - ss << this->data_[i] << " "; - } - ss << this->data_[this->data_.size() - 1] << "]"; - return ss.str(); - } -}; - -/** 2D Vector class. - * - * Two dimensional vector class. - */ -template -class Vector2 : public Vector<2, Type> -{ -public: - Vector2() : Vector<2, Type>() {} - Vector2(const std::vector &data) : Vector<2, Type>(data) {} - - Vector2(Type x, Type y) - { - this->data_[0] = x; - this->data_[1] = y; - } - - Vector2(const Matrix<2, 1, Type> &other) : Vector<2, Type>(other) {} - - Type &x() { return this->data_[0]; } - - const Type &x() const { return this->data_[0]; } - - Type &y() { 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. - * - * Implementations defined here are meant to operate on anything that inherits - * from the base Matrix class. - */ -namespace matrix -{ - -/** Transposes a matrix and returns the result - * - * @param m input matrix. - */ -template -Matrix transpose(const Matrix &m) -{ - Matrix trans; - for (int i = 0; i < M; ++i) { - for (int j = 0; j < N; ++j) { - trans[j][i] = m[i][j]; - } - } - return trans; -} - -/** Returns the dot product between two vectors - * - * @param m1,m2 Input matrices. - */ -template -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]; - } - return sum; -} - -/** Multiplies two matrices together. - * - * @param m1,m2 Matrix inputs - * - * Requires the two matrices to be compatible with multiplication. - */ -template -Matrix multiply(const Matrix &m1, const Matrix &m2) -{ - /// @todo Think if this should be a static_assert. - if (N != P) { - throw std::runtime_error( - "Matrices don't have the right dimensions for multiplication"); - } - - Matrix res; - - /// Performs multiplication by getting the rows and columns, transposing - /// one of them and then doting the result. - for (int i = 0; i < M; ++i) { - for (int j = 0; j < Q; ++j) { - res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j)); - } - } - - return res; -} - -} // namespace matrix - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/body.h b/include/YAGE/Physics/body.h new file mode 100644 index 00000000..c67d2b12 --- /dev/null +++ b/include/YAGE/Physics/body.h @@ -0,0 +1,56 @@ +/* ---------------------------------------------------------------------------- + * body.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_PHYSICS_BODY_HPP +#define YAGE_PHYSICS_BODY_HPP + +#include "Math/matrix.hpp" + +namespace yage +{ +class Body +{ +public: + // gravity constant + static const double GRAVITY; + +protected: + // center of mass of the object + Vector2d position_ = Vector2d(0, 0); + + // mass of the object + double mass_ = 1; + + // current velocity of the object + Vector2d velocity_ = Vector2d(0, 0); + + // boolean that defines if gravity can act on the object + bool gravity_ = true; + + // current acceleration + Vector2d acceleration_ = 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; + + 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); +}; +} // namespace yage + +#endif diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp deleted file mode 100644 index c67d2b12..00000000 --- a/include/YAGE/Physics/body.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* ---------------------------------------------------------------------------- - * body.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_BODY_HPP -#define YAGE_PHYSICS_BODY_HPP - -#include "Math/matrix.hpp" - -namespace yage -{ -class Body -{ -public: - // gravity constant - static const double GRAVITY; - -protected: - // center of mass of the object - Vector2d position_ = Vector2d(0, 0); - - // mass of the object - double mass_ = 1; - - // current velocity of the object - Vector2d velocity_ = Vector2d(0, 0); - - // boolean that defines if gravity can act on the object - bool gravity_ = true; - - // current acceleration - Vector2d acceleration_ = 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; - - 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); -}; -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/collider.h b/include/YAGE/Physics/collider.h new file mode 100644 index 00000000..7b4ff060 --- /dev/null +++ b/include/YAGE/Physics/collider.h @@ -0,0 +1,43 @@ +/* ---------------------------------------------------------------------------- + * collider.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_PHYSICS_COLLIDER_HPP +#define YAGE_PHYSICS_COLLIDER_HPP + +#include + +namespace yage +{ + +// The Collider class helps collision detection by providing a general shape +// for different shapes to have their own collision algorithms. +class Collider +{ +protected: + // position of the object + glm::vec2 position_; + + // size of the object + glm::vec2 size_; + +public: + 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; + + // function that returns if a point is inside the shape + virtual bool inside(const glm::vec2 &point) const = 0; +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/Physics/collider.hpp b/include/YAGE/Physics/collider.hpp deleted file mode 100644 index 7b4ff060..00000000 --- a/include/YAGE/Physics/collider.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* ---------------------------------------------------------------------------- - * collider.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_COLLIDER_HPP -#define YAGE_PHYSICS_COLLIDER_HPP - -#include - -namespace yage -{ - -// The Collider class helps collision detection by providing a general shape -// for different shapes to have their own collision algorithms. -class Collider -{ -protected: - // position of the object - glm::vec2 position_; - - // size of the object - glm::vec2 size_; - -public: - 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; - - // function that returns if a point is inside the shape - virtual bool inside(const glm::vec2 &point) const = 0; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/collisionbody.h b/include/YAGE/Physics/collisionbody.h new file mode 100644 index 00000000..b7403e81 --- /dev/null +++ b/include/YAGE/Physics/collisionbody.h @@ -0,0 +1,28 @@ +/* ---------------------------------------------------------------------------- + * collisionbody.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_COLLISION_BODY_HPP +#define YAGE_COLLISION_BODY_HPP + +#include "Physics/body.hpp" + +namespace yage +{ + +// a collision body will be a body that is static and not affected by gravity, +// with infinite mass +class CollisionBody : public Body +{ +public: + CollisionBody(); + virtual ~CollisionBody(); +}; + +} // yage + +#endif diff --git a/include/YAGE/Physics/collisionbody.hpp b/include/YAGE/Physics/collisionbody.hpp deleted file mode 100644 index b7403e81..00000000 --- a/include/YAGE/Physics/collisionbody.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- - * collisionbody.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_COLLISION_BODY_HPP -#define YAGE_COLLISION_BODY_HPP - -#include "Physics/body.hpp" - -namespace yage -{ - -// a collision body will be a body that is static and not affected by gravity, -// with infinite mass -class CollisionBody : public Body -{ -public: - CollisionBody(); - virtual ~CollisionBody(); -}; - -} // yage - -#endif diff --git a/include/YAGE/Physics/particlebody.h b/include/YAGE/Physics/particlebody.h new file mode 100644 index 00000000..15f1ae5a --- /dev/null +++ b/include/YAGE/Physics/particlebody.h @@ -0,0 +1,32 @@ +/* ---------------------------------------------------------------------------- + * particlebody.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_PHYSICS_PARTICLE_BODY_HPP +#define YAGE_PHYSICS_PARTICLE_BODY_HPP + +#include "Math/matrix.hpp" +#include "Physics/body.hpp" + +namespace yage +{ + +class ParticleBody : public Body +{ +public: + 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 update() override; +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp deleted file mode 100644 index 15f1ae5a..00000000 --- a/include/YAGE/Physics/particlebody.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* ---------------------------------------------------------------------------- - * particlebody.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_PARTICLE_BODY_HPP -#define YAGE_PHYSICS_PARTICLE_BODY_HPP - -#include "Math/matrix.hpp" -#include "Physics/body.hpp" - -namespace yage -{ - -class ParticleBody : public Body -{ -public: - 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 update() override; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/physics.h b/include/YAGE/Physics/physics.h new file mode 100644 index 00000000..8146672a --- /dev/null +++ b/include/YAGE/Physics/physics.h @@ -0,0 +1,19 @@ +/* ---------------------------------------------------------------------------- + * physics.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_PHYSICS_HPP +#define YAGE_PHYSICS_HPP + +#include "body.hpp" +#include "collider.hpp" +#include "collisionbody.hpp" +#include "particlebody.hpp" +#include "rectanglecollider.hpp" +#include "rigidbody.hpp" + +#endif diff --git a/include/YAGE/Physics/physics.hpp b/include/YAGE/Physics/physics.hpp deleted file mode 100644 index 8146672a..00000000 --- a/include/YAGE/Physics/physics.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* ---------------------------------------------------------------------------- - * physics.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_HPP -#define YAGE_PHYSICS_HPP - -#include "body.hpp" -#include "collider.hpp" -#include "collisionbody.hpp" -#include "particlebody.hpp" -#include "rectanglecollider.hpp" -#include "rigidbody.hpp" - -#endif diff --git a/include/YAGE/Physics/rectanglecollider.h b/include/YAGE/Physics/rectanglecollider.h new file mode 100644 index 00000000..f6f6c481 --- /dev/null +++ b/include/YAGE/Physics/rectanglecollider.h @@ -0,0 +1,30 @@ +/* ---------------------------------------------------------------------------- + * rectanglecollider.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_RECTANGLE_COLLIDER_HPP +#define YAGE_RECTANGLE_COLLIDER_HPP + +#include "Physics/collider.hpp" + +#include + +namespace yage +{ + +class RectangleCollider : public Collider +{ +public: + RectangleCollider(const glm::vec2 &position, const glm::vec2 &size); + + bool collides(const Collider &collider) const override; + bool inside(const glm::vec2 &point) const override; +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/Physics/rectanglecollider.hpp b/include/YAGE/Physics/rectanglecollider.hpp deleted file mode 100644 index f6f6c481..00000000 --- a/include/YAGE/Physics/rectanglecollider.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* ---------------------------------------------------------------------------- - * rectanglecollider.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RECTANGLE_COLLIDER_HPP -#define YAGE_RECTANGLE_COLLIDER_HPP - -#include "Physics/collider.hpp" - -#include - -namespace yage -{ - -class RectangleCollider : public Collider -{ -public: - RectangleCollider(const glm::vec2 &position, const glm::vec2 &size); - - bool collides(const Collider &collider) const override; - bool inside(const glm::vec2 &point) const override; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/rigidbody.h b/include/YAGE/Physics/rigidbody.h new file mode 100644 index 00000000..48ca6761 --- /dev/null +++ b/include/YAGE/Physics/rigidbody.h @@ -0,0 +1,28 @@ +/* ---------------------------------------------------------------------------- + * rigidbody.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_RIGID_BODY_HPP +#define YAGE_RIGID_BODY_HPP + +#include + +#include "particlebody.hpp" + +namespace yage +{ + +class RigidBody : public ParticleBody +{ +public: + RigidBody(const Vector2d &position = Vector2d(0, 0), double mass = 1, + const Vector2d &velocity = Vector2d(0, 0), bool gravity = true); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/Physics/rigidbody.hpp b/include/YAGE/Physics/rigidbody.hpp deleted file mode 100644 index 48ca6761..00000000 --- a/include/YAGE/Physics/rigidbody.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- - * rigidbody.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RIGID_BODY_HPP -#define YAGE_RIGID_BODY_HPP - -#include - -#include "particlebody.hpp" - -namespace yage -{ - -class RigidBody : public ParticleBody -{ -public: - RigidBody(const Vector2d &position = Vector2d(0, 0), double mass = 1, - const Vector2d &velocity = Vector2d(0, 0), bool gravity = true); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/camera2d.h b/include/YAGE/camera2d.h new file mode 100644 index 00000000..ecf819b6 --- /dev/null +++ b/include/YAGE/camera2d.h @@ -0,0 +1,40 @@ +/* ---------------------------------------------------------------------------- + * camera2d.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef CAMERA_2D_HPP +#define CAMERA_2D_HPP + +#include "glslprogram.hpp" + +#include +#include + +namespace yage +{ + +class Camera2D +{ +private: + bool update_matrix_ = true; + float scale_ = 1; + glm::vec2 position_; + glm::mat4 camera_matrix_; + glm::mat4 ortho_matrix_; + +public: + Camera2D(int screen_width = 1280, int screen_height = 720); + + // update camera location + void update(GlslProgram &program); + // camera movement + void move(const glm::vec2 &direction); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/camera2d.hpp b/include/YAGE/camera2d.hpp deleted file mode 100644 index 354b3a17..00000000 --- a/include/YAGE/camera2d.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* ---------------------------------------------------------------------------- - * camera2d.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef CAMERA_2D_HPP -#define CAMERA_2D_HPP - -#include "glslprogram.hpp" - -#include -#include - -namespace yage -{ - -class Camera2D -{ -private: - bool matrix_needs_update_ = true; - float scale_ = 1; - glm::vec2 position_; - glm::mat4 camera_matrix_; - glm::mat4 ortho_matrix_; - -public: - Camera2D(int screen_width = 1280, int screen_height = 720); - - // update camera location - void update(GlslProgram &program); - // camera movement - void move(const glm::vec2 &direction); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/glslprogram.h b/include/YAGE/glslprogram.h new file mode 100644 index 00000000..154e2e57 --- /dev/null +++ b/include/YAGE/glslprogram.h @@ -0,0 +1,52 @@ +/* ---------------------------------------------------------------------------- + * glslprogram.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef GLSL_PROGRAM_HPP +#define GLSL_PROGRAM_HPP + +#include + +#include + +namespace yage +{ + +class GlslProgram +{ +private: + /// compiled shader program id + GLuint program_id_ = 0; + GLuint vertex_shader_id_ = 0; + GLuint fragment_shader_id_ = 0; + int attribute_index_ = 0; + + /// compiles one shader + void compileShader(const GLuint &shader, const std::string &file_path); + +public: + GlslProgram() = default; + GlslProgram(const GlslProgram &) = delete; + GlslProgram(GlslProgram &&) = delete; + ~GlslProgram(); + + 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 linkShaders(); + void addAttribute(const std::string &attribute_name); + GLint getUniformLocation(const std::string &uniform_name); + void use(); + void unuse(); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/glslprogram.hpp b/include/YAGE/glslprogram.hpp deleted file mode 100644 index 154e2e57..00000000 --- a/include/YAGE/glslprogram.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* ---------------------------------------------------------------------------- - * glslprogram.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef GLSL_PROGRAM_HPP -#define GLSL_PROGRAM_HPP - -#include - -#include - -namespace yage -{ - -class GlslProgram -{ -private: - /// compiled shader program id - GLuint program_id_ = 0; - GLuint vertex_shader_id_ = 0; - GLuint fragment_shader_id_ = 0; - int attribute_index_ = 0; - - /// compiles one shader - void compileShader(const GLuint &shader, const std::string &file_path); - -public: - GlslProgram() = default; - GlslProgram(const GlslProgram &) = delete; - GlslProgram(GlslProgram &&) = delete; - ~GlslProgram(); - - 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 linkShaders(); - void addAttribute(const std::string &attribute_name); - GLint getUniformLocation(const std::string &uniform_name); - void use(); - void unuse(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/imageloader.h b/include/YAGE/imageloader.h new file mode 100644 index 00000000..770307d1 --- /dev/null +++ b/include/YAGE/imageloader.h @@ -0,0 +1,27 @@ +/* ---------------------------------------------------------------------------- + * imageloader.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef IMAGE_LOADER_HPP +#define IMAGE_LOADER_HPP + +#include "texture.hpp" + +#include + +namespace yage +{ + +class ImageLoader +{ +public: + static Texture loadPng(const std::string &file_path); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/imageloader.hpp b/include/YAGE/imageloader.hpp deleted file mode 100644 index 770307d1..00000000 --- a/include/YAGE/imageloader.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* ---------------------------------------------------------------------------- - * imageloader.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef IMAGE_LOADER_HPP -#define IMAGE_LOADER_HPP - -#include "texture.hpp" - -#include - -namespace yage -{ - -class ImageLoader -{ -public: - static Texture loadPng(const std::string &file_path); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/inputmanager.h b/include/YAGE/inputmanager.h new file mode 100644 index 00000000..61c5ce53 --- /dev/null +++ b/include/YAGE/inputmanager.h @@ -0,0 +1,28 @@ +/* ---------------------------------------------------------------------------- + * inputmanager.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef INPUT_MANAGER_HPP +#define INPUT_MANAGER_HPP + +#include + +namespace yage +{ + +class InputManager +{ +private: + std::unordered_map key_map_; + +public: + void keyPressed(unsigned key); + void keyReleased(unsigned key); + bool isKeyPressed(unsigned key) const; +}; +} // namespace yage +#endif diff --git a/include/YAGE/inputmanager.hpp b/include/YAGE/inputmanager.hpp deleted file mode 100644 index 61c5ce53..00000000 --- a/include/YAGE/inputmanager.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- - * inputmanager.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef INPUT_MANAGER_HPP -#define INPUT_MANAGER_HPP - -#include - -namespace yage -{ - -class InputManager -{ -private: - std::unordered_map key_map_; - -public: - void keyPressed(unsigned key); - void keyReleased(unsigned key); - bool isKeyPressed(unsigned key) const; -}; -} // namespace yage -#endif diff --git a/include/YAGE/iomanager.h b/include/YAGE/iomanager.h new file mode 100644 index 00000000..4f30e51c --- /dev/null +++ b/include/YAGE/iomanager.h @@ -0,0 +1,27 @@ +/* ---------------------------------------------------------------------------- + * iomanager.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef IO_MANAGER_HPP +#define IO_MANAGER_HPP + +#include +#include + +namespace yage +{ + +class IoManager +{ +public: + static bool readFileToBuffer(const std::string &file_path, + std::vector &buffer); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/iomanager.hpp b/include/YAGE/iomanager.hpp deleted file mode 100644 index 4f30e51c..00000000 --- a/include/YAGE/iomanager.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* ---------------------------------------------------------------------------- - * iomanager.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef IO_MANAGER_HPP -#define IO_MANAGER_HPP - -#include -#include - -namespace yage -{ - -class IoManager -{ -public: - static bool readFileToBuffer(const std::string &file_path, - std::vector &buffer); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/picopng.h b/include/YAGE/picopng.h new file mode 100644 index 00000000..c0a42c28 --- /dev/null +++ b/include/YAGE/picopng.h @@ -0,0 +1,20 @@ +/* ---------------------------------------------------------------------------- + * picopng.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#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); + +} // namespace yage diff --git a/include/YAGE/picopng.hpp b/include/YAGE/picopng.hpp deleted file mode 100644 index c0a42c28..00000000 --- a/include/YAGE/picopng.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/* ---------------------------------------------------------------------------- - * picopng.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#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); - -} // namespace yage diff --git a/include/YAGE/resourcemanager.h b/include/YAGE/resourcemanager.h new file mode 100644 index 00000000..ebd30476 --- /dev/null +++ b/include/YAGE/resourcemanager.h @@ -0,0 +1,31 @@ +/* ---------------------------------------------------------------------------- + * resourcemanager.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef RESOURCE_MANAGER_HPP +#define RESOURCE_MANAGER_HPP + +#include "texture.hpp" +#include "texturecache.hpp" + +#include + +namespace yage +{ + +class ResourceManager +{ +private: + static TextureCache texture_cache_; + +public: + static Texture getTexture(const std::string &texture_path); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/resourcemanager.hpp b/include/YAGE/resourcemanager.hpp deleted file mode 100644 index ebd30476..00000000 --- a/include/YAGE/resourcemanager.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* ---------------------------------------------------------------------------- - * resourcemanager.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef RESOURCE_MANAGER_HPP -#define RESOURCE_MANAGER_HPP - -#include "texture.hpp" -#include "texturecache.hpp" - -#include - -namespace yage -{ - -class ResourceManager -{ -private: - static TextureCache texture_cache_; - -public: - static Texture getTexture(const std::string &texture_path); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/sprite.h b/include/YAGE/sprite.h new file mode 100644 index 00000000..28e13437 --- /dev/null +++ b/include/YAGE/sprite.h @@ -0,0 +1,47 @@ +/* ---------------------------------------------------------------------------- + * sprite.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef SPRITE_HPP +#define SPRITE_HPP + +#include "texture.hpp" + +#include + +#include + +namespace yage +{ + +class Sprite +{ +private: + float x_; + float y_; + float width_; + float height_; + GLuint vbo_id_ = 0; + Texture texture_; + +public: + Sprite(); + Sprite(const Sprite &) = delete; + Sprite(Sprite &&) = delete; + ~Sprite(); + + Sprite &operator=(const Sprite &) = delete; + Sprite &operator=(Sprite &&) = delete; + + void init(float x, float y, float width, float height, + const std::string &texture_path); + void draw(); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/sprite.hpp b/include/YAGE/sprite.hpp deleted file mode 100644 index 28e13437..00000000 --- a/include/YAGE/sprite.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* ---------------------------------------------------------------------------- - * sprite.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef SPRITE_HPP -#define SPRITE_HPP - -#include "texture.hpp" - -#include - -#include - -namespace yage -{ - -class Sprite -{ -private: - float x_; - float y_; - float width_; - float height_; - GLuint vbo_id_ = 0; - Texture texture_; - -public: - Sprite(); - Sprite(const Sprite &) = delete; - Sprite(Sprite &&) = delete; - ~Sprite(); - - Sprite &operator=(const Sprite &) = delete; - Sprite &operator=(Sprite &&) = delete; - - void init(float x, float y, float width, float height, - const std::string &texture_path); - void draw(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/spritebatch.h b/include/YAGE/spritebatch.h new file mode 100644 index 00000000..add58b43 --- /dev/null +++ b/include/YAGE/spritebatch.h @@ -0,0 +1,105 @@ +/* ---------------------------------------------------------------------------- + * spritebatch.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_SPRITE_BATCH_HPP +#define YAGE_SPRITE_BATCH_HPP + +#include "vertex.hpp" + +#include +#include + +#include + +namespace yage +{ + +class SpriteBatch; + +/** Glyph with information of the texture. + */ +class Glyph +{ +private: + GLuint texture_; + float depth_; + Vertex top_left_; + Vertex top_right_; + Vertex bottom_right_; + 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); + + GLuint texture() const { return texture_; } + float depth() const { return depth_; } + Vertex top_left() const { return top_left_; } + Vertex top_right() const { return top_right_; } + Vertex bottom_right() const { return bottom_right_; } + Vertex bottom_left() const { return bottom_left_; } +}; + +class RenderBatch +{ + friend SpriteBatch; + +private: + GLsizei num_vertices_; + GLint offset_; + GLuint texture_; + +public: + RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); + + GLint offset() const { return offset_; } + GLsizei num_vertices() const { return num_vertices_; } + GLuint texture() const { return texture_; } +}; + +class SpriteBatch +{ +public: + static const int NUM_VERTICES = 6; + +private: + GLuint vbo_ = 0; + GLuint vao_ = 0; + std::vector glyphs_; + std::vector glyph_ptrs_; + std::vector render_batches_; + +public: + SpriteBatch(); + SpriteBatch(const SpriteBatch &) = delete; + SpriteBatch(SpriteBatch &&) = delete; + ~SpriteBatch(); + + 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); + // render the batch + void render(); + +private: + void createVertexArray(); + void createRenderBatches(); + void sortGlyphs(); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp deleted file mode 100644 index add58b43..00000000 --- a/include/YAGE/spritebatch.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/* ---------------------------------------------------------------------------- - * spritebatch.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_SPRITE_BATCH_HPP -#define YAGE_SPRITE_BATCH_HPP - -#include "vertex.hpp" - -#include -#include - -#include - -namespace yage -{ - -class SpriteBatch; - -/** Glyph with information of the texture. - */ -class Glyph -{ -private: - GLuint texture_; - float depth_; - Vertex top_left_; - Vertex top_right_; - Vertex bottom_right_; - 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); - - GLuint texture() const { return texture_; } - float depth() const { return depth_; } - Vertex top_left() const { return top_left_; } - Vertex top_right() const { return top_right_; } - Vertex bottom_right() const { return bottom_right_; } - Vertex bottom_left() const { return bottom_left_; } -}; - -class RenderBatch -{ - friend SpriteBatch; - -private: - GLsizei num_vertices_; - GLint offset_; - GLuint texture_; - -public: - RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); - - GLint offset() const { return offset_; } - GLsizei num_vertices() const { return num_vertices_; } - GLuint texture() const { return texture_; } -}; - -class SpriteBatch -{ -public: - static const int NUM_VERTICES = 6; - -private: - GLuint vbo_ = 0; - GLuint vao_ = 0; - std::vector glyphs_; - std::vector glyph_ptrs_; - std::vector render_batches_; - -public: - SpriteBatch(); - SpriteBatch(const SpriteBatch &) = delete; - SpriteBatch(SpriteBatch &&) = delete; - ~SpriteBatch(); - - 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); - // render the batch - void render(); - -private: - void createVertexArray(); - void createRenderBatches(); - void sortGlyphs(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/texture.h b/include/YAGE/texture.h new file mode 100644 index 00000000..d2cc3bdd --- /dev/null +++ b/include/YAGE/texture.h @@ -0,0 +1,25 @@ +/* ---------------------------------------------------------------------------- + * texture.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef GL_TEXTURE_HPP +#define GL_TEXTURE_HPP + +#include + +namespace yage +{ + +struct Texture { + GLuint id; + int width; + int height; +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/texture.hpp b/include/YAGE/texture.hpp deleted file mode 100644 index d2cc3bdd..00000000 --- a/include/YAGE/texture.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* ---------------------------------------------------------------------------- - * texture.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef GL_TEXTURE_HPP -#define GL_TEXTURE_HPP - -#include - -namespace yage -{ - -struct Texture { - GLuint id; - int width; - int height; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/texturecache.h b/include/YAGE/texturecache.h new file mode 100644 index 00000000..1542ad79 --- /dev/null +++ b/include/YAGE/texturecache.h @@ -0,0 +1,32 @@ +/* ---------------------------------------------------------------------------- + * texturecache.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef TEXTURE_CACHE_HPP +#define TEXTURE_CACHE_HPP + +#include "texture.hpp" + +#include + +namespace yage +{ + +class TextureCache +{ +private: + std::unordered_map texture_map_; + +public: + TextureCache(); + + Texture getTexture(const std::string &texture_path); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/texturecache.hpp b/include/YAGE/texturecache.hpp deleted file mode 100644 index 1542ad79..00000000 --- a/include/YAGE/texturecache.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* ---------------------------------------------------------------------------- - * texturecache.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef TEXTURE_CACHE_HPP -#define TEXTURE_CACHE_HPP - -#include "texture.hpp" - -#include - -namespace yage -{ - -class TextureCache -{ -private: - std::unordered_map texture_map_; - -public: - TextureCache(); - - Texture getTexture(const std::string &texture_path); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/vertex.h b/include/YAGE/vertex.h new file mode 100644 index 00000000..ef379888 --- /dev/null +++ b/include/YAGE/vertex.h @@ -0,0 +1,84 @@ +/* ---------------------------------------------------------------------------- + * vertex.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef VERTEX_HPP +#define VERTEX_HPP + +#include + +namespace yage +{ + +struct Position { + float x; + float y; + + Position() = default; + + Position(float x_, float y_) : x(x_), y(y_) {} +}; + +struct Color { + GLubyte r; + GLubyte g; + GLubyte b; + GLubyte a; + + Color() = default; + + Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) + : r(r_), g(g_), b(b_), a(a_) + { + } +}; + +struct UV { + float u; + float v; + + UV() = default; + + UV(float u_, float v_) : u(u_), v(v_) {} +}; + +struct Vertex { + Position position; + Color color; + UV uv; + + Vertex() = default; + + Vertex(const Position &position_, const Color &color_, const UV &uv_) + : position(position_), color(color_), uv(uv_) + { + } + + void setPosition(float x, float y) + { + position.x = x; + position.y = y; + } + + 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) + { + uv.u = u; + uv.v = v; + } +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/vertex.hpp b/include/YAGE/vertex.hpp deleted file mode 100644 index ef379888..00000000 --- a/include/YAGE/vertex.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/* ---------------------------------------------------------------------------- - * vertex.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef VERTEX_HPP -#define VERTEX_HPP - -#include - -namespace yage -{ - -struct Position { - float x; - float y; - - Position() = default; - - Position(float x_, float y_) : x(x_), y(y_) {} -}; - -struct Color { - GLubyte r; - GLubyte g; - GLubyte b; - GLubyte a; - - Color() = default; - - Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) - : r(r_), g(g_), b(b_), a(a_) - { - } -}; - -struct UV { - float u; - float v; - - UV() = default; - - UV(float u_, float v_) : u(u_), v(v_) {} -}; - -struct Vertex { - Position position; - Color color; - UV uv; - - Vertex() = default; - - Vertex(const Position &position_, const Color &color_, const UV &uv_) - : position(position_), color(color_), uv(uv_) - { - } - - void setPosition(float x, float y) - { - position.x = x; - position.y = y; - } - - 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) - { - uv.u = u; - uv.v = v; - } -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/window.h b/include/YAGE/window.h new file mode 100644 index 00000000..51b217f8 --- /dev/null +++ b/include/YAGE/window.h @@ -0,0 +1,55 @@ +/* ---------------------------------------------------------------------------- + * window.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#ifndef WINDOW_HPP +#define WINDOW_HPP + +#include + +#include + +namespace yage +{ + +// window flags that can change it's appearance +enum WindowFlags : unsigned { + SHOWN = 0x1, + HIDDEN = 0x2, + FULLSCREEN = 0x4, + BORDERLESS = 0x8, +}; + +// window wrapper around SDL_Window pointer +class Window +{ +private: + /// window handle + SDL_Window *window_ = nullptr; + +public: + Window(); + Window(const Window &) = delete; + Window(Window &&) = delete; + /// destroys the window handle + ~Window(); + + 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, + unsigned flags = WindowFlags::SHOWN); + /// swap the buffer + void swapBuffer(); + /// clear buffer + void clearBuffer(); +}; + +} // namespace yage + +#endif diff --git a/include/YAGE/window.hpp b/include/YAGE/window.hpp deleted file mode 100644 index 51b217f8..00000000 --- a/include/YAGE/window.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* ---------------------------------------------------------------------------- - * window.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef WINDOW_HPP -#define WINDOW_HPP - -#include - -#include - -namespace yage -{ - -// window flags that can change it's appearance -enum WindowFlags : unsigned { - SHOWN = 0x1, - HIDDEN = 0x2, - FULLSCREEN = 0x4, - BORDERLESS = 0x8, -}; - -// window wrapper around SDL_Window pointer -class Window -{ -private: - /// window handle - SDL_Window *window_ = nullptr; - -public: - Window(); - Window(const Window &) = delete; - Window(Window &&) = delete; - /// destroys the window handle - ~Window(); - - 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, - unsigned flags = WindowFlags::SHOWN); - /// swap the buffer - void swapBuffer(); - /// clear buffer - void clearBuffer(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/yage.h b/include/YAGE/yage.h new file mode 100644 index 00000000..13d6d560 --- /dev/null +++ b/include/YAGE/yage.h @@ -0,0 +1,63 @@ +/* ---------------------------------------------------------------------------- + * yage.hpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +/** @file Includes all the headers in the main YAGE project. + * + * This does not include + */ + +#ifndef YAGE_HPP +#define YAGE_HPP + +#include "camera2d.hpp" +#include "glslprogram.hpp" +#include "imageloader.hpp" +#include "inputmanager.hpp" +#include "iomanager.hpp" +#include "picopng.hpp" +#include "resourcemanager.hpp" +#include "spritebatch.hpp" +#include "texture.hpp" +#include "vertex.hpp" +#include "window.hpp" + +#include + +#include + +/** Project namespace. + * + * Avoids collision as all the classes and global functions are wrapped in. + * it. + */ +namespace yage +{ + +/** Initializes YAGE. + * + * This is only there to initialize SDL2. + * + * @return Returns true if the initialization was successful. + */ +bool init() +{ + return SDL_Init(SDL_INIT_VIDEO); +} + +/** Quit and cleanup YAGE + * + * SDL2 needs to clean itself up. + */ +void quit() +{ + SDL_Quit(); +} + +} // namespace yage + +#endif diff --git a/include/YAGE/yage.hpp b/include/YAGE/yage.hpp deleted file mode 100644 index 13d6d560..00000000 --- a/include/YAGE/yage.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* ---------------------------------------------------------------------------- - * yage.hpp - * - * Copyright (c) 2017 Yann Herklotz Grave -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -/** @file Includes all the headers in the main YAGE project. - * - * This does not include - */ - -#ifndef YAGE_HPP -#define YAGE_HPP - -#include "camera2d.hpp" -#include "glslprogram.hpp" -#include "imageloader.hpp" -#include "inputmanager.hpp" -#include "iomanager.hpp" -#include "picopng.hpp" -#include "resourcemanager.hpp" -#include "spritebatch.hpp" -#include "texture.hpp" -#include "vertex.hpp" -#include "window.hpp" - -#include - -#include - -/** Project namespace. - * - * Avoids collision as all the classes and global functions are wrapped in. - * it. - */ -namespace yage -{ - -/** Initializes YAGE. - * - * This is only there to initialize SDL2. - * - * @return Returns true if the initialization was successful. - */ -bool init() -{ - return SDL_Init(SDL_INIT_VIDEO); -} - -/** Quit and cleanup YAGE - * - * SDL2 needs to clean itself up. - */ -void quit() -{ - SDL_Quit(); -} - -} // namespace yage - -#endif diff --git a/src/camera2d.cpp b/src/camera2d.cpp index 0ddd454e..7f2dd2d7 100644 --- a/src/camera2d.cpp +++ b/src/camera2d.cpp @@ -22,14 +22,14 @@ Camera2D::Camera2D(int screen_width, int screen_height) void Camera2D::update(GlslProgram &program) { - if (matrix_needs_update_) { + if (update_matrix_) { glm::vec3 translate(-position_.x, -position_.y, 0.f); glm::vec3 scale(scale_, scale_, 0.f); camera_matrix_ = glm::translate(ortho_matrix_, translate); camera_matrix_ = glm::scale(glm::mat4(1.f), scale) * camera_matrix_; - matrix_needs_update_ = false; + update_matrix_ = false; } GLint matrix_location = program.getUniformLocation("P"); @@ -39,7 +39,7 @@ void Camera2D::update(GlslProgram &program) void Camera2D::move(const glm::vec2 &direction) { position_ += direction; - matrix_needs_update_ = true; + update_matrix_ = true; } } // namespace yage -- cgit