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