Subversion Repositories gelsvn

Rev

Rev 2 | Rev 89 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 12
Line 4... Line 4...
4
#include "ExceptionStandard.h"
4
#include "ExceptionStandard.h"
5
#include "CGLA.h"
5
#include "CGLA.h"
6
#include "Vec3f.h"
6
#include "Vec3f.h"
7
#include "ArithSqMatFloat.h"
7
#include "ArithSqMatFloat.h"
8
 
8
 
9
namespace CGLA {
9
namespace CGLA 
-
 
10
{
10
 
11
 
11
	CGLA_DERIVEEXCEPTION(Mat3x3fException)
12
  CGLA_DERIVEEXCEPTION(Mat3x3fException)
12
	CGLA_DERIVEEXCEPTION(Mat3x3fSingular)
13
    CGLA_DERIVEEXCEPTION(Mat3x3fSingular)
13
 
14
 
14
	/** 3 by 3 float matrix.
15
    /** 3 by 3 float matrix.
15
			This class will typically be used for rotation or
16
	This class will typically be used for rotation or
16
			scaling matrices for 3D vectors. */
17
	scaling matrices for 3D vectors. */
17
	template<class V, class M>
18
    template<class V, class M>
18
	class ArithSqMat3x3Float: public ArithSqMatFloat<V, M, 3>
19
    class ArithSqMat3x3Float: public ArithSqMatFloat<V, M, 3>
19
	{
20
    {
20
	public:
21
    public:
21
 
22
 
22
		/// Vector type
23
      /// Vector type
23
		typedef V VectorType;
24
      typedef V VectorType;
24
 
25
 
25
		/// The type of a matrix element
26
      /// The type of a matrix element
26
		typedef typename V::ScalarType ScalarType;
27
      typedef typename V::ScalarType ScalarType;
27
 
28
 
28
	public:
29
    public:
29
 
30
 
30
		/// Construct matrix from 3 Vec3f vectors.
31
      /// Construct matrix from 3 Vec3f vectors.
31
		ArithSqMat3x3Float(V _a, V _b, V _c): 
32
      ArithSqMat3x3Float(V _a, V _b, V _c): 
32
			ArithSqMatFloat<V, M, 3> (_a,_b,_c) {}
33
	ArithSqMatFloat<V, M, 3> (_a,_b,_c) {}
33
  
34
  
34
		/// Construct the 0 matrix
35
      /// Construct the 0 matrix
35
		ArithSqMat3x3Float() {}
36
      ArithSqMat3x3Float() {}
36
 
37
 
37
		/// Construct a matrix from a single scalar value.
38
      /// Construct a matrix from a single scalar value.
38
		explicit ArithSqMat3x3Float(ScalarType a): 
39
      explicit ArithSqMat3x3Float(ScalarType a): 
39
			ArithSqMatFloat<V, M, 3>(a) {}
40
	ArithSqMatFloat<V, M, 3>(a) {}
40
 
41
 
41
	};
42
    };
42
 
43
 
43
	/// Invert 3x3 matrix
44
  /// Invert 3x3 matrix
44
	template<class V, class M>
45
  template<class V, class M>
45
	M invert(const ArithSqMat3x3Float<V,M>&);
46
    M invert(const ArithSqMat3x3Float<V,M>&);
46
 
47
 
47
	/** Compute determinant. There is a more generic function for
48
  /** Compute determinant. There is a more generic function for
48
			computing determinants of square matrices (ArithSqMat). This one
49
      computing determinants of square matrices (ArithSqMat). This one
49
			is faster but works only on Mat3x3f */
50
      is faster but works only on Mat3x3f */
50
	template<class V, class M>
51
  template<class V, class M>
51
	inline 
52
    inline 
52
	typename ArithSqMat3x3Float<V,M>::ScalarType
53
    typename ArithSqMat3x3Float<V,M>::ScalarType
53
 	determinant(const ArithSqMat3x3Float<V,M>& m)
54
    determinant(const ArithSqMat3x3Float<V,M>& m)
54
	{
55
    {
55
		return 
56
      return 
56
			m[0][0]*m[1][1]*m[2][2] +
57
	m[0][0]*m[1][1]*m[2][2] +
57
			m[0][1]*m[1][2]*m[2][0] +
58
	m[0][1]*m[1][2]*m[2][0] +
58
			m[0][2]*m[1][0]*m[2][1] -
59
	m[0][2]*m[1][0]*m[2][1] -
59
			m[0][2]*m[1][1]*m[2][0] -
60
	m[0][2]*m[1][1]*m[2][0] -
60
			m[0][0]*m[1][2]*m[2][1] -
61
	m[0][0]*m[1][2]*m[2][1] -
61
			m[0][1]*m[1][0]*m[2][2] ;
62
	m[0][1]*m[1][0]*m[2][2] ;
62
	}
63
    }
63
 
64
 
64
 
65
 
65
}
66
}
66
#endif
67
#endif
67
 
68