TrueReality  v0.1.1912
MatrixImpl.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2017 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Maxim Serebrennik
20 */
21 
22 #include <trBase/Quat.h>
23 #include <trBase/Vec3d.h>
24 #include <trBase/Vec3f.h>
25 #include <trBase/Vec4d.h>
26 #include <trBase/Vec4f.h>
27 
28 namespace trBase
29 {
32  {
33  MakeIdentity();
34  }
35 
38  : mMatrix(mat)
39  {
40  }
41 
43  MatrixImpl::MatrixImpl(float const * const ptr)
44  : mMatrix(ptr)
45  {
46  }
47 
49  MatrixImpl::MatrixImpl(double const * const ptr)
50  : mMatrix(ptr)
51  {
52  }
53 
55  MatrixImpl::MatrixImpl(const Quat& quat)
56  : mMatrix(quat)
57  {
58  }
59 
62  value_type a10, value_type a11, value_type a12, value_type a13,
63  value_type a20, value_type a21, value_type a22, value_type a23,
64  value_type a30, value_type a31, value_type a32, value_type a33)
65  : mMatrix(a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, a31, a32, a33)
66  {
67  }
68 
70  osg::MatrixImpl& MatrixImpl::GetOSGMatrix()
71  {
72  return mMatrix;
73  }
74 
76  const osg::MatrixImpl& MatrixImpl::GetOSGMatrix() const
77  {
78  return mMatrix;
79  }
80 
82  int MatrixImpl::Compare(const MatrixImpl& m) const
83  {
84  return mMatrix.compare(m);
85  }
86 
88  bool MatrixImpl::Valid() const
89  {
90  return mMatrix.valid();
91  }
92 
94  bool MatrixImpl::IsNaN() const
95  {
96  return mMatrix.isNaN();
97  }
98 
100  void MatrixImpl::Set(const MatrixImpl& rhs)
101  {
102  Set(rhs.Ptr());
103  }
104 
106  void MatrixImpl::Set(float const * const ptr)
107  {
108  mMatrix.set(ptr);
109  }
110 
112  void MatrixImpl::Set(double const * const ptr)
113  {
114  mMatrix.set(ptr);
115  }
116 
118  void MatrixImpl::Set(value_type a00, value_type a01, value_type a02, value_type a03,
119  value_type a10, value_type a11, value_type a12, value_type a13,
120  value_type a20, value_type a21, value_type a22, value_type a23,
121  value_type a30, value_type a31, value_type a32, value_type a33)
122  {
123  mMatrix.set(a00, a01, a02, a03, a10, a11, a12, a13,
124  a20, a21, a22, a23, a30, a31, a32, a33);
125  }
126 
128  MatrixImpl::value_type* MatrixImpl::Ptr()
129  {
130  return mMatrix.ptr();
131  }
132 
134  const MatrixImpl::value_type* MatrixImpl::Ptr() const
135  {
136  return mMatrix.ptr();
137  }
138 
140  void MatrixImpl::MakeIdentity()
141  {
142  mMatrix.makeIdentity();
143  }
144 
146  void MatrixImpl::MakeScale(const Vec3f& v)
147  {
148  mMatrix.makeScale(v);
149  }
150 
152  void MatrixImpl::MakeScale(const Vec3d& v)
153  {
154  mMatrix.makeScale(v);
155  }
156 
158  void MatrixImpl::MakeScale(value_type x, value_type y, value_type z)
159  {
160  mMatrix.makeScale(x, y, z);
161  }
162 
164  void MatrixImpl::MakeTranslate(const Vec3f& v)
165  {
166  mMatrix.makeTranslate(v);
167  }
168 
170  void MatrixImpl::MakeTranslate(const Vec3d& v)
171  {
172  mMatrix.makeTranslate(v);
173  }
174 
176  void MatrixImpl::MakeTranslate(value_type x, value_type y, value_type z)
177  {
178  mMatrix.makeTranslate(x, y, z);
179  }
180 
182  void MatrixImpl::MakeRotate(const Vec3f& from, const Vec3f& to)
183  {
184  mMatrix.makeRotate(from, to);
185  }
186 
188  void MatrixImpl::MakeRotate(const Vec3d& from, const Vec3d& to)
189  {
190  mMatrix.makeRotate(from, to);
191  }
192 
194  void MatrixImpl::MakeRotate(value_type angle, const Vec3f& axis)
195  {
196  mMatrix.makeRotate(angle, axis);
197  }
198 
200  void MatrixImpl::MakeRotate(value_type angle, const Vec3d& axis)
201  {
202  mMatrix.makeRotate(angle, axis);
203  }
204 
206  void MatrixImpl::MakeRotate(value_type angle, value_type x, value_type y, value_type z)
207  {
208  mMatrix.makeRotate(angle, x, y, z);
209  }
210 
212  void MatrixImpl::MakeRotate(const Quat& q)
213  {
214  mMatrix.makeRotate(q);
215  }
216 
218  void MatrixImpl::MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3)
219  {
220  mMatrix.makeRotate(angle1, axis1, angle2, axis2, angle3, axis3);
221  }
222 
224  void MatrixImpl::MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3)
225  {
226  mMatrix.makeRotate(angle1, axis1, angle2, axis2, angle3, axis3);
227  }
228 
230  void MatrixImpl::Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const
231  {
232  mMatrix.decompose(translation, rotation, scale, so);
233  }
234 
236  void MatrixImpl::Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const
237  {
238  mMatrix.decompose(translation, rotation, scale, so);
239  }
240 
242  void MatrixImpl::MakeOrtho(value_type left, value_type right, value_type bottom, value_type top, value_type zNear, value_type zFar)
243  {
244  mMatrix.makeOrtho(left, right, bottom, top, zNear, zFar);
245  }
246 
248  bool MatrixImpl::GetOrtho(value_type& left, value_type& right, value_type& bottom, value_type& top, value_type& zNear, value_type& zFar) const
249  {
250  return mMatrix.getOrtho(left, right, bottom, top, zNear, zFar);
251  }
252 
254  void MatrixImpl::MakeOrtho2D(value_type left, value_type right, value_type bottom, value_type top)
255  {
256  mMatrix.makeOrtho(left, right, bottom, top, -1.0, 1.0);
257  }
258 
260  void MatrixImpl::MakeFrustum(value_type left, value_type right, value_type bottom, value_type top, value_type zNear, value_type zFar)
261  {
262  mMatrix.makeFrustum(left, right, bottom, top, zNear, zFar);
263  }
264 
266  bool MatrixImpl::GetFrustum(value_type& left, value_type& right, value_type& bottom, value_type& top, value_type& zNear, value_type& zFar) const
267  {
268  return mMatrix.getFrustum(left, right, bottom, top, zNear, zFar);
269  }
270 
272  void MatrixImpl::MakePerspective(value_type fovy, value_type aspectRatio, value_type zNear, value_type zFar)
273  {
274  mMatrix.makePerspective(fovy, aspectRatio, zNear, zFar);
275  }
276 
278  bool MatrixImpl::GetPerspective(value_type& fovy, value_type& aspectRatio, value_type& zNear, value_type& zFar) const
279  {
280  return mMatrix.getPerspective(fovy, aspectRatio, zNear, zFar);
281  }
282 
284  void MatrixImpl::MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up)
285  {
286  mMatrix.makeLookAt(eye.GetOSGVector(), center.GetOSGVector(), up.GetOSGVector());
287  }
288 
290  void MatrixImpl::MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up)
291  {
292  mMatrix.makeLookAt(eye, center, up);
293  }
294 
296  void MatrixImpl::GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance) const
297  {
298  mMatrix.getLookAt(eye, center, up, lookDistance);
299  }
300 
302  void MatrixImpl::GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance) const
303  {
304  mMatrix.getLookAt(eye, center, up, lookDistance);
305  }
306 
308  bool MatrixImpl::Invert(const MatrixImpl& rhs)
309  {
310  return mMatrix.invert(rhs);
311  }
312 
314  bool MatrixImpl::Invert_4x3(const MatrixImpl& rhs)
315  {
316  return mMatrix.invert_4x3(rhs);
317  }
318 
320  bool MatrixImpl::Invert_4x4(const MatrixImpl& rhs)
321  {
322  return mMatrix.invert_4x4(rhs);
323  }
324 
326  void MatrixImpl::OrthoNormalize(const MatrixImpl& rhs)
327  {
328  mMatrix.orthoNormalize(rhs);
329  }
330 
332  void MatrixImpl::SetRotate(const Quat& q)
333  {
334  mMatrix.setRotate(q);
335  }
336 
338  Quat MatrixImpl::GetRotate() const
339  {
340  return mMatrix.getRotate();
341  }
342 
344  void MatrixImpl::SetTrans(value_type tx, value_type ty, value_type tz)
345  {
346  mMatrix.setTrans(tx, ty, tz);
347  }
348 
350  void MatrixImpl::SetTrans(const Vec3f& v)
351  {
352  mMatrix.setTrans(v);
353  }
354 
356  void MatrixImpl::SetTrans(const Vec3d& v)
357  {
358  mMatrix.setTrans(v);
359  }
360 
362  Vec3d MatrixImpl::GetTrans() const
363  {
364  return mMatrix.getTrans();
365  }
366 
368  Vec3d MatrixImpl::GetScale() const
369  {
370  return mMatrix.getScale();
371  }
372 
374  void MatrixImpl::SetScale(value_type x, value_type y, value_type z)
375  {
376  mMatrix(0, 0) = x;
377  mMatrix(1, 1) = y;
378  mMatrix(2, 2) = z;
379  }
380 
382  void MatrixImpl::SetScale(const Vec3f& v)
383  {
384  SetScale(v[0], v[1], v[2]);
385  }
386 
388  void MatrixImpl::SetScale(const Vec3d& v)
389  {
390  SetScale(v[0], v[1], v[2]);
391  }
392 
394  Vec3f MatrixImpl::PreMult(const Vec3f& v) const
395  {
396  return mMatrix.preMult(v);
397  }
398 
400  Vec3d MatrixImpl::PreMult(const Vec3d& v) const
401  {
402  return mMatrix.preMult(v);
403  }
404 
406  Vec3f MatrixImpl::PostMult(const Vec3f& v) const
407  {
408  return mMatrix.postMult(v);
409  }
410 
412  Vec3d MatrixImpl::PostMult(const Vec3d& v) const
413  {
414  return mMatrix.postMult(v);
415  }
416 
418  Vec4f MatrixImpl::PreMult(const Vec4f& v) const
419  {
420  return mMatrix.preMult(v);
421  }
422 
424  Vec4d MatrixImpl::PreMult(const Vec4d& v) const
425  {
426  return mMatrix.preMult(v);
427  }
428 
430  Vec4f MatrixImpl::PostMult(const Vec4f& v) const
431  {
432  return mMatrix.postMult(v);
433  }
434 
436  Vec4d MatrixImpl::PostMult(const Vec4d& v) const
437  {
438  return mMatrix.postMult(v);
439  }
440 
442  void MatrixImpl::Mult(const MatrixImpl& m1, const MatrixImpl& m2)
443  {
444  mMatrix.mult(m1, m2);
445  }
446 
448  void MatrixImpl::PreMult(const MatrixImpl& m)
449  {
450  mMatrix.preMult(m);
451  }
452 
454  void MatrixImpl::PostMult(const MatrixImpl& m)
455  {
456  mMatrix.postMult(m);
457  }
458 
460  void MatrixImpl::PreMultTranslate(const Vec3d& v)
461  {
462  mMatrix.preMultTranslate(v);
463  }
464 
466  void MatrixImpl::PreMultTranslate(const Vec3f& v)
467  {
468  mMatrix.preMultTranslate(v);
469  }
470 
472  void MatrixImpl::PostMultTranslate(const Vec3d& v)
473  {
474  mMatrix.postMultTranslate(v);
475  }
476 
478  void MatrixImpl::PostMultTranslate(const Vec3f& v)
479  {
480  mMatrix.postMultTranslate(v);
481  }
482 
484  void MatrixImpl::PreMultScale(const Vec3d& v)
485  {
486  mMatrix.preMultScale(v);
487  }
488 
490  void MatrixImpl::PreMultScale(const Vec3f& v)
491  {
492  mMatrix.preMultScale(v);
493  }
494 
496  void MatrixImpl::PostMultScale(const Vec3d& v)
497  {
498  mMatrix.postMultScale(v);
499  }
500 
502  void MatrixImpl::PostMultScale(const Vec3f& v)
503  {
504  mMatrix.postMultScale(v);
505  }
506 
508  void MatrixImpl::PreMultRotate(const Quat& q)
509  {
510  mMatrix.preMultRotate(q);
511  }
512 
514  void MatrixImpl::PostMultRotate(const Quat& q)
515  {
516  mMatrix.preMultRotate(q);
517  }
518 
520  std::string MatrixImpl::ToString(int precision)
521  {
522  return std::string("[" + trUtil::StringUtils::ToString<value_type>(mMatrix(0, 0), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(0, 1), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(0, 2), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(0, 3), precision) +
523  "] [" + trUtil::StringUtils::ToString<value_type>(mMatrix(1, 0), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(1, 1), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(1, 2), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(1, 3), precision) +
524  "] [" + trUtil::StringUtils::ToString<value_type>(mMatrix(2, 0), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(2, 1), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(2, 2), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(2, 3), precision) +
525  "] [" + trUtil::StringUtils::ToString<value_type>(mMatrix(3, 0), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(3, 1), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(3, 2), precision) + ", " + trUtil::StringUtils::ToString<value_type>(mMatrix(3, 3), precision) +
526  "]");
527  }
528 
530  MatrixImpl MatrixImpl::Identity(void)
531  {
532  MatrixImpl m;
533  m.MakeIdentity();
534  return m;
535  }
536 
538  MatrixImpl MatrixImpl::Scale(const Vec3f& sv)
539  {
540  MatrixImpl m;
541  m.MakeScale(sv);
542  return m;
543  }
544 
546  MatrixImpl MatrixImpl::Scale(const Vec3d& sv)
547  {
548  MatrixImpl m;
549  m.MakeScale(sv);
550  return m;
551  }
552 
554  MatrixImpl MatrixImpl::Scale(value_type sx, value_type sy, value_type sz)
555  {
556  MatrixImpl m;
557  m.MakeScale(sx, sy, sz);
558  return m;
559  }
560 
562  MatrixImpl MatrixImpl::Translate(const Vec3f& dv)
563  {
564  MatrixImpl m;
565  m.MakeTranslate(dv);
566  return m;
567  }
568 
570  MatrixImpl MatrixImpl::Translate(const Vec3d& dv)
571  {
572  MatrixImpl m;
573  m.MakeTranslate(dv);
574  return m;
575  }
576 
578  MatrixImpl MatrixImpl::Translate(value_type x, value_type y, value_type z)
579  {
580  MatrixImpl m;
581  m.MakeTranslate(x, y, z);
582  return m;
583  }
584 
586  MatrixImpl MatrixImpl::Rotate(const Vec3f& from, const Vec3f& to)
587  {
588  MatrixImpl m;
589  m.MakeRotate(from, to);
590  return m;
591  }
592 
594  MatrixImpl MatrixImpl::Rotate(const Vec3d& from, const Vec3d& to)
595  {
596  MatrixImpl m;
597  m.MakeRotate(from, to);
598  return m;
599  }
600 
602  MatrixImpl MatrixImpl::Rotate(value_type angle, value_type x, value_type y, value_type z)
603  {
604  MatrixImpl m;
605  m.MakeRotate(angle, x, y, z);
606  return m;
607  }
608 
610  MatrixImpl MatrixImpl::Rotate(value_type angle, const Vec3f& axis)
611  {
612  MatrixImpl m;
613  m.MakeRotate(angle, axis);
614  return m;
615  }
616 
618  MatrixImpl MatrixImpl::Rotate(value_type angle, const Vec3d& axis)
619  {
620  MatrixImpl m;
621  m.MakeRotate(angle, axis);
622  return m;
623  }
624 
626  MatrixImpl MatrixImpl::Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3)
627  {
628  MatrixImpl m;
629  m.MakeRotate(angle1, axis1, angle2, axis2, angle3, axis3);
630  return m;
631  }
632 
634  MatrixImpl MatrixImpl::Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3)
635  {
636  MatrixImpl m;
637  m.MakeRotate(angle1, axis1, angle2, axis2, angle3, axis3);
638  return m;
639  }
640 
642  MatrixImpl MatrixImpl::Rotate(const Quat& quat)
643  {
644  MatrixImpl m;
645  m.MakeRotate(quat);
646  return m;
647  }
648 
650  MatrixImpl MatrixImpl::Inverse(const MatrixImpl& matrix)
651  {
652  MatrixImpl m;
653  m.Invert(matrix);
654  return m;
655  }
656 
658  MatrixImpl MatrixImpl::OrthoNormal(const MatrixImpl& matrix)
659  {
660  MatrixImpl m;
661  m.OrthoNormalize(matrix);
662  return m;
663  }
664 
666  MatrixImpl MatrixImpl::Ortho(value_type left, value_type right, value_type bottom, value_type top, value_type zNear, value_type zFar)
667  {
668  MatrixImpl m;
669  m.MakeOrtho(left, right, bottom, top, zNear, zFar);
670  return m;
671  }
672 
674  MatrixImpl MatrixImpl::Ortho2D(value_type left, value_type right, value_type bottom, value_type top)
675  {
676  MatrixImpl m;
677  m.MakeOrtho2D(left, right, bottom, top);
678  return m;
679  }
680 
682  MatrixImpl MatrixImpl::Frustum(value_type left, value_type right, value_type bottom, value_type top, value_type zNear, value_type zFar)
683  {
684  MatrixImpl m;
685  m.MakeFrustum(left, right, bottom, top, zNear, zFar);
686  return m;
687  }
688 
690  MatrixImpl MatrixImpl::Perspective(value_type fovy, value_type aspectRatio, value_type zNear, value_type zFar)
691  {
692  MatrixImpl m;
693  m.MakePerspective(fovy, aspectRatio, zNear, zFar);
694  return m;
695  }
696 
698  MatrixImpl MatrixImpl::LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up)
699  {
700  MatrixImpl m;
701  m.MakeLookAt(eye, center, up);
702  return m;
703  }
704 
706  MatrixImpl MatrixImpl::LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up)
707  {
708  MatrixImpl m;
709  m.MakeLookAt(eye, center, up);
710  return m;
711  }
712 
714  Vec3f MatrixImpl::Transform3x3(const Vec3f& v, const MatrixImpl& m)
715  {
716  return osg::MatrixImpl::transform3x3(v, m);
717  }
718 
720  Vec3d MatrixImpl::Transform3x3(const Vec3d& v, const MatrixImpl& m)
721  {
722  return osg::MatrixImpl::transform3x3(v, m);
723  }
724 
726  Vec3f MatrixImpl::Transform3x3(const MatrixImpl& m, const Vec3f& v)
727  {
728  return osg::MatrixImpl::transform3x3(m, v);
729  }
730 
732  Vec3d MatrixImpl::Transform3x3(const MatrixImpl& m, const Vec3d& v)
733  {
734  return osg::MatrixImpl::transform3x3(m, v);
735  }
736 
738  MatrixImpl& MatrixImpl::operator = (const MatrixImpl& rhs)
739  {
740  if (&rhs == this) return *this;
741  Set(rhs);
742  return *this;
743  }
744 
746  bool MatrixImpl::operator > (const MatrixImpl& m) const
747  {
748  return Compare(m)>0;
749  }
750 
752  bool MatrixImpl::operator < (const MatrixImpl& m) const
753  {
754  return Compare(m)<0;
755  }
756 
758  bool MatrixImpl::operator == (const MatrixImpl& m) const
759  {
760  return Compare(m) == 0;
761  }
762 
764  bool MatrixImpl::operator != (const MatrixImpl& m) const
765  {
766  return Compare(m) != 0;
767  }
768 
770  Vec3f MatrixImpl::operator* (const Vec3f& v) const
771  {
772  return mMatrix * v;
773  }
774 
776  Vec3d MatrixImpl::operator* (const Vec3d& v) const
777  {
778  return mMatrix * v;
779  }
780 
782  Vec4f MatrixImpl::operator* (const Vec4f& v) const
783  {
784  return mMatrix * v;
785  }
786 
788  Vec4d MatrixImpl::operator* (const Vec4d& v) const
789  {
790  return mMatrix * v;
791  }
792 
794  void MatrixImpl::operator *= (const MatrixImpl& other)
795  {
796  if (this == &other)
797  {
798  MatrixImpl temp(other);
799  PostMult(temp);
800  }
801  else
802  {
803  PostMult(other);
804  }
805  }
806 
808  MatrixImpl MatrixImpl::operator * (const MatrixImpl &m) const
809  {
810  MatrixImpl r;
811  r.Mult(*this, m);
812  return r;
813  }
814 
816  MatrixImpl MatrixImpl::operator * (MatrixImpl::value_type rhs) const
817  {
818  return MatrixImpl(
819  mMatrix(0, 0) * rhs,
820  mMatrix(0, 1) * rhs,
821  mMatrix(0, 2) * rhs,
822  mMatrix(0, 3) * rhs,
823  mMatrix(1, 0) * rhs,
824  mMatrix(1, 1) * rhs,
825  mMatrix(1, 2) * rhs,
826  mMatrix(1, 3) * rhs,
827  mMatrix(2, 0) * rhs,
828  mMatrix(2, 1) * rhs,
829  mMatrix(2, 2) * rhs,
830  mMatrix(2, 3) * rhs,
831  mMatrix(3, 0) * rhs,
832  mMatrix(3, 1) * rhs,
833  mMatrix(3, 2) * rhs,
834  mMatrix(3, 3) * rhs);
835  }
836 
838  MatrixImpl& MatrixImpl::operator *= (MatrixImpl::value_type rhs)
839  {
840  mMatrix(0, 0) *= rhs;
841  mMatrix(0, 1) *= rhs;
842  mMatrix(0, 2) *= rhs;
843  mMatrix(0, 3) *= rhs;
844  mMatrix(1, 0) *= rhs;
845  mMatrix(1, 1) *= rhs;
846  mMatrix(1, 2) *= rhs;
847  mMatrix(1, 3) *= rhs;
848  mMatrix(2, 0) *= rhs;
849  mMatrix(2, 1) *= rhs;
850  mMatrix(2, 2) *= rhs;
851  mMatrix(2, 3) *= rhs;
852  mMatrix(3, 0) *= rhs;
853  mMatrix(3, 1) *= rhs;
854  mMatrix(3, 2) *= rhs;
855  mMatrix(3, 3) *= rhs;
856  return *this;
857  }
858 
860  MatrixImpl MatrixImpl::operator / (MatrixImpl::value_type rhs) const
861  {
862  return MatrixImpl(
863  mMatrix(0, 0) / rhs,
864  mMatrix(0, 1) / rhs,
865  mMatrix(0, 2) / rhs,
866  mMatrix(0, 3) / rhs,
867  mMatrix(1, 0) / rhs,
868  mMatrix(1, 1) / rhs,
869  mMatrix(1, 2) / rhs,
870  mMatrix(1, 3) / rhs,
871  mMatrix(2, 0) / rhs,
872  mMatrix(2, 1) / rhs,
873  mMatrix(2, 2) / rhs,
874  mMatrix(2, 3) / rhs,
875  mMatrix(3, 0) / rhs,
876  mMatrix(3, 1) / rhs,
877  mMatrix(3, 2) / rhs,
878  mMatrix(3, 3) / rhs);
879  }
880 
882  MatrixImpl& MatrixImpl::operator /= (MatrixImpl::value_type rhs)
883  {
884  mMatrix(0, 0) /= rhs;
885  mMatrix(0, 1) /= rhs;
886  mMatrix(0, 2) /= rhs;
887  mMatrix(0, 3) /= rhs;
888  mMatrix(1, 0) /= rhs;
889  mMatrix(1, 1) /= rhs;
890  mMatrix(1, 2) /= rhs;
891  mMatrix(1, 3) /= rhs;
892  mMatrix(2, 0) /= rhs;
893  mMatrix(2, 1) /= rhs;
894  mMatrix(2, 2) /= rhs;
895  mMatrix(2, 3) /= rhs;
896  mMatrix(3, 0) /= rhs;
897  mMatrix(3, 1) /= rhs;
898  mMatrix(3, 2) /= rhs;
899  mMatrix(3, 3) /= rhs;
900  return *this;
901  }
902 
905  {
906  return MatrixImpl(
907  mMatrix(0, 0) + rhs(0, 0),
908  mMatrix(0, 1) + rhs(0, 1),
909  mMatrix(0, 2) + rhs(0, 2),
910  mMatrix(0, 3) + rhs(0, 3),
911  mMatrix(1, 0) + rhs(1, 0),
912  mMatrix(1, 1) + rhs(1, 1),
913  mMatrix(1, 2) + rhs(1, 2),
914  mMatrix(1, 3) + rhs(1, 3),
915  mMatrix(2, 0) + rhs(2, 0),
916  mMatrix(2, 1) + rhs(2, 1),
917  mMatrix(2, 2) + rhs(2, 2),
918  mMatrix(2, 3) + rhs(2, 3),
919  mMatrix(3, 0) + rhs(3, 0),
920  mMatrix(3, 1) + rhs(3, 1),
921  mMatrix(3, 2) + rhs(3, 2),
922  mMatrix(3, 3) + rhs(3, 3));
923  }
924 
926  MatrixImpl& MatrixImpl::operator += (const MatrixImpl& rhs)
927  {
928  mMatrix(0, 0) += rhs(0, 0);
929  mMatrix(0, 1) += rhs(0, 1);
930  mMatrix(0, 2) += rhs(0, 2);
931  mMatrix(0, 3) += rhs(0, 3);
932  mMatrix(1, 0) += rhs(1, 0);
933  mMatrix(1, 1) += rhs(1, 1);
934  mMatrix(1, 2) += rhs(1, 2);
935  mMatrix(1, 3) += rhs(1, 3);
936  mMatrix(2, 0) += rhs(2, 0);
937  mMatrix(2, 1) += rhs(2, 1);
938  mMatrix(2, 2) += rhs(2, 2);
939  mMatrix(2, 3) += rhs(2, 3);
940  mMatrix(3, 0) += rhs(3, 0);
941  mMatrix(3, 1) += rhs(3, 1);
942  mMatrix(3, 2) += rhs(3, 2);
943  mMatrix(3, 3) += rhs(3, 3);
944  return *this;
945  }
946 
948  MatrixImpl MatrixImpl::operator - (const MatrixImpl& rhs) const
949  {
950  return MatrixImpl(
951  mMatrix(0, 0) - rhs(0, 0),
952  mMatrix(0, 1) - rhs(0, 1),
953  mMatrix(0, 2) - rhs(0, 2),
954  mMatrix(0, 3) - rhs(0, 3),
955  mMatrix(1, 0) - rhs(1, 0),
956  mMatrix(1, 1) - rhs(1, 1),
957  mMatrix(1, 2) - rhs(1, 2),
958  mMatrix(1, 3) - rhs(1, 3),
959  mMatrix(2, 0) - rhs(2, 0),
960  mMatrix(2, 1) - rhs(2, 1),
961  mMatrix(2, 2) - rhs(2, 2),
962  mMatrix(2, 3) - rhs(2, 3),
963  mMatrix(3, 0) - rhs(3, 0),
964  mMatrix(3, 1) - rhs(3, 1),
965  mMatrix(3, 2) - rhs(3, 2),
966  mMatrix(3, 3) - rhs(3, 3));
967  }
968 
970  MatrixImpl& MatrixImpl::operator -= (const MatrixImpl& rhs)
971  {
972  mMatrix(0, 0) -= rhs(0, 0);
973  mMatrix(0, 1) -= rhs(0, 1);
974  mMatrix(0, 2) -= rhs(0, 2);
975  mMatrix(0, 3) -= rhs(0, 3);
976  mMatrix(1, 0) -= rhs(1, 0);
977  mMatrix(1, 1) -= rhs(1, 1);
978  mMatrix(1, 2) -= rhs(1, 2);
979  mMatrix(1, 3) -= rhs(1, 3);
980  mMatrix(2, 0) -= rhs(2, 0);
981  mMatrix(2, 1) -= rhs(2, 1);
982  mMatrix(2, 2) -= rhs(2, 2);
983  mMatrix(2, 3) -= rhs(2, 3);
984  mMatrix(3, 0) -= rhs(3, 0);
985  mMatrix(3, 1) -= rhs(3, 1);
986  mMatrix(3, 2) -= rhs(3, 2);
987  mMatrix(3, 3) -= rhs(3, 3);
988  return *this;
989  }
990 
992  MatrixImpl::value_type& MatrixImpl::operator()(int row, int col)
993  {
994  return mMatrix(row, col);
995  }
996 
998  MatrixImpl::value_type MatrixImpl::operator()(int row, int col) const
999  {
1000  return mMatrix(row, col);
1001  }
1002 
1004  MatrixImpl::operator osg::MatrixImpl() const
1005  {
1006  return mMatrix;
1007  }
1008 
1010  MatrixImpl::operator osg::MatrixImpl&()
1011  {
1012  return mMatrix;
1013  }
1014 
1016  MatrixImpl::operator const osg::MatrixImpl&() const
1017  {
1018  return mMatrix;
1019  }
1020 
1022  MatrixImpl::operator osg::MatrixImpl*()
1023  {
1024  return &mMatrix;
1025  }
1026 
1028  std::ostream& operator << (std::ostream& ios, const MatrixImpl& m)
1029  {
1030  ios << "[" << m(0, 0) << ", " << m(0, 1) << ", " << m(0, 2) << ", " << m(0, 3) <<
1031  "] [" << m(1, 0) << ", " << m(1, 1) << ", " << m(1, 2) << ", " << m(1, 3) <<
1032  "] [" << m(2, 0) << ", " << m(2, 1) << ", " << m(2, 2) << ", " << m(2, 3) <<
1033  "] [" << m(3, 0) << ", " << m(3, 1) << ", " << m(3, 2) << ", " << m(3, 3) <<
1034  "]";
1035  return ios;
1036  }
1037 }
std::string operator+(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:193
bool operator==(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:187
int Compare(const Matrixf &m) const
Compare the current Matrix to the passed in one.
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Matrixd &q)
Stream insertion operator.
osg::Matrixf mMatrix
Definition: Matrixf.h:1753
float value_type
Definition: Matrixf.h:45
#define MatrixImpl
Definition: Matrixd.cpp:28
std::string ToString(const T &t, int precision=-1)
A utility function to convert a basic type into a string.
Definition: StringUtils.h:334
Vec3f PostMult(const Vec3f &v) const
PostMultiply the matrix by the passed in vector.
void SetScale(value_type x, value_type y, value_type z)
Sets the scale values of the matrix.
void Set(const Matrixf &rhs)
Set the current Matrix from a passed in one.