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 "Skybox.h"
22 #include "Matrix.h"
23 
24 #include <cmath>
25 #include <cstdlib>
26 #include <cstring>
27 
28 namespace Skybox
29 {
30  /* Identity matrix. */
31  const float Matrix::identityArray[16] =
32  {
33  1.0f, 0.0f, 0.0f, 0.0f,
34  0.0f, 1.0f, 0.0f, 0.0f,
35  0.0f, 0.0f, 1.0f, 0.0f,
36  0.0f, 0.0f, 0.0f, 1.0f
37  };
38 
39  /* Please see header for specification. */
40  Matrix::Matrix(const float* array)
41  {
42  memcpy(elements, array, 16 * sizeof(float));
43  }
44 
45  /* Please see header for specification. */
47 
48  /* Please see header for specification. */
50 
51  /* Please see header for specification. */
52  float* Matrix::getAsArray(void)
53  {
54  return elements;
55  }
56 
57  /* Please see header for specification. */
58  Matrix& Matrix::operator=(const Matrix &another)
59  {
60  if(this != &another)
61  {
62  memcpy(this->elements, another.elements, 16 * sizeof(float));
63  }
64 
65  return *this;
66  }
67 
68  /* Please see header for specification. */
69  Matrix Matrix::matrixOrthographic(float left, float right, float bottom, float top, float zNear, float zFar)
70  {
71  Matrix result = identityMatrix;
72 
73  result.elements[0] = 2.0f / (right - left);
74  result.elements[12] = -(right + left) / (right - left);
75 
76  result.elements[5] = 2.0f / (top - bottom);
77  result.elements[13] = -(top + bottom) / (top - bottom);
78 
79  result.elements[10] = -2.0f / (zFar - zNear);
80  result.elements[14] = -(zFar + zNear) / (zFar - zNear);
81 
82  return result;
83  }
84 }
const float identityArray[16]
Definition: Matrix.cpp:34
float elements[16]
A 16 element floating point array used to represent a 4x4 matrix.
Definition: Matrix.h:36
Matrix & operator=(const Matrix &another)
Overloading assingment operater to do deep copy of the Matrix elements.
Definition: Matrix.cpp:58
static const float identityArray[]
A 4x4 identity Matrix;.
Definition: Matrix.h:41
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:69
Functions for manipulating matrices.
Definition: Matrix.h:29
GLint left
Definition: gl2ext.h:2704
static Matrix identityMatrix
The identity matrix.
Definition: Matrix.h:73
float * getAsArray(void)
Get the matrix elements as a column major order array.
Definition: Matrix.cpp:52
Matrix(void)
Default constructor.
Definition: Matrix.cpp:49
GLint GLint bottom
Definition: gl2ext.h:2704