OpenSceneGraph 3.6.5
Matrixd
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_MATRIXD
15#define OSG_MATRIXD 1
16
17#include <osg/Object>
18#include <osg/Vec3d>
19#include <osg/Vec4d>
20#include <osg/Quat>
21
22namespace osg {
23
24class Matrixf;
25
27{
28 public:
29
30 typedef double value_type;
31 typedef float other_value_type;
32
33 inline Matrixd() { makeIdentity(); }
34 inline Matrixd( const Matrixd& mat) { set(mat.ptr()); }
35 Matrixd( const Matrixf& mat );
36 inline explicit Matrixd( float const * const ptr ) { set(ptr); }
37 inline explicit Matrixd( double const * const ptr ) { set(ptr); }
38 inline explicit Matrixd( const Quat& quat ) { makeRotate(quat); }
39
41 value_type a10, value_type a11, value_type a12, value_type a13,
42 value_type a20, value_type a21, value_type a22, value_type a23,
43 value_type a30, value_type a31, value_type a32, value_type a33);
44
46
47 int compare(const Matrixd& m) const;
48
49 bool operator < (const Matrixd& m) const { return compare(m)<0; }
50 bool operator == (const Matrixd& m) const { return compare(m)==0; }
51 bool operator != (const Matrixd& m) const { return compare(m)!=0; }
52
53 inline value_type& operator()(int row, int col) { return _mat[row][col]; }
54 inline value_type operator()(int row, int col) const { return _mat[row][col]; }
55
56 inline bool valid() const { return !isNaN(); }
57 inline bool isNaN() const { return osg::isNaN(_mat[0][0]) || osg::isNaN(_mat[0][1]) || osg::isNaN(_mat[0][2]) || osg::isNaN(_mat[0][3]) ||
58 osg::isNaN(_mat[1][0]) || osg::isNaN(_mat[1][1]) || osg::isNaN(_mat[1][2]) || osg::isNaN(_mat[1][3]) ||
59 osg::isNaN(_mat[2][0]) || osg::isNaN(_mat[2][1]) || osg::isNaN(_mat[2][2]) || osg::isNaN(_mat[2][3]) ||
60 osg::isNaN(_mat[3][0]) || osg::isNaN(_mat[3][1]) || osg::isNaN(_mat[3][2]) || osg::isNaN(_mat[3][3]); }
61
62 inline Matrixd& operator = (const Matrixd& rhs)
63 {
64 if( &rhs == this ) return *this;
65 set(rhs.ptr());
66 return *this;
67 }
68
69 Matrixd& operator = (const Matrixf& other);
70
71 inline void set(const Matrixd& rhs) { set(rhs.ptr()); }
72
73 void set(const Matrixf& rhs);
74
75 inline void set(float const * const ptr)
76 {
77 value_type* local_ptr = (value_type*)_mat;
78 for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
79 }
80
81 inline void set(double const * const ptr)
82 {
83 value_type* local_ptr = (value_type*)_mat;
84 for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
85 }
86
90 value_type a30, value_type a31, value_type a32,value_type a33);
91
92 value_type * ptr() { return (value_type*)_mat; }
93 const value_type * ptr() const { return (const value_type *)_mat; }
94
95 bool isIdentity() const
96 {
97 return _mat[0][0]==1.0 && _mat[0][1]==0.0 && _mat[0][2]==0.0 && _mat[0][3]==0.0 &&
98 _mat[1][0]==0.0 && _mat[1][1]==1.0 && _mat[1][2]==0.0 && _mat[1][3]==0.0 &&
99 _mat[2][0]==0.0 && _mat[2][1]==0.0 && _mat[2][2]==1.0 && _mat[2][3]==0.0 &&
100 _mat[3][0]==0.0 && _mat[3][1]==0.0 && _mat[3][2]==0.0 && _mat[3][3]==1.0;
101 }
102
104
105 void makeScale( const Vec3f& );
106 void makeScale( const Vec3d& );
108
109 void makeTranslate( const Vec3f& );
110 void makeTranslate( const Vec3d& );
112
113 void makeRotate( const Vec3f& from, const Vec3f& to );
114 void makeRotate( const Vec3d& from, const Vec3d& to );
115 void makeRotate( value_type angle, const Vec3f& axis );
116 void makeRotate( value_type angle, const Vec3d& axis );
118 void makeRotate( const Quat& );
119 void makeRotate( value_type angle1, const Vec3f& axis1,
120 value_type angle2, const Vec3f& axis2,
121 value_type angle3, const Vec3f& axis3);
122 void makeRotate( value_type angle1, const Vec3d& axis1,
123 value_type angle2, const Vec3d& axis2,
124 value_type angle3, const Vec3d& axis3);
125
126
128 void decompose( osg::Vec3f& translation,
129 osg::Quat& rotation,
131 osg::Quat& so ) const;
132
134 void decompose( osg::Vec3d& translation,
135 osg::Quat& rotation,
137 osg::Quat& so ) const;
138
139
143 void makeOrtho(double left, double right,
144 double bottom, double top,
145 double zNear, double zFar);
146
151 bool getOrtho(double& left, double& right,
152 double& bottom, double& top,
153 double& zNear, double& zFar) const;
154
156 bool getOrtho(float& left, float& right,
157 float& bottom, float& top,
158 float& zNear, float& zFar) const;
159
160
164 inline void makeOrtho2D(double left, double right,
165 double bottom, double top)
166 {
167 makeOrtho(left,right,bottom,top,-1.0,1.0);
168 }
169
170
174 void makeFrustum(double left, double right,
175 double bottom, double top,
176 double zNear, double zFar);
177
182 bool getFrustum(double& left, double& right,
183 double& bottom, double& top,
184 double& zNear, double& zFar) const;
185
187 bool getFrustum(float& left, float& right,
188 float& bottom, float& top,
189 float& zNear, float& zFar) const;
190
195 void makePerspective(double fovy, double aspectRatio,
196 double zNear, double zFar);
197
208 bool getPerspective(double& fovy, double& aspectRatio,
209 double& zNear, double& zFar) const;
210
212 bool getPerspective(float& fovy, float& aspectRatio,
213 float& zNear, float& zFar) const;
214
218 void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
219
223 void getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,
224 value_type lookDistance=1.0f) const;
225
229 void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,
230 value_type lookDistance=1.0f) const;
231
233 inline bool invert( const Matrixd& rhs)
234 {
235 bool is_4x3 = (rhs._mat[0][3]==0.0 && rhs._mat[1][3]==0.0 && rhs._mat[2][3]==0.0 && rhs._mat[3][3]==1.0);
236 return is_4x3 ? invert_4x3(rhs) : invert_4x4(rhs);
237 }
238
240 bool invert_4x3( const Matrixd& rhs);
241
243 bool invert_4x4( const Matrixd& rhs);
244
246 bool transpose(const Matrixd&rhs);
247
249 bool transpose3x3(const Matrixd&rhs);
250
252 void orthoNormalize(const Matrixd& rhs);
253
254 // basic utility functions to create new matrices
255 inline static Matrixd identity( void );
256 inline static Matrixd scale( const Vec3f& sv);
257 inline static Matrixd scale( const Vec3d& sv);
258 inline static Matrixd scale( value_type sx, value_type sy, value_type sz);
259 inline static Matrixd translate( const Vec3f& dv);
260 inline static Matrixd translate( const Vec3d& dv);
261 inline static Matrixd translate( value_type x, value_type y, value_type z);
262 inline static Matrixd rotate( const Vec3f& from, const Vec3f& to);
263 inline static Matrixd rotate( const Vec3d& from, const Vec3d& to);
264 inline static Matrixd rotate( value_type angle, value_type x, value_type y, value_type z);
265 inline static Matrixd rotate( value_type angle, const Vec3f& axis);
266 inline static Matrixd rotate( value_type angle, const Vec3d& axis);
267 inline static Matrixd rotate( value_type angle1, const Vec3f& axis1,
268 value_type angle2, const Vec3f& axis2,
269 value_type angle3, const Vec3f& axis3);
270 inline static Matrixd rotate( value_type angle1, const Vec3d& axis1,
271 value_type angle2, const Vec3d& axis2,
272 value_type angle3, const Vec3d& axis3);
273 inline static Matrixd rotate( const Quat& quat);
274 inline static Matrixd inverse( const Matrixd& matrix);
275 inline static Matrixd orthoNormal(const Matrixd& matrix);
279 inline static Matrixd ortho(double left, double right,
280 double bottom, double top,
281 double zNear, double zFar);
282
286 inline static Matrixd ortho2D(double left, double right,
287 double bottom, double top);
288
292 inline static Matrixd frustum(double left, double right,
293 double bottom, double top,
294 double zNear, double zFar);
295
300 inline static Matrixd perspective(double fovy, double aspectRatio,
301 double zNear, double zFar);
302
306 inline static Matrixd lookAt(const Vec3f& eye,
307 const Vec3f& center,
308 const Vec3f& up);
309
313 inline static Matrixd lookAt(const Vec3d& eye,
314 const Vec3d& center,
315 const Vec3d& up);
316
317 inline Vec3f preMult( const Vec3f& v ) const;
318 inline Vec3d preMult( const Vec3d& v ) const;
319 inline Vec3f postMult( const Vec3f& v ) const;
320 inline Vec3d postMult( const Vec3d& v ) const;
321 inline Vec3f operator* ( const Vec3f& v ) const;
322 inline Vec3d operator* ( const Vec3d& v ) const;
323 inline Vec4f preMult( const Vec4f& v ) const;
324 inline Vec4d preMult( const Vec4d& v ) const;
325 inline Vec4f postMult( const Vec4f& v ) const;
326 inline Vec4d postMult( const Vec4d& v ) const;
327 inline Vec4f operator* ( const Vec4f& v ) const;
328 inline Vec4d operator* ( const Vec4d& v ) const;
329
330#ifdef OSG_USE_DEPRECATED_API
331 inline void set(const Quat& q) { makeRotate(q); }
332 inline void get(Quat& q) const { q = getRotate(); }
333#endif
334
335 void setRotate(const Quat& q);
341
343 void setTrans( const Vec3f& v );
344 void setTrans( const Vec3d& v );
345
346 inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); }
347
348 inline Vec3d getScale() const {
349 Vec3d x_vec(_mat[0][0],_mat[1][0],_mat[2][0]);
350 Vec3d y_vec(_mat[0][1],_mat[1][1],_mat[2][1]);
351 Vec3d z_vec(_mat[0][2],_mat[1][2],_mat[2][2]);
352 return Vec3d(x_vec.length(), y_vec.length(), z_vec.length());
353 }
354
356 inline static Vec3f transform3x3(const Vec3f& v,const Matrixd& m);
357
359 inline static Vec3d transform3x3(const Vec3d& v,const Matrixd& m);
360
362 inline static Vec3f transform3x3(const Matrixd& m,const Vec3f& v);
363
365 inline static Vec3d transform3x3(const Matrixd& m,const Vec3d& v);
366
367 // basic Matrixd multiplication, our workhorse methods.
368 void mult( const Matrixd&, const Matrixd& );
369 void preMult( const Matrixd& );
370 void postMult( const Matrixd& );
371
373 inline void preMultTranslate( const Vec3d& v );
374 inline void preMultTranslate( const Vec3f& v );
376 inline void postMultTranslate( const Vec3d& v );
377 inline void postMultTranslate( const Vec3f& v );
378
380 inline void preMultScale( const Vec3d& v );
381 inline void preMultScale( const Vec3f& v );
383 inline void postMultScale( const Vec3d& v );
384 inline void postMultScale( const Vec3f& v );
385
387 inline void preMultRotate( const Quat& q );
389 inline void postMultRotate( const Quat& q );
390
391 inline void operator *= ( const Matrixd& other )
392 { if( this == &other ) {
393 Matrixd temp(other);
394 postMult( temp );
395 }
396 else postMult( other );
397 }
398
399 inline Matrixd operator * ( const Matrixd &m ) const
400 {
401 osg::Matrixd r;
402 r.mult(*this,m);
403 return r;
404 }
405
406 protected:
408
409};
410
411class RefMatrixd : public Object, public Matrixd
412{
413 public:
414
415 RefMatrixd():Object(false), Matrixd() {}
416 RefMatrixd( const Matrixd& other) : Object(false), Matrixd(other) {}
417 RefMatrixd( const Matrixf& other) : Object(false), Matrixd(other) {}
418 RefMatrixd( const RefMatrixd& other) : Object(other), Matrixd(other) {}
419 explicit RefMatrixd( Matrixd::value_type const * const def ):Object(false), Matrixd(def) {}
424 Object(false),
425 Matrixd(a00, a01, a02, a03,
426 a10, a11, a12, a13,
427 a20, a21, a22, a23,
428 a30, a31, a32, a33) {}
429
430 virtual Object* cloneType() const { return new RefMatrixd(); }
431 virtual Object* clone(const CopyOp&) const { return new RefMatrixd(*this); }
432 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const RefMatrixd*>(obj)!=NULL; }
433 virtual const char* libraryName() const { return "osg"; }
434 virtual const char* className() const { return "Matrix"; }
435
436
437 protected:
438
439 virtual ~RefMatrixd() {}
440};
441
442
443// static utility methods
445{
446 Matrixd m;
447 m.makeIdentity();
448 return m;
449}
450
452{
453 Matrixd m;
454 m.makeScale(sx,sy,sz);
455 return m;
456}
457
458inline Matrixd Matrixd::scale(const Vec3f& v )
459{
460 return scale(v.x(), v.y(), v.z() );
461}
462
463inline Matrixd Matrixd::scale(const Vec3d& v )
464{
465 return scale(v.x(), v.y(), v.z() );
466}
467
469{
470 Matrixd m;
471 m.makeTranslate(tx,ty,tz);
472 return m;
473}
474
476{
477 return translate(v.x(), v.y(), v.z() );
478}
479
481{
482 return translate(v.x(), v.y(), v.z() );
483}
484
485inline Matrixd Matrixd::rotate( const Quat& q )
486{
487 return Matrixd(q);
488}
490{
491 Matrixd m;
492 m.makeRotate(angle,x,y,z);
493 return m;
494}
495inline Matrixd Matrixd::rotate(value_type angle, const Vec3f& axis )
496{
497 Matrixd m;
498 m.makeRotate(angle,axis);
499 return m;
500}
501inline Matrixd Matrixd::rotate(value_type angle, const Vec3d& axis )
502{
503 Matrixd m;
504 m.makeRotate(angle,axis);
505 return m;
506}
507inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1,
508 value_type angle2, const Vec3f& axis2,
509 value_type angle3, const Vec3f& axis3)
510{
511 Matrixd m;
512 m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
513 return m;
514}
515inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1,
516 value_type angle2, const Vec3d& axis2,
517 value_type angle3, const Vec3d& axis3)
518{
519 Matrixd m;
520 m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
521 return m;
522}
523inline Matrixd Matrixd::rotate(const Vec3f& from, const Vec3f& to )
524{
525 Matrixd m;
526 m.makeRotate(from,to);
527 return m;
528}
529inline Matrixd Matrixd::rotate(const Vec3d& from, const Vec3d& to )
530{
531 Matrixd m;
532 m.makeRotate(from,to);
533 return m;
534}
535
536inline Matrixd Matrixd::inverse( const Matrixd& matrix)
537{
538 Matrixd m;
539 m.invert(matrix);
540 return m;
541}
542
544{
545 Matrixd m;
546 m.orthoNormalize(matrix);
547 return m;
548}
549
550inline Matrixd Matrixd::ortho(double left, double right,
551 double bottom, double top,
552 double zNear, double zFar)
553{
554 Matrixd m;
555 m.makeOrtho(left,right,bottom,top,zNear,zFar);
556 return m;
557}
558
559inline Matrixd Matrixd::ortho2D(double left, double right,
560 double bottom, double top)
561{
562 Matrixd m;
563 m.makeOrtho2D(left,right,bottom,top);
564 return m;
565}
566
567inline Matrixd Matrixd::frustum(double left, double right,
568 double bottom, double top,
569 double zNear, double zFar)
570{
571 Matrixd m;
572 m.makeFrustum(left,right,bottom,top,zNear,zFar);
573 return m;
574}
575
576inline Matrixd Matrixd::perspective(double fovy, double aspectRatio,
577 double zNear, double zFar)
578{
579 Matrixd m;
580 m.makePerspective(fovy,aspectRatio,zNear,zFar);
581 return m;
582}
583
584inline Matrixd Matrixd::lookAt(const Vec3f& eye,
585 const Vec3f& center,
586 const Vec3f& up)
587{
588 Matrixd m;
589 m.makeLookAt(eye,center,up);
590 return m;
591}
592
593inline Matrixd Matrixd::lookAt(const Vec3d& eye,
594 const Vec3d& center,
595 const Vec3d& up)
596{
597 Matrixd m;
598 m.makeLookAt(eye,center,up);
599 return m;
600}
601
602inline Vec3f Matrixd::postMult( const Vec3f& v ) const
603{
604 value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
605 return Vec3f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
606 (_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
607 (_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
608}
609
610inline Vec3d Matrixd::postMult( const Vec3d& v ) const
611{
612 value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
613 return Vec3d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
614 (_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
615 (_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
616}
617
618inline Vec3f Matrixd::preMult( const Vec3f& v ) const
619{
620 value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
621 return Vec3f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
622 (_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
623 (_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
624}
625
626inline Vec3d Matrixd::preMult( const Vec3d& v ) const
627{
628 value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
629 return Vec3d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
630 (_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
631 (_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
632}
633
634inline Vec4f Matrixd::postMult( const Vec4f& v ) const
635{
636 return Vec4f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
637 (_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
638 (_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
639 (_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
640}
641inline Vec4d Matrixd::postMult( const Vec4d& v ) const
642{
643 return Vec4d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
644 (_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
645 (_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
646 (_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
647}
648
649inline Vec4f Matrixd::preMult( const Vec4f& v ) const
650{
651 return Vec4f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
652 (_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
653 (_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
654 (_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
655}
656
657inline Vec4d Matrixd::preMult( const Vec4d& v ) const
658{
659 return Vec4d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
660 (_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
661 (_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
662 (_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
663}
664
665inline Vec3f Matrixd::transform3x3(const Vec3f& v,const Matrixd& m)
666{
667 return Vec3f( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
668 (m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
669 (m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
670}
671inline Vec3d Matrixd::transform3x3(const Vec3d& v,const Matrixd& m)
672{
673 return Vec3d( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
674 (m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
675 (m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
676}
677
678inline Vec3f Matrixd::transform3x3(const Matrixd& m,const Vec3f& v)
679{
680 return Vec3f( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
681 (m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
682 (m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
683}
684inline Vec3d Matrixd::transform3x3(const Matrixd& m,const Vec3d& v)
685{
686 return Vec3d( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
687 (m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
688 (m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
689}
690
691inline void Matrixd::preMultTranslate( const Vec3d& v )
692{
693 for (unsigned i = 0; i < 3; ++i)
694 {
695 double tmp = v[i];
696 if (tmp == 0)
697 continue;
698 _mat[3][0] += tmp*_mat[i][0];
699 _mat[3][1] += tmp*_mat[i][1];
700 _mat[3][2] += tmp*_mat[i][2];
701 _mat[3][3] += tmp*_mat[i][3];
702 }
703}
704
705inline void Matrixd::preMultTranslate( const Vec3f& v )
706{
707 for (unsigned i = 0; i < 3; ++i)
708 {
709 float tmp = v[i];
710 if (tmp == 0)
711 continue;
712 _mat[3][0] += tmp*_mat[i][0];
713 _mat[3][1] += tmp*_mat[i][1];
714 _mat[3][2] += tmp*_mat[i][2];
715 _mat[3][3] += tmp*_mat[i][3];
716 }
717}
718
719inline void Matrixd::postMultTranslate( const Vec3d& v )
720{
721 for (unsigned i = 0; i < 3; ++i)
722 {
723 double tmp = v[i];
724 if (tmp == 0)
725 continue;
726 _mat[0][i] += tmp*_mat[0][3];
727 _mat[1][i] += tmp*_mat[1][3];
728 _mat[2][i] += tmp*_mat[2][3];
729 _mat[3][i] += tmp*_mat[3][3];
730 }
731}
732
733inline void Matrixd::postMultTranslate( const Vec3f& v )
734{
735 for (unsigned i = 0; i < 3; ++i)
736 {
737 float tmp = v[i];
738 if (tmp == 0)
739 continue;
740 _mat[0][i] += tmp*_mat[0][3];
741 _mat[1][i] += tmp*_mat[1][3];
742 _mat[2][i] += tmp*_mat[2][3];
743 _mat[3][i] += tmp*_mat[3][3];
744 }
745}
746
747inline void Matrixd::preMultScale( const Vec3d& v )
748{
749 _mat[0][0] *= v[0]; _mat[0][1] *= v[0]; _mat[0][2] *= v[0]; _mat[0][3] *= v[0];
750 _mat[1][0] *= v[1]; _mat[1][1] *= v[1]; _mat[1][2] *= v[1]; _mat[1][3] *= v[1];
751 _mat[2][0] *= v[2]; _mat[2][1] *= v[2]; _mat[2][2] *= v[2]; _mat[2][3] *= v[2];
752}
753
754inline void Matrixd::preMultScale( const Vec3f& v )
755{
756 _mat[0][0] *= v[0]; _mat[0][1] *= v[0]; _mat[0][2] *= v[0]; _mat[0][3] *= v[0];
757 _mat[1][0] *= v[1]; _mat[1][1] *= v[1]; _mat[1][2] *= v[1]; _mat[1][3] *= v[1];
758 _mat[2][0] *= v[2]; _mat[2][1] *= v[2]; _mat[2][2] *= v[2]; _mat[2][3] *= v[2];
759}
760
761inline void Matrixd::postMultScale( const Vec3d& v )
762{
763 _mat[0][0] *= v[0]; _mat[1][0] *= v[0]; _mat[2][0] *= v[0]; _mat[3][0] *= v[0];
764 _mat[0][1] *= v[1]; _mat[1][1] *= v[1]; _mat[2][1] *= v[1]; _mat[3][1] *= v[1];
765 _mat[0][2] *= v[2]; _mat[1][2] *= v[2]; _mat[2][2] *= v[2]; _mat[3][2] *= v[2];
766}
767
768inline void Matrixd::postMultScale( const Vec3f& v )
769{
770 _mat[0][0] *= v[0]; _mat[1][0] *= v[0]; _mat[2][0] *= v[0]; _mat[3][0] *= v[0];
771 _mat[0][1] *= v[1]; _mat[1][1] *= v[1]; _mat[2][1] *= v[1]; _mat[3][1] *= v[1];
772 _mat[0][2] *= v[2]; _mat[1][2] *= v[2]; _mat[2][2] *= v[2]; _mat[3][2] *= v[2];
773}
774
775inline void Matrixd::preMultRotate( const Quat& q )
776{
777 if (q.zeroRotation())
778 return;
779 Matrixd r;
780 r.setRotate(q);
781 preMult(r);
782}
783
784inline void Matrixd::postMultRotate( const Quat& q )
785{
786 if (q.zeroRotation())
787 return;
788 Matrixd r;
789 r.setRotate(q);
790 postMult(r);
791}
792
793inline Vec3f operator* (const Vec3f& v, const Matrixd& m )
794{
795 return m.preMult(v);
796}
797
798inline Vec3d operator* (const Vec3d& v, const Matrixd& m )
799{
800 return m.preMult(v);
801}
802
803inline Vec4f operator* (const Vec4f& v, const Matrixd& m )
804{
805 return m.preMult(v);
806}
807
808inline Vec4d operator* (const Vec4d& v, const Matrixd& m )
809{
810 return m.preMult(v);
811}
812
813inline Vec3f Matrixd::operator* (const Vec3f& v) const
814{
815 return postMult(v);
816}
817
818inline Vec3d Matrixd::operator* (const Vec3d& v) const
819{
820 return postMult(v);
821}
822
823inline Vec4f Matrixd::operator* (const Vec4f& v) const
824{
825 return postMult(v);
826}
827
828inline Vec4d Matrixd::operator* (const Vec4d& v) const
829{
830 return postMult(v);
831}
832
833
834} //namespace osg
835
836
837#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f operator*(const Vec3f &v, const Matrixd &m)
Definition Matrixd:793
T * get(unsigned int contextID)
Definition ContextData:152
bool isNaN(float v)
Definition Math:133
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
Definition Matrixd:27
void makeRotate(value_type angle, const Vec3d &axis)
Matrixd(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33)
float other_value_type
Definition Matrixd:31
void setRotate(const Quat &q)
Vec3d getScale() const
Definition Matrixd:348
~Matrixd()
Definition Matrixd:45
static Vec3f transform3x3(const Vec3f &v, const Matrixd &m)
apply a 3x3 transform of v*M[0..2,0..2].
Definition Matrixd:665
static Matrixd ortho2D(double left, double right, double bottom, double top)
Create a 2D orthographic projection.
Definition Matrixd:559
void postMultRotate(const Quat &q)
Optimized version of postMult(rotate(q));.
Definition Matrixd:784
bool isIdentity() const
Definition Matrixd:95
void makeRotate(const Vec3d &from, const Vec3d &to)
void set(const Matrixd &rhs)
Definition Matrixd:71
void setTrans(value_type tx, value_type ty, value_type tz)
void makeTranslate(value_type, value_type, value_type)
void preMultScale(const Vec3d &v)
Optimized version of preMult(scale(v));.
Definition Matrixd:747
void makeLookAt(const Vec3d &eye, const Vec3d &center, const Vec3d &up)
Set the position and orientation to be a view matrix, using the same convention as gluLookAt.
value_type _mat[4][4]
Definition Matrixd:407
Quat getRotate() const
Get the matrix rotation as a Quat.
void set(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33)
void makeRotate(value_type angle, const Vec3f &axis)
bool getOrtho(float &left, float &right, float &bottom, float &top, float &zNear, float &zFar) const
float version of getOrtho(..)
static Matrixd orthoNormal(const Matrixd &matrix)
Definition Matrixd:543
void setTrans(const Vec3f &v)
void postMultScale(const Vec3d &v)
Optimized version of postMult(scale(v));.
Definition Matrixd:761
Matrixd(const Matrixd &mat)
Definition Matrixd:34
Matrixd(const Matrixf &mat)
Matrixd()
Definition Matrixd:33
bool getPerspective(double &fovy, double &aspectRatio, double &zNear, double &zFar) const
Get the frustum settings of a symmetric perspective projection matrix.
bool invert_4x4(const Matrixd &rhs)
full 4x4 matrix invert.
static Matrixd frustum(double left, double right, double bottom, double top, double zNear, double zFar)
Create a perspective projection.
Definition Matrixd:567
void makeRotate(const Quat &)
void makeScale(const Vec3d &)
void makeScale(value_type, value_type, value_type)
value_type * ptr()
Definition Matrixd:92
bool transpose(const Matrixd &rhs)
transpose a matrix
void setTrans(const Vec3d &v)
Matrixd(float const *const ptr)
Definition Matrixd:36
static Matrixd lookAt(const Vec3f &eye, const Vec3f &center, const Vec3f &up)
Create the position and orientation as per a camera, using the same convention as gluLookAt.
Definition Matrixd:584
static Matrixd ortho(double left, double right, double bottom, double top, double zNear, double zFar)
Create an orthographic projection matrix.
Definition Matrixd:550
void makeFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
Set to a perspective projection.
Matrixd(const Quat &quat)
Definition Matrixd:38
void getLookAt(Vec3d &eye, Vec3d &center, Vec3d &up, value_type lookDistance=1.0f) const
Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt.
void orthoNormalize(const Matrixd &rhs)
ortho-normalize the 3x3 rotation & scale matrix
Matrixd(double const *const ptr)
Definition Matrixd:37
int compare(const Matrixd &m) const
void preMultTranslate(const Vec3d &v)
Optimized version of preMult(translate(v));.
Definition Matrixd:691
void makeRotate(value_type angle1, const Vec3d &axis1, value_type angle2, const Vec3d &axis2, value_type angle3, const Vec3d &axis3)
const value_type * ptr() const
Definition Matrixd:93
Vec3f operator*(const Vec3f &v) const
Definition Matrixd:813
Vec3f preMult(const Vec3f &v) const
Definition Matrixd:618
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
value_type operator()(int row, int col) const
Definition Matrixd:54
static Matrixd scale(const Vec3f &sv)
Definition Matrixd:458
bool valid() const
Definition Matrixd:56
static Matrixd perspective(double fovy, double aspectRatio, double zNear, double zFar)
Create a symmetrical perspective projection.
Definition Matrixd:576
void makeTranslate(const Vec3f &)
void set(float const *const ptr)
Definition Matrixd:75
void postMult(const Matrixd &)
Vec3d getTrans() const
Definition Matrixd:346
void makeOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
Set to an orthographic projection.
static Matrixd rotate(const Vec3f &from, const Vec3f &to)
Definition Matrixd:523
void makeScale(const Vec3f &)
static Matrixd inverse(const Matrixd &matrix)
Definition Matrixd:536
Vec3f postMult(const Vec3f &v) const
Definition Matrixd:602
value_type & operator()(int row, int col)
Definition Matrixd:53
void decompose(osg::Vec3d &translation, osg::Quat &rotation, osg::Vec3d &scale, osg::Quat &so) const
decompose the matrix into translation, rotation, scale and scale orientation.
void set(const Matrixf &rhs)
void getLookAt(Vec3f &eye, Vec3f &center, Vec3f &up, value_type lookDistance=1.0f) const
Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt.
bool getOrtho(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the orthographic settings of the orthographic projection matrix.
void makeOrtho2D(double left, double right, double bottom, double top)
Set to a 2D orthographic projection.
Definition Matrixd:164
bool invert_4x3(const Matrixd &rhs)
4x3 matrix invert, not right hand column is assumed to be 0,0,0,1.
double value_type
Definition Matrixd:30
void preMultRotate(const Quat &q)
Optimized version of preMult(rotate(q));.
Definition Matrixd:775
static Matrixd translate(const Vec3f &dv)
Definition Matrixd:475
void preMult(const Matrixd &)
void makeTranslate(const Vec3d &)
void makeRotate(value_type angle1, const Vec3f &axis1, value_type angle2, const Vec3f &axis2, value_type angle3, const Vec3f &axis3)
bool getFrustum(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the frustum settings of a perspective projection matrix.
void makePerspective(double fovy, double aspectRatio, double zNear, double zFar)
Set to a symmetrical perspective projection.
void postMultTranslate(const Vec3d &v)
Optimized version of postMult(translate(v));.
Definition Matrixd:719
void makeRotate(const Vec3f &from, const Vec3f &to)
bool getPerspective(float &fovy, float &aspectRatio, float &zNear, float &zFar) const
float version of getPerspective(..)
bool invert(const Matrixd &rhs)
invert the matrix rhs, automatically select invert_4x3 or invert_4x4.
Definition Matrixd:233
static Matrixd identity(void)
Definition Matrixd:444
bool getFrustum(float &left, float &right, float &bottom, float &top, float &zNear, float &zFar) const
float version of getFrustum(..)
void decompose(osg::Vec3f &translation, osg::Quat &rotation, osg::Vec3f &scale, osg::Quat &so) const
decompose the matrix into translation, rotation, scale and scale orientation.
bool isNaN() const
Definition Matrixd:57
void makeIdentity()
void mult(const Matrixd &, const Matrixd &)
void set(double const *const ptr)
Definition Matrixd:81
bool transpose3x3(const Matrixd &rhs)
transpose orthogonal part of the matrix
RefMatrixd(Matrixd::value_type a00, Matrixd::value_type a01, Matrixd::value_type a02, Matrixd::value_type a03, Matrixd::value_type a10, Matrixd::value_type a11, Matrixd::value_type a12, Matrixd::value_type a13, Matrixd::value_type a20, Matrixd::value_type a21, Matrixd::value_type a22, Matrixd::value_type a23, Matrixd::value_type a30, Matrixd::value_type a31, Matrixd::value_type a32, Matrixd::value_type a33)
Definition Matrixd:420
RefMatrixd(const Matrixf &other)
Definition Matrixd:417
virtual bool isSameKindAs(const Object *obj) const
Definition Matrixd:432
RefMatrixd(Matrixd::value_type const *const def)
Definition Matrixd:419
virtual Object * cloneType() const
Clone the type of an object, with Object* return type.
Definition Matrixd:430
RefMatrixd(const RefMatrixd &other)
Definition Matrixd:418
virtual Object * clone(const CopyOp &) const
Clone an object, with Object* return type.
Definition Matrixd:431
RefMatrixd()
Definition Matrixd:415
virtual const char * libraryName() const
return the name of the object's library.
Definition Matrixd:433
virtual ~RefMatrixd()
Definition Matrixd:439
RefMatrixd(const Matrixd &other)
Definition Matrixd:416
virtual const char * className() const
return the name of the object's class type.
Definition Matrixd:434
Definition Matrixf:27
Object()
Construct an object.
Definition Object:69
A quaternion class.
Definition Quat:30
bool zeroRotation() const
return true if the Quat represents a zero rotation, and therefore can be ignored in computations.
Definition Quat:173
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
value_type & z()
Definition Vec3d:87
value_type & x()
Definition Vec3d:85
value_type & y()
Definition Vec3d:86
value_type length() const
Length of the vector = sqrt( vec .
Definition Vec3d:181
General purpose float triple for use as vertices, vectors and normals.
Definition Vec3f:29
value_type & z()
Definition Vec3f:82
value_type & y()
Definition Vec3f:81
value_type & x()
Definition Vec3f:80
General purpose double quad.
Definition Vec4d:29
value_type & x()
Definition Vec4d:90
value_type & y()
Definition Vec4d:91
value_type & z()
Definition Vec4d:92
value_type & w()
Definition Vec4d:93
General purpose float quad.
Definition Vec4f:28
value_type & y()
Definition Vec4f:88
value_type & x()
Definition Vec4f:87
value_type & z()
Definition Vec4f:89
value_type & w()
Definition Vec4f:90
#define NULL
Definition Export:55
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.