Rev 595 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/* ----------------------------------------------------------------------- *
* This file is part of GEL, http://www.imm.dtu.dk/GEL
* Copyright (C) the authors and DTU Informatics
* For license and list of authors, see ../../doc/intro.pdf
* ----------------------------------------------------------------------- */
#include "ArithSqMat3x3Float.h"
#include "Mat3x3f.h"
#include "Mat3x3d.h"
namespace CGLA {
template<class V, class M>
M invert(const ArithSqMat3x3Float<V,M>& _a)
{
// Based on Cramer's rule (Akenine-Möller et al. 2008, Section A.3.1) and
// Cedrick Collomb. A tutorial on inverting 3 by 3 matrices with cross products.
// http://www.emptyloop.com/technotes/
M a = transpose(_a);
V a1a2 = cross(a[1], a[2]);
float det = dot(a[0], a1a2);
if(fabs(det) < TINYf)
throw(Mat3x3fSingular("Tried to invert singular matrix"));
return M(a1a2, cross(a[2], a[0]), cross(a[0], a[1]))*(1.0f/det);
}
template class ArithSqMat3x3Float<Vec3f,Mat3x3f>;
template Mat3x3f invert(const ArithSqMat3x3Float<Vec3f,Mat3x3f>&);
template class ArithSqMat3x3Float<Vec3d,Mat3x3d>;
template Mat3x3d invert(const ArithSqMat3x3Float<Vec3d,Mat3x3d>&);
}