|
1 /* |
|
2 * Name : Matrix4d.h |
|
3 * Description : |
|
4 * Project : This file is part of OpenMAR, an Open Mobile Augmented Reality browser |
|
5 * Website : http://OpenMAR.org |
|
6 * |
|
7 * Copyright (c) 2010 David Caabeiro |
|
8 * |
|
9 * All rights reserved. This program and the accompanying materials are made available |
|
10 * under the terms of the Eclipse Public License v1.0 which accompanies this |
|
11 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html |
|
12 * |
|
13 */ |
|
14 |
|
15 #ifndef MATRIX4D_H_ |
|
16 #define MATRIX4D_H_ |
|
17 |
|
18 #include "Scalar.h" |
|
19 #include "Vector3d.h" |
|
20 #include "Vector4d.h" |
|
21 |
|
22 /** |
|
23 * @brief Provides needed 4d-matrix functionality and operations |
|
24 */ |
|
25 class Matrix4d |
|
26 { |
|
27 public: |
|
28 Matrix4d(); |
|
29 Matrix4d(Scalar m00, Scalar m01, Scalar m02, Scalar m03, |
|
30 Scalar m10, Scalar m11, Scalar m12, Scalar m13, |
|
31 Scalar m20, Scalar m21, Scalar m22, Scalar m23, |
|
32 Scalar m30, Scalar m31, Scalar m32, Scalar m33); |
|
33 |
|
34 const Vector4d operator*(const Vector4d& v) const; |
|
35 const Matrix4d& operator*(Scalar s); |
|
36 |
|
37 void Load(Scalar m00, Scalar m01, Scalar m02, Scalar m03, |
|
38 Scalar m10, Scalar m11, Scalar m12, Scalar m13, |
|
39 Scalar m20, Scalar m21, Scalar m22, Scalar m23, |
|
40 Scalar m30, Scalar m31, Scalar m32, Scalar m33); |
|
41 |
|
42 const Matrix4d Transpose() const; |
|
43 |
|
44 //private: |
|
45 Scalar m[16]; |
|
46 }; |
|
47 |
|
48 inline Matrix4d::Matrix4d() |
|
49 { |
|
50 m[0] = 1; m[1] = 0; m[2] = 0; m[3] = 0; |
|
51 m[4] = 0; m[5] = 1; m[6] = 0; m[7] = 0; |
|
52 m[8] = 0; m[9] = 0; m[10] = 1; m[11] = 0; |
|
53 m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1; |
|
54 } |
|
55 |
|
56 inline Matrix4d::Matrix4d(Scalar m00, Scalar m01, Scalar m02, Scalar m03, |
|
57 Scalar m10, Scalar m11, Scalar m12, Scalar m13, |
|
58 Scalar m20, Scalar m21, Scalar m22, Scalar m23, |
|
59 Scalar m30, Scalar m31, Scalar m32, Scalar m33) |
|
60 { |
|
61 Load(m00, m01, m02, m03, |
|
62 m10, m11, m12, m13, |
|
63 m20, m21, m22, m23, |
|
64 m30, m31, m32, m33); |
|
65 } |
|
66 |
|
67 inline const Vector4d Matrix4d::operator*(const Vector4d& v) const |
|
68 { |
|
69 return Vector4d( |
|
70 m[0] * v.mX + m[1] * v.mY + m[2] * v.mZ + m[3] * v.mW, |
|
71 m[4] * v.mX + m[5] * v.mY + m[6] * v.mZ + m[7] * v.mW, |
|
72 m[8] * v.mX + m[9] * v.mY + m[10] * v.mZ + m[11] * v.mW, |
|
73 m[12] * v.mX + m[13] * v.mY + m[14] * v.mZ + m[15] * v.mW |
|
74 ); |
|
75 } |
|
76 |
|
77 inline const Matrix4d& Matrix4d::operator*(Scalar s) |
|
78 { |
|
79 for (TInt i = 0; i < 16; ++i) |
|
80 m[i] *= s; |
|
81 |
|
82 return *this; |
|
83 } |
|
84 |
|
85 inline void Matrix4d::Load(Scalar m00, Scalar m01, Scalar m02, Scalar m03, |
|
86 Scalar m10, Scalar m11, Scalar m12, Scalar m13, |
|
87 Scalar m20, Scalar m21, Scalar m22, Scalar m23, |
|
88 Scalar m30, Scalar m31, Scalar m32, Scalar m33) |
|
89 { |
|
90 m[0] = m00; m[1] = m01; m[2] = m02; m[3] = m03; |
|
91 m[4] = m10; m[5] = m11; m[6] = m12; m[7] = m13; |
|
92 m[8] = m20; m[9] = m21; m[10] = m22; m[11] = m23; |
|
93 m[12] = m30; m[13] = m31; m[14] = m32; m[15] = m33; |
|
94 } |
|
95 |
|
96 inline const Matrix4d Matrix4d::Transpose() const |
|
97 { |
|
98 return Matrix4d( |
|
99 m[0], m[4], m[8], m[12], |
|
100 m[1], m[5], m[9], m[13], |
|
101 m[2], m[6], m[10], m[14], |
|
102 m[3], m[7], m[11], m[15] |
|
103 ); |
|
104 } |
|
105 |
|
106 #endif // MATRIX4D_H_ |