2 |
bj |
1 |
#ifndef __CGLA_ARITHSQMAT4X4FLOAT_H
|
|
|
2 |
#define __CGLA_ARITHSQMAT4X4FLOAT_H
|
|
|
3 |
|
|
|
4 |
#include "ExceptionStandard.h"
|
|
|
5 |
#include "CGLA.h"
|
|
|
6 |
#include "Vec3f.h"
|
|
|
7 |
#include "Vec3Hf.h"
|
|
|
8 |
#include "Vec4f.h"
|
|
|
9 |
#include "ArithSqMatFloat.h"
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
namespace CGLA {
|
|
|
13 |
|
|
|
14 |
CGLA_DERIVEEXCEPTION(Mat4x4fException)
|
|
|
15 |
CGLA_DERIVEEXCEPTION(Mat4x4fNotAffine)
|
|
|
16 |
CGLA_DERIVEEXCEPTION(Mat4x4fSingular)
|
|
|
17 |
|
|
|
18 |
/** Four by four float matrix.
|
|
|
19 |
This class is useful for transformations such as perspective projections
|
|
|
20 |
or translation where 3x3 matrices do not suffice. */
|
|
|
21 |
template<class V, class M>
|
|
|
22 |
class ArithSqMat4x4Float: public ArithSqMatFloat<V, M, 4>
|
|
|
23 |
{
|
|
|
24 |
public:
|
|
|
25 |
|
|
|
26 |
/// Construct a Mat4x4f from four V vectors
|
|
|
27 |
ArithSqMat4x4Float(V a, V b, V c, V d):
|
|
|
28 |
ArithSqMatFloat<V, M, 4> (a,b,c,d) {}
|
|
|
29 |
|
|
|
30 |
/// Construct the 0 matrix
|
|
|
31 |
ArithSqMat4x4Float() {}
|
|
|
32 |
|
|
|
33 |
/// Construct from a pointed to array of 16 floats.
|
|
|
34 |
ArithSqMat4x4Float(const float* sa): ArithSqMatFloat<V, M, 4> (sa) {}
|
|
|
35 |
|
|
|
36 |
/** Multiply vector onto matrix. Here the fourth coordinate
|
|
|
37 |
is se to 0. This removes any translation from the matrix.
|
|
|
38 |
Useful if one wants to transform a vector which does not
|
|
|
39 |
represent a point but a direction. Note that this is not
|
|
|
40 |
correct for transforming normal vectors if the matric
|
|
|
41 |
contains anisotropic scaling. */
|
|
|
42 |
template<class T, class VecT>
|
|
|
43 |
const VecT mul_3D_vector(const ArithVec3Float<T,VecT>& v_in) const
|
|
|
44 |
{
|
|
|
45 |
V v_out = (*this) * V(v_in[0],v_in[1],v_in[2],0);
|
|
|
46 |
return VecT(v_out[0],v_out[1],v_out[2]);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/** Multiply 3D point onto matrix. Here the fourth coordinate
|
|
|
50 |
becomes 1 to ensure that the point is translated. Note that
|
|
|
51 |
the vector is converted back into a Vec3f without any
|
|
|
52 |
division by w. This is deliberate: Typically, w=1 except
|
|
|
53 |
for projections. If we are doing projection, we can use
|
|
|
54 |
project_3D_point instead */
|
|
|
55 |
template<class T, class VecT>
|
|
|
56 |
const VecT mul_3D_point(const ArithVec3Float<T,VecT> & v_in) const
|
|
|
57 |
{
|
|
|
58 |
V v_out = (*this) * V(v_in[0],v_in[1],v_in[2],1);
|
|
|
59 |
return VecT(v_out[0],v_out[1],v_out[2]);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/** Multiply 3D point onto matrix. We set w=1 before
|
|
|
63 |
multiplication and divide by w after multiplication. */
|
|
|
64 |
template<class T, class VecT>
|
|
|
65 |
const VecT project_3D_point(const ArithVec3Float<T,VecT>& v_in) const
|
|
|
66 |
{
|
|
|
67 |
V v_out = (*this) * V(v_in[0],v_in[1],v_in[2],1);
|
|
|
68 |
v_out.de_homogenize();
|
|
|
69 |
return VecT(v_out[0],v_out[1],v_out[2]);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
};
|
|
|
73 |
|
|
|
74 |
/** Compute the adjoint of a matrix. This is the matrix where each
|
|
|
75 |
entry is the subdeterminant of 'in' where the row and column of
|
|
|
76 |
the element is removed. Use mostly to compute the inverse */
|
|
|
77 |
template<class V, class M>
|
|
|
78 |
M adjoint(const ArithSqMat4x4Float<V,M>&);
|
|
|
79 |
|
|
|
80 |
/** Compute the determinant of a 4x4f matrix. */
|
|
|
81 |
template<class V, class M>
|
|
|
82 |
double
|
|
|
83 |
determinant(const ArithSqMat4x4Float<V,M>&);
|
|
|
84 |
|
|
|
85 |
/// Compute the inverse matrix of a Mat4x4f.
|
|
|
86 |
template<class V, class M>
|
|
|
87 |
M invert(const ArithSqMat4x4Float<V,M>&);
|
|
|
88 |
|
|
|
89 |
/// Compute the inverse matrix of a Mat4x4f that is affine
|
|
|
90 |
template<class V, class M>
|
|
|
91 |
M invert_affine(const ArithSqMat4x4Float<V,M>&);
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
#endif
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|