1 #ifndef __DALI_MATRIX3_H__
2 #define __DALI_MATRIX3_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/math/vector3.h>
23 #include <dali/public-api/math/matrix.h>
32 * @brief A 3x3 matrix.
35 class DALI_IMPORT_API Matrix3
39 friend std::ostream& operator<< (std::ostream& o, const Matrix3& matrix);
42 * @brief The identity matrix
44 static const Matrix3 IDENTITY;
52 * @brief Copy Constructor.
54 * @param[in] m Another 3x3 matrix
56 Matrix3(const Matrix3& m);
61 * @param[in] m A 4x4 matrix. The translation and shear components are ignored.
63 Matrix3(const Matrix& m);
68 * @param[in] s00 First element
69 * @param[in] s01 Second element
70 * @param[in] s02 Third element
71 * @param[in] s10 Fourth element
72 * @param[in] s11 Fifth element
73 * @param[in] s12 Sixth element
74 * @param[in] s20 Seventh element
75 * @param[in] s21 Eighth element
76 * @param[in] s22 Ninth element
78 Matrix3(float s00, float s01, float s02, float s10, float s11, float s12, float s20, float s21, float s22);
81 * @brief Assignment Operator
82 * @param matrix from which to copy values
83 * @return reference to this object
85 Matrix3& operator=( const Matrix3& matrix );
88 * @brief Assignment Operator
89 * @param matrix from which to copy values
90 * @return reference to this object
92 Matrix3& operator=( const Matrix& matrix );
95 * @brief The equality operator.
97 * Utilises appropriate machine epsilon values.
99 * @param [in] rhs the Matrix to compare this to
100 * @return true if the matrices are equal
102 bool operator==(const Matrix3 & rhs) const;
105 * @brief The inequality operator.
107 * Utilises appropriate machine epsilon values.
109 * @param [in] rhs the Matrix to compare this to
110 * @return true if the matrices are equal
112 bool operator!=(const Matrix3 & rhs) const;
122 * @brief Sets the matrix to the identity matrix.
127 * @brief Returns the contents of the matrix as an array of 9 floats.
129 * The order of the values for a matrix is:
130 * xAxis.x yAxis.x zAxis.x
131 * xAxis.y yAxis.y zAxis.y
132 * xAxis.z yAxis.z zAxis.z
133 * @return the matrix contents as an array of 9 floats.
135 const float* AsFloat() const {return &mElements[0];}
138 * @brief Returns the contents of the matrix as an array of 9 floats.
140 * The order of the values for a matrix is:
141 * xAxis.x yAxis.x zAxis.x
142 * xAxis.y yAxis.y zAxis.y
143 * xAxis.z yAxis.z zAxis.z
144 * @return the matrix contents as an array of 9 floats.
146 float* AsFloat() {return &mElements[0];}
149 * @brief Inverts the matrix.
151 * @return true if successful
156 * @brief Swaps the rows to columns
162 * @brief Multiplies all elements of the matrix by the scale value.
164 * @param scale - the value by which to scale the whole matrix.
167 void Scale(float scale);
170 * @brief Magnitude returns the average of the absolute values of the
173 * (The Magnitude of the unit matrix is therefore 1)
174 * @return the magnitude - always positive.
176 float Magnitude() const;
179 * @brief If the matrix is invertible, then this method inverts, transposes
180 * and scales the matrix such that the resultant element values
183 * If the matrix is not invertible, then the matrix is left unchanged.
185 * @return true if the matrix is invertible, otherwise false
187 bool ScaledInverseTranspose();
190 * @brief Function to multiply two matrices and store the result onto third.
192 * Use this method in time critical path as it does not require temporaries
193 * @param result of the multiplication
194 * @param lhs matrix, this can be same matrix as result
195 * @param rhs matrix, this cannot be same matrix as result
197 static void Multiply( Matrix3& result, const Matrix3& lhs, const Matrix3& rhs );
201 float mElements[9]; ///< The elements of the matrix
205 * @brief Print a 3x3 matrix.
207 * @param [in] o The output stream operator.
208 * @param [in] matrix The matrix to print.
209 * @return The output stream operator.
211 DALI_IMPORT_API std::ostream& operator<< (std::ostream& o, const Matrix3& matrix);
215 #endif //__DALI_MATRIX3_H__