1 #ifndef _TCUMATRIXUTIL_HPP
2 #define _TCUMATRIXUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Matrix utility functions
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuMatrix.hpp"
33 template <typename T, int Size>
34 Matrix<T, Size+1, Size+1> translationMatrix (const Vector<T, Size>& translation);
36 template <typename T, int Rows, int Cols>
37 Matrix<T, Cols, Rows> transpose (const Matrix<T, Rows, Cols>& mat);
39 // 2D affine transformations.
40 Matrix<float, 2, 2> rotationMatrix (float radians);
41 Matrix<float, 2, 2> shearMatrix (const Vector<float, 2>& shear);
44 Matrix<float, 3, 3> rotationMatrixX (float radiansX);
45 Matrix<float, 3, 3> rotationMatrixY (float radiansY);
46 Matrix<float, 3, 3> rotationMatrixZ (float radiansZ);
50 // Builds a translation matrix for a homogenous coordinate system
51 template <typename T, int Len>
52 inline Matrix<T, Len+1, Len+1> translationMatrix (const Vector<T, Len>& translation)
54 Matrix<T, Len+1, Len+1> res = Matrix<T, Len+1, Len+1>();
55 for (int row = 0; row < Len; row++)
56 res(row, Len) = translation.m_data[row];
60 template <typename T, int Rows, int Cols>
61 inline Matrix<T, Cols, Rows> transpose (const Matrix<T, Rows, Cols>& mat)
63 Matrix<T, Cols, Rows> res;
64 for (int row = 0; row < Rows; row++)
65 for (int col = 0; col < Cols; col++)
66 res(col, row) = mat(row, col);
70 inline Matrix<float, 2, 2> rotationMatrix (float radians)
72 Matrix<float, 2, 2> mat;
73 float c = deFloatCos(radians);
74 float s = deFloatSin(radians);
84 inline Matrix<float, 2, 2> shearMatrix (const Vector<float, 2>& shear)
86 Matrix<float, 2, 2> mat;
88 mat(0, 1) = shear.x();
89 mat(1, 0) = shear.y();
90 mat(1, 1) = 1.0f + shear.x()*shear.y();
94 inline Matrix<float, 3, 3> rotationMatrixX (float radiansX)
96 Matrix<float, 3, 3> mat(1.0f);
97 float c = deFloatCos(radiansX);
98 float s = deFloatSin(radiansX);
108 inline Matrix<float, 3, 3> rotationMatrixY (float radiansY)
110 Matrix<float, 3, 3> mat(1.0f);
111 float c = deFloatCos(radiansY);
112 float s = deFloatSin(radiansY);
122 inline Matrix<float, 3, 3> rotationMatrixZ (float radiansZ)
124 Matrix<float, 3, 3> mat(1.0f);
125 float c = deFloatCos(radiansZ);
126 float s = deFloatSin(radiansZ);
138 #endif // _TCUMATRIXUTIL_HPP