Subversion Repositories gelsvn

Rev

Rev 501 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
7
/** @file Mat4x4d.h
8
 * @brief 4x4 double matrix class
9
 */
10
 
5 jab 11
#ifndef __CGLA_MAT4X4D_H__
12
#define __CGLA_MAT4X4D_H__
13
 
14
#include "ExceptionStandard.h"
15
#include "CGLA.h"
16
#include "Vec3d.h"
17
#include "Vec3Hf.h"
18
#include "Vec4d.h"
19
#include "ArithSqMat4x4Float.h"
20
 
21
 
22
namespace CGLA {
23
 
24
 
89 jab 25
  /** \brief 4x4 double matrix.
26
 
12 jab 27
      This class is useful for transformations such as perspective projections 
28
      or translation where 3x3 matrices do not suffice. */
29
  class Mat4x4d: public ArithSqMat4x4Float<Vec4d, Mat4x4d>
30
    {
31
    public:
5 jab 32
 
12 jab 33
      /// Construct a Mat4x4d from four Vec4d vectors
34
      Mat4x4d(Vec4d _a, Vec4d _b, Vec4d _c, Vec4d _d): 
35
	ArithSqMat4x4Float<Vec4d, Mat4x4d> (_a,_b,_c,_d) {}
5 jab 36
 
12 jab 37
      /// Construct the nan matrix
38
      Mat4x4d() {}
5 jab 39
 
12 jab 40
      /// Construct a matrix with identical elements.
43 jrf 41
      explicit Mat4x4d(double a): ArithSqMat4x4Float<Vec4d, Mat4x4d> (a) {}
12 jab 42
    };
10 jab 43
 
12 jab 44
  /// Create a rotation _matrix. Rotates about one of the major axes.
45
  Mat4x4d rotation_Mat4x4d(CGLA::Axis axis, float angle);
5 jab 46
 
12 jab 47
  /// Create a translation matrix
48
  Mat4x4d translation_Mat4x4d(const Vec3d&);
5 jab 49
 
12 jab 50
  /// Create a scaling matrix.
51
  Mat4x4d scaling_Mat4x4d(const Vec3d&);
5 jab 52
 
12 jab 53
  /// Create an identity matrix.
54
  inline Mat4x4d identity_Mat4x4d()
55
    {
501 jrf 56
      return Mat4x4d(Vec4d(1.0,0.0,0.0,0.0), 
57
		     Vec4d(0.0,1.0,0.0,0.0), 
58
		     Vec4d(0.0,0.0,1.0,0.0), 
59
		     Vec4d(0.0,0.0,0.0,1.0));
12 jab 60
    }
50 jrf 61
 
62
  /** Compute inverse assuming that the upper-left 3x3 sub-matrix is
63
      orthonormal (which is the case if the transformation is only
64
      a concatenation of rotations and translations).
65
  */
66
  inline Mat4x4d invert_ortho(const Mat4x4d& m)
67
  {
68
    Vec3d rx(m[0][0], m[1][0], m[2][0]);
69
    Vec3d ry(m[0][1], m[1][1], m[2][1]);
70
    Vec3d rz(m[0][2], m[1][2], m[2][2]);
71
    Vec3d t(m[0][3], m[1][3], m[2][3]);
72
 
73
    return Mat4x4d(Vec4d(rx, -dot(t, rx)),
74
		   Vec4d(ry, -dot(t, ry)),
75
		   Vec4d(rz, -dot(t, rz)),
76
		   Vec4d(0.0, 0.0, 0.0, 1.0));
77
  }   
5 jab 78
}
79
#endif
80
 
81
 
82
 
83
 
84
 
85
 
86