OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Matrix.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #include "Common.h"
22 #include "Mathematics.h"
23 #include "Matrix.h"
24 
25 #include <cmath>
26 #include <cstring>
27 #include <cstdio>
28 #include <cstdlib>
29 
30 namespace MaliSDK
31 {
32  /* [Define bias matrix] */
33  /* Bias matrix. */
34  const float Matrix::biasArray[16] =
35  {
36  0.5f, 0.0f, 0.0f, 0.0f,
37  0.0f, 0.5f, 0.0f, 0.0f,
38  0.0f, 0.0f, 0.5f, 0.0f,
39  0.5f, 0.5f, 0.5f, 1.0f,
40  };
41  /* [Define bias matrix] */
42 
43  /* Identity matrix. */
44  const float Matrix::identityArray[16] =
45  {
46  1.0f, 0.0f, 0.0f, 0.0f,
47  0.0f, 1.0f, 0.0f, 0.0f,
48  0.0f, 0.0f, 1.0f, 0.0f,
49  0.0f, 0.0f, 0.0f, 1.0f,
50  };
51 
52  Matrix Matrix::biasMatrix = Matrix(biasArray);
53  Matrix Matrix::identityMatrix = Matrix(identityArray);
54 
55  Matrix::Matrix(const float* array)
56  {
57  memcpy(elements, array, 16 * sizeof(float));
58  }
59 
60  Matrix::Matrix(void)
61  {
62  }
63 
64  float& Matrix::operator[] (unsigned element)
65  {
66  ASSERT(element <= 15, "Invalid matrix element index.");
67 
68  return elements[element];
69  }
70 
71  Matrix Matrix::operator* (Matrix right)
72  {
73  return multiply(this, &right);
74  }
75 
76  Matrix& Matrix::operator= (const Matrix &another)
77  {
78  if (this != &another)
79  {
80  memcpy(this->elements, another.elements, 16 * sizeof(float));
81  }
82 
83  return *this;
84  }
85 
86  Matrix Matrix::createRotationX(float angleInDegrees)
87  {
88  float angleInRadians = degreesToRadians(angleInDegrees);
89  Matrix result = identityMatrix;
90 
91  result.elements[5] = cos(angleInRadians);
92  result.elements[9] = -sin(angleInRadians);
93  result.elements[6] = sin(angleInRadians);
94  result.elements[10] = cos(angleInRadians);
95 
96  return result;
97  }
98 
99  Matrix Matrix::createRotationY(float angleInDegrees)
100  {
101  float angleInRadians = degreesToRadians(angleInDegrees);
102  Matrix result = identityMatrix;
103 
104  result.elements[0] = cos(angleInRadians);
105  result.elements[8] = sin(angleInRadians);
106  result.elements[2] = -sin(angleInRadians);
107  result.elements[10] = cos(angleInRadians);
108 
109  return result;
110  }
111 
112  Matrix Matrix::createRotationZ(float angleInDegrees)
113  {
114  float angleInRarians = degreesToRadians(angleInDegrees);
115  Matrix result = identityMatrix;
116 
117  result.elements[0] = cos(angleInRarians);
118  result.elements[4] = -sin(angleInRarians);
119  result.elements[1] = sin(angleInRarians);
120  result.elements[5] = cos(angleInRarians);
121 
122  return result;
123  }
124 
125  Matrix Matrix::createScaling(float x, float y, float z)
126  {
127  Matrix result = identityMatrix;
128 
129  result.elements[0] = x;
130  result.elements[5] = y;
131  result.elements[10] = z;
132 
133  return result;
134  }
135 
136  Matrix Matrix::createTranslation(float x, float y, float z)
137  {
138  Matrix result = identityMatrix;
139 
140  result.elements[12] = x;
141  result.elements[13] = y;
142  result.elements[14] = z;
143 
144  return result;
145  }
146 
147  float* Matrix::getAsArray(void)
148  {
149  return elements;
150  }
151 
152  float Matrix::matrixDeterminant(float *matrix)
153  {
154  float result = 0.0f;
155 
156  result = matrix[0] * (matrix[4] * matrix[8] - matrix[7] * matrix[5]);
157  result -= matrix[3] * (matrix[1] * matrix[8] - matrix[7] * matrix[2]);
158  result += matrix[6] * (matrix[1] * matrix[5] - matrix[4] * matrix[2]);
159 
160  return result;
161  }
162 
163  float Matrix::matrixDeterminant(Matrix *matrix)
164  {
165  float matrix3x3[9];
166  float determinant3x3 = 0.0f;
167  float result = 0.0f;
168 
169  /* Remove (i, j) (1, 1) to form new 3x3 matrix. */
170  matrix3x3[0] = matrix->elements[5];
171  matrix3x3[1] = matrix->elements[6];
172  matrix3x3[2] = matrix->elements[7];
173  matrix3x3[3] = matrix->elements[9];
174  matrix3x3[4] = matrix->elements[10];
175  matrix3x3[5] = matrix->elements[11];
176  matrix3x3[6] = matrix->elements[13];
177  matrix3x3[7] = matrix->elements[14];
178  matrix3x3[8] = matrix->elements[15];
179  determinant3x3 = matrixDeterminant(matrix3x3);
180  result += matrix->elements[0] * determinant3x3;
181 
182  /* Remove (i, j) (1, 2) to form new 3x3 matrix. */
183  matrix3x3[0] = matrix->elements[1];
184  matrix3x3[1] = matrix->elements[2];
185  matrix3x3[2] = matrix->elements[3];
186  matrix3x3[3] = matrix->elements[9];
187  matrix3x3[4] = matrix->elements[10];
188  matrix3x3[5] = matrix->elements[11];
189  matrix3x3[6] = matrix->elements[13];
190  matrix3x3[7] = matrix->elements[14];
191  matrix3x3[8] = matrix->elements[15];
192  determinant3x3 = matrixDeterminant(matrix3x3);
193  result -= matrix->elements[4] * determinant3x3;
194 
195  /* Remove (i, j) (1, 3) to form new 3x3 matrix. */
196  matrix3x3[0] = matrix->elements[1];
197  matrix3x3[1] = matrix->elements[2];
198  matrix3x3[2] = matrix->elements[3];
199  matrix3x3[3] = matrix->elements[5];
200  matrix3x3[4] = matrix->elements[6];
201  matrix3x3[5] = matrix->elements[7];
202  matrix3x3[6] = matrix->elements[13];
203  matrix3x3[7] = matrix->elements[14];
204  matrix3x3[8] = matrix->elements[15];
205  determinant3x3 = matrixDeterminant(matrix3x3);
206  result += matrix->elements[8] * determinant3x3;
207 
208  /* Remove (i, j) (1, 4) to form new 3x3 matrix. */
209  matrix3x3[0] = matrix->elements[1];
210  matrix3x3[1] = matrix->elements[2];
211  matrix3x3[2] = matrix->elements[3];
212  matrix3x3[3] = matrix->elements[5];
213  matrix3x3[4] = matrix->elements[6];
214  matrix3x3[5] = matrix->elements[7];
215  matrix3x3[6] = matrix->elements[9];
216  matrix3x3[7] = matrix->elements[10];
217  matrix3x3[8] = matrix->elements[11];
218  determinant3x3 = matrixDeterminant(matrix3x3);
219  result -= matrix->elements[12] * determinant3x3;
220 
221  return result;
222  }
223 
224  Matrix Matrix::matrixInvert(Matrix *matrix)
225  {
226  Matrix result;
227  float matrix3x3[9];
228 
229  /* Find the cofactor of each element. */
230  /* Element (i, j) (1, 1) */
231  matrix3x3[0] = matrix->elements[5];
232  matrix3x3[1] = matrix->elements[6];
233  matrix3x3[2] = matrix->elements[7];
234  matrix3x3[3] = matrix->elements[9];
235  matrix3x3[4] = matrix->elements[10];
236  matrix3x3[5] = matrix->elements[11];
237  matrix3x3[6] = matrix->elements[13];
238  matrix3x3[7] = matrix->elements[14];
239  matrix3x3[8] = matrix->elements[15];
240  result.elements[0] = matrixDeterminant(matrix3x3);
241 
242  /* Element (i, j) (1, 2) */
243  matrix3x3[0] = matrix->elements[1];
244  matrix3x3[1] = matrix->elements[2];
245  matrix3x3[2] = matrix->elements[3];
246  matrix3x3[3] = matrix->elements[9];
247  matrix3x3[4] = matrix->elements[10];
248  matrix3x3[5] = matrix->elements[11];
249  matrix3x3[6] = matrix->elements[13];
250  matrix3x3[7] = matrix->elements[14];
251  matrix3x3[8] = matrix->elements[15];
252  result.elements[4] = -matrixDeterminant(matrix3x3);
253 
254  /* Element (i, j) (1, 3) */
255  matrix3x3[0] = matrix->elements[1];
256  matrix3x3[1] = matrix->elements[2];
257  matrix3x3[2] = matrix->elements[3];
258  matrix3x3[3] = matrix->elements[5];
259  matrix3x3[4] = matrix->elements[6];
260  matrix3x3[5] = matrix->elements[7];
261  matrix3x3[6] = matrix->elements[13];
262  matrix3x3[7] = matrix->elements[14];
263  matrix3x3[8] = matrix->elements[15];
264  result.elements[8] = matrixDeterminant(matrix3x3);
265 
266  /* Element (i, j) (1, 4) */
267  matrix3x3[0] = matrix->elements[1];
268  matrix3x3[1] = matrix->elements[2];
269  matrix3x3[2] = matrix->elements[3];
270  matrix3x3[3] = matrix->elements[5];
271  matrix3x3[4] = matrix->elements[6];
272  matrix3x3[5] = matrix->elements[7];
273  matrix3x3[6] = matrix->elements[9];
274  matrix3x3[7] = matrix->elements[10];
275  matrix3x3[8] = matrix->elements[11];
276  result.elements[12] = -matrixDeterminant(matrix3x3);
277 
278  /* Element (i, j) (2, 1) */
279  matrix3x3[0] = matrix->elements[4];
280  matrix3x3[1] = matrix->elements[6];
281  matrix3x3[2] = matrix->elements[7];
282  matrix3x3[3] = matrix->elements[8];
283  matrix3x3[4] = matrix->elements[10];
284  matrix3x3[5] = matrix->elements[11];
285  matrix3x3[6] = matrix->elements[12];
286  matrix3x3[7] = matrix->elements[14];
287  matrix3x3[8] = matrix->elements[15];
288  result.elements[1] = -matrixDeterminant(matrix3x3);
289 
290  /* Element (i, j) (2, 2) */
291  matrix3x3[0] = matrix->elements[0];
292  matrix3x3[1] = matrix->elements[2];
293  matrix3x3[2] = matrix->elements[3];
294  matrix3x3[3] = matrix->elements[8];
295  matrix3x3[4] = matrix->elements[10];
296  matrix3x3[5] = matrix->elements[11];
297  matrix3x3[6] = matrix->elements[12];
298  matrix3x3[7] = matrix->elements[14];
299  matrix3x3[8] = matrix->elements[15];
300  result.elements[5] = matrixDeterminant(matrix3x3);
301 
302  /* Element (i, j) (2, 3) */
303  matrix3x3[0] = matrix->elements[0];
304  matrix3x3[1] = matrix->elements[2];
305  matrix3x3[2] = matrix->elements[3];
306  matrix3x3[3] = matrix->elements[4];
307  matrix3x3[4] = matrix->elements[6];
308  matrix3x3[5] = matrix->elements[7];
309  matrix3x3[6] = matrix->elements[12];
310  matrix3x3[7] = matrix->elements[14];
311  matrix3x3[8] = matrix->elements[15];
312  result.elements[9] = -matrixDeterminant(matrix3x3);
313 
314  /* Element (i, j) (2, 4) */
315  matrix3x3[0] = matrix->elements[0];
316  matrix3x3[1] = matrix->elements[2];
317  matrix3x3[2] = matrix->elements[3];
318  matrix3x3[3] = matrix->elements[4];
319  matrix3x3[4] = matrix->elements[6];
320  matrix3x3[5] = matrix->elements[7];
321  matrix3x3[6] = matrix->elements[8];
322  matrix3x3[7] = matrix->elements[10];
323  matrix3x3[8] = matrix->elements[11];
324  result.elements[13] = matrixDeterminant(matrix3x3);
325 
326  /* Element (i, j) (3, 1) */
327  matrix3x3[0] = matrix->elements[4];
328  matrix3x3[1] = matrix->elements[5];
329  matrix3x3[2] = matrix->elements[7];
330  matrix3x3[3] = matrix->elements[8];
331  matrix3x3[4] = matrix->elements[9];
332  matrix3x3[5] = matrix->elements[11];
333  matrix3x3[6] = matrix->elements[12];
334  matrix3x3[7] = matrix->elements[13];
335  matrix3x3[8] = matrix->elements[15];
336  result.elements[2] = matrixDeterminant(matrix3x3);
337 
338  /* Element (i, j) (3, 2) */
339  matrix3x3[0] = matrix->elements[0];
340  matrix3x3[1] = matrix->elements[1];
341  matrix3x3[2] = matrix->elements[3];
342  matrix3x3[3] = matrix->elements[8];
343  matrix3x3[4] = matrix->elements[9];
344  matrix3x3[5] = matrix->elements[11];
345  matrix3x3[6] = matrix->elements[12];
346  matrix3x3[7] = matrix->elements[13];
347  matrix3x3[8] = matrix->elements[15];
348  result.elements[6] = -matrixDeterminant(matrix3x3);
349 
350  /* Element (i, j) (3, 3) */
351  matrix3x3[0] = matrix->elements[0];
352  matrix3x3[1] = matrix->elements[1];
353  matrix3x3[2] = matrix->elements[3];
354  matrix3x3[3] = matrix->elements[4];
355  matrix3x3[4] = matrix->elements[5];
356  matrix3x3[5] = matrix->elements[7];
357  matrix3x3[6] = matrix->elements[12];
358  matrix3x3[7] = matrix->elements[13];
359  matrix3x3[8] = matrix->elements[15];
360  result.elements[10] = matrixDeterminant(matrix3x3);
361 
362  /* Element (i, j) (3, 4) */
363  matrix3x3[0] = matrix->elements[0];
364  matrix3x3[1] = matrix->elements[1];
365  matrix3x3[2] = matrix->elements[3];
366  matrix3x3[3] = matrix->elements[4];
367  matrix3x3[4] = matrix->elements[5];
368  matrix3x3[5] = matrix->elements[7];
369  matrix3x3[6] = matrix->elements[8];
370  matrix3x3[7] = matrix->elements[9];
371  matrix3x3[8] = matrix->elements[11];
372  result.elements[14] = -matrixDeterminant(matrix3x3);
373 
374  /* Element (i, j) (4, 1) */
375  matrix3x3[0] = matrix->elements[4];
376  matrix3x3[1] = matrix->elements[5];
377  matrix3x3[2] = matrix->elements[6];
378  matrix3x3[3] = matrix->elements[8];
379  matrix3x3[4] = matrix->elements[9];
380  matrix3x3[5] = matrix->elements[10];
381  matrix3x3[6] = matrix->elements[12];
382  matrix3x3[7] = matrix->elements[13];
383  matrix3x3[8] = matrix->elements[14];
384  result.elements[3] = -matrixDeterminant(matrix3x3);
385 
386  /* Element (i, j) (4, 2) */
387  matrix3x3[0] = matrix->elements[0];
388  matrix3x3[1] = matrix->elements[1];
389  matrix3x3[2] = matrix->elements[2];
390  matrix3x3[3] = matrix->elements[8];
391  matrix3x3[4] = matrix->elements[9];
392  matrix3x3[5] = matrix->elements[10];
393  matrix3x3[6] = matrix->elements[12];
394  matrix3x3[7] = matrix->elements[13];
395  matrix3x3[8] = matrix->elements[14];
396  result.elements[7] = matrixDeterminant(matrix3x3);
397 
398  /* Element (i, j) (4, 3) */
399  matrix3x3[0] = matrix->elements[0];
400  matrix3x3[1] = matrix->elements[1];
401  matrix3x3[2] = matrix->elements[2];
402  matrix3x3[3] = matrix->elements[4];
403  matrix3x3[4] = matrix->elements[5];
404  matrix3x3[5] = matrix->elements[6];
405  matrix3x3[6] = matrix->elements[12];
406  matrix3x3[7] = matrix->elements[13];
407  matrix3x3[8] = matrix->elements[14];
408  result.elements[11] = -matrixDeterminant(matrix3x3);
409 
410  /* Element (i, j) (4, 4) */
411  matrix3x3[0] = matrix->elements[0];
412  matrix3x3[1] = matrix->elements[1];
413  matrix3x3[2] = matrix->elements[2];
414  matrix3x3[3] = matrix->elements[4];
415  matrix3x3[4] = matrix->elements[5];
416  matrix3x3[5] = matrix->elements[6];
417  matrix3x3[6] = matrix->elements[8];
418  matrix3x3[7] = matrix->elements[9];
419  matrix3x3[8] = matrix->elements[10];
420  result.elements[15] = matrixDeterminant(matrix3x3);
421 
422  /* The adjoint is the transpose of the cofactor matrix. */
423  matrixTranspose(&result);
424 
425  /* The inverse is the adjoint divided by the determinant. */
426  result = matrixScale(&result, 1.0f / matrixDeterminant(matrix));
427 
428  return result;
429  }
430 
432  {
433  Vec3f xVector;
434  Vec3f yVector;
435  Vec3f zVector = { center.x - eye.x, center.y - eye.y, center.z - eye.z };
436  Matrix result = identityMatrix;
437 
438  zVector.normalize();
439 
440  xVector = Vec3f::cross(zVector, up);
441  xVector.normalize();
442 
443  yVector = Vec3f::cross(xVector, zVector);
444 
445  /*
446  * The final lookAt should look like:
447  *
448  * lookAt[] = {xVector.x, yVector.x, -zVector.x, 0.0f,
449  * xVector.y, yVector.y, -zVector.y, 0.0f,
450  * xVector.z, yVector.z, -zVector.z, 0.0f,
451  * dot(xVector, eye), dot(yVector, eye), dot(zVector, eye), 1.0f };
452  */
453 
454  result[0] = xVector.x;
455  result[1] = yVector.x;
456  result[2] = -zVector.x;
457 
458  result[4] = xVector.y;
459  result[5] = yVector.y;
460  result[6] = -zVector.y;
461 
462  result[8] = xVector.z;
463  result[9] = yVector.z;
464  result[10] = -zVector.z;
465 
466  result[12] = Vec3f::dot(xVector, eye);
467  result[13] = Vec3f::dot(yVector, eye);
468  result[14] = Vec3f::dot(zVector, eye);
469 
470  return result;
471  }
472 
474  float right,
475  float bottom,
476  float top,
477  float zNear,
478  float zFar)
479  {
480  Matrix result = identityMatrix;
481 
482  result.elements[ 0] = 2.0f / (right - left);
483  result.elements[12] = -(right + left) / (right - left);
484 
485  result.elements[ 5] = 2.0f / (top - bottom);
486  result.elements[13] = -(top + bottom) / (top - bottom);
487 
488  result.elements[10] = -2.0f / (zFar - zNear);
489  result.elements[14] = -(zFar + zNear) / (zFar - zNear);
490 
491  return result;
492  }
493 
494  Matrix Matrix::matrixPerspective(float FOV, float ratio, float zNear, float zFar)
495  {
496  Matrix result = identityMatrix;
497 
498  FOV = 1.0f / tan(FOV * 0.5f);
499 
500  result.elements[0] = FOV / ratio;
501  result.elements[5] = FOV;
502  result.elements[10] = -(zFar + zNear) / (zFar - zNear);
503  result.elements[11] = -1.0f;
504  result.elements[14] = (-2.0f * zFar * zNear) / (zFar - zNear);
505  result.elements[15] = 0.0f;
506 
507  return result;
508  }
509 
510  Matrix Matrix::matrixScale(Matrix *matrix, float scale)
511  {
512  Matrix result;
513 
514  for (int allElements = 0; allElements < 16; allElements++)
515  {
516  result.elements[allElements] = matrix->elements[allElements] * scale;
517  }
518 
519  return result;
520  }
521 
522  void Matrix::matrixTranspose(Matrix *matrix)
523  {
524  float temp;
525 
526  temp = matrix->elements[1];
527  matrix->elements[1] = matrix->elements[4];
528  matrix->elements[4] = temp;
529 
530  temp = matrix->elements[2];
531  matrix->elements[2] = matrix->elements[8];
532  matrix->elements[8] = temp;
533 
534  temp = matrix->elements[3];
535  matrix->elements[3] = matrix->elements[12];
536  matrix->elements[12] = temp;
537 
538  temp = matrix->elements[6];
539  matrix->elements[6] = matrix->elements[9];
540  matrix->elements[9] = temp;
541 
542  temp = matrix->elements[7];
543  matrix->elements[7] = matrix->elements[13];
544  matrix->elements[13] = temp;
545 
546  temp = matrix->elements[11];
547  matrix->elements[11] = matrix->elements[14];
548  matrix->elements[14] = temp;
549  }
550 
551  Matrix Matrix::multiply(Matrix *left, Matrix *right)
552  {
553  Matrix result;
554 
555  for (int row = 0; row < 4; row++)
556  {
557  for (int column = 0; column < 4; column++)
558  {
559  /* result.elements[row * 4 + column] = left->elements[0 + row * 4] * right->elements[column + 0 * 4];
560  * result.elements[row * 4 + column] += left->elements[1 + row * 4] * right->elements[column + 1 * 4];
561  * result.elements[row * 4 + column] += left->elements[2 + row * 4] * right->elements[column + 2 * 4];
562  * result.elements[row * 4 + column] += left->elements[3 + row * 4] * right->elements[column + 3 * 4];*/
563  float accumulator = 0.0f;
564 
565  for (int allElements = 0; allElements < 4; allElements++)
566  {
567  accumulator += left->elements[allElements * 4 + row] * right->elements[column * 4 + allElements];
568  }
569 
570  result.elements[column * 4 + row] = accumulator;
571  }
572  }
573 
574  return result;
575  }
576 
577  Vec4f Matrix::vertexTransform(Vec4f *vertex, Matrix *matrix)
578  {
579  Vec4f result;
580 
581  result.x = vertex->x * matrix->elements[0];
582  result.x += vertex->y * matrix->elements[4];
583  result.x += vertex->z * matrix->elements[8];
584  result.x += vertex->w * matrix->elements[12];
585 
586  result.y = vertex->x * matrix->elements[1];
587  result.y += vertex->y * matrix->elements[5];
588  result.y += vertex->z * matrix->elements[9];
589  result.y += vertex->w * matrix->elements[13];
590 
591  result.z = vertex->x * matrix->elements[2];
592  result.z += vertex->y * matrix->elements[6];
593  result.z += vertex->z * matrix->elements[10];
594  result.z += vertex->w * matrix->elements[14];
595 
596  result.w = vertex->x * matrix->elements[3];
597  result.w += vertex->y * matrix->elements[7];
598  result.w += vertex->z * matrix->elements[11];
599  result.w += vertex->w * matrix->elements[15];
600 
601  return result;
602  }
603 }
const float identityArray[16]
Definition: Matrix.cpp:34
float & operator[](unsigned element)
Array operator for accessing the elements of the matrix.
Definition: Matrix.cpp:53
Matrix operator*(Matrix right)
Multiply operator to post multiply a matrix by another.
Definition: Matrix.cpp:63
static Matrix identityMatrix
The identity matrix.
Definition: Matrix.h:90
static float dot(Vec3f &vector1, Vec3f &vector2)
Calculate dot product between two 3D floating point vectors.
Definition: VectorTypes.h:45
static Vec3f cross(const Vec3f &vector1, const Vec3f &vector2)
Calculate cross product between two 3D floating point vectors.
Definition: VectorTypes.h:108
Functions for manipulating matrices.
Definition: Matrix.h:31
Matrix(void)
Default constructor.
Definition: Matrix.cpp:49
static const float identityArray[]
A 4x4 identity Matrix;.
Definition: Matrix.h:50
static Matrix matrixInvert(Matrix *matrix)
Get the inverse of a matrix.
Definition: Matrix.cpp:155
static Matrix createTranslation(float x, float y, float z)
Create and return a translation matrix.
Definition: Matrix.cpp:414
static Matrix matrixOrthographic(float left, float right, float bottom, float top, float zNear, float zFar)
Create and return an orthographic projection matrix.
Definition: Matrix.cpp:483
static Matrix createScaling(float x, float y, float z)
Create and return a scaling matrix.
Definition: Matrix.cpp:403
static const float biasArray[]
A 4x4 bias Matrix;.
Definition: Matrix.h:54
static Matrix matrixLookAt(Vec3f eye, Vec3f center, Vec3f up)
Create and return a look at matrix.
Definition: Matrix.cpp:431
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
Definition: Matrix.cpp:425
static Matrix biasMatrix
The bias matrix.
Definition: Matrix.h:102
float * getAsArray(void)
Get the matrix elements as a column major order array.
Definition: Matrix.cpp:78
A 3D floating point vector.
Definition: VectorTypes.h:83
GLfloat GLfloat f
Definition: gl2ext.h:2707
static Vec4f vertexTransform(Vec4f *vector, Matrix *matrix)
Transform a 4D vertex by a matrix.
Definition: Matrix.cpp:559
Matrix scale
Definition: RotoZoom.cpp:64
static Matrix createRotationY(float angle)
Create and return a rotation matrix around the y-axis matrix.
Definition: Matrix.cpp:511
static Matrix createRotationZ(float angle)
Create and return a rotation matrix around the z-axis matrix.
Definition: Matrix.cpp:523
static float matrixDeterminant(float *matrix)
Calculate determinant of supplied 3x3 matrix.
Definition: Matrix.cpp:83
float degreesToRadians(float degrees)
Convert an angle in degrees to radians.
Definition: Mathematics.h:86
static void matrixTranspose(Matrix *matrix)
Transpose a matrix in-place.
Definition: Matrix.cpp:374
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
static Matrix multiply(Matrix *left, Matrix *right)
Multiply 2 matrices to return a third.
Definition: Matrix.cpp:535
Matrix & operator=(const Matrix &another)
Overloading assingment operater to do deep copy of the Matrix elements.
Definition: Matrix.cpp:68
GLint left
Definition: gl2ext.h:2704
#define ASSERT(x, s)
Definition: common.h:45
float elements[16]
A 16 element floating point array used to represent a 4x4 matrix.
Definition: Matrix.h:38
static Matrix createRotationX(float angle)
Create and return a rotation matrix around the x-axis matrix.
Definition: Matrix.cpp:499
GLint y
Definition: gl2ext.h:179
void normalize(void)
Normalize 3D floating point vector.
Definition: VectorTypes.h:91
static Matrix matrixScale(Matrix *matrix, float scale)
Scale each element in a matrix by a constant.
Definition: Matrix.cpp:362
GLint GLint bottom
Definition: gl2ext.h:2704