TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Matrix4.h
Go to the documentation of this file.
1 
12 #ifndef G3D_Matrix4_h
13 #define G3D_Matrix4_h
14 
15 #ifdef _MSC_VER
16 // Disable conditional expression is constant, which occurs incorrectly on inlined functions
17 # pragma warning (push)
18 # pragma warning( disable : 4127 )
19 #endif
20 
21 #include "G3D/platform.h"
22 #include "G3D/debugAssert.h"
23 #include "G3D/Matrix3.h"
24 #include "G3D/Vector3.h"
25 
26 namespace G3D {
27 
28 class Any;
29 class Matrix2;
30 
36 class Matrix4 {
37 private:
38 
39  float elt[4][4];
40 
45  float subDeterminant(int excludeRow, int excludeCol) const;
46 
47  // Hidden operators
48  bool operator<(const Matrix4&) const;
49  bool operator>(const Matrix4&) const;
50  bool operator<=(const Matrix4&) const;
51  bool operator>=(const Matrix4&) const;
52 
53 public:
54 
65  explicit Matrix4(const Any& any);
66 
67  Any toAny() const;
68 
69  Matrix4(
70  float r1c1, float r1c2, float r1c3, float r1c4,
71  float r2c1, float r2c2, float r2c3, float r2c4,
72  float r3c1, float r3c2, float r3c3, float r3c4,
73  float r4c1, float r4c2, float r4c3, float r4c4);
74 
78  Matrix4(const float* init);
79 
83  Matrix4(const class Matrix3& upper3x3, const class Vector3& lastCol = Vector3::zero());
84 
85  Matrix4(const class CoordinateFrame& c);
86 
87  Matrix4(const double* init);
88 
90  Matrix4();
91 
92  static Matrix4 diagonal(float e00, float e11, float e22, float e33) {
93  return Matrix4(e00, 0, 0, 0,
94  0, e11, 0, 0,
95  0, 0, e22, 0,
96  0, 0, 0, e33);
97  }
98 
103 
104  // Special values.
105  // Intentionally not inlined: see Matrix3::identity() for details.
106  static const Matrix4& identity();
107  static const Matrix4& zero();
108 
117  (double& left,
118  double& right,
119  double& bottom,
120  double& top,
121  double& nearval,
122  double& farval,
123  float updirection = -1.0f) const;
124 
125  inline float* operator[](int r) {
126  debugAssert(r >= 0);
127  debugAssert(r < 4);
128  return (float*)&elt[r];
129  }
130 
131  inline const float* operator[](int r) const {
132  debugAssert(r >= 0);
133  debugAssert(r < 4);
134  return (const float*)&elt[r];
135  }
136 
138  inline operator float* () {
139  return (float*)&elt[0][0];
140  }
141 
142  inline operator const float* () const {
143  return (const float*)&elt[0][0];
144  }
145 
146  Matrix4 operator*(const Matrix4& other) const;
147  Matrix4 operator+(const Matrix4& other) const {
148  Matrix4 result;
149  for (int r = 0; r < 4; ++r) {
150  for (int c = 0; c < 4; ++c) {
151  result.elt[r][c] = elt[r][c] + other.elt[r][c];
152  }
153  }
154  return result;
155  }
156 
157  class Matrix3 upper3x3() const;
158 
159  class Matrix2 upper2x2() const;
160 
162  class Vector3 homoMul(const class Vector3& v, float w) const;
163 
173  float left,
174  float right,
175  float bottom,
176  float top,
177  float nearval,
178  float farval,
179  float upDirection = -1.0f);
180 
185  const class Rect2D& rect,
186  float nearval,
187  float farval,
188  float upDirection = -1.0f);
189 
197  double left,
198  double right,
199  double bottom,
200  double top,
201  double nearval,
202  double farval,
203  float upDirection = -1.0f);
204 
205  void setRow(int r, const class Vector4& v);
206  void setColumn(int c, const Vector4& v);
207 
208  const Vector4& row(int r) const;
209  Vector4 column(int c) const;
210 
211  Matrix4 operator*(const float s) const;
212  Vector4 operator*(const Vector4& vector) const;
213 
214  Matrix4 transpose() const;
215 
216  bool operator!=(const Matrix4& other) const;
217  bool operator==(const Matrix4& other) const;
218 
219  float determinant() const;
220  Matrix4 inverse() const;
221 
229  Matrix4 adjoint() const;
230  Matrix4 cofactor() const;
231 
233  void serialize(class BinaryOutput& b) const;
234  void deserialize(class BinaryInput& b);
235 
236  std::string toString() const;
237 
239  inline static Matrix4 scale(const Vector3& v) {
240  return Matrix4(v.x, 0, 0, 0,
241  0, v.y, 0, 0,
242  0, 0, v.z, 0,
243  0, 0, 0, 1);
244  }
245 
247  inline static Matrix4 scale(float x, float y, float z) {
248  return scale(Vector3(x, y, z));
249  }
250 
252  inline static Matrix4 scale(float s) {
253  return scale(s,s,s);
254  }
255 
257  inline static Matrix4 translation(const Vector3& v) {
258  return Matrix4(Matrix3::identity(), v);
259  }
260 
261  inline static Matrix4 translation(float x, float y, float z) {
262  return Matrix4(Matrix3::identity(), Vector3(x, y, z));
263  }
264 
266  inline static Matrix4 yawDegrees(float deg) {
268  }
269 
270  inline static Matrix4 pitchDegrees(float deg) {
272  }
273 
274  inline static Matrix4 rollDegrees(float deg) {
276  }
277 };
278 
279 
282 private:
283 
284  double elt[4][4];
285 
286 public:
287 
288  explicit Matrix4float64(const Matrix4& m);
289 
291  Matrix4float64();
292 
294  double r1c1, double r1c2, double r1c3, double r1c4,
295  double r2c1, double r2c2, double r2c3, double r2c4,
296  double r3c1, double r3c2, double r3c3, double r3c4,
297  double r4c1, double r4c2, double r4c3, double r4c4);
298 
299  // Special values.
300  // Intentionally not inlined: see Matrix3::identity() for details.
301  static const Matrix4float64& identity();
302 
303  static const Matrix4float64& zero();
304 
305  bool operator!=(const Matrix4float64& other) const;
306 
307  bool operator==(const Matrix4float64& other) const;
308 
309  Vector4 operator*(const Vector4& vector) const;
310 
312  double left,
313  double right,
314  double bottom,
315  double top,
316  double nearval,
317  double farval,
318  float upDirection = -1.0f);
319 
320  inline double* operator[](int r) {
321  debugAssert(r >= 0);
322  debugAssert(r < 4);
323  return (double*)&elt[r];
324  }
325 
326  inline const double* operator[](int r) const {
327  debugAssert(r >= 0);
328  debugAssert(r < 4);
329  return (const double*)&elt[r];
330  }
331 
332  inline operator double* () {
333  return (double*)&elt[0][0];
334  }
335 
336  inline operator const double* () const {
337  return (const double*)&elt[0][0];
338  }
339 };
340 
341 
342 } // namespace
343 
344 #ifdef _MSC_VER
345 # pragma warning (pop)
346 #endif
347 
348 #endif
float subDeterminant(int excludeRow, int excludeCol) const
Definition: Matrix4.cpp:469
static const Matrix4 & zero()
Definition: Matrix4.cpp:97
Definition: Matrix2.h:10
bool operator!=(const Matrix4 &other) const
Definition: Matrix4.cpp:398
static Matrix4 diagonal(float e00, float e11, float e22, float e33)
Definition: Matrix4.h:92
float * operator[](int r)
Definition: Matrix4.h:125
float x
Definition: Vector3.h:62
static Matrix4 scale(float s)
Definition: Matrix4.h:252
bool operator!=(const Matrix4float64 &other) const
Definition: Matrix4.cpp:599
static Matrix4 scale(const Vector3 &v)
Definition: Matrix4.h:239
Vector4 column(int c) const
Definition: Matrix4.cpp:333
bool operator>(const Matrix4 &) const
Definition: BinaryInput.h:69
A rigid body RT (rotation-translation) transformation.
Definition: CoordinateFrame.h:59
void setColumn(int c, const Vector4 &v)
Definition: Matrix4.cpp:321
static Matrix4 perspectiveProjection(double left, double right, double bottom, double top, double nearval, double farval, float upDirection=-1.0f)
Definition: Matrix4.cpp:189
static Matrix4 translation(const Vector3 &v)
Definition: Matrix4.h:257
const double * operator[](int r) const
Definition: Matrix4.h:326
Matrix4 transpose() const
Definition: Matrix4.cpp:386
Matrix4 cofactor() const
Definition: Matrix4.cpp:449
static const Matrix4float64 & zero()
Definition: Matrix4.cpp:593
Definition: AABox.h:25
bool any(float x)
Definition: g3dmath.h:424
static Matrix4 rollDegrees(float deg)
Definition: Matrix4.h:274
double * operator[](int r)
Definition: Matrix4.h:320
bool operator==(const Matrix4float64 &other) const
Definition: Matrix4.cpp:604
const float * operator[](int r) const
Definition: Matrix4.h:131
static Matrix4 yawDegrees(float deg)
Definition: Matrix4.h:266
void getPerspectiveProjectionParameters(double &left, double &right, double &bottom, double &top, double &nearval, double &farval, float updirection=-1.0f) const
Definition: Matrix4.cpp:226
Definition: Rect2D.h:40
float y
Definition: Vector3.h:62
static Matrix3 fromAxisAngle(const Vector3 &rkAxis, float fRadians)
Definition: Matrix3.cpp:1346
Any toAny() const
Definition: Matrix4.cpp:75
Definition: Vector3.h:58
bool operator<(const Matrix4 &) const
static const Vector3 & unitX()
Definition: Vector3.cpp:121
static const Vector3 & zero()
Definition: Vector3.cpp:119
Definition: Matrix4.h:36
Easy loading and saving of human-readable configuration files.
Definition: Any.h:184
void deserialize(class BinaryInput &b)
Definition: Matrix4.cpp:533
Matrix4 operator*(const Matrix4 &other) const
Definition: Matrix4.cpp:342
class Matrix2 upper2x2() const
Definition: Matrix4.cpp:141
static const Matrix4 & identity()
Definition: Matrix4.cpp:87
double toRadians(double deg)
Definition: g3dmath.h:798
static const Vector3 & unitY()
Definition: Vector3.cpp:122
#define debugAssert(exp)
Definition: debugAssert.h:160
class Vector3 homoMul(const class Vector3 &v, float w) const
Definition: Matrix4.cpp:368
G3D::int16 z
Definition: Vector3int16.h:46
void serialize(class BinaryOutput &b) const
Definition: Matrix4.cpp:524
bool operator==(const Matrix4 &other) const
Definition: Matrix4.cpp:403
Definition: Matrix4.h:281
G3D::int16 y
Definition: Vector2int16.h:38
bool operator<=(const Matrix4 &) const
Definition: Vector4.h:39
const Vector4 & row(int r) const
Definition: Matrix4.cpp:328
static Matrix4 translation(float x, float y, float z)
Definition: Matrix4.h:261
void setRow(int r, const class Vector4 &v)
Definition: Matrix4.cpp:314
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
static const Vector3 & unitZ()
Definition: Vector3.cpp:123
Matrix4 operator+(const Matrix4 &other) const
Definition: Matrix4.h:147
class Matrix3 upper3x3() const
Definition: Matrix4.cpp:134
Definition: Matrix3.h:37
Vector4 operator*(const Vector4 &vector) const
Definition: Matrix4.cpp:625
std::string toString() const
Definition: Matrix4.cpp:541
Matrix4()
Definition: Matrix4.cpp:305
float z
Definition: Vector3.h:62
static Matrix4 orthogonalProjection(float left, float right, float bottom, float top, float nearval, float farval, float upDirection=-1.0f)
Definition: Matrix4.cpp:156
Definition: BinaryOutput.h:52
float elt[4][4]
Definition: Matrix4.h:39
bool operator>=(const Matrix4 &) const
static Matrix4 pitchDegrees(float deg)
Definition: Matrix4.h:270
class CoordinateFrame approxCoordinateFrame() const
Definition: Matrix4.cpp:507
static Matrix4 scale(float x, float y, float z)
Definition: Matrix4.h:247
Matrix4float64()
Definition: Matrix4.cpp:562
#define const
Definition: zconf.h:217
G3D::int16 x
Definition: Vector2int16.h:37
float determinant() const
Definition: Matrix4.cpp:424
Matrix4 inverse() const
Definition: Matrix4.cpp:436
static Matrix4float64 perspectiveProjection(double left, double right, double bottom, double top, double nearval, double farval, float upDirection=-1.0f)
Definition: Matrix4.cpp:639
static const Matrix4float64 & identity()
Definition: Matrix4.cpp:583
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
Matrix4 adjoint() const
Definition: Matrix4.cpp:431