From 792bba05b934be5e5ef8365bd0c7ddeab5cb9e85 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Sep 2003 22:35:34 +0000 Subject: [PATCH] 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. --- examples/osghangglide/GliderManipulator.cpp | 14 +++--- examples/osghangglide/GliderManipulator.h | 8 ++-- examples/osgimpostor/TestManipulator.cpp | 14 +++--- examples/osgimpostor/TestManipulator.h | 8 ++-- include/osg/AnimationPath | 50 +++++++++++++++++---- include/osg/Matrix | 9 +++- include/osg/Matrixd | 37 ++++++++------- include/osg/Matrixf | 29 +++++++----- include/osgGA/AnimationPathManipulator | 10 ++--- include/osgGA/DriveManipulator | 8 ++-- include/osgGA/FlightManipulator | 8 ++-- include/osgGA/KeySwitchMatrixManipulator | 8 ++-- include/osgGA/MatrixManipulator | 10 ++--- include/osgGA/TrackballManipulator | 8 ++-- include/osgProducer/OsgCameraGroup | 5 ++- include/osgProducer/OsgSceneHandler | 1 - src/osg/Matrixd.cpp | 17 +++++++ src/osg/Matrixf.cpp | 17 +++++++ src/osgGA/DriveManipulator.cpp | 12 ++--- src/osgGA/FlightManipulator.cpp | 14 +++--- src/osgGA/TrackballManipulator.cpp | 16 +++---- src/osgProducer/OsgCameraGroup.cpp | 11 ++--- src/osgProducer/Viewer.cpp | 18 ++++---- 23 files changed, 203 insertions(+), 129 deletions(-) diff --git a/examples/osghangglide/GliderManipulator.cpp b/examples/osghangglide/GliderManipulator.cpp index fc00714f4..8645702e3 100644 --- a/examples/osghangglide/GliderManipulator.cpp +++ b/examples/osghangglide/GliderManipulator.cpp @@ -181,21 +181,21 @@ void GliderManipulator::addMouseEvent(const GUIEventAdapter& ea) } -void GliderManipulator::setByMatrix(const osg::Matrix& matrix) +void GliderManipulator::setByMatrix(const osg::Matrixd& matrix) { _eye = matrix.getTrans(); matrix.get(_rotation); _distance = 1.0f; } -osg::Matrix GliderManipulator::getMatrix() const +osg::Matrixd GliderManipulator::getMatrix() const { - return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye); + return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_eye); } -osg::Matrix GliderManipulator::getInverseMatrix() const +osg::Matrixd GliderManipulator::getInverseMatrix() const { - return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse()); + return osg::Matrixd::translate(-_eye)*osg::Matrixd::rotate(_rotation.inverse()); } void GliderManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up) @@ -207,7 +207,7 @@ void GliderManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv osg::Vec3 u(s^f); u.normalize(); - osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0f, + osg::Matrixd rotation_matrix(s[0], u[0], -f[0], 0.0f, s[1], u[1], -f[1], 0.0f, s[2], u[2], -f[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); @@ -261,7 +261,7 @@ bool GliderManipulator::calcMovement() float dy = _ga_t0->getYnormalized(); - osg::Matrix rotation_matrix; + osg::Matrixd rotation_matrix; rotation_matrix.makeRotate(_rotation); osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix; diff --git a/examples/osghangglide/GliderManipulator.h b/examples/osghangglide/GliderManipulator.h index 01bc0d8b6..aca1c8bdb 100644 --- a/examples/osghangglide/GliderManipulator.h +++ b/examples/osghangglide/GliderManipulator.h @@ -33,16 +33,16 @@ class GliderManipulator : public osgGA::MatrixManipulator virtual const char* className() const { return "Glider"; } /** 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*); diff --git a/examples/osgimpostor/TestManipulator.cpp b/examples/osgimpostor/TestManipulator.cpp index b7f62dad4..23f524a7c 100644 --- a/examples/osgimpostor/TestManipulator.cpp +++ b/examples/osgimpostor/TestManipulator.cpp @@ -179,21 +179,21 @@ void TestManipulator::addMouseEvent(const GUIEventAdapter& ea) _ga_t0 = &ea; } -void TestManipulator::setByMatrix(const osg::Matrix& matrix) +void TestManipulator::setByMatrix(const osg::Matrixd& matrix) { _center = matrix.getTrans(); matrix.get(_rotation); _distance = 1.0f; } -osg::Matrix TestManipulator::getMatrix() const +osg::Matrixd TestManipulator::getMatrix() const { - return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_center); + return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_center); } -osg::Matrix TestManipulator::getInverseMatrix() const +osg::Matrixd TestManipulator::getInverseMatrix() const { - return osg::Matrix::translate(-_center)*osg::Matrix::rotate(_rotation.inverse()); + return osg::Matrixd::translate(-_center)*osg::Matrixd::rotate(_rotation.inverse()); } void TestManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up) @@ -205,7 +205,7 @@ void TestManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,c osg::Vec3 u(s^f); u.normalize(); - osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0f, + osg::Matrixd rotation_matrix(s[0], u[0], -f[0], 0.0f, s[1], u[1], -f[1], 0.0f, s[2], u[2], -f[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); @@ -258,7 +258,7 @@ bool TestManipulator::calcMovement() } else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON) { - osg::Matrix rotation_matrix(_rotation); + osg::Matrixd rotation_matrix(_rotation); osg::Vec3 uv = osg::Vec3(0.0f,1.0f,0.0f)*rotation_matrix; diff --git a/examples/osgimpostor/TestManipulator.h b/examples/osgimpostor/TestManipulator.h index 11693254e..10da48da3 100644 --- a/examples/osgimpostor/TestManipulator.h +++ b/examples/osgimpostor/TestManipulator.h @@ -16,16 +16,16 @@ class TestManipulator : public osgGA::MatrixManipulator virtual ~TestManipulator(); /** 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; /** Attach a node to the manipulator. Automatically detaches previously attached node. diff --git a/include/osg/AnimationPath b/include/osg/AnimationPath index a99320d82..fefb29269 100644 --- a/include/osg/AnimationPath +++ b/include/osg/AnimationPath @@ -14,7 +14,8 @@ #ifndef OSG_ANIMATIONPATH #define OSG_ANIMATIONPATH 1 -#include +#include +#include #include #include @@ -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; diff --git a/include/osg/Matrix b/include/osg/Matrix index 1c051ef0e..ad6d0af13 100644 --- a/include/osg/Matrix +++ b/include/osg/Matrix @@ -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 diff --git a/include/osg/Matrixd b/include/osg/Matrixd index 434bbaf32..f30ea4740 100644 --- a/include/osg/Matrixd +++ b/include/osg/Matrixd @@ -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 ) { diff --git a/include/osg/Matrixf b/include/osg/Matrixf index 9ff0f5876..18f4e257b 100644 --- a/include/osg/Matrixf +++ b/include/osg/Matrixf @@ -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, diff --git a/include/osgGA/AnimationPathManipulator b/include/osgGA/AnimationPathManipulator index 49eca53a2..d9737791d 100644 --- a/include/osgGA/AnimationPathManipulator +++ b/include/osgGA/AnimationPathManipulator @@ -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; }; diff --git a/include/osgGA/DriveManipulator b/include/osgGA/DriveManipulator index 4d46ffff3..d6e9d0263 100644 --- a/include/osgGA/DriveManipulator +++ b/include/osgGA/DriveManipulator @@ -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*); diff --git a/include/osgGA/FlightManipulator b/include/osgGA/FlightManipulator index 695612781..e76b95d3a 100644 --- a/include/osgGA/FlightManipulator +++ b/include/osgGA/FlightManipulator @@ -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*); diff --git a/include/osgGA/KeySwitchMatrixManipulator b/include/osgGA/KeySwitchMatrixManipulator index 4c67c1862..8fa55e0c6 100644 --- a/include/osgGA/KeySwitchMatrixManipulator +++ b/include/osgGA/KeySwitchMatrixManipulator @@ -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(); } diff --git a/include/osgGA/MatrixManipulator b/include/osgGA/MatrixManipulator index 2bd98572c..083708e81 100644 --- a/include/osgGA/MatrixManipulator +++ b/include/osgGA/MatrixManipulator @@ -15,7 +15,7 @@ #define OSGGA_MatrixManipulator 1 #include -#include +#include #include @@ -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; } diff --git a/include/osgGA/TrackballManipulator b/include/osgGA/TrackballManipulator index 179765059..6dbada132 100644 --- a/include/osgGA/TrackballManipulator +++ b/include/osgGA/TrackballManipulator @@ -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; } diff --git a/include/osgProducer/OsgCameraGroup b/include/osgProducer/OsgCameraGroup index e911e297a..1418da45d 100644 --- a/include/osgProducer/OsgCameraGroup +++ b/include/osgProducer/OsgCameraGroup @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -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(); diff --git a/include/osgProducer/OsgSceneHandler b/include/osgProducer/OsgSceneHandler index 63e9c0b2f..cf872a501 100644 --- a/include/osgProducer/OsgSceneHandler +++ b/include/osgProducer/OsgSceneHandler @@ -18,7 +18,6 @@ #include #include -#include namespace osgProducer { diff --git a/src/osg/Matrixd.cpp b/src/osg/Matrixd.cpp index 49ac5b7ea..946bdd209 100644 --- a/src/osg/Matrixd.cpp +++ b/src/osg/Matrixd.cpp @@ -12,9 +12,26 @@ */ #include +#include // specialise Matrix_implementaiton to be Matrixd #define Matrix_implementation Matrixd +osg::Matrixd::Matrixd( const osg::Matrixf& mat ) +{ + set(mat.ptr()); +} + +osg::Matrixd& osg::Matrixd::operator = (const osg::Matrixf& rhs) +{ + set(rhs.ptr()); + return *this; +} + +void osg::Matrixd::set(const osg::Matrixf& rhs) +{ + set(rhs.ptr()); +} + // now compile up Matrix via Matrix_implementation #include "Matrix_implementation.cpp" diff --git a/src/osg/Matrixf.cpp b/src/osg/Matrixf.cpp index 9c0b74434..0977c8208 100644 --- a/src/osg/Matrixf.cpp +++ b/src/osg/Matrixf.cpp @@ -12,9 +12,26 @@ */ #include +#include // specialise Matrix_implementaiton to be Matrixf #define Matrix_implementation Matrixf +osg::Matrixf::Matrixf( const osg::Matrixd& mat ) +{ + set(mat.ptr()); +} + +osg::Matrixf& osg::Matrixf::operator = (const osg::Matrixd& rhs) +{ + set(rhs.ptr()); + return *this; +} + +void osg::Matrixf::set(const osg::Matrixd& rhs) +{ + set(rhs.ptr()); +} + // now compile up Matrix via Matrix_implementation #include "Matrix_implementation.cpp" diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index c09f91924..4c659f370 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -166,7 +166,7 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) osg::Vec3 ep = _eye; - Matrix rotation_matrix; + Matrixd rotation_matrix; rotation_matrix.get(_rotation); osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix; osg::Vec3 bp = ep; @@ -353,20 +353,20 @@ void DriveManipulator::addMouseEvent(const GUIEventAdapter& ea) _ga_t0 = &ea; } -void DriveManipulator::setByMatrix(const osg::Matrix& matrix) +void DriveManipulator::setByMatrix(const osg::Matrixd& matrix) { _eye = matrix.getTrans(); matrix.get(_rotation); } -osg::Matrix DriveManipulator::getMatrix() const +osg::Matrixd DriveManipulator::getMatrix() const { - return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye); + return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_eye); } -osg::Matrix DriveManipulator::getInverseMatrix() const +osg::Matrixd DriveManipulator::getInverseMatrix() const { - return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse()); + return osg::Matrixd::translate(-_eye)*osg::Matrixd::rotate(_rotation.inverse()); } void DriveManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up) diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index ad29e47d4..c0a35b06a 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -180,21 +180,21 @@ void FlightManipulator::addMouseEvent(const GUIEventAdapter& ea) } -void FlightManipulator::setByMatrix(const osg::Matrix& matrix) +void FlightManipulator::setByMatrix(const osg::Matrixd& matrix) { _eye = matrix.getTrans(); matrix.get(_rotation); _distance = 1.0f; } -osg::Matrix FlightManipulator::getMatrix() const +osg::Matrixd FlightManipulator::getMatrix() const { - return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye); + return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_eye); } -osg::Matrix FlightManipulator::getInverseMatrix() const +osg::Matrixd FlightManipulator::getInverseMatrix() const { - return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse()); + return osg::Matrixd::translate(-_eye)*osg::Matrixd::rotate(_rotation.inverse()); } void FlightManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up) @@ -206,7 +206,7 @@ void FlightManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv osg::Vec3 u(s^f); u.normalize(); - osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0f, + osg::Matrixd rotation_matrix(s[0], u[0], -f[0], 0.0f, s[1], u[1], -f[1], 0.0f, s[2], u[2], -f[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); @@ -258,7 +258,7 @@ bool FlightManipulator::calcMovement() float dy = _ga_t0->getYnormalized(); - osg::Matrix rotation_matrix; + osg::Matrixd rotation_matrix; rotation_matrix.makeRotate(_rotation); osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix; diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index 6a36a667c..ec7e4e46f 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -189,24 +189,20 @@ void TrackballManipulator::addMouseEvent(const GUIEventAdapter& ea) _ga_t0 = &ea; } -void TrackballManipulator::setByMatrix(const osg::Matrix& matrix) +void TrackballManipulator::setByMatrix(const osg::Matrixd& matrix) { - _center = osg::Vec3(0.0f,0.0f,-_distance)*matrix;//matrix.getTrans(); + _center = osg::Vec3(0.0f,0.0f,-_distance)*matrix; matrix.get(_rotation); - - osg::Matrix rotation_matrix(_rotation); -// _center -= osg::Vec3(0.0f,0.0f,_distance)*rotation_matrix; - } -osg::Matrix TrackballManipulator::getMatrix() const +osg::Matrixd TrackballManipulator::getMatrix() const { - return osg::Matrix::translate(0.0f,0.0f,_distance)*osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_center); + return osg::Matrixd::translate(0.0,0.0,_distance)*osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_center); } -osg::Matrix TrackballManipulator::getInverseMatrix() const +osg::Matrixd TrackballManipulator::getInverseMatrix() const { - return osg::Matrix::translate(-_center)*osg::Matrix::rotate(_rotation.inverse())*osg::Matrix::translate(0.0f,0.0f,-_distance); + return osg::Matrixd::translate(-_center)*osg::Matrixd::rotate(_rotation.inverse())*osg::Matrixd::translate(0.0,0.0,-_distance); } void TrackballManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up) diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index a079dbdbb..c8da0471d 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -436,19 +436,16 @@ const osg::Node* OsgCameraGroup::getTopMostSceneData() const return _scene_data.get(); } -void OsgCameraGroup::setView(const osg::Matrix& matrix) +void OsgCameraGroup::setView(const osg::Matrixd& matrix) { - Producer::Matrix pm;//(matrix.ptr()); - for(int i=0;i<4;++i) - for(int j=0;j<4;++j) - pm(i,j)=matrix(i,j); + Producer::Matrix pm(matrix.ptr()); setViewByMatrix(pm); } -const osg::Matrix OsgCameraGroup::getViewMatrix() const +osg::Matrixd OsgCameraGroup::getViewMatrix() const { - osg::Matrix matrix; + osg::Matrixd matrix; if (_cfg.valid() && _cfg->getNumberOfCameras()>=1) { const Producer::Camera *cam = _cfg->getCamera(0); diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index a02c8eaae..4d6f9694d 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -72,7 +72,7 @@ public: virtual void apply(osg::Projection& pr) { // stack the intersect rays, transform to new projection, traverse // Assumes that the Projection is an absolute projection - osg::Matrix mt; + osg::Matrixd mt; mt.invert(pr.getMatrix()); osg::Vec3 npt=osg::Vec3(xp,yp,-1.0f) * mt, farpt=osg::Vec3(xp,yp,1.0f) * mt; @@ -105,11 +105,11 @@ public: return _PIVsegHitList; } - osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Matrix &projm, const float x, const float y) + osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Matrixd &projm, const float x, const float y) { // utility for non=sceneview viewers // x,y are values returned by - osg::Matrix inverseMVPW; + osg::Matrixd inverseMVPW; inverseMVPW.invert(projm); osg::Vec3 near_point = osg::Vec3(x,y,-1.0f)*inverseMVPW; osg::Vec3 far_point = osg::Vec3(x,y,1.0f)*inverseMVPW; @@ -303,7 +303,7 @@ void Viewer::setViewByMatrix( const Producer::Matrix & pm) // now convert Producer matrix to an osg::Matrix so we can update // the internal camera... - osg::Matrix matrix(pm.ptr()); + osg::Matrixd matrix(pm.ptr()); _keyswitchManipulator->setByInverseMatrix(matrix); } } @@ -439,7 +439,7 @@ void Viewer::update() if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentMatrixManipulator()) { osgGA::MatrixManipulator* mm = _keyswitchManipulator->getCurrentMatrixManipulator(); - osg::Matrix matrix = mm->getInverseMatrix(); + osg::Matrixd matrix = mm->getInverseMatrix(); CameraGroup::setViewByMatrix(Producer::Matrix(matrix.ptr())); setFusionDistance(mm->getFusionDistanceMode(),mm->getFusionDistanceValue()); @@ -452,7 +452,7 @@ void Viewer::frame() if (getRecordingAnimationPath() && getAnimationPath()) { - osg::Matrix matrix; + osg::Matrixd matrix; matrix.invert(getViewMatrix()); osg::Quat quat; matrix.get(quat); @@ -538,7 +538,7 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil osgProducer::OsgSceneHandler* sh = dynamic_cast(camera->getSceneHandler()); osgUtil::SceneView* sv = sh?sh->getSceneView():0; - osg::Matrix vum; + osg::Matrixd vum; if (sv!=0) { vum.set(sv->getViewMatrix() * @@ -546,8 +546,8 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil } else { - vum.set(osg::Matrix(camera->getViewMatrix()) * - osg::Matrix(camera->getProjectionMatrix())); + vum.set(osg::Matrixd(camera->getViewMatrix()) * + osg::Matrixd(camera->getProjectionMatrix())); } PickVisitor iv;