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.
21 #include <FBaseDoubleMatrix4.h>
22 #include <FBaseSysLog.h>
24 namespace Tizen { namespace Base
27 static const int MATRIX_SIZE = sizeof(double) * 16;
28 #define SWAP_VALUES(a, b, tmp) \
33 DoubleMatrix4::DoubleMatrix4(void)
39 DoubleMatrix4::DoubleMatrix4(const DoubleMatrix4& rhs)
42 memcpy(matrix, rhs.matrix, MATRIX_SIZE);
45 DoubleMatrix4::DoubleMatrix4(const double matrix[4][4])
48 memcpy(this->matrix, matrix, MATRIX_SIZE);
51 DoubleMatrix4::~DoubleMatrix4(void)
56 DoubleMatrix4::operator ==(const DoubleMatrix4& rhs) const
63 return (matrix[0][0] == rhs.matrix[0][0] &&
64 matrix[0][1] == rhs.matrix[0][1] &&
65 matrix[0][2] == rhs.matrix[0][2] &&
66 matrix[0][3] == rhs.matrix[0][3] &&
67 matrix[1][0] == rhs.matrix[1][0] &&
68 matrix[1][1] == rhs.matrix[1][1] &&
69 matrix[1][2] == rhs.matrix[1][2] &&
70 matrix[1][3] == rhs.matrix[1][3] &&
71 matrix[2][0] == rhs.matrix[2][0] &&
72 matrix[2][1] == rhs.matrix[2][1] &&
73 matrix[2][2] == rhs.matrix[2][2] &&
74 matrix[2][3] == rhs.matrix[2][3] &&
75 matrix[3][0] == rhs.matrix[3][0] &&
76 matrix[3][1] == rhs.matrix[3][1] &&
77 matrix[3][2] == rhs.matrix[3][2] &&
78 matrix[3][3] == rhs.matrix[3][3]);
82 DoubleMatrix4::operator !=(const DoubleMatrix4& rhs) const
84 return !(*this == rhs);
88 DoubleMatrix4::operator =(const DoubleMatrix4& rhs)
92 memcpy(matrix, rhs.matrix, MATRIX_SIZE);
99 DoubleMatrix4::operator =(double value)
101 matrix[0][0] = value;
102 matrix[1][0] = value;
103 matrix[2][0] = value;
104 matrix[3][0] = value;
106 matrix[0][1] = value;
107 matrix[1][1] = value;
108 matrix[2][1] = value;
109 matrix[3][1] = value;
111 matrix[0][2] = value;
112 matrix[1][2] = value;
113 matrix[2][2] = value;
114 matrix[3][2] = value;
116 matrix[0][3] = value;
117 matrix[1][3] = value;
118 matrix[2][3] = value;
119 matrix[3][3] = value;
125 DoubleMatrix4::operator *(const DoubleMatrix4& rhs) const // need to check performance
127 DoubleMatrix4 resultMatrix;
129 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];
130 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];
131 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];
132 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];
134 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];
135 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];
136 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];
137 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];
139 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];
140 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];
141 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];
142 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];
144 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];
145 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];
146 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];
147 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];
153 DoubleMatrix4::operator *(double value) const
155 DoubleMatrix4 resultMatrix(matrix);
157 resultMatrix.matrix[0][0] *= value;
158 resultMatrix.matrix[0][1] *= value;
159 resultMatrix.matrix[0][2] *= value;
160 resultMatrix.matrix[0][3] *= value;
162 resultMatrix.matrix[1][0] *= value;
163 resultMatrix.matrix[1][1] *= value;
164 resultMatrix.matrix[1][2] *= value;
165 resultMatrix.matrix[1][3] *= value;
167 resultMatrix.matrix[2][0] *= value;
168 resultMatrix.matrix[2][1] *= value;
169 resultMatrix.matrix[2][2] *= value;
170 resultMatrix.matrix[2][3] *= value;
172 resultMatrix.matrix[3][0] *= value;
173 resultMatrix.matrix[3][1] *= value;
174 resultMatrix.matrix[3][2] *= value;
175 resultMatrix.matrix[3][3] *= value;
181 DoubleMatrix4::operator +(const DoubleMatrix4& rhs) const
183 DoubleMatrix4 resultMatrix(matrix);
185 resultMatrix.matrix[0][0] += rhs.matrix[0][0];
186 resultMatrix.matrix[0][1] += rhs.matrix[0][1];
187 resultMatrix.matrix[0][2] += rhs.matrix[0][2];
188 resultMatrix.matrix[0][3] += rhs.matrix[0][3];
190 resultMatrix.matrix[1][0] += rhs.matrix[1][0];
191 resultMatrix.matrix[1][1] += rhs.matrix[1][1];
192 resultMatrix.matrix[1][2] += rhs.matrix[1][2];
193 resultMatrix.matrix[1][3] += rhs.matrix[1][3];
195 resultMatrix.matrix[2][0] += rhs.matrix[2][0];
196 resultMatrix.matrix[2][1] += rhs.matrix[2][1];
197 resultMatrix.matrix[2][2] += rhs.matrix[2][2];
198 resultMatrix.matrix[2][3] += rhs.matrix[2][3];
200 resultMatrix.matrix[3][0] += rhs.matrix[3][0];
201 resultMatrix.matrix[3][1] += rhs.matrix[3][1];
202 resultMatrix.matrix[3][2] += rhs.matrix[3][2];
203 resultMatrix.matrix[3][3] += rhs.matrix[3][3];
209 DoubleMatrix4::operator +(double value) const
211 DoubleMatrix4 resultMatrix(matrix);
213 resultMatrix.matrix[0][0] += value;
214 resultMatrix.matrix[0][1] += value;
215 resultMatrix.matrix[0][2] += value;
216 resultMatrix.matrix[0][3] += value;
218 resultMatrix.matrix[1][0] += value;
219 resultMatrix.matrix[1][1] += value;
220 resultMatrix.matrix[1][2] += value;
221 resultMatrix.matrix[1][3] += value;
223 resultMatrix.matrix[2][0] += value;
224 resultMatrix.matrix[2][1] += value;
225 resultMatrix.matrix[2][2] += value;
226 resultMatrix.matrix[2][3] += value;
228 resultMatrix.matrix[3][0] += value;
229 resultMatrix.matrix[3][1] += value;
230 resultMatrix.matrix[3][2] += value;
231 resultMatrix.matrix[3][3] += value;
237 DoubleMatrix4::operator -(const DoubleMatrix4& rhs) const
239 DoubleMatrix4 resultMatrix(matrix);
241 resultMatrix.matrix[0][0] -= rhs.matrix[0][0];
242 resultMatrix.matrix[0][1] -= rhs.matrix[0][1];
243 resultMatrix.matrix[0][2] -= rhs.matrix[0][2];
244 resultMatrix.matrix[0][3] -= rhs.matrix[0][3];
246 resultMatrix.matrix[1][0] -= rhs.matrix[1][0];
247 resultMatrix.matrix[1][1] -= rhs.matrix[1][1];
248 resultMatrix.matrix[1][2] -= rhs.matrix[1][2];
249 resultMatrix.matrix[1][3] -= rhs.matrix[1][3];
251 resultMatrix.matrix[2][0] -= rhs.matrix[2][0];
252 resultMatrix.matrix[2][1] -= rhs.matrix[2][1];
253 resultMatrix.matrix[2][2] -= rhs.matrix[2][2];
254 resultMatrix.matrix[2][3] -= rhs.matrix[2][3];
256 resultMatrix.matrix[3][0] -= rhs.matrix[3][0];
257 resultMatrix.matrix[3][1] -= rhs.matrix[3][1];
258 resultMatrix.matrix[3][2] -= rhs.matrix[3][2];
259 resultMatrix.matrix[3][3] -= rhs.matrix[3][3];
265 DoubleMatrix4::operator -(double value) const
267 DoubleMatrix4 resultMatrix(matrix);
269 resultMatrix.matrix[0][0] -= value;
270 resultMatrix.matrix[0][1] -= value;
271 resultMatrix.matrix[0][2] -= value;
272 resultMatrix.matrix[0][3] -= value;
274 resultMatrix.matrix[1][0] -= value;
275 resultMatrix.matrix[1][1] -= value;
276 resultMatrix.matrix[1][2] -= value;
277 resultMatrix.matrix[1][3] -= value;
279 resultMatrix.matrix[2][0] -= value;
280 resultMatrix.matrix[2][1] -= value;
281 resultMatrix.matrix[2][2] -= value;
282 resultMatrix.matrix[2][3] -= value;
284 resultMatrix.matrix[3][0] -= value;
285 resultMatrix.matrix[3][1] -= value;
286 resultMatrix.matrix[3][2] -= value;
287 resultMatrix.matrix[3][3] -= value;
293 DoubleMatrix4::operator *=(const DoubleMatrix4& rhs)
300 DoubleMatrix4::operator *=(double value)
302 *this = *this * value;
307 DoubleMatrix4::operator +=(const DoubleMatrix4& rhs)
314 DoubleMatrix4::operator +=(double value)
316 *this = *this + value;
321 DoubleMatrix4::operator -=(const DoubleMatrix4& rhs)
328 DoubleMatrix4::operator -=(double value)
330 *this = *this - value;
335 operator +(const double& value, const DoubleMatrix4& rhs)
341 operator *(const double& value, const DoubleMatrix4& rhs)
347 operator -(const double& value, const DoubleMatrix4& rhs)
349 DoubleMatrix4 returnMatrix(rhs);
350 returnMatrix.Negate();
351 returnMatrix += value;
356 DoubleMatrix4::Equals(const Tizen::Base::Object& obj) const
358 const DoubleMatrix4* pMatrix = dynamic_cast< const DoubleMatrix4* >(&obj);
365 return (*this == *pMatrix);
369 DoubleMatrix4::GetHashCode(void) const
371 return (Tizen::Base::Double::GetHashCode(matrix[0][0]) + Tizen::Base::Double::GetHashCode(matrix[1][0]) +
372 Tizen::Base::Double::GetHashCode(matrix[2][0]) + Tizen::Base::Double::GetHashCode(matrix[3][0]) +
373 Tizen::Base::Double::GetHashCode(matrix[0][1]) + Tizen::Base::Double::GetHashCode(matrix[1][1]) +
374 Tizen::Base::Double::GetHashCode(matrix[2][1]) + Tizen::Base::Double::GetHashCode(matrix[3][1]) +
375 Tizen::Base::Double::GetHashCode(matrix[0][2]) + Tizen::Base::Double::GetHashCode(matrix[1][2]) +
376 Tizen::Base::Double::GetHashCode(matrix[2][2]) + Tizen::Base::Double::GetHashCode(matrix[3][2]) +
377 Tizen::Base::Double::GetHashCode(matrix[0][3]) + Tizen::Base::Double::GetHashCode(matrix[1][3]) +
378 Tizen::Base::Double::GetHashCode(matrix[2][3]) + Tizen::Base::Double::GetHashCode(matrix[3][3]));
382 DoubleMatrix4::GetDeterminant(void) const
384 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
385 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
386 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
387 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
388 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
389 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
391 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
392 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
393 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
394 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
395 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
396 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
398 return a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
402 DoubleMatrix4::GetInverse(void) const
404 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
405 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
406 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
407 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
408 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
409 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
411 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
412 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
413 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
414 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
415 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
416 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
418 double determinant = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
420 if (Tizen::Base::Double::Compare(determinant, 0.0f) == 0)
425 double inverseMatrix[4][4];
427 inverseMatrix[0][0] = (matrix[1][1] * b5 - matrix[1][2] * b4 + matrix[1][3] * b3) / determinant;
428 inverseMatrix[1][0] = (-matrix[1][0] * b5 + matrix[1][2] * b2 - matrix[1][3] * b1) / determinant;
429 inverseMatrix[2][0] = (matrix[1][0] * b4 - matrix[1][1] * b2 + matrix[1][3] * b0) / determinant;
430 inverseMatrix[3][0] = (-matrix[1][0] * b3 + matrix[1][1] * b1 - matrix[1][2] * b0) / determinant;
432 inverseMatrix[0][1] = (-matrix[0][1] * b5 + matrix[0][2] * b4 - matrix[0][3] * b3) / determinant;
433 inverseMatrix[1][1] = (matrix[0][0] * b5 - matrix[0][2] * b2 + matrix[0][3] * b1) / determinant;
434 inverseMatrix[2][1] = (-matrix[0][0] * b4 + matrix[0][1] * b2 - matrix[0][3] * b0) / determinant;
435 inverseMatrix[3][1] = (matrix[0][0] * b3 - matrix[0][1] * b1 + matrix[0][2] * b0) / determinant;
437 inverseMatrix[0][2] = (matrix[3][1] * a5 - matrix[3][2] * a4 + matrix[3][3] * a3) / determinant;
438 inverseMatrix[1][2] = (-matrix[3][0] * a5 + matrix[3][2] * a2 - matrix[3][3] * a1) / determinant;
439 inverseMatrix[2][2] = (matrix[3][0] * a4 - matrix[3][1] * a2 + matrix[3][3] * a0) / determinant;
440 inverseMatrix[3][2] = (-matrix[3][0] * a3 + matrix[3][1] * a1 - matrix[3][2] * a0) / determinant;
442 inverseMatrix[0][3] = (-matrix[2][1] * a5 + matrix[2][2] * a4 - matrix[2][3] * a3) / determinant;
443 inverseMatrix[1][3] = (matrix[2][0] * a5 - matrix[2][2] * a2 + matrix[2][3] * a1) / determinant;
444 inverseMatrix[2][3] = (-matrix[2][0] * a4 + matrix[2][1] * a2 - matrix[2][3] * a0) / determinant;
445 inverseMatrix[3][3] = (matrix[2][0] * a3 - matrix[2][1] * a1 + matrix[2][2] * a0) / determinant;
447 return DoubleMatrix4(inverseMatrix);
451 DoubleMatrix4::GetTrace(void) const
453 return matrix[0][0] + matrix[1][1] + matrix[2][2] + matrix[3][3];
457 DoubleMatrix4::GetTranspose(void) const
459 DoubleMatrix4 transposeMatrix(matrix);
460 transposeMatrix.Transpose();
462 return transposeMatrix;
466 DoubleMatrix4::IsIdentity(void) const
468 if ((Tizen::Base::Double::Compare(matrix[0][0], 1.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][1], 1.0f) != 0) ||
469 (Tizen::Base::Double::Compare(matrix[2][2], 1.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][3], 1.0f) != 0))
474 if ((Tizen::Base::Double::Compare(matrix[0][1], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[0][2], 0.0f) != 0) ||
475 (Tizen::Base::Double::Compare(matrix[0][3], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][0], 0.0f) != 0) ||
476 (Tizen::Base::Double::Compare(matrix[1][2], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][3], 0.0f) != 0) ||
477 (Tizen::Base::Double::Compare(matrix[2][0], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[2][1], 0.0f) != 0) ||
478 (Tizen::Base::Double::Compare(matrix[2][3], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][0], 0.0f) != 0) ||
479 (Tizen::Base::Double::Compare(matrix[3][1], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][2], 0.0f) != 0))
488 DoubleMatrix4::IsInvertible(void) const
490 if (Tizen::Base::Double::Compare(GetDeterminant(), 0.0f) == 0)
499 DoubleMatrix4::Negate(void)
501 matrix[0][0] = -matrix[0][0];
502 matrix[0][1] = -matrix[0][1];
503 matrix[0][2] = -matrix[0][2];
504 matrix[0][3] = -matrix[0][3];
506 matrix[1][0] = -matrix[1][0];
507 matrix[1][1] = -matrix[1][1];
508 matrix[1][2] = -matrix[1][2];
509 matrix[1][3] = -matrix[1][3];
511 matrix[2][0] = -matrix[2][0];
512 matrix[2][1] = -matrix[2][1];
513 matrix[2][2] = -matrix[2][2];
514 matrix[2][3] = -matrix[2][3];
516 matrix[3][0] = -matrix[3][0];
517 matrix[3][1] = -matrix[3][1];
518 matrix[3][2] = -matrix[3][2];
519 matrix[3][3] = -matrix[3][3];
523 DoubleMatrix4::SetAsIdentity(void)
547 DoubleMatrix4::Invert(void)
549 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
550 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
551 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
552 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
553 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
554 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
556 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
557 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
558 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
559 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
560 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
561 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
563 double determinant = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
565 SysTryReturnResult(NID_BASE, Tizen::Base::Double::Compare(determinant, 0.0f) != 0, E_INVALID_OPERATION,
566 "The current instance is not invertible.");
568 double inverseMatrix[4][4];
570 inverseMatrix[0][0] = (matrix[1][1] * b5 - matrix[1][2] * b4 + matrix[1][3] * b3) / determinant;
571 inverseMatrix[1][0] = (-matrix[1][0] * b5 + matrix[1][2] * b2 - matrix[1][3] * b1) / determinant;
572 inverseMatrix[2][0] = (matrix[1][0] * b4 - matrix[1][1] * b2 + matrix[1][3] * b0) / determinant;
573 inverseMatrix[3][0] = (-matrix[1][0] * b3 + matrix[1][1] * b1 - matrix[1][2] * b0) / determinant;
575 inverseMatrix[0][1] = (-matrix[0][1] * b5 + matrix[0][2] * b4 - matrix[0][3] * b3) / determinant;
576 inverseMatrix[1][1] = (matrix[0][0] * b5 - matrix[0][2] * b2 + matrix[0][3] * b1) / determinant;
577 inverseMatrix[2][1] = (-matrix[0][0] * b4 + matrix[0][1] * b2 - matrix[0][3] * b0) / determinant;
578 inverseMatrix[3][1] = (matrix[0][0] * b3 - matrix[0][1] * b1 + matrix[0][2] * b0) / determinant;
580 inverseMatrix[0][2] = (matrix[3][1] * a5 - matrix[3][2] * a4 + matrix[3][3] * a3) / determinant;
581 inverseMatrix[1][2] = (-matrix[3][0] * a5 + matrix[3][2] * a2 - matrix[3][3] * a1) / determinant;
582 inverseMatrix[2][2] = (matrix[3][0] * a4 - matrix[3][1] * a2 + matrix[3][3] * a0) / determinant;
583 inverseMatrix[3][2] = (-matrix[3][0] * a3 + matrix[3][1] * a1 - matrix[3][2] * a0) / determinant;
585 inverseMatrix[0][3] = (-matrix[2][1] * a5 + matrix[2][2] * a4 - matrix[2][3] * a3) / determinant;
586 inverseMatrix[1][3] = (matrix[2][0] * a5 - matrix[2][2] * a2 + matrix[2][3] * a1) / determinant;
587 inverseMatrix[2][3] = (-matrix[2][0] * a4 + matrix[2][1] * a2 - matrix[2][3] * a0) / determinant;
588 inverseMatrix[3][3] = (matrix[2][0] * a3 - matrix[2][1] * a1 + matrix[2][2] * a0) / determinant;
590 memcpy(matrix, inverseMatrix, MATRIX_SIZE);
596 DoubleMatrix4::Transpose(void)
599 SWAP_VALUES(matrix[0][1], matrix[1][0], tmp);
600 SWAP_VALUES(matrix[0][2], matrix[2][0], tmp);
601 SWAP_VALUES(matrix[0][3], matrix[3][0], tmp);
603 SWAP_VALUES(matrix[1][2], matrix[2][1], tmp);
604 SWAP_VALUES(matrix[1][3], matrix[3][1], tmp);
606 SWAP_VALUES(matrix[2][3], matrix[3][2], tmp);
610 DoubleMatrix4::SetAsNull(void)