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_UtilsMatrix4.h
20 * @brief The Matrix4 class
24 #ifndef _FUI_EFFECTS_INTERNAL_UTILS_MATRIX4_H_
25 #define _FUI_EFFECTS_INTERNAL_UTILS_MATRIX4_H_
27 #include "FUiEffects_UtilsAdapterFunctions.h"
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Utils
31 template<class T> class Vector4;
32 template<class T> class _Vector3;
33 template<class T> class Matrix3;
34 template<class T> class Quaternion;
36 template<class T> class Matrix4
39 typedef Matrix4<T> SelfType;
48 inline explicit Matrix4(const T& aValue);
49 inline explicit Matrix4(const T* aValues);
50 inline Matrix4(const SelfType& aOther);
51 inline Matrix4(const Vector4<T>& aI, const Vector4<T>& aJ,
52 const Vector4<T>& aK, const Vector4<T>& aC);
53 inline Matrix4(const _Vector3<T>& aI, const _Vector3<T>& aJ,
54 const _Vector3<T>& aK, const _Vector3<T>& aC);
55 inline Matrix4(const T& a11, const T& a12, const T& a13, const T& a14,
56 const T& a21, const T& a22, const T& a23, const T& a24,
57 const T& a31, const T& a32, const T& a33, const T& a34,
58 const T& a41, const T& a42, const T& a43, const T& a44);
60 inline SelfType& operator=(const SelfType& aRhv);
62 inline SelfType& set(const T& aValue);
63 inline SelfType& set(const T* aValues);
64 inline SelfType& set(const SelfType& aOther);
65 inline SelfType& set(const Vector4<T>& aI, const Vector4<T>& aJ,
66 const Vector4<T>& aK, const Vector4<T>& aC);
67 inline SelfType& set(const _Vector3<T>& aI, const _Vector3<T>& aJ,
68 const _Vector3<T>& aK, const _Vector3<T>& aC);
69 inline SelfType& set(const T& a11, const T& a12, const T& a13, const T& a14,
70 const T& a21, const T& a22, const T& a23, const T& a24,
71 const T& a31, const T& a32, const T& a33, const T& a34,
72 const T& a41, const T& a42, const T& a43, const T& a44);
74 inline SelfType& identity();
75 inline static const SelfType& getIdentity();
76 inline bool isIdentity() const;
78 inline SelfType operator-() const;
79 inline SelfType& inverse();
80 inline SelfType getInversed() const;
81 inline SelfType& transpose();
82 inline SelfType getTransposed() const;
84 inline SelfType& operator+=(const SelfType& aRhv);
85 inline SelfType& operator+=(const T& aRhv);
86 inline SelfType& operator-=(const SelfType& aRhv);
87 inline SelfType& operator-=(const T& aRhv);
88 inline SelfType& operator*=(const SelfType& aRhv);
89 inline SelfType& operator*=(const T& aRhv);
90 inline SelfType& operator/=(const T& aRhv);
91 inline SelfType GetMultipliedByMember(const SelfType& aRhv) const;
92 inline SelfType& multiplyByMember(const SelfType& aRhv);
93 static inline SelfType createMultipliedByMember(const SelfType& aLhv, const SelfType& aRhv);
94 inline SelfType getDividedByMember(const SelfType& aRhv) const;
95 inline SelfType& divideByMember(const SelfType& aRhv);
96 static inline SelfType createDividedByMember(const SelfType& aLhv, const SelfType& aRhv);
98 inline T* getPointer();
99 inline const T* getPointer() const;
100 inline T& get(unsigned int aRow, unsigned int aColumn);
101 inline const T& get(unsigned int aRow, unsigned int aColumn) const;
102 inline T& get(unsigned int aAbsIndex);
103 inline const T& get(unsigned int aAbsIndex) const;
104 inline SelfType& set(unsigned int aRow, unsigned int aColumn, const T& aValue);
105 inline SelfType& set(unsigned int aAbsIndex, const T& aValue);
106 inline Vector4<T>& getRow(unsigned int aRow);
107 inline const Vector4<T>& getRow(unsigned int aRow) const;
108 inline SelfType& setRow(unsigned int aRow, const Vector4<T>& aValue);
109 inline Vector4<T> getColumn(unsigned int aColumn) const;
110 inline SelfType& setColumn(unsigned int aColumn, const Vector4<T>& aValue);
111 inline T& operator()(unsigned int aRow, unsigned int aColumn);
112 inline const T& operator()(unsigned int aRow, unsigned int aColumn) const;
113 inline T& operator()(unsigned int aAbsIndex);
114 inline const T& operator()(unsigned int aAbsIndex) const;
115 inline T& operator[](unsigned int aAbsIndex);
116 inline const T& operator[](unsigned int aAbsIndex) const;
118 inline SelfType& lerp(const SelfType& aTo, const T& aCoeff);
119 inline SelfType getLerped(const SelfType& aTo, const T& aCoeff) const;
120 inline SelfType& makeLerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
121 static inline SelfType createLerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
122 inline SelfType& slerp(const SelfType& aTo, const T& aCoeff);
123 inline SelfType getSlerped(const SelfType& aTo, const T& aCoeff) const;
124 inline SelfType& makeSlerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
125 static inline SelfType createSlerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
127 inline T determinant() const;
129 inline Vector4<T>& applyTransform(Vector4<T>& aVector) const;
130 inline Vector4<T> getAppliedTransform(const Vector4<T>& aVector) const;
131 inline Vector4<T>& applyRotation(Vector4<T>& aVector) const;
132 inline Vector4<T> getAppliedRotation(const Vector4<T>& aVector) const;
133 inline Vector4<T>& applyTranslate(Vector4<T>& aVector) const;
134 inline Vector4<T> getAppliedTranslate(const Vector4<T>& aVector) const;
136 inline _Vector3<T>& applyTransform(_Vector3<T>& aVector) const;
137 inline _Vector3<T> getAppliedTransform(const _Vector3<T>& aVector) const;
138 inline _Vector3<T>& applyRotation(_Vector3<T>& aVector) const;
139 inline _Vector3<T> getAppliedRotation(const _Vector3<T>& aVector) const;
140 inline _Vector3<T>& applyTranslate(_Vector3<T>& aVector) const;
141 inline _Vector3<T> getAppliedTranslate(const _Vector3<T>& aVector) const;
143 inline Quaternion<T>& applyRotation(Quaternion<T>& aQuaternion) const;
144 inline Quaternion<T> getAppliedRotation(const Quaternion<T>& aQuaternion) const;
146 inline SelfType& setRotation(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder = ROTATION_XYZ);
147 inline SelfType& setRotation(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder = ROTATION_XYZ);
148 inline SelfType& setRotationX(const T& aAngleRAD);
149 inline SelfType& setRotationY(const T& aAngleRAD);
150 inline SelfType& setRotationZ(const T& aAngleRAD);
151 inline SelfType& setRotationAxis(const _Vector3<T>& aAxis, const T& aAngleRAD);
152 inline SelfType& setRotationAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD);
153 inline SelfType& setRotation(const Quaternion<T>& aRotation);
154 inline SelfType& setRotation(const Matrix3<T>& aRotation);
155 inline SelfType& makeRotation(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder = ROTATION_XYZ);
156 inline SelfType& makeRotation(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder = ROTATION_XYZ);
157 inline SelfType& makeRotationX(const T& aAngleRAD);
158 inline SelfType& makeRotationY(const T& aAngleRAD);
159 inline SelfType& makeRotationZ(const T& aAngleRAD);
160 inline SelfType& makeRotationAxis(const _Vector3<T>& aAxis, const T& aAngleRAD);
161 inline SelfType& makeRotationAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD);
162 inline SelfType& makeRotation(const Quaternion<T>& aRotation);
163 inline SelfType& makeRotation(const Matrix3<T>& aRotation);
164 inline SelfType& rotate(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder = ROTATION_XYZ);
165 inline SelfType& rotate(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder3 = ROTATION_XYZ);
166 inline SelfType& rotateX(const T& aAngleRAD);
167 inline SelfType& rotateY(const T& aAngleRAD);
168 inline SelfType& rotateZ(const T& aAngleRAD);
169 inline SelfType& rotateAxis(const _Vector3<T>& aAxis, const T& aAngleRAD);
170 inline SelfType& rotateAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD);
171 inline SelfType& rotate(const Quaternion<T>& aRotation);
172 inline SelfType& rotate(const Matrix3<T>& aRotation);
173 inline SelfType& rotate(const Matrix4<T>& aRotation);
174 static inline SelfType createRotation(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder = ROTATION_XYZ);
175 static inline SelfType createRotation(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder = ROTATION_XYZ);
176 static inline SelfType createRotationX(const T& aAngleRAD);
177 static inline SelfType createRotationY(const T& aAngleRAD);
178 static inline SelfType createRotationZ(const T& aAngleRAD);
179 static inline SelfType createRotationAxis(const _Vector3<T>& aAxis, const T& aAngleRAD);
180 static inline SelfType createRotationAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD);
181 static inline SelfType createRotation(const Quaternion<T>& aRotation);
182 static inline SelfType createRotation(const Matrix3<T>& aRotation);
183 inline const SelfType& getRotationAngles(T& aXAngleRAD, T& aYAngeRAD, T& aZAngleRAD, unsigned int aSolutionNumber = 1) const;
184 inline Quaternion<T> getQuaternion() const;
185 inline Quaternion<T>& getQuaternion(Quaternion<T>& aRotation) const;
186 inline Matrix3<T> getRotation() const;
187 inline Matrix3<T>& getRotation(Matrix3<T>& aRotation) const;
189 inline SelfType& makeScale(const T& aX, const T& aY, const T& aZ);
190 inline SelfType& makeScale(const _Vector3<T>& aScale);
191 inline SelfType& setScale(const T& aX, const T& aY, const T& aZ);
192 inline SelfType& setScale(const _Vector3<T>& aScale);
193 static inline SelfType createScale(const T& aX, const T& aY, const T& aZ);
194 static inline SelfType createScale(const _Vector3<T>& aScale);
195 inline SelfType& scale(const T& aX, const T& aY, const T& aZ);
196 inline SelfType& scale(const _Vector3<T>& aScale);
198 inline SelfType& setTranslation(const T& aX, const T& aY, const T& aZ);
199 inline SelfType& setTranslation(const _Vector3<T>& aTran);
200 inline SelfType& makeTranslation(const T& aX, const T& aY, const T& aZ);
201 inline SelfType& makeTranslation(const _Vector3<T>& aTran);
202 inline SelfType& translate(const T& aX, const T& aY, const T& aZ);
203 inline SelfType& translate(const _Vector3<T>& aTran);
204 static inline SelfType createTranslation(const T& aX, const T& aY, const T& aZ);
205 static inline SelfType createTranslation(const _Vector3<T>& aTran);
206 inline _Vector3<T> getTranslation() const;
207 inline Vector4<T> getFullTranslation() const;
209 inline SelfType& makeLookAtLH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp);
210 inline SelfType& makeLookAtRH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp);
211 inline SelfType& makeOrthoRH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar);
212 inline SelfType& makeOrthoLH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar);
213 inline SelfType& makeOrthoRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
214 inline SelfType& makeOrthoLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
215 inline SelfType& makePerspectiveLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
216 inline SelfType& makePerspectiveRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
217 inline SelfType& makePerspectiveLH(const T& aWidth, const T& aHeight, const T& aZnear, const T& aZFar);
218 inline SelfType& makePerspectiveRH(const T& aWidth, const T& aHeight, const T& aZnear, const T& aZFar);
219 inline SelfType& makePerspectiveFovLH(const T& aFovY, const T& aAspect, const T& aZnear, const T& aZFar);
220 inline SelfType& makePerspectiveFovRH(const T& aFovY, const T& aAspect, const T& aZnear, const T& aZFar);
221 static inline SelfType createLookAtLH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp);
222 static inline SelfType createLookAtRH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp);
223 static inline SelfType createOrthoRH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar);
224 static inline SelfType createOrthoLH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar);
225 static inline SelfType createOrthoRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
226 static inline SelfType createOrthoLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
227 static inline SelfType createPerspectiveLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
228 static inline SelfType createPerspectiveRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar);
229 static inline SelfType createPerspectiveLH(const T& aWidth, const T& aHeight, const T& aZnear, const T& aZFar);
230 static inline SelfType createPerspectiveRH(const T& aWidth, const T& aHeight, const T& aZnear, const T& aZFar);
231 static inline SelfType createPerspectiveFovLH(const T& aFovY, const T& aAspect, const T& aZnear, const T& aZFar);
232 static inline SelfType createPerspectiveFovRH(const T& aFovY, const T& aAspect, const T& aZnear, const T& aZFar);
234 inline bool getOrthoParamsRH(T& aLeft, T& aRight, T& aTop, T& aBottom, T& aZNear, T& aZFar) const;
235 inline bool getPerspectiveParamsRH(T& aLeft, T& aRight, T& aTop, T& aBottom, T& aZNear, T& aZFar) const;
236 inline bool getPerspectiveParamsRH(T& aFovY, T& aAspect, T& aZNear, T& aZFar) const;
237 inline bool getViewParams(_Vector3<T>& aPosition, _Vector3<T>& aDirection, _Vector3<T>& aUp, _Vector3<T>& aRight) const;
240 typedef Matrix4<float> Mat4f;
241 typedef Matrix4<double> Mat4d;
243 template<class T> inline Matrix4<T> operator+(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv);
244 template<class T> inline Matrix4<T> operator+(const Matrix4<T>& aLhv, const T& aRhv);
245 template<class T> inline Matrix4<T> operator+(const T& aLhv, const Matrix4<T>& aRhv);
246 template<class T> inline Matrix4<T> operator-(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv);
247 template<class T> inline Matrix4<T> operator-(const Matrix4<T>& aLhv, const T& aRhv);
248 template<class T> inline Matrix4<T> operator-(const T& aLhv, const Matrix4<T>& aRhv);
249 template<class T> inline Matrix4<T> operator*(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv);
250 template<class T> inline Matrix4<T> operator*(const Matrix4<T>& aLhv, const T& aRhv);
251 template<class T> inline Matrix4<T> operator*(const T& aLhv, const Matrix4<T>& aRhv);
252 template<class T> inline Vector4<T> operator*(const Matrix4<T>& aLhv, const Vector4<T>& aRhv);
253 template<class T> inline Vector4<T> operator*(const Vector4<T>& aLhv, const Matrix4<T>& aRhv);
254 template<class T> inline _Vector3<T> operator*(const Matrix4<T>& aLhv, const _Vector3<T>& aRhv);
255 template<class T> inline _Vector3<T> operator*(const _Vector3<T>& aLhv, const Matrix4<T>& aRhv);
256 template<class T> inline Matrix4<T> operator/(const Matrix4<T>& aLhv, const T& aRhv);
257 template<class T> inline Matrix4<T> operator/(const T& aLhv, const Matrix4<T>& aRhv);
258 template<class T> inline bool operator==(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv);
259 template<class T> inline bool operator==(const Matrix4<T>& aLhv, const T& aRhv);
260 template<class T> inline bool operator==(const T& aLhv, const Matrix4<T>& aRhv);
261 template<class T> inline bool operator!=(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv);
262 template<class T> inline bool operator!=(const Matrix4<T>& aLhv, const T& aRhv);
263 template<class T> inline bool operator!=(const T& aLhv, const Matrix4<T>& aRhv);
265 template<class T> inline Matrix4<T>::Matrix4() {}
267 template<class T> inline Matrix4<T>::Matrix4(const T& aValue):
268 i(aValue), j(aValue), k(aValue), c(aValue) {}
270 template<class T> inline Matrix4<T>::Matrix4(const T* aValues):
271 i(aValues[0], aValues[1], aValues[2], aValues[3]),
272 j(aValues[4], aValues[5], aValues[6], aValues[7]),
273 k(aValues[8], aValues[9], aValues[10], aValues[11]),
274 c(aValues[12], aValues[13], aValues[14], aValues[15]) {}
276 template<class T> inline Matrix4<T>::Matrix4(const Matrix4<T>& aOther):
277 i(aOther.i), j(aOther.j), k(aOther.k), c(aOther.c) {}
279 template<class T> inline Matrix4<T>::Matrix4(const Vector4<T>& aI, const Vector4<T>& aJ, const Vector4<T>& aK, const Vector4<T>& aC):
280 i(aI), j(aJ), k(aK), c(aC) {}
282 template<class T> inline Matrix4<T>::Matrix4(const _Vector3<T>& aI, const _Vector3<T>& aJ, const _Vector3<T>& aK, const _Vector3<T>& aC):
283 i(aI, T(0.0f)), j(aJ, T(0.0f)), k(aK, T(0.0f)), c(aC, T(1.0f)) {}
285 template<class T> inline Matrix4<T>::Matrix4(const T& a11, const T& a12, const T& a13, const T& a14,
286 const T& a21, const T& a22, const T& a23, const T& a24,
287 const T& a31, const T& a32, const T& a33, const T& a34,
288 const T& a41, const T& a42, const T& a43, const T& a44):
289 i(a11, a12, a13, a14), j(a21, a22, a23, a24), k(a31, a32, a33, a34), c(a41, a42, a43, a44) {}
291 template<class T> inline Matrix4<T>& Matrix4<T>::operator=(const Matrix4<T>& aRhv)
300 template<class T> inline Matrix4<T>& Matrix4<T>::set(const T& aValue)
309 template<class T> inline Matrix4<T>& Matrix4<T>::set(const T* aValues)
311 i.set(aValues[0], aValues[1], aValues[2], aValues[3]);
312 j.set(aValues[4], aValues[5], aValues[6], aValues[7]);
313 k.set(aValues[8], aValues[9], aValues[10], aValues[11]);
314 c.set(aValues[12], aValues[13], aValues[14], aValues[15]);
318 template<class T> inline Matrix4<T>& Matrix4<T>::set(const Matrix4<T>& aOther)
327 template<class T> inline Matrix4<T>& Matrix4<T>::set(const Vector4<T>& aI, const Vector4<T>& aJ,
328 const Vector4<T>& aK, const Vector4<T>& aC)
337 template<class T> inline Matrix4<T>& Matrix4<T>::set(const _Vector3<T>& aI, const _Vector3<T>& aJ,
338 const _Vector3<T>& aK, const _Vector3<T>& aC)
347 template<class T> inline Matrix4<T>& Matrix4<T>::set(const T& a11, const T& a12, const T& a13, const T& a14,
348 const T& a21, const T& a22, const T& a23, const T& a24,
349 const T& a31, const T& a32, const T& a33, const T& a34,
350 const T& a41, const T& a42, const T& a43, const T& a44)
352 i.set(a11, a12, a13, a14);
353 j.set(a21, a22, a23, a24);
354 k.set(a31, a32, a33, a34);
355 c.set(a41, a42, a43, a44);
359 template<class T> inline Matrix4<T>& Matrix4<T>::identity()
361 return operator=(getIdentity());
364 template<class T> inline const Matrix4<T>& Matrix4<T>::getIdentity()
366 static Matrix4<T> identityMatrix(
367 T(1.0f), T(0.0f), T(0.0f), T(0.0f),
368 T(0.0f), T(1.0f), T(0.0f), T(0.0f),
369 T(0.0f), T(0.0f), T(1.0f), T(0.0f),
370 T(0.0f), T(0.0f), T(0.0f), T(1.0f));
371 return identityMatrix;
374 template<class T> inline Matrix4<T> Matrix4<T>::operator-() const
376 return Matrix4<T>(-i, -j, -k, -c);
379 template<class T> inline Matrix4<T>& Matrix4<T>::inverse()
381 static const T t0(0.0f);
384 if(EffectsEqual(s, t0)) return *this;
386 (j.y*(k.z*c.w - k.w*c.z) + j.z*(k.w*c.y - k.y*c.w) + j.w*(k.y*c.z - k.z*c.y)) / s,
387 (k.y*(i.z*c.w - i.w*c.z) + k.z*(i.w*c.y - i.y*c.w) + k.w*(i.y*c.z - i.z*c.y)) / s,
388 (c.y*(i.z*j.w - i.w*j.z) + c.z*(i.w*j.y - i.y*j.w) + c.w*(i.y*j.z - i.z*j.y)) / s,
389 (i.y*(j.w*k.z - j.z*k.w) + i.z*(j.y*k.w - j.w*k.y) + i.w*(j.z*k.y - j.y*k.z)) / s,
390 (j.z*(k.x*c.w - k.w*c.x) + j.w*(k.z*c.x - k.x*c.z) + j.x*(k.w*c.z - k.z*c.w)) / s,
391 (k.z*(i.x*c.w - i.w*c.x) + k.w*(i.z*c.x - i.x*c.z) + k.x*(i.w*c.z - i.z*c.w)) / s,
392 (c.z*(i.x*j.w - i.w*j.x) + c.w*(i.z*j.x - i.x*j.z) + c.x*(i.w*j.z - i.z*j.w)) / s,
393 (i.z*(j.w*k.x - j.x*k.w) + i.w*(j.x*k.z - j.z*k.x) + i.x*(j.z*k.w - j.w*k.z)) / s,
394 (j.w*(k.x*c.y - k.y*c.x) + j.x*(k.y*c.w - k.w*c.y) + j.y*(k.w*c.x - k.x*c.w)) / s,
395 (k.w*(i.x*c.y - i.y*c.x) + k.x*(i.y*c.w - i.w*c.y) + k.y*(i.w*c.x - i.x*c.w)) / s,
396 (c.w*(i.x*j.y - i.y*j.x) + c.x*(i.y*j.w - i.w*j.y) + c.y*(i.w*j.x - i.x*j.w)) / s,
397 (i.w*(j.y*k.x - j.x*k.y) + i.x*(j.w*k.y - j.y*k.w) + i.y*(j.x*k.w - j.w*k.x)) / s,
398 (j.x*(k.z*c.y - k.y*c.z) + j.y*(k.x*c.z - k.z*c.x) + j.z*(k.y*c.x - k.x*c.y)) / s,
399 (k.x*(i.z*c.y - i.y*c.z) + k.y*(i.x*c.z - i.z*c.x) + k.z*(i.y*c.x - i.x*c.y)) / s,
400 (c.x*(i.z*j.y - i.y*j.z) + c.y*(i.x*j.z - i.z*j.x) + c.z*(i.y*j.x - i.x*j.y)) / s,
401 (i.x*(j.y*k.z - j.z*k.y) + i.y*(j.z*k.x - j.x*k.z) + i.z*(j.x*k.y - j.y*k.x)) / s);
405 template<class T> inline Matrix4<T> Matrix4<T>::getInversed() const
407 static const T t0(0.0f);
410 if(EffectsEqual(s, t0)) return *this;
412 (j.y*(k.z*c.w - k.w*c.z) + j.z*(k.w*c.y - k.y*c.w) + j.w*(k.y*c.z - k.z*c.y)) / s,
413 (k.y*(i.z*c.w - i.w*c.z) + k.z*(i.w*c.y - i.y*c.w) + k.w*(i.y*c.z - i.z*c.y)) / s,
414 (c.y*(i.z*j.w - i.w*j.z) + c.z*(i.w*j.y - i.y*j.w) + c.w*(i.y*j.z - i.z*j.y)) / s,
415 (i.y*(j.w*k.z - j.z*k.w) + i.z*(j.y*k.w - j.w*k.y) + i.w*(j.z*k.y - j.y*k.z)) / s,
416 (j.z*(k.x*c.w - k.w*c.x) + j.w*(k.z*c.x - k.x*c.z) + j.x*(k.w*c.z - k.z*c.w)) / s,
417 (k.z*(i.x*c.w - i.w*c.x) + k.w*(i.z*c.x - i.x*c.z) + k.x*(i.w*c.z - i.z*c.w)) / s,
418 (c.z*(i.x*j.w - i.w*j.x) + c.w*(i.z*j.x - i.x*j.z) + c.x*(i.w*j.z - i.z*j.w)) / s,
419 (i.z*(j.w*k.x - j.x*k.w) + i.w*(j.x*k.z - j.z*k.x) + i.x*(j.z*k.w - j.w*k.z)) / s,
420 (j.w*(k.x*c.y - k.y*c.x) + j.x*(k.y*c.w - k.w*c.y) + j.y*(k.w*c.x - k.x*c.w)) / s,
421 (k.w*(i.x*c.y - i.y*c.x) + k.x*(i.y*c.w - i.w*c.y) + k.y*(i.w*c.x - i.x*c.w)) / s,
422 (c.w*(i.x*j.y - i.y*j.x) + c.x*(i.y*j.w - i.w*j.y) + c.y*(i.w*j.x - i.x*j.w)) / s,
423 (i.w*(j.y*k.x - j.x*k.y) + i.x*(j.w*k.y - j.y*k.w) + i.y*(j.x*k.w - j.w*k.x)) / s,
424 (j.x*(k.z*c.y - k.y*c.z) + j.y*(k.x*c.z - k.z*c.x) + j.z*(k.y*c.x - k.x*c.y)) / s,
425 (k.x*(i.z*c.y - i.y*c.z) + k.y*(i.x*c.z - i.z*c.x) + k.z*(i.y*c.x - i.x*c.y)) / s,
426 (c.x*(i.z*j.y - i.y*j.z) + c.y*(i.x*j.z - i.z*j.x) + c.z*(i.y*j.x - i.x*j.y)) / s,
427 (i.x*(j.y*k.z - j.z*k.y) + i.y*(j.z*k.x - j.x*k.z) + i.z*(j.x*k.y - j.y*k.x)) / s);
431 template<class T> inline Matrix4<T>& Matrix4<T>::transpose()
433 EffectsSwap(i.y, j.x);
434 EffectsSwap(i.z, k.x);
435 EffectsSwap(i.w, c.x);
436 EffectsSwap(j.z, k.y);
437 EffectsSwap(j.w, c.y);
438 EffectsSwap(k.w, c.z);
442 template<class T> inline Matrix4<T> Matrix4<T>::getTransposed() const
444 Matrix4 transposed(i.x, j.x, k.x, c.x,
452 template<class T> inline Matrix4<T>& Matrix4<T>::operator+=(const Matrix4<T>& aRhv)
460 template<class T> inline Matrix4<T>& Matrix4<T>::operator+=(const T& aRhv)
468 template<class T> inline Matrix4<T>& Matrix4<T>::operator-=(const Matrix4<T>& aRhv)
476 template<class T> inline Matrix4<T>& Matrix4<T>::operator-=(const T& aRhv)
484 template<class T> inline Matrix4<T>& Matrix4<T>::operator*=(const T& aRhv)
493 template<class T> inline Matrix4<T> Matrix4<T>::GetMultipliedByMember(const Matrix4<T>& aRhv) const
495 return Matrix4<T>(i * aRhv.i, j * aRhv.j, k * aRhv.k, c * aRhv.c);
498 template<class T> inline Matrix4<T>& Matrix4<T>::multiplyByMember(const Matrix4<T>& aRhv)
507 template<class T> inline Matrix4<T> Matrix4<T>::createMultipliedByMember(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
509 return Matrix4<T>(aLhv.i * aRhv.i, aLhv.j * aRhv.j, aLhv.k * aRhv.k, aLhv.c * aRhv.c);
512 template<class T> inline Matrix4<T>& Matrix4<T>::operator*=(const Matrix4<T>& aRhv)
515 i.x * aRhv.i.x + i.y * aRhv.j.x + i.z * aRhv.k.x + i.w * aRhv.c.x,
516 i.x * aRhv.i.y + i.y * aRhv.j.y + i.z * aRhv.k.y + i.w * aRhv.c.y,
517 i.x * aRhv.i.z + i.y * aRhv.j.z + i.z * aRhv.k.z + i.w * aRhv.c.z,
518 i.x * aRhv.i.w + i.y * aRhv.j.w + i.z * aRhv.k.w + i.w * aRhv.c.w,
520 j.x * aRhv.i.x + j.y * aRhv.j.x + j.z * aRhv.k.x + j.w * aRhv.c.x,
521 j.x * aRhv.i.y + j.y * aRhv.j.y + j.z * aRhv.k.y + j.w * aRhv.c.y,
522 j.x * aRhv.i.z + j.y * aRhv.j.z + j.z * aRhv.k.z + j.w * aRhv.c.z,
523 j.x * aRhv.i.w + j.y * aRhv.j.w + j.z * aRhv.k.w + j.w * aRhv.c.w,
525 k.x * aRhv.i.x + k.y * aRhv.j.x + k.z * aRhv.k.x + k.w * aRhv.c.x,
526 k.x * aRhv.i.y + k.y * aRhv.j.y + k.z * aRhv.k.y + k.w * aRhv.c.y,
527 k.x * aRhv.i.z + k.y * aRhv.j.z + k.z * aRhv.k.z + k.w * aRhv.c.z,
528 k.x * aRhv.i.w + k.y * aRhv.j.w + k.z * aRhv.k.w + k.w * aRhv.c.w,
530 c.x * aRhv.i.x + c.y * aRhv.j.x + c.z * aRhv.k.x + c.w * aRhv.c.x,
531 c.x * aRhv.i.y + c.y * aRhv.j.y + c.z * aRhv.k.y + c.w * aRhv.c.y,
532 c.x * aRhv.i.z + c.y * aRhv.j.z + c.z * aRhv.k.z + c.w * aRhv.c.z,
533 c.x * aRhv.i.w + c.y * aRhv.j.w + c.z * aRhv.k.w + c.w * aRhv.c.w);
537 template<class T> inline Matrix4<T> Matrix4<T>::getDividedByMember(const Matrix4<T>& aRhv) const
539 return Matrix4<T>(i / aRhv.i, j / aRhv.j, k / aRhv.k, c / aRhv.c);
542 template<class T> inline Matrix4<T>& Matrix4<T>::divideByMember(const Matrix4<T>& aRhv)
550 template<class T> inline Matrix4<T> Matrix4<T>::createDividedByMember(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
552 return Matrix4<T>(aLhv.i / aRhv.i, aLhv.j / aRhv.j, aLhv.k / aRhv.k, aLhv.c / aRhv.c);
555 template<class T> inline Matrix4<T>& Matrix4<T>::operator/=(const T& aRhv)
564 template<class T> inline bool Matrix4<T>::isIdentity() const
566 return *this == getIdentity();
569 template<class T> inline T* Matrix4<T>::getPointer()
571 return i.getPointer();
574 template<class T> inline const T* Matrix4<T>::getPointer() const
576 return i.getPointer();
579 template<class T> inline T& Matrix4<T>::get(unsigned int aRow, unsigned int aColumn)
581 return operator()(aRow, aColumn);
584 template<class T> inline const T& Matrix4<T>::get(unsigned int aRow, unsigned int aColumn) const
586 return operator()(aRow, aColumn);
589 template<class T> inline T& Matrix4<T>::get(unsigned int aAbsIndex)
591 return operator()(aAbsIndex);
594 template<class T> inline const T& Matrix4<T>::get(unsigned int aAbsIndex) const
596 return operator()(aAbsIndex);
599 template<class T> inline Vector4<T>& Matrix4<T>::getRow(unsigned int aRow)
613 template<class T> inline const Vector4<T>& Matrix4<T>::getRow(unsigned int aRow) const
627 template<class T> inline Vector4<T> Matrix4<T>::getColumn(unsigned int aColumn) const
632 return Vector4<T>(i.y, j.y, k.y, c.y);
634 return Vector4<T>(i.z, j.z, k.z, c.z);
636 return Vector4<T>(i.w, j.w, k.w, c.w);
639 return Vector4<T>(i.x, j.x, k.x, c.x);
642 template<class T> inline T& Matrix4<T>::operator()(unsigned int aRow, unsigned int aColumn)
644 return operator[]((aRow << 2) + aColumn);
647 template<class T> inline const T& Matrix4<T>::operator()(unsigned int aRow, unsigned int aColumn) const
649 return operator[]((aRow << 2) + aColumn);
652 template<class T> inline T& Matrix4<T>::operator()(unsigned int aAbsIndex)
654 return operator[](aAbsIndex);
657 template<class T> inline const T& Matrix4<T>::operator()(unsigned int aAbsIndex) const
659 return operator[](aAbsIndex);
662 template<class T> inline T& Matrix4<T>::operator[](unsigned int aAbsIndex)
664 return getPointer()[aAbsIndex];
667 template<class T> inline const T& Matrix4<T>::operator[](unsigned int aAbsIndex) const
669 return getPointer()[aAbsIndex];
672 template<class T> inline Matrix4<T>& Matrix4<T>::setColumn(unsigned int aColumn, const Vector4<T>& aValue)
705 template<class T> inline Matrix4<T>& Matrix4<T>::setRow(unsigned int aRow, const Vector4<T>& aValue)
726 template<class T> inline Matrix4<T>& Matrix4<T>::set(unsigned int aRow, unsigned int aColumn, const T& aValue)
728 operator()(aRow, aColumn) = aValue;
732 template<class T> inline Matrix4<T>& Matrix4<T>::set(unsigned int aAbsIndex, const T& aValue)
734 operator()(aAbsIndex) = aValue;
738 template<class T> inline Matrix4<T>& Matrix4<T>::lerp(const Matrix4<T>& aTo, const T& aCoeff)
740 i.lerp(aTo.i, aCoeff);
741 j.lerp(aTo.j, aCoeff);
742 k.lerp(aTo.k, aCoeff);
743 c.lerp(aTo.c, aCoeff);
747 template<class T> inline Matrix4<T> Matrix4<T>::getLerped(const Matrix4<T>& aTo, const T& aCoeff) const
749 Matrix4<T> result(i.getLerped(aTo.i, aCoeff),
750 j.getLerped(aTo.j, aCoeff),
751 k.getLerped(aTo.k, aCoeff),
752 c.getLerped(aTo.c, aCoeff));
756 template<class T> inline Matrix4<T>& Matrix4<T>::makeLerped(const Matrix4<T>& aFrom, const Matrix4<T>& aTo, const T& aCoeff)
758 i.makeLerped(aFrom.i, aTo.i, aCoeff);
759 j.makeLerped(aFrom.j, aTo.j, aCoeff);
760 k.makeLerped(aFrom.k, aTo.k, aCoeff);
761 c.makeLerped(aFrom.c, aTo.c, aCoeff);
764 template<class T> inline Matrix4<T> Matrix4<T>::createLerped(const Matrix4<T>& aFrom, const Matrix4<T>& aTo, const T& aCoeff)
766 return Matrix4<T>().makeLerped(aFrom, aTo, aCoeff);
769 template<class T> inline Matrix4<T>& Matrix4<T>::slerp(const Matrix4<T>& aTo, const T& aCoeff)
771 setRotation(getQuaternion().slerp(aTo.getQuaternion(), aCoeff));
772 c.lerp(aTo.c, aCoeff);
776 template<class T> inline Matrix4<T> Matrix4<T>::getSlerped(const Matrix4<T>& aTo, const T& aCoeff) const
779 result.makeRotation(getQuaternion().slerp(aTo.getQuaternion(), aCoeff));
780 result.c = c.getLerped(aTo.c, aCoeff);
784 template<class T> inline Matrix4<T>& Matrix4<T>::makeSlerped(const Matrix4<T>& aFrom, const Matrix4<T>& aTo, const T& aCoeff)
786 makeRotation(aFrom.getQuaternion().slerp(aTo.getQuaternion(), aCoeff));
787 c.makeLerped(aFrom.c, aTo.c, aCoeff);
791 template<class T> inline Matrix4<T> Matrix4<T>::createSlerped(const Matrix4<T>& aFrom, const Matrix4<T>& aTo, const T& aCoeff)
793 return Matrix4<T>().makeSlerped(aFrom, aTo, aCoeff);
796 template<class T> inline T Matrix4<T>::determinant() const
798 return (i.x * j.y - i.y * j.x) * (k.z * c.w - k.w * c.z)-
799 (i.x * j.z - i.z * j.x) * (k.y * c.w - k.w * c.y)+
800 (i.x * j.w - i.w * j.x) * (k.y * c.z - k.z * c.y)+
801 (i.y * j.z - i.z * j.y) * (k.x * c.w - k.w * c.x)-
802 (i.y * j.w - i.w * j.y) * (k.x * c.z - k.z * c.x)+
803 (i.z * j.w - i.w * j.z) * (k.x * c.y - k.y * c.x);
806 template<class T> inline Vector4<T>& Matrix4<T>::applyTransform(Vector4<T>& aVector) const
809 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x + aVector.w * c.x,
810 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y + aVector.w * c.y,
811 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z + aVector.w * c.z,
812 aVector.x * i.w + aVector.y * j.w + aVector.z * k.w + aVector.w * c.w);
815 template<class T> inline Vector4<T> Matrix4<T>::getAppliedTransform(const Vector4<T>& aVector) const
818 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x + aVector.w * c.x,
819 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y + aVector.w * c.y,
820 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z + aVector.w * c.z,
821 aVector.x * i.w + aVector.y * j.w + aVector.z * k.w + aVector.w * c.w);
824 template<class T> inline Vector4<T>& Matrix4<T>::applyRotation(Vector4<T>& aVector) const
827 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x,
828 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y,
829 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z,
833 template<class T> inline Vector4<T> Matrix4<T>::getAppliedRotation(const Vector4<T>& aVector) const
836 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x,
837 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y,
838 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z,
842 template<class T> inline Vector4<T>& Matrix4<T>::applyTranslate(Vector4<T>& aVector) const
845 aVector.x + aVector.w * c.x,
846 aVector.y + aVector.w * c.y,
847 aVector.z + aVector.w * c.z,
851 template<class T> inline Vector4<T> Matrix4<T>::getAppliedTranslate(const Vector4<T>& aVector) const
854 aVector.x + aVector.w * c.x,
855 aVector.y + aVector.w * c.y,
856 aVector.z + aVector.w * c.z,
860 template<class T> inline _Vector3<T>& Matrix4<T>::applyTransform(_Vector3<T>& aVector) const
863 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x + c.x,
864 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y + c.y,
865 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z + c.z);
868 template<class T> inline _Vector3<T> Matrix4<T>::getAppliedTransform(const _Vector3<T>& aVector) const
871 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x + c.x,
872 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y + c.y,
873 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z + c.z);
876 template<class T> inline _Vector3<T>& Matrix4<T>::applyRotation(_Vector3<T>& aVector) const
879 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x,
880 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y,
881 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z);
884 template<class T> inline _Vector3<T> Matrix4<T>::getAppliedRotation(const _Vector3<T>& aVector) const
887 aVector.x * i.x + aVector.y * j.x + aVector.z * k.x,
888 aVector.x * i.y + aVector.y * j.y + aVector.z * k.y,
889 aVector.x * i.z + aVector.y * j.z + aVector.z * k.z);
892 template<class T> inline _Vector3<T>& Matrix4<T>::applyTranslate(_Vector3<T>& aVector) const
900 template<class T> inline _Vector3<T> Matrix4<T>::getAppliedTranslate(const _Vector3<T>& aVector) const
908 template<class T> inline Quaternion<T>& Matrix4<T>::applyRotation(Quaternion<T>& aQuaternion) const
911 return aQuaternion.set(getQuaternion() * aQuaternion);
914 template<class T> inline Quaternion<T> Matrix4<T>::getAppliedRotation(const Quaternion<T>& aQuaternion) const
916 return getQuaternion() * aQuaternion;
919 template<class T> inline Matrix4<T>& Matrix4<T>::setRotation(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder)
922 result.makeRotation(aXAngleRAD, aYAngleRAD, aZAngleRAD, aOrder);
924 i.x = result.i.x; i.y = result.i.y; i.z = result.i.z;
925 j.x = result.j.x; j.y = result.j.y; j.z = result.j.z;
926 k.x = result.k.x; k.y = result.k.y; k.z = result.k.z;
930 template<class T> inline Matrix4<T>& Matrix4<T>::setRotation(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder)
932 return setRotation(aAnglesRAD.x, aAnglesRAD.y, aAnglesRAD.z, aOrder);
935 template<class T> inline Matrix4<T>& Matrix4<T>::setRotationX(const T& aAngleRAD)
937 const T c = effects_cos(aAngleRAD);
938 const T s = effects_sin(aAngleRAD);
940 i.y = i.z = j.x = k.x = T(0.0f);
948 template<class T> inline Matrix4<T>& Matrix4<T>::setRotationY(const T& aAngleRAD)
950 const T c = effects_cos(aAngleRAD);
951 const T s = effects_sin(aAngleRAD);
953 i.y = j.x = j.z = k.y = T(0.0f);
961 template<class T> inline Matrix4<T>& Matrix4<T>::setRotationZ(const T& aAngleRAD)
963 const T c = effects_cos(aAngleRAD);
964 const T s = effects_sin(aAngleRAD);
966 i.z = j.z = k.x = k.y = T(0.0f);
974 template<class T> inline Matrix4<T>& Matrix4<T>::setRotationAxis(const _Vector3<T>& aAxis, const T& aAngleRAD)
976 return setRotationAxis(aAxis.x, aAxis.y, aAxis.z, aAngleRAD);
979 template<class T> inline Matrix4<T>& Matrix4<T>::setRotationAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD)
982 result.makeRotationAxis(aXAxis, aYAxis, aZAxis, aAngleRAD);
984 i.x = result.i.x; i.y = result.i.y; i.z = result.i.z;
985 j.x = result.j.x; j.y = result.j.y; j.z = result.j.z;
986 k.x = result.k.x; k.y = result.k.y; k.z = result.k.z;
990 template<class T> inline Matrix4<T>& Matrix4<T>::setRotation(const Quaternion<T>& aRotation)
992 T wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
993 T s = T(2.0f) / aRotation.lengthSqr(); // 4 mul 3 add 1 div
994 x2 = aRotation.x * s; y2 = aRotation.y * s; z2 = aRotation.z * s;
995 xx = aRotation.x * x2; xy = aRotation.x * y2; xz = aRotation.x * z2;
996 yy = aRotation.y * y2; yz = aRotation.y * z2; zz = aRotation.z * z2;
997 wx = aRotation.w * x2; wy = aRotation.w * y2; wz = aRotation.w * z2;
1000 i.x = t1 - (yy + zz);
1005 j.y = t1 - (xx + zz);
1010 k.z = t1 - (xx + yy);
1014 template<class T> inline Matrix4<T>& Matrix4<T>::setRotation(const Matrix3<T>& aRotation)
1016 i.x = aRotation.i.x; i.y = aRotation.i.y; i.z = aRotation.i.z;
1017 j.x = aRotation.j.x; j.y = aRotation.j.y; j.z = aRotation.j.z;
1018 k.x = aRotation.k.x; k.y = aRotation.k.y; k.z = aRotation.k.z;
1022 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotation(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder)
1027 makeRotationX(aXAngleRAD);
1028 rotateY(aYAngleRAD);
1029 rotateZ(aZAngleRAD);
1032 makeRotationX(aXAngleRAD);
1033 rotateZ(aZAngleRAD);
1034 rotateY(aYAngleRAD);
1037 makeRotationY(aYAngleRAD);
1038 rotateX(aXAngleRAD);
1039 rotateZ(aZAngleRAD);
1042 makeRotationY(aYAngleRAD);
1043 rotateZ(aZAngleRAD);
1044 rotateX(aXAngleRAD);
1047 makeRotationZ(aZAngleRAD);
1048 rotateX(aXAngleRAD);
1049 rotateY(aYAngleRAD);
1052 makeRotationZ(aZAngleRAD);
1053 rotateY(aYAngleRAD);
1054 rotateX(aXAngleRAD);
1062 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotation(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder)
1064 return makeRotation(aAnglesRAD.x, aAnglesRAD.y, aAnglesRAD.z, aOrder);
1067 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotationX(const T& aAngleRAD)
1070 const T c = effects_cos(aAngleRAD);
1071 const T s = effects_sin(aAngleRAD);
1079 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotationY(const T& aAngleRAD)
1082 const T c = effects_cos(aAngleRAD);
1083 const T s = effects_sin(aAngleRAD);
1091 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotationZ(const T& aAngleRAD)
1094 const T c = effects_cos(aAngleRAD);
1095 const T s = effects_sin(aAngleRAD);
1103 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotationAxis(const _Vector3<T>& aAxis, const T& aAngleRAD)
1105 return makeRotationAxis(aAxis.x, aAxis.y, aAxis.z, aAngleRAD);
1108 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotationAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD)
1110 static const T t1(1.0f);
1112 _Vector3<T> v(aXAxis, aYAxis, aZAxis);
1114 const T sa = effects_sin(aAngleRAD);
1115 const T ca = effects_cos(aAngleRAD);
1116 const T inv_ca = t1 - ca;
1121 i.x = ca + inv_ca * v.x * v.x;
1122 i.y = inv_ca * v.x * v.y - sa * v.z;
1123 i.z = inv_ca * v.z * v.x + sa * v.y;
1124 j.x = inv_ca * v.x * v.y + sa * v.z;
1125 j.y = ca + inv_ca * v.y * v.y;
1126 j.z = inv_ca * v.y * v.z - sa * v.x;
1127 k.x = inv_ca * v.z * v.x - sa * v.y;
1128 k.y = inv_ca * v.y * v.z + sa * v.x;
1129 k.z = ca + inv_ca * v.z * v.z;
1134 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotation(const Quaternion<T>& aRotation)
1137 return setRotation(aRotation);
1140 template<class T> inline Matrix4<T>& Matrix4<T>::makeRotation(const Matrix3<T>& aRotation)
1143 return setRotation(aRotation);
1146 template<class T> inline Matrix4<T> Matrix4<T>::createRotation(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder)
1148 return Matrix4<T>().makeRotation(aXAngleRAD, aYAngleRAD, aZAngleRAD, aOrder);
1151 template<class T> inline Matrix4<T> Matrix4<T>::createRotation(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder)
1153 return Matrix4<T>().makeRotation(aAnglesRAD, aOrder);
1156 template<class T> inline Matrix4<T> Matrix4<T>::createRotationX(const T& aAngleRAD)
1158 return Matrix4<T>().makeRotationX(aAngleRAD);
1161 template<class T> inline Matrix4<T> Matrix4<T>::createRotationY(const T& aAngleRAD)
1163 return Matrix4<T>().makeRotationY(aAngleRAD);
1166 template<class T> inline Matrix4<T> Matrix4<T>::createRotationZ(const T& aAngleRAD)
1168 return Matrix4<T>().makeRotationZ(aAngleRAD);
1171 template<class T> inline Matrix4<T> Matrix4<T>::createRotationAxis(const _Vector3<T>& aAxis, const T& aAngleRAD)
1173 return Matrix4<T>().makeRotationAxis(aAxis, aAngleRAD);
1176 template<class T> inline Matrix4<T> Matrix4<T>::createRotationAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD)
1178 return Matrix4<T>().makeRotationAxis(aXAxis, aYAxis, aZAxis, aAngleRAD);
1181 template<class T> inline Matrix4<T> Matrix4<T>::createRotation(const Quaternion<T>& aRotation)
1183 return Matrix4<T>().makeRotation(aRotation);
1186 template<class T> inline Matrix4<T> Matrix4<T>::createRotation(const Matrix3<T>& aRotation)
1188 return Matrix4<T>().makeRotation(aRotation);
1191 template<class T> inline Matrix4<T>& Matrix4<T>::rotate(const T& aXAngleRAD, const T& aYAngleRAD, const T& aZAngleRAD, RotationOrder3 aOrder)
1193 return rotate(Matrix4<T>().makeRotation(aXAngleRAD, aYAngleRAD, aZAngleRAD, aOrder));
1195 template<class T> inline Matrix4<T>& Matrix4<T>::rotate(const _Vector3<T>& aAnglesRAD, RotationOrder3 aOrder3)
1197 return rotate(Matrix4<T>().makeRotation(aAnglesRAD, aOrder3));
1199 template<class T> inline Matrix4<T>& Matrix4<T>::rotateX(const T& aAngleRAD)
1201 return rotate(Matrix4<T>().makeRotationX(aAngleRAD));
1203 template<class T> inline Matrix4<T>& Matrix4<T>::rotateY(const T& aAngleRAD)
1205 return rotate(Matrix4<T>().makeRotationY(aAngleRAD));
1207 template<class T> inline Matrix4<T>& Matrix4<T>::rotateZ(const T& aAngleRAD)
1209 return rotate(Matrix4<T>().makeRotationZ(aAngleRAD));
1211 template<class T> inline Matrix4<T>& Matrix4<T>::rotateAxis(const _Vector3<T>& aAxis, const T& aAngleRAD)
1213 return rotate(Matrix4<T>().makeRotationAxis(aAxis, aAngleRAD));
1215 template<class T> inline Matrix4<T>& Matrix4<T>::rotateAxis(const T& aXAxis, const T& aYAxis, const T& aZAxis, const T& aAngleRAD)
1217 return rotate(Matrix4<T>().makeRotationAxis(aXAxis, aYAxis, aZAxis, aAngleRAD));
1219 template<class T> inline Matrix4<T>& Matrix4<T>::rotate(const Quaternion<T>& aRotation)
1221 return rotate(Matrix4<T>().makeRotation(aRotation));
1223 template<class T> inline Matrix4<T>& Matrix4<T>::rotate(const Matrix3<T>& aRotation)
1225 const T _11 = i.x * aRotation.i.x + i.y * aRotation.j.x + i.z * aRotation.k.x;
1226 const T _12 = i.x * aRotation.i.y + i.y * aRotation.j.y + i.z * aRotation.k.y;
1227 const T _13 = i.x * aRotation.i.z + i.y * aRotation.j.z + i.z * aRotation.k.z;
1229 const T _21 = j.x * aRotation.i.x + j.y * aRotation.j.x + j.z * aRotation.k.x;
1230 const T _22 = j.x * aRotation.i.y + j.y * aRotation.j.y + j.z * aRotation.k.y;
1231 const T _23 = j.x * aRotation.i.z + j.y * aRotation.j.z + j.z * aRotation.k.z;
1233 const T _31 = k.x * aRotation.i.x + k.y * aRotation.j.x + k.z * aRotation.k.x;
1234 const T _32 = k.x * aRotation.i.y + k.y * aRotation.j.y + k.z * aRotation.k.y;
1235 const T _33 = k.x * aRotation.i.z + k.y * aRotation.j.z + k.z * aRotation.k.z;
1237 i.x = _11; i.y = _12; i.z = _13;
1238 j.x = _21; j.y = _22; j.z = _23;
1239 k.x = _31; k.y = _32; k.z = _33;
1243 template<class T> inline Matrix4<T>& Matrix4<T>::rotate(const Matrix4<T>& aRotation)
1245 const T _11 = i.x * aRotation.i.x + i.y * aRotation.j.x + i.z * aRotation.k.x;
1246 const T _12 = i.x * aRotation.i.y + i.y * aRotation.j.y + i.z * aRotation.k.y;
1247 const T _13 = i.x * aRotation.i.z + i.y * aRotation.j.z + i.z * aRotation.k.z;
1249 const T _21 = j.x * aRotation.i.x + j.y * aRotation.j.x + j.z * aRotation.k.x;
1250 const T _22 = j.x * aRotation.i.y + j.y * aRotation.j.y + j.z * aRotation.k.y;
1251 const T _23 = j.x * aRotation.i.z + j.y * aRotation.j.z + j.z * aRotation.k.z;
1253 const T _31 = k.x * aRotation.i.x + k.y * aRotation.j.x + k.z * aRotation.k.x;
1254 const T _32 = k.x * aRotation.i.y + k.y * aRotation.j.y + k.z * aRotation.k.y;
1255 const T _33 = k.x * aRotation.i.z + k.y * aRotation.j.z + k.z * aRotation.k.z;
1257 i.x = _11; i.y = _12; i.z = _13;
1258 j.x = _21; j.y = _22; j.z = _23;
1259 k.x = _31; k.y = _32; k.z = _33;
1263 template<class T> inline const Matrix4<T>& Matrix4<T>::getRotationAngles(T& aXAngleRAD, T& aYAngeRAD, T& aZAngleRAD, unsigned int aSolutionNumber) const
1265 static const T t0(0.0f);
1266 static const T t2(2.0f);
1267 static const T pi(fPI);
1269 T& yaw = aZAngleRAD;
1270 T& pitch = aYAngeRAD;
1271 T& roll = aXAngleRAD;
1281 Euler euler_out2; //second solution
1283 // Check that pitch is not at a singularity
1284 if(EffectsAbs(k.x) >= T(1.0f))
1287 euler_out2.yaw = t0;
1289 // From difference of angles formula
1290 T delta = effects_atan2(i.x, i.z);
1291 if (k.x > 0) //gimbal locked up
1293 euler_out.pitch = pi / t2;
1294 euler_out2.pitch = pi / t2;
1295 euler_out.roll = euler_out.pitch + delta;
1296 euler_out2.roll = euler_out.pitch + delta;
1298 else // gimbal locked down
1300 euler_out.pitch = -pi / t2;
1301 euler_out2.pitch = -pi / t2;
1302 euler_out.roll = -euler_out.pitch + delta;
1303 euler_out2.roll = -euler_out.pitch + delta;
1308 euler_out.pitch = - effects_asin(k.x);
1309 euler_out2.pitch = pi - euler_out.pitch;
1311 euler_out.roll = effects_atan2(k.y / effects_cos(euler_out.pitch), k.z / effects_cos(euler_out.pitch));
1313 euler_out2.roll = effects_atan2(k.y / effects_cos(euler_out2.pitch), k.z / effects_cos(euler_out2.pitch));
1315 euler_out.yaw = effects_atan2(j.x / effects_cos(euler_out.pitch), i.x / effects_cos(euler_out.pitch));
1317 euler_out2.yaw = effects_atan2(j.x / effects_cos(euler_out2.pitch), i.x / effects_cos(euler_out2.pitch));
1320 if (aSolutionNumber == 1)
1322 yaw = euler_out.yaw;
1323 pitch = euler_out.pitch;
1324 roll = euler_out.roll;
1328 yaw = euler_out2.yaw;
1329 pitch = euler_out2.pitch;
1330 roll = euler_out2.roll;
1334 template<class T> inline Quaternion<T>& Matrix4<T>::getQuaternion(Quaternion<T>& aRotation) const
1336 static const T t0(0.0f);
1337 static const T thalf(0.5f);
1338 static const T t1(1.0f);
1340 Quaternion<T>& result = aRotation;
1342 T tr = i.x + j.y + k.z; // trace of martix
1344 { // if trace positive than "w" is biggest component
1345 result.set(j.z - k.y, k.x - i.z, i.y - j.x, tr + t1);
1346 result *= (T(0.5f) / effects_sqrt(result.w)); // "w" contain the "norm * 4"
1349 else // Some of vector components is bigger
1351 if((i.x > j.y) && (i.x > k.z))
1353 result.set(t1 + i.x - j.y - k.z, j.x + i.y, k.x + i.z, j.z - k.y);
1354 result *= (thalf / effects_sqrt(result.x));
1361 result.set(j.x + i.y, t1 + j.y - i.x - k.z, k.y + j.z, k.x - i.z);
1362 result *= (thalf / effects_sqrt(result.x));
1367 result.set(k.x + i.z, k.y + j.z, t1 + k.z - i.x - j.y, i.y - j.x);
1368 result *= (thalf / effects_sqrt(result.z));
1373 return result.normalize();
1375 template<class T> inline Quaternion<T> Matrix4<T>::getQuaternion() const
1377 Quaternion<T> result;
1378 return getQuaternion(result);
1380 template<class T> inline Matrix3<T> Matrix4<T>::getRotation() const
1382 return Matrix3<T>(i.x, i.y, i.z,
1387 template<class T> inline Matrix4<T>& Matrix4<T>::makeScale(const T& aX, const T& aY, const T& aZ)
1390 return setScale(aX, aY, aZ);
1392 template<class T> inline Matrix4<T>& Matrix4<T>::makeScale(const _Vector3<T>& aScale)
1394 return makeScale(aScale.x, aScale.y, aScale.z);
1396 template<class T> inline Matrix4<T> Matrix4<T>::createScale(const T& aX, const T& aY, const T& aZ)
1398 return Matrix4<T>().makeScale(aX, aY, aZ);
1400 template<class T> inline Matrix4<T> Matrix4<T>::createScale(const _Vector3<T>& aScale)
1402 return Matrix4<T>().makeScale(aScale);
1404 template<class T> inline Matrix4<T>& Matrix4<T>::setScale(const T& aX, const T& aY, const T& aZ)
1410 i.y = i.z = j.x = j.z = k.x = k.y = T(0.0f);
1413 template<class T> inline Matrix4<T>& Matrix4<T>::setScale(const _Vector3<T>& aScale)
1415 return setScale(aScale.x, aScale.y, aScale.z);
1417 template<class T> inline Matrix4<T>& Matrix4<T>::scale(const T& aX, const T& aY, const T& aZ)
1419 i.x *= aX; i.y *= aY; i.z *= aZ;
1420 j.x *= aX; j.y *= aY; j.z *= aZ;
1421 k.x *= aX; k.y *= aY; k.z *= aZ;
1425 template<class T> inline Matrix4<T>& Matrix4<T>::scale(const _Vector3<T>& aScale)
1427 return scale(aScale.x, aScale.y, aScale.z);
1430 template<class T> inline Matrix4<T>& Matrix4<T>::setTranslation(const T& aX, const T& aY, const T& aZ)
1437 template<class T> inline Matrix4<T>& Matrix4<T>::setTranslation(const _Vector3<T>& aTran)
1439 return setTranslation(aTran.x, aTran.y, aTran.z);
1441 template<class T> inline Matrix4<T>& Matrix4<T>::makeTranslation(const T& aX, const T& aY, const T& aZ)
1444 return setTranslation(aX, aY, aZ);
1446 template<class T> inline Matrix4<T>& Matrix4<T>::makeTranslation(const _Vector3<T>& aTran)
1448 return makeTranslation(aTran.x, aTran.y, aTran.z);
1450 template<class T> inline Matrix4<T> Matrix4<T>::createTranslation(const T& aX, const T& aY, const T& aZ)
1452 return Matrix4<T>().makeTranslation(aX, aY, aZ);
1454 template<class T> inline Matrix4<T> Matrix4<T>::createTranslation(const _Vector3<T>& aTran)
1456 return Matrix4<T>().makeTranslation(aTran);
1458 template<class T> inline Matrix4<T>& Matrix4<T>::translate(const T& aX, const T& aY, const T& aZ)
1465 template<class T> inline Matrix4<T>& Matrix4<T>::translate(const _Vector3<T>& aTran)
1467 return translate(aTran.x, aTran.y, aTran.z);
1469 template<class T> inline _Vector3<T> Matrix4<T>::getTranslation() const
1471 return c.swizzle(0, 1, 2);
1473 template<class T> inline Vector4<T> Matrix4<T>::getFullTranslation() const
1478 template<class T> inline Matrix4<T>& Matrix4<T>::makeLookAtLH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp)
1480 static const T t0(0.0f);
1481 static const T t1(1.0f);
1483 _Vector3<T> z((aAt - aEye).normalize());
1484 _Vector3<T> x; x.makeCrossed(aUp, z).normalize();
1485 _Vector3<T> y; y.makeCrossed(z, x);
1487 i.x = x.x; i.y = y.x; i.z = z.x; i.w = t0;
1488 j.x = x.y; j.y = y.y; j.z = z.y; j.w = t0;
1489 k.x = x.z; k.y = y.z; k.z = z.z; k.w = t0;
1496 template<class T> inline Matrix4<T>& Matrix4<T>::makeLookAtRH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp)
1498 static const T t0(0.0f);
1499 static const T t1(1.0f);
1501 _Vector3<T> z((aEye - aAt).normalize());
1502 _Vector3<T> x; x.makeCrossed(aUp, z).normalize();
1503 _Vector3<T> y; y.makeCrossed(z, x);
1505 i.x = x.x; i.y = y.x; i.z = z.x; i.w = t0;
1506 j.x = x.y; j.y = y.y; j.z = z.y; j.w = t0;
1507 k.x = x.z; k.y = y.z; k.z = z.z; k.w = t0;
1514 template<class T> inline Matrix4<T>& Matrix4<T>::makeOrthoRH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar)
1516 static const T t2(2.0f);
1521 k.z = t2 / (aZNear - aZFar);
1522 c.z = (aZFar + aZNear) / (aZNear - aZFar);
1525 template<class T> inline Matrix4<T>& Matrix4<T>::makeOrthoLH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar)
1527 makeOrthoRH(aWidth, aHeight, aZNear, aZFar);
1531 template<class T> inline Matrix4<T>& Matrix4<T>::makeOrthoRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1533 static const T t2(2.0f);
1537 i.x = t2 / (aRight - aLeft);
1538 j.y = t2 / (aTop - aBottom);
1539 k.z = t2 / (aZNear - aZFar);
1541 c.x = (aLeft + aRight) / (aLeft - aRight);
1542 c.y = (aTop + aBottom) / (aBottom - aTop);
1543 c.z = (aZFar + aZNear) / (aZNear - aZFar);
1547 template<class T> inline Matrix4<T>& Matrix4<T>::makeOrthoLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1549 makeOrthoRH(aLeft, aRight, aTop, aBottom, aZNear, aZFar);
1553 template<class T> inline Matrix4<T>& Matrix4<T>::makePerspectiveLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1555 makePerspectiveRH(aLeft, aRight, aTop, aBottom, aZNear, aZFar);
1559 template<class T> inline Matrix4<T>& Matrix4<T>::makePerspectiveRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1561 static const T t0(0.0f);
1562 static const T t1(1.0f);
1563 static const T t2(2.0f);
1566 i.x = t2 * aZNear / (aRight - aLeft);
1567 j.y = t2 * aZNear / (aTop - aBottom);
1568 k.z = (aZFar + aZNear) / (aZNear - aZFar);
1572 k.x = (aLeft + aRight) / (aRight - aLeft);
1573 k.y = (aTop + aBottom) / (aTop - aBottom);
1574 c.z = t2 * aZNear * aZFar / (aZNear - aZFar);
1578 template<class T> inline Matrix4<T>& Matrix4<T>::makePerspectiveLH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar)
1580 makePerspectiveRH(aWidth, aHeight, aZNear, aZFar);
1584 template<class T> inline Matrix4<T>& Matrix4<T>::makePerspectiveRH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar)
1586 static const T t0(0.0f);
1587 static const T t1(1.0f);
1588 static const T t2(2.0f);
1591 i.x = t2 * aZNear / aWidth;
1592 j.y = t2 * aZNear / aHeight;
1593 k.z = (aZFar + aZNear) / (aZNear - aZFar);
1594 c.z = t2 * aZNear * aZFar / (aZNear - aZFar);
1599 template<class T> inline Matrix4<T>& Matrix4<T>::makePerspectiveFovLH(const T& aFovY, const T& aAspect, const T& aZNear, const T& aZFar)
1601 makePerspectiveFovRH(aFovY, aAspect, aZNear, aZFar);
1605 template<class T> inline Matrix4<T>& Matrix4<T>::makePerspectiveFovRH(const T& aFovY, const T& aAspect, const T& aZNear, const T& aZFar)
1607 static const T t0(0.0f);
1608 static const T t1(1.0f);
1609 static const T t2(2.0f);
1612 j.y = t1 / tan(aFovY / t2);
1613 i.x = j.y / aAspect;
1614 k.z = (aZFar + aZNear) / (aZNear - aZFar);
1616 c.z = t2 * (aZNear * aZFar / (aZNear - aZFar));
1621 template<class T> inline Matrix4<T> Matrix4<T>::createLookAtLH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp)
1623 return Matrix4<T>().makeLookAtLH(aEye, aAt, aUp);
1625 template<class T> inline Matrix4<T> Matrix4<T>::createLookAtRH(const _Vector3<T>& aEye, const _Vector3<T>& aAt, const _Vector3<T>& aUp)
1627 return Matrix4<T>().makeLookAtRH(aEye, aAt, aUp);
1629 template<class T> inline Matrix4<T> Matrix4<T>::createOrthoRH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar)
1631 return Matrix4<T>().makeOrthoRH(aWidth, aHeight, aZNear, aZFar);
1633 template<class T> inline Matrix4<T> Matrix4<T>::createOrthoLH(const T& aWidth, const T& aHeight, const T& aZNear, const T& aZFar)
1635 return Matrix4<T>().makeOrthoLH(aWidth, aHeight, aZNear, aZFar);
1637 template<class T> inline Matrix4<T> Matrix4<T>::createOrthoRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1639 return Matrix4<T>().makeOrthoRH(aLeft, aRight, aTop, aBottom, aZNear, aZFar);
1641 template<class T> inline Matrix4<T> Matrix4<T>::createOrthoLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1643 return Matrix4<T>().makeOrthoLH(aLeft, aRight, aTop, aBottom, aZNear, aZFar);
1645 template<class T> inline Matrix4<T> Matrix4<T>::createPerspectiveLH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1647 return Matrix4<T>().makePerspectiveLH(aLeft, aRight, aTop, aBottom, aZNear, aZFar);
1649 template<class T> inline Matrix4<T> Matrix4<T>::createPerspectiveRH(const T& aLeft, const T& aRight, const T& aTop, const T& aBottom, const T& aZNear, const T& aZFar)
1651 return Matrix4<T>().makePerspectiveRH(aLeft, aRight, aTop, aBottom, aZNear, aZFar);
1653 template<class T> inline Matrix4<T> Matrix4<T>::createPerspectiveLH(const T& aWidth, const T& aHeight, const T& aZnear, const T& aZFar)
1655 return Matrix4<T>().makePerspectiveLH(aWidth, aHeight, aZnear, aZFar);
1657 template<class T> inline Matrix4<T> Matrix4<T>::createPerspectiveRH(const T& aWidth, const T& aHeight, const T& aZnear, const T& aZFar)
1659 return Matrix4<T>().makePerspectiveRH(aWidth, aHeight, aZnear, aZFar);
1661 template<class T> inline Matrix4<T> Matrix4<T>::createPerspectiveFovLH(const T& aFovY, const T& aAspect, const T& aZnear, const T& aZFar)
1663 return Matrix4<T>().makePerspectiveFovLH(aFovY, aAspect, aZnear, aZFar);
1665 template<class T> inline Matrix4<T> Matrix4<T>::createPerspectiveFovRH(const T& aFovY, const T& aAspect, const T& aZnear, const T& aZFar)
1667 return Matrix4<T>().makePerspectiveFovRH(aFovY, aAspect, aZnear, aZFar);
1670 template<class T> inline bool Matrix4<T>::getOrthoParamsRH(T& aLeft, T& aRight, T& aTop, T& aBottom, T& aZNear, T& aZFar) const
1672 static const T t1(1.0f);
1674 aZNear = (c.z + t1) / k.z;
1675 aZFar = (c.z - t1) / k.z;
1677 aLeft = -(t1 + c.x) / i.x;
1678 aRight = (t1 - c.x) / i.x;
1680 aBottom = -(t1 + c.y) / j.y;
1681 aTop = (t1 - c.y) / j.y;
1685 template<class T> inline bool Matrix4<T>::getPerspectiveParamsRH(T& aLeft, T& aRight, T& aTop, T& aBottom, T& aZNear, T& aZFar) const
1687 static const T t1(1.0f);
1689 aZNear = c.z / (k.z - t1);
1690 aZFar = c.z / (t1 + k.z);
1692 aLeft = aZNear * (k.x - t1) / i.x;
1693 aRight = aZNear * (t1 + k.x) / i.x;
1695 aTop = aZNear * (t1 + k.y) / j.y;
1696 aBottom = aZNear * (k.y - t1) / j.y;
1700 template<class T> inline bool Matrix4<T>::getPerspectiveParamsRH(T& aFovY, T& aAspect, T& aZNear, T& aZFar) const
1702 T left, right, bottom, top;
1703 bool result = getPerspectiveParamsRH(left, right, top, bottom, aZNear, aZFar);
1706 T height = top - bottom;
1707 T width = right - left;
1708 aAspect = width / height;
1709 aFovY = T(2.0f) * effects_atan(height / aZNear * T(0.5f));
1713 template<class T> inline bool Matrix4<T>::getViewParams(_Vector3<T>& aPosition, _Vector3<T>& aDirection, _Vector3<T>& aUp, _Vector3<T>& aRight) const
1715 aRight.set(i.x, j.x, k.x);
1716 aUp.set(i.y, j.y, k.y);
1717 aDirection.set(-i.z, -j.z, -k.z);
1718 aPosition = aDirection * c.z - aRight * c.x - aUp * c.y;
1722 template<class T> inline bool isEqual(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv, const T& aEpsilon = effects_epsilon<T>::epsilon())
1724 return isEqual(aLhv.i, aRhv.i, aEpsilon) && isEqual(aLhv.j, aRhv.j, aEpsilon) && isEqual(aLhv.k, aRhv.k, aEpsilon) && isEqual(aLhv.c, aRhv.c, aEpsilon);
1726 template<class T> inline Matrix4<T> operator+(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
1728 return Matrix4<T>(aLhv.i + aRhv.i, aLhv.j + aRhv.j, aLhv.k + aRhv.k, aLhv.c + aRhv.c);
1730 template<class T> inline Matrix4<T> operator+(const Matrix4<T>& aLhv, const T& aRhv)
1732 return Matrix4<T>(aLhv.i + aRhv, aLhv.j + aRhv, aLhv.k + aRhv, aLhv.c + aRhv);
1734 template<class T> inline Matrix4<T> operator+(const T& aLhv, const Matrix4<T>& aRhv)
1736 return Matrix4<T>(aLhv + aRhv.i, aLhv + aRhv.j, aLhv + aRhv.k, aLhv + aRhv.c);
1738 template<class T> inline Matrix4<T> operator-(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
1740 return Matrix4<T>(aLhv.i - aRhv.i, aLhv.j - aRhv.j, aLhv.k - aRhv.k, aLhv.c - aRhv.c);
1742 template<class T> inline Matrix4<T> operator-(const Matrix4<T>& aLhv, const T& aRhv)
1744 return Matrix4<T>(aLhv.i - aRhv, aLhv.j - aRhv, aLhv.k - aRhv, aLhv.c - aRhv);
1746 template<class T> inline Matrix4<T> operator-(const T& aLhv, const Matrix4<T>& aRhv)
1748 return Matrix4<T>(aLhv - aRhv.i, aLhv - aRhv.j, aLhv - aRhv.k, aLhv - aRhv.c);
1750 template<class T> inline Matrix4<T> operator*(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
1753 aLhv.i.x * aRhv.i.x + aLhv.i.y * aRhv.j.x + aLhv.i.z * aRhv.k.x + aLhv.i.w * aRhv.c.x,
1754 aLhv.i.x * aRhv.i.y + aLhv.i.y * aRhv.j.y + aLhv.i.z * aRhv.k.y + aLhv.i.w * aRhv.c.y,
1755 aLhv.i.x * aRhv.i.z + aLhv.i.y * aRhv.j.z + aLhv.i.z * aRhv.k.z + aLhv.i.w * aRhv.c.z,
1756 aLhv.i.x * aRhv.i.w + aLhv.i.y * aRhv.j.w + aLhv.i.z * aRhv.k.w + aLhv.i.w * aRhv.c.w,
1758 aLhv.j.x * aRhv.i.x + aLhv.j.y * aRhv.j.x + aLhv.j.z * aRhv.k.x + aLhv.j.w * aRhv.c.x,
1759 aLhv.j.x * aRhv.i.y + aLhv.j.y * aRhv.j.y + aLhv.j.z * aRhv.k.y + aLhv.j.w * aRhv.c.y,
1760 aLhv.j.x * aRhv.i.z + aLhv.j.y * aRhv.j.z + aLhv.j.z * aRhv.k.z + aLhv.j.w * aRhv.c.z,
1761 aLhv.j.x * aRhv.i.w + aLhv.j.y * aRhv.j.w + aLhv.j.z * aRhv.k.w + aLhv.j.w * aRhv.c.w,
1763 aLhv.k.x * aRhv.i.x + aLhv.k.y * aRhv.j.x + aLhv.k.z * aRhv.k.x + aLhv.k.w * aRhv.c.x,
1764 aLhv.k.x * aRhv.i.y + aLhv.k.y * aRhv.j.y + aLhv.k.z * aRhv.k.y + aLhv.k.w * aRhv.c.y,
1765 aLhv.k.x * aRhv.i.z + aLhv.k.y * aRhv.j.z + aLhv.k.z * aRhv.k.z + aLhv.k.w * aRhv.c.z,
1766 aLhv.k.x * aRhv.i.w + aLhv.k.y * aRhv.j.w + aLhv.k.z * aRhv.k.w + aLhv.k.w * aRhv.c.w,
1768 aLhv.c.x * aRhv.i.x + aLhv.c.y * aRhv.j.x + aLhv.c.z * aRhv.k.x + aLhv.c.w * aRhv.c.x,
1769 aLhv.c.x * aRhv.i.y + aLhv.c.y * aRhv.j.y + aLhv.c.z * aRhv.k.y + aLhv.c.w * aRhv.c.y,
1770 aLhv.c.x * aRhv.i.z + aLhv.c.y * aRhv.j.z + aLhv.c.z * aRhv.k.z + aLhv.c.w * aRhv.c.z,
1771 aLhv.c.x * aRhv.i.w + aLhv.c.y * aRhv.j.w + aLhv.c.z * aRhv.k.w + aLhv.c.w * aRhv.c.w);
1773 template<class T> inline Matrix4<T> operator*(const Matrix4<T>& aLhv, const T& aRhv)
1775 return Matrix4<T>(aLhv.i * aRhv, aLhv.j * aRhv, aLhv.k * aRhv, aLhv.c * aRhv);
1777 template<class T> inline Matrix4<T> operator*(const T& aLhv, const Matrix4<T>& aRhv)
1779 return Matrix4<T>(aLhv * aRhv.i, aLhv * aRhv.j, aLhv * aRhv.k, aLhv * aRhv.c);
1781 template<class T> inline Vector4<T> operator*(const Matrix4<T>& aLhv, const Vector4<T>& aRhv)
1783 return Vector4<T>(aLhv.i.dot(aRhv), aLhv.j.dot(aRhv), aLhv.k.dot(aRhv), aLhv.c.dot(aRhv));
1785 template<class T> inline Vector4<T> operator*(const Vector4<T>& aLhv, const Matrix4<T>& aRhv)
1787 return aRhv.getAppliedTransform(aLhv);
1789 template<class T> inline _Vector3<T> operator*(const _Vector3<T>& aLhv, const Matrix4<T>& aRhv)
1791 return aRhv.getAppliedTransform(aLhv);
1793 template<class T> inline _Vector3<T> operator*(const Matrix4<T>& aLhv, const _Vector3<T>& aRhv)
1795 return _Vector3<T>( aLhv.i.x * aRhv.x + aLhv.i.y * aRhv.y + aLhv.i.z * aRhv.z + aLhv.i.w,
1796 aLhv.j.x * aRhv.x + aLhv.j.y * aRhv.y + aLhv.j.z * aRhv.z + aLhv.j.w,
1797 aLhv.k.x * aRhv.x + aLhv.k.y * aRhv.y + aLhv.k.z * aRhv.z + aLhv.k.w);
1799 template<class T> inline Matrix4<T> operator/(const Matrix4<T>& aLhv, const T& aRhv)
1801 return Matrix4<T>(aLhv.i / aRhv, aLhv.j / aRhv, aLhv.k / aRhv, aLhv.c / aRhv);
1803 template<class T> inline Matrix4<T> operator/(const T& aLhv, const Matrix4<T>& aRhv)
1805 return Matrix4<T>(aLhv / aRhv.i, aLhv / aRhv.j, aLhv / aRhv.k, aLhv / aRhv.c);
1807 template<class T> inline bool operator==(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
1809 return aLhv.i == aRhv.i && aLhv.j == aRhv.j && aLhv.k == aRhv.k && aLhv.c == aRhv.c;
1811 template<class T> inline bool operator==(const Matrix4<T>& aLhv, const T& aRhv)
1813 return aLhv.i == aRhv && aLhv.j == aRhv && aLhv.k == aRhv && aLhv.c == aRhv;
1815 template<class T> inline bool operator==(const T& aLhv, const Matrix4<T>& aRhv)
1817 return aLhv == aRhv.i && aLhv == aRhv.j && aLhv == aRhv.k && aLhv == aRhv.c;
1819 template<class T> inline bool operator!=(const Matrix4<T>& aLhv, const Matrix4<T>& aRhv)
1821 return !(aLhv == aRhv);
1823 template<class T> inline bool operator!=(const Matrix4<T>& aLhv, const T& aRhv)
1825 return !(aLhv == aRhv);
1827 template<class T> inline bool operator!=(const T& aLhv, const Matrix4<T>& aRhv)
1829 return !(aLhv == aRhv);
1831 } } } } //Tizen::Ui::Effects::_Utils
1833 #endif //_FUI_EFFECTS_INTERNAL_UTILS_MATRIX4_H_