2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseDoubleMatrix4.cpp
19 * @brief This is the implementation for DoubleMatrix class.
22 #include <FBaseDoubleMatrix4.h>
23 #include <FBaseSysLog.h>
25 namespace Tizen { namespace Base
28 static const int MATRIX_SIZE = sizeof(double) * 16;
29 #define SWAP_VALUES(a, b, tmp) \
34 DoubleMatrix4::DoubleMatrix4(void)
40 DoubleMatrix4::DoubleMatrix4(const DoubleMatrix4& rhs)
43 memcpy(matrix, rhs.matrix, MATRIX_SIZE);
46 DoubleMatrix4::DoubleMatrix4(const double matrix[4][4])
49 memcpy(this->matrix, matrix, MATRIX_SIZE);
52 DoubleMatrix4::~DoubleMatrix4(void)
57 DoubleMatrix4::operator ==(const DoubleMatrix4& rhs) const
64 return (matrix[0][0] == rhs.matrix[0][0] &&
65 matrix[0][1] == rhs.matrix[0][1] &&
66 matrix[0][2] == rhs.matrix[0][2] &&
67 matrix[0][3] == rhs.matrix[0][3] &&
68 matrix[1][0] == rhs.matrix[1][0] &&
69 matrix[1][1] == rhs.matrix[1][1] &&
70 matrix[1][2] == rhs.matrix[1][2] &&
71 matrix[1][3] == rhs.matrix[1][3] &&
72 matrix[2][0] == rhs.matrix[2][0] &&
73 matrix[2][1] == rhs.matrix[2][1] &&
74 matrix[2][2] == rhs.matrix[2][2] &&
75 matrix[2][3] == rhs.matrix[2][3] &&
76 matrix[3][0] == rhs.matrix[3][0] &&
77 matrix[3][1] == rhs.matrix[3][1] &&
78 matrix[3][2] == rhs.matrix[3][2] &&
79 matrix[3][3] == rhs.matrix[3][3]);
83 DoubleMatrix4::operator !=(const DoubleMatrix4& rhs) const
85 return !(*this == rhs);
89 DoubleMatrix4::operator =(const DoubleMatrix4& rhs)
93 memcpy(matrix, rhs.matrix, MATRIX_SIZE);
100 DoubleMatrix4::operator =(double value)
102 matrix[0][0] = value;
103 matrix[1][0] = value;
104 matrix[2][0] = value;
105 matrix[3][0] = value;
107 matrix[0][1] = value;
108 matrix[1][1] = value;
109 matrix[2][1] = value;
110 matrix[3][1] = value;
112 matrix[0][2] = value;
113 matrix[1][2] = value;
114 matrix[2][2] = value;
115 matrix[3][2] = value;
117 matrix[0][3] = value;
118 matrix[1][3] = value;
119 matrix[2][3] = value;
120 matrix[3][3] = value;
126 DoubleMatrix4::operator *(const DoubleMatrix4& rhs) const // need to check performance
128 DoubleMatrix4 resultMatrix;
130 resultMatrix.matrix[0][0] = matrix[0][0] * rhs.matrix[0][0] + matrix[0][1] * rhs.matrix[1][0] + matrix[0][2] * rhs.matrix[2][0] + matrix[0][3] * rhs.matrix[3][0];
131 resultMatrix.matrix[0][1] = matrix[0][0] * rhs.matrix[0][1] + matrix[0][1] * rhs.matrix[1][1] + matrix[0][2] * rhs.matrix[2][1] + matrix[0][3] * rhs.matrix[3][1];
132 resultMatrix.matrix[0][2] = matrix[0][0] * rhs.matrix[0][2] + matrix[0][1] * rhs.matrix[1][2] + matrix[0][2] * rhs.matrix[2][2] + matrix[0][3] * rhs.matrix[3][2];
133 resultMatrix.matrix[0][3] = matrix[0][0] * rhs.matrix[0][3] + matrix[0][1] * rhs.matrix[1][3] + matrix[0][2] * rhs.matrix[2][3] + matrix[0][3] * rhs.matrix[3][3];
135 resultMatrix.matrix[1][0] = matrix[1][0] * rhs.matrix[0][0] + matrix[1][1] * rhs.matrix[1][0] + matrix[1][2] * rhs.matrix[2][0] + matrix[1][3] * rhs.matrix[3][0];
136 resultMatrix.matrix[1][1] = matrix[1][0] * rhs.matrix[0][1] + matrix[1][1] * rhs.matrix[1][1] + matrix[1][2] * rhs.matrix[2][1] + matrix[1][3] * rhs.matrix[3][1];
137 resultMatrix.matrix[1][2] = matrix[1][0] * rhs.matrix[0][2] + matrix[1][1] * rhs.matrix[1][2] + matrix[1][2] * rhs.matrix[2][2] + matrix[1][3] * rhs.matrix[3][2];
138 resultMatrix.matrix[1][3] = matrix[1][0] * rhs.matrix[0][3] + matrix[1][1] * rhs.matrix[1][3] + matrix[1][2] * rhs.matrix[2][3] + matrix[1][3] * rhs.matrix[3][3];
140 resultMatrix.matrix[2][0] = matrix[2][0] * rhs.matrix[0][0] + matrix[2][1] * rhs.matrix[1][0] + matrix[2][2] * rhs.matrix[2][0] + matrix[2][3] * rhs.matrix[3][0];
141 resultMatrix.matrix[2][1] = matrix[2][0] * rhs.matrix[0][1] + matrix[2][1] * rhs.matrix[1][1] + matrix[2][2] * rhs.matrix[2][1] + matrix[2][3] * rhs.matrix[3][1];
142 resultMatrix.matrix[2][2] = matrix[2][0] * rhs.matrix[0][2] + matrix[2][1] * rhs.matrix[1][2] + matrix[2][2] * rhs.matrix[2][2] + matrix[2][3] * rhs.matrix[3][2];
143 resultMatrix.matrix[2][3] = matrix[2][0] * rhs.matrix[0][3] + matrix[2][1] * rhs.matrix[1][3] + matrix[2][2] * rhs.matrix[2][3] + matrix[2][3] * rhs.matrix[3][3];
145 resultMatrix.matrix[3][0] = matrix[3][0] * rhs.matrix[0][0] + matrix[3][1] * rhs.matrix[1][0] + matrix[3][2] * rhs.matrix[2][0] + matrix[3][3] * rhs.matrix[3][0];
146 resultMatrix.matrix[3][1] = matrix[3][0] * rhs.matrix[0][1] + matrix[3][1] * rhs.matrix[1][1] + matrix[3][2] * rhs.matrix[2][1] + matrix[3][3] * rhs.matrix[3][1];
147 resultMatrix.matrix[3][2] = matrix[3][0] * rhs.matrix[0][2] + matrix[3][1] * rhs.matrix[1][2] + matrix[3][2] * rhs.matrix[2][2] + matrix[3][3] * rhs.matrix[3][2];
148 resultMatrix.matrix[3][3] = matrix[3][0] * rhs.matrix[0][3] + matrix[3][1] * rhs.matrix[1][3] + matrix[3][2] * rhs.matrix[2][3] + matrix[3][3] * rhs.matrix[3][3];
154 DoubleMatrix4::operator *(double value) const
156 DoubleMatrix4 resultMatrix(matrix);
158 resultMatrix.matrix[0][0] *= value;
159 resultMatrix.matrix[0][1] *= value;
160 resultMatrix.matrix[0][2] *= value;
161 resultMatrix.matrix[0][3] *= value;
163 resultMatrix.matrix[1][0] *= value;
164 resultMatrix.matrix[1][1] *= value;
165 resultMatrix.matrix[1][2] *= value;
166 resultMatrix.matrix[1][3] *= value;
168 resultMatrix.matrix[2][0] *= value;
169 resultMatrix.matrix[2][1] *= value;
170 resultMatrix.matrix[2][2] *= value;
171 resultMatrix.matrix[2][3] *= value;
173 resultMatrix.matrix[3][0] *= value;
174 resultMatrix.matrix[3][1] *= value;
175 resultMatrix.matrix[3][2] *= value;
176 resultMatrix.matrix[3][3] *= value;
182 DoubleMatrix4::operator +(const DoubleMatrix4& rhs) const
184 DoubleMatrix4 resultMatrix(matrix);
186 resultMatrix.matrix[0][0] += rhs.matrix[0][0];
187 resultMatrix.matrix[0][1] += rhs.matrix[0][1];
188 resultMatrix.matrix[0][2] += rhs.matrix[0][2];
189 resultMatrix.matrix[0][3] += rhs.matrix[0][3];
191 resultMatrix.matrix[1][0] += rhs.matrix[1][0];
192 resultMatrix.matrix[1][1] += rhs.matrix[1][1];
193 resultMatrix.matrix[1][2] += rhs.matrix[1][2];
194 resultMatrix.matrix[1][3] += rhs.matrix[1][3];
196 resultMatrix.matrix[2][0] += rhs.matrix[2][0];
197 resultMatrix.matrix[2][1] += rhs.matrix[2][1];
198 resultMatrix.matrix[2][2] += rhs.matrix[2][2];
199 resultMatrix.matrix[2][3] += rhs.matrix[2][3];
201 resultMatrix.matrix[3][0] += rhs.matrix[3][0];
202 resultMatrix.matrix[3][1] += rhs.matrix[3][1];
203 resultMatrix.matrix[3][2] += rhs.matrix[3][2];
204 resultMatrix.matrix[3][3] += rhs.matrix[3][3];
210 DoubleMatrix4::operator +(double value) const
212 DoubleMatrix4 resultMatrix(matrix);
214 resultMatrix.matrix[0][0] += value;
215 resultMatrix.matrix[0][1] += value;
216 resultMatrix.matrix[0][2] += value;
217 resultMatrix.matrix[0][3] += value;
219 resultMatrix.matrix[1][0] += value;
220 resultMatrix.matrix[1][1] += value;
221 resultMatrix.matrix[1][2] += value;
222 resultMatrix.matrix[1][3] += value;
224 resultMatrix.matrix[2][0] += value;
225 resultMatrix.matrix[2][1] += value;
226 resultMatrix.matrix[2][2] += value;
227 resultMatrix.matrix[2][3] += value;
229 resultMatrix.matrix[3][0] += value;
230 resultMatrix.matrix[3][1] += value;
231 resultMatrix.matrix[3][2] += value;
232 resultMatrix.matrix[3][3] += value;
238 DoubleMatrix4::operator -(const DoubleMatrix4& rhs) const
240 DoubleMatrix4 resultMatrix(matrix);
242 resultMatrix.matrix[0][0] -= rhs.matrix[0][0];
243 resultMatrix.matrix[0][1] -= rhs.matrix[0][1];
244 resultMatrix.matrix[0][2] -= rhs.matrix[0][2];
245 resultMatrix.matrix[0][3] -= rhs.matrix[0][3];
247 resultMatrix.matrix[1][0] -= rhs.matrix[1][0];
248 resultMatrix.matrix[1][1] -= rhs.matrix[1][1];
249 resultMatrix.matrix[1][2] -= rhs.matrix[1][2];
250 resultMatrix.matrix[1][3] -= rhs.matrix[1][3];
252 resultMatrix.matrix[2][0] -= rhs.matrix[2][0];
253 resultMatrix.matrix[2][1] -= rhs.matrix[2][1];
254 resultMatrix.matrix[2][2] -= rhs.matrix[2][2];
255 resultMatrix.matrix[2][3] -= rhs.matrix[2][3];
257 resultMatrix.matrix[3][0] -= rhs.matrix[3][0];
258 resultMatrix.matrix[3][1] -= rhs.matrix[3][1];
259 resultMatrix.matrix[3][2] -= rhs.matrix[3][2];
260 resultMatrix.matrix[3][3] -= rhs.matrix[3][3];
266 DoubleMatrix4::operator -(double value) const
268 DoubleMatrix4 resultMatrix(matrix);
270 resultMatrix.matrix[0][0] -= value;
271 resultMatrix.matrix[0][1] -= value;
272 resultMatrix.matrix[0][2] -= value;
273 resultMatrix.matrix[0][3] -= value;
275 resultMatrix.matrix[1][0] -= value;
276 resultMatrix.matrix[1][1] -= value;
277 resultMatrix.matrix[1][2] -= value;
278 resultMatrix.matrix[1][3] -= value;
280 resultMatrix.matrix[2][0] -= value;
281 resultMatrix.matrix[2][1] -= value;
282 resultMatrix.matrix[2][2] -= value;
283 resultMatrix.matrix[2][3] -= value;
285 resultMatrix.matrix[3][0] -= value;
286 resultMatrix.matrix[3][1] -= value;
287 resultMatrix.matrix[3][2] -= value;
288 resultMatrix.matrix[3][3] -= value;
294 DoubleMatrix4::operator *=(const DoubleMatrix4& rhs)
301 DoubleMatrix4::operator *=(double value)
303 *this = *this * value;
308 DoubleMatrix4::operator +=(const DoubleMatrix4& rhs)
315 DoubleMatrix4::operator +=(double value)
317 *this = *this + value;
322 DoubleMatrix4::operator -=(const DoubleMatrix4& rhs)
329 DoubleMatrix4::operator -=(double value)
331 *this = *this - value;
336 operator +(const double& value, const DoubleMatrix4& rhs)
342 operator *(const double& value, const DoubleMatrix4& rhs)
348 operator -(const double& value, const DoubleMatrix4& rhs)
350 DoubleMatrix4 returnMatrix(rhs);
351 returnMatrix.Negate();
352 returnMatrix += value;
357 DoubleMatrix4::Equals(const Tizen::Base::Object& obj) const
359 const DoubleMatrix4* pMatrix = dynamic_cast <const DoubleMatrix4*>(&obj);
366 return (*this == *pMatrix);
370 DoubleMatrix4::GetHashCode(void) const
372 return (Tizen::Base::Double::GetHashCode(matrix[0][0]) + Tizen::Base::Double::GetHashCode(matrix[1][0]) +
373 Tizen::Base::Double::GetHashCode(matrix[2][0]) + Tizen::Base::Double::GetHashCode(matrix[3][0]) +
374 Tizen::Base::Double::GetHashCode(matrix[0][1]) + Tizen::Base::Double::GetHashCode(matrix[1][1]) +
375 Tizen::Base::Double::GetHashCode(matrix[2][1]) + Tizen::Base::Double::GetHashCode(matrix[3][1]) +
376 Tizen::Base::Double::GetHashCode(matrix[0][2]) + Tizen::Base::Double::GetHashCode(matrix[1][2]) +
377 Tizen::Base::Double::GetHashCode(matrix[2][2]) + Tizen::Base::Double::GetHashCode(matrix[3][2]) +
378 Tizen::Base::Double::GetHashCode(matrix[0][3]) + Tizen::Base::Double::GetHashCode(matrix[1][3]) +
379 Tizen::Base::Double::GetHashCode(matrix[2][3]) + Tizen::Base::Double::GetHashCode(matrix[3][3]));
383 DoubleMatrix4::GetDeterminant(void) const
385 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
386 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
387 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
388 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
389 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
390 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
392 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
393 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
394 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
395 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
396 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
397 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
399 return a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
403 DoubleMatrix4::GetInverse(void) const
405 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
406 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
407 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
408 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
409 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
410 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
412 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
413 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
414 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
415 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
416 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
417 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
419 double determinant = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
421 if (Tizen::Base::Double::Compare(determinant, 0.0f) == 0)
426 double inverseMatrix[4][4];
428 inverseMatrix[0][0] = (matrix[1][1] * b5 - matrix[1][2] * b4 + matrix[1][3] * b3) / determinant;
429 inverseMatrix[1][0] = (-matrix[1][0] * b5 + matrix[1][2] * b2 - matrix[1][3] * b1) / determinant;
430 inverseMatrix[2][0] = (matrix[1][0] * b4 - matrix[1][1] * b2 + matrix[1][3] * b0) / determinant;
431 inverseMatrix[3][0] = (-matrix[1][0] * b3 + matrix[1][1] * b1 - matrix[1][2] * b0) / determinant;
433 inverseMatrix[0][1] = (-matrix[0][1] * b5 + matrix[0][2] * b4 - matrix[0][3] * b3) / determinant;
434 inverseMatrix[1][1] = (matrix[0][0] * b5 - matrix[0][2] * b2 + matrix[0][3] * b1) / determinant;
435 inverseMatrix[2][1] = (-matrix[0][0] * b4 + matrix[0][1] * b2 - matrix[0][3] * b0) / determinant;
436 inverseMatrix[3][1] = (matrix[0][0] * b3 - matrix[0][1] * b1 + matrix[0][2] * b0) / determinant;
438 inverseMatrix[0][2] = (matrix[3][1] * a5 - matrix[3][2] * a4 + matrix[3][3] * a3) / determinant;
439 inverseMatrix[1][2] = (-matrix[3][0] * a5 + matrix[3][2] * a2 - matrix[3][3] * a1) / determinant;
440 inverseMatrix[2][2] = (matrix[3][0] * a4 - matrix[3][1] * a2 + matrix[3][3] * a0) / determinant;
441 inverseMatrix[3][2] = (-matrix[3][0] * a3 + matrix[3][1] * a1 - matrix[3][2] * a0) / determinant;
443 inverseMatrix[0][3] = (-matrix[2][1] * a5 + matrix[2][2] * a4 - matrix[2][3] * a3) / determinant;
444 inverseMatrix[1][3] = (matrix[2][0] * a5 - matrix[2][2] * a2 + matrix[2][3] * a1) / determinant;
445 inverseMatrix[2][3] = (-matrix[2][0] * a4 + matrix[2][1] * a2 - matrix[2][3] * a0) / determinant;
446 inverseMatrix[3][3] = (matrix[2][0] * a3 - matrix[2][1] * a1 + matrix[2][2] * a0) / determinant;
448 return DoubleMatrix4(inverseMatrix);
452 DoubleMatrix4::GetTrace(void) const
454 return matrix[0][0] + matrix[1][1] + matrix[2][2] + matrix[3][3];
458 DoubleMatrix4::GetTranspose(void) const
460 DoubleMatrix4 transposeMatrix(matrix);
461 transposeMatrix.Transpose();
463 return transposeMatrix;
467 DoubleMatrix4::IsIdentity(void) const
469 if ((Tizen::Base::Double::Compare(matrix[0][0], 1.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][1], 1.0f) != 0) ||
470 (Tizen::Base::Double::Compare(matrix[2][2], 1.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][3], 1.0f) != 0))
475 if ((Tizen::Base::Double::Compare(matrix[0][1], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[0][2], 0.0f) != 0) ||
476 (Tizen::Base::Double::Compare(matrix[0][3], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][0], 0.0f) != 0) ||
477 (Tizen::Base::Double::Compare(matrix[1][2], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][3], 0.0f) != 0) ||
478 (Tizen::Base::Double::Compare(matrix[2][0], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[2][1], 0.0f) != 0) ||
479 (Tizen::Base::Double::Compare(matrix[2][3], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][0], 0.0f) != 0) ||
480 (Tizen::Base::Double::Compare(matrix[3][1], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][2], 0.0f) != 0))
489 DoubleMatrix4::IsInvertible(void) const
491 if (Tizen::Base::Double::Compare(GetDeterminant(), 0.0f) == 0)
500 DoubleMatrix4::Negate(void)
502 matrix[0][0] = -matrix[0][0];
503 matrix[0][1] = -matrix[0][1];
504 matrix[0][2] = -matrix[0][2];
505 matrix[0][3] = -matrix[0][3];
507 matrix[1][0] = -matrix[1][0];
508 matrix[1][1] = -matrix[1][1];
509 matrix[1][2] = -matrix[1][2];
510 matrix[1][3] = -matrix[1][3];
512 matrix[2][0] = -matrix[2][0];
513 matrix[2][1] = -matrix[2][1];
514 matrix[2][2] = -matrix[2][2];
515 matrix[2][3] = -matrix[2][3];
517 matrix[3][0] = -matrix[3][0];
518 matrix[3][1] = -matrix[3][1];
519 matrix[3][2] = -matrix[3][2];
520 matrix[3][3] = -matrix[3][3];
524 DoubleMatrix4::SetAsIdentity(void)
548 DoubleMatrix4::Invert(void)
550 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
551 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
552 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
553 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
554 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
555 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
557 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
558 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
559 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
560 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
561 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
562 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
564 double determinant = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
566 SysTryReturnResult(NID_BASE, Tizen::Base::Double::Compare(determinant, 0.0f) != 0, E_INVALID_OPERATION,
567 "The current instance is not invertible.");
569 double inverseMatrix[4][4];
571 inverseMatrix[0][0] = (matrix[1][1] * b5 - matrix[1][2] * b4 + matrix[1][3] * b3) / determinant;
572 inverseMatrix[1][0] = (-matrix[1][0] * b5 + matrix[1][2] * b2 - matrix[1][3] * b1) / determinant;
573 inverseMatrix[2][0] = (matrix[1][0] * b4 - matrix[1][1] * b2 + matrix[1][3] * b0) / determinant;
574 inverseMatrix[3][0] = (-matrix[1][0] * b3 + matrix[1][1] * b1 - matrix[1][2] * b0) / determinant;
576 inverseMatrix[0][1] = (-matrix[0][1] * b5 + matrix[0][2] * b4 - matrix[0][3] * b3) / determinant;
577 inverseMatrix[1][1] = (matrix[0][0] * b5 - matrix[0][2] * b2 + matrix[0][3] * b1) / determinant;
578 inverseMatrix[2][1] = (-matrix[0][0] * b4 + matrix[0][1] * b2 - matrix[0][3] * b0) / determinant;
579 inverseMatrix[3][1] = (matrix[0][0] * b3 - matrix[0][1] * b1 + matrix[0][2] * b0) / determinant;
581 inverseMatrix[0][2] = (matrix[3][1] * a5 - matrix[3][2] * a4 + matrix[3][3] * a3) / determinant;
582 inverseMatrix[1][2] = (-matrix[3][0] * a5 + matrix[3][2] * a2 - matrix[3][3] * a1) / determinant;
583 inverseMatrix[2][2] = (matrix[3][0] * a4 - matrix[3][1] * a2 + matrix[3][3] * a0) / determinant;
584 inverseMatrix[3][2] = (-matrix[3][0] * a3 + matrix[3][1] * a1 - matrix[3][2] * a0) / determinant;
586 inverseMatrix[0][3] = (-matrix[2][1] * a5 + matrix[2][2] * a4 - matrix[2][3] * a3) / determinant;
587 inverseMatrix[1][3] = (matrix[2][0] * a5 - matrix[2][2] * a2 + matrix[2][3] * a1) / determinant;
588 inverseMatrix[2][3] = (-matrix[2][0] * a4 + matrix[2][1] * a2 - matrix[2][3] * a0) / determinant;
589 inverseMatrix[3][3] = (matrix[2][0] * a3 - matrix[2][1] * a1 + matrix[2][2] * a0) / determinant;
591 memcpy(matrix, inverseMatrix, MATRIX_SIZE);
597 DoubleMatrix4::Transpose(void)
600 SWAP_VALUES(matrix[0][1], matrix[1][0], tmp);
601 SWAP_VALUES(matrix[0][2], matrix[2][0], tmp);
602 SWAP_VALUES(matrix[0][3], matrix[3][0], tmp);
604 SWAP_VALUES(matrix[1][2], matrix[2][1], tmp);
605 SWAP_VALUES(matrix[1][3], matrix[3][1], tmp);
607 SWAP_VALUES(matrix[2][3], matrix[3][2], tmp);
611 DoubleMatrix4::SetAsNull(void)