OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreMatrix4.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Matrix4__
29 #define __Matrix4__
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 
34 #include "OgreVector3.h"
35 #include "OgreMatrix3.h"
36 #include "OgreVector4.h"
37 #include "OgrePlane.h"
38 namespace Ogre
39 {
79  {
80  protected:
82  union {
83  Real m[4][4];
84  Real _m[16];
85  };
86  public:
91  inline Matrix4()
92  {
93  }
94 
95  inline Matrix4(
96  Real m00, Real m01, Real m02, Real m03,
97  Real m10, Real m11, Real m12, Real m13,
98  Real m20, Real m21, Real m22, Real m23,
99  Real m30, Real m31, Real m32, Real m33 )
100  {
101  m[0][0] = m00;
102  m[0][1] = m01;
103  m[0][2] = m02;
104  m[0][3] = m03;
105  m[1][0] = m10;
106  m[1][1] = m11;
107  m[1][2] = m12;
108  m[1][3] = m13;
109  m[2][0] = m20;
110  m[2][1] = m21;
111  m[2][2] = m22;
112  m[2][3] = m23;
113  m[3][0] = m30;
114  m[3][1] = m31;
115  m[3][2] = m32;
116  m[3][3] = m33;
117  }
118 
122  inline Matrix4(const Matrix3& m3x3)
123  {
124  operator=(IDENTITY);
125  operator=(m3x3);
126  }
127 
131  inline Matrix4(const Quaternion& rot)
132  {
133  Matrix3 m3x3;
134  rot.ToRotationMatrix(m3x3);
135  operator=(IDENTITY);
136  operator=(m3x3);
137  }
138 
139 
142  inline void swap(Matrix4& other)
143  {
144  std::swap(m[0][0], other.m[0][0]);
145  std::swap(m[0][1], other.m[0][1]);
146  std::swap(m[0][2], other.m[0][2]);
147  std::swap(m[0][3], other.m[0][3]);
148  std::swap(m[1][0], other.m[1][0]);
149  std::swap(m[1][1], other.m[1][1]);
150  std::swap(m[1][2], other.m[1][2]);
151  std::swap(m[1][3], other.m[1][3]);
152  std::swap(m[2][0], other.m[2][0]);
153  std::swap(m[2][1], other.m[2][1]);
154  std::swap(m[2][2], other.m[2][2]);
155  std::swap(m[2][3], other.m[2][3]);
156  std::swap(m[3][0], other.m[3][0]);
157  std::swap(m[3][1], other.m[3][1]);
158  std::swap(m[3][2], other.m[3][2]);
159  std::swap(m[3][3], other.m[3][3]);
160  }
161 
162  inline Real* operator [] ( size_t iRow )
163  {
164  assert( iRow < 4 );
165  return m[iRow];
166  }
167 
168  inline const Real *operator [] ( size_t iRow ) const
169  {
170  assert( iRow < 4 );
171  return m[iRow];
172  }
173 
174  inline Matrix4 concatenate(const Matrix4 &m2) const
175  {
176  Matrix4 r;
177  r.m[0][0] = m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0] + m[0][3] * m2.m[3][0];
178  r.m[0][1] = m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1] + m[0][3] * m2.m[3][1];
179  r.m[0][2] = m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2] + m[0][3] * m2.m[3][2];
180  r.m[0][3] = m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3] * m2.m[3][3];
181 
182  r.m[1][0] = m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0] + m[1][3] * m2.m[3][0];
183  r.m[1][1] = m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1] + m[1][3] * m2.m[3][1];
184  r.m[1][2] = m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2] + m[1][3] * m2.m[3][2];
185  r.m[1][3] = m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3] * m2.m[3][3];
186 
187  r.m[2][0] = m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0] + m[2][3] * m2.m[3][0];
188  r.m[2][1] = m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1] + m[2][3] * m2.m[3][1];
189  r.m[2][2] = m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2] + m[2][3] * m2.m[3][2];
190  r.m[2][3] = m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3] * m2.m[3][3];
191 
192  r.m[3][0] = m[3][0] * m2.m[0][0] + m[3][1] * m2.m[1][0] + m[3][2] * m2.m[2][0] + m[3][3] * m2.m[3][0];
193  r.m[3][1] = m[3][0] * m2.m[0][1] + m[3][1] * m2.m[1][1] + m[3][2] * m2.m[2][1] + m[3][3] * m2.m[3][1];
194  r.m[3][2] = m[3][0] * m2.m[0][2] + m[3][1] * m2.m[1][2] + m[3][2] * m2.m[2][2] + m[3][3] * m2.m[3][2];
195  r.m[3][3] = m[3][0] * m2.m[0][3] + m[3][1] * m2.m[1][3] + m[3][2] * m2.m[2][3] + m[3][3] * m2.m[3][3];
196 
197  return r;
198  }
199 
202  inline Matrix4 operator * ( const Matrix4 &m2 ) const
203  {
204  return concatenate( m2 );
205  }
206 
216  inline Vector3 operator * ( const Vector3 &v ) const
217  {
218  Vector3 r;
219 
220  Real fInvW = 1.0f / ( m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] );
221 
222  r.x = ( m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] ) * fInvW;
223  r.y = ( m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] ) * fInvW;
224  r.z = ( m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] ) * fInvW;
225 
226  return r;
227  }
228  inline Vector4 operator * (const Vector4& v) const
229  {
230  return Vector4(
231  m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w,
232  m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
233  m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
234  m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w
235  );
236  }
237  inline Plane operator * (const Plane& p) const
238  {
239  Plane ret;
240  Matrix4 invTrans = inverse().transpose();
241  Vector4 v4( p.normal.x, p.normal.y, p.normal.z, p.d );
242  v4 = invTrans * v4;
243  ret.normal.x = v4.x;
244  ret.normal.y = v4.y;
245  ret.normal.z = v4.z;
246  ret.d = v4.w / ret.normal.normalise();
247 
248  return ret;
249  }
250 
251 
254  inline Matrix4 operator + ( const Matrix4 &m2 ) const
255  {
256  Matrix4 r;
257 
258  r.m[0][0] = m[0][0] + m2.m[0][0];
259  r.m[0][1] = m[0][1] + m2.m[0][1];
260  r.m[0][2] = m[0][2] + m2.m[0][2];
261  r.m[0][3] = m[0][3] + m2.m[0][3];
262 
263  r.m[1][0] = m[1][0] + m2.m[1][0];
264  r.m[1][1] = m[1][1] + m2.m[1][1];
265  r.m[1][2] = m[1][2] + m2.m[1][2];
266  r.m[1][3] = m[1][3] + m2.m[1][3];
267 
268  r.m[2][0] = m[2][0] + m2.m[2][0];
269  r.m[2][1] = m[2][1] + m2.m[2][1];
270  r.m[2][2] = m[2][2] + m2.m[2][2];
271  r.m[2][3] = m[2][3] + m2.m[2][3];
272 
273  r.m[3][0] = m[3][0] + m2.m[3][0];
274  r.m[3][1] = m[3][1] + m2.m[3][1];
275  r.m[3][2] = m[3][2] + m2.m[3][2];
276  r.m[3][3] = m[3][3] + m2.m[3][3];
277 
278  return r;
279  }
280 
283  inline Matrix4 operator - ( const Matrix4 &m2 ) const
284  {
285  Matrix4 r;
286  r.m[0][0] = m[0][0] - m2.m[0][0];
287  r.m[0][1] = m[0][1] - m2.m[0][1];
288  r.m[0][2] = m[0][2] - m2.m[0][2];
289  r.m[0][3] = m[0][3] - m2.m[0][3];
290 
291  r.m[1][0] = m[1][0] - m2.m[1][0];
292  r.m[1][1] = m[1][1] - m2.m[1][1];
293  r.m[1][2] = m[1][2] - m2.m[1][2];
294  r.m[1][3] = m[1][3] - m2.m[1][3];
295 
296  r.m[2][0] = m[2][0] - m2.m[2][0];
297  r.m[2][1] = m[2][1] - m2.m[2][1];
298  r.m[2][2] = m[2][2] - m2.m[2][2];
299  r.m[2][3] = m[2][3] - m2.m[2][3];
300 
301  r.m[3][0] = m[3][0] - m2.m[3][0];
302  r.m[3][1] = m[3][1] - m2.m[3][1];
303  r.m[3][2] = m[3][2] - m2.m[3][2];
304  r.m[3][3] = m[3][3] - m2.m[3][3];
305 
306  return r;
307  }
308 
311  inline bool operator == ( const Matrix4& m2 ) const
312  {
313  if(
314  m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
315  m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
316  m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
317  m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
318  return false;
319  return true;
320  }
321 
324  inline bool operator != ( const Matrix4& m2 ) const
325  {
326  if(
327  m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
328  m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
329  m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
330  m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
331  return true;
332  return false;
333  }
334 
337  inline void operator = ( const Matrix3& mat3 )
338  {
339  m[0][0] = mat3.m[0][0]; m[0][1] = mat3.m[0][1]; m[0][2] = mat3.m[0][2];
340  m[1][0] = mat3.m[1][0]; m[1][1] = mat3.m[1][1]; m[1][2] = mat3.m[1][2];
341  m[2][0] = mat3.m[2][0]; m[2][1] = mat3.m[2][1]; m[2][2] = mat3.m[2][2];
342  }
343 
344  inline Matrix4 transpose(void) const
345  {
346  return Matrix4(m[0][0], m[1][0], m[2][0], m[3][0],
347  m[0][1], m[1][1], m[2][1], m[3][1],
348  m[0][2], m[1][2], m[2][2], m[3][2],
349  m[0][3], m[1][3], m[2][3], m[3][3]);
350  }
351 
352  /*
353  -----------------------------------------------------------------------
354  Translation Transformation
355  -----------------------------------------------------------------------
356  */
359  inline void setTrans( const Vector3& v )
360  {
361  m[0][3] = v.x;
362  m[1][3] = v.y;
363  m[2][3] = v.z;
364  }
365 
368  inline Vector3 getTrans() const
369  {
370  return Vector3(m[0][3], m[1][3], m[2][3]);
371  }
372 
373 
376  inline void makeTrans( const Vector3& v )
377  {
378  m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = v.x;
379  m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = v.y;
380  m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = v.z;
381  m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
382  }
383 
384  inline void makeTrans( Real tx, Real ty, Real tz )
385  {
386  m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = tx;
387  m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = ty;
388  m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = tz;
389  m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
390  }
391 
394  inline static Matrix4 getTrans( const Vector3& v )
395  {
396  Matrix4 r;
397 
398  r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = v.x;
399  r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = v.y;
400  r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = v.z;
401  r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
402 
403  return r;
404  }
405 
408  inline static Matrix4 getTrans( Real t_x, Real t_y, Real t_z )
409  {
410  Matrix4 r;
411 
412  r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = t_x;
413  r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = t_y;
414  r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = t_z;
415  r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
416 
417  return r;
418  }
419 
420  /*
421  -----------------------------------------------------------------------
422  Scale Transformation
423  -----------------------------------------------------------------------
424  */
427  inline void setScale( const Vector3& v )
428  {
429  m[0][0] = v.x;
430  m[1][1] = v.y;
431  m[2][2] = v.z;
432  }
433 
436  inline static Matrix4 getScale( const Vector3& v )
437  {
438  Matrix4 r;
439  r.m[0][0] = v.x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
440  r.m[1][0] = 0.0; r.m[1][1] = v.y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
441  r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = v.z; r.m[2][3] = 0.0;
442  r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
443 
444  return r;
445  }
446 
449  inline static Matrix4 getScale( Real s_x, Real s_y, Real s_z )
450  {
451  Matrix4 r;
452  r.m[0][0] = s_x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
453  r.m[1][0] = 0.0; r.m[1][1] = s_y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
454  r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = s_z; r.m[2][3] = 0.0;
455  r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
456 
457  return r;
458  }
459 
463  inline void extract3x3Matrix(Matrix3& m3x3) const
464  {
465  m3x3.m[0][0] = m[0][0];
466  m3x3.m[0][1] = m[0][1];
467  m3x3.m[0][2] = m[0][2];
468  m3x3.m[1][0] = m[1][0];
469  m3x3.m[1][1] = m[1][1];
470  m3x3.m[1][2] = m[1][2];
471  m3x3.m[2][0] = m[2][0];
472  m3x3.m[2][1] = m[2][1];
473  m3x3.m[2][2] = m[2][2];
474 
475  }
476 
478  inline bool hasScale() const
479  {
480  // check magnitude of column vectors (==local axes)
481  Real t = m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0];
482  if (!Math::RealEqual(t, 1.0, (Real)1e-04))
483  return true;
484  t = m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1];
485  if (!Math::RealEqual(t, 1.0, (Real)1e-04))
486  return true;
487  t = m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2];
488  if (!Math::RealEqual(t, 1.0, (Real)1e-04))
489  return true;
490 
491  return false;
492  }
493 
495  inline bool hasNegativeScale() const
496  {
497  return determinant() < 0;
498  }
499 
503  {
504  Matrix3 m3x3;
505  extract3x3Matrix(m3x3);
506  return Quaternion(m3x3);
507  }
508 
509  static const Matrix4 ZERO;
510  static const Matrix4 ZEROAFFINE;
511  static const Matrix4 IDENTITY;
515 
516  inline Matrix4 operator*(Real scalar) const
517  {
518  return Matrix4(
519  scalar*m[0][0], scalar*m[0][1], scalar*m[0][2], scalar*m[0][3],
520  scalar*m[1][0], scalar*m[1][1], scalar*m[1][2], scalar*m[1][3],
521  scalar*m[2][0], scalar*m[2][1], scalar*m[2][2], scalar*m[2][3],
522  scalar*m[3][0], scalar*m[3][1], scalar*m[3][2], scalar*m[3][3]);
523  }
524 
527  inline _OgreExport friend std::ostream& operator <<
528  ( std::ostream& o, const Matrix4& mat )
529  {
530  o << "Matrix4(";
531  for (size_t i = 0; i < 4; ++i)
532  {
533  o << " row" << (unsigned)i << "{";
534  for(size_t j = 0; j < 4; ++j)
535  {
536  o << mat[i][j] << " ";
537  }
538  o << "}";
539  }
540  o << ")";
541  return o;
542  }
543 
544  Matrix4 adjoint() const;
545  Real determinant() const;
546  Matrix4 inverse() const;
547 
554  void makeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
555 
561  void makeInverseTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
562 
565  void decomposition(Vector3& position, Vector3& scale, Quaternion& orientation) const;
566 
572  inline bool isAffine(void) const
573  {
574  return m[3][0] == 0 && m[3][1] == 0 && m[3][2] == 0 && m[3][3] == 1;
575  }
576 
581  Matrix4 inverseAffine(void) const;
582 
587  inline Matrix4 concatenateAffine(const Matrix4 &m2) const
588  {
589  assert(isAffine() && m2.isAffine());
590 
591  return Matrix4(
592  m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0],
593  m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1],
594  m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2],
595  m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3],
596 
597  m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0],
598  m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1],
599  m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2],
600  m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3],
601 
602  m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0],
603  m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1],
604  m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2],
605  m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3],
606 
607  0, 0, 0, 1);
608  }
609 
617  inline Vector3 transformAffine(const Vector3& v) const
618  {
619  assert(isAffine());
620 
621  return Vector3(
622  m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3],
623  m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3],
624  m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3]);
625  }
626 
631  inline Vector4 transformAffine(const Vector4& v) const
632  {
633  assert(isAffine());
634 
635  return Vector4(
636  m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w,
637  m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
638  m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
639  v.w);
640  }
641  };
642 
643  /* Removed from Vector4 and made a non-member here because otherwise
644  OgreMatrix4.h and OgreVector4.h have to try to include and inline each
645  other, which frankly doesn't work ;)
646  */
647  inline Vector4 operator * (const Vector4& v, const Matrix4& mat)
648  {
649  return Vector4(
650  v.x*mat[0][0] + v.y*mat[1][0] + v.z*mat[2][0] + v.w*mat[3][0],
651  v.x*mat[0][1] + v.y*mat[1][1] + v.z*mat[2][1] + v.w*mat[3][1],
652  v.x*mat[0][2] + v.y*mat[1][2] + v.z*mat[2][2] + v.w*mat[3][2],
653  v.x*mat[0][3] + v.y*mat[1][3] + v.z*mat[2][3] + v.w*mat[3][3]
654  );
655  }
659 }
660 #endif
Matrix4()
Default constructor.
Definition: OgreMatrix4.h:91
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
static const Matrix4 ZERO
Definition: OgreMatrix4.h:509
float Real
Software floating point type.
Matrix4 concatenateAffine(const Matrix4 &m2) const
Concatenate two affine matrices.
Definition: OgreMatrix4.h:587
#define _OgreExport
Definition: OgrePlatform.h:260
Matrix4 concatenate(const Matrix4 &m2) const
Definition: OgreMatrix4.h:174
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Real m[4][4]
Definition: OgreMatrix4.h:83
static const Matrix4 ZEROAFFINE
Definition: OgreMatrix4.h:510
Real m[3][3]
Definition: OgreMatrix3.h:286
bool hasScale() const
Determines if this matrix involves a scaling.
Definition: OgreMatrix4.h:478
static const Matrix4 IDENTITY
Definition: OgreMatrix4.h:511
Matrix4(const Quaternion &rot)
Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling Qua...
Definition: OgreMatrix4.h:131
Matrix4(const Matrix3 &m3x3)
Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling 3x3...
Definition: OgreMatrix4.h:122
void setTrans(const Vector3 &v)
Sets the translation transformation part of the matrix.
Definition: OgreMatrix4.h:359
A 3x3 matrix which can represent rotations around axes.
Definition: OgreMatrix3.h:68
Radian operator*(Real a, const Radian &b)
Definition: OgreMath.h:747
static bool RealEqual(Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon())
Compare 2 reals, using tolerance for inaccuracies.
Implementation of a Quaternion, i.e.
bool isAffine(void) const
Check whether or not the matrix is affine matrix.
Definition: OgreMatrix4.h:572
void makeTrans(const Vector3 &v)
Builds a translation matrix.
Definition: OgreMatrix4.h:376
Vector3 getTrans() const
Extracts the translation transformation part of the matrix.
Definition: OgreMatrix4.h:368
void ToRotationMatrix(Matrix3 &kRot) const
Vector3 transformAffine(const Vector3 &v) const
3-D Vector transformation specially for an affine matrix.
Definition: OgreMatrix4.h:617
void swap(Matrix4 &other)
Exchange the contents of this matrix with another.
Definition: OgreMatrix4.h:142
void makeTrans(Real tx, Real ty, Real tz)
Definition: OgreMatrix4.h:384
Quaternion extractQuaternion() const
Extracts the rotation / scaling part as a quaternion from the Matrix.
Definition: OgreMatrix4.h:502
bool hasNegativeScale() const
Determines if this matrix involves a negative scaling.
Definition: OgreMatrix4.h:495
Matrix4(Real m00, Real m01, Real m02, Real m03, Real m10, Real m11, Real m12, Real m13, Real m20, Real m21, Real m22, Real m23, Real m30, Real m31, Real m32, Real m33)
Definition: OgreMatrix4.h:95
void extract3x3Matrix(Matrix3 &m3x3) const
Extracts the rotation / scaling part of the Matrix as a 3x3 matrix.
Definition: OgreMatrix4.h:463
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Vector4 transformAffine(const Vector4 &v) const
4-D Vector transformation specially for an affine matrix.
Definition: OgreMatrix4.h:631
void setScale(const Vector3 &v)
Sets the scale part of the matrix.
Definition: OgreMatrix4.h:427
static Matrix4 getScale(const Vector3 &v)
Gets a scale matrix.
Definition: OgreMatrix4.h:436
Matrix4 transpose(void) const
Definition: OgreMatrix4.h:344
Vector3 normal
Definition: OgrePlane.h:144
static Matrix4 getScale(Real s_x, Real s_y, Real s_z)
Gets a scale matrix - variation for not using a vector.
Definition: OgreMatrix4.h:449
Real normalise()
Normalises the vector.
Definition: OgreVector3.h:446
static Matrix4 getTrans(Real t_x, Real t_y, Real t_z)
Gets a translation matrix - variation for not using a vector.
Definition: OgreMatrix4.h:408
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Matrix4 operator*(Real scalar) const
Definition: OgreMatrix4.h:516
static Matrix4 getTrans(const Vector3 &v)
Gets a translation matrix.
Definition: OgreMatrix4.h:394
static const Matrix4 CLIPSPACE2DTOIMAGESPACE
Useful little matrix which takes 2D clipspace {-1, 1} to {0,1} and inverts the Y. ...
Definition: OgreMatrix4.h:514
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)