OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // In other words, this is the layout of the matrix: | 71 // In other words, this is the layout of the matrix: |
72 // | 72 // |
73 // | m_matrix[0][0] m_matrix[1][0] m_matrix[2][0] m_matrix[3][0] | | 73 // | m_matrix[0][0] m_matrix[1][0] m_matrix[2][0] m_matrix[3][0] | |
74 // | m_matrix[0][1] m_matrix[1][1] m_matrix[2][1] m_matrix[3][1] | | 74 // | m_matrix[0][1] m_matrix[1][1] m_matrix[2][1] m_matrix[3][1] | |
75 // | m_matrix[0][2] m_matrix[1][2] m_matrix[2][2] m_matrix[3][2] | | 75 // | m_matrix[0][2] m_matrix[1][2] m_matrix[2][2] m_matrix[3][2] | |
76 // | m_matrix[0][3] m_matrix[1][3] m_matrix[2][3] m_matrix[3][3] | | 76 // | m_matrix[0][3] m_matrix[1][3] m_matrix[2][3] m_matrix[3][3] | |
77 | 77 |
78 typedef double Vector4[4]; | 78 typedef double Vector4[4]; |
79 typedef double Vector3[3]; | 79 typedef double Vector3[3]; |
80 | 80 |
81 const double SMALL_NUMBER = 1.e-8; | 81 const double SmallNumber = 1.e-8; |
82 | 82 |
83 // inverse(original_matrix, inverse_matrix) | 83 // inverse(original_matrix, inverse_matrix) |
84 // | 84 // |
85 // calculate the inverse of a 4x4 matrix | 85 // calculate the inverse of a 4x4 matrix |
86 // | 86 // |
87 // -1 | 87 // -1 |
88 // A = ___1__ adjoint A | 88 // A = ___1__ adjoint A |
89 // det A | 89 // det A |
90 | 90 |
91 // double = determinant2x2(double a, double b, double c, double d) | 91 // double = determinant2x2(double a, double b, double c, double d) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 #endif | 213 #endif |
214 | 214 |
215 // Returns false if the matrix is not invertible | 215 // Returns false if the matrix is not invertible |
216 static bool inverse(const TransformationMatrix::Matrix4& matrix, TransformationM
atrix::Matrix4& result) | 216 static bool inverse(const TransformationMatrix::Matrix4& matrix, TransformationM
atrix::Matrix4& result) |
217 { | 217 { |
218 // Calculate the 4x4 determinant | 218 // Calculate the 4x4 determinant |
219 // If the determinant is zero, | 219 // If the determinant is zero, |
220 // then the inverse matrix is not unique. | 220 // then the inverse matrix is not unique. |
221 double det = determinant4x4(matrix); | 221 double det = determinant4x4(matrix); |
222 | 222 |
223 if (fabs(det) < SMALL_NUMBER) | 223 if (fabs(det) < SmallNumber) |
224 return false; | 224 return false; |
225 | 225 |
226 #if CPU(ARM64) | 226 #if CPU(ARM64) |
227 double rdet = 1 / det; | 227 double rdet = 1 / det; |
228 const double* mat = &(matrix[0][0]); | 228 const double* mat = &(matrix[0][0]); |
229 double* pr = &(result[0][0]); | 229 double* pr = &(result[0][0]); |
230 asm volatile( | 230 asm volatile( |
231 // mat: v16 - v23 | 231 // mat: v16 - v23 |
232 // m11, m12, m13, m14 | 232 // m11, m12, m13, m14 |
233 // m21, m22, m23, m24 | 233 // m21, m22, m23, m24 |
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 } | 1442 } |
1443 } | 1443 } |
1444 | 1444 |
1445 bool TransformationMatrix::isInvertible() const | 1445 bool TransformationMatrix::isInvertible() const |
1446 { | 1446 { |
1447 if (isIdentityOrTranslation()) | 1447 if (isIdentityOrTranslation()) |
1448 return true; | 1448 return true; |
1449 | 1449 |
1450 double det = blink::determinant4x4(m_matrix); | 1450 double det = blink::determinant4x4(m_matrix); |
1451 | 1451 |
1452 if (fabs(det) < SMALL_NUMBER) | 1452 if (fabs(det) < SmallNumber) |
1453 return false; | 1453 return false; |
1454 | 1454 |
1455 return true; | 1455 return true; |
1456 } | 1456 } |
1457 | 1457 |
1458 TransformationMatrix TransformationMatrix::inverse() const | 1458 TransformationMatrix TransformationMatrix::inverse() const |
1459 { | 1459 { |
1460 if (isIdentityOrTranslation()) { | 1460 if (isIdentityOrTranslation()) { |
1461 // identity matrix | 1461 // identity matrix |
1462 if (m_matrix[3][0] == 0 && m_matrix[3][1] == 0 && m_matrix[3][2] == 0) | 1462 if (m_matrix[3][0] == 0 && m_matrix[3][1] == 0 && m_matrix[3][2] == 0) |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 ret.setDouble(2, 2, matrix.m33()); | 1669 ret.setDouble(2, 2, matrix.m33()); |
1670 ret.setDouble(2, 3, matrix.m43()); | 1670 ret.setDouble(2, 3, matrix.m43()); |
1671 ret.setDouble(3, 0, matrix.m14()); | 1671 ret.setDouble(3, 0, matrix.m14()); |
1672 ret.setDouble(3, 1, matrix.m24()); | 1672 ret.setDouble(3, 1, matrix.m24()); |
1673 ret.setDouble(3, 2, matrix.m34()); | 1673 ret.setDouble(3, 2, matrix.m34()); |
1674 ret.setDouble(3, 3, matrix.m44()); | 1674 ret.setDouble(3, 3, matrix.m44()); |
1675 return ret; | 1675 return ret; |
1676 } | 1676 } |
1677 | 1677 |
1678 } | 1678 } |
OLD | NEW |