Merge "Remove the actor from exclusive list in RenderTaskList when the actor is destr...
[platform/core/uifw/dali-core.git] / dali / public-api / math / matrix3.h
1 #ifndef __DALI_MATRIX3_H__
2 #define __DALI_MATRIX3_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/math/vector3.h>
23 #include <dali/public-api/math/matrix.h>
24 #include <dali/public-api/common/type-traits.h>
25
26 namespace Dali
27 {
28 /**
29  * @addtogroup dali_core_math
30  * @{
31  */
32
33 class Matrix;
34 struct Vector2;
35
36 /**
37  * @brief A 3x3 matrix.
38  *
39  */
40 class DALI_IMPORT_API Matrix3
41 {
42 public:
43
44   friend std::ostream& operator<< (std::ostream& o, const Matrix3& matrix);
45
46   /**
47    * @brief The identity matrix
48    */
49   static const Matrix3 IDENTITY;
50
51   /**
52    * @brief Constructor.
53    */
54   Matrix3();
55
56   /**
57    * @brief Copy Constructor.
58    *
59    * @param[in] m Another 3x3 matrix
60    */
61   Matrix3(const Matrix3& m);
62
63   /**
64    * @brief Constructor.
65    *
66    * @param[in] m A 4x4 matrix. The translation and shear components are ignored.
67    */
68   Matrix3(const Matrix& m);
69
70   /**
71    * @brief Constructor.
72    *
73    * @param[in] s00 First element
74    * @param[in] s01 Second element
75    * @param[in] s02 Third element
76    * @param[in] s10 Fourth element
77    * @param[in] s11 Fifth element
78    * @param[in] s12 Sixth element
79    * @param[in] s20 Seventh element
80    * @param[in] s21 Eighth element
81    * @param[in] s22 Ninth element
82    */
83   Matrix3(float s00, float s01, float s02, float s10, float s11, float s12, float s20, float s21, float s22);
84
85   /**
86    * @brief Assignment Operator
87    * @param matrix from which to copy values
88    * @return reference to this object
89    */
90   Matrix3& operator=( const Matrix3& matrix );
91
92   /**
93    * @brief Assignment Operator
94    * @param matrix from which to copy values
95    * @return reference to this object
96    */
97   Matrix3& operator=( const Matrix& matrix );
98
99   /**
100    * @brief The equality operator.
101    *
102    * Utilises appropriate machine epsilon values.
103    *
104    * @param [in] rhs    the Matrix to compare this to
105    * @return true if the matrices are equal
106    */
107   bool operator==(const Matrix3 & rhs) const;
108
109   /**
110    * @brief The inequality operator.
111    *
112    * Utilises appropriate machine epsilon values.
113    *
114    * @param [in] rhs    the Matrix to compare this to
115    * @return true if the matrices are equal
116    */
117   bool operator!=(const Matrix3 & rhs) const;
118
119   /**
120    * @brief Destructor.
121    */
122   ~Matrix3()
123   {
124   }
125
126   /**
127    * @brief Sets the matrix to the identity matrix.
128    */
129   void SetIdentity();
130
131   /**
132    * @brief Returns the contents of the matrix as an array of 9 floats.
133    *
134    * The order of the values for a matrix is:
135    *   xAxis.x yAxis.x zAxis.x
136    *   xAxis.y yAxis.y zAxis.y
137    *   xAxis.z yAxis.z zAxis.z
138    * @return the matrix contents as an array of 9 floats.
139    */
140   const float* AsFloat() const {return &mElements[0];}
141
142   /**
143    * @brief Returns the contents of the matrix as an array of 9 floats.
144    *
145    * The order of the values for a matrix is:
146    *   xAxis.x yAxis.x zAxis.x
147    *   xAxis.y yAxis.y zAxis.y
148    *   xAxis.z yAxis.z zAxis.z
149    * @return the matrix contents as an array of 9 floats.
150    */
151   float* AsFloat() {return &mElements[0];}
152
153   /**
154    * @brief Inverts the matrix.
155    *
156    * @return true if successful
157    */
158   bool Invert();
159
160   /**
161    * @brief Swaps the rows to columns
162    * @return true
163    */
164   bool Transpose();
165
166   /**
167    * @brief Multiplies all elements of the matrix by the scale value.
168    *
169    * @param scale - the value by which to scale the whole matrix.
170
171    */
172   void Scale(float scale);
173
174   /**
175    * @brief Magnitude returns the average of the absolute values of the
176    * elements * 3.
177    *
178    * (The Magnitude of the unit matrix is therefore 1)
179    * @return the magnitude - always positive.
180    */
181   float Magnitude() const;
182
183   /**
184    * @brief If the matrix is invertible, then this method inverts, transposes
185    * and scales the matrix such that the resultant element values
186    * average 1.
187    *
188    * If the matrix is not invertible, then the matrix is left unchanged.
189
190    * @return true if the matrix is invertible, otherwise false
191    */
192   bool ScaledInverseTranspose();
193
194   /**
195    * @brief Function to multiply two matrices and store the result onto third.
196    *
197    * Use this method in time critical path as it does not require temporaries
198    * @param result of the multiplication
199    * @param lhs matrix, this can be same matrix as result
200    * @param rhs matrix, this cannot be same matrix as result
201    */
202   static void Multiply( Matrix3& result, const Matrix3& lhs, const Matrix3& rhs );
203
204 private:
205
206   float mElements[9]; ///< The elements of the matrix
207 };
208
209 /**
210  * @brief Print a 3x3 matrix.
211  *
212  * @param [in] o The output stream operator.
213  * @param [in] matrix The matrix to print.
214  * @return The output stream operator.
215  */
216 DALI_IMPORT_API std::ostream& operator<< (std::ostream& o, const Matrix3& matrix);
217
218 // Allow Matrix3 to be treated as a POD type
219 template <> struct TypeTraits< Matrix3 > : public BasicTypes< Matrix3 > { enum { IS_TRIVIAL_TYPE = true }; };
220
221 /**
222  * @}
223  */
224 } // namespace Dali
225
226 #endif //__DALI_MATRIX3_H__