595 |
jab |
1 |
/* ----------------------------------------------------------------------- *
|
|
|
2 |
* This file is part of GEL, http://www.imm.dtu.dk/GEL
|
|
|
3 |
* Copyright (C) the authors and DTU Informatics
|
|
|
4 |
* For license and list of authors, see ../../doc/intro.pdf
|
|
|
5 |
* ----------------------------------------------------------------------- */
|
|
|
6 |
|
2 |
bj |
7 |
#include "ArithSqMat3x3Float.h"
|
|
|
8 |
#include "Mat3x3f.h"
|
113 |
jab |
9 |
#include "Mat3x3d.h"
|
2 |
bj |
10 |
|
|
|
11 |
namespace CGLA {
|
|
|
12 |
|
|
|
13 |
template<class V, class M>
|
|
|
14 |
M invert(const ArithSqMat3x3Float<V,M>& _a)
|
|
|
15 |
{
|
692 |
jerf |
16 |
// Based on Cramer's rule (Akenine-Möller et al. 2008, Section A.3.1) and
|
|
|
17 |
// Cedrick Collomb. A tutorial on inverting 3 by 3 matrices with cross products.
|
|
|
18 |
// http://www.emptyloop.com/technotes/
|
2 |
bj |
19 |
|
692 |
jerf |
20 |
M a = transpose(_a);
|
|
|
21 |
V a1a2 = cross(a[1], a[2]);
|
|
|
22 |
float det = dot(a[0], a1a2);
|
|
|
23 |
if(fabs(det) < TINYf)
|
|
|
24 |
throw(Mat3x3fSingular("Tried to invert singular matrix"));
|
|
|
25 |
return M(a1a2, cross(a[2], a[0]), cross(a[0], a[1]))*(1.0f/det);
|
2 |
bj |
26 |
}
|
|
|
27 |
template class ArithSqMat3x3Float<Vec3f,Mat3x3f>;
|
|
|
28 |
template Mat3x3f invert(const ArithSqMat3x3Float<Vec3f,Mat3x3f>&);
|
112 |
jab |
29 |
|
|
|
30 |
template class ArithSqMat3x3Float<Vec3d,Mat3x3d>;
|
|
|
31 |
template Mat3x3d invert(const ArithSqMat3x3Float<Vec3d,Mat3x3d>&);
|
2 |
bj |
32 |
}
|