1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
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.
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.
26class OSG_EXPORT Matrixd
30 typedef double value_type;
31 typedef float other_value_type;
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); }
40 Matrixd(value_type a00, value_type a01, value_type a02, value_type a03,
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);
47 int compare(const Matrixd& m) const;
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; }
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]; }
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]); }
62 inline Matrixd& operator = (const Matrixd& rhs)
64 if( &rhs == this ) return *this;
69 Matrixd& operator = (const Matrixf& other);
71 inline void set(const Matrixd& rhs) { set(rhs.ptr()); }
73 void set(const Matrixf& rhs);
75 inline void set(float const * const ptr)
77 value_type* local_ptr = (value_type*)_mat;
78 for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
81 inline void set(double const * const ptr)
83 value_type* local_ptr = (value_type*)_mat;
84 for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
87 void set(value_type a00, value_type a01, value_type a02,value_type a03,
88 value_type a10, value_type a11, value_type a12,value_type a13,
89 value_type a20, value_type a21, value_type a22,value_type a23,
90 value_type a30, value_type a31, value_type a32,value_type a33);
92 value_type * ptr() { return (value_type*)_mat; }
93 const value_type * ptr() const { return (const value_type *)_mat; }
95 bool isIdentity() const
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;
105 void makeScale( const Vec3f& );
106 void makeScale( const Vec3d& );
107 void makeScale( value_type, value_type, value_type );
109 void makeTranslate( const Vec3f& );
110 void makeTranslate( const Vec3d& );
111 void makeTranslate( value_type, value_type, value_type );
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 );
117 void makeRotate( value_type angle, value_type x, value_type y, value_type z );
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);
127 /** decompose the matrix into translation, rotation, scale and scale orientation.*/
128 void decompose( osg::Vec3f& translation,
131 osg::Quat& so ) const;
133 /** decompose the matrix into translation, rotation, scale and scale orientation.*/
134 void decompose( osg::Vec3d& translation,
137 osg::Quat& so ) const;
140 /** Set to an orthographic projection.
141 * See glOrtho for further details.
143 void makeOrtho(double left, double right,
144 double bottom, double top,
145 double zNear, double zFar);
147 /** Get the orthographic settings of the orthographic projection matrix.
148 * Note, if matrix is not an orthographic matrix then invalid values
151 bool getOrtho(double& left, double& right,
152 double& bottom, double& top,
153 double& zNear, double& zFar) const;
155 /** float version of getOrtho(..) */
156 bool getOrtho(float& left, float& right,
157 float& bottom, float& top,
158 float& zNear, float& zFar) const;
161 /** Set to a 2D orthographic projection.
162 * See glOrtho2D for further details.
164 inline void makeOrtho2D(double left, double right,
165 double bottom, double top)
167 makeOrtho(left,right,bottom,top,-1.0,1.0);
171 /** Set to a perspective projection.
172 * See glFrustum for further details.
174 void makeFrustum(double left, double right,
175 double bottom, double top,
176 double zNear, double zFar);
178 /** Get the frustum settings of a perspective projection matrix.
179 * Note, if matrix is not a perspective matrix then invalid values
182 bool getFrustum(double& left, double& right,
183 double& bottom, double& top,
184 double& zNear, double& zFar) const;
186 /** float version of getFrustum(..) */
187 bool getFrustum(float& left, float& right,
188 float& bottom, float& top,
189 float& zNear, float& zFar) const;
191 /** Set to a symmetrical perspective projection.
192 * See gluPerspective for further details.
193 * Aspect ratio is defined as width/height.
195 void makePerspective(double fovy, double aspectRatio,
196 double zNear, double zFar);
198 /** Get the frustum settings of a symmetric perspective projection
200 * Return false if matrix is not a perspective matrix,
201 * where parameter values are undefined.
202 * Note, if matrix is not a symmetric perspective matrix then the
203 * shear will be lost.
204 * Asymmetric matrices occur when stereo, power walls, caves and
205 * reality center display are used.
206 * In these configuration one should use the AsFrustum method instead.
208 bool getPerspective(double& fovy, double& aspectRatio,
209 double& zNear, double& zFar) const;
211 /** float version of getPerspective(..) */
212 bool getPerspective(float& fovy, float& aspectRatio,
213 float& zNear, float& zFar) const;
215 /** Set the position and orientation to be a view matrix,
216 * using the same convention as gluLookAt.
218 void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
220 /** Get to the position and orientation of a modelview matrix,
221 * using the same convention as gluLookAt.
223 void getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,
224 value_type lookDistance=1.0f) const;
226 /** Get to the position and orientation of a modelview matrix,
227 * using the same convention as gluLookAt.
229 void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,
230 value_type lookDistance=1.0f) const;
232 /** invert the matrix rhs, automatically select invert_4x3 or invert_4x4. */
233 inline bool invert( const Matrixd& rhs)
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);
239 /** 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. */
240 bool invert_4x3( const Matrixd& rhs);
242 /** full 4x4 matrix invert. */
243 bool invert_4x4( const Matrixd& rhs);
245 /** transpose a matrix */
246 bool transpose(const Matrixd&rhs);
248 /** transpose orthogonal part of the matrix **/
249 bool transpose3x3(const Matrixd&rhs);
251 /** ortho-normalize the 3x3 rotation & scale matrix */
252 void orthoNormalize(const Matrixd& rhs);
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);
276 /** Create an orthographic projection matrix.
277 * See glOrtho for further details.
279 inline static Matrixd ortho(double left, double right,
280 double bottom, double top,
281 double zNear, double zFar);
283 /** Create a 2D orthographic projection.
284 * See glOrtho for further details.
286 inline static Matrixd ortho2D(double left, double right,
287 double bottom, double top);
289 /** Create a perspective projection.
290 * See glFrustum for further details.
292 inline static Matrixd frustum(double left, double right,
293 double bottom, double top,
294 double zNear, double zFar);
296 /** Create a symmetrical perspective projection.
297 * See gluPerspective for further details.
298 * Aspect ratio is defined as width/height.
300 inline static Matrixd perspective(double fovy, double aspectRatio,
301 double zNear, double zFar);
303 /** Create the position and orientation as per a camera,
304 * using the same convention as gluLookAt.
306 inline static Matrixd lookAt(const Vec3f& eye,
310 /** Create the position and orientation as per a camera,
311 * using the same convention as gluLookAt.
313 inline static Matrixd lookAt(const Vec3d& eye,
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;
330#ifdef OSG_USE_DEPRECATED_API
331 inline void set(const Quat& q) { makeRotate(q); } /// deprecated, replace with makeRotate(q)
332 inline void get(Quat& q) const { q = getRotate(); } /// deprecated, replace with getRotate()
335 void setRotate(const Quat& q);
336 /** Get the matrix rotation as a Quat. Note that this function
337 * assumes a non-scaled matrix and will return incorrect results
338 * for scaled matrixces. Consider decompose() instead.
340 Quat getRotate() const;
342 void setTrans( value_type tx, value_type ty, value_type tz );
343 void setTrans( const Vec3f& v );
344 void setTrans( const Vec3d& v );
346 inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); }
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());
355 /** apply a 3x3 transform of v*M[0..2,0..2]. */
356 inline static Vec3f transform3x3(const Vec3f& v,const Matrixd& m);
358 /** apply a 3x3 transform of v*M[0..2,0..2]. */
359 inline static Vec3d transform3x3(const Vec3d& v,const Matrixd& m);
361 /** apply a 3x3 transform of M[0..2,0..2]*v. */
362 inline static Vec3f transform3x3(const Matrixd& m,const Vec3f& v);
364 /** apply a 3x3 transform of M[0..2,0..2]*v. */
365 inline static Vec3d transform3x3(const Matrixd& m,const Vec3d& v);
367 // basic Matrixd multiplication, our workhorse methods.
368 void mult( const Matrixd&, const Matrixd& );
369 void preMult( const Matrixd& );
370 void postMult( const Matrixd& );
372 /** Optimized version of preMult(translate(v)); */
373 inline void preMultTranslate( const Vec3d& v );
374 inline void preMultTranslate( const Vec3f& v );
375 /** Optimized version of postMult(translate(v)); */
376 inline void postMultTranslate( const Vec3d& v );
377 inline void postMultTranslate( const Vec3f& v );
379 /** Optimized version of preMult(scale(v)); */
380 inline void preMultScale( const Vec3d& v );
381 inline void preMultScale( const Vec3f& v );
382 /** Optimized version of postMult(scale(v)); */
383 inline void postMultScale( const Vec3d& v );
384 inline void postMultScale( const Vec3f& v );
386 /** Optimized version of preMult(rotate(q)); */
387 inline void preMultRotate( const Quat& q );
388 /** Optimized version of postMult(rotate(q)); */
389 inline void postMultRotate( const Quat& q );
391 inline void operator *= ( const Matrixd& other )
392 { if( this == &other ) {
396 else postMult( other );
399 inline Matrixd operator * ( const Matrixd &m ) const
407 value_type _mat[4][4];
411class RefMatrixd : public Object, public Matrixd
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) {}
420 RefMatrixd( Matrixd::value_type a00, Matrixd::value_type a01, Matrixd::value_type a02, Matrixd::value_type a03,
421 Matrixd::value_type a10, Matrixd::value_type a11, Matrixd::value_type a12, Matrixd::value_type a13,
422 Matrixd::value_type a20, Matrixd::value_type a21, Matrixd::value_type a22, Matrixd::value_type a23,
423 Matrixd::value_type a30, Matrixd::value_type a31, Matrixd::value_type a32, Matrixd::value_type a33):
425 Matrixd(a00, a01, a02, a03,
428 a30, a31, a32, a33) {}
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"; }
439 virtual ~RefMatrixd() {}
443// static utility methods
444inline Matrixd Matrixd::identity(void)
451inline Matrixd Matrixd::scale(value_type sx, value_type sy, value_type sz)
454 m.makeScale(sx,sy,sz);
458inline Matrixd Matrixd::scale(const Vec3f& v )
460 return scale(v.x(), v.y(), v.z() );
463inline Matrixd Matrixd::scale(const Vec3d& v )
465 return scale(v.x(), v.y(), v.z() );
468inline Matrixd Matrixd::translate(value_type tx, value_type ty, value_type tz)
471 m.makeTranslate(tx,ty,tz);
475inline Matrixd Matrixd::translate(const Vec3f& v )
477 return translate(v.x(), v.y(), v.z() );
480inline Matrixd Matrixd::translate(const Vec3d& v )
482 return translate(v.x(), v.y(), v.z() );
485inline Matrixd Matrixd::rotate( const Quat& q )
489inline Matrixd Matrixd::rotate(value_type angle, value_type x, value_type y, value_type z )
492 m.makeRotate(angle,x,y,z);
495inline Matrixd Matrixd::rotate(value_type angle, const Vec3f& axis )
498 m.makeRotate(angle,axis);
501inline Matrixd Matrixd::rotate(value_type angle, const Vec3d& axis )
504 m.makeRotate(angle,axis);
507inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1,
508 value_type angle2, const Vec3f& axis2,
509 value_type angle3, const Vec3f& axis3)
512 m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
515inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1,
516 value_type angle2, const Vec3d& axis2,
517 value_type angle3, const Vec3d& axis3)
520 m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
523inline Matrixd Matrixd::rotate(const Vec3f& from, const Vec3f& to )
526 m.makeRotate(from,to);
529inline Matrixd Matrixd::rotate(const Vec3d& from, const Vec3d& to )
532 m.makeRotate(from,to);
536inline Matrixd Matrixd::inverse( const Matrixd& matrix)
543inline Matrixd Matrixd::orthoNormal(const Matrixd& matrix)
546 m.orthoNormalize(matrix);
550inline Matrixd Matrixd::ortho(double left, double right,
551 double bottom, double top,
552 double zNear, double zFar)
555 m.makeOrtho(left,right,bottom,top,zNear,zFar);
559inline Matrixd Matrixd::ortho2D(double left, double right,
560 double bottom, double top)
563 m.makeOrtho2D(left,right,bottom,top);
567inline Matrixd Matrixd::frustum(double left, double right,
568 double bottom, double top,
569 double zNear, double zFar)
572 m.makeFrustum(left,right,bottom,top,zNear,zFar);
576inline Matrixd Matrixd::perspective(double fovy, double aspectRatio,
577 double zNear, double zFar)
580 m.makePerspective(fovy,aspectRatio,zNear,zFar);
584inline Matrixd Matrixd::lookAt(const Vec3f& eye,
589 m.makeLookAt(eye,center,up);
593inline Matrixd Matrixd::lookAt(const Vec3d& eye,
598 m.makeLookAt(eye,center,up);
602inline Vec3f Matrixd::postMult( const Vec3f& v ) const
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) ;
610inline Vec3d Matrixd::postMult( const Vec3d& v ) const
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) ;
618inline Vec3f Matrixd::preMult( const Vec3f& v ) const
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);
626inline Vec3d Matrixd::preMult( const Vec3d& v ) const
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);
634inline Vec4f Matrixd::postMult( const Vec4f& v ) const
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())) ;
641inline Vec4d Matrixd::postMult( const Vec4d& v ) const
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())) ;
649inline Vec4f Matrixd::preMult( const Vec4f& v ) const
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()));
657inline Vec4d Matrixd::preMult( const Vec4d& v ) const
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()));
665inline Vec3f Matrixd::transform3x3(const Vec3f& v,const Matrixd& m)
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()));
671inline Vec3d Matrixd::transform3x3(const Vec3d& v,const Matrixd& m)
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()));
678inline Vec3f Matrixd::transform3x3(const Matrixd& m,const Vec3f& v)
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()) ) ;
684inline Vec3d Matrixd::transform3x3(const Matrixd& m,const Vec3d& v)
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()) ) ;
691inline void Matrixd::preMultTranslate( const Vec3d& v )
693 for (unsigned i = 0; i < 3; ++i)
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];
705inline void Matrixd::preMultTranslate( const Vec3f& v )
707 for (unsigned i = 0; i < 3; ++i)
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];
719inline void Matrixd::postMultTranslate( const Vec3d& v )
721 for (unsigned i = 0; i < 3; ++i)
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];
733inline void Matrixd::postMultTranslate( const Vec3f& v )
735 for (unsigned i = 0; i < 3; ++i)
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];
747inline void Matrixd::preMultScale( const Vec3d& v )
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];
754inline void Matrixd::preMultScale( const Vec3f& v )
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];
761inline void Matrixd::postMultScale( const Vec3d& v )
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];
768inline void Matrixd::postMultScale( const Vec3f& v )
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];
775inline void Matrixd::preMultRotate( const Quat& q )
777 if (q.zeroRotation())
784inline void Matrixd::postMultRotate( const Quat& q )
786 if (q.zeroRotation())
793inline Vec3f operator* (const Vec3f& v, const Matrixd& m )
798inline Vec3d operator* (const Vec3d& v, const Matrixd& m )
803inline Vec4f operator* (const Vec4f& v, const Matrixd& m )
808inline Vec4d operator* (const Vec4d& v, const Matrixd& m )
813inline Vec3f Matrixd::operator* (const Vec3f& v) const
818inline Vec3d Matrixd::operator* (const Vec3d& v) const
823inline Vec4f Matrixd::operator* (const Vec4f& v) const
828inline Vec4d Matrixd::operator* (const Vec4d& v) const