Subversion Repositories gelsvn

Rev

Rev 595 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 595 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
/** @file ArithSqMat3x3Float.h
7
/** @file ArithSqMat3x3Float.h
8
 * @brief Abstract 3x3 floating point matrix class
8
 * @brief Abstract 3x3 floating point matrix class
9
 */
9
 */
10
 
10
 
11
#ifndef __CGLA_ARITHSQMAT3X3FLOAT_H__
11
#ifndef __CGLA_ARITHSQMAT3X3FLOAT_H__
12
#define __CGLA_ARITHSQMAT3X3FLOAT_H__
12
#define __CGLA_ARITHSQMAT3X3FLOAT_H__
13
 
13
 
14
#include "ExceptionStandard.h"
14
#include "ExceptionStandard.h"
15
#include "CGLA.h"
15
#include "CGLA.h"
16
#include "Vec3f.h"
16
#include "Vec3f.h"
17
#include "ArithSqMatFloat.h"
17
#include "ArithSqMatFloat.h"
18
 
18
 
19
namespace CGLA 
19
namespace CGLA 
20
{
20
{
21
 
21
 
22
  CGLA_DERIVEEXCEPTION(Mat3x3fException)
22
  CGLA_DERIVEEXCEPTION(Mat3x3fException)
23
    CGLA_DERIVEEXCEPTION(Mat3x3fSingular)
23
    CGLA_DERIVEEXCEPTION(Mat3x3fSingular)
24
 
24
 
25
    /** \brief 3 by 3 float matrix template.
25
    /** \brief 3 by 3 float matrix template.
26
				
26
				
27
		This class template will typically be used for rotation or
27
		This class template will typically be used for rotation or
28
		scaling matrices for 3D vectors. */
28
		scaling matrices for 3D vectors. */
29
    template<class V, class M>
29
    template<class V, class M>
30
    class ArithSqMat3x3Float: public ArithSqMatFloat<V, M, 3>
30
    class ArithSqMat3x3Float: public ArithSqMatFloat<V, M, 3>
31
    {
31
    {
32
    public:
32
    public:
33
 
33
 
34
      /// Vector type
34
      /// Vector type
35
      typedef V VectorType;
35
      typedef V VectorType;
36
 
36
 
37
      /// The type of a matrix element
37
      /// The type of a matrix element
38
      typedef typename V::ScalarType ScalarType;
38
      typedef typename V::ScalarType ScalarType;
39
 
39
 
40
    public:
40
    public:
41
 
41
 
42
      /// Construct matrix from 3 Vec3f vectors.
42
      /// Construct matrix from 3 Vec3f vectors.
43
      ArithSqMat3x3Float(V _a, V _b, V _c): 
43
      ArithSqMat3x3Float(V _a, V _b, V _c): 
44
	ArithSqMatFloat<V, M, 3> (_a,_b,_c) {}
44
	ArithSqMatFloat<V, M, 3> (_a,_b,_c) {}
45
  
45
  
46
      /// Construct the 0 matrix
46
      /// Construct the 0 matrix
47
      ArithSqMat3x3Float() {}
47
      ArithSqMat3x3Float() {}
48
 
48
 
49
      /// Construct a matrix from a single scalar value.
49
      /// Construct a matrix from a single scalar value.
50
      explicit ArithSqMat3x3Float(ScalarType a): 
50
      explicit ArithSqMat3x3Float(ScalarType a): 
51
	ArithSqMatFloat<V, M, 3>(a) {}
51
	ArithSqMatFloat<V, M, 3>(a) {}
52
 
52
 
53
    };
53
    };
54
 
54
 
55
  /// Invert 3x3 matrix
55
  /// Invert 3x3 matrix
56
  template<class V, class M>
56
  template<class V, class M>
57
    M invert(const ArithSqMat3x3Float<V,M>&);
57
    M invert(const ArithSqMat3x3Float<V,M>&);
58
 
58
 
59
  /** Compute determinant. There is a more generic function for
59
  /** Compute determinant. There is a more generic function for
60
      computing determinants of square matrices (ArithSqMat). This one
60
      computing determinants of square matrices (ArithSqMat). This one
61
      is faster but works only on Mat3x3f */
61
      is faster but works only on Mat3x3f */
62
  template<class V, class M>
62
  template<class V, class M>
63
    inline 
63
    inline 
64
    typename ArithSqMat3x3Float<V,M>::ScalarType
64
    typename ArithSqMat3x3Float<V,M>::ScalarType
65
    determinant(const ArithSqMat3x3Float<V,M>& m)
65
    determinant(const ArithSqMat3x3Float<V,M>& m)
66
    {
66
    {
67
      return 
67
      return 
68
	m[0][0]*m[1][1]*m[2][2] +
68
	m[0][0]*m[1][1]*m[2][2] +
69
	m[0][1]*m[1][2]*m[2][0] +
69
	m[0][1]*m[1][2]*m[2][0] +
70
	m[0][2]*m[1][0]*m[2][1] -
70
	m[0][2]*m[1][0]*m[2][1] -
71
	m[0][2]*m[1][1]*m[2][0] -
71
	m[0][2]*m[1][1]*m[2][0] -
72
	m[0][0]*m[1][2]*m[2][1] -
72
	m[0][0]*m[1][2]*m[2][1] -
73
	m[0][1]*m[1][0]*m[2][2] ;
73
	m[0][1]*m[1][0]*m[2][2] ;
74
    }
74
    }
75
 
75
 
76
 
76
 
77
}
77
}
78
#endif
78
#endif
79
 
79
 
80
 
80
 
81
 
81
 
82
 
82
 
83
 
83
 
84
 
84
 
85
 
85
 
86
 
86