From 41b27388646a8159de3830dc21dcf3ac2519bd8e Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 21 Aug 2017 20:54:29 +0100 Subject: Updating docs --- annotated.html | 2 +- body_8hpp_source.html | 4 ++-- camera2d_8hpp_source.html | 2 +- classes.html | 2 +- classyage_1_1Glyph-members.html | 2 +- classyage_1_1Glyph.html | 2 +- classyage_1_1Matrix-members.html | 9 ++++++--- classyage_1_1Matrix.html | 14 +++++++++++++- classyage_1_1Vector2-members.html | 8 +++++--- classyage_1_1Vector2.html | 2 +- collider_8hpp_source.html | 2 +- collisionbody_8hpp_source.html | 2 +- dir_5ac3a90c14a160db9539610948ce4998.html | 2 +- dir_68267d1309a1af8e8297ef4c3efbcdba.html | 2 +- dir_b233a2caca2b45d5ef987dbbf49782d0.html | 2 +- dir_d44c64559bbebec7f509842c48db8b23.html | 2 +- dir_f562165b51c585c003877be645f219b5.html | 2 +- files.html | 2 +- functions.html | 11 ++++++++++- functions_func.html | 11 ++++++++++- functions_vars.html | 2 +- glslprogram_8hpp_source.html | 2 +- hierarchy.html | 2 +- imageloader_8hpp_source.html | 2 +- index.html | 2 +- inputmanager_8hpp_source.html | 2 +- iomanager_8hpp_source.html | 2 +- math_8hpp_source.html | 2 +- matrix_8hpp.html | 2 +- matrix_8hpp_source.html | 15 +++++++++------ md_README.html | 2 +- md_docs_README.html | 2 +- namespacemembers.html | 2 +- namespacemembers_func.html | 2 +- namespaces.html | 2 +- namespaceyage_1_1matrix.html | 2 +- pages.html | 2 +- particlebody_8hpp_source.html | 4 ++-- physics_8hpp_source.html | 2 +- picopng_8hpp_source.html | 4 ++-- rectanglecollider_8hpp_source.html | 2 +- resourcemanager_8hpp_source.html | 2 +- rigidbody_8hpp_source.html | 4 ++-- search/all_0.js | 2 +- search/all_1.js | 4 +--- search/all_2.js | 5 +++-- search/all_3.js | 6 +----- search/all_4.js | 3 ++- search/all_5.js | 6 +++++- search/all_6.js | 4 +--- search/all_7.js | 4 ++-- search/all_8.html | 26 ++++++++++++++++++++++++++ search/all_8.js | 6 ++++++ search/all_9.html | 26 ++++++++++++++++++++++++++ search/all_9.js | 5 +++++ search/functions_0.js | 2 +- search/functions_1.js | 2 +- search/functions_2.js | 2 +- search/functions_3.js | 3 +-- search/functions_4.js | 2 +- search/functions_5.js | 3 ++- search/functions_6.html | 26 ++++++++++++++++++++++++++ search/functions_6.js | 4 ++++ search/functions_7.html | 26 ++++++++++++++++++++++++++ search/functions_7.js | 5 +++++ search/searchdata.js | 4 ++-- sprite_8hpp_source.html | 2 +- spritebatch_8hpp_source.html | 4 ++-- texture_8hpp_source.html | 2 +- texturecache_8hpp_source.html | 2 +- vertex_8hpp_source.html | 2 +- window_8hpp_source.html | 2 +- yage_8hpp_source.html | 2 +- 73 files changed, 251 insertions(+), 91 deletions(-) create mode 100644 search/all_8.html create mode 100644 search/all_8.js create mode 100644 search/all_9.html create mode 100644 search/all_9.js create mode 100644 search/functions_6.html create mode 100644 search/functions_6.js create mode 100644 search/functions_7.html create mode 100644 search/functions_7.js diff --git a/annotated.html b/annotated.html index 3343fe52..ade4b1ef 100644 --- a/annotated.html +++ b/annotated.html @@ -75,7 +75,7 @@ $(function() { diff --git a/body_8hpp_source.html b/body_8hpp_source.html index 5c690c90..67fbda66 100644 --- a/body_8hpp_source.html +++ b/body_8hpp_source.html @@ -69,12 +69,12 @@ $(function() {
1 /* ----------------------------------------------------------------------------
2  * body.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_PHYSICS_BODY_HPP
10 #define YAGE_PHYSICS_BODY_HPP
11 
12 #include "Math/matrix.hpp"
13 
14 namespace yage {
15 class Body {
16 public:
17  // gravity constant
18  static const double GRAVITY;
19 
20 protected:
21  // center of mass of the object
22  Vector2d position_ = Vector2d(0, 0);
23 
24  // mass of the object
25  double mass_ = 1;
26 
27  // current velocity of the object
28  Vector2d velocity_ = Vector2d(0, 0);
29 
30  // boolean that defines if gravity can act on the object
31  bool gravity_ = true;
32 
33  // current acceleration
34  Vector2d acceleration_ = Vector2d(0, 0);
35 
36  // force acting on the body
37  Vector2d force_ = Vector2d(0, 0);
38 
39 public:
40  // apply force to the object and update the velocity
41  virtual void applyForce(const Vector2d& force) = 0;
42  virtual void update() = 0;
43 
44  double xPosition() const;
45  double yPosition() const;
46 
47 protected:
48  // protected constructor to initialize member variables
49  Body(const Vector2d& position = Vector2d(0, 0), double mass = 1, const Vector2d& velocity = Vector2d(0, 0), bool gravity = false);
50 };
51 } // namespace yage
52 
53 #endif
Templated matrix class.
-
Vector2< double > Vector2d
Definition of a 2D vector.
Definition: matrix.hpp:313
+
Vector2< double > Vector2d
Definition of a 2D vector.
Definition: matrix.hpp:314
Definition: camera2d.hpp:17
diff --git a/camera2d_8hpp_source.html b/camera2d_8hpp_source.html index fb0ba693..88e016c9 100644 --- a/camera2d_8hpp_source.html +++ b/camera2d_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/classes.html b/classes.html index 50c0e04d..937f882f 100644 --- a/classes.html +++ b/classes.html @@ -78,7 +78,7 @@ $(function() { diff --git a/classyage_1_1Glyph-members.html b/classyage_1_1Glyph-members.html index b107c42c..1fd3edb0 100644 --- a/classyage_1_1Glyph-members.html +++ b/classyage_1_1Glyph-members.html @@ -74,7 +74,7 @@ $(function() { diff --git a/classyage_1_1Glyph.html b/classyage_1_1Glyph.html index d25826d0..8952fe5a 100644 --- a/classyage_1_1Glyph.html +++ b/classyage_1_1Glyph.html @@ -84,7 +84,7 @@ $(function() { diff --git a/classyage_1_1Matrix-members.html b/classyage_1_1Matrix-members.html index b8c020ba..266b0cc6 100644 --- a/classyage_1_1Matrix-members.html +++ b/classyage_1_1Matrix-members.html @@ -71,15 +71,18 @@ $(function() {

This is the complete list of members for yage::Matrix< Rows, Cols, Type >, including all inherited members.

- - + + + + +
colSize() constyage::Matrix< Rows, Cols, Type >inline
data_yage::Matrix< Rows, Cols, Type >protected
begin()yage::Matrix< Rows, Cols, Type >inline
colSize() constyage::Matrix< Rows, Cols, Type >inline
data_yage::Matrix< Rows, Cols, Type >protected
end()yage::Matrix< Rows, Cols, Type >inline
getRow(int row) constyage::Matrix< Rows, Cols, Type >inline
Matrix()yage::Matrix< Rows, Cols, Type >inline
rowSize() constyage::Matrix< Rows, Cols, Type >inline
toString() constyage::Matrix< Rows, Cols, Type >inlinevirtual
diff --git a/classyage_1_1Matrix.html b/classyage_1_1Matrix.html index e4e7ea88..1b51e1bf 100644 --- a/classyage_1_1Matrix.html +++ b/classyage_1_1Matrix.html @@ -95,6 +95,18 @@ int Matrix< 1, Cols, Type > getRow (int row) const  Return the row specified row as a Matrix with only one row. More...
  + +std::vector< Type >::iterator begin () + iterator support for begin
+  + +std::vector< Type >::iterator end () + iterator support for end
+  + +virtual std::string toString () const + prints out the matrix, but can also be implemented by other classes to print data differently
+  @@ -154,7 +166,7 @@ template<int Rows = 4, int Cols = 4, class Type = double> diff --git a/classyage_1_1Vector2-members.html b/classyage_1_1Vector2-members.html index 6109e940..8fdc2462 100644 --- a/classyage_1_1Vector2-members.html +++ b/classyage_1_1Vector2-members.html @@ -71,15 +71,17 @@ $(function() {

This is the complete list of members for yage::Vector2< Type >, including all inherited members.

Protected Attributes

- - + + + +
colSize() constyage::Matrix< Rows, 1, Type >inline
data_yage::Matrix< Rows, 1, Type >protected
begin()yage::Matrix< Rows, 1, Type >inline
colSize() constyage::Matrix< Rows, 1, Type >inline
data_yage::Matrix< Rows, 1, Type >protected
end()yage::Matrix< Rows, 1, Type >inline
getRow(int row) constyage::Matrix< Rows, 1, Type >inline
Matrix()yage::Matrix< Rows, 1, Type >inline
rowSize() constyage::Matrix< Rows, 1, Type >inline
diff --git a/classyage_1_1Vector2.html b/classyage_1_1Vector2.html index 3fb2a17e..ab3801f6 100644 --- a/classyage_1_1Vector2.html +++ b/classyage_1_1Vector2.html @@ -89,7 +89,7 @@ class yage::Vector2< Type > diff --git a/collider_8hpp_source.html b/collider_8hpp_source.html index 55c8c165..0573cab3 100644 --- a/collider_8hpp_source.html +++ b/collider_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/collisionbody_8hpp_source.html b/collisionbody_8hpp_source.html index 60b1197a..4bec29de 100644 --- a/collisionbody_8hpp_source.html +++ b/collisionbody_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/dir_5ac3a90c14a160db9539610948ce4998.html b/dir_5ac3a90c14a160db9539610948ce4998.html index bf6a927b..bc5201e5 100644 --- a/dir_5ac3a90c14a160db9539610948ce4998.html +++ b/dir_5ac3a90c14a160db9539610948ce4998.html @@ -78,7 +78,7 @@ Files diff --git a/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 0512fd74..772f3095 100644 --- a/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -71,7 +71,7 @@ $(function() { diff --git a/dir_b233a2caca2b45d5ef987dbbf49782d0.html b/dir_b233a2caca2b45d5ef987dbbf49782d0.html index 1228d2d0..85f63058 100644 --- a/dir_b233a2caca2b45d5ef987dbbf49782d0.html +++ b/dir_b233a2caca2b45d5ef987dbbf49782d0.html @@ -71,7 +71,7 @@ $(function() { diff --git a/dir_d44c64559bbebec7f509842c48db8b23.html b/dir_d44c64559bbebec7f509842c48db8b23.html index dc7dc80b..fddbcbd1 100644 --- a/dir_d44c64559bbebec7f509842c48db8b23.html +++ b/dir_d44c64559bbebec7f509842c48db8b23.html @@ -75,7 +75,7 @@ Directories diff --git a/dir_f562165b51c585c003877be645f219b5.html b/dir_f562165b51c585c003877be645f219b5.html index d011e813..00e8ea60 100644 --- a/dir_f562165b51c585c003877be645f219b5.html +++ b/dir_f562165b51c585c003877be645f219b5.html @@ -75,7 +75,7 @@ Directories diff --git a/files.html b/files.html index 9e8c2d32..28800373 100644 --- a/files.html +++ b/files.html @@ -98,7 +98,7 @@ $(function() { diff --git a/functions.html b/functions.html index 72f8cc4f..d0a6c55e 100644 --- a/functions.html +++ b/functions.html @@ -61,12 +61,18 @@ $(function() {
Here is a list of all documented class members with links to the class documentation for each member:
diff --git a/functions_func.html b/functions_func.html index 3680146d..78396290 100644 --- a/functions_func.html +++ b/functions_func.html @@ -61,9 +61,15 @@ $(function() {
 
diff --git a/functions_vars.html b/functions_vars.html index 7673bf72..28dd8ef6 100644 --- a/functions_vars.html +++ b/functions_vars.html @@ -68,7 +68,7 @@ $(function() { diff --git a/glslprogram_8hpp_source.html b/glslprogram_8hpp_source.html index 9264a1e4..68587eb0 100644 --- a/glslprogram_8hpp_source.html +++ b/glslprogram_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/hierarchy.html b/hierarchy.html index 1f803a1a..def36f3b 100644 --- a/hierarchy.html +++ b/hierarchy.html @@ -77,7 +77,7 @@ $(function() { diff --git a/imageloader_8hpp_source.html b/imageloader_8hpp_source.html index cec7b450..42649bed 100644 --- a/imageloader_8hpp_source.html +++ b/imageloader_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/index.html b/index.html index 931c473f..dac957b2 100644 --- a/index.html +++ b/index.html @@ -67,7 +67,7 @@ $(function() { diff --git a/inputmanager_8hpp_source.html b/inputmanager_8hpp_source.html index 80a300de..7344aa87 100644 --- a/inputmanager_8hpp_source.html +++ b/inputmanager_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/iomanager_8hpp_source.html b/iomanager_8hpp_source.html index caefa921..6a9a8160 100644 --- a/iomanager_8hpp_source.html +++ b/iomanager_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/math_8hpp_source.html b/math_8hpp_source.html index a0dcb1f6..fb357a91 100644 --- a/math_8hpp_source.html +++ b/math_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/matrix_8hpp.html b/matrix_8hpp.html index ee3eca83..6cebe7ac 100644 --- a/matrix_8hpp.html +++ b/matrix_8hpp.html @@ -132,7 +132,7 @@ Functions diff --git a/matrix_8hpp_source.html b/matrix_8hpp_source.html index 3cacf5e6..2d51d501 100644 --- a/matrix_8hpp_source.html +++ b/matrix_8hpp_source.html @@ -68,20 +68,23 @@ $(function() {
matrix.hpp
-Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * matrix.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
19 #ifndef YAGE_MATH_MATRIX_HPP
20 #define YAGE_MATH_MATRIX_HPP
21 
22 #include <algorithm>
23 #include <exception>
24 #include <iostream>
25 #include <sstream>
26 #include <string>
27 #include <vector>
28 
29 namespace yage {
30 
31 template <int Rows, int Cols, class Type>
32 class Matrix;
33 
41 namespace detail {
42 
51 template <int Rows, int Cols, class Type>
52 class Row {
53 private:
54  Matrix<Rows, Cols, Type>* parent_;
55  int index_;
56 
57 public:
58  Row<Rows, Cols, Type>(Matrix<Rows, Cols, Type>* parent, int index)
59  : parent_(parent), index_(index) {}
60 
61  Type& operator[](int col) {
62  // the index is the y-position of the element in the matrix
63  return parent_->data_[index_ * Cols + col];
64  }
65 
66  const Type& operator[](int col) const {
67  return parent_->data_[index_ * Cols + col];
68  }
69 };
70 
71 } // detail
72 
81 template <int Rows = 4, int Cols = 4, class Type = double>
82 class Matrix {
83  // friended with the row class so that it can access protected member data
84  friend class detail::Row<Rows, Cols, Type>;
85 
86 protected:
88  std::vector<Type> data_;
89 
90 public:
92  Matrix<Rows, Cols, Type>() : data_(Rows * Cols) {}
93  Matrix<Rows, Cols, Type>(const std::vector<Type>& data) : data_(data) {}
94 
96  int rowSize() const { return Rows; }
97 
99  int colSize() const { return Cols; }
100 
107  Matrix<1, Cols, Type> getRow(int row) const {
108  Matrix<1, Cols, Type> rowMatrix;
109  for (int i = 0; i < Cols; ++i) {
110  rowMatrix[0][i] = data_[row][i];
111  }
112  return rowMatrix;
113  }
114 
115  // returns the column in a column matrix
116  Matrix<Rows, 1, Type> getCol(int col) const {
117  Matrix<Rows, 1, Type> colMatrix;
118  for (int i = 0; i < Rows; ++i) {
119  colMatrix[i][0] = data_[i][col];
120  }
121  return colMatrix;
122  }
123 
124  // iterator support for begin
125  typename std::vector<Type>::iterator begin() { return data_.begin(); }
126 
127  // iterator support for end
128  typename std::vector<Type>::iterator end() { return data_.end(); }
129 
130  // prints out the matrix, but can also be implemented by other classes to
131  // print data differently
132  virtual std::string toString() const {
133  std::stringstream ss;
134  ss << '[';
135  for (int i = 0; i < Rows - 1; ++i) {
136  ss << '[';
137  for (int j = 0; j < Cols - 1; ++j) {
138  ss << data_[i * Cols + j] << ' ';
139  }
140  ss << data_[(Rows - 1) * Cols + Cols - 1] << "],";
141  }
142  ss << '[';
143  for (int j = 0; j < Cols - 1; ++j) {
144  ss << data_[(Rows - 1) * Cols + j] << ' ';
145  }
146  ss << data_[(Rows - 1) * Cols + Cols - 1] << "]]";
147  return ss.str();
148  }
149 
150  detail::Row<Rows, Cols, Type> operator[](int row) {
151  return detail::Row<Rows, Cols, Type>(this, row);
152  }
153 
154  detail::Row<Rows, Cols, Type> operator[](int row) const {
155  // TODO got to fix this
156  return detail::Row<Rows, Cols, Type>((Matrix<Rows, Cols, Type>*)this,
157  row);
158  }
159 
160  Matrix<Rows, Cols, Type>& operator+=(const Matrix<Rows, Cols, Type>& rhs) {
161  std::vector<Type> out;
162  out.reserve(data_.size());
163  std::transform(data_.begin(), data_.end(), rhs.data_.begin(),
164  std::back_inserter(out),
165  [](Type a, Type b) { return a + b; });
166  data_ = std::move(out);
167  return *this;
168  }
169 
170  Matrix<Rows, Cols, Type>& operator-=(const Matrix<Rows, Cols, Type>& rhs) {
171  std::vector<Type> out;
172  out.reserve(data_.size());
173  std::transform(data_.begin(), data_.end(), rhs.begin(),
174  std::back_inserter(out),
175  [](Type a, Type b) { return a - b; });
176  data_ = std::move(out);
177  return *this;
178  }
179 };
180 
181 template <int M, int N, class T>
182 Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const Matrix<M, N, T>& rhs) {
183  lhs += rhs;
184  return lhs;
185 }
186 
187 template <int M, int N, class T>
188 Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const Matrix<M, N, T>& rhs) {
189  lhs -= rhs;
190  return lhs;
191 }
192 
193 template <int M, int N, class T>
194 Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const T& rhs) {
195  for (auto& data : lhs) {
196  data += rhs;
197  }
198  return lhs;
199 }
200 
201 template <int M, int N, class T>
202 Matrix<M, N, T> operator+(const T& lhs, Matrix<M, N, T> rhs) {
203  for (auto& data : rhs) {
204  data += lhs;
205  }
206  return rhs;
207 }
208 
209 template <int M, int N, class T>
210 Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const T& rhs) {
211  for (auto& data : lhs) {
212  data -= rhs;
213  }
214  return lhs;
215 }
216 
217 template <int M, int N, class T>
218 Matrix<M, N, T> operator-(const T& lhs, Matrix<M, N, T> rhs) {
219  for (auto& data : rhs) {
220  data = lhs - data;
221  }
222  return rhs;
223 }
224 
225 template <int M, int N, class T>
226 Matrix<M, N, T> operator*(Matrix<M, N, T> lhs, const T& rhs) {
227  for (auto& data : lhs) {
228  data *= rhs;
229  }
230  return lhs;
231 }
232 
233 template <int M, int N, class T>
234 Matrix<M, N, T> operator*(const T& lhs, Matrix<M, N, T> rhs) {
235  for (auto& data : rhs) {
236  data *= lhs;
237  }
238  return rhs;
239 }
240 
241 template <int M, int N, class T>
242 Matrix<M, N, T> operator/(Matrix<M, N, T> lhs, const T& rhs) {
243  for (auto& data : lhs) {
244  data /= rhs;
245  }
246  return lhs;
247 }
248 
249 template <int M, int N, class T>
250 bool operator==(const Matrix<M, N, T>& lhs, const Matrix<M, N, T>& rhs) {
251  for (int i = 0; i < M; ++i)
252  for (int j = 0; j < N; ++j)
253  if (lhs[i][j] != rhs[i][j]) return false;
254  return true;
255 }
256 
257 template <int M, int N, class T>
258 std::ostream& operator<<(std::ostream& os, const Matrix<M, N, T>& mat) {
259  return os << mat.toString();
260 }
261 
262 template <int Rows = 2, class Type = double>
263 class Vector : public Matrix<Rows, 1, Type> {
264 public:
265  Vector<Rows, Type>() : Matrix<Rows, 1, Type>() {}
266  Vector<Rows, Type>(const Matrix<Rows, 1, Type>& other)
267  : Matrix<Rows, 1, Type>(other) {}
268  Vector<Rows, Type>(const std::vector<Type>& data)
269  : Matrix<Rows, 1, Type>(data) {}
270 
271  Type& operator[](int col) { return this->data_[col]; }
272 
273  const Type& operator[](int col) const { return this->data_[col]; }
274 
275  virtual std::string toString() const {
276  std::stringstream ss;
277  ss << "[";
278  for (std::size_t i = 0; i < this->data_.size() - 1; ++i) {
279  ss << this->data_[i] << " ";
280  }
281  ss << this->data_[this->data_.size() - 1] << "]";
282  return ss.str();
283  }
284 };
285 
290 template <class Type = double>
291 class Vector2 : public Vector<2, Type> {
292 public:
293  Vector2<Type>() : Vector<2, Type>() {}
294  Vector2<Type>(const std::vector<Type>& data) : Vector<2, Type>(data) {}
295 
296  Vector2<Type>(Type x, Type y) {
297  this->data_[0] = x;
298  this->data_[1] = y;
299  }
300 
301  Vector2<Type>(const Matrix<2, 1, Type>& other) : Vector<2, Type>(other) {}
302 
303  Type& x() { return this->data_[0]; }
304 
305  const Type& x() const { return this->data_[0]; }
306 
307  Type& y() { return this->data_[1]; }
308 
309  const Type& y() const { return this->data_[1]; }
310 };
311 
314 
316 namespace matrix {
317 
322 template <int M, int N, class T>
324  Matrix<N, M, T> trans;
325  for (int i = 0; i < M; ++i) {
326  for (int j = 0; j < N; ++j) {
327  trans[j][i] = m[i][j];
328  }
329  }
330  return trans;
331 }
332 
337 template <int R, class T>
338 T dot(const Matrix<R, 1, T>& m1, const Matrix<R, 1, T>& m2) {
339  T sum = 0;
340  for (int i = 0; i < R; ++i) {
341  sum += m1[i][0] * m2[i][0];
342  }
343  return sum;
344 }
345 
352 template <int M, int N, int P, int Q, class T>
354  if (N != P) {
355  throw std::runtime_error(
356  "Matrices don't have the right dimensions for multiplication");
357  }
358 
359  Matrix<M, Q, T> res;
360 
361  for (int i = 0; i < M; ++i) {
362  for (int j = 0; j < Q; ++j) {
363  res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j));
364  }
365  }
366 
367  return res;
368 }
369 
370 } // matrix
371 
372 } // yage
373 
374 #endif
int rowSize() const
Returns the row size of the Matrix.
Definition: matrix.hpp:96
+Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * matrix.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
19 #ifndef YAGE_MATH_MATRIX_HPP
20 #define YAGE_MATH_MATRIX_HPP
21 
22 #include <algorithm>
23 #include <exception>
24 #include <iostream>
25 #include <sstream>
26 #include <string>
27 #include <vector>
28 
29 namespace yage {
30 
31 template <int Rows, int Cols, class Type>
32 class Matrix;
33 
41 namespace detail {
42 
51 template <int Rows, int Cols, class Type>
52 class Row {
53 private:
54  Matrix<Rows, Cols, Type>* parent_;
55  int index_;
56 
57 public:
58  Row<Rows, Cols, Type>(Matrix<Rows, Cols, Type>* parent, int index)
59  : parent_(parent), index_(index) {}
60 
61  Type& operator[](int col) {
62  // the index is the y-position of the element in the matrix
63  return parent_->data_[index_ * Cols + col];
64  }
65 
66  const Type& operator[](int col) const {
67  return parent_->data_[index_ * Cols + col];
68  }
69 };
70 
71 } // detail
72 
81 template <int Rows = 4, int Cols = 4, class Type = double>
82 class Matrix {
83  // friended with the row class so that it can access protected member data
84  friend class detail::Row<Rows, Cols, Type>;
85 
86 protected:
88  std::vector<Type> data_;
89 
90 public:
92  Matrix<Rows, Cols, Type>() : data_(Rows * Cols) {}
93  Matrix<Rows, Cols, Type>(const std::vector<Type>& data) : data_(data) {}
94 
96  int rowSize() const { return Rows; }
97 
99  int colSize() const { return Cols; }
100 
107  Matrix<1, Cols, Type> getRow(int row) const {
108  Matrix<1, Cols, Type> rowMatrix;
109  for (int i = 0; i < Cols; ++i) {
110  rowMatrix[0][i] = data_[row][i];
111  }
112  return rowMatrix;
113  }
114 
115  // returns the column in a column matrix
116  Matrix<Rows, 1, Type> getCol(int col) const {
117  Matrix<Rows, 1, Type> colMatrix;
118  for (int i = 0; i < Rows; ++i) {
119  colMatrix[i][0] = data_[i][col];
120  }
121  return colMatrix;
122  }
123 
125  typename std::vector<Type>::iterator begin() { return data_.begin(); }
126 
128  typename std::vector<Type>::iterator end() { return data_.end(); }
129 
133  virtual std::string toString() const {
134  std::stringstream ss;
135  ss << '[';
136  for (int i = 0; i < Rows - 1; ++i) {
137  ss << '[';
138  for (int j = 0; j < Cols - 1; ++j) {
139  ss << data_[i * Cols + j] << ' ';
140  }
141  ss << data_[(Rows - 1) * Cols + Cols - 1] << "],";
142  }
143  ss << '[';
144  for (int j = 0; j < Cols - 1; ++j) {
145  ss << data_[(Rows - 1) * Cols + j] << ' ';
146  }
147  ss << data_[(Rows - 1) * Cols + Cols - 1] << "]]";
148  return ss.str();
149  }
150 
151  detail::Row<Rows, Cols, Type> operator[](int row) {
152  return detail::Row<Rows, Cols, Type>(this, row);
153  }
154 
155  detail::Row<Rows, Cols, Type> operator[](int row) const {
156  // TODO got to fix this
157  return detail::Row<Rows, Cols, Type>((Matrix<Rows, Cols, Type>*)this,
158  row);
159  }
160 
161  Matrix<Rows, Cols, Type>& operator+=(const Matrix<Rows, Cols, Type>& rhs) {
162  std::vector<Type> out;
163  out.reserve(data_.size());
164  std::transform(data_.begin(), data_.end(), rhs.data_.begin(),
165  std::back_inserter(out),
166  [](Type a, Type b) { return a + b; });
167  data_ = std::move(out);
168  return *this;
169  }
170 
171  Matrix<Rows, Cols, Type>& operator-=(const Matrix<Rows, Cols, Type>& rhs) {
172  std::vector<Type> out;
173  out.reserve(data_.size());
174  std::transform(data_.begin(), data_.end(), rhs.begin(),
175  std::back_inserter(out),
176  [](Type a, Type b) { return a - b; });
177  data_ = std::move(out);
178  return *this;
179  }
180 };
181 
182 template <int M, int N, class T>
183 Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const Matrix<M, N, T>& rhs) {
184  lhs += rhs;
185  return lhs;
186 }
187 
188 template <int M, int N, class T>
189 Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const Matrix<M, N, T>& rhs) {
190  lhs -= rhs;
191  return lhs;
192 }
193 
194 template <int M, int N, class T>
195 Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const T& rhs) {
196  for (auto& data : lhs) {
197  data += rhs;
198  }
199  return lhs;
200 }
201 
202 template <int M, int N, class T>
203 Matrix<M, N, T> operator+(const T& lhs, Matrix<M, N, T> rhs) {
204  for (auto& data : rhs) {
205  data += lhs;
206  }
207  return rhs;
208 }
209 
210 template <int M, int N, class T>
211 Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const T& rhs) {
212  for (auto& data : lhs) {
213  data -= rhs;
214  }
215  return lhs;
216 }
217 
218 template <int M, int N, class T>
219 Matrix<M, N, T> operator-(const T& lhs, Matrix<M, N, T> rhs) {
220  for (auto& data : rhs) {
221  data = lhs - data;
222  }
223  return rhs;
224 }
225 
226 template <int M, int N, class T>
227 Matrix<M, N, T> operator*(Matrix<M, N, T> lhs, const T& rhs) {
228  for (auto& data : lhs) {
229  data *= rhs;
230  }
231  return lhs;
232 }
233 
234 template <int M, int N, class T>
235 Matrix<M, N, T> operator*(const T& lhs, Matrix<M, N, T> rhs) {
236  for (auto& data : rhs) {
237  data *= lhs;
238  }
239  return rhs;
240 }
241 
242 template <int M, int N, class T>
243 Matrix<M, N, T> operator/(Matrix<M, N, T> lhs, const T& rhs) {
244  for (auto& data : lhs) {
245  data /= rhs;
246  }
247  return lhs;
248 }
249 
250 template <int M, int N, class T>
251 bool operator==(const Matrix<M, N, T>& lhs, const Matrix<M, N, T>& rhs) {
252  for (int i = 0; i < M; ++i)
253  for (int j = 0; j < N; ++j)
254  if (lhs[i][j] != rhs[i][j]) return false;
255  return true;
256 }
257 
258 template <int M, int N, class T>
259 std::ostream& operator<<(std::ostream& os, const Matrix<M, N, T>& mat) {
260  return os << mat.toString();
261 }
262 
263 template <int Rows = 2, class Type = double>
264 class Vector : public Matrix<Rows, 1, Type> {
265 public:
266  Vector<Rows, Type>() : Matrix<Rows, 1, Type>() {}
267  Vector<Rows, Type>(const Matrix<Rows, 1, Type>& other)
268  : Matrix<Rows, 1, Type>(other) {}
269  Vector<Rows, Type>(const std::vector<Type>& data)
270  : Matrix<Rows, 1, Type>(data) {}
271 
272  Type& operator[](int col) { return this->data_[col]; }
273 
274  const Type& operator[](int col) const { return this->data_[col]; }
275 
276  virtual std::string toString() const {
277  std::stringstream ss;
278  ss << "[";
279  for (std::size_t i = 0; i < this->data_.size() - 1; ++i) {
280  ss << this->data_[i] << " ";
281  }
282  ss << this->data_[this->data_.size() - 1] << "]";
283  return ss.str();
284  }
285 };
286 
291 template <class Type = double>
292 class Vector2 : public Vector<2, Type> {
293 public:
294  Vector2<Type>() : Vector<2, Type>() {}
295  Vector2<Type>(const std::vector<Type>& data) : Vector<2, Type>(data) {}
296 
297  Vector2<Type>(Type x, Type y) {
298  this->data_[0] = x;
299  this->data_[1] = y;
300  }
301 
302  Vector2<Type>(const Matrix<2, 1, Type>& other) : Vector<2, Type>(other) {}
303 
304  Type& x() { return this->data_[0]; }
305 
306  const Type& x() const { return this->data_[0]; }
307 
308  Type& y() { return this->data_[1]; }
309 
310  const Type& y() const { return this->data_[1]; }
311 };
312 
315 
317 namespace matrix {
318 
323 template <int M, int N, class T>
325  Matrix<N, M, T> trans;
326  for (int i = 0; i < M; ++i) {
327  for (int j = 0; j < N; ++j) {
328  trans[j][i] = m[i][j];
329  }
330  }
331  return trans;
332 }
333 
338 template <int R, class T>
339 T dot(const Matrix<R, 1, T>& m1, const Matrix<R, 1, T>& m2) {
340  T sum = 0;
341  for (int i = 0; i < R; ++i) {
342  sum += m1[i][0] * m2[i][0];
343  }
344  return sum;
345 }
346 
353 template <int M, int N, int P, int Q, class T>
355  if (N != P) {
356  throw std::runtime_error(
357  "Matrices don't have the right dimensions for multiplication");
358  }
359 
360  Matrix<M, Q, T> res;
361 
362  for (int i = 0; i < M; ++i) {
363  for (int j = 0; j < Q; ++j) {
364  res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j));
365  }
366  }
367 
368  return res;
369 }
370 
371 } // matrix
372 
373 } // yage
374 
375 #endif
int rowSize() const
Returns the row size of the Matrix.
Definition: matrix.hpp:96
int colSize() const
Returns the column size of the Matrixxs.
Definition: matrix.hpp:99
-
2D Vector class.
Definition: matrix.hpp:291
+
2D Vector class.
Definition: matrix.hpp:292
+
std::vector< Type >::iterator end()
iterator support for end
Definition: matrix.hpp:128
std::vector< Type > data_
Vector containing the data of the matrix.
Definition: matrix.hpp:88
-
Matrix< M, Q, T > multiply(const Matrix< M, N, T > &m1, const Matrix< P, Q, T > &m2)
Multiplies two matrices together.
Definition: matrix.hpp:353
-
Matrix< N, M, T > transpose(const Matrix< M, N, T > &m)
Transposes a matrix and returns the result.
Definition: matrix.hpp:323
+
Matrix< M, Q, T > multiply(const Matrix< M, N, T > &m1, const Matrix< P, Q, T > &m2)
Multiplies two matrices together.
Definition: matrix.hpp:354
+
Matrix< N, M, T > transpose(const Matrix< M, N, T > &m)
Transposes a matrix and returns the result.
Definition: matrix.hpp:324
Base Matrix class used by other similar classes.
Definition: matrix.hpp:32
-
T dot(const Matrix< R, 1, T > &m1, const Matrix< R, 1, T > &m2)
Returns the dot product between two vectors.
Definition: matrix.hpp:338
+
virtual std::string toString() const
prints out the matrix, but can also be implemented by other classes to print data differently ...
Definition: matrix.hpp:133
+
T dot(const Matrix< R, 1, T > &m1, const Matrix< R, 1, T > &m2)
Returns the dot product between two vectors.
Definition: matrix.hpp:339
Matrix< 1, Cols, Type > getRow(int row) const
Return the row specified row as a Matrix with only one row.
Definition: matrix.hpp:107
Definition: camera2d.hpp:17
+
std::vector< Type >::iterator begin()
iterator support for begin
Definition: matrix.hpp:125
diff --git a/md_README.html b/md_README.html index a3def9bc..1d9723ac 100644 --- a/md_README.html +++ b/md_README.html @@ -70,7 +70,7 @@ $(function() {
diff --git a/md_docs_README.html b/md_docs_README.html index 0151bbcd..ee45230a 100644 --- a/md_docs_README.html +++ b/md_docs_README.html @@ -68,7 +68,7 @@ $(function() { diff --git a/namespacemembers.html b/namespacemembers.html index d77aa2c4..0bb2904b 100644 --- a/namespacemembers.html +++ b/namespacemembers.html @@ -74,7 +74,7 @@ $(function() { diff --git a/namespacemembers_func.html b/namespacemembers_func.html index ce1c0e4e..9ad261ae 100644 --- a/namespacemembers_func.html +++ b/namespacemembers_func.html @@ -74,7 +74,7 @@ $(function() { diff --git a/namespaces.html b/namespaces.html index eb950963..a8397fc2 100644 --- a/namespaces.html +++ b/namespaces.html @@ -73,7 +73,7 @@ $(function() { diff --git a/namespaceyage_1_1matrix.html b/namespaceyage_1_1matrix.html index cb3af0fc..a674fc0f 100644 --- a/namespaceyage_1_1matrix.html +++ b/namespaceyage_1_1matrix.html @@ -200,7 +200,7 @@ template<int M, int N, class T > diff --git a/pages.html b/pages.html index bdcfda79..f9f11ef5 100644 --- a/pages.html +++ b/pages.html @@ -73,7 +73,7 @@ $(function() { diff --git a/particlebody_8hpp_source.html b/particlebody_8hpp_source.html index dfb8f070..be762175 100644 --- a/particlebody_8hpp_source.html +++ b/particlebody_8hpp_source.html @@ -69,12 +69,12 @@ $(function() {
1 /* ----------------------------------------------------------------------------
2  * particlebody.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_PARTICLE_BODY_HPP
10 #define YAGE_PARTICLE_BODY_HPP
11 
12 #include "Math/matrix.hpp"
13 
14 #include "body.hpp"
15 
16 namespace yage {
17 
18 class ParticleBody : public Body {
19 public:
20  ParticleBody(const Vector2d& position = Vector2d(0, 0), double mass = 1,
21  const Vector2d& velocity = Vector2d(0, 0),
22  bool gravity = true);
23 
24  // apply a force to the rigid body
25  virtual void applyForce(const Vector2d& force);
26  virtual void update();
27 };
28 
29 } // yage
30 
31 #endif
Templated matrix class.
-
Vector2< double > Vector2d
Definition of a 2D vector.
Definition: matrix.hpp:313
+
Vector2< double > Vector2d
Definition of a 2D vector.
Definition: matrix.hpp:314
Definition: camera2d.hpp:17
diff --git a/physics_8hpp_source.html b/physics_8hpp_source.html index 97b791c0..738a7fe9 100644 --- a/physics_8hpp_source.html +++ b/physics_8hpp_source.html @@ -71,7 +71,7 @@ $(function() {
1 /* ----------------------------------------------------------------------------
2  * physics.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_PHYSICS_HPP
10 #define YAGE_PHYSICS_HPP
11 
12 #include "body.hpp"
13 #include "collider.hpp"
14 #include "collisionbody.hpp"
15 #include "particlebody.hpp"
16 #include "rectanglecollider.hpp"
17 #include "rigidbody.hpp"
18 
19 #endif
diff --git a/picopng_8hpp_source.html b/picopng_8hpp_source.html index 4e748532..8fb6921e 100644 --- a/picopng_8hpp_source.html +++ b/picopng_8hpp_source.html @@ -68,11 +68,11 @@ $(function() {
picopng.hpp
-
1 /* ----------------------------------------------------------------------------
2  * picopng.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #include <vector>
10 #include <cstdlib>
11 
12 namespace yage
13 {
14 
15 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);
16 
17 } // yage
Definition: camera2d.hpp:17
+
1 /* ----------------------------------------------------------------------------
2  * picopng.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #include <vector>
10 #include <cstdlib>
11 
12 namespace yage
13 {
14 
15 extern int decodePNG(std::vector<unsigned char> &out_image,
16  unsigned long &image_width,
17  unsigned long &image_height,
18  const unsigned char *in_png,
19  size_t in_size,
20  bool convert_to_rgba32 = true);
21 
22 } // yage
Definition: camera2d.hpp:17
diff --git a/rectanglecollider_8hpp_source.html b/rectanglecollider_8hpp_source.html index fccd48bb..948bfc2d 100644 --- a/rectanglecollider_8hpp_source.html +++ b/rectanglecollider_8hpp_source.html @@ -72,7 +72,7 @@ $(function() {
diff --git a/resourcemanager_8hpp_source.html b/resourcemanager_8hpp_source.html index d8334b45..79da5db7 100644 --- a/resourcemanager_8hpp_source.html +++ b/resourcemanager_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/rigidbody_8hpp_source.html b/rigidbody_8hpp_source.html index bff3c0c7..4e8419c3 100644 --- a/rigidbody_8hpp_source.html +++ b/rigidbody_8hpp_source.html @@ -68,12 +68,12 @@ $(function() {
rigidbody.hpp
-
1 /* ----------------------------------------------------------------------------
2  * rigidbody.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_RIGID_BODY_HPP
10 #define YAGE_RIGID_BODY_HPP
11 
12 #include <glm/glm.hpp>
13 
14 #include "particlebody.hpp"
15 
16 namespace yage {
17 
18 class RigidBody : public ParticleBody {
19 public:
20  RigidBody(const Vector2d& position = Vector2d(0, 0), double mass = 1,
21  const Vector2d& velocity = Vector2d(0, 0), bool gravity = true);
22 };
23 
24 } // yage
25 
26 #endif
Vector2< double > Vector2d
Definition of a 2D vector.
Definition: matrix.hpp:313
+
1 /* ----------------------------------------------------------------------------
2  * rigidbody.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_RIGID_BODY_HPP
10 #define YAGE_RIGID_BODY_HPP
11 
12 #include <glm/glm.hpp>
13 
14 #include "particlebody.hpp"
15 
16 namespace yage {
17 
18 class RigidBody : public ParticleBody {
19 public:
20  RigidBody(const Vector2d& position = Vector2d(0, 0), double mass = 1,
21  const Vector2d& velocity = Vector2d(0, 0), bool gravity = true);
22 };
23 
24 } // yage
25 
26 #endif
Vector2< double > Vector2d
Definition of a 2D vector.
Definition: matrix.hpp:314
Definition: camera2d.hpp:17
diff --git a/search/all_0.js b/search/all_0.js index 230a28fd..48682bc0 100644 --- a/search/all_0.js +++ b/search/all_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['colsize',['colSize',['../classyage_1_1Matrix.html#a2753285bcc49a050a49976a6dbc8e89a',1,'yage::Matrix']]] + ['begin',['begin',['../classyage_1_1Matrix.html#a83d77d3a40ced5e2b703a6d66b6e6055',1,'yage::Matrix']]] ]; diff --git a/search/all_1.js b/search/all_1.js index 5193cc53..230a28fd 100644 --- a/search/all_1.js +++ b/search/all_1.js @@ -1,6 +1,4 @@ var searchData= [ - ['data_5f',['data_',['../classyage_1_1Matrix.html#a0ab11922319366f6e74f6e9e7d7abeed',1,'yage::Matrix']]], - ['dot',['dot',['../namespaceyage_1_1matrix.html#ac4d2f55a5c3369ec42001776a582c30a',1,'yage::matrix']]], - ['documentation',['Documentation',['../md_docs_README.html',1,'']]] + ['colsize',['colSize',['../classyage_1_1Matrix.html#a2753285bcc49a050a49976a6dbc8e89a',1,'yage::Matrix']]] ]; diff --git a/search/all_2.js b/search/all_2.js index a2c9e4ea..5193cc53 100644 --- a/search/all_2.js +++ b/search/all_2.js @@ -1,5 +1,6 @@ var searchData= [ - ['getrow',['getRow',['../classyage_1_1Matrix.html#adffb22a99417271958621ff1f51b7f08',1,'yage::Matrix']]], - ['glyph',['Glyph',['../classyage_1_1Glyph.html',1,'yage']]] + ['data_5f',['data_',['../classyage_1_1Matrix.html#a0ab11922319366f6e74f6e9e7d7abeed',1,'yage::Matrix']]], + ['dot',['dot',['../namespaceyage_1_1matrix.html#ac4d2f55a5c3369ec42001776a582c30a',1,'yage::matrix']]], + ['documentation',['Documentation',['../md_docs_README.html',1,'']]] ]; diff --git a/search/all_3.js b/search/all_3.js index 7c08ffa0..46243ac3 100644 --- a/search/all_3.js +++ b/search/all_3.js @@ -1,8 +1,4 @@ var searchData= [ - ['matrix',['Matrix',['../classyage_1_1Matrix.html',1,'yage::Matrix< Rows, Cols, Type >'],['../classyage_1_1Matrix.html#a73b7d1f94f4f72a2294b71b3a35794ad',1,'yage::Matrix::Matrix()']]], - ['matrix_2ehpp',['matrix.hpp',['../matrix_8hpp.html',1,'']]], - ['matrix_3c_20rows_2c_201_2c_20double_20_3e',['Matrix< Rows, 1, double >',['../classyage_1_1Matrix.html',1,'yage']]], - ['matrix_3c_20rows_2c_201_2c_20type_20_3e',['Matrix< Rows, 1, Type >',['../classyage_1_1Matrix.html',1,'yage']]], - ['multiply',['multiply',['../namespaceyage_1_1matrix.html#a277125ad9fa06a7119c59d350e129985',1,'yage::matrix']]] + ['end',['end',['../classyage_1_1Matrix.html#a20ea5fe16d27ef15f775b5497cadc851',1,'yage::Matrix']]] ]; diff --git a/search/all_4.js b/search/all_4.js index a2780bef..a2c9e4ea 100644 --- a/search/all_4.js +++ b/search/all_4.js @@ -1,4 +1,5 @@ var searchData= [ - ['rowsize',['rowSize',['../classyage_1_1Matrix.html#acaf0837fade0cb4179603b97ac224965',1,'yage::Matrix']]] + ['getrow',['getRow',['../classyage_1_1Matrix.html#adffb22a99417271958621ff1f51b7f08',1,'yage::Matrix']]], + ['glyph',['Glyph',['../classyage_1_1Glyph.html',1,'yage']]] ]; diff --git a/search/all_5.js b/search/all_5.js index 20f93422..7c08ffa0 100644 --- a/search/all_5.js +++ b/search/all_5.js @@ -1,4 +1,8 @@ var searchData= [ - ['transpose',['transpose',['../namespaceyage_1_1matrix.html#a62de4b4b6bab23717d957c370f2e41c7',1,'yage::matrix']]] + ['matrix',['Matrix',['../classyage_1_1Matrix.html',1,'yage::Matrix< Rows, Cols, Type >'],['../classyage_1_1Matrix.html#a73b7d1f94f4f72a2294b71b3a35794ad',1,'yage::Matrix::Matrix()']]], + ['matrix_2ehpp',['matrix.hpp',['../matrix_8hpp.html',1,'']]], + ['matrix_3c_20rows_2c_201_2c_20double_20_3e',['Matrix< Rows, 1, double >',['../classyage_1_1Matrix.html',1,'yage']]], + ['matrix_3c_20rows_2c_201_2c_20type_20_3e',['Matrix< Rows, 1, Type >',['../classyage_1_1Matrix.html',1,'yage']]], + ['multiply',['multiply',['../namespaceyage_1_1matrix.html#a277125ad9fa06a7119c59d350e129985',1,'yage::matrix']]] ]; diff --git a/search/all_6.js b/search/all_6.js index e583272e..a2780bef 100644 --- a/search/all_6.js +++ b/search/all_6.js @@ -1,6 +1,4 @@ var searchData= [ - ['vector2',['Vector2',['../classyage_1_1Vector2.html',1,'yage']]], - ['vector2_3c_20double_20_3e',['Vector2< double >',['../classyage_1_1Vector2.html',1,'yage']]], - ['vector2d',['Vector2d',['../matrix_8hpp.html#a6cdcf60e5d3972cac5e8a6be40403078',1,'yage']]] + ['rowsize',['rowSize',['../classyage_1_1Matrix.html#acaf0837fade0cb4179603b97ac224965',1,'yage::Matrix']]] ]; diff --git a/search/all_7.js b/search/all_7.js index a2bef0db..50943f5d 100644 --- a/search/all_7.js +++ b/search/all_7.js @@ -1,5 +1,5 @@ var searchData= [ - ['matrix',['matrix',['../namespaceyage_1_1matrix.html',1,'yage']]], - ['yage',['YAGE',['../md_README.html',1,'']]] + ['tostring',['toString',['../classyage_1_1Matrix.html#aaa7273d046ac077da76ffaec876041d7',1,'yage::Matrix']]], + ['transpose',['transpose',['../namespaceyage_1_1matrix.html#a62de4b4b6bab23717d957c370f2e41c7',1,'yage::matrix']]] ]; diff --git a/search/all_8.html b/search/all_8.html new file mode 100644 index 00000000..11e27cdb --- /dev/null +++ b/search/all_8.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/search/all_8.js b/search/all_8.js new file mode 100644 index 00000000..e583272e --- /dev/null +++ b/search/all_8.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['vector2',['Vector2',['../classyage_1_1Vector2.html',1,'yage']]], + ['vector2_3c_20double_20_3e',['Vector2< double >',['../classyage_1_1Vector2.html',1,'yage']]], + ['vector2d',['Vector2d',['../matrix_8hpp.html#a6cdcf60e5d3972cac5e8a6be40403078',1,'yage']]] +]; diff --git a/search/all_9.html b/search/all_9.html new file mode 100644 index 00000000..f8abbbe5 --- /dev/null +++ b/search/all_9.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/search/all_9.js b/search/all_9.js new file mode 100644 index 00000000..a2bef0db --- /dev/null +++ b/search/all_9.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['matrix',['matrix',['../namespaceyage_1_1matrix.html',1,'yage']]], + ['yage',['YAGE',['../md_README.html',1,'']]] +]; diff --git a/search/functions_0.js b/search/functions_0.js index 230a28fd..48682bc0 100644 --- a/search/functions_0.js +++ b/search/functions_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['colsize',['colSize',['../classyage_1_1Matrix.html#a2753285bcc49a050a49976a6dbc8e89a',1,'yage::Matrix']]] + ['begin',['begin',['../classyage_1_1Matrix.html#a83d77d3a40ced5e2b703a6d66b6e6055',1,'yage::Matrix']]] ]; diff --git a/search/functions_1.js b/search/functions_1.js index 298c1dd0..230a28fd 100644 --- a/search/functions_1.js +++ b/search/functions_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['dot',['dot',['../namespaceyage_1_1matrix.html#ac4d2f55a5c3369ec42001776a582c30a',1,'yage::matrix']]] + ['colsize',['colSize',['../classyage_1_1Matrix.html#a2753285bcc49a050a49976a6dbc8e89a',1,'yage::Matrix']]] ]; diff --git a/search/functions_2.js b/search/functions_2.js index 995953e1..298c1dd0 100644 --- a/search/functions_2.js +++ b/search/functions_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['getrow',['getRow',['../classyage_1_1Matrix.html#adffb22a99417271958621ff1f51b7f08',1,'yage::Matrix']]] + ['dot',['dot',['../namespaceyage_1_1matrix.html#ac4d2f55a5c3369ec42001776a582c30a',1,'yage::matrix']]] ]; diff --git a/search/functions_3.js b/search/functions_3.js index a327fdef..46243ac3 100644 --- a/search/functions_3.js +++ b/search/functions_3.js @@ -1,5 +1,4 @@ var searchData= [ - ['matrix',['Matrix',['../classyage_1_1Matrix.html#a73b7d1f94f4f72a2294b71b3a35794ad',1,'yage::Matrix']]], - ['multiply',['multiply',['../namespaceyage_1_1matrix.html#a277125ad9fa06a7119c59d350e129985',1,'yage::matrix']]] + ['end',['end',['../classyage_1_1Matrix.html#a20ea5fe16d27ef15f775b5497cadc851',1,'yage::Matrix']]] ]; diff --git a/search/functions_4.js b/search/functions_4.js index a2780bef..995953e1 100644 --- a/search/functions_4.js +++ b/search/functions_4.js @@ -1,4 +1,4 @@ var searchData= [ - ['rowsize',['rowSize',['../classyage_1_1Matrix.html#acaf0837fade0cb4179603b97ac224965',1,'yage::Matrix']]] + ['getrow',['getRow',['../classyage_1_1Matrix.html#adffb22a99417271958621ff1f51b7f08',1,'yage::Matrix']]] ]; diff --git a/search/functions_5.js b/search/functions_5.js index 20f93422..a327fdef 100644 --- a/search/functions_5.js +++ b/search/functions_5.js @@ -1,4 +1,5 @@ var searchData= [ - ['transpose',['transpose',['../namespaceyage_1_1matrix.html#a62de4b4b6bab23717d957c370f2e41c7',1,'yage::matrix']]] + ['matrix',['Matrix',['../classyage_1_1Matrix.html#a73b7d1f94f4f72a2294b71b3a35794ad',1,'yage::Matrix']]], + ['multiply',['multiply',['../namespaceyage_1_1matrix.html#a277125ad9fa06a7119c59d350e129985',1,'yage::matrix']]] ]; diff --git a/search/functions_6.html b/search/functions_6.html new file mode 100644 index 00000000..c5061236 --- /dev/null +++ b/search/functions_6.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/search/functions_6.js b/search/functions_6.js new file mode 100644 index 00000000..a2780bef --- /dev/null +++ b/search/functions_6.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['rowsize',['rowSize',['../classyage_1_1Matrix.html#acaf0837fade0cb4179603b97ac224965',1,'yage::Matrix']]] +]; diff --git a/search/functions_7.html b/search/functions_7.html new file mode 100644 index 00000000..83a7b84b --- /dev/null +++ b/search/functions_7.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/search/functions_7.js b/search/functions_7.js new file mode 100644 index 00000000..50943f5d --- /dev/null +++ b/search/functions_7.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['tostring',['toString',['../classyage_1_1Matrix.html#aaa7273d046ac077da76ffaec876041d7',1,'yage::Matrix']]], + ['transpose',['transpose',['../namespaceyage_1_1matrix.html#a62de4b4b6bab23717d957c370f2e41c7',1,'yage::matrix']]] +]; diff --git a/search/searchdata.js b/search/searchdata.js index b9f3d40a..0bd01c3e 100644 --- a/search/searchdata.js +++ b/search/searchdata.js @@ -1,10 +1,10 @@ var indexSectionsWithContent = { - 0: "cdgmrtvy", + 0: "bcdegmrtvy", 1: "gmv", 2: "y", 3: "m", - 4: "cdgmrt", + 4: "bcdegmrt", 5: "d", 6: "v", 7: "dy" diff --git a/sprite_8hpp_source.html b/sprite_8hpp_source.html index b24937d0..dcfcbbe7 100644 --- a/sprite_8hpp_source.html +++ b/sprite_8hpp_source.html @@ -72,7 +72,7 @@ $(function() {
diff --git a/spritebatch_8hpp_source.html b/spritebatch_8hpp_source.html index f111d3c5..0c583581 100644 --- a/spritebatch_8hpp_source.html +++ b/spritebatch_8hpp_source.html @@ -68,12 +68,12 @@ $(function() {
spritebatch.hpp
-
1 /* ----------------------------------------------------------------------------
2  * spritebatch.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_SPRITE_BATCH_HPP
10 #define YAGE_SPRITE_BATCH_HPP
11 
12 #include "vertex.hpp"
13 
14 #include <GL/glew.h>
15 #include <glm/glm.hpp>
16 
17 #include <vector>
18 
19 namespace yage {
20 
21 class SpriteBatch;
22 
25 class Glyph {
26  // member variables
27 private:
28  GLuint texture_;
29  float depth_;
30  Vertex top_left_;
31  Vertex top_right_;
32  Vertex bottom_right_;
33  Vertex bottom_left_;
34 
35  // member functions
36 public:
37  Glyph(GLuint texture, float depth, const Vertex& top_left,
38  const Vertex& top_right, const Vertex& bottom_right,
39  const Vertex& bottom_left);
40 
41  GLuint texture() const { return texture_; }
42  float depth() const { return depth_; }
43  Vertex top_left() const { return top_left_; }
44  Vertex top_right() const { return top_right_; }
45  Vertex bottom_right() const { return bottom_right_; }
46  Vertex bottom_left() const { return bottom_left_; }
47 };
48 
49 class RenderBatch {
50  friend SpriteBatch;
51 private:
52  GLsizei num_vertices_;
53  GLint offset_;
54  GLuint texture_;
55 
56 public:
57  RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture);
58 
59  GLint offset() const { return offset_; }
60  GLsizei num_vertices() const { return num_vertices_; }
61  GLuint texture() const { return texture_; }
62 };
63 
64 class SpriteBatch {
65 public:
66  static const int NUM_VERTICES = 6;
67 
68 private:
69  GLuint vbo_ = 0;
70  GLuint vao_ = 0;
71  std::vector<Glyph> glyphs_;
72  std::vector<Glyph*> glyph_ptrs_;
73  std::vector<RenderBatch> render_batches_;
74 
75  // member functions
76 public:
77  SpriteBatch();
78  SpriteBatch(const SpriteBatch&) = delete;
79  SpriteBatch(SpriteBatch&&) = delete;
80  ~SpriteBatch();
81 
82  SpriteBatch& operator=(const SpriteBatch&) = delete;
83  SpriteBatch& operator=(SpriteBatch&&) = delete;
84 
85  // initialize vaos and vbos
86  void init();
87  void begin();
88  void end();
89  // adds a sprite to the sprite batch to be rendered later
90  void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect,
91  GLuint texture, const Color& color, float depth);
92  // render the batch
93  void render();
94 
95 private:
96  void createVertexArray();
97  void createRenderBatches();
98  void sortGlyphs();
99 };
100 
101 } // yage
102 
103 #endif
Glyph with information of the texture.
Definition: spritebatch.hpp:25
+
1 /* ----------------------------------------------------------------------------
2  * spritebatch.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_SPRITE_BATCH_HPP
10 #define YAGE_SPRITE_BATCH_HPP
11 
12 #include "vertex.hpp"
13 
14 #include <GL/glew.h>
15 #include <glm/glm.hpp>
16 
17 #include <vector>
18 
19 namespace yage {
20 
21 class SpriteBatch;
22 
25 class Glyph {
26 private:
27  GLuint texture_;
28  float depth_;
29  Vertex top_left_;
30  Vertex top_right_;
31  Vertex bottom_right_;
32  Vertex bottom_left_;
33 
34 public:
35  Glyph(GLuint texture, float depth, const Vertex& top_left,
36  const Vertex& top_right, const Vertex& bottom_right,
37  const Vertex& bottom_left);
38 
39  GLuint texture() const { return texture_; }
40  float depth() const { return depth_; }
41  Vertex top_left() const { return top_left_; }
42  Vertex top_right() const { return top_right_; }
43  Vertex bottom_right() const { return bottom_right_; }
44  Vertex bottom_left() const { return bottom_left_; }
45 };
46 
47 class RenderBatch {
48  friend SpriteBatch;
49 private:
50  GLsizei num_vertices_;
51  GLint offset_;
52  GLuint texture_;
53 
54 public:
55  RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture);
56 
57  GLint offset() const { return offset_; }
58  GLsizei num_vertices() const { return num_vertices_; }
59  GLuint texture() const { return texture_; }
60 };
61 
62 class SpriteBatch {
63 public:
64  static const int NUM_VERTICES = 6;
65 
66 private:
67  GLuint vbo_ = 0;
68  GLuint vao_ = 0;
69  std::vector<Glyph> glyphs_;
70  std::vector<Glyph*> glyph_ptrs_;
71  std::vector<RenderBatch> render_batches_;
72 
73 public:
74  SpriteBatch();
75  SpriteBatch(const SpriteBatch&) = delete;
76  SpriteBatch(SpriteBatch&&) = delete;
77  ~SpriteBatch();
78 
79  SpriteBatch& operator=(const SpriteBatch&) = delete;
80  SpriteBatch& operator=(SpriteBatch&&) = delete;
81 
82  // initialize vaos and vbos
83  void init();
84  void begin();
85  void end();
86  // adds a sprite to the sprite batch to be rendered later
87  void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect,
88  GLuint texture, const Color& color, float depth);
89  // render the batch
90  void render();
91 
92 private:
93  void createVertexArray();
94  void createRenderBatches();
95  void sortGlyphs();
96 };
97 
98 } // namespace yage
99 
100 #endif
Glyph with information of the texture.
Definition: spritebatch.hpp:25
Definition: camera2d.hpp:17
diff --git a/texture_8hpp_source.html b/texture_8hpp_source.html index 28a57d87..399f1145 100644 --- a/texture_8hpp_source.html +++ b/texture_8hpp_source.html @@ -72,7 +72,7 @@ $(function() {
diff --git a/texturecache_8hpp_source.html b/texturecache_8hpp_source.html index 1aef8d26..a6071900 100644 --- a/texturecache_8hpp_source.html +++ b/texturecache_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/vertex_8hpp_source.html b/vertex_8hpp_source.html index d8dbd763..7bd0555a 100644 --- a/vertex_8hpp_source.html +++ b/vertex_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/window_8hpp_source.html b/window_8hpp_source.html index edc5459b..f437dfce 100644 --- a/window_8hpp_source.html +++ b/window_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { diff --git a/yage_8hpp_source.html b/yage_8hpp_source.html index 1f99d4c5..45e6b27c 100644 --- a/yage_8hpp_source.html +++ b/yage_8hpp_source.html @@ -72,7 +72,7 @@ $(function() { -- cgit