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:
Robert Osfield
2003-09-05 22:35:34 +00:00
parent a2834d74d2
commit 792bba05b9
23 changed files with 203 additions and 129 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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 )
{

View File

@@ -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,

View File

@@ -42,16 +42,16 @@ class OSGGA_EXPORT AnimationPathManipulator : public MatrixManipulator
virtual const char* className() const { return "AnimationPath"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix) { _matrix = matrix; }
virtual void setByMatrix(const osg::Matrixd& matrix) { _matrix = matrix; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { _matrix.invert(matrix); }
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _matrix.invert(matrix); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const { return _matrix; }
virtual osg::Matrixd getMatrix() const { return _matrix; }
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const { return osg::Matrix::inverse(_matrix); }
virtual osg::Matrixd getInverseMatrix() const { return osg::Matrixd::inverse(_matrix); }
void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; }
@@ -88,7 +88,7 @@ class OSGGA_EXPORT AnimationPathManipulator : public MatrixManipulator
double _animStartOfTimedPeriod;
int _numOfFramesSinceStartOfTimedPeriod;
osg::Matrix _matrix;
osg::Matrixd _matrix;
};

View File

@@ -35,16 +35,16 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator
virtual const char* className() const { return "Drive"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
virtual void setByMatrix(const osg::Matrixd& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
virtual osg::Matrixd getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
virtual osg::Matrixd getInverseMatrix() const;
virtual void setNode(osg::Node*);

View File

@@ -35,16 +35,16 @@ class OSGGA_EXPORT FlightManipulator : public MatrixManipulator
virtual const char* className() const { return "Flight"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
virtual void setByMatrix(const osg::Matrixd& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
virtual osg::Matrixd getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
virtual osg::Matrixd getInverseMatrix() const;
virtual void setNode(osg::Node*);

View File

@@ -66,16 +66,16 @@ public:
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix) { _current->setByMatrix(matrix); }
virtual void setByMatrix(const osg::Matrixd& matrix) { _current->setByMatrix(matrix); }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { _current->setByInverseMatrix(matrix); }
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _current->setByInverseMatrix(matrix); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const { return _current->getMatrix(); }
virtual osg::Matrixd getMatrix() const { return _current->getMatrix(); }
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const { return _current->getInverseMatrix(); }
virtual osg::Matrixd getInverseMatrix() const { return _current->getInverseMatrix(); }
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _current->getFusionDistanceMode(); }

View File

@@ -15,7 +15,7 @@
#define OSGGA_MatrixManipulator 1
#include <osg/Node>
#include <osg/Matrix>
#include <osg/Matrixd>
#include <osgUtil/SceneView>
@@ -41,16 +41,16 @@ public:
virtual const char* className() const { return "MatrixManipulator"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix) = 0;
virtual void setByMatrix(const osg::Matrixd& matrix) = 0;
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) = 0;
virtual void setByInverseMatrix(const osg::Matrixd& matrix) = 0;
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const = 0;
virtual osg::Matrixd getMatrix() const = 0;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const = 0;
virtual osg::Matrixd getInverseMatrix() const = 0;
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE; }

View File

@@ -28,16 +28,16 @@ class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator
virtual const char* className() const { return "Trackball"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
virtual void setByMatrix(const osg::Matrixd& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
virtual osg::Matrixd getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
virtual osg::Matrixd getInverseMatrix() const;
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }

View File

@@ -25,6 +25,7 @@
#include <osg/StateSet>
#include <osg/FrameStamp>
#include <osg/DisplaySettings>
#include <osg/Matrixd>
#include <osgDB/DatabasePager>
@@ -155,11 +156,11 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
/** Set the model view matrix of the camera group,
* by individually set all the camera groups's camera.*/
virtual void setView(const osg::Matrix& matrix);
virtual void setView(const osg::Matrixd& matrix);
/** Get the model view martrix of the camera group,
* taking its value for camera 0.*/
const osg::Matrix getViewMatrix() const;
osg::Matrixd getViewMatrix() const;
virtual void sync();

View File

@@ -18,7 +18,6 @@
#include <Producer/Camera>
#include <osgUtil/SceneView>
#include <osg/Matrix>
namespace osgProducer {