2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiEffects_UtilsMatrix3.h
20 * @brief The Matrix3 class
24 #ifndef _FUI_EFFECTS_INTERNAL_UTILS_MATRIX3_H_
25 #define _FUI_EFFECTS_INTERNAL_UTILS_MATRIX3_H_
27 #include "FUiEffects_UtilsAdapterFunctions.h"
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Utils
31 template<class T> class _Vector3;
32 template<class T> class _Vector2;
33 template<class T> class Matrix2;
34 template<class T> class Quaternion;
36 template<class T> class Matrix3
39 typedef Matrix3<T> SelfType;
47 inline explicit Matrix3(const T& aValue);
48 inline explicit Matrix3(const T* aValue);
49 inline Matrix3(const SelfType& aOther);
50 inline Matrix3(const _Vector3<T>& aI, const _Vector3<T>& aJ, const _Vector3<T>& aC);
51 inline Matrix3(const _Vector2<T>& aI, const _Vector2<T>& aJ, const _Vector2<T>& aC);
52 inline Matrix3(const T& a11, const T& a12, const T& a13,
53 const T& a21, const T& a22, const T& a23,
54 const T& a31, const T& a32, const T& a33);
56 inline SelfType& operator=(const SelfType& aRhv);
58 inline SelfType& set(const T& aValue);
59 inline SelfType& set(const T* aValue);
60 inline SelfType& set(const SelfType& aOther);
61 inline SelfType& set(const _Vector3<T>& aI, const _Vector3<T>& aJ, const _Vector3<T>& aC);
62 inline SelfType& set(const _Vector2<T>& aI, const _Vector2<T>& aJ, const _Vector2<T>& aC);
63 inline SelfType& set(const T& a11, const T& a12, const T& a13,
64 const T& a21, const T& a22, const T& a23,
65 const T& a31, const T& a32, const T& a33);
67 inline SelfType& identity();
68 inline static const SelfType& getIdentity();
69 inline bool isIdentity() const;
71 inline SelfType operator-() const;
72 inline SelfType& inverse();
73 inline SelfType getInversed() const;
74 inline SelfType& transpose();
75 inline SelfType getTransposed() const;
77 inline SelfType& operator+=(const SelfType& aRhv);
78 inline SelfType& operator+=(const T& aRhv);
79 inline SelfType& operator-=(const SelfType& aRhv);
80 inline SelfType& operator-=(const T& aRhv);
81 inline SelfType& operator*=(const SelfType& aRhv);
82 inline SelfType& operator*=(const T& aRhv);
83 inline SelfType& operator/=(const T& aRhv);
84 inline SelfType GetMultipliedByMember(const SelfType& aRhv) const;
85 static inline SelfType createMultipliedByMember(const SelfType& aLhv, const SelfType& aRhv);
86 inline SelfType& multiplyByMember(const SelfType& aRhv);
87 inline SelfType getDividedByMember(const SelfType& aRhv) const;
88 static inline SelfType createDividedByMember(const SelfType& aLhv, const SelfType& aRhv);
89 inline SelfType& divideByMember(const SelfType& aRhv);
91 inline T* getPointer();
92 inline const T* getPointer() const;
93 inline T& get(unsigned int aRow, unsigned int aColumn);
94 inline const T& get(unsigned int aRow, unsigned int aColumn) const;
95 inline T& get(unsigned int aAbsIndex);
96 inline const T& get(unsigned int aAbsIndex) const;
97 inline SelfType& set(unsigned int aRow, unsigned int aColumn, const T& aValue);
98 inline SelfType& set(unsigned int aAbsIndex, const T& aValue);
99 inline _Vector3<T>& getRow(unsigned int aRow);
100 inline const _Vector3<T>& getRow(unsigned int aRow) const;
101 inline SelfType& setRow(unsigned int aRow, const _Vector3<T>& aValue);
102 inline _Vector3<T> getColumn(unsigned int aColumn) const;
103 inline SelfType& setColumn(unsigned int aColumn, const _Vector3<T>& aValue);
104 inline T& operator()(unsigned int aRow, unsigned int aColumn);
105 inline const T& operator()(unsigned int aRow, unsigned int aColumn) const;
106 inline T& operator()(unsigned int aAbsIndex);
107 inline const T& operator()(unsigned int aAbsIndex) const;
108 inline T& operator[](unsigned int aAbsIndex);
109 inline const T& operator[](unsigned int aAbsIndex) const;
111 inline SelfType& lerp(const SelfType& aTo, const T& aCoeff);
112 inline SelfType getLerped(const SelfType& aTo, const T& aCoeff) const;
113 inline SelfType& makeLerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
114 static inline SelfType createLerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
115 inline SelfType& slerp(const SelfType& aTo, const T& aCoeff);
116 inline SelfType getSlerped(const SelfType& aTo, const T& aCoeff) const;
117 inline SelfType& makeSlerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
118 static inline SelfType createSlerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
120 inline T determinant() const;
122 inline _Vector3<T>& applyTransform(_Vector3<T>& aVector) const;
123 inline _Vector3<T> getAppliedTransform(const _Vector3<T>& aVector) const;
124 inline _Vector3<T>& applyRotation(_Vector3<T>& aVector) const;
125 inline _Vector3<T> getAppliedRotation(const _Vector3<T>& aVector) const;
126 inline _Vector3<T>& applyTranslate(_Vector3<T>& aVector) const;
127 inline _Vector3<T> getAppliedTranslate(const _Vector3<T>& aVector) const;
129 inline _Vector2<T>& applyTransform(_Vector2<T>& aVector) const;
130 inline _Vector2<T> getAppliedTransform(const _Vector2<T>& aVector) const;
131 inline _Vector2<T>& applyRotation(_Vector2<T>& aVector) const;
132 inline _Vector2<T> getAppliedRotation(const _Vector2<T>& aVector) const;
133 inline _Vector2<T>& applyTranslate(_Vector2<T>& aVector) const;
134 inline _Vector2<T> getAppliedTranslate(const _Vector2<T>& aVector) const;
136 inline SelfType& setRotation(const T& aAngleRAD);
137 inline SelfType& setRotation(const Matrix2<T>& aRotation);
138 inline SelfType& setRotation(const Matrix3<T>& aRotation);
139 inline SelfType& makeRotation(const T& aAngleRAD);
140 inline SelfType& makeRotation(const Matrix2<T>& aRotation);
141 inline SelfType& makeRotation(const Matrix3<T>& aRotation);
142 inline SelfType& rotate(const T& aAngleRAD);
143 inline SelfType& rotate(const Matrix2<T>& aRotation);
144 inline SelfType& rotate(const Matrix3<T>& aRotation);
145 static inline SelfType createRotation(const T& aAngleRAD);
146 static inline SelfType createRotation(const Matrix2<T>& aRotation);
147 static inline SelfType createRotation(const Matrix3<T>& aRotation);
148 inline Matrix2<T> getRotation() const;
149 inline T getRotationAngle() const;
151 inline SelfType& makeScale(const T& aX, const T& aY);
152 inline SelfType& makeScale(const _Vector2<T>& aScale);
153 inline SelfType& setScale(const T& aX, const T& aY);
154 inline SelfType& setScale(const _Vector2<T>& aScale);
155 static inline SelfType createScale(const T& aX, const T& aY);
156 static inline SelfType createScale(const _Vector2<T>& aScale);
157 inline SelfType& scale(const T& aX, const T& aY);
158 inline SelfType& scale(const _Vector2<T>& aScale);
160 inline SelfType& setTranslation(const T& aX, const T& aY);
161 inline SelfType& setTranslation(const _Vector2<T>& aTran);
162 inline SelfType& makeTranslation(const T& aX, const T& aY);
163 inline SelfType& makeTranslation(const _Vector2<T>& aTran);
164 inline SelfType& translate(const T& aX, const T& aY);
165 inline SelfType& translate(const _Vector2<T>& aTran);
166 static inline SelfType createTranslation(const T& aX, const T& aY);
167 static inline SelfType createTranslation(const _Vector2<T>& aTran);
168 inline _Vector2<T> getTranslation() const;
169 inline _Vector3<T> getFullTranslation() const;
171 inline T magnitude() const;
172 inline T magnitude_sqr() const;
173 inline T trace() const;
174 inline Matrix2<T> minorMatrix(int row, int column) const;
175 inline SelfType& makeCross(const _Vector3<T>& aVector);
176 static inline SelfType createCross(const _Vector3<T>& aVector);
178 inline const SelfType& QR_Decomposition(SelfType& aQ, SelfType& aR) const;
181 typedef Matrix3<float> Mat3f;
182 typedef Matrix3<double> Mat3d;
184 template<class T> inline Matrix3<T> operator+(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv);
185 template<class T> inline Matrix3<T> operator+(const Matrix3<T>& aLhv, const T& aRhv);
186 template<class T> inline Matrix3<T> operator+(const T& aLhv, const Matrix3<T>& aRhv);
187 template<class T> inline Matrix3<T> operator-(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv);
188 template<class T> inline Matrix3<T> operator-(const Matrix3<T>& aLhv, const T& aRhv);
189 template<class T> inline Matrix3<T> operator-(const T& aLhv, const Matrix3<T>& aRhv);
190 template<class T> inline Matrix3<T> operator*(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv);
191 template<class T> inline Matrix3<T> operator*(const Matrix3<T>& aLhv, const T& aRhv);
192 template<class T> inline Matrix3<T> operator*(const T& aLhv, const Matrix3<T>& aRhv);
193 template<class T> inline _Vector3<T> operator*(const Matrix3<T>& aLhv, const _Vector3<T>& aRhv);
194 template<class T> inline _Vector3<T> operator*(const _Vector3<T>& aLhv, const Matrix3<T>& aRhv);
195 template<class T> inline _Vector2<T> operator*(const Matrix3<T>& aLhv, const _Vector2<T>& aRhv);
196 template<class T> inline _Vector2<T> operator*(const _Vector2<T>& aLhv, const Matrix3<T>& aRhv);
197 template<class T> inline Matrix3<T> operator/(const Matrix3<T>& aLhv, const T& aRhv);
198 template<class T> inline Matrix3<T> operator/(const T& aLhv, const Matrix3<T>& aRhv);
199 template<class T> inline bool operator==(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv);
200 template<class T> inline bool operator==(const T& aLhv, const Matrix3<T>& aRhv);
201 template<class T> inline bool operator==(const Matrix3<T>& aLhv, const T& aRhv);
202 template<class T> inline bool operator!=(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv);
203 template<class T> inline bool operator!=(const T& aLhv, const Matrix3<T>& aRhv);
204 template<class T> inline bool operator!=(const Matrix3<T>& aLhv, const T& aRhv);
206 template<class T> Matrix3<T>::Matrix3() {}
208 template<class T> Matrix3<T>::Matrix3(const T& aValue):
209 i(aValue), j(aValue), k(aValue) {}
211 template<class T> Matrix3<T>::Matrix3(const T* aValue):
212 i(aValue[0], aValue[1], aValue[2]), j(aValue[3], aValue[4], aValue[5]), k(aValue[6], aValue[7], aValue[8]) {}
214 template<class T> Matrix3<T>::Matrix3(const Matrix3<T>& aOther):
215 i(aOther.i), j(aOther.j), k(aOther.k) {}
217 template<class T> Matrix3<T>::Matrix3(const _Vector3<T>& aI, const _Vector3<T>& aJ, const _Vector3<T>& aK):
218 i(aI), j(aJ), k(aK) {}
220 template<class T> Matrix3<T>::Matrix3(const _Vector2<T>& aI, const _Vector2<T>& aJ, const _Vector2<T>& aK):
221 i(aI, T(0.0f)), j(aJ, T(0.0f)), k(aK, T(1.0f)) {}
223 template<class T> Matrix3<T>::Matrix3(const T& a11, const T& a12, const T& a13,
224 const T& a21, const T& a22, const T& a23,
225 const T& a31, const T& a32, const T& a33):
226 i(a11, a12, a13), j(a21, a22, a23), k(a31, a32, a33) {}
229 template<class T> Matrix3<T>& Matrix3<T>::operator=(const Matrix3<T>& aRhv)
237 template<class T> Matrix3<T>& Matrix3<T>::set(const T& aValue)
245 template<class T> Matrix3<T>& Matrix3<T>::set(const T* aValue)
247 i.set(aValue[0], aValue[1], aValue[2]);
248 j.set(aValue[3], aValue[4], aValue[5]);
249 k.set(aValue[6], aValue[7], aValue[8]);
253 template<class T> Matrix3<T>& Matrix3<T>::set(const Matrix3<T>& aOther)
261 template<class T> Matrix3<T>& Matrix3<T>::set(const _Vector3<T>& aI, const _Vector3<T>& aJ, const _Vector3<T>& aK)
269 template<class T> Matrix3<T>& Matrix3<T>::set(const _Vector2<T>& aI, const _Vector2<T>& aJ, const _Vector2<T>& aK)
277 template<class T> Matrix3<T>& Matrix3<T>::set(const T& a11, const T& a12, const T& a13,
278 const T& a21, const T& a22, const T& a23,
279 const T& a31, const T& a32, const T& a33)
281 i.set(a11, a12, a13);
282 j.set(a21, a22, a23);
283 k.set(a31, a32, a33);
287 template<class T> inline Matrix3<T>& Matrix3<T>::identity()
289 return operator=(getIdentity());
292 template<class T> inline const Matrix3<T>& Matrix3<T>::getIdentity()
294 static Matrix3<T> identityMatrix(
295 T(1.0f), T(0.0f), T(0.0f),
296 T(0.0f), T(1.0f), T(0.0f),
297 T(0.0f), T(0.0f), T(1.0f));
298 return identityMatrix;
301 template<class T> inline bool Matrix3<T>::isIdentity() const
303 return *this == getIdentity();
306 template<class T> inline Matrix3<T> Matrix3<T>::operator-() const
308 return Matrix3<T>(-i, -j, -k);
311 template<class T> inline Matrix3<T>& Matrix3<T>::inverse()
313 static const T t0(0.0f);
314 static const T t1(1.0f);
317 if(EffectsEqual(s, t0)) return *this;
319 return set( (j.y * k.z - k.y * j.z) * inv_det, -(i.y * k.z - k.y * i.z) * inv_det, (i.y * j.z - j.y * i.z) * inv_det,
320 -(j.x * k.z - k.x * j.z) * inv_det, (i.x * k.z - k.x * i.z) * inv_det, -(i.x * j.z - j.x * i.z) * inv_det,
321 (j.x * k.y - k.x * j.y) * inv_det, -(i.x * k.y - k.x * i.y) * inv_det, (i.x * j.y - j.x * i.y) * inv_det);
323 template<class T> inline Matrix3<T> Matrix3<T>::getInversed() const
325 static const T t0(0.0f);
326 static const T t1(1.0f);
329 if(EffectsEqual(s, t0)) return *this;
331 return Matrix3<T>( (j.y * k.z - k.y * j.z) * inv_det, -(i.y * k.z - k.y * i.z) * inv_det, (i.y * j.z - j.y * i.z) * inv_det,
332 -(j.x * k.z - k.x * j.z) * inv_det, (i.x * k.z - k.x * i.z) * inv_det, -(i.x * j.z - j.x * i.z) * inv_det,
333 (j.x * k.y - k.x * j.y) * inv_det, -(i.x * k.y - k.x * i.y) * inv_det, (i.x * j.y - j.x * i.y) * inv_det);
336 template <class T> inline T Matrix3<T>::determinant() const
339 i.x * (j.y * k.z - j.z * k.y)
340 - i.y * (j.x * k.z - j.z * k.x)
341 + i.z * (j.x * k.y - j.y * k.x);
344 template<class T> inline Matrix3<T>& Matrix3<T>::transpose()
346 EffectsSwap(i.y, j.x);
347 EffectsSwap(i.z, k.x);
348 EffectsSwap(j.z, k.y);
352 template<class T> inline Matrix3<T> Matrix3<T>::getTransposed() const
354 return Matrix3<T>( i.x, j.x, k.x,
359 template<class T> inline T* Matrix3<T>::getPointer()
361 return i.getPointer();
364 template<class T> inline const T* Matrix3<T>::getPointer() const
366 return i.getPointer();
369 template<class T> inline T& Matrix3<T>::get(unsigned int aRow, unsigned int aColumn)
371 return operator()(aRow, aColumn);
374 template<class T> inline const T& Matrix3<T>::get(unsigned int aRow, unsigned int aColumn) const
376 return operator()(aRow, aColumn);
379 template<class T> inline T& Matrix3<T>::get(unsigned int aAbsIndex)
381 return operator()(aAbsIndex);
384 template<class T> inline const T& Matrix3<T>::get(unsigned int aAbsIndex) const
386 return operator()(aAbsIndex);
389 template<class T> inline _Vector3<T>& Matrix3<T>::getRow(unsigned int aRow)
401 template<class T> inline const _Vector3<T>& Matrix3<T>::getRow(unsigned int aRow) const
413 template<class T> inline _Vector3<T> Matrix3<T>::getColumn(unsigned int aColumn) const
418 return _Vector3<T>(i.y, j.y, k.y);
420 return _Vector3<T>(i.z, j.z, k.z);
423 return _Vector3<T>(i.x, j.x, k.x);
426 template<class T> inline T& Matrix3<T>::operator()(unsigned int aRow, unsigned int aColumn)
428 return operator[]((aRow * 3) + aColumn);
431 template<class T> inline const T& Matrix3<T>::operator()(unsigned int aRow, unsigned int aColumn) const
433 return operator[]((aRow * 3) + aColumn);
436 template<class T> inline T& Matrix3<T>::operator()(unsigned int aAbsIndex)
438 return operator[](aAbsIndex);
441 template<class T> inline const T& Matrix3<T>::operator()(unsigned int aAbsIndex) const
443 return operator[](aAbsIndex);
446 template<class T> inline T& Matrix3<T>::operator[](unsigned int aAbsIndex)
448 return getPointer()[aAbsIndex];
451 template<class T> inline const T& Matrix3<T>::operator[](unsigned int aAbsIndex) const
453 return getPointer()[aAbsIndex];
456 template<class T> inline Matrix3<T>& Matrix3<T>::setColumn(unsigned int aColumn, const _Vector3<T>& aValue)
480 template<class T> inline Matrix3<T>& Matrix3<T>::setRow(unsigned int aRow, const _Vector3<T>& aValue)
498 template<class T> inline Matrix3<T>& Matrix3<T>::set(unsigned int aRow, unsigned int aColumn, const T& aValue)
500 operator()(aRow, aColumn) = aValue;
504 template<class T> inline Matrix3<T>& Matrix3<T>::set(unsigned int aAbsIndex, const T& aValue)
506 operator()(aAbsIndex) = aValue;
512 template<class T> inline Matrix3<T>& Matrix3<T>::operator+=(const Matrix3<T>& aRhv)
519 template<class T> inline Matrix3<T>& Matrix3<T>::operator+=(const T& aRhv)
526 template<class T> inline Matrix3<T>& Matrix3<T>::operator-=(const Matrix3<T>& aRhv)
533 template<class T> inline Matrix3<T>& Matrix3<T>::operator-=(const T& aRhv)
540 template<class T> inline Matrix3<T>& Matrix3<T>::operator*=(const T& aRhv)
548 template<class T> inline Matrix3<T> Matrix3<T>::GetMultipliedByMember(const Matrix3<T>& aRhv) const
550 return Matrix3<T>(i * aRhv.i, j * aRhv.j, k * aRhv.k);
553 template<class T> inline Matrix3<T>& Matrix3<T>::multiplyByMember(const Matrix3<T>& aRhv)
561 template<class T> inline Matrix3<T> Matrix3<T>::createMultipliedByMember(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
563 return Matrix3<T>(aLhv.i * aRhv.i, aLhv.j * aRhv.j, aLhv.k * aRhv.k);
566 template<class T> inline Matrix3<T>& Matrix3<T>::operator*=(const Matrix3<T>& aRhv)
569 i.x * aRhv.i.x + i.y * aRhv.j.x + i.z * aRhv.k.x,
570 i.x * aRhv.i.y + i.y * aRhv.j.y + i.z * aRhv.k.y,
571 i.x * aRhv.i.z + i.y * aRhv.j.z + i.z * aRhv.k.z,
573 j.x * aRhv.i.x + j.y * aRhv.j.x + j.z * aRhv.k.x,
574 j.x * aRhv.i.y + j.y * aRhv.j.y + j.z * aRhv.k.y,
575 j.x * aRhv.i.z + j.y * aRhv.j.z + j.z * aRhv.k.z,
577 k.x * aRhv.i.x + k.y * aRhv.j.x + k.z * aRhv.k.x,
578 k.x * aRhv.i.y + k.y * aRhv.j.y + k.z * aRhv.k.y,
579 k.x * aRhv.i.z + k.y * aRhv.j.z + k.z * aRhv.k.z);
583 template<class T> inline Matrix3<T> Matrix3<T>::getDividedByMember(const Matrix3<T>& aRhv) const
585 return Matrix3<T>(i / aRhv.i, j / aRhv.j, k / aRhv.k);
588 template<class T> inline Matrix3<T>& Matrix3<T>::divideByMember(const Matrix3<T>& aRhv)
595 template<class T> inline Matrix3<T> Matrix3<T>::createDividedByMember(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
597 return Matrix3<T>(aLhv.i / aRhv.i, aLhv.j / aRhv.j, aLhv.k / aRhv.k);
600 template<class T> inline Matrix3<T>& Matrix3<T>::operator/=(const T& aRhv)
610 template<class T> inline _Vector3<T>& Matrix3<T>::applyTransform(_Vector3<T>& aVector) const
613 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x,
614 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y,
615 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z);
618 template<class T> inline _Vector3<T> Matrix3<T>::getAppliedTransform(const _Vector3<T>& aVector) const
621 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x,
622 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y,
623 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z);
626 template<class T> inline _Vector3<T>& Matrix3<T>::applyRotation(_Vector3<T>& aVector) const
629 aVector.x * i.x + aVector.y * j.x,
630 aVector.x * i.y + aVector.y * j.y,
634 template<class T> inline _Vector3<T> Matrix3<T>::getAppliedRotation(const _Vector3<T>& aVector) const
637 aVector.x * i.x + aVector.y * j.x,
638 aVector.x * i.y + aVector.y * j.y,
642 template<class T> inline _Vector3<T>& Matrix3<T>::applyTranslate(_Vector3<T>& aVector) const
645 aVector.x + aVector.z * k.x,
646 aVector.y + aVector.z * k.y,
650 template<class T> inline _Vector3<T> Matrix3<T>::getAppliedTranslate(const _Vector3<T>& aVector) const
653 aVector.x + aVector.z * k.x,
654 aVector.y + aVector.z * k.y,
658 template<class T> inline _Vector2<T>& Matrix3<T>::applyTransform(_Vector2<T>& aVector) const
661 aVector.x * i.x + aVector.y * j.x + k.x,
662 aVector.x * i.y + aVector.y * j.y + k.y);
665 template<class T> inline _Vector2<T> Matrix3<T>::getAppliedTransform(const _Vector2<T>& aVector) const
668 aVector.x * i.x + aVector.y * j.x + k.x,
669 aVector.x * i.y + aVector.y * j.y + k.y);
672 template<class T> inline _Vector2<T>& Matrix3<T>::applyRotation(_Vector2<T>& aVector) const
675 aVector.x * i.x + aVector.y * j.x,
676 aVector.x * i.y + aVector.y * j.y);
679 template<class T> inline _Vector2<T> Matrix3<T>::getAppliedRotation(const _Vector2<T>& aVector) const
682 aVector.x * i.x + aVector.y * j.x,
683 aVector.x * i.y + aVector.y * j.y);
686 template<class T> inline _Vector2<T>& Matrix3<T>::applyTranslate(_Vector2<T>& aVector) const
693 template<class T> inline _Vector2<T> Matrix3<T>::getAppliedTranslate(const _Vector2<T>& aVector) const
700 template<class T> inline Matrix3<T>& Matrix3<T>::setRotation(const T& aAngleRAD)
702 const T s = effects_sin(aAngleRAD);
703 const T c = effects_cos(aAngleRAD);
710 template<class T> inline Matrix3<T>& Matrix3<T>::setRotation(const Matrix2<T>& aRotation)
718 template<class T> inline Matrix3<T>& Matrix3<T>::setRotation(const Matrix3<T>& aRotation)
726 template<class T> inline Matrix3<T>& Matrix3<T>::makeRotation(const T& aAngleRAD)
729 return setRotation(aAngleRAD);
731 template<class T> inline Matrix3<T>& Matrix3<T>::makeRotation(const Matrix2<T>& aRotation)
734 return setRotation(aRotation);
736 template<class T> inline Matrix3<T>& Matrix3<T>::makeRotation(const Matrix3<T>& aRotation)
739 return setRotation(aRotation);
741 template<class T> inline Matrix3<T>& Matrix3<T>::rotate(const T& aAngleRAD)
743 const T s = effects_sin(aAngleRAD);
744 const T c = effects_cos(aAngleRAD);
745 const T ix = i.x * c - i.y * s;
746 const T iy = i.x * s + i.y * c;
747 const T jx = j.x * c - j.y * s;
748 const T jy = j.x * s + j.y * c;
755 template<class T> inline Matrix3<T>& Matrix3<T>::rotate(const Matrix2<T>& aRotation)
757 const T ix = i.x * aRotation.i.x + i.y * aRotation.j.x;
758 const T iy = i.x * aRotation.i.y + i.y * aRotation.j.y;
759 const T jx = j.x * aRotation.i.x + j.y * aRotation.j.x;
760 const T jy = j.x * aRotation.i.y + j.y * aRotation.j.y;
767 template<class T> inline Matrix3<T>& Matrix3<T>::rotate(const Matrix3<T>& aRotation)
769 const T ix = i.x * aRotation.i.x + i.y * aRotation.j.x;
770 const T iy = i.x * aRotation.i.y + i.y * aRotation.j.y;
771 const T jx = j.x * aRotation.i.x + j.y * aRotation.j.x;
772 const T jy = j.x * aRotation.i.y + j.y * aRotation.j.y;
779 template<class T> inline Matrix3<T> Matrix3<T>::createRotation(const T& aAngleRAD)
781 return Matrix3<T>().makeRotation(aAngleRAD);
783 template<class T> inline Matrix3<T> Matrix3<T>::createRotation(const Matrix2<T>& aRotation)
785 return Matrix3<T>().makeRotation(aRotation);
787 template<class T> inline Matrix3<T> Matrix3<T>::createRotation(const Matrix3<T>& aRotation)
789 return Matrix3<T>().makeRotation(aRotation);
791 template<class T> inline Matrix2<T> Matrix3<T>::getRotation() const
793 return Matrix2<T>(i.x, i.y, j.x, j.y);
795 template<class T> inline T Matrix3<T>::getRotationAngle() const
797 static const T t0(0.0f);
798 static const T t1(1.0f);
800 static const _Vector2<T> orig_vector(t1, t0);
801 static const _Vector2<T> orig_vector_cross(t0, t1);
803 _Vector2<T> rotated(getAppliedRotation(orig_vector).normalize());
804 const T angleCos = effects_clamp(rotated.dot(orig_vector), -t1, t1);
805 const T angleCosCross = effects_clamp(rotated.dot(orig_vector_cross), -t1, t1);
807 if(angleCosCross > t0)
808 return effects_acos(angleCos);
809 return -effects_acos(angleCos);
812 template<class T> inline Matrix3<T>& Matrix3<T>::makeScale(const T& aX, const T& aY)
815 return setScale(aX, aY);
817 template<class T> inline Matrix3<T>& Matrix3<T>::makeScale(const _Vector2<T>& aScale)
819 return makeScale(aScale.x, aScale.y);
821 template<class T> inline Matrix3<T> Matrix3<T>::createScale(const T& aX, const T& aY)
823 return Matrix3<T>().makeScale(aX, aY);
825 template<class T> inline Matrix3<T> Matrix3<T>::createScale(const _Vector2<T>& aScale)
827 return Matrix3<T>().makeScale(aScale);
829 template<class T> inline Matrix3<T>& Matrix3<T>::setScale(const T& aX, const T& aY)
837 template<class T> inline Matrix3<T>& Matrix3<T>::setScale(const _Vector2<T>& aScale)
839 return setScale(aScale.x, aScale.y);
841 template<class T> inline Matrix3<T>& Matrix3<T>::scale(const T& aX, const T& aY)
843 i.x *= aX; i.y *= aY;
844 j.x *= aX; j.y *= aY;
848 template<class T> inline Matrix3<T>& Matrix3<T>::scale(const _Vector2<T>& aScale)
850 return scale(aScale.x, aScale.y);
853 template<class T> inline Matrix3<T>& Matrix3<T>::setTranslation(const T& aX, const T& aY)
859 template<class T> inline Matrix3<T>& Matrix3<T>::setTranslation(const _Vector2<T>& aTran)
861 return setTranslation(aTran.x, aTran.y);
863 template<class T> inline Matrix3<T>& Matrix3<T>::makeTranslation(const T& aX, const T& aY)
866 return setTranslation(aX, aY);
868 template<class T> inline Matrix3<T>& Matrix3<T>::makeTranslation(const _Vector2<T>& aTran)
870 return makeTranslation(aTran.x, aTran.y);
872 template<class T> inline Matrix3<T> Matrix3<T>::createTranslation(const T& aX, const T& aY)
874 return Matrix3<T>().makeTranslation(aX, aY);
876 template<class T> inline Matrix3<T> Matrix3<T>::createTranslation(const _Vector2<T>& aTran)
878 return Matrix3<T>().makeTranslation(aTran);
880 template<class T> inline Matrix3<T>& Matrix3<T>::translate(const T& aX, const T& aY)
886 template<class T> inline Matrix3<T>& Matrix3<T>::translate(const _Vector2<T>& aTran)
888 return translate(aTran.x, aTran.y);
890 template<class T> inline _Vector2<T> Matrix3<T>::getTranslation() const
892 return k.swizzle(0, 1);
894 template<class T> inline _Vector3<T> Matrix3<T>::getFullTranslation() const
899 template<class T> inline Matrix3<T>& Matrix3<T>::lerp(const Matrix3<T>& aTo, const T& aCoeff)
901 i.lerp(aTo.i, aCoeff);
902 j.lerp(aTo.j, aCoeff);
903 k.lerp(aTo.k, aCoeff);
907 template<class T> inline Matrix3<T> Matrix3<T>::getLerped(const Matrix3<T>& aTo, const T& aCoeff) const
909 Matrix3<T> result(i.getLerped(aTo.i, aCoeff),
910 j.getLerped(aTo.j, aCoeff),
911 k.getLerped(aTo.k, aCoeff));
915 template<class T> inline Matrix3<T>& Matrix3<T>::makeLerped(const Matrix3<T>& aFrom, const Matrix3<T>& aTo, const T& aCoeff)
917 i.makeLerped(aFrom.i, aTo.i, aCoeff);
918 j.makeLerped(aFrom.j, aTo.j, aCoeff);
919 k.makeLerped(aFrom.k, aTo.k, aCoeff);
922 template<class T> inline Matrix3<T> Matrix3<T>::createLerped(const Matrix3<T>& aFrom, const Matrix3<T>& aTo, const T& aCoeff)
924 return Matrix3<T>().makeLerped(aFrom, aTo, aCoeff);
927 template<class T> inline Matrix3<T>& Matrix3<T>::slerp(const Matrix3<T>& aTo, const T& aCoeff)
929 setRotation(effects_lerp(getRotationAngle(), aTo.getRotationAngle(), aCoeff));
930 k.lerp(aTo.k, aCoeff);
934 template<class T> inline Matrix3<T> Matrix3<T>::getSlerped(const Matrix3<T>& aTo, const T& aCoeff) const
937 result.makeRotation(effects_lerp(getRotationAngle(), aTo.getRotationAngle(), aCoeff));
938 result.k = k.getLerped(aTo.k, aCoeff);
942 template<class T> inline Matrix3<T>& Matrix3<T>::makeSlerped(const Matrix3<T>& aFrom, const Matrix3<T>& aTo, const T& aCoeff)
944 makeRotation(effects_lerp(aFrom.getRotationAngle(), aTo.getRotationAngle(), aCoeff));
945 k.makeLerped(aFrom.k, aTo.k, aCoeff);
949 template<class T> inline Matrix3<T> Matrix3<T>::createSlerped(const Matrix3<T>& aFrom, const Matrix3<T>& aTo, const T& aCoeff)
951 return Matrix3<T>().makeSlerped(aFrom, aTo, aCoeff);
954 template<class T> inline T Matrix3<T>::magnitude_sqr() const
956 return i.dot(i) + j.dot(j) + k.dot(k);
958 template<class T> inline T Matrix3<T>::magnitude() const
960 return effects_sqrt(magnitude_sqr());
962 template<class T> inline T Matrix3<T>::trace() const
964 return i.x + j.y + k.z;
966 template<class T> inline Matrix2<T> Matrix3<T>::minorMatrix(int row, int column) const
971 int column_counter = 0;
972 for(int current_row = 0; 3 > current_row; ++current_row)
974 if(current_row == row)
978 for(int current_column = 0; 3 > current_column; ++current_column)
980 if(current_column == column)
983 result(row_counter, column_counter) = this->operator()(current_row, current_column);
990 template<class T> inline Matrix3<T>& Matrix3<T>::makeCross(const _Vector3<T>& aVector)
992 static const T t0(0.0f);
994 return set( t0, -aVector.z, aVector.y,
995 aVector.z, t0, -aVector.x,
996 -aVector.y, aVector.x, t0);
998 template<class T> inline Matrix3<T> Matrix3<T>::createCross(const _Vector3<T>& aVector)
1000 return Matrix3<T>().makeCross(aVector);
1003 template<class T> inline const Matrix3<T>& Matrix3<T>::QR_Decomposition(Matrix3<T>& aQ, Matrix3<T>& aR) const
1005 aR.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
1009 for (int k = 0; k < 3; ++k)
1011 for (int i = 0; i < k; ++i)
1013 _Vector3<T> v1 = aQ.getColumn(i);
1014 _Vector3<T> v2 = aQ.getColumn(k);
1015 aR(i, k) = v1.dot(v2);
1017 _Vector3<T> v3 = aR(i, k) * v1;
1018 _Vector3<T> v4 = v2 - v3;
1019 aQ.setColumn(k, v4);
1022 _Vector3<T> qv1 = aQ.getColumn(k);
1023 aR(k, k) = qv1.length();
1025 _Vector3<T> qv2 = qv1 / aR(k, k);
1026 aQ.setColumn(k, qv2);
1032 template<class T> inline bool isEqual(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv, const T& aEpsilon = effects_epsilon<T>::epsilon())
1034 return isEqual(aLhv.i, aRhv.i, aEpsilon) && isEqual(aLhv.j, aRhv.j, aEpsilon) && isEqual(aLhv.k, aRhv.k, aEpsilon);
1036 template<class T> inline Matrix3<T> operator+(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
1038 return Matrix3<T>(aLhv.i + aRhv.i, aLhv.j + aRhv.j, aLhv.k + aRhv.k);
1040 template<class T> inline Matrix3<T> operator+(const Matrix3<T>& aLhv, const T& aRhv)
1042 return Matrix3<T>(aLhv.i + aRhv, aLhv.j + aRhv, aLhv.k + aRhv);
1044 template<class T> inline Matrix3<T> operator+(const T& aLhv, const Matrix3<T>& aRhv)
1046 return Matrix3<T>(aLhv + aRhv.i, aLhv + aRhv.j, aLhv + aRhv.k);
1048 template<class T> inline Matrix3<T> operator-(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
1050 return Matrix3<T>(aLhv.i - aRhv.i, aLhv.j - aRhv.j, aLhv.k - aRhv.k);
1052 template<class T> inline Matrix3<T> operator-(const Matrix3<T>& aLhv, const T& aRhv)
1054 return Matrix3<T>(aLhv.i - aRhv, aLhv.j - aRhv, aLhv.k - aRhv);
1056 template<class T> inline Matrix3<T> operator-(const T& aLhv, const Matrix3<T>& aRhv)
1058 return Matrix3<T>(aLhv - aRhv.i, aLhv - aRhv.j, aLhv - aRhv.k);
1060 template<class T> inline Matrix3<T> operator*(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
1063 aLhv.i.x * aRhv.i.x + aLhv.i.y * aRhv.j.x + aLhv.i.z * aRhv.k.x,
1064 aLhv.i.x * aRhv.i.y + aLhv.i.y * aRhv.j.y + aLhv.i.z * aRhv.k.y,
1065 aLhv.i.x * aRhv.i.z + aLhv.i.y * aRhv.j.z + aLhv.i.z * aRhv.k.z,
1067 aLhv.j.x * aRhv.i.x + aLhv.j.y * aRhv.j.x + aLhv.j.z * aRhv.k.x,
1068 aLhv.j.x * aRhv.i.y + aLhv.j.y * aRhv.j.y + aLhv.j.z * aRhv.k.y,
1069 aLhv.j.x * aRhv.i.z + aLhv.j.y * aRhv.j.z + aLhv.j.z * aRhv.k.z,
1071 aLhv.k.x * aRhv.i.x + aLhv.k.y * aRhv.j.x + aLhv.k.z * aRhv.k.x,
1072 aLhv.k.x * aRhv.i.y + aLhv.k.y * aRhv.j.y + aLhv.k.z * aRhv.k.y,
1073 aLhv.k.x * aRhv.i.z + aLhv.k.y * aRhv.j.z + aLhv.k.z * aRhv.k.z);
1075 template<class T> inline Matrix3<T> operator*(const Matrix3<T>& aLhv, const T& aRhv)
1077 return Matrix3<T>(aLhv.i * aRhv, aLhv.j * aRhv, aLhv.k * aRhv);
1079 template<class T> inline Matrix3<T> operator*(const T& aLhv, const Matrix3<T>& aRhv)
1081 return Matrix3<T>(aLhv * aRhv.i, aLhv * aRhv.j, aLhv * aRhv.k);
1083 template<class T> inline _Vector3<T> operator*(const _Vector3<T>& aLhv, const Matrix3<T>& aRhv)
1085 return aRhv.getAppliedTransform(aLhv);
1087 template<class T> inline _Vector3<T> operator*(const Matrix3<T>& aLhv, const _Vector3<T>& aRhv)
1089 return _Vector3<T>( aLhv.i.x * aRhv.x + aLhv.i.y * aRhv.y + aLhv.i.z * aRhv.z,
1090 aLhv.j.x * aRhv.x + aLhv.j.y * aRhv.y + aLhv.j.z * aRhv.z,
1091 aLhv.k.x * aRhv.x + aLhv.k.y * aRhv.y + aLhv.k.z * aRhv.z);
1093 template<class T> inline _Vector2<T> operator*(const _Vector2<T>& aLhv, const Matrix3<T>& aRhv)
1095 return aRhv.getAppliedTransform(aLhv);
1097 template<class T> inline _Vector2<T> operator*(const Matrix3<T>& aLhv, const _Vector2<T>& aRhv)
1099 return _Vector2<T>( aLhv.i.x * aRhv.x + aLhv.i.y * aRhv.y + aLhv.i.z,
1100 aLhv.j.x * aRhv.x + aLhv.j.y * aRhv.y + aLhv.j.z);
1102 template<class T> inline Matrix3<T> operator/(const Matrix3<T>& aLhv, const T& aRhv)
1104 return Matrix3<T>(aLhv.i / aRhv, aLhv.j / aRhv, aLhv.k / aRhv);
1106 template<class T> inline Matrix3<T> operator/(const T& aLhv, const Matrix3<T>& aRhv)
1108 return Matrix3<T>(aLhv / aRhv.i, aLhv / aRhv.j, aLhv / aRhv.k);
1110 template<class T> inline bool operator==(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
1112 return aLhv.i == aRhv.i && aLhv.j == aRhv.j && aLhv.k == aRhv.k;
1114 template<class T> inline bool operator==(const Matrix3<T>& aLhv, const T& aRhv)
1116 return aLhv.i == aRhv && aLhv.j == aRhv && aLhv.k == aRhv;
1118 template<class T> inline bool operator==(const T& aLhv, const Matrix3<T>& aRhv)
1120 return aLhv == aRhv.i && aLhv == aRhv.j && aLhv == aRhv.k;
1122 template<class T> inline bool operator!=(const Matrix3<T>& aLhv, const Matrix3<T>& aRhv)
1124 return !(aLhv == aRhv);
1126 template<class T> inline bool operator!=(const Matrix3<T>& aLhv, const T& aRhv)
1128 return !(aLhv == aRhv);
1130 template<class T> inline bool operator!=(const T& aLhv, const Matrix3<T>& aRhv)
1132 return !(aLhv == aRhv);
1134 } } } } //Tizen::Ui::Effects::_Utils
1136 #endif //_FUI_EFFECTS_INTERNAL_UTILS_MATRIX3_H_