Subversion Repositories gelsvn

Rev

Rev 12 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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