-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
0 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,104 +384,3 @@ Matrix3 nv::inverse(const Matrix3 & m) { | |
|
||
|
||
|
||
|
||
#if 0 | ||
|
||
// Copyright (C) 1999-2004 Michael Garland. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, provided that the above | ||
// copyright notice(s) and this permission notice appear in all copies of | ||
// the Software and that both the above copyright notice(s) and this | ||
// permission notice appear in supporting documentation. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
// OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
// HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL | ||
// INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING | ||
// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
// NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
// | ||
// Except as contained in this notice, the name of a copyright holder | ||
// shall not be used in advertising or otherwise to promote the sale, use | ||
// or other dealings in this Software without prior written authorization | ||
// of the copyright holder. | ||
|
||
|
||
// Matrix inversion code for 4x4 matrices using Gaussian elimination | ||
// with partial pivoting. This is a specialized version of a | ||
// procedure originally due to Paul Heckbert <[email protected]>. | ||
// | ||
// Returns determinant of A, and B=inverse(A) | ||
// If matrix A is singular, returns 0 and leaves trash in B. | ||
// | ||
#define SWAP(a, b, t) {t = a; a = b; b = t;} | ||
double invert(Mat4& B, const Mat4& m) | ||
{ | ||
Mat4 A = m; | ||
int i, j, k; | ||
double max, t, det, pivot; | ||
|
||
/*---------- forward elimination ----------*/ | ||
|
||
for (i=0; i<4; i++) /* put identity matrix in B */ | ||
for (j=0; j<4; j++) | ||
B(i, j) = (double)(i==j); | ||
|
||
det = 1.0; | ||
for (i=0; i<4; i++) { /* eliminate in column i, below diag */ | ||
max = -1.; | ||
for (k=i; k<4; k++) /* find pivot for column i */ | ||
if (fabs(A(k, i)) > max) { | ||
max = fabs(A(k, i)); | ||
j = k; | ||
} | ||
if (max<=0.) return 0.; /* if no nonzero pivot, PUNT */ | ||
if (j!=i) { /* swap rows i and j */ | ||
for (k=i; k<4; k++) | ||
SWAP(A(i, k), A(j, k), t); | ||
for (k=0; k<4; k++) | ||
SWAP(B(i, k), B(j, k), t); | ||
det = -det; | ||
} | ||
pivot = A(i, i); | ||
det *= pivot; | ||
for (k=i+1; k<4; k++) /* only do elems to right of pivot */ | ||
A(i, k) /= pivot; | ||
for (k=0; k<4; k++) | ||
B(i, k) /= pivot; | ||
/* we know that A(i, i) will be set to 1, so don't bother to do it */ | ||
|
||
for (j=i+1; j<4; j++) { /* eliminate in rows below i */ | ||
t = A(j, i); /* we're gonna zero this guy */ | ||
for (k=i+1; k<4; k++) /* subtract scaled row i from row j */ | ||
A(j, k) -= A(i, k)*t; /* (ignore k<=i, we know they're 0) */ | ||
for (k=0; k<4; k++) | ||
B(j, k) -= B(i, k)*t; | ||
} | ||
} | ||
|
||
/*---------- backward elimination ----------*/ | ||
|
||
for (i=4-1; i>0; i--) { /* eliminate in column i, above diag */ | ||
for (j=0; j<i; j++) { /* eliminate in rows above i */ | ||
t = A(j, i); /* we're gonna zero this guy */ | ||
for (k=0; k<4; k++) /* subtract scaled row i from row j */ | ||
B(j, k) -= B(i, k)*t; | ||
} | ||
} | ||
|
||
return det; | ||
} | ||
|
||
#endif // 0 | ||
|
||
|
||
|