diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/llmath/m3math.cpp | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmath/m3math.cpp | 91 |
1 files changed, 81 insertions, 10 deletions
diff --git a/linden/indra/llmath/m3math.cpp b/linden/indra/llmath/m3math.cpp index 6741f05..5c3eb08 100644 --- a/linden/indra/llmath/m3math.cpp +++ b/linden/indra/llmath/m3math.cpp | |||
@@ -136,7 +136,7 @@ void LLMatrix3::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) const | |||
136 | 136 | ||
137 | // Clear and Assignment Functions | 137 | // Clear and Assignment Functions |
138 | 138 | ||
139 | const LLMatrix3& LLMatrix3::identity() | 139 | const LLMatrix3& LLMatrix3::setIdentity() |
140 | { | 140 | { |
141 | mMatrix[0][0] = 1.f; | 141 | mMatrix[0][0] = 1.f; |
142 | mMatrix[0][1] = 0.f; | 142 | mMatrix[0][1] = 0.f; |
@@ -152,7 +152,23 @@ const LLMatrix3& LLMatrix3::identity() | |||
152 | return (*this); | 152 | return (*this); |
153 | } | 153 | } |
154 | 154 | ||
155 | const LLMatrix3& LLMatrix3::zero() | 155 | const LLMatrix3& LLMatrix3::clear() |
156 | { | ||
157 | mMatrix[0][0] = 0.f; | ||
158 | mMatrix[0][1] = 0.f; | ||
159 | mMatrix[0][2] = 0.f; | ||
160 | |||
161 | mMatrix[1][0] = 0.f; | ||
162 | mMatrix[1][1] = 0.f; | ||
163 | mMatrix[1][2] = 0.f; | ||
164 | |||
165 | mMatrix[2][0] = 0.f; | ||
166 | mMatrix[2][1] = 0.f; | ||
167 | mMatrix[2][2] = 0.f; | ||
168 | return (*this); | ||
169 | } | ||
170 | |||
171 | const LLMatrix3& LLMatrix3::setZero() | ||
156 | { | 172 | { |
157 | mMatrix[0][0] = 0.f; | 173 | mMatrix[0][0] = 0.f; |
158 | mMatrix[0][1] = 0.f; | 174 | mMatrix[0][1] = 0.f; |
@@ -190,15 +206,26 @@ F32 LLMatrix3::determinant() const | |||
190 | mMatrix[0][2] * (mMatrix[1][0] * mMatrix[2][1] - mMatrix[1][1] * mMatrix[2][0]); | 206 | mMatrix[0][2] * (mMatrix[1][0] * mMatrix[2][1] - mMatrix[1][1] * mMatrix[2][0]); |
191 | } | 207 | } |
192 | 208 | ||
193 | // This is identical to the transMat3() method because we assume a rotation matrix | 209 | // inverts this matrix |
194 | const LLMatrix3& LLMatrix3::invert() | 210 | void LLMatrix3::invert() |
195 | { | 211 | { |
196 | // transpose the matrix | 212 | // fails silently if determinant is zero too small |
197 | F32 temp; | 213 | F32 det = determinant(); |
198 | temp = mMatrix[VX][VY]; mMatrix[VX][VY] = mMatrix[VY][VX]; mMatrix[VY][VX] = temp; | 214 | const F32 VERY_SMALL_DETERMINANT = 0.000001f; |
199 | temp = mMatrix[VX][VZ]; mMatrix[VX][VZ] = mMatrix[VZ][VX]; mMatrix[VZ][VX] = temp; | 215 | if (fabs(det) > VERY_SMALL_DETERMINANT) |
200 | temp = mMatrix[VY][VZ]; mMatrix[VY][VZ] = mMatrix[VZ][VY]; mMatrix[VZ][VY] = temp; | 216 | { |
201 | return *this; | 217 | // invertiable |
218 | LLMatrix3 t(*this); | ||
219 | mMatrix[VX][VX] = ( t.mMatrix[VY][VY] * t.mMatrix[VZ][VZ] - t.mMatrix[VY][VZ] * t.mMatrix[VZ][VY] ) / det; | ||
220 | mMatrix[VY][VX] = ( t.mMatrix[VY][VZ] * t.mMatrix[VZ][VX] - t.mMatrix[VY][VX] * t.mMatrix[VZ][VZ] ) / det; | ||
221 | mMatrix[VZ][VX] = ( t.mMatrix[VY][VX] * t.mMatrix[VZ][VY] - t.mMatrix[VY][VY] * t.mMatrix[VZ][VX] ) / det; | ||
222 | mMatrix[VX][VY] = ( t.mMatrix[VZ][VY] * t.mMatrix[VX][VZ] - t.mMatrix[VZ][VZ] * t.mMatrix[VX][VY] ) / det; | ||
223 | mMatrix[VY][VY] = ( t.mMatrix[VZ][VZ] * t.mMatrix[VX][VX] - t.mMatrix[VZ][VX] * t.mMatrix[VX][VZ] ) / det; | ||
224 | mMatrix[VZ][VY] = ( t.mMatrix[VZ][VX] * t.mMatrix[VX][VY] - t.mMatrix[VZ][VY] * t.mMatrix[VX][VX] ) / det; | ||
225 | mMatrix[VX][VZ] = ( t.mMatrix[VX][VY] * t.mMatrix[VY][VZ] - t.mMatrix[VX][VZ] * t.mMatrix[VY][VY] ) / det; | ||
226 | mMatrix[VY][VZ] = ( t.mMatrix[VX][VZ] * t.mMatrix[VY][VX] - t.mMatrix[VX][VX] * t.mMatrix[VY][VZ] ) / det; | ||
227 | mMatrix[VZ][VZ] = ( t.mMatrix[VX][VX] * t.mMatrix[VY][VY] - t.mMatrix[VX][VY] * t.mMatrix[VY][VX] ) / det; | ||
228 | } | ||
202 | } | 229 | } |
203 | 230 | ||
204 | // does not assume a rotation matrix, and does not divide by determinant, assuming results will be renormalized | 231 | // does not assume a rotation matrix, and does not divide by determinant, assuming results will be renormalized |
@@ -351,6 +378,27 @@ const LLMatrix3& LLMatrix3::setRows(const LLVector3 &fwd, const LLVector3 &left, | |||
351 | return *this; | 378 | return *this; |
352 | } | 379 | } |
353 | 380 | ||
381 | const LLMatrix3& LLMatrix3::setRow( U32 rowIndex, const LLVector3& row ) | ||
382 | { | ||
383 | llassert( rowIndex >= 0 && rowIndex < NUM_VALUES_IN_MAT3 ); | ||
384 | |||
385 | mMatrix[rowIndex][0] = row[0]; | ||
386 | mMatrix[rowIndex][1] = row[1]; | ||
387 | mMatrix[rowIndex][2] = row[2]; | ||
388 | |||
389 | return *this; | ||
390 | } | ||
391 | |||
392 | const LLMatrix3& LLMatrix3::setCol( U32 colIndex, const LLVector3& col ) | ||
393 | { | ||
394 | llassert( colIndex >= 0 && colIndex < NUM_VALUES_IN_MAT3 ); | ||
395 | |||
396 | mMatrix[0][colIndex] = col[0]; | ||
397 | mMatrix[1][colIndex] = col[1]; | ||
398 | mMatrix[2][colIndex] = col[2]; | ||
399 | |||
400 | return *this; | ||
401 | } | ||
354 | 402 | ||
355 | // Rotate exisitng mMatrix | 403 | // Rotate exisitng mMatrix |
356 | const LLMatrix3& LLMatrix3::rotate(const F32 angle, const F32 x, const F32 y, const F32 z) | 404 | const LLMatrix3& LLMatrix3::rotate(const F32 angle, const F32 x, const F32 y, const F32 z) |
@@ -384,6 +432,16 @@ const LLMatrix3& LLMatrix3::rotate(const LLQuaternion &q) | |||
384 | return *this; | 432 | return *this; |
385 | } | 433 | } |
386 | 434 | ||
435 | void LLMatrix3::add(const LLMatrix3& other_matrix) | ||
436 | { | ||
437 | for (S32 i = 0; i < 3; ++i) | ||
438 | { | ||
439 | for (S32 j = 0; j < 3; ++j) | ||
440 | { | ||
441 | mMatrix[i][j] += other_matrix.mMatrix[i][j]; | ||
442 | } | ||
443 | } | ||
444 | } | ||
387 | 445 | ||
388 | LLVector3 LLMatrix3::getFwdRow() const | 446 | LLVector3 LLMatrix3::getFwdRow() const |
389 | { | 447 | { |
@@ -536,6 +594,19 @@ const LLMatrix3& operator*=(LLMatrix3 &a, const LLMatrix3 &b) | |||
536 | return a; | 594 | return a; |
537 | } | 595 | } |
538 | 596 | ||
597 | const LLMatrix3& operator*=(LLMatrix3 &a, F32 scalar ) | ||
598 | { | ||
599 | for( U32 i = 0; i < NUM_VALUES_IN_MAT3; ++i ) | ||
600 | { | ||
601 | for( U32 j = 0; j < NUM_VALUES_IN_MAT3; ++j ) | ||
602 | { | ||
603 | a.mMatrix[i][j] *= scalar; | ||
604 | } | ||
605 | } | ||
606 | |||
607 | return a; | ||
608 | } | ||
609 | |||
539 | std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a) | 610 | std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a) |
540 | { | 611 | { |
541 | s << "{ " | 612 | s << "{ " |