1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 |
|
---|
6 | /**
|
---|
7 | @file FMMatrix44.h
|
---|
8 | The file containing the class and global functions for 4x4 matrices.
|
---|
9 | */
|
---|
10 |
|
---|
11 | #ifndef _FM_MATRIX44_H_
|
---|
12 | #define _FM_MATRIX44_H_
|
---|
13 |
|
---|
14 | /**
|
---|
15 | A 4x4 matrix: use to represent 3D transformations.
|
---|
16 |
|
---|
17 | @ingroup FMath
|
---|
18 | */
|
---|
19 | class FCOLLADA_EXPORT FMMatrix44
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | float m[4][4]; /**< The matrix elements stored in a 2D array. */
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Creates a FMMatrix44 from the \c float array.
|
---|
26 | *
|
---|
27 | * The float array stores the elements in the following order: m[0][0],
|
---|
28 | * m[1][0], m[2][0], m[3][0], m[0][1], m[1][1], m[2][1], m[3][1], m[0][2],
|
---|
29 | * m[1][2], m[2][2], m[3][2], m[0][3], m[1][3], m[2][3], m[3][3].
|
---|
30 | *
|
---|
31 | * @param _m The \c float array to create the matrix from.
|
---|
32 | */
|
---|
33 | FMMatrix44(const float* _m);
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Creates an empty FMMatrix44.
|
---|
37 | *
|
---|
38 | * The default values are non deterministic.
|
---|
39 | */
|
---|
40 | #ifndef _DEBUG
|
---|
41 | FMMatrix44() {}
|
---|
42 | #else
|
---|
43 | FMMatrix44() { memset(m, 55, 16 * sizeof(float)); }
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Get this FMMatrix44 as an array of \c floats.
|
---|
48 | *
|
---|
49 | * The array contains the elements in the following order: m[0][0],
|
---|
50 | * m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0],
|
---|
51 | * m[2][1], m[2][2], m[0][3], m[3][0], m[3][1], m[3][2], m[3][3].
|
---|
52 | *
|
---|
53 | * @return The \c float array.
|
---|
54 | */
|
---|
55 | operator float*() { return &m[0][0]; }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Get this FMMatrix44 as an array of \c floats.
|
---|
59 | *
|
---|
60 | * The array contains the elements in the following order: m[0][0],
|
---|
61 | * m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0],
|
---|
62 | * m[2][1], m[2][2], m[0][3], m[3][0], m[3][1], m[3][2], m[3][3].
|
---|
63 | *
|
---|
64 | * @return The \c float array.
|
---|
65 | */
|
---|
66 | operator const float*() const { return &m[0][0]; }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Get a specified row of FMMatrix44 as an array of \c floats.
|
---|
70 | *
|
---|
71 | * @param a The row index, starting at 0, of the row to get.
|
---|
72 | * @return The \c float array of the elements in the specified row.
|
---|
73 | */
|
---|
74 | float* operator[](int a) { return m[a]; }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Get a specified row of FMMatrix44 as an array of \c floats.
|
---|
78 | *
|
---|
79 | * @param a The row index, starting at 0, of the row to get.
|
---|
80 | * @return The \c float array of the elements in the specified row.
|
---|
81 | */
|
---|
82 | const float* operator[](int a) const { return m[a]; }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Assign this FMMatrix44's elements to be the same as that of the given
|
---|
86 | * FMMatrix44.
|
---|
87 | *
|
---|
88 | * @param copy The FMMatrix to copy elements from.
|
---|
89 | * @return This FMMatrix.
|
---|
90 | */
|
---|
91 | FMMatrix44& operator=(const FMMatrix44& copy);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Gets the transposed of this FMMatrix44.
|
---|
95 | *
|
---|
96 | * @return The transposed of this FMMatrix.
|
---|
97 | */
|
---|
98 | FMMatrix44 Transposed() const;
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Gets the inversion of this FMMatrix33.
|
---|
102 | *
|
---|
103 | * @return The inversion of this FMMatrix.
|
---|
104 | */
|
---|
105 | FMMatrix44 Inverted() const;
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Decompose this FMMatrix44 into it's scale, rotation, and translation
|
---|
109 | * components; it also tells whether it is inverted.
|
---|
110 | *
|
---|
111 | * @param Scale The FMVector to place the scale components to.
|
---|
112 | * @param Rotation The FMVector to place the rotation components to.
|
---|
113 | * @param Translation The FMVector to place the translation components to.
|
---|
114 | * @param inverted The value corresponding to if it was inverted (-1.0f or
|
---|
115 | * 1.0f)
|
---|
116 | */
|
---|
117 | void Decompose(FMVector3& Scale, FMVector3& Rotation, FMVector3& Translation, float& inverted) const;
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Transforms the given point by this FMMatrix44.
|
---|
121 | *
|
---|
122 | * @param coordinate The point to transform.
|
---|
123 | * @return The FMVector3 representation of the transformed point.
|
---|
124 | */
|
---|
125 | FMVector3 TransformCoordinate(const FMVector3& coordinate) const;
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Transforms the given vector by this FMMatrix44.
|
---|
129 | *
|
---|
130 | * @param v The vector to transform.
|
---|
131 | * @return The FMVector3 representation of the transformed vector.
|
---|
132 | */
|
---|
133 | FMVector3 TransformVector(const FMVector3& v) const;
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Gets the translation component of this FMMatrix44.
|
---|
137 | *
|
---|
138 | * @return The FMVector3 representation of the translation.
|
---|
139 | */
|
---|
140 | FMVector3 GetTranslation() const;
|
---|
141 |
|
---|
142 | public:
|
---|
143 | static FMMatrix44 Identity; /**< The identity FMMatrix44. */
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Gets the FMMatrix44 representation of a 3D translation.
|
---|
147 | *
|
---|
148 | * The translation in the x, y and z directions correspond to the \a x,
|
---|
149 | * \a y, and \a z components of the FMVector3.
|
---|
150 | *
|
---|
151 | * @param translation The FMVector3 to get the translation components from.
|
---|
152 | * @return The translation FMMatrix44.
|
---|
153 | */
|
---|
154 | static FMMatrix44 TranslationMatrix(const FMVector3& translation);
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Gets the FMMatrix44 representation of a 3D rotation about a given axis
|
---|
158 | * by an angle.
|
---|
159 | *
|
---|
160 | * @param axis The axis of rotation.
|
---|
161 | * @param angle The angle of rotation in radians.
|
---|
162 | * @return The rotation FMMatrix44.
|
---|
163 | */
|
---|
164 | static FMMatrix44 AxisRotationMatrix(const FMVector3& axis, float angle);
|
---|
165 | };
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Matrix multiplication with two FMMatrix44.
|
---|
169 | *
|
---|
170 | * @param m1 The first matrix.
|
---|
171 | * @param m2 The second matrix.
|
---|
172 | * @return The FMMatrix44 representation of the resulting matrix.
|
---|
173 | */
|
---|
174 | FMMatrix44 FCOLLADA_EXPORT operator*(const FMMatrix44& m1, const FMMatrix44& m2);
|
---|
175 |
|
---|
176 | /**
|
---|
177 | Matrix equality comparison function.
|
---|
178 | @param m1 The first matrix.
|
---|
179 | @param m2 The second matrix.
|
---|
180 | @return Whether the given matrices are equal.
|
---|
181 | */
|
---|
182 | bool IsEquivalent(const FMMatrix44& m1, const FMMatrix44& m2);
|
---|
183 |
|
---|
184 | /**
|
---|
185 | Matrix equality operator override.
|
---|
186 | @param m1 The first matrix.
|
---|
187 | @param m2 The second matrix.
|
---|
188 | @return Whether the given matrices are equal.
|
---|
189 | */
|
---|
190 | inline bool operator==(const FMMatrix44& m1, const FMMatrix44& m2) { return IsEquivalent(m1, m2); }
|
---|
191 |
|
---|
192 | /** A dynamically-sized array of 4x4 matrices. */
|
---|
193 | typedef vector<FMMatrix44> FMMatrix44List;
|
---|
194 |
|
---|
195 | #endif // _FM_MATRIX44_H_
|
---|