2004-08-31 21:19:30 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
2003-09-06 04:48:42 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_MATRIXD
|
|
|
|
#define OSG_MATRIXD 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
2004-05-20 18:15:48 +08:00
|
|
|
#include <osg/Vec3d>
|
|
|
|
#include <osg/Vec4d>
|
2003-09-06 04:48:42 +08:00
|
|
|
#include <osg/Quat>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2003-09-06 06:35:34 +08:00
|
|
|
class Matrixf;
|
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Matrixd
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2003-09-09 16:56:51 +08:00
|
|
|
typedef double value_type;
|
2003-09-06 04:48:42 +08:00
|
|
|
|
|
|
|
inline Matrixd() { makeIdentity(); }
|
2003-09-06 06:35:34 +08:00
|
|
|
inline Matrixd( const Matrixd& mat) { set(mat.ptr()); }
|
|
|
|
Matrixd( const Matrixf& mat );
|
2003-09-06 04:48:42 +08:00
|
|
|
inline explicit Matrixd( float const * const ptr ) { set(ptr); }
|
|
|
|
inline explicit Matrixd( double const * const ptr ) { set(ptr); }
|
2006-08-01 01:31:21 +08:00
|
|
|
inline explicit Matrixd( const Quat& quat ) { makeRotate(quat); }
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
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);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
|
|
|
~Matrixd() {}
|
|
|
|
|
2005-04-17 18:41:23 +08:00
|
|
|
int compare(const Matrixd& m) const;
|
2003-09-06 04:48:42 +08:00
|
|
|
|
|
|
|
bool operator < (const Matrixd& m) const { return compare(m)<0; }
|
|
|
|
bool operator == (const Matrixd& m) const { return compare(m)==0; }
|
|
|
|
bool operator != (const Matrixd& m) const { return compare(m)!=0; }
|
|
|
|
|
|
|
|
inline value_type& operator()(int row, int col) { return _mat[row][col]; }
|
|
|
|
inline value_type operator()(int row, int col) const { return _mat[row][col]; }
|
|
|
|
|
|
|
|
inline bool valid() const { return !isNaN(); }
|
|
|
|
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]) ||
|
|
|
|
osg::isNaN(_mat[1][0]) || osg::isNaN(_mat[1][1]) || osg::isNaN(_mat[1][2]) || osg::isNaN(_mat[1][3]) ||
|
|
|
|
osg::isNaN(_mat[2][0]) || osg::isNaN(_mat[2][1]) || osg::isNaN(_mat[2][2]) || osg::isNaN(_mat[2][3]) ||
|
|
|
|
osg::isNaN(_mat[3][0]) || osg::isNaN(_mat[3][1]) || osg::isNaN(_mat[3][2]) || osg::isNaN(_mat[3][3]); }
|
|
|
|
|
2003-09-06 06:35:34 +08:00
|
|
|
inline Matrixd& operator = (const Matrixd& rhs)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2003-09-06 06:35:34 +08:00
|
|
|
if( &rhs == this ) return *this;
|
|
|
|
set(rhs.ptr());
|
2003-09-06 04:48:42 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
Matrixd& operator = (const Matrixf& other);
|
2003-09-06 06:35:34 +08:00
|
|
|
|
|
|
|
inline void set(const Matrixd& rhs) { set(rhs.ptr()); }
|
|
|
|
|
|
|
|
void set(const Matrixf& rhs);
|
|
|
|
|
2003-09-06 04:48:42 +08:00
|
|
|
inline void set(float const * const ptr)
|
|
|
|
{
|
2003-09-06 06:35:34 +08:00
|
|
|
value_type* local_ptr = (value_type*)_mat;
|
|
|
|
for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void set(double const * const ptr)
|
|
|
|
{
|
2003-09-06 06:35:34 +08:00
|
|
|
value_type* local_ptr = (value_type*)_mat;
|
|
|
|
for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
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);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
|
|
|
value_type * ptr() { return (value_type*)_mat; }
|
|
|
|
const value_type * ptr() const { return (const value_type *)_mat; }
|
|
|
|
|
2006-11-25 05:10:57 +08:00
|
|
|
bool isIdentity() const
|
|
|
|
{
|
|
|
|
return _mat[0][0]==1.0 && _mat[0][1]==0.0 && _mat[0][2]==0.0 && _mat[0][3]==0.0 &&
|
|
|
|
_mat[1][0]==0.0 && _mat[1][1]==1.0 && _mat[1][2]==0.0 && _mat[1][3]==0.0 &&
|
|
|
|
_mat[2][0]==0.0 && _mat[2][1]==0.0 && _mat[2][2]==1.0 && _mat[2][3]==0.0 &&
|
|
|
|
_mat[3][0]==0.0 && _mat[3][1]==0.0 && _mat[3][2]==0.0 && _mat[3][3]==1.0;
|
|
|
|
}
|
2007-02-11 02:01:37 +08:00
|
|
|
|
|
|
|
void makeIdentity();
|
2006-11-25 05:10:57 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeScale( const Vec3f& );
|
|
|
|
void makeScale( const Vec3d& );
|
2003-09-06 04:48:42 +08:00
|
|
|
void makeScale( value_type, value_type, value_type );
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeTranslate( const Vec3f& );
|
|
|
|
void makeTranslate( const Vec3d& );
|
2003-09-06 04:48:42 +08:00
|
|
|
void makeTranslate( value_type, value_type, value_type );
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeRotate( const Vec3f& from, const Vec3f& to );
|
|
|
|
void makeRotate( const Vec3d& from, const Vec3d& to );
|
|
|
|
void makeRotate( value_type angle, const Vec3f& axis );
|
|
|
|
void makeRotate( value_type angle, const Vec3d& axis );
|
2004-01-10 04:33:23 +08:00
|
|
|
void makeRotate( value_type angle, value_type x, value_type y, value_type z );
|
2003-09-06 04:48:42 +08:00
|
|
|
void makeRotate( const Quat& );
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeRotate( value_type angle1, const Vec3f& axis1,
|
|
|
|
value_type angle2, const Vec3f& axis2,
|
|
|
|
value_type angle3, const Vec3f& axis3);
|
|
|
|
void makeRotate( value_type angle1, const Vec3d& axis1,
|
|
|
|
value_type angle2, const Vec3d& axis2,
|
|
|
|
value_type angle3, const Vec3d& axis3);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2007-02-11 02:01:37 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** decompose the matrix into translation, rotation, scale and scale orientation.*/
|
2007-02-11 02:01:37 +08:00
|
|
|
void decompose( osg::Vec3f& translation,
|
|
|
|
osg::Quat& rotation,
|
|
|
|
osg::Vec3f& scale,
|
|
|
|
osg::Quat& so ) const;
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** decompose the matrix into translation, rotation, scale and scale orientation.*/
|
2007-02-11 02:01:37 +08:00
|
|
|
void decompose( osg::Vec3d& translation,
|
|
|
|
osg::Quat& rotation,
|
|
|
|
osg::Vec3d& scale,
|
|
|
|
osg::Quat& so ) const;
|
|
|
|
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Set to an orthographic projection.
|
|
|
|
* See glOrtho for further details.
|
|
|
|
*/
|
|
|
|
void makeOrtho(double left, double right,
|
2003-09-06 04:48:42 +08:00
|
|
|
double bottom, double top,
|
2004-08-31 21:19:30 +08:00
|
|
|
double zNear, double zFar);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the orthographic settings of the orthographic projection matrix.
|
2004-08-31 21:19:30 +08:00
|
|
|
* Note, if matrix is not an orthographic matrix then invalid values
|
|
|
|
* will be returned.
|
|
|
|
*/
|
|
|
|
bool getOrtho(double& left, double& right,
|
2003-09-06 04:48:42 +08:00
|
|
|
double& bottom, double& top,
|
2004-08-31 21:19:30 +08:00
|
|
|
double& zNear, double& zFar) const;
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Set to a 2D orthographic projection.
|
|
|
|
* See glOrtho2D for further details.
|
|
|
|
*/
|
|
|
|
inline void makeOrtho2D(double left, double right,
|
2003-09-06 04:48:42 +08:00
|
|
|
double bottom, double top)
|
|
|
|
{
|
|
|
|
makeOrtho(left,right,bottom,top,-1.0,1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Set to a perspective projection.
|
|
|
|
* See glFrustum for further details.
|
|
|
|
*/
|
|
|
|
void makeFrustum(double left, double right,
|
2003-09-06 04:48:42 +08:00
|
|
|
double bottom, double top,
|
2004-08-31 21:19:30 +08:00
|
|
|
double zNear, double zFar);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Get the frustum settings of a perspective projection matrix.
|
|
|
|
* Note, if matrix is not a perspective matrix then invalid values
|
|
|
|
* will be returned.
|
|
|
|
*/
|
|
|
|
bool getFrustum(double& left, double& right,
|
2003-09-29 21:14:34 +08:00
|
|
|
double& bottom, double& top,
|
2004-08-31 21:19:30 +08:00
|
|
|
double& zNear, double& zFar) const;
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Set to a symmetrical perspective projection.
|
|
|
|
* See gluPerspective for further details.
|
|
|
|
* Aspect ratio is defined as width/height.
|
|
|
|
*/
|
|
|
|
void makePerspective(double fovy, double aspectRatio,
|
2003-09-06 04:48:42 +08:00
|
|
|
double zNear, double zFar);
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Get the frustum settings of a symmetric perspective projection
|
|
|
|
* matrix.
|
|
|
|
* Return false if matrix is not a perspective matrix,
|
|
|
|
* where parameter values are undefined.
|
|
|
|
* Note, if matrix is not a symmetric perspective matrix then the
|
|
|
|
* shear will be lost.
|
|
|
|
* Asymmetric matrices occur when stereo, power walls, caves and
|
|
|
|
* reality center display are used.
|
|
|
|
* In these configuration one should use the AsFrustum method instead.
|
|
|
|
*/
|
|
|
|
bool getPerspective(double& fovy, double& aspectRatio,
|
2004-01-24 00:09:56 +08:00
|
|
|
double& zNear, double& zFar) const;
|
2003-09-29 21:14:34 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Set the position and orientation to be a view matrix,
|
|
|
|
* using the same convention as gluLookAt.
|
|
|
|
*/
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Get to the position and orientation of a modelview matrix,
|
|
|
|
* using the same convention as gluLookAt.
|
|
|
|
*/
|
|
|
|
void getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,
|
|
|
|
value_type lookDistance=1.0f) const;
|
2004-05-20 18:15:48 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Get to the position and orientation of a modelview matrix,
|
|
|
|
* using the same convention as gluLookAt.
|
|
|
|
*/
|
|
|
|
void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,
|
|
|
|
value_type lookDistance=1.0f) const;
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2006-07-28 21:48:08 +08:00
|
|
|
/** invert the matrix rhs, automatically select invert_4x3 or invert_4x4. */
|
|
|
|
inline bool invert( const Matrixd& rhs)
|
|
|
|
{
|
2006-07-31 22:49:36 +08:00
|
|
|
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);
|
|
|
|
return is_4x3 ? invert_4x3(rhs) : invert_4x4(rhs);
|
2006-07-28 21:48:08 +08:00
|
|
|
}
|
2004-01-12 22:22:18 +08:00
|
|
|
|
2006-07-28 21:48:08 +08:00
|
|
|
/** 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. */
|
|
|
|
bool invert_4x3( const Matrixd& rhs);
|
2004-01-12 22:22:18 +08:00
|
|
|
|
|
|
|
/** full 4x4 matrix invert. */
|
2006-07-28 21:48:08 +08:00
|
|
|
bool invert_4x4( const Matrixd& rhs);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2005-05-31 14:21:16 +08:00
|
|
|
/** ortho-normalize the 3x3 rotation & scale matrix */
|
|
|
|
void orthoNormalize(const Matrixd& rhs);
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
// basic utility functions to create new matrices
|
|
|
|
inline static Matrixd identity( void );
|
2004-05-20 18:15:48 +08:00
|
|
|
inline static Matrixd scale( const Vec3f& sv);
|
|
|
|
inline static Matrixd scale( const Vec3d& sv);
|
2003-09-06 04:48:42 +08:00
|
|
|
inline static Matrixd scale( value_type sx, value_type sy, value_type sz);
|
2004-05-20 18:15:48 +08:00
|
|
|
inline static Matrixd translate( const Vec3f& dv);
|
|
|
|
inline static Matrixd translate( const Vec3d& dv);
|
2003-09-06 04:48:42 +08:00
|
|
|
inline static Matrixd translate( value_type x, value_type y, value_type z);
|
2004-05-20 18:15:48 +08:00
|
|
|
inline static Matrixd rotate( const Vec3f& from, const Vec3f& to);
|
|
|
|
inline static Matrixd rotate( const Vec3d& from, const Vec3d& to);
|
2004-01-10 04:33:23 +08:00
|
|
|
inline static Matrixd rotate( value_type angle, value_type x, value_type y, value_type z);
|
2004-05-20 18:15:48 +08:00
|
|
|
inline static Matrixd rotate( value_type angle, const Vec3f& axis);
|
|
|
|
inline static Matrixd rotate( value_type angle, const Vec3d& axis);
|
|
|
|
inline static Matrixd rotate( value_type angle1, const Vec3f& axis1,
|
|
|
|
value_type angle2, const Vec3f& axis2,
|
|
|
|
value_type angle3, const Vec3f& axis3);
|
|
|
|
inline static Matrixd rotate( value_type angle1, const Vec3d& axis1,
|
|
|
|
value_type angle2, const Vec3d& axis2,
|
|
|
|
value_type angle3, const Vec3d& axis3);
|
2003-09-06 04:48:42 +08:00
|
|
|
inline static Matrixd rotate( const Quat& quat);
|
|
|
|
inline static Matrixd inverse( const Matrixd& matrix);
|
2005-05-31 14:21:16 +08:00
|
|
|
inline static Matrixd orthoNormal(const Matrixd& matrix);
|
2004-08-31 21:19:30 +08:00
|
|
|
/** Create an orthographic projection matrix.
|
|
|
|
* See glOrtho for further details.
|
|
|
|
*/
|
|
|
|
inline static Matrixd ortho(double left, double right,
|
|
|
|
double bottom, double top,
|
|
|
|
double zNear, double zFar);
|
|
|
|
|
|
|
|
/** Create a 2D orthographic projection.
|
|
|
|
* See glOrtho for further details.
|
|
|
|
*/
|
|
|
|
inline static Matrixd ortho2D(double left, double right,
|
|
|
|
double bottom, double top);
|
|
|
|
|
|
|
|
/** Create a perspective projection.
|
|
|
|
* See glFrustum for further details.
|
|
|
|
*/
|
|
|
|
inline static Matrixd frustum(double left, double right,
|
|
|
|
double bottom, double top,
|
|
|
|
double zNear, double zFar);
|
|
|
|
|
|
|
|
/** Create a symmetrical perspective projection.
|
|
|
|
* See gluPerspective for further details.
|
|
|
|
* Aspect ratio is defined as width/height.
|
|
|
|
*/
|
|
|
|
inline static Matrixd perspective(double fovy, double aspectRatio,
|
|
|
|
double zNear, double zFar);
|
|
|
|
|
|
|
|
/** Create the position and orientation as per a camera,
|
|
|
|
* using the same convention as gluLookAt.
|
|
|
|
*/
|
|
|
|
inline 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.
|
|
|
|
*/
|
|
|
|
inline static Matrixd lookAt(const Vec3d& eye,
|
|
|
|
const Vec3d& center,
|
|
|
|
const Vec3d& up);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f preMult( const Vec3f& v ) const;
|
|
|
|
inline Vec3d preMult( const Vec3d& v ) const;
|
|
|
|
inline Vec3f postMult( const Vec3f& v ) const;
|
|
|
|
inline Vec3d postMult( const Vec3d& v ) const;
|
|
|
|
inline Vec3f operator* ( const Vec3f& v ) const;
|
|
|
|
inline Vec3d operator* ( const Vec3d& v ) const;
|
|
|
|
inline Vec4f preMult( const Vec4f& v ) const;
|
|
|
|
inline Vec4d preMult( const Vec4d& v ) const;
|
|
|
|
inline Vec4f postMult( const Vec4f& v ) const;
|
|
|
|
inline Vec4d postMult( const Vec4d& v ) const;
|
|
|
|
inline Vec4f operator* ( const Vec4f& v ) const;
|
|
|
|
inline Vec4d operator* ( const Vec4d& v ) const;
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2006-08-01 01:31:21 +08:00
|
|
|
#ifdef USE_DEPRECATED_API
|
|
|
|
inline void set(const Quat& q) { makeRotate(q); }
|
|
|
|
inline void get(Quat& q) const { q = getRotate(); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void setRotate(const Quat& q);
|
2008-02-27 19:46:05 +08:00
|
|
|
/** Get the matrix rotation as a Quat. Note that this function
|
|
|
|
* assumes a non-scaled matrix and will return incorrect results
|
|
|
|
* for scaled matrixces. Consider decompose() instead.
|
|
|
|
*/
|
2006-08-01 01:31:21 +08:00
|
|
|
Quat getRotate() const;
|
|
|
|
|
2003-09-06 04:48:42 +08:00
|
|
|
void setTrans( value_type tx, value_type ty, value_type tz );
|
2005-11-18 01:44:48 +08:00
|
|
|
void setTrans( const Vec3f& v );
|
|
|
|
void setTrans( const Vec3d& v );
|
2004-05-20 18:15:48 +08:00
|
|
|
|
|
|
|
inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); }
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2005-05-31 14:21:16 +08:00
|
|
|
inline Vec3d getScale() const {
|
|
|
|
Vec3d x_vec(_mat[0][0],_mat[1][0],_mat[2][0]);
|
|
|
|
Vec3d y_vec(_mat[0][1],_mat[1][1],_mat[2][1]);
|
|
|
|
Vec3d z_vec(_mat[0][2],_mat[1][2],_mat[2][2]);
|
|
|
|
return Vec3d(x_vec.length(), y_vec.length(), z_vec.length());
|
|
|
|
}
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** apply a 3x3 transform of v*M[0..2,0..2]. */
|
|
|
|
inline static Vec3f transform3x3(const Vec3f& v,const Matrixd& m);
|
2004-05-20 18:15:48 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** apply a 3x3 transform of v*M[0..2,0..2]. */
|
|
|
|
inline static Vec3d transform3x3(const Vec3d& v,const Matrixd& m);
|
2004-05-20 18:15:48 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** apply a 3x3 transform of M[0..2,0..2]*v. */
|
|
|
|
inline static Vec3f transform3x3(const Matrixd& m,const Vec3f& v);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** apply a 3x3 transform of M[0..2,0..2]*v. */
|
|
|
|
inline static Vec3d transform3x3(const Matrixd& m,const Vec3d& v);
|
2003-09-06 04:48:42 +08:00
|
|
|
|
|
|
|
// basic Matrixd multiplication, our workhorse methods.
|
|
|
|
void mult( const Matrixd&, const Matrixd& );
|
|
|
|
void preMult( const Matrixd& );
|
|
|
|
void postMult( const Matrixd& );
|
|
|
|
|
2008-09-18 00:14:28 +08:00
|
|
|
/** Optimized version of preMult(translate(v)); */
|
|
|
|
inline void preMultTranslate( const Vec3d& v );
|
|
|
|
inline void preMultTranslate( const Vec3f& v );
|
|
|
|
/** Optimized version of postMult(translate(v)); */
|
|
|
|
inline void postMultTranslate( const Vec3d& v );
|
|
|
|
inline void postMultTranslate( const Vec3f& v );
|
|
|
|
|
|
|
|
/** Optimized version of preMult(scale(v)); */
|
|
|
|
inline void preMultScale( const Vec3d& v );
|
|
|
|
inline void preMultScale( const Vec3f& v );
|
|
|
|
/** Optimized version of postMult(scale(v)); */
|
|
|
|
inline void postMultScale( const Vec3d& v );
|
|
|
|
inline void postMultScale( const Vec3f& v );
|
|
|
|
|
|
|
|
/** Optimized version of preMult(rotate(q)); */
|
|
|
|
inline void preMultRotate( const Quat& q );
|
|
|
|
/** Optimized version of postMult(rotate(q)); */
|
|
|
|
inline void postMultRotate( const Quat& q );
|
|
|
|
|
2003-09-06 04:48:42 +08:00
|
|
|
inline void operator *= ( const Matrixd& other )
|
|
|
|
{ if( this == &other ) {
|
|
|
|
Matrixd temp(other);
|
|
|
|
postMult( temp );
|
|
|
|
}
|
|
|
|
else postMult( other );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd operator * ( const Matrixd &m ) const
|
2004-08-31 21:19:30 +08:00
|
|
|
{
|
|
|
|
osg::Matrixd r;
|
2003-09-06 04:48:42 +08:00
|
|
|
r.mult(*this,m);
|
2004-08-31 21:19:30 +08:00
|
|
|
return r;
|
|
|
|
}
|
2003-09-06 06:35:34 +08:00
|
|
|
|
2003-09-06 04:48:42 +08:00
|
|
|
protected:
|
|
|
|
value_type _mat[4][4];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class RefMatrixd : public Object, public Matrixd
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2006-05-02 23:52:46 +08:00
|
|
|
RefMatrixd():Object(false), Matrixd() {}
|
|
|
|
RefMatrixd( const Matrixd& other) : Object(false), Matrixd(other) {}
|
|
|
|
RefMatrixd( const Matrixf& other) : Object(false), Matrixd(other) {}
|
2003-09-06 04:48:42 +08:00
|
|
|
RefMatrixd( const RefMatrixd& other) : Object(other), Matrixd(other) {}
|
2006-05-02 23:52:46 +08:00
|
|
|
explicit RefMatrixd( Matrixd::value_type const * const def ):Object(false), Matrixd(def) {}
|
2003-09-06 04:48:42 +08:00
|
|
|
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):
|
2006-05-02 23:52:46 +08:00
|
|
|
Object(false),
|
2003-09-06 04:48:42 +08:00
|
|
|
Matrixd(a00, a01, a02, a03,
|
2004-08-31 21:19:30 +08:00
|
|
|
a10, a11, a12, a13,
|
|
|
|
a20, a21, a22, a23,
|
|
|
|
a30, a31, a32, a33) {}
|
2003-09-06 04:48:42 +08:00
|
|
|
|
|
|
|
virtual Object* cloneType() const { return new RefMatrixd(); }
|
|
|
|
virtual Object* clone(const CopyOp&) const { return new RefMatrixd(*this); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const RefMatrixd*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "Matrix"; }
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~RefMatrixd() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
// static utility methods
|
2003-09-06 04:48:42 +08:00
|
|
|
inline Matrixd Matrixd::identity(void)
|
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeIdentity();
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd Matrixd::scale(value_type sx, value_type sy, value_type sz)
|
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeScale(sx,sy,sz);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Matrixd Matrixd::scale(const Vec3f& v )
|
|
|
|
{
|
|
|
|
return scale(v.x(), v.y(), v.z() );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd Matrixd::scale(const Vec3d& v )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
return scale(v.x(), v.y(), v.z() );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd Matrixd::translate(value_type tx, value_type ty, value_type tz)
|
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeTranslate(tx,ty,tz);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Matrixd Matrixd::translate(const Vec3f& v )
|
|
|
|
{
|
|
|
|
return translate(v.x(), v.y(), v.z() );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd Matrixd::translate(const Vec3d& v )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
return translate(v.x(), v.y(), v.z() );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd Matrixd::rotate( const Quat& q )
|
|
|
|
{
|
2003-09-06 06:35:34 +08:00
|
|
|
return Matrixd(q);
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
2004-01-10 04:33:23 +08:00
|
|
|
inline Matrixd Matrixd::rotate(value_type angle, value_type x, value_type y, value_type z )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(angle,x,y,z);
|
|
|
|
return m;
|
|
|
|
}
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Matrixd Matrixd::rotate(value_type angle, const Vec3f& axis )
|
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(angle,axis);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
inline Matrixd Matrixd::rotate(value_type angle, const Vec3d& axis )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(angle,axis);
|
|
|
|
return m;
|
|
|
|
}
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1,
|
2004-08-31 21:19:30 +08:00
|
|
|
value_type angle2, const Vec3f& axis2,
|
|
|
|
value_type angle3, const Vec3f& axis3)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
|
|
|
|
return m;
|
|
|
|
}
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1,
|
2004-08-31 21:19:30 +08:00
|
|
|
value_type angle2, const Vec3d& axis2,
|
|
|
|
value_type angle3, const Vec3d& axis3)
|
2004-05-20 18:15:48 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
inline Matrixd Matrixd::rotate(const Vec3f& from, const Vec3f& to )
|
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(from,to);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
inline Matrixd Matrixd::rotate(const Vec3d& from, const Vec3d& to )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeRotate(from,to);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Matrixd Matrixd::inverse( const Matrixd& matrix)
|
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.invert(matrix);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2005-11-02 18:45:56 +08:00
|
|
|
inline Matrixd Matrixd::orthoNormal(const Matrixd& matrix)
|
2005-05-31 14:21:16 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.orthoNormalize(matrix);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
inline Matrixd Matrixd::ortho(double left, double right,
|
2004-05-20 18:15:48 +08:00
|
|
|
double bottom, double top,
|
2004-08-31 21:19:30 +08:00
|
|
|
double zNear, double zFar)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeOrtho(left,right,bottom,top,zNear,zFar);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
inline Matrixd Matrixd::ortho2D(double left, double right,
|
2004-05-20 18:15:48 +08:00
|
|
|
double bottom, double top)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeOrtho2D(left,right,bottom,top);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
inline Matrixd Matrixd::frustum(double left, double right,
|
2004-05-20 18:15:48 +08:00
|
|
|
double bottom, double top,
|
2004-08-31 21:19:30 +08:00
|
|
|
double zNear, double zFar)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeFrustum(left,right,bottom,top,zNear,zFar);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
inline Matrixd Matrixd::perspective(double fovy, double aspectRatio,
|
|
|
|
double zNear, double zFar)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makePerspective(fovy,aspectRatio,zNear,zFar);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
inline Matrixd Matrixd::lookAt(const Vec3f& eye,
|
|
|
|
const Vec3f& center,
|
|
|
|
const Vec3f& up)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeLookAt(eye,center,up);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
inline Matrixd Matrixd::lookAt(const Vec3d& eye,
|
|
|
|
const Vec3d& center,
|
|
|
|
const Vec3d& up)
|
2004-05-20 18:15:48 +08:00
|
|
|
{
|
|
|
|
Matrixd m;
|
|
|
|
m.makeLookAt(eye,center,up);
|
|
|
|
return m;
|
|
|
|
}
|
2003-09-06 04:48:42 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f Matrixd::postMult( const Vec3f& v ) const
|
|
|
|
{
|
|
|
|
value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
|
|
|
|
return Vec3f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
|
|
|
|
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
|
|
|
|
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
|
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3d Matrixd::postMult( const Vec3d& v ) const
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2004-01-10 04:33:23 +08:00
|
|
|
value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
|
2004-05-20 18:15:48 +08:00
|
|
|
return Vec3d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
|
2003-09-06 04:48:42 +08:00
|
|
|
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
|
|
|
|
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f Matrixd::preMult( const Vec3f& v ) const
|
|
|
|
{
|
|
|
|
value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
|
|
|
|
return Vec3f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
|
|
|
|
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
|
|
|
|
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
|
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3d Matrixd::preMult( const Vec3d& v ) const
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2004-01-10 04:33:23 +08:00
|
|
|
value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
|
2004-05-20 18:15:48 +08:00
|
|
|
return Vec3d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
|
2003-09-06 04:48:42 +08:00
|
|
|
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
|
|
|
|
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4f Matrixd::postMult( const Vec4f& v ) const
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2004-05-20 18:15:48 +08:00
|
|
|
return Vec4f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
|
|
|
|
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
|
|
|
|
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
|
|
|
|
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
|
|
|
|
}
|
|
|
|
inline Vec4d Matrixd::postMult( const Vec4d& v ) const
|
|
|
|
{
|
|
|
|
return Vec4d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
|
2003-09-06 04:48:42 +08:00
|
|
|
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
|
|
|
|
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
|
|
|
|
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4f Matrixd::preMult( const Vec4f& v ) const
|
|
|
|
{
|
|
|
|
return Vec4f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
|
|
|
|
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
|
|
|
|
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
|
|
|
|
(_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
|
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4d Matrixd::preMult( const Vec4d& v ) const
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2004-05-20 18:15:48 +08:00
|
|
|
return Vec4d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
|
2003-09-06 04:48:42 +08:00
|
|
|
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
|
|
|
|
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
|
|
|
|
(_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
|
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f Matrixd::transform3x3(const Vec3f& v,const Matrixd& m)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2004-05-20 18:15:48 +08:00
|
|
|
return Vec3f( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
|
|
|
|
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
|
|
|
|
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
|
|
|
|
}
|
|
|
|
inline Vec3d Matrixd::transform3x3(const Vec3d& v,const Matrixd& m)
|
|
|
|
{
|
|
|
|
return Vec3d( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
|
2003-09-06 04:48:42 +08:00
|
|
|
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
|
|
|
|
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f Matrixd::transform3x3(const Matrixd& m,const Vec3f& v)
|
|
|
|
{
|
|
|
|
return Vec3f( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
|
|
|
|
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
|
|
|
|
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
|
|
|
|
}
|
|
|
|
inline Vec3d Matrixd::transform3x3(const Matrixd& m,const Vec3d& v)
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2004-05-20 18:15:48 +08:00
|
|
|
return Vec3d( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
|
2003-09-06 04:48:42 +08:00
|
|
|
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
|
|
|
|
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
|
|
|
|
}
|
|
|
|
|
2008-09-18 00:14:28 +08:00
|
|
|
inline void Matrixd::preMultTranslate( const Vec3d& v )
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
double tmp = v[i];
|
|
|
|
if (tmp == 0)
|
|
|
|
continue;
|
|
|
|
_mat[3][0] += tmp*_mat[i][0];
|
|
|
|
_mat[3][1] += tmp*_mat[i][1];
|
|
|
|
_mat[3][2] += tmp*_mat[i][2];
|
|
|
|
_mat[3][3] += tmp*_mat[i][3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::preMultTranslate( const Vec3f& v )
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
float tmp = v[i];
|
|
|
|
if (tmp == 0)
|
|
|
|
continue;
|
|
|
|
_mat[3][0] += tmp*_mat[i][0];
|
|
|
|
_mat[3][1] += tmp*_mat[i][1];
|
|
|
|
_mat[3][2] += tmp*_mat[i][2];
|
|
|
|
_mat[3][3] += tmp*_mat[i][3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::postMultTranslate( const Vec3d& v )
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
double tmp = v[i];
|
|
|
|
if (tmp == 0)
|
|
|
|
continue;
|
|
|
|
_mat[0][i] += tmp*_mat[0][3];
|
|
|
|
_mat[1][i] += tmp*_mat[1][3];
|
|
|
|
_mat[2][i] += tmp*_mat[2][3];
|
|
|
|
_mat[3][i] += tmp*_mat[3][3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::postMultTranslate( const Vec3f& v )
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
float tmp = v[i];
|
|
|
|
if (tmp == 0)
|
|
|
|
continue;
|
|
|
|
_mat[0][i] += tmp*_mat[0][3];
|
|
|
|
_mat[1][i] += tmp*_mat[1][3];
|
|
|
|
_mat[2][i] += tmp*_mat[2][3];
|
|
|
|
_mat[3][i] += tmp*_mat[3][3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::preMultScale( const Vec3d& v )
|
|
|
|
{
|
|
|
|
_mat[0][0] *= v[0]; _mat[0][1] *= v[0]; _mat[0][2] *= v[0]; _mat[0][3] *= v[0];
|
|
|
|
_mat[1][0] *= v[1]; _mat[1][1] *= v[1]; _mat[1][2] *= v[1]; _mat[1][3] *= v[1];
|
|
|
|
_mat[2][0] *= v[2]; _mat[2][1] *= v[2]; _mat[2][2] *= v[2]; _mat[2][3] *= v[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::preMultScale( const Vec3f& v )
|
|
|
|
{
|
|
|
|
_mat[0][0] *= v[0]; _mat[0][1] *= v[0]; _mat[0][2] *= v[0]; _mat[0][3] *= v[0];
|
|
|
|
_mat[1][0] *= v[1]; _mat[1][1] *= v[1]; _mat[1][2] *= v[1]; _mat[1][3] *= v[1];
|
|
|
|
_mat[2][0] *= v[2]; _mat[2][1] *= v[2]; _mat[2][2] *= v[2]; _mat[2][3] *= v[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::postMultScale( const Vec3d& v )
|
|
|
|
{
|
|
|
|
_mat[0][0] *= v[0]; _mat[1][0] *= v[0]; _mat[2][0] *= v[0]; _mat[3][0] *= v[0];
|
|
|
|
_mat[0][1] *= v[1]; _mat[1][1] *= v[1]; _mat[2][1] *= v[1]; _mat[3][1] *= v[1];
|
|
|
|
_mat[0][2] *= v[2]; _mat[1][2] *= v[2]; _mat[2][2] *= v[2]; _mat[3][2] *= v[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::postMultScale( const Vec3f& v )
|
|
|
|
{
|
|
|
|
_mat[0][0] *= v[0]; _mat[1][0] *= v[0]; _mat[2][0] *= v[0]; _mat[3][0] *= v[0];
|
|
|
|
_mat[0][1] *= v[1]; _mat[1][1] *= v[1]; _mat[2][1] *= v[1]; _mat[3][1] *= v[1];
|
|
|
|
_mat[0][2] *= v[2]; _mat[1][2] *= v[2]; _mat[2][2] *= v[2]; _mat[3][2] *= v[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::preMultRotate( const Quat& q )
|
|
|
|
{
|
|
|
|
if (q.zeroRotation())
|
|
|
|
return;
|
|
|
|
Matrixd r;
|
|
|
|
r.setRotate(q);
|
|
|
|
preMult(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Matrixd::postMultRotate( const Quat& q )
|
|
|
|
{
|
|
|
|
if (q.zeroRotation())
|
|
|
|
return;
|
|
|
|
Matrixd r;
|
|
|
|
r.setRotate(q);
|
|
|
|
postMult(r);
|
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f operator* (const Vec3f& v, const Matrixd& m )
|
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return m.preMult(v);
|
2004-05-20 18:15:48 +08:00
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3d operator* (const Vec3d& v, const Matrixd& m )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return m.preMult(v);
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4f operator* (const Vec4f& v, const Matrixd& m )
|
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return m.preMult(v);
|
2004-05-20 18:15:48 +08:00
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4d operator* (const Vec4d& v, const Matrixd& m )
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return m.preMult(v);
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3f Matrixd::operator* (const Vec3f& v) const
|
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return postMult(v);
|
2004-05-20 18:15:48 +08:00
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec3d Matrixd::operator* (const Vec3d& v) const
|
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return postMult(v);
|
2004-05-20 18:15:48 +08:00
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4f Matrixd::operator* (const Vec4f& v) const
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return postMult(v);
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
2004-08-31 21:19:30 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline Vec4d Matrixd::operator* (const Vec4d& v) const
|
2003-09-06 04:48:42 +08:00
|
|
|
{
|
2005-11-18 01:44:48 +08:00
|
|
|
return postMult(v);
|
2003-09-06 04:48:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} //namespace osg
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|