2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 FBaseDoubleMatrix4.cpp
20 * @brief This is the implementation for DoubleMatrix class.
23 #include <FBaseDoubleMatrix4.h>
24 #include <FBaseSysLog.h>
26 namespace Tizen { namespace Base
29 static const int MATRIX_SIZE = sizeof(double) * 16;
30 #define SWAP_VALUES(a, b, tmp) \
35 DoubleMatrix4::DoubleMatrix4(void)
41 DoubleMatrix4::DoubleMatrix4(const DoubleMatrix4& rhs)
44 memcpy(matrix, rhs.matrix, MATRIX_SIZE);
47 DoubleMatrix4::DoubleMatrix4(const double matrix[4][4])
50 memcpy(this->matrix, matrix, MATRIX_SIZE);
53 DoubleMatrix4::~DoubleMatrix4(void)
58 DoubleMatrix4::operator ==(const DoubleMatrix4& rhs) const
65 return (matrix[0][0] == rhs.matrix[0][0] &&
66 matrix[0][1] == rhs.matrix[0][1] &&
67 matrix[0][2] == rhs.matrix[0][2] &&
68 matrix[0][3] == rhs.matrix[0][3] &&
69 matrix[1][0] == rhs.matrix[1][0] &&
70 matrix[1][1] == rhs.matrix[1][1] &&
71 matrix[1][2] == rhs.matrix[1][2] &&
72 matrix[1][3] == rhs.matrix[1][3] &&
73 matrix[2][0] == rhs.matrix[2][0] &&
74 matrix[2][1] == rhs.matrix[2][1] &&
75 matrix[2][2] == rhs.matrix[2][2] &&
76 matrix[2][3] == rhs.matrix[2][3] &&
77 matrix[3][0] == rhs.matrix[3][0] &&
78 matrix[3][1] == rhs.matrix[3][1] &&
79 matrix[3][2] == rhs.matrix[3][2] &&
80 matrix[3][3] == rhs.matrix[3][3]);
84 DoubleMatrix4::operator !=(const DoubleMatrix4& rhs) const
86 return !(*this == rhs);
90 DoubleMatrix4::operator =(const DoubleMatrix4& rhs)
94 memcpy(matrix, rhs.matrix, MATRIX_SIZE);
101 DoubleMatrix4::operator =(double value)
103 matrix[0][0] = value;
104 matrix[1][0] = value;
105 matrix[2][0] = value;
106 matrix[3][0] = value;
108 matrix[0][1] = value;
109 matrix[1][1] = value;
110 matrix[2][1] = value;
111 matrix[3][1] = value;
113 matrix[0][2] = value;
114 matrix[1][2] = value;
115 matrix[2][2] = value;
116 matrix[3][2] = value;
118 matrix[0][3] = value;
119 matrix[1][3] = value;
120 matrix[2][3] = value;
121 matrix[3][3] = value;
127 DoubleMatrix4::operator *(const DoubleMatrix4& rhs) const // need to check performance
129 DoubleMatrix4 resultMatrix;
131 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];
132 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];
133 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];
134 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];
136 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];
137 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];
138 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];
139 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];
141 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];
142 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];
143 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];
144 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];
146 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];
147 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];
148 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];
149 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];
155 DoubleMatrix4::operator *(double value) const
157 DoubleMatrix4 resultMatrix(matrix);
159 resultMatrix.matrix[0][0] *= value;
160 resultMatrix.matrix[0][1] *= value;
161 resultMatrix.matrix[0][2] *= value;
162 resultMatrix.matrix[0][3] *= value;
164 resultMatrix.matrix[1][0] *= value;
165 resultMatrix.matrix[1][1] *= value;
166 resultMatrix.matrix[1][2] *= value;
167 resultMatrix.matrix[1][3] *= value;
169 resultMatrix.matrix[2][0] *= value;
170 resultMatrix.matrix[2][1] *= value;
171 resultMatrix.matrix[2][2] *= value;
172 resultMatrix.matrix[2][3] *= value;
174 resultMatrix.matrix[3][0] *= value;
175 resultMatrix.matrix[3][1] *= value;
176 resultMatrix.matrix[3][2] *= value;
177 resultMatrix.matrix[3][3] *= value;
183 DoubleMatrix4::operator +(const DoubleMatrix4& rhs) const
185 DoubleMatrix4 resultMatrix(matrix);
187 resultMatrix.matrix[0][0] += rhs.matrix[0][0];
188 resultMatrix.matrix[0][1] += rhs.matrix[0][1];
189 resultMatrix.matrix[0][2] += rhs.matrix[0][2];
190 resultMatrix.matrix[0][3] += rhs.matrix[0][3];
192 resultMatrix.matrix[1][0] += rhs.matrix[1][0];
193 resultMatrix.matrix[1][1] += rhs.matrix[1][1];
194 resultMatrix.matrix[1][2] += rhs.matrix[1][2];
195 resultMatrix.matrix[1][3] += rhs.matrix[1][3];
197 resultMatrix.matrix[2][0] += rhs.matrix[2][0];
198 resultMatrix.matrix[2][1] += rhs.matrix[2][1];
199 resultMatrix.matrix[2][2] += rhs.matrix[2][2];
200 resultMatrix.matrix[2][3] += rhs.matrix[2][3];
202 resultMatrix.matrix[3][0] += rhs.matrix[3][0];
203 resultMatrix.matrix[3][1] += rhs.matrix[3][1];
204 resultMatrix.matrix[3][2] += rhs.matrix[3][2];
205 resultMatrix.matrix[3][3] += rhs.matrix[3][3];
211 DoubleMatrix4::operator +(double value) const
213 DoubleMatrix4 resultMatrix(matrix);
215 resultMatrix.matrix[0][0] += value;
216 resultMatrix.matrix[0][1] += value;
217 resultMatrix.matrix[0][2] += value;
218 resultMatrix.matrix[0][3] += value;
220 resultMatrix.matrix[1][0] += value;
221 resultMatrix.matrix[1][1] += value;
222 resultMatrix.matrix[1][2] += value;
223 resultMatrix.matrix[1][3] += value;
225 resultMatrix.matrix[2][0] += value;
226 resultMatrix.matrix[2][1] += value;
227 resultMatrix.matrix[2][2] += value;
228 resultMatrix.matrix[2][3] += value;
230 resultMatrix.matrix[3][0] += value;
231 resultMatrix.matrix[3][1] += value;
232 resultMatrix.matrix[3][2] += value;
233 resultMatrix.matrix[3][3] += value;
239 DoubleMatrix4::operator -(const DoubleMatrix4& rhs) const
241 DoubleMatrix4 resultMatrix(matrix);
243 resultMatrix.matrix[0][0] -= rhs.matrix[0][0];
244 resultMatrix.matrix[0][1] -= rhs.matrix[0][1];
245 resultMatrix.matrix[0][2] -= rhs.matrix[0][2];
246 resultMatrix.matrix[0][3] -= rhs.matrix[0][3];
248 resultMatrix.matrix[1][0] -= rhs.matrix[1][0];
249 resultMatrix.matrix[1][1] -= rhs.matrix[1][1];
250 resultMatrix.matrix[1][2] -= rhs.matrix[1][2];
251 resultMatrix.matrix[1][3] -= rhs.matrix[1][3];
253 resultMatrix.matrix[2][0] -= rhs.matrix[2][0];
254 resultMatrix.matrix[2][1] -= rhs.matrix[2][1];
255 resultMatrix.matrix[2][2] -= rhs.matrix[2][2];
256 resultMatrix.matrix[2][3] -= rhs.matrix[2][3];
258 resultMatrix.matrix[3][0] -= rhs.matrix[3][0];
259 resultMatrix.matrix[3][1] -= rhs.matrix[3][1];
260 resultMatrix.matrix[3][2] -= rhs.matrix[3][2];
261 resultMatrix.matrix[3][3] -= rhs.matrix[3][3];
267 DoubleMatrix4::operator -(double value) const
269 DoubleMatrix4 resultMatrix(matrix);
271 resultMatrix.matrix[0][0] -= value;
272 resultMatrix.matrix[0][1] -= value;
273 resultMatrix.matrix[0][2] -= value;
274 resultMatrix.matrix[0][3] -= value;
276 resultMatrix.matrix[1][0] -= value;
277 resultMatrix.matrix[1][1] -= value;
278 resultMatrix.matrix[1][2] -= value;
279 resultMatrix.matrix[1][3] -= value;
281 resultMatrix.matrix[2][0] -= value;
282 resultMatrix.matrix[2][1] -= value;
283 resultMatrix.matrix[2][2] -= value;
284 resultMatrix.matrix[2][3] -= value;
286 resultMatrix.matrix[3][0] -= value;
287 resultMatrix.matrix[3][1] -= value;
288 resultMatrix.matrix[3][2] -= value;
289 resultMatrix.matrix[3][3] -= value;
295 DoubleMatrix4::operator *=(const DoubleMatrix4& rhs)
302 DoubleMatrix4::operator *=(double value)
304 *this = *this * value;
309 DoubleMatrix4::operator +=(const DoubleMatrix4& rhs)
316 DoubleMatrix4::operator +=(double value)
318 *this = *this + value;
323 DoubleMatrix4::operator -=(const DoubleMatrix4& rhs)
330 DoubleMatrix4::operator -=(double value)
332 *this = *this - value;
337 operator +(const double& value, const DoubleMatrix4& rhs)
343 operator *(const double& value, const DoubleMatrix4& rhs)
349 operator -(const double& value, const DoubleMatrix4& rhs)
351 DoubleMatrix4 returnMatrix(rhs);
352 returnMatrix.Negate();
353 returnMatrix += value;
358 DoubleMatrix4::Equals(const Tizen::Base::Object& obj) const
360 const DoubleMatrix4* pMatrix = dynamic_cast <const DoubleMatrix4*>(&obj);
367 return (*this == *pMatrix);
371 DoubleMatrix4::GetHashCode(void) const
373 return (Tizen::Base::Double::GetHashCode(matrix[0][0]) + Tizen::Base::Double::GetHashCode(matrix[1][0]) +
374 Tizen::Base::Double::GetHashCode(matrix[2][0]) + Tizen::Base::Double::GetHashCode(matrix[3][0]) +
375 Tizen::Base::Double::GetHashCode(matrix[0][1]) + Tizen::Base::Double::GetHashCode(matrix[1][1]) +
376 Tizen::Base::Double::GetHashCode(matrix[2][1]) + Tizen::Base::Double::GetHashCode(matrix[3][1]) +
377 Tizen::Base::Double::GetHashCode(matrix[0][2]) + Tizen::Base::Double::GetHashCode(matrix[1][2]) +
378 Tizen::Base::Double::GetHashCode(matrix[2][2]) + Tizen::Base::Double::GetHashCode(matrix[3][2]) +
379 Tizen::Base::Double::GetHashCode(matrix[0][3]) + Tizen::Base::Double::GetHashCode(matrix[1][3]) +
380 Tizen::Base::Double::GetHashCode(matrix[2][3]) + Tizen::Base::Double::GetHashCode(matrix[3][3]));
384 DoubleMatrix4::GetDeterminant(void) const
386 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
387 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
388 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
389 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
390 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
391 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
393 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
394 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
395 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
396 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
397 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
398 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
400 return a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
404 DoubleMatrix4::GetInverse(void) const
406 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
407 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
408 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
409 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
410 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
411 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
413 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
414 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
415 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
416 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
417 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
418 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
420 double determinant = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
422 if (Tizen::Base::Double::Compare(determinant, 0.0f) == 0)
427 double inverseMatrix[4][4];
429 inverseMatrix[0][0] = (matrix[1][1] * b5 - matrix[1][2] * b4 + matrix[1][3] * b3) / determinant;
430 inverseMatrix[1][0] = (-matrix[1][0] * b5 + matrix[1][2] * b2 - matrix[1][3] * b1) / determinant;
431 inverseMatrix[2][0] = (matrix[1][0] * b4 - matrix[1][1] * b2 + matrix[1][3] * b0) / determinant;
432 inverseMatrix[3][0] = (-matrix[1][0] * b3 + matrix[1][1] * b1 - matrix[1][2] * b0) / determinant;
434 inverseMatrix[0][1] = (-matrix[0][1] * b5 + matrix[0][2] * b4 - matrix[0][3] * b3) / determinant;
435 inverseMatrix[1][1] = (matrix[0][0] * b5 - matrix[0][2] * b2 + matrix[0][3] * b1) / determinant;
436 inverseMatrix[2][1] = (-matrix[0][0] * b4 + matrix[0][1] * b2 - matrix[0][3] * b0) / determinant;
437 inverseMatrix[3][1] = (matrix[0][0] * b3 - matrix[0][1] * b1 + matrix[0][2] * b0) / determinant;
439 inverseMatrix[0][2] = (matrix[3][1] * a5 - matrix[3][2] * a4 + matrix[3][3] * a3) / determinant;
440 inverseMatrix[1][2] = (-matrix[3][0] * a5 + matrix[3][2] * a2 - matrix[3][3] * a1) / determinant;
441 inverseMatrix[2][2] = (matrix[3][0] * a4 - matrix[3][1] * a2 + matrix[3][3] * a0) / determinant;
442 inverseMatrix[3][2] = (-matrix[3][0] * a3 + matrix[3][1] * a1 - matrix[3][2] * a0) / determinant;
444 inverseMatrix[0][3] = (-matrix[2][1] * a5 + matrix[2][2] * a4 - matrix[2][3] * a3) / determinant;
445 inverseMatrix[1][3] = (matrix[2][0] * a5 - matrix[2][2] * a2 + matrix[2][3] * a1) / determinant;
446 inverseMatrix[2][3] = (-matrix[2][0] * a4 + matrix[2][1] * a2 - matrix[2][3] * a0) / determinant;
447 inverseMatrix[3][3] = (matrix[2][0] * a3 - matrix[2][1] * a1 + matrix[2][2] * a0) / determinant;
449 return DoubleMatrix4(inverseMatrix);
453 DoubleMatrix4::GetTrace(void) const
455 return matrix[0][0] + matrix[1][1] + matrix[2][2] + matrix[3][3];
459 DoubleMatrix4::GetTranspose(void) const
461 DoubleMatrix4 transposeMatrix(matrix);
462 transposeMatrix.Transpose();
464 return transposeMatrix;
468 DoubleMatrix4::IsIdentity(void) const
470 if ((Tizen::Base::Double::Compare(matrix[0][0], 1.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][1], 1.0f) != 0) ||
471 (Tizen::Base::Double::Compare(matrix[2][2], 1.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][3], 1.0f) != 0))
476 if ((Tizen::Base::Double::Compare(matrix[0][1], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[0][2], 0.0f) != 0) ||
477 (Tizen::Base::Double::Compare(matrix[0][3], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][0], 0.0f) != 0) ||
478 (Tizen::Base::Double::Compare(matrix[1][2], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[1][3], 0.0f) != 0) ||
479 (Tizen::Base::Double::Compare(matrix[2][0], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[2][1], 0.0f) != 0) ||
480 (Tizen::Base::Double::Compare(matrix[2][3], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][0], 0.0f) != 0) ||
481 (Tizen::Base::Double::Compare(matrix[3][1], 0.0f) != 0) || (Tizen::Base::Double::Compare(matrix[3][2], 0.0f) != 0))
490 DoubleMatrix4::IsInvertible(void) const
492 if (Tizen::Base::Double::Compare(GetDeterminant(), 0.0f) == 0)
501 DoubleMatrix4::Negate(void)
503 matrix[0][0] = -matrix[0][0];
504 matrix[0][1] = -matrix[0][1];
505 matrix[0][2] = -matrix[0][2];
506 matrix[0][3] = -matrix[0][3];
508 matrix[1][0] = -matrix[1][0];
509 matrix[1][1] = -matrix[1][1];
510 matrix[1][2] = -matrix[1][2];
511 matrix[1][3] = -matrix[1][3];
513 matrix[2][0] = -matrix[2][0];
514 matrix[2][1] = -matrix[2][1];
515 matrix[2][2] = -matrix[2][2];
516 matrix[2][3] = -matrix[2][3];
518 matrix[3][0] = -matrix[3][0];
519 matrix[3][1] = -matrix[3][1];
520 matrix[3][2] = -matrix[3][2];
521 matrix[3][3] = -matrix[3][3];
525 DoubleMatrix4::SetAsIdentity(void)
549 DoubleMatrix4::Invert(void)
551 double a0 = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
552 double a1 = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
553 double a2 = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
554 double a3 = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
555 double a4 = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
556 double a5 = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
558 double b0 = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
559 double b1 = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
560 double b2 = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
561 double b3 = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
562 double b4 = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
563 double b5 = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
565 double determinant = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
567 SysTryReturnResult(NID_BASE, Tizen::Base::Double::Compare(determinant, 0.0f) != 0, E_INVALID_OPERATION,
568 "The current instance is not invertible.");
570 double inverseMatrix[4][4];
572 inverseMatrix[0][0] = (matrix[1][1] * b5 - matrix[1][2] * b4 + matrix[1][3] * b3) / determinant;
573 inverseMatrix[1][0] = (-matrix[1][0] * b5 + matrix[1][2] * b2 - matrix[1][3] * b1) / determinant;
574 inverseMatrix[2][0] = (matrix[1][0] * b4 - matrix[1][1] * b2 + matrix[1][3] * b0) / determinant;
575 inverseMatrix[3][0] = (-matrix[1][0] * b3 + matrix[1][1] * b1 - matrix[1][2] * b0) / determinant;
577 inverseMatrix[0][1] = (-matrix[0][1] * b5 + matrix[0][2] * b4 - matrix[0][3] * b3) / determinant;
578 inverseMatrix[1][1] = (matrix[0][0] * b5 - matrix[0][2] * b2 + matrix[0][3] * b1) / determinant;
579 inverseMatrix[2][1] = (-matrix[0][0] * b4 + matrix[0][1] * b2 - matrix[0][3] * b0) / determinant;
580 inverseMatrix[3][1] = (matrix[0][0] * b3 - matrix[0][1] * b1 + matrix[0][2] * b0) / determinant;
582 inverseMatrix[0][2] = (matrix[3][1] * a5 - matrix[3][2] * a4 + matrix[3][3] * a3) / determinant;
583 inverseMatrix[1][2] = (-matrix[3][0] * a5 + matrix[3][2] * a2 - matrix[3][3] * a1) / determinant;
584 inverseMatrix[2][2] = (matrix[3][0] * a4 - matrix[3][1] * a2 + matrix[3][3] * a0) / determinant;
585 inverseMatrix[3][2] = (-matrix[3][0] * a3 + matrix[3][1] * a1 - matrix[3][2] * a0) / determinant;
587 inverseMatrix[0][3] = (-matrix[2][1] * a5 + matrix[2][2] * a4 - matrix[2][3] * a3) / determinant;
588 inverseMatrix[1][3] = (matrix[2][0] * a5 - matrix[2][2] * a2 + matrix[2][3] * a1) / determinant;
589 inverseMatrix[2][3] = (-matrix[2][0] * a4 + matrix[2][1] * a2 - matrix[2][3] * a0) / determinant;
590 inverseMatrix[3][3] = (matrix[2][0] * a3 - matrix[2][1] * a1 + matrix[2][2] * a0) / determinant;
592 memcpy(matrix, inverseMatrix, MATRIX_SIZE);
598 DoubleMatrix4::Transpose(void)
601 SWAP_VALUES(matrix[0][1], matrix[1][0], tmp);
602 SWAP_VALUES(matrix[0][2], matrix[2][0], tmp);
603 SWAP_VALUES(matrix[0][3], matrix[3][0], tmp);
605 SWAP_VALUES(matrix[1][2], matrix[2][1], tmp);
606 SWAP_VALUES(matrix[1][3], matrix[3][1], tmp);
608 SWAP_VALUES(matrix[2][3], matrix[3][2], tmp);
612 DoubleMatrix4::SetAsNull(void)