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 // 2D affine transformations.
37 Matrix<float, 2, 2> rotationMatrix (float radians);
38 Matrix<float, 2, 2> shearMatrix (const Vector<float, 2>& shear);
41 Matrix<float, 3, 3> rotationMatrixX (float radiansX);
42 Matrix<float, 3, 3> rotationMatrixY (float radiansY);
43 Matrix<float, 3, 3> rotationMatrixZ (float radiansZ);
47 // Builds a translation matrix for a homogenous coordinate system
48 template <typename T, int Len>
49 inline Matrix<T, Len+1, Len+1> translationMatrix (const Vector<T, Len>& translation)
51 Matrix<T, Len+1, Len+1> res = Matrix<T, Len+1, Len+1>();
52 for (int row = 0; row < Len; row++)
53 res(row, Len) = translation.m_data[row];
57 inline Matrix<float, 2, 2> rotationMatrix (float radians)
59 Matrix<float, 2, 2> mat;
60 float c = deFloatCos(radians);
61 float s = deFloatSin(radians);
71 inline Matrix<float, 2, 2> shearMatrix (const Vector<float, 2>& shear)
73 Matrix<float, 2, 2> mat;
75 mat(0, 1) = shear.x();
76 mat(1, 0) = shear.y();
77 mat(1, 1) = 1.0f + shear.x()*shear.y();
81 inline Matrix<float, 3, 3> rotationMatrixX (float radiansX)
83 Matrix<float, 3, 3> mat(1.0f);
84 float c = deFloatCos(radiansX);
85 float s = deFloatSin(radiansX);
95 inline Matrix<float, 3, 3> rotationMatrixY (float radiansY)
97 Matrix<float, 3, 3> mat(1.0f);
98 float c = deFloatCos(radiansY);
99 float s = deFloatSin(radiansY);
109 inline Matrix<float, 3, 3> rotationMatrixZ (float radiansZ)
111 Matrix<float, 3, 3> mat(1.0f);
112 float c = deFloatCos(radiansZ);
113 float s = deFloatSin(radiansZ);
125 #endif // _TCUMATRIXUTIL_HPP