Added new Matrixf and Matrixd implementations.
Made Matrix be a typedef to either Matrixf or Matrixd. Defaults to Matrixf. Converted the osgGA::MatrixManipulators and osgProducer::Viewer/OsgCameraGroup across to using exclusively Matrixd for internal computations and passing betwen Manipulators, Producer and SceneView. Note, SceneView still uses Matrix internally so will depend on what is set as the default in include/osg/Matrix. Added the ability to osgProducer::setDone/getDone(), kept done() as the method that the viewer main loop uses for detecting the exit condition.
This commit is contained in:
@@ -14,7 +14,8 @@
|
||||
#ifndef OSG_ANIMATIONPATH
|
||||
#define OSG_ANIMATIONPATH 1
|
||||
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Matrixf>
|
||||
#include <osg/Matrixd>
|
||||
#include <osg/Quat>
|
||||
#include <osg/NodeCallback>
|
||||
|
||||
@@ -71,24 +72,47 @@ class SG_EXPORT AnimationPath : public virtual osg::Object
|
||||
_scale = first._scale*one_minus_ratio + second._scale*ratio;
|
||||
}
|
||||
|
||||
inline void getMatrix(Matrix& matrix) const
|
||||
inline void getMatrix(Matrixf& matrix) const
|
||||
{
|
||||
matrix.makeScale(_scale);
|
||||
matrix.postMult(osg::Matrix::rotate(_rotation));
|
||||
matrix.postMult(osg::Matrix::translate(_position));
|
||||
matrix.postMult(osg::Matrixf::rotate(_rotation));
|
||||
matrix.postMult(osg::Matrixf::translate(_position));
|
||||
}
|
||||
|
||||
inline void getInverse(Matrix& matrix) const
|
||||
inline void getMatrix(Matrixd& matrix) const
|
||||
{
|
||||
matrix.makeScale(_scale);
|
||||
matrix.postMult(osg::Matrixd::rotate(_rotation));
|
||||
matrix.postMult(osg::Matrixd::translate(_position));
|
||||
}
|
||||
|
||||
inline void getInverse(Matrixf& matrix) const
|
||||
{
|
||||
matrix.makeScale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.y());
|
||||
matrix.postMult(osg::Matrix::rotate(_rotation.inverse()));
|
||||
matrix.postMult(osg::Matrix::translate(-_position));
|
||||
matrix.postMult(osg::Matrixf::rotate(_rotation.inverse()));
|
||||
matrix.postMult(osg::Matrixf::translate(-_position));
|
||||
}
|
||||
|
||||
inline void getInverse(Matrixd& matrix) const
|
||||
{
|
||||
matrix.makeScale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.y());
|
||||
matrix.postMult(osg::Matrixd::rotate(_rotation.inverse()));
|
||||
matrix.postMult(osg::Matrixd::translate(-_position));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** get the transformation matrix for a point in time.*/
|
||||
bool getMatrix(double time,Matrix& matrix) const
|
||||
bool getMatrix(double time,Matrixf& matrix) const
|
||||
{
|
||||
ControlPoint cp;
|
||||
if (!getInterpolatedControlPoint(time,cp)) return false;
|
||||
cp.getMatrix(matrix);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** get the transformation matrix for a point in time.*/
|
||||
bool getMatrix(double time,Matrixd& matrix) const
|
||||
{
|
||||
ControlPoint cp;
|
||||
if (!getInterpolatedControlPoint(time,cp)) return false;
|
||||
@@ -97,7 +121,7 @@ class SG_EXPORT AnimationPath : public virtual osg::Object
|
||||
}
|
||||
|
||||
/** get the inverse transformation matrix for a point in time.*/
|
||||
bool getInverse(double time,Matrix& matrix) const
|
||||
bool getInverse(double time,Matrixf& matrix) const
|
||||
{
|
||||
ControlPoint cp;
|
||||
if (!getInterpolatedControlPoint(time,cp)) return false;
|
||||
@@ -105,6 +129,14 @@ class SG_EXPORT AnimationPath : public virtual osg::Object
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getInverse(double time,Matrixd& matrix) const
|
||||
{
|
||||
ControlPoint cp;
|
||||
if (!getInterpolatedControlPoint(time,cp)) return false;
|
||||
cp.getInverse(matrix);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** get the local ControlPoint frame for a point in time.*/
|
||||
virtual bool getInterpolatedControlPoint(double time,ControlPoint& controlPoint) const;
|
||||
|
||||
|
||||
@@ -20,8 +20,13 @@
|
||||
namespace osg {
|
||||
|
||||
|
||||
typedef Matrixd Matrix;
|
||||
typedef RefMatrixd RefMatrix;
|
||||
// default to using floating Matrices - Matrixf
|
||||
typedef Matrixf Matrix;
|
||||
typedef RefMatrixf RefMatrix;
|
||||
|
||||
// // default to using double Matrices - Matrixd
|
||||
// typedef Matrixd Matrix;
|
||||
// typedef RefMatrixd RefMatrix;
|
||||
|
||||
|
||||
} //namespace osg
|
||||
|
||||
@@ -26,15 +26,18 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
class Matrixf;
|
||||
|
||||
class SG_EXPORT Matrixd
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef double value_type;
|
||||
typedef float value_type;
|
||||
|
||||
inline Matrixd() { makeIdentity(); }
|
||||
inline Matrixd( const Matrixd& other) { set(other.ptr()); }
|
||||
inline Matrixd( const Matrixd& mat) { set(mat.ptr()); }
|
||||
Matrixd( const Matrixf& mat );
|
||||
inline explicit Matrixd( float const * const ptr ) { set(ptr); }
|
||||
inline explicit Matrixd( double const * const ptr ) { set(ptr); }
|
||||
inline explicit Matrixd( const Quat& quat ) { set(quat); }
|
||||
@@ -61,26 +64,29 @@ class SG_EXPORT Matrixd
|
||||
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]); }
|
||||
|
||||
inline Matrixd& operator = (const Matrixd& other)
|
||||
inline Matrixd& operator = (const Matrixd& rhs)
|
||||
{
|
||||
if( &other == this ) return *this;
|
||||
set(other.ptr());
|
||||
if( &rhs == this ) return *this;
|
||||
set(rhs.ptr());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void set(const Matrixd& other)
|
||||
{
|
||||
set(other.ptr());
|
||||
}
|
||||
|
||||
inline Matrixd& operator = (const Matrixf& other);
|
||||
|
||||
inline void set(const Matrixd& rhs) { set(rhs.ptr()); }
|
||||
|
||||
void set(const Matrixf& rhs);
|
||||
|
||||
inline void set(float const * const ptr)
|
||||
{
|
||||
std::copy(ptr,ptr+16,(value_type*)_mat);
|
||||
value_type* local_ptr = (value_type*)_mat;
|
||||
for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
|
||||
}
|
||||
|
||||
inline void set(double const * const ptr)
|
||||
{
|
||||
std::copy(ptr,ptr+16,(value_type*)_mat);
|
||||
value_type* local_ptr = (value_type*)_mat;
|
||||
for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
|
||||
}
|
||||
|
||||
void set( value_type a00, value_type a01, value_type a02, value_type a03,
|
||||
@@ -234,7 +240,7 @@ class SG_EXPORT Matrixd
|
||||
r.mult(*this,m);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
value_type _mat[4][4];
|
||||
|
||||
@@ -246,6 +252,7 @@ class RefMatrixd : public Object, public Matrixd
|
||||
|
||||
RefMatrixd():Matrixd() {}
|
||||
RefMatrixd( const Matrixd& other) : Matrixd(other) {}
|
||||
RefMatrixd( const Matrixf& other) : Matrixd(other) {}
|
||||
RefMatrixd( const RefMatrixd& other) : Object(other), Matrixd(other) {}
|
||||
explicit RefMatrixd( Matrixd::value_type const * const def ):Matrixd(def) {}
|
||||
RefMatrixd( Matrixd::value_type a00, Matrixd::value_type a01, Matrixd::value_type a02, Matrixd::value_type a03,
|
||||
@@ -304,9 +311,7 @@ inline Matrixd Matrixd::translate(const Vec3& v )
|
||||
|
||||
inline Matrixd Matrixd::rotate( const Quat& q )
|
||||
{
|
||||
Matrixd m;
|
||||
m.makeRotate( q );
|
||||
return m;
|
||||
return Matrixd(q);
|
||||
}
|
||||
inline Matrixd Matrixd::rotate(float angle, float x, float y, float z )
|
||||
{
|
||||
|
||||
@@ -34,7 +34,8 @@ class SG_EXPORT Matrixf
|
||||
typedef float value_type;
|
||||
|
||||
inline Matrixf() { makeIdentity(); }
|
||||
inline Matrixf( const Matrixf& other) { set(other.ptr()); }
|
||||
inline Matrixf( const Matrixf& mat) { set(mat.ptr()); }
|
||||
Matrixf( const Matrixd& mat );
|
||||
inline explicit Matrixf( float const * const ptr ) { set(ptr); }
|
||||
inline explicit Matrixf( double const * const ptr ) { set(ptr); }
|
||||
inline explicit Matrixf( const Quat& quat ) { set(quat); }
|
||||
@@ -61,26 +62,29 @@ class SG_EXPORT Matrixf
|
||||
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]); }
|
||||
|
||||
inline Matrixf& operator = (const Matrixf& other)
|
||||
inline Matrixf& operator = (const Matrixf& rhs)
|
||||
{
|
||||
if( &other == this ) return *this;
|
||||
set(other.ptr());
|
||||
if( &rhs == this ) return *this;
|
||||
set(rhs.ptr());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void set(const Matrixf& other)
|
||||
{
|
||||
set(other.ptr());
|
||||
}
|
||||
|
||||
|
||||
Matrixf& operator = (const Matrixd& rhs);
|
||||
|
||||
void set(const Matrixd& rhs);
|
||||
|
||||
inline void set(const Matrixf& rhs) { set(rhs.ptr()); }
|
||||
|
||||
inline void set(float const * const ptr)
|
||||
{
|
||||
std::copy(ptr,ptr+16,(value_type*)_mat);
|
||||
value_type* local_ptr = (value_type*)_mat;
|
||||
for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
|
||||
}
|
||||
|
||||
inline void set(double const * const ptr)
|
||||
{
|
||||
std::copy(ptr,ptr+16,(value_type*)_mat);
|
||||
value_type* local_ptr = (value_type*)_mat;
|
||||
for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i];
|
||||
}
|
||||
|
||||
void set( value_type a00, value_type a01, value_type a02, value_type a03,
|
||||
@@ -246,6 +250,7 @@ class RefMatrixf : public Object, public Matrixf
|
||||
|
||||
RefMatrixf():Matrixf() {}
|
||||
RefMatrixf( const Matrixf& other) : Matrixf(other) {}
|
||||
RefMatrixf( const Matrixd& other) : Matrixf(other) {}
|
||||
RefMatrixf( const RefMatrixf& other) : Object(other), Matrixf(other) {}
|
||||
explicit RefMatrixf( Matrixf::value_type const * const def ):Matrixf(def) {}
|
||||
RefMatrixf( Matrixf::value_type a00, Matrixf::value_type a01, Matrixf::value_type a02, Matrixf::value_type a03,
|
||||
|
||||
Reference in New Issue
Block a user