diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 136850d08..4b84d6134 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -911,6 +911,30 @@ SOURCE=..\..\Include\Osg\Vec4 # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\Vec2f +# End Source File +# Begin Source File + +SOURCE=..\..\Include\Osg\Vec3f +# End Source File +# Begin Source File + +SOURCE=..\..\Include\Osg\Vec4f +# End Source File +# Begin Source File + +SOURCE=..\..\Include\Osg\Vec2d +# End Source File +# Begin Source File + +SOURCE=..\..\Include\Osg\Vec3d +# End Source File +# Begin Source File + +SOURCE=..\..\Include\Osg\Vec4d +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\Version # End Source File # Begin Source File diff --git a/examples/osgsimulation/osgsimulation.cpp b/examples/osgsimulation/osgsimulation.cpp index 543aeb2a3..b52a29b38 100644 --- a/examples/osgsimulation/osgsimulation.cpp +++ b/examples/osgsimulation/osgsimulation.cpp @@ -2,12 +2,47 @@ #include #include +#include +#include +#include + +#include #include #include #include #include +// for the grid data.. +#include "../osghangglide/terrain_coords.h" + +osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y) +{ + osgUtil::IntersectVisitor iv; + osg::ref_ptr segDown = new osg::LineSegment; + + const osg::BoundingSphere& bs = subgraph->getBound(); + float zMax = bs.center().z()+bs.radius(); + float zMin = bs.center().z()-bs.radius(); + + segDown->set(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax)); + iv.addLineSegment(segDown.get()); + + subgraph->accept(iv); + + if (iv.hits()) + { + osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get()); + if (!hitList.empty()) + { + osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); + return ip; + } + } + + return osg::Vec3(x,y,0.0f); +} + ////////////////////////////////////////////////////////////////////////////// // MAIN SCENE GRAPH BUILDING FUNCTION @@ -16,13 +51,57 @@ void build_world(osg::Group *root) { + osg::Geode* terrainGeode = new osg::Geode; + { + osg::StateSet* stateset = new osg::StateSet(); + osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + if (image) + { + osg::Texture2D* texture = new osg::Texture2D; + texture->setImage(image); + stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); + } + + terrainGeode->setStateSet( stateset ); + + float size = 1000; // 10km; + float scale = size/39.0f; // 10km; + float z_scale = scale*3.0f; + + osg::HeightField* grid = new osg::HeightField; + grid->allocateGrid(38,39); + grid->setXInterval(scale); + grid->setYInterval(scale); + + for(unsigned int r=0;r<39;++r) + { + for(unsigned int c=0;c<38;++c) + { + grid->setHeight(c,r,z_scale*vertex[r+c*39][2]); + } + } + terrainGeode->addDrawable(new osg::ShapeDrawable(grid)); + + root->addChild(terrainGeode); + } + + + + osg::PositionAttitudeTransform* positionEffects = new osg::PositionAttitudeTransform; + positionEffects->setPosition(computeTerrainIntersection(terrainGeode,100.0f,100.0f)); + root->addChild(positionEffects); + osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect; osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect; osgParticle::FireEffect* fire = new osgParticle::FireEffect; - root->addChild(explosion); - root->addChild(smoke); - root->addChild(fire); + osg::Geode* geode = new osg::Geode; + geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),10.0f))); + positionEffects->addChild(geode); + + positionEffects->addChild(explosion); + positionEffects->addChild(smoke); + positionEffects->addChild(fire); osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater; diff --git a/examples/osgunittests/osgunittests.cpp b/examples/osgunittests/osgunittests.cpp index 61b6065dd..5600c37fc 100644 --- a/examples/osgunittests/osgunittests.cpp +++ b/examples/osgunittests/osgunittests.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/include/osg/AnimationPath b/include/osg/AnimationPath index f7b3794d2..348d62246 100644 --- a/include/osg/AnimationPath +++ b/include/osg/AnimationPath @@ -47,24 +47,24 @@ class SG_EXPORT AnimationPath : public virtual osg::Object ControlPoint(): _scale(1.0f,1.0f,1.0f) {} - ControlPoint(const osg::Vec3& position): + ControlPoint(const osg::Vec3d& position): _position(position), _rotation(), _scale(1.0f,1.0f,1.0f) {} - ControlPoint(const osg::Vec3& position, const osg::Quat& rotation): + ControlPoint(const osg::Vec3d& position, const osg::Quat& rotation): _position(position), _rotation(rotation), _scale(1.0f,1.0f,1.0f) {} - ControlPoint(const osg::Vec3& position, const osg::Quat& rotation, const osg::Vec3& scale): + ControlPoint(const osg::Vec3d& position, const osg::Quat& rotation, const osg::Vec3d& scale): _position(position), _rotation(rotation), _scale(scale) {} - osg::Vec3 _position; + osg::Vec3d _position; osg::Quat _rotation; - osg::Vec3 _scale; + osg::Vec3d _scale; inline void interpolate(float ratio,const ControlPoint& first, const ControlPoint& second) @@ -230,8 +230,8 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback AnimationPath* getAnimationPath() { return _animationPath.get(); } const AnimationPath* getAnimationPath() const { return _animationPath.get(); } - inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; } - inline const Vec3& getPivotPoint() const { return _pivotPoint; } + inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; } + inline const Vec3d& getPivotPoint() const { return _pivotPoint; } void setUseInverseMatrix(bool useInverseMatrix) { _useInverseMatrix = useInverseMatrix; } bool getUseInverseMatrix() const { return _useInverseMatrix; } @@ -259,7 +259,7 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback public: ref_ptr _animationPath; - osg::Vec3 _pivotPoint; + osg::Vec3d _pivotPoint; bool _useInverseMatrix; double _timeOffset; double _timeMultiplier; diff --git a/include/osg/CoordinateSystemNode b/include/osg/CoordinateSystemNode index 8a58e330a..5dfaa984c 100644 --- a/include/osg/CoordinateSystemNode +++ b/include/osg/CoordinateSystemNode @@ -57,7 +57,7 @@ class EllipsoidModel : public Object inline void computeLocalToWorldTransformFromXYZ(double X, double Y, double Z, osg::Matrixd& localToWorld) const; - inline osg::Vec3 computeLocalUpVector(double X, double Y, double Z) const; + inline osg::Vec3d computeLocalUpVector(double X, double Y, double Z) const; protected: @@ -109,16 +109,10 @@ class SG_EXPORT CoordinateSystemNode : public Group const EllipsoidModel* getEllipsoidModel() const { return _ellipsoidModel.get(); } /** compute the local coorindate frame for specified point.*/ - CoordinateFrame computeLocalCoordinateFrame(const Vec3& position) const; + CoordinateFrame computeLocalCoordinateFrame(const Vec3d& position) const; /** compute the local coorindate frame for specified point.*/ - CoordinateFrame computeLocalCoordinateFrame(double X, double Y, double Z) const; - - /** compute the local coorindate frame for specified point.*/ - osg::Vec3 computeLocalUpVector(const Vec3& position) const; - - /** compute the local coorindate frame for specified point.*/ - osg::Vec3 computeLocalUpVector(double X, double Y, double Z) const; + osg::Vec3d computeLocalUpVector(const Vec3d& position) const; protected: @@ -211,7 +205,7 @@ inline void EllipsoidModel::computeLocalToWorldTransformFromXYZ(double X, double localToWorld(2,2) = Z; } -inline osg::Vec3 EllipsoidModel::computeLocalUpVector(double X, double Y, double Z) const +inline osg::Vec3d EllipsoidModel::computeLocalUpVector(double X, double Y, double Z) const { osg::Vec3 normal(X,Y,Z); normal.normalize(); diff --git a/include/osg/Drawable b/include/osg/Drawable index 2360c31d1..1e7cdc1d9 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -22,9 +22,9 @@ namespace osg { -class Vec2; -class Vec3; -class Vec4; +class Vec2f; +class Vec3f; +class Vec4f; class UByte4; class Geometry; diff --git a/include/osg/Matrixd b/include/osg/Matrixd index d1c099acf..74d0ca685 100644 --- a/include/osg/Matrixd +++ b/include/osg/Matrixd @@ -15,8 +15,10 @@ #define OSG_MATRIXD 1 #include -#include -#include +#include +#include +#include +#include #include #include @@ -71,7 +73,7 @@ class SG_EXPORT Matrixd return *this; } - inline Matrixd& operator = (const Matrixf& other); + Matrixd& operator = (const Matrixf& other); inline void set(const Matrixd& rhs) { set(rhs.ptr()); } @@ -103,19 +105,26 @@ class SG_EXPORT Matrixd void makeIdentity(); - void makeScale( const Vec3& ); + void makeScale( const Vec3f& ); + void makeScale( const Vec3d& ); void makeScale( value_type, value_type, value_type ); - void makeTranslate( const Vec3& ); + void makeTranslate( const Vec3f& ); + void makeTranslate( const Vec3d& ); void makeTranslate( value_type, value_type, value_type ); - void makeRotate( const Vec3& from, const Vec3& to ); - void makeRotate( value_type angle, const Vec3& axis ); + 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 ); void makeRotate( value_type angle, value_type x, value_type y, value_type z ); void makeRotate( const Quat& ); - void makeRotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3); + 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); @@ -163,10 +172,13 @@ class SG_EXPORT Matrixd double& zNear, double& zFar) const; /** Set to the position and orientation modelview matrix, using the same convention as gluLookAt. */ - void makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up); - + void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up); + /** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ - void getLookAt(Vec3& eye,Vec3& center,Vec3& up,value_type lookDistance=1.0f) const; + void getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,value_type lookDistance=1.0f) const; + + /** 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; /** invert the matrix rhs. */ bool invert( const Matrixd& rhs); @@ -179,16 +191,23 @@ class SG_EXPORT Matrixd //basic utility functions to create new matrices inline static Matrixd identity( void ); - inline static Matrixd scale( const Vec3& sv); + inline static Matrixd scale( const Vec3f& sv); + inline static Matrixd scale( const Vec3d& sv); inline static Matrixd scale( value_type sx, value_type sy, value_type sz); - inline static Matrixd translate( const Vec3& dv); + inline static Matrixd translate( const Vec3f& dv); + inline static Matrixd translate( const Vec3d& dv); inline static Matrixd translate( value_type x, value_type y, value_type z); - inline static Matrixd rotate( const Vec3& from, const Vec3& to); + inline static Matrixd rotate( const Vec3f& from, const Vec3f& to); + inline static Matrixd rotate( const Vec3d& from, const Vec3d& to); inline static Matrixd rotate( value_type angle, value_type x, value_type y, value_type z); - inline static Matrixd rotate( value_type angle, const Vec3& axis); - inline static Matrixd rotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3); + 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); inline static Matrixd rotate( const Quat& quat); inline static Matrixd inverse( const Matrixd& matrix); @@ -212,29 +231,45 @@ class SG_EXPORT Matrixd double zNear, double zFar); /** Create the position and orientation as per a camera, using the same convention as gluLookAt. */ - inline static Matrixd lookAt(const Vec3& eye,const Vec3& center,const Vec3& up); + 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); - - inline Vec3 preMult( const Vec3& v ) const; - inline Vec3 postMult( const Vec3& v ) const; - inline Vec3 operator* ( const Vec3& v ) const; - inline Vec4 preMult( const Vec4& v ) const; - inline Vec4 postMult( const Vec4& v ) const; - inline Vec4 operator* ( const Vec4& v ) const; + 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; void setTrans( value_type tx, value_type ty, value_type tz ); - void setTrans( const Vec3& v ); - inline Vec3 getTrans() const { return Vec3(_mat[3][0],_mat[3][1],_mat[3][2]); } + void setTrans( const Vec3f& v ); + void setTrans( const Vec3d& v ); - inline Vec3 getScale() const { return Vec3(_mat[0][0],_mat[1][1],_mat[2][2]); } + inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); } + + inline Vec3d getScale() const { return Vec3d(_mat[0][0],_mat[1][1],_mat[2][2]); } /** apply apply an 3x3 transform of v*M[0..2,0..2] */ - inline static Vec3 transform3x3(const Vec3& v,const Matrixd& m); - /** apply apply an 3x3 transform of M[0..2,0..2]*v */ - inline static Vec3 transform3x3(const Matrixd& m,const Vec3& v); + inline static Vec3f transform3x3(const Vec3f& v,const Matrixd& m); + /** apply apply an 3x3 transform of v*M[0..2,0..2] */ + inline static Vec3d transform3x3(const Vec3d& v,const Matrixd& m); + + /** apply apply an 3x3 transform of M[0..2,0..2]*v */ + inline static Vec3f transform3x3(const Matrixd& m,const Vec3f& v); + + /** apply apply an 3x3 transform of M[0..2,0..2]*v */ + inline static Vec3d transform3x3(const Matrixd& m,const Vec3d& v); // basic Matrixd multiplication, our workhorse methods. void mult( const Matrixd&, const Matrixd& ); @@ -307,7 +342,12 @@ inline Matrixd Matrixd::scale(value_type sx, value_type sy, value_type sz) return m; } -inline Matrixd Matrixd::scale(const Vec3& v ) +inline Matrixd Matrixd::scale(const Vec3f& v ) +{ + return scale(v.x(), v.y(), v.z() ); +} + +inline Matrixd Matrixd::scale(const Vec3d& v ) { return scale(v.x(), v.y(), v.z() ); } @@ -319,7 +359,12 @@ inline Matrixd Matrixd::translate(value_type tx, value_type ty, value_type tz) return m; } -inline Matrixd Matrixd::translate(const Vec3& v ) +inline Matrixd Matrixd::translate(const Vec3f& v ) +{ + return translate(v.x(), v.y(), v.z() ); +} + +inline Matrixd Matrixd::translate(const Vec3d& v ) { return translate(v.x(), v.y(), v.z() ); } @@ -334,21 +379,41 @@ inline Matrixd Matrixd::rotate(value_type angle, value_type x, value_type y, val m.makeRotate(angle,x,y,z); return m; } -inline Matrixd Matrixd::rotate(value_type angle, const Vec3& axis ) +inline Matrixd Matrixd::rotate(value_type angle, const Vec3f& axis ) { Matrixd m; m.makeRotate(angle,axis); return m; } -inline Matrixd Matrixd::rotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3) +inline Matrixd Matrixd::rotate(value_type angle, const Vec3d& axis ) +{ + Matrixd m; + m.makeRotate(angle,axis); + return m; +} +inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1, + value_type angle2, const Vec3f& axis2, + value_type angle3, const Vec3f& axis3) { Matrixd m; m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3); return m; } -inline Matrixd Matrixd::rotate(const Vec3& from, const Vec3& to ) +inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1, + value_type angle2, const Vec3d& axis2, + value_type angle3, const Vec3d& axis3) +{ + 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 ) { Matrixd m; m.makeRotate(from,to); @@ -363,8 +428,8 @@ inline Matrixd Matrixd::inverse( const Matrixd& matrix) } inline Matrixd Matrixd::ortho(double left, double right, - double bottom, double top, - double zNear, double zFar) + double bottom, double top, + double zNear, double zFar) { Matrixd m; m.makeOrtho(left,right,bottom,top,zNear,zFar); @@ -372,7 +437,7 @@ inline Matrixd Matrixd::ortho(double left, double right, } inline Matrixd Matrixd::ortho2D(double left, double right, - double bottom, double top) + double bottom, double top) { Matrixd m; m.makeOrtho2D(left,right,bottom,top); @@ -380,8 +445,8 @@ inline Matrixd Matrixd::ortho2D(double left, double right, } inline Matrixd Matrixd::frustum(double left, double right, - double bottom, double top, - double zNear, double zFar) + double bottom, double top, + double zNear, double zFar) { Matrixd m; m.makeFrustum(left,right,bottom,top,zNear,zFar); @@ -396,74 +461,136 @@ inline Matrixd Matrixd::perspective(double fovy,double aspectRatio, return m; } -inline Matrixd Matrixd::lookAt(const Vec3& eye,const Vec3& center,const Vec3& up) +inline Matrixd Matrixd::lookAt(const Vec3f& eye,const Vec3f& center,const Vec3f& up) { Matrixd m; m.makeLookAt(eye,center,up); return m; } +inline Matrixd Matrixd::lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up) +{ + Matrixd m; + m.makeLookAt(eye,center,up); + return m; +} -inline Vec3 Matrixd::postMult( const Vec3& v ) const +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 Vec3( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d, + 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) ; +} +inline Vec3d Matrixd::postMult( const Vec3d& 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 Vec3d( (_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) ; } -inline Vec3 Matrixd::preMult( const Vec3& v ) const +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 Vec3( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d, + 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); +} +inline Vec3d Matrixd::preMult( const Vec3d& 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 Vec3d( (_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); } -inline Vec4 Matrixd::postMult( const Vec4& v ) const +inline Vec4f Matrixd::postMult( const Vec4f& v ) const { - return Vec4( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()), + 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()), (_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 Vec4 Matrixd::preMult( const Vec4& v ) const +inline Vec4f Matrixd::preMult( const Vec4f& v ) const { - return Vec4( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()), + 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())); } -inline Vec3 Matrixd::transform3x3(const Vec3& v,const Matrixd& m) +inline Vec4d Matrixd::preMult( const Vec4d& v ) const { - return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()), + return Vec4d( (_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())); +} +inline Vec3f Matrixd::transform3x3(const Vec3f& v,const Matrixd& m) +{ + 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()), (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 Vec3 Matrixd::transform3x3(const Matrixd& m,const Vec3& v) +inline Vec3f Matrixd::transform3x3(const Matrixd& m,const Vec3f& v) { - return Vec3( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()), + 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) +{ + return Vec3d( (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 Vec3 operator* (const Vec3& v, const Matrixd& m ) +inline Vec3f operator* (const Vec3f& v, const Matrixd& m ) { return m.preMult(v); } -inline Vec4 operator* (const Vec4& v, const Matrixd& m ) +inline Vec3d operator* (const Vec3d& v, const Matrixd& m ) +{ + return m.preMult(v); +} +inline Vec4f operator* (const Vec4f& v, const Matrixd& m ) +{ + return m.preMult(v); +} +inline Vec4d operator* (const Vec4d& v, const Matrixd& m ) { return m.preMult(v); } -inline Vec3 Matrixd::operator* (const Vec3& v) const +inline Vec3f Matrixd::operator* (const Vec3f& v) const { return postMult(v); } -inline Vec4 Matrixd::operator* (const Vec4& v) const +inline Vec3d Matrixd::operator* (const Vec3d& v) const +{ + return postMult(v); +} +inline Vec4f Matrixd::operator* (const Vec4f& v) const +{ + return postMult(v); +} +inline Vec4d Matrixd::operator* (const Vec4d& v) const { return postMult(v); } diff --git a/include/osg/Matrixf b/include/osg/Matrixf index 5796f3323..d42550b6e 100644 --- a/include/osg/Matrixf +++ b/include/osg/Matrixf @@ -15,8 +15,10 @@ #define OSG_MATRIXF 1 #include -#include -#include +#include +#include +#include +#include #include #include @@ -26,12 +28,14 @@ namespace osg { +class Matrixd; + class SG_EXPORT Matrixf { public: - typedef float value_type; + typedef double value_type; inline Matrixf() { makeIdentity(); } inline Matrixf( const Matrixf& mat) { set(mat.ptr()); } @@ -68,13 +72,13 @@ class SG_EXPORT Matrixf set(rhs.ptr()); return *this; } - - Matrixf& operator = (const Matrixd& rhs); - - void set(const Matrixd& rhs); + + Matrixf& operator = (const Matrixd& other); inline void set(const Matrixf& rhs) { set(rhs.ptr()); } + void set(const Matrixd& rhs); + inline void set(float const * const ptr) { value_type* local_ptr = (value_type*)_mat; @@ -101,19 +105,26 @@ class SG_EXPORT Matrixf void makeIdentity(); - void makeScale( const Vec3& ); + void makeScale( const Vec3f& ); + void makeScale( const Vec3d& ); void makeScale( value_type, value_type, value_type ); - void makeTranslate( const Vec3& ); + void makeTranslate( const Vec3f& ); + void makeTranslate( const Vec3d& ); void makeTranslate( value_type, value_type, value_type ); - void makeRotate( const Vec3& from, const Vec3& to ); - void makeRotate( value_type angle, const Vec3& axis ); + 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 ); void makeRotate( value_type angle, value_type x, value_type y, value_type z ); void makeRotate( const Quat& ); - void makeRotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3); + 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); @@ -142,7 +153,7 @@ class SG_EXPORT Matrixf double zNear, double zFar); /** Get the frustum setting of a perspective projection matrix. - * Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/ + * Note, if matrix is not an perspective matrix then invalid values will be returned.*/ bool getFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; @@ -160,14 +171,16 @@ class SG_EXPORT Matrixf bool getPerspective(double& fovy,double& aspectRatio, double& zNear, double& zFar) const; - /** Set to the position and orientation modelview matrix, using the same convention as gluLookAt. */ - void makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up); - - /** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ - void getLookAt(Vec3& eye,Vec3& center,Vec3& up,value_type lookDistance=1.0f) const; + void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up); - /** invert the matrix rhs placing result in this matrix.*/ + /** 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; + + /** 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; + + /** invert the matrix rhs. */ bool invert( const Matrixf& rhs); /** full 4x4 matrix invert. */ @@ -178,16 +191,23 @@ class SG_EXPORT Matrixf //basic utility functions to create new matrices inline static Matrixf identity( void ); - inline static Matrixf scale( const Vec3& sv); + inline static Matrixf scale( const Vec3f& sv); + inline static Matrixf scale( const Vec3d& sv); inline static Matrixf scale( value_type sx, value_type sy, value_type sz); - inline static Matrixf translate( const Vec3& dv); + inline static Matrixf translate( const Vec3f& dv); + inline static Matrixf translate( const Vec3d& dv); inline static Matrixf translate( value_type x, value_type y, value_type z); - inline static Matrixf rotate( const Vec3& from, const Vec3& to); + inline static Matrixf rotate( const Vec3f& from, const Vec3f& to); + inline static Matrixf rotate( const Vec3d& from, const Vec3d& to); inline static Matrixf rotate( value_type angle, value_type x, value_type y, value_type z); - inline static Matrixf rotate( value_type angle, const Vec3& axis); - inline static Matrixf rotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3); + inline static Matrixf rotate( value_type angle, const Vec3f& axis); + inline static Matrixf rotate( value_type angle, const Vec3d& axis); + inline static Matrixf rotate( value_type angle1, const Vec3f& axis1, + value_type angle2, const Vec3f& axis2, + value_type angle3, const Vec3f& axis3); + inline static Matrixf rotate( value_type angle1, const Vec3d& axis1, + value_type angle2, const Vec3d& axis2, + value_type angle3, const Vec3d& axis3); inline static Matrixf rotate( const Quat& quat); inline static Matrixf inverse( const Matrixf& matrix); @@ -211,29 +231,45 @@ class SG_EXPORT Matrixf double zNear, double zFar); /** Create the position and orientation as per a camera, using the same convention as gluLookAt. */ - inline static Matrixf lookAt(const Vec3& eye,const Vec3& center,const Vec3& up); + inline static Matrixf 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 Matrixf lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up); - - inline Vec3 preMult( const Vec3& v ) const; - inline Vec3 postMult( const Vec3& v ) const; - inline Vec3 operator* ( const Vec3& v ) const; - inline Vec4 preMult( const Vec4& v ) const; - inline Vec4 postMult( const Vec4& v ) const; - inline Vec4 operator* ( const Vec4& v ) const; + 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; void setTrans( value_type tx, value_type ty, value_type tz ); - void setTrans( const Vec3& v ); - inline Vec3 getTrans() const { return Vec3(_mat[3][0],_mat[3][1],_mat[3][2]); } + void setTrans( const Vec3f& v ); + void setTrans( const Vec3d& v ); - inline Vec3 getScale() const { return Vec3(_mat[0][0],_mat[1][1],_mat[2][2]); } + inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); } + + inline Vec3d getScale() const { return Vec3d(_mat[0][0],_mat[1][1],_mat[2][2]); } /** apply apply an 3x3 transform of v*M[0..2,0..2] */ - inline static Vec3 transform3x3(const Vec3& v,const Matrixf& m); - /** apply apply an 3x3 transform of M[0..2,0..2]*v */ - inline static Vec3 transform3x3(const Matrixf& m,const Vec3& v); + inline static Vec3f transform3x3(const Vec3f& v,const Matrixf& m); + /** apply apply an 3x3 transform of v*M[0..2,0..2] */ + inline static Vec3d transform3x3(const Vec3d& v,const Matrixf& m); + + /** apply apply an 3x3 transform of M[0..2,0..2]*v */ + inline static Vec3f transform3x3(const Matrixf& m,const Vec3f& v); + + /** apply apply an 3x3 transform of M[0..2,0..2]*v */ + inline static Vec3d transform3x3(const Matrixf& m,const Vec3d& v); // basic Matrixf multiplication, our workhorse methods. void mult( const Matrixf&, const Matrixf& ); @@ -306,7 +342,12 @@ inline Matrixf Matrixf::scale(value_type sx, value_type sy, value_type sz) return m; } -inline Matrixf Matrixf::scale(const Vec3& v ) +inline Matrixf Matrixf::scale(const Vec3f& v ) +{ + return scale(v.x(), v.y(), v.z() ); +} + +inline Matrixf Matrixf::scale(const Vec3d& v ) { return scale(v.x(), v.y(), v.z() ); } @@ -318,7 +359,12 @@ inline Matrixf Matrixf::translate(value_type tx, value_type ty, value_type tz) return m; } -inline Matrixf Matrixf::translate(const Vec3& v ) +inline Matrixf Matrixf::translate(const Vec3f& v ) +{ + return translate(v.x(), v.y(), v.z() ); +} + +inline Matrixf Matrixf::translate(const Vec3d& v ) { return translate(v.x(), v.y(), v.z() ); } @@ -333,21 +379,41 @@ inline Matrixf Matrixf::rotate(value_type angle, value_type x, value_type y, val m.makeRotate(angle,x,y,z); return m; } -inline Matrixf Matrixf::rotate(value_type angle, const Vec3& axis ) +inline Matrixf Matrixf::rotate(value_type angle, const Vec3f& axis ) { Matrixf m; m.makeRotate(angle,axis); return m; } -inline Matrixf Matrixf::rotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3) +inline Matrixf Matrixf::rotate(value_type angle, const Vec3d& axis ) +{ + Matrixf m; + m.makeRotate(angle,axis); + return m; +} +inline Matrixf Matrixf::rotate( value_type angle1, const Vec3f& axis1, + value_type angle2, const Vec3f& axis2, + value_type angle3, const Vec3f& axis3) { Matrixf m; m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3); return m; } -inline Matrixf Matrixf::rotate(const Vec3& from, const Vec3& to ) +inline Matrixf Matrixf::rotate( value_type angle1, const Vec3d& axis1, + value_type angle2, const Vec3d& axis2, + value_type angle3, const Vec3d& axis3) +{ + Matrixf m; + m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3); + return m; +} +inline Matrixf Matrixf::rotate(const Vec3f& from, const Vec3f& to ) +{ + Matrixf m; + m.makeRotate(from,to); + return m; +} +inline Matrixf Matrixf::rotate(const Vec3d& from, const Vec3d& to ) { Matrixf m; m.makeRotate(from,to); @@ -395,74 +461,136 @@ inline Matrixf Matrixf::perspective(double fovy,double aspectRatio, return m; } -inline Matrixf Matrixf::lookAt(const Vec3& eye,const Vec3& center,const Vec3& up) +inline Matrixf Matrixf::lookAt(const Vec3f& eye,const Vec3f& center,const Vec3f& up) { Matrixf m; m.makeLookAt(eye,center,up); return m; } +inline Matrixf Matrixf::lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up) +{ + Matrixf m; + m.makeLookAt(eye,center,up); + return m; +} -inline Vec3 Matrixf::postMult( const Vec3& v ) const +inline Vec3f Matrixf::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 Vec3( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d, + 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) ; +} +inline Vec3d Matrixf::postMult( const Vec3d& 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 Vec3d( (_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) ; } -inline Vec3 Matrixf::preMult( const Vec3& v ) const +inline Vec3f Matrixf::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 Vec3( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d, + 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); +} +inline Vec3d Matrixf::preMult( const Vec3d& 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 Vec3d( (_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); } -inline Vec4 Matrixf::postMult( const Vec4& v ) const +inline Vec4f Matrixf::postMult( const Vec4f& v ) const { - return Vec4( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()), + 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 Matrixf::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()), (_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 Vec4 Matrixf::preMult( const Vec4& v ) const +inline Vec4f Matrixf::preMult( const Vec4f& v ) const { - return Vec4( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()), + 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())); } -inline Vec3 Matrixf::transform3x3(const Vec3& v,const Matrixf& m) +inline Vec4d Matrixf::preMult( const Vec4d& v ) const { - return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()), + return Vec4d( (_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())); +} +inline Vec3f Matrixf::transform3x3(const Vec3f& v,const Matrixf& m) +{ + 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 Matrixf::transform3x3(const Vec3d& v,const Matrixf& m) +{ + return Vec3d( (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 Vec3 Matrixf::transform3x3(const Matrixf& m,const Vec3& v) +inline Vec3f Matrixf::transform3x3(const Matrixf& m,const Vec3f& v) { - return Vec3( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()), + 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 Matrixf::transform3x3(const Matrixf& m,const Vec3d& v) +{ + return Vec3d( (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 Vec3 operator* (const Vec3& v, const Matrixf& m ) +inline Vec3f operator* (const Vec3f& v, const Matrixf& m ) { return m.preMult(v); } -inline Vec4 operator* (const Vec4& v, const Matrixf& m ) +inline Vec3d operator* (const Vec3d& v, const Matrixf& m ) +{ + return m.preMult(v); +} +inline Vec4f operator* (const Vec4f& v, const Matrixf& m ) +{ + return m.preMult(v); +} +inline Vec4d operator* (const Vec4d& v, const Matrixf& m ) { return m.preMult(v); } -inline Vec3 Matrixf::operator* (const Vec3& v) const +inline Vec3f Matrixf::operator* (const Vec3f& v) const { return postMult(v); } -inline Vec4 Matrixf::operator* (const Vec4& v) const +inline Vec3d Matrixf::operator* (const Vec3d& v) const +{ + return postMult(v); +} +inline Vec4f Matrixf::operator* (const Vec4f& v) const +{ + return postMult(v); +} +inline Vec4d Matrixf::operator* (const Vec4d& v) const { return postMult(v); } diff --git a/include/osg/PositionAttitudeTransform b/include/osg/PositionAttitudeTransform index 69b9fc18f..02ce19a56 100644 --- a/include/osg/PositionAttitudeTransform +++ b/include/osg/PositionAttitudeTransform @@ -17,6 +17,7 @@ #include #include #include +#include #include namespace osg { @@ -42,20 +43,20 @@ class SG_EXPORT PositionAttitudeTransform : public Transform virtual PositionAttitudeTransform* asPositionAttitudeTransform() { return this; } virtual const PositionAttitudeTransform* asPositionAttitudeTransform() const { return this; } - inline void setPosition(const Vec3& pos) { _position = pos; dirtyBound(); } - inline const Vec3& getPosition() const { return _position; } + inline void setPosition(const Vec3d& pos) { _position = pos; dirtyBound(); } + inline const Vec3d& getPosition() const { return _position; } inline void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); } inline const Quat& getAttitude() const { return _attitude; } - inline void setScale(const Vec3& scale) { _scale = scale; dirtyBound(); } - inline const Vec3& getScale() const { return _scale; } + inline void setScale(const Vec3d& scale) { _scale = scale; dirtyBound(); } + inline const Vec3d& getScale() const { return _scale; } - inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; dirtyBound(); } - inline const Vec3& getPivotPoint() const { return _pivotPoint; } + inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; dirtyBound(); } + inline const Vec3d& getPivotPoint() const { return _pivotPoint; } virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const; @@ -66,10 +67,10 @@ class SG_EXPORT PositionAttitudeTransform : public Transform virtual ~PositionAttitudeTransform() {} - Vec3 _position; + Vec3d _position; Quat _attitude; - Vec3 _scale; - Vec3 _pivotPoint; + Vec3d _scale; + Vec3d _pivotPoint; }; } diff --git a/include/osg/Quat b/include/osg/Quat index 4681f8c89..93cde38d8 100644 --- a/include/osg/Quat +++ b/include/osg/Quat @@ -15,8 +15,10 @@ #define OSG_QUAT 1 #include -#include -#include +#include +#include +#include +#include namespace osg { @@ -43,7 +45,7 @@ class SG_EXPORT Quat _v[3]=w; } - inline Quat( const Vec4& v ) + inline Quat( const Vec4f& v ) { _v[0]=v.x(); _v[1]=v.y(); @@ -51,19 +53,38 @@ class SG_EXPORT Quat _v[3]=v.w(); } - inline Quat( value_type angle, const Vec3& axis) + inline Quat( const Vec4d& v ) + { + _v[0]=v.x(); + _v[1]=v.y(); + _v[2]=v.z(); + _v[3]=v.w(); + } + + inline Quat( value_type angle, const Vec3f& axis) + { + makeRotate(angle,axis); + } + inline Quat( value_type angle, const Vec3d& axis) { makeRotate(angle,axis); } - inline Quat( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3) + inline Quat( value_type angle1, const Vec3f& axis1, + value_type angle2, const Vec3f& axis2, + value_type angle3, const Vec3f& axis3) { makeRotate(angle1,axis1,angle2,axis2,angle3,axis3); } - inline bool operator == (const Quat& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; } + inline Quat( value_type angle1, const Vec3d& axis1, + value_type angle2, const Vec3d& axis2, + value_type angle3, const Vec3d& axis3) + { + makeRotate(angle1,axis1,angle2,axis2,angle3,axis3); + } + + inline bool operator == (const Quat& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; } inline bool operator != (const Quat& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; } @@ -82,14 +103,14 @@ class SG_EXPORT Quat Methods to access data members ---------------------------------- */ - inline Vec4 asVec4() const + inline Vec4d asVec4() const { - return Vec4(_v[0], _v[1], _v[2], _v[3]); + return Vec4d(_v[0], _v[1], _v[2], _v[3]); } - inline Vec3 asVec3() const + inline Vec3d asVec3() const { - return Vec3(_v[0], _v[1], _v[2]); + return Vec3d(_v[0], _v[1], _v[2]); } inline void set(value_type x, value_type y, value_type z, value_type w) @@ -100,7 +121,15 @@ class SG_EXPORT Quat _v[3]=w; } - inline void set(const osg::Vec4& v) + inline void set(const osg::Vec4f& v) + { + _v[0]=v.x(); + _v[1]=v.y(); + _v[2]=v.z(); + _v[3]=v.w(); + } + + inline void set(const osg::Vec4d& v) { _v[0]=v.x(); _v[1]=v.y(); @@ -215,7 +244,7 @@ class SG_EXPORT Quat /// Binary addition inline const Quat operator + (const Quat& rhs) const { - return Vec4(_v[0]+rhs._v[0], _v[1]+rhs._v[1], + return Quat(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]); } @@ -289,23 +318,37 @@ class SG_EXPORT Quat -------------------------------------------------------- */ void makeRotate( value_type angle, value_type x, value_type y, value_type z ); - void makeRotate ( value_type angle, const Vec3& vec ); + void makeRotate ( value_type angle, const Vec3f& vec ); + void makeRotate ( value_type angle, const Vec3d& vec ); - void makeRotate ( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3); + 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); /** Make a rotation Quat which will rotate vec1 to vec2. Generally take adot product to get the angle between these and then use a cross product to get the rotation axis Watch out for the two special cases of when the vectors are co-incident or opposite in direction.*/ - void makeRotate( const Vec3& vec1, const Vec3& vec2 ); + void makeRotate( const Vec3f& vec1, const Vec3f& vec2 ); + /** Make a rotation Quat which will rotate vec1 to vec2. + Generally take adot product to get the angle between these + and then use a cross product to get the rotation axis + Watch out for the two special cases of when the vectors + are co-incident or opposite in direction.*/ + void makeRotate( const Vec3d& vec1, const Vec3d& vec2 ); /** Return the angle and vector components represented by the quaternion.*/ void getRotate ( value_type & angle, value_type & x, value_type & y, value_type & z ) const; + /** Return the angle and vector represented by the quaternion.*/ - void getRotate ( value_type & angle, Vec3& vec ) const; + void getRotate ( value_type & angle, Vec3f& vec ) const; + + /** Return the angle and vector represented by the quaternion.*/ + void getRotate ( value_type & angle, Vec3d& vec ) const; /** Spherical Linear Interpolation. As t goes from 0 to 1, the Quat object goes from "from" to "to". */ diff --git a/include/osg/Vec2 b/include/osg/Vec2 index 552ac5ec8..d4d27f6a1 100644 --- a/include/osg/Vec2 +++ b/include/osg/Vec2 @@ -14,159 +14,12 @@ #ifndef OSG_VEC2 #define OSG_VEC2 1 -#include - -#include +#include namespace osg { -/** General purpose float pair, uses include representation of - texture coordinates. - No support yet added for float * Vec2 - is it necessary? - Need to define a non-member non-friend operator* etc. - BTW: Vec2 * float is okay -*/ + typedef Vec2f Vec2; -class Vec2 -{ - public: +} - Vec2() {_v[0]=0.0f; _v[1]=0.0f;} - Vec2(float x,float y) { _v[0]=x; _v[1]=y; } - - float _v[2]; - - inline bool operator == (const Vec2& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; } - - inline bool operator != (const Vec2& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; } - - inline bool operator < (const Vec2& v) const - { - if (_v[0]v._v[0]) return false; - else return (_v[1]0.0f) - { - float inv = 1.0f/norm; - _v[0] *= inv; - _v[1] *= inv; - } - return( norm ); - } - - friend inline std::ostream& operator << (std::ostream& output, const Vec2& vec) - { - output << vec._v[0] << " " - << vec._v[1]; - return output; // to enable cascading - } - -}; // end of class Vec2 - -} // end of namespace osg #endif diff --git a/include/osg/Vec2d b/include/osg/Vec2d new file mode 100644 index 000000000..70194fedd --- /dev/null +++ b/include/osg/Vec2d @@ -0,0 +1,179 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * 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_VEC2D +#define OSG_VEC2D 1 + +#include + +#include + +namespace osg { + +/** General purpose float pair, uses include representation of + texture coordinates. + No support yet added for float * Vec2d - is it necessary? + Need to define a non-member non-friend operator* etc. + BTW: Vec2d * float is okay +*/ + +class Vec2d +{ + public: + + typedef float value_type; + value_type _v[2]; + + Vec2d() {_v[0]=0.0; _v[1]=0.0;} + + Vec2d(float x,float y) { _v[0]=x; _v[1]=y; } + + inline Vec2d(const Vec2f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]} + + inline operator Vec3f() const { return Vec2f(_v[0],_v[1]);} + + + inline bool operator == (const Vec2d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; } + + inline bool operator != (const Vec2d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; } + + inline bool operator < (const Vec2d& v) const + { + if (_v[0]v._v[0]) return false; + else return (_v[1]0.0) + { + float inv = 1.0/norm; + _v[0] *= inv; + _v[1] *= inv; + } + return( norm ); + } + + friend inline std::ostream& operator << (std::ostream& output, const Vec2d& vec) + { + output << vec._v[0] << " " + << vec._v[1]; + return output; // to enable cascading + } + +}; // end of class Vec2d + +} // end of namespace osg +#endif diff --git a/include/osg/Vec2f b/include/osg/Vec2f new file mode 100644 index 000000000..ea8017bf5 --- /dev/null +++ b/include/osg/Vec2f @@ -0,0 +1,174 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * 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_VEC2F +#define OSG_VEC2F 1 + +#include + +#include + +namespace osg { + +/** General purpose float pair, uses include representation of + texture coordinates. + No support yet added for float * Vec2f - is it necessary? + Need to define a non-member non-friend operator* etc. + BTW: Vec2f * float is okay +*/ + +class Vec2f +{ + public: + + typedef float value_type; + value_type _v[2]; + + Vec2f() {_v[0]=0.0; _v[1]=0.0;} + Vec2f(float x,float y) { _v[0]=x; _v[1]=y; } + + + inline bool operator == (const Vec2f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; } + + inline bool operator != (const Vec2f& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; } + + inline bool operator < (const Vec2f& v) const + { + if (_v[0]v._v[0]) return false; + else return (_v[1]0.0) + { + float inv = 1.0/norm; + _v[0] *= inv; + _v[1] *= inv; + } + return( norm ); + } + + friend inline std::ostream& operator << (std::ostream& output, const Vec2f& vec) + { + output << vec._v[0] << " " + << vec._v[1]; + return output; // to enable cascading + } + +}; // end of class Vec2f + +} // end of namespace osg +#endif diff --git a/include/osg/Vec3 b/include/osg/Vec3 index 79bdc914d..ca1b74ecd 100644 --- a/include/osg/Vec3 +++ b/include/osg/Vec3 @@ -14,191 +14,12 @@ #ifndef OSG_VEC3 #define OSG_VEC3 1 -#include - -#include +#include namespace osg { -/** General purpose float triple for use as vertices, vectors and normals. - Provides general maths operations from addition through to cross products. - No support yet added for float * Vec3 - is it necessary? - Need to define a non-member non-friend operator* etc. - Vec3 * float is okay -*/ -class Vec3 -{ - public: + typedef Vec3f Vec3; - Vec3() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f;} - Vec3(float x,float y,float z) { _v[0]=x; _v[1]=y; _v[2]=z; } - - float _v[3]; - - inline bool operator == (const Vec3& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; } - - inline bool operator != (const Vec3& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; } - - inline bool operator < (const Vec3& v) const - { - if (_v[0]v._v[0]) return false; - else if (_v[1]v._v[1]) return false; - else return (_v[2]0.0f) - { - float inv = 1.0f/norm; - _v[0] *= inv; - _v[1] *= inv; - _v[2] *= inv; - } - return( norm ); - } - - friend inline std::ostream& operator << (std::ostream& output, const Vec3& vec); - -}; // end of class Vec3 - -inline std::ostream& operator << (std::ostream& output, const Vec3& vec) -{ - output << vec._v[0] << " " - << vec._v[1] << " " - << vec._v[2]; - return output; // to enable cascading } -const Vec3 X_AXIS(1.0f,0.0f,0.0f); -const Vec3 Y_AXIS(0.0f,1.0f,0.0f); -const Vec3 Z_AXIS(0.0f,0.0f,1.0f); - -} // end of namespace osg - #endif diff --git a/include/osg/Vec3d b/include/osg/Vec3d new file mode 100644 index 000000000..766d00423 --- /dev/null +++ b/include/osg/Vec3d @@ -0,0 +1,207 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * 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_VEC3D +#define OSG_VEC3D 1 + +#include + +#include + +namespace osg { + +/** General purpose float triple for use as vertices, vectors and normals. + Provides general maths operations from addition through to cross products. + No support yet added for float * Vec3d - is it necessary? + Need to define a non-member non-friend operator* etc. + Vec3d * float is okay +*/ + +class Vec3d +{ + public: + + typedef float value_type; + value_type _v[3]; + + Vec3d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;} + + inline Vec3d(const Vec3f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; _v[2]=vec._v[2];} + + inline operator Vec3f() const { return Vec3f(_v[0],_v[1],_v[2]);} + + Vec3d(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; } + + inline bool operator == (const Vec3d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; } + + inline bool operator != (const Vec3d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; } + + inline bool operator < (const Vec3d& v) const + { + if (_v[0]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else return (_v[2]0.0) + { + value_type inv = 1.0/norm; + _v[0] *= inv; + _v[1] *= inv; + _v[2] *= inv; + } + return( norm ); + } + + friend inline std::ostream& operator << (std::ostream& output, const Vec3d& vec); + +}; // end of class Vec3d + +inline std::ostream& operator << (std::ostream& output, const Vec3d& vec) +{ + output << vec._v[0] << " " + << vec._v[1] << " " + << vec._v[2]; + return output; // to enable cascading +} + +} // end of namespace osg + +#endif diff --git a/include/osg/Vec3f b/include/osg/Vec3f new file mode 100644 index 000000000..81716ecc3 --- /dev/null +++ b/include/osg/Vec3f @@ -0,0 +1,206 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * 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_VEC3F +#define OSG_VEC3F 1 + +#include + +#include + +namespace osg { + +/** General purpose float triple for use as vertices, vectors and normals. + Provides general maths operations from addition through to cross products. + No support yet added for float * Vec3f - is it necessary? + Need to define a non-member non-friend operator* etc. + Vec3f * float is okay +*/ +class Vec3f +{ + public: + + typedef float value_type; + value_type _v[3]; + + Vec3f() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;} + Vec3f(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; } + + + inline bool operator == (const Vec3f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; } + + inline bool operator != (const Vec3f& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; } + + inline bool operator < (const Vec3f& v) const + { + if (_v[0]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else return (_v[2]0.0) + { + value_type inv = 1.0/norm; + _v[0] *= inv; + _v[1] *= inv; + _v[2] *= inv; + } + return( norm ); + } + + friend inline std::ostream& operator << (std::ostream& output, const Vec3f& vec); + +}; // end of class Vec3f + +inline std::ostream& operator << (std::ostream& output, const Vec3f& vec) +{ + output << vec._v[0] << " " + << vec._v[1] << " " + << vec._v[2]; + return output; // to enable cascading +} + +const Vec3f X_AXIS(1.0,0.0,0.0); +const Vec3f Y_AXIS(0.0,1.0,0.0); +const Vec3f Z_AXIS(0.0,0.0,1.0); + +} // end of namespace osg + +#endif diff --git a/include/osg/Vec4 b/include/osg/Vec4 index 70f4e40fb..8b5cd896e 100644 --- a/include/osg/Vec4 +++ b/include/osg/Vec4 @@ -14,234 +14,12 @@ #ifndef OSG_VEC4 #define OSG_VEC4 1 -#include - -#include +#include namespace osg { -/** General purpose float quad, uses include representation - of colour coordinates. - No support yet added for float * Vec4 - is it necessary? - Need to define a non-member non-friend operator* etc. - Vec4 * float is okay -*/ -class Vec4 -{ - public: + typedef Vec4f Vec4; - // Methods are defined here so that they are implicitly inlined - - Vec4() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f; _v[3]=0.0f;} - - Vec4(float x, float y, float z, float w) - { - _v[0]=x; - _v[1]=y; - _v[2]=z; - _v[3]=w; - } - - Vec4(const Vec3& v3,float w) - { - _v[0]=v3[0]; - _v[1]=v3[1]; - _v[2]=v3[2]; - _v[3]=w; - } - - - float _v[4]; - - inline bool operator == (const Vec4& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; } - - inline bool operator != (const Vec4& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; } - - inline bool operator < (const Vec4& v) const - { - if (_v[0]v._v[0]) return false; - else if (_v[1]v._v[1]) return false; - else if (_v[2]v._v[2]) return false; - else return (_v[3]0.0f) - { - float inv = 1.0f/norm; - _v[0] *= inv; - _v[1] *= inv; - _v[2] *= inv; - _v[3] *= inv; - } - return( norm ); - } - - friend inline std::ostream& operator << (std::ostream& output, const Vec4& vec) - { - output << vec._v[0] << " " - << vec._v[1] << " " - << vec._v[2] << " " - << vec._v[3]; - return output; // to enable cascading - } - -}; // end of class Vec4 - - -/** Compute the dot product of a (Vec3,1.0) and a Vec4.*/ -inline float operator * (const Vec3& lhs,const Vec4& rhs) -{ - return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3]; } -/** Compute the dot product of a Vec4 and a (Vec3,1.0).*/ -inline float operator * (const Vec4& lhs,const Vec3& rhs) -{ - return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3]; -} - -} // end of namespace osg - #endif diff --git a/include/osg/Vec4d b/include/osg/Vec4d new file mode 100644 index 000000000..f18f11228 --- /dev/null +++ b/include/osg/Vec4d @@ -0,0 +1,252 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * 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_VEC4D +#define OSG_VEC4D 1 + +#include +#include + +namespace osg { + +/** General purpose float quad, uses include representation + of colour coordinates. + No support yet added for float * Vec4d - is it necessary? + Need to define a non-member non-friend operator* etc. + Vec4d * float is okay +*/ +class Vec4d +{ + public: + + typedef float value_type; + + value_type _v[4]; + + // Methods are defined here so that they are implicitly inlined + + Vec4d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0;} + + Vec4d(value_type x, value_type y, value_type z, value_type w) + { + _v[0]=x; + _v[1]=y; + _v[2]=z; + _v[3]=w; + } + + Vec4d(const Vec3d& v3,value_type w) + { + _v[0]=v3[0]; + _v[1]=v3[1]; + _v[2]=v3[2]; + _v[3]=w; + } + + inline Vec4d(const Vec4f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; _v[2]=vec._v[2]; _v[3]=vec._v[3];} + + inline operator Vec4f() const { return Vec4f(_v[0],_v[1],_v[2],_v[3]);} + + + inline bool operator == (const Vec4d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; } + + inline bool operator != (const Vec4d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; } + + inline bool operator < (const Vec4d& v) const + { + if (_v[0]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else if (_v[2]v._v[2]) return false; + else return (_v[3]0.0f) + { + value_type inv = 1.0f/norm; + _v[0] *= inv; + _v[1] *= inv; + _v[2] *= inv; + _v[3] *= inv; + } + return( norm ); + } + + friend inline std::ostream& operator << (std::ostream& output, const Vec4d& vec) + { + output << vec._v[0] << " " + << vec._v[1] << " " + << vec._v[2] << " " + << vec._v[3]; + return output; // to enable cascading + } + +}; // end of class Vec4d + + +/** Compute the dot product of a (Vec3,1.0) and a Vec4d.*/ +inline Vec4d::value_type operator * (const Vec3d& lhs,const Vec4d& rhs) +{ + return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3]; +} + +/** Compute the dot product of a Vec4d and a (Vec3,1.0).*/ +inline Vec4d::value_type operator * (const Vec4d& lhs,const Vec3d& rhs) +{ + return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3]; +} + +} // end of namespace osg + +#endif diff --git a/include/osg/Vec4f b/include/osg/Vec4f new file mode 100644 index 000000000..45aac196a --- /dev/null +++ b/include/osg/Vec4f @@ -0,0 +1,248 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * 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_VEC4F +#define OSG_VEC4F 1 + +#include + +#include + +namespace osg { + +/** General purpose float quad, uses include representation + of colour coordinates. + No support yet added for float * Vec4f - is it necessary? + Need to define a non-member non-friend operator* etc. + Vec4f * float is okay +*/ +class Vec4f +{ + public: + + typedef float value_type; + + value_type _v[4]; + + // Methods are defined here so that they are implicitly inlined + + Vec4f() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0;} + + Vec4f(value_type x, value_type y, value_type z, value_type w) + { + _v[0]=x; + _v[1]=y; + _v[2]=z; + _v[3]=w; + } + + Vec4f(const Vec3f& v3,value_type w) + { + _v[0]=v3[0]; + _v[1]=v3[1]; + _v[2]=v3[2]; + _v[3]=w; + } + + inline bool operator == (const Vec4f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; } + + inline bool operator != (const Vec4f& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; } + + inline bool operator < (const Vec4f& v) const + { + if (_v[0]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else if (_v[2]v._v[2]) return false; + else return (_v[3]0.0f) + { + value_type inv = 1.0f/norm; + _v[0] *= inv; + _v[1] *= inv; + _v[2] *= inv; + _v[3] *= inv; + } + return( norm ); + } + + friend inline std::ostream& operator << (std::ostream& output, const Vec4f& vec) + { + output << vec._v[0] << " " + << vec._v[1] << " " + << vec._v[2] << " " + << vec._v[3]; + return output; // to enable cascading + } + +}; // end of class Vec4f + + +/** Compute the dot product of a (Vec3,1.0) and a Vec4f.*/ +inline Vec4f::value_type operator * (const Vec3f& lhs,const Vec4f& rhs) +{ + return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3]; +} + +/** Compute the dot product of a Vec4f and a (Vec3,1.0).*/ +inline Vec4f::value_type operator * (const Vec4f& lhs,const Vec3f& rhs) +{ + return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3]; +} + +} // end of namespace osg + +#endif diff --git a/include/osgDB/FieldReaderIterator b/include/osgDB/FieldReaderIterator index 6ead28016..88ffbd6d6 100644 --- a/include/osgDB/FieldReaderIterator +++ b/include/osgDB/FieldReaderIterator @@ -14,9 +14,9 @@ #ifndef OSGDB_FIELDREADERITERATOR #define OSGDB_FIELDREADERITERATOR 1 -#include -#include -#include +#include +#include +#include #include #include @@ -66,17 +66,17 @@ class OSGDB_EXPORT FieldReaderIterator bool readSequence(const char* keyword,unsigned int& value); bool readSequence(const char* keyword,int& value); bool readSequence(const char* keyword,float& value); - bool readSequence(const char* keyword,osg::Vec2& value); - bool readSequence(const char* keyword,osg::Vec3& value); - bool readSequence(const char* keyword,osg::Vec4& value); + bool readSequence(const char* keyword,osg::Vec2f& value); + bool readSequence(const char* keyword,osg::Vec3f& value); + bool readSequence(const char* keyword,osg::Vec4f& value); bool readSequence(std::string& value); bool readSequence(unsigned int& value); bool readSequence(int& value); bool readSequence(float& value); - bool readSequence(osg::Vec2& value); - bool readSequence(osg::Vec3& value); - bool readSequence(osg::Vec4& value); + bool readSequence(osg::Vec2f& value); + bool readSequence(osg::Vec3f& value); + bool readSequence(osg::Vec4f& value); private: diff --git a/include/osgGA/DriveManipulator b/include/osgGA/DriveManipulator index d6e9d0263..1b83c5821 100644 --- a/include/osgGA/DriveManipulator +++ b/include/osgGA/DriveManipulator @@ -71,7 +71,7 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator /** Add the current mouse GUIEvent to internal stack.*/ void addMouseEvent(const GUIEventAdapter& ea); - void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up); + void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up); /** For the give mouse movement calculate the movement of the camera. Return true is camera has moved and a redraw is required.*/ @@ -83,10 +83,10 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator osg::ref_ptr _node; - float _modelScale; - float _velocity; - float _height; - float _buffer; + double _modelScale; + double _velocity; + double _height; + double _buffer; enum SpeedControlMode { USE_MOUSE_Y_FOR_SPEED, @@ -95,9 +95,9 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator SpeedControlMode _speedMode; - osg::Vec3 _eye; - osg::Quat _rotation; - float _distance; + osg::Vec3d _eye; + osg::Quat _rotation; + double _distance; }; } diff --git a/include/osgGA/FlightManipulator b/include/osgGA/FlightManipulator index e76b95d3a..9884eb10b 100644 --- a/include/osgGA/FlightManipulator +++ b/include/osgGA/FlightManipulator @@ -92,14 +92,14 @@ class OSGGA_EXPORT FlightManipulator : public MatrixManipulator osg::ref_ptr _node; - float _modelScale; - float _velocity; + double _modelScale; + double _velocity; YawControlMode _yawMode; - osg::Vec3 _eye; + osg::Vec3d _eye; osg::Quat _rotation; - float _distance; + double _distance; }; diff --git a/include/osgGA/MatrixManipulator b/include/osgGA/MatrixManipulator index 86a0b1fd8..4164d262d 100644 --- a/include/osgGA/MatrixManipulator +++ b/include/osgGA/MatrixManipulator @@ -45,7 +45,7 @@ public: class CoordinateFrameCallback : public osg::Referenced { public: - virtual osg::CoordinateFrame getCoordinateFrame(double X, double Y, double Z) const = 0; + virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0; protected: virtual ~CoordinateFrameCallback() {} }; @@ -60,15 +60,15 @@ public: const CoordinateFrameCallback* getCoordinateFrameCallback() const { return _coordinateFrameCallback.get(); } /** get the coordinate frame.*/ - osg::CoordinateFrame getCoordinateFrame(double X, double Y, double Z) const + osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const { - if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(X,Y,Z); + if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position); return osg::CoordinateFrame(); } - osg::Vec3 getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(0,0),cf(0,1),cf(0,2)); } - osg::Vec3 getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(1,0),cf(1,1),cf(1,2)); } - osg::Vec3 getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(2,0),cf(2,1),cf(2,2)); } + osg::Vec3d getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(0,0),cf(0,1),cf(0,2)); } + osg::Vec3d getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(1,0),cf(1,1),cf(1,2)); } + osg::Vec3d getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(2,0),cf(2,1),cf(2,2)); } /** set the position of the matrix manipulator using a 4x4 Matrix.*/ virtual void setByMatrix(const osg::Matrixd& matrix) = 0; diff --git a/include/osgGA/TerrainManipulator b/include/osgGA/TerrainManipulator index 18a5c9edc..942dc7d2e 100644 --- a/include/osgGA/TerrainManipulator +++ b/include/osgGA/TerrainManipulator @@ -98,14 +98,14 @@ class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator /** Add the current mouse GUIEvent to internal stack.*/ void addMouseEvent(const GUIEventAdapter& ea); - void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up); + void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up); /** For the give mouse movement calculate the movement of the camera. Return true is camera has moved and a redraw is required.*/ bool calcMovement(); - void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y); - float tb_project_to_sphere(float r, float x, float y); + void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y); + double tb_project_to_sphere(double r, double x, double y); /** Check the speed at which the mouse is moving. @@ -122,14 +122,14 @@ class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator osg::ref_ptr _node; - float _modelScale; + double _modelScale; RotationMode _rotationMode; - float _minimumZoomScale; + double _minimumZoomScale; bool _thrown; - double _center[3]; + osg::Vec3d _center; osg::Quat _rotation; float _distance; diff --git a/include/osgGA/TrackballManipulator b/include/osgGA/TrackballManipulator index 604486951..c5c5405eb 100644 --- a/include/osgGA/TrackballManipulator +++ b/include/osgGA/TrackballManipulator @@ -106,14 +106,14 @@ class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator osg::ref_ptr _node; - float _modelScale; - float _minimumZoomScale; + double _modelScale; + double _minimumZoomScale; bool _thrown; - osg::Vec3 _center; - osg::Quat _rotation; - float _distance; + osg::Vec3d _center; + osg::Quat _rotation; + double _distance; }; diff --git a/src/osg/AnimationPath.cpp b/src/osg/AnimationPath.cpp index 018c30e1f..ac3e00682 100644 --- a/src/osg/AnimationPath.cpp +++ b/src/osg/AnimationPath.cpp @@ -111,7 +111,7 @@ class AnimationPathCallbackVisitor : public NodeVisitor { public: - AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, const osg::Vec3& pivotPoint, bool useInverseMatrix): + AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, const osg::Vec3d& pivotPoint, bool useInverseMatrix): _cp(cp), _pivotPoint(pivotPoint), _useInverseMatrix(useInverseMatrix) {} @@ -149,7 +149,7 @@ class AnimationPathCallbackVisitor : public NodeVisitor } AnimationPath::ControlPoint _cp; - osg::Vec3 _pivotPoint; + osg::Vec3d _pivotPoint; bool _useInverseMatrix; }; diff --git a/src/osg/CoordinateSystemNode.cpp b/src/osg/CoordinateSystemNode.cpp index 87bb76b1a..0c43c42da 100644 --- a/src/osg/CoordinateSystemNode.cpp +++ b/src/osg/CoordinateSystemNode.cpp @@ -32,41 +32,31 @@ CoordinateSystemNode::CoordinateSystemNode(const CoordinateSystemNode& csn,const _ellipsoidModel = csn._ellipsoidModel; } -CoordinateFrame CoordinateSystemNode::computeLocalCoordinateFrame(const Vec3& position) const -{ - return computeLocalCoordinateFrame(position.x(), position.y(), position.z()); -} - -CoordinateFrame CoordinateSystemNode::computeLocalCoordinateFrame(double X, double Y, double Z) const +CoordinateFrame CoordinateSystemNode::computeLocalCoordinateFrame(const Vec3d& position) const { if (_ellipsoidModel.valid()) { Matrixd localToWorld; - _ellipsoidModel->computeLocalToWorldTransformFromXYZ(X,Y,Z, localToWorld); + _ellipsoidModel->computeLocalToWorldTransformFromXYZ(position.x(),position.y(),position.z(), localToWorld); return localToWorld; } else { - return Matrixd::translate(X,Y,Z); + return Matrixd::translate(position); } } -osg::Vec3 CoordinateSystemNode::computeLocalUpVector(const Vec3& position) const -{ - return computeLocalUpVector(position.x(), position.y(), position.z()); -} - -osg::Vec3 CoordinateSystemNode::computeLocalUpVector(double X, double Y, double Z) const +osg::Vec3d CoordinateSystemNode::computeLocalUpVector(const Vec3d& position) const { if (_ellipsoidModel.valid()) { - return _ellipsoidModel->computeLocalUpVector(X,Y,Z); + return _ellipsoidModel->computeLocalUpVector(position.x(),position.y(),position.z()); } else { - return osg::Vec3(0.0f,0.0f,1.0f); + return osg::Vec3d(0.0f,0.0f,1.0f); } } diff --git a/src/osg/CullStack.cpp b/src/osg/CullStack.cpp index 1eff4b53f..39be0ae2c 100644 --- a/src/osg/CullStack.cpp +++ b/src/osg/CullStack.cpp @@ -214,7 +214,7 @@ void CullStack::pushModelViewMatrix(RefMatrix* matrix) pushCullingSet(); #if 1 - osg::Vec3 slow_eyepoint(osg::Matrix::inverse(*matrix).getTrans()); + osg::Vec3f slow_eyepoint = osg::Matrix::inverse(*matrix).getTrans(); _eyePointStack.push_back(slow_eyepoint); #else diff --git a/src/osg/Matrix_implementation.cpp b/src/osg/Matrix_implementation.cpp index 4d6c75110..46e8e776d 100644 --- a/src/osg/Matrix_implementation.cpp +++ b/src/osg/Matrix_implementation.cpp @@ -175,7 +175,13 @@ void Matrix_implementation::setTrans( value_type tx, value_type ty, value_type t } -void Matrix_implementation::setTrans( const Vec3& v ) +void Matrix_implementation::setTrans( const Vec3f& v ) +{ + _mat[3][0] = v[0]; + _mat[3][1] = v[1]; + _mat[3][2] = v[2]; +} +void Matrix_implementation::setTrans( const Vec3d& v ) { _mat[3][0] = v[0]; _mat[3][1] = v[1]; @@ -190,7 +196,12 @@ void Matrix_implementation::makeIdentity() SET_ROW(3, 0, 0, 0, 1 ) } -void Matrix_implementation::makeScale( const Vec3& v ) +void Matrix_implementation::makeScale( const Vec3f& v ) +{ + makeScale(v[0], v[1], v[2] ); +} + +void Matrix_implementation::makeScale( const Vec3d& v ) { makeScale(v[0], v[1], v[2] ); } @@ -203,7 +214,12 @@ void Matrix_implementation::makeScale( value_type x, value_type y, value_type z SET_ROW(3, 0, 0, 0, 1 ) } -void Matrix_implementation::makeTranslate( const Vec3& v ) +void Matrix_implementation::makeTranslate( const Vec3f& v ) +{ + makeTranslate( v[0], v[1], v[2] ); +} + +void Matrix_implementation::makeTranslate( const Vec3d& v ) { makeTranslate( v[0], v[1], v[2] ); } @@ -216,14 +232,26 @@ void Matrix_implementation::makeTranslate( value_type x, value_type y, value_typ SET_ROW(3, x, y, z, 1 ) } -void Matrix_implementation::makeRotate( const Vec3& from, const Vec3& to ) +void Matrix_implementation::makeRotate( const Vec3f& from, const Vec3f& to ) +{ + Quat quat; + quat.makeRotate(from,to); + set(quat); +} +void Matrix_implementation::makeRotate( const Vec3d& from, const Vec3d& to ) { Quat quat; quat.makeRotate(from,to); set(quat); } -void Matrix_implementation::makeRotate( value_type angle, const Vec3& axis ) +void Matrix_implementation::makeRotate( value_type angle, const Vec3f& axis ) +{ + Quat quat; + quat.makeRotate( angle, axis); + set(quat); +} +void Matrix_implementation::makeRotate( value_type angle, const Vec3d& axis ) { Quat quat; quat.makeRotate( angle, axis); @@ -242,9 +270,20 @@ void Matrix_implementation::makeRotate( const Quat& quat ) set(quat); } -void Matrix_implementation::makeRotate( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3) +void Matrix_implementation::makeRotate( value_type angle1, const Vec3f& axis1, + value_type angle2, const Vec3f& axis2, + value_type angle3, const Vec3f& axis3) +{ + Quat quat; + quat.makeRotate(angle1, axis1, + angle2, axis2, + angle3, axis3); + set(quat); +} + +void Matrix_implementation::makeRotate( value_type angle1, const Vec3d& axis1, + value_type angle2, const Vec3d& axis2, + value_type angle3, const Vec3d& axis3) { Quat quat; quat.makeRotate(angle1, axis1, @@ -688,13 +727,13 @@ bool Matrix_implementation::getPerspective(double& fovy,double& aspectRatio, return false; } -void Matrix_implementation::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up) +void Matrix_implementation::makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up) { - Vec3 f(center-eye); + Vec3d f(center-eye); f.normalize(); - Vec3 s(f^up); + Vec3d s(f^up); s.normalize(); - Vec3 u(s^f); + Vec3d u(s^f); u.normalize(); set( @@ -706,13 +745,25 @@ void Matrix_implementation::makeLookAt(const Vec3& eye,const Vec3& center,const preMult(Matrix_implementation::translate(-eye)); } -void Matrix_implementation::getLookAt(Vec3& eye,Vec3& center,Vec3& up,value_type lookDistance) const + +void Matrix_implementation::getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,value_type lookDistance) const { Matrix_implementation inv; inv.invert(*this); - eye = osg::Vec3(0.0,0.0,0.0)*inv; - up = transform3x3(*this,osg::Vec3(0.0,1.0,0.0)); - center = transform3x3(*this,osg::Vec3(0.0,0.0,-1)); + eye = osg::Vec3f(0.0,0.0,0.0)*inv; + up = transform3x3(*this,osg::Vec3f(0.0,1.0,0.0)); + center = transform3x3(*this,osg::Vec3f(0.0,0.0,-1)); + center.normalize(); + center = eye + center*lookDistance; +} + +void Matrix_implementation::getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,value_type lookDistance) const +{ + Matrix_implementation inv; + inv.invert(*this); + eye = osg::Vec3d(0.0,0.0,0.0)*inv; + up = transform3x3(*this,osg::Vec3d(0.0,1.0,0.0)); + center = transform3x3(*this,osg::Vec3d(0.0,0.0,-1)); center.normalize(); center = eye + center*lookDistance; } diff --git a/src/osg/Quat.cpp b/src/osg/Quat.cpp index d745ba5d0..fe2a16bf5 100644 --- a/src/osg/Quat.cpp +++ b/src/osg/Quat.cpp @@ -12,8 +12,6 @@ */ #include #include -#include -#include #include #include @@ -62,15 +60,28 @@ void Quat::makeRotate( value_type angle, value_type x, value_type y, value_type } -void Quat::makeRotate( value_type angle, const Vec3& vec ) +void Quat::makeRotate( value_type angle, const Vec3f& vec ) +{ + makeRotate( angle, vec[0], vec[1], vec[2] ); +} +void Quat::makeRotate( value_type angle, const Vec3d& vec ) { makeRotate( angle, vec[0], vec[1], vec[2] ); } -void Quat::makeRotate ( value_type angle1, const Vec3& axis1, - value_type angle2, const Vec3& axis2, - value_type angle3, const Vec3& axis3) +void Quat::makeRotate ( value_type angle1, const Vec3f& axis1, + value_type angle2, const Vec3f& axis2, + value_type angle3, const Vec3f& axis3) +{ + makeRotate(angle1,Vec3d(axis1), + angle2,Vec3d(axis2), + angle3,Vec3d(axis3)); +} + +void Quat::makeRotate ( value_type angle1, const Vec3d& axis1, + value_type angle2, const Vec3d& axis2, + value_type angle3, const Vec3d& axis3) { Quat q1; q1.makeRotate(angle1,axis1); Quat q2; q2.makeRotate(angle2,axis2); @@ -79,12 +90,18 @@ void Quat::makeRotate ( value_type angle1, const Vec3& axis1, *this = q1*q2*q3; } + +void Quat::makeRotate( const Vec3f& from, const Vec3f& to ) +{ + makeRotate( Vec3d(from), Vec3d(to) ); +} + // Make a rotation Quat which will rotate vec1 to vec2 // Generally take adot product to get the angle between these // and then use a cross product to get the rotation axis // Watch out for the two special cases of when the vectors // are co-incident or opposite in direction. -void Quat::makeRotate( const Vec3& from, const Vec3& to ) +void Quat::makeRotate( const Vec3d& from, const Vec3d& to ) { const value_type epsilon = 0.00001; @@ -106,15 +123,17 @@ void Quat::makeRotate( const Vec3& from, const Vec3& to ) { // vectors are close to being opposite, so will need to find a // vector orthongonal to from to rotate about. - osg::Vec3 tmp; + Vec3d tmp; if (fabs(from.x()) #include + #include #include #include diff --git a/src/osgDB/FieldReaderIterator.cpp b/src/osgDB/FieldReaderIterator.cpp index 5992a5b8b..290cbc8da 100644 --- a/src/osgDB/FieldReaderIterator.cpp +++ b/src/osgDB/FieldReaderIterator.cpp @@ -433,7 +433,7 @@ bool FieldReaderIterator::readSequence(const char* keyword,float& value) return false; } -bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2& value) +bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2f& value) { if ((*this)[0].matchWord(keyword) && (*this)[1].getFloat(value[0]) && @@ -445,7 +445,7 @@ bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2& value) return false; } -bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3& value) +bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3f& value) { if ((*this)[0].matchWord(keyword) && (*this)[1].getFloat(value[0]) && @@ -458,7 +458,7 @@ bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3& value) return false; } -bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec4& value) +bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec4f& value) { if ((*this)[0].matchWord(keyword) && (*this)[1].getFloat(value[0]) && @@ -513,7 +513,7 @@ bool FieldReaderIterator::readSequence(float& value) return false; } -bool FieldReaderIterator::readSequence(osg::Vec2& value) +bool FieldReaderIterator::readSequence(osg::Vec2f& value) { if ((*this)[0].getFloat(value[0]) && (*this)[1].getFloat(value[1])) @@ -524,7 +524,7 @@ bool FieldReaderIterator::readSequence(osg::Vec2& value) return false; } -bool FieldReaderIterator::readSequence(osg::Vec3& value) +bool FieldReaderIterator::readSequence(osg::Vec3f& value) { if ((*this)[0].getFloat(value[0]) && (*this)[1].getFloat(value[1]) && @@ -536,7 +536,7 @@ bool FieldReaderIterator::readSequence(osg::Vec3& value) return false; } -bool FieldReaderIterator::readSequence(osg::Vec4& value) +bool FieldReaderIterator::readSequence(osg::Vec4f& value) { if ((*this)[0].getFloat(value[0]) && (*this)[1].getFloat(value[1]) && diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index 77db2a4d7..ebe1659c1 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -74,12 +74,12 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) const osg::BoundingSphere& boundingSphere=_node->getBound(); - osg::Vec3 ep = boundingSphere._center; - osg::Vec3 bp = ep; + osg::Vec3d ep = boundingSphere._center; + osg::Vec3d bp = ep; - osg::CoordinateFrame cf=getCoordinateFrame(ep.x(), ep.y(), ep.z()); + osg::CoordinateFrame cf=getCoordinateFrame(ep); - ep -= getUpVector(cf)* _modelScale*0.0001f; + ep -= getUpVector(cf)* _modelScale*0.0001; bp -= getUpVector(cf)* _modelScale; // check to see if any obstruction in front. @@ -99,16 +99,16 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) if (!hitList.empty()) { // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); + osg::Vec3d np = hitList.front().getWorldIntersectNormal(); - osg::Vec3 uv; - if (np * getUpVector(cf)>0.0f) uv = np; + osg::Vec3d uv; + if (np * getUpVector(cf)>0.0) uv = np; else uv = -np; ep = ip; ep += getUpVector(cf)*_height; - osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f); + osg::Vec3 lv = uv^osg::Vec3d(1.0,0.0,0.0); computePosition(ep,lv,uv); @@ -135,16 +135,16 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) if (!hitList.empty()) { // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); + osg::Vec3d np = hitList.front().getWorldIntersectNormal(); - osg::Vec3 uv; - if (np*getUpVector(cf)>0.0f) uv = np; + osg::Vec3d uv; + if (np*getUpVector(cf)>0.0) uv = np; else uv = -np; ep = ip; ep += getUpVector(cf)*_height; - osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f); + osg::Vec3 lv = uv^osg::Vec3d(1.0,0.0,0.0); computePosition(ep,lv,uv); positionSet = true; @@ -157,14 +157,14 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) if (!positionSet) { computePosition( - boundingSphere._center+osg::Vec3( 0.0,-2.0f * boundingSphere._radius,0.0f), - osg::Vec3(0.0f,1.0f,0.0f), - osg::Vec3(0.0f,0.0f,1.0f)); + boundingSphere._center+osg::Vec3d( 0.0,-2.0 * boundingSphere._radius,0.0), + osg::Vec3d(0.0,1.0,0.0), + osg::Vec3d(0.0,0.0,1.0)); } } - _velocity = 0.0f; + _velocity = 0.0; us.requestRedraw(); @@ -181,14 +181,14 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) _velocity = 0.0f; - osg::Vec3 ep = _eye; + osg::Vec3d ep = _eye; - osg::CoordinateFrame cf=getCoordinateFrame(ep.x(), ep.y(), ep.z()); + osg::CoordinateFrame cf=getCoordinateFrame(ep); Matrixd rotation_matrix; rotation_matrix.set(_rotation); - osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix; - osg::Vec3 bp = ep; + osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix; + osg::Vec3d bp = ep; bp -= getUpVector(cf)*_modelScale; // check to see if any obstruction in front. @@ -208,15 +208,15 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) if (!hitList.empty()) { // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); + osg::Vec3d np = hitList.front().getWorldIntersectNormal(); - osg::Vec3 uv; - if (np*getUpVector(cf)>0.0f) uv = np; + osg::Vec3d uv; + if (np*getUpVector(cf)>0.0) uv = np; else uv = -np; ep = ip+uv*_height; - osg::Vec3 lv = uv^sv; + osg::Vec3d lv = uv^sv; computePosition(ep,lv,uv); @@ -386,19 +386,19 @@ osg::Matrixd DriveManipulator::getInverseMatrix() const 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) +void DriveManipulator::computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up) { - osg::Vec3 f(lv); + osg::Vec3d f(lv); f.normalize(); - osg::Vec3 s(f^up); + osg::Vec3d s(f^up); s.normalize(); - osg::Vec3 u(s^f); + osg::Vec3d u(s^f); u.normalize(); - osg::Matrix 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); + osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0, + s[1], u[1], -f[1], 0.0, + s[2], u[2], -f[2], 0.0, + 0.0, 0.0, 0.0, 1.0); _eye = eye; rotation_matrix.get(_rotation); @@ -423,7 +423,7 @@ bool DriveManipulator::calcMovement() { case(USE_MOUSE_Y_FOR_SPEED): { - float dy = _ga_t0->getYnormalized(); + double dy = _ga_t0->getYnormalized(); _velocity = _modelScale*0.2f*dy; break; } @@ -434,53 +434,53 @@ bool DriveManipulator::calcMovement() { // pan model. - _velocity += dt*_modelScale*0.02f; + _velocity += dt*_modelScale*0.02; } else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON || buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON)) { - _velocity = 0.0f; + _velocity = 0.0; } else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON) { - _velocity -= dt*_modelScale*0.02f; + _velocity -= dt*_modelScale*0.02; } break; } } - osg::CoordinateFrame cf=getCoordinateFrame(_eye.x(), _eye.y(), _eye.z()); + osg::CoordinateFrame cf=getCoordinateFrame(_eye); osg::Matrix rotation_matrix; rotation_matrix.makeRotate(_rotation); - osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix; - osg::Vec3 lv = osg::Vec3(0.0f,0.0f,-1.0f) * rotation_matrix; + osg::Vec3d up = osg::Vec3d(0.0,1.0,0.0) * rotation_matrix; + osg::Vec3d lv = osg::Vec3d(0.0,0.0,-1.0) * rotation_matrix; // rotate the camera. - float dx = _ga_t0->getXnormalized(); + double dx = _ga_t0->getXnormalized(); - float yaw = -inDegrees(dx*50.0f*dt); + double yaw = -inDegrees(dx*50.0f*dt); osg::Quat yaw_rotation; yaw_rotation.makeRotate(yaw,up); _rotation *= yaw_rotation; rotation_matrix.makeRotate(_rotation); - osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix; + osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix; // movement is big enough the move the eye point along the look vector. - if (fabsf(_velocity*dt)>1e-8) + if (fabs(_velocity*dt)>1e-8) { - float distanceToMove = _velocity*dt; + double distanceToMove = _velocity*dt; - float signedBuffer; - if (distanceToMove>=0.0f) signedBuffer=_buffer; + double signedBuffer; + if (distanceToMove>=0.0) signedBuffer=_buffer; else signedBuffer=-_buffer; // check to see if any obstruction in front. @@ -497,16 +497,16 @@ bool DriveManipulator::calcMovement() if (!hitList.empty()) { // notify(INFO) << "Hit obstruction"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); distanceToMove = (ip-_eye).length()-_buffer; - _velocity = 0.0f; + _velocity = 0.0; } } // check to see if forward point is correct height above terrain. - osg::Vec3 fp = _eye+lv*distanceToMove; - osg::Vec3 lfp = fp-up*_height*5; + osg::Vec3d fp = _eye+lv*distanceToMove; + osg::Vec3d lfp = fp-up*_height*5; iv.reset(); @@ -522,10 +522,10 @@ bool DriveManipulator::calcMovement() if (!hitList.empty()) { // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); + osg::Vec3d np = hitList.front().getWorldIntersectNormal(); - if (up*np>0.0f) up = np; + if (up*np>0.0) up = np; else up = -np; _eye = ip+up*_height; @@ -542,7 +542,7 @@ bool DriveManipulator::calcMovement() // no hit on the terrain found therefore resort to a fall under // under the influence of gravity. - osg::Vec3 dp = lfp; + osg::Vec3d dp = lfp; dp -= getUpVector(cf)* (2*_modelScale); iv.reset(); @@ -560,10 +560,10 @@ bool DriveManipulator::calcMovement() { notify(INFO) << "Hit terrain on decent ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); + osg::Vec3d np = hitList.front().getWorldIntersectNormal(); - if (up*np>0.0f) up = np; + if (up*np>0.0) up = np; else up = -np; _eye = ip+up*_height; diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index 769e6707d..1a702025b 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -257,19 +257,19 @@ bool FlightManipulator::calcMovement() float dx = _ga_t0->getXnormalized(); float dy = _ga_t0->getYnormalized(); - osg::CoordinateFrame cf=getCoordinateFrame(_eye.x(), _eye.y(), _eye.z()); + osg::CoordinateFrame cf=getCoordinateFrame(_eye); osg::Matrixd rotation_matrix; rotation_matrix.makeRotate(_rotation); - osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix; - osg::Vec3 lv = osg::Vec3(0.0f,0.0f,-1.0f) * rotation_matrix; + osg::Vec3d up = osg::Vec3(0.0,1.0,0.0) * rotation_matrix; + osg::Vec3d lv = osg::Vec3(0.0,0.0,-1.0) * rotation_matrix; - osg::Vec3 sv = lv^up; + osg::Vec3d sv = lv^up; sv.normalize(); - float pitch = -inDegrees(dy*75.0f*dt); - float roll = inDegrees(dx*50.0f*dt); + double pitch = -inDegrees(dy*75.0f*dt); + double roll = inDegrees(dx*50.0f*dt); osg::Quat delta_rotate; @@ -284,8 +284,8 @@ bool FlightManipulator::calcMovement() if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED) { //float bank = asinf(sv.z()); - float bank = asinf(sv *getUpVector(cf)); - float yaw = inRadians(bank)*dt; + double bank = asinf(sv *getUpVector(cf)); + double yaw = inRadians(bank)*dt; osg::Quat yaw_rotate; //yaw_rotate.makeRotate(yaw,0.0f,0.0f,1.0f); diff --git a/src/osgGA/TerrainManipulator.cpp b/src/osgGA/TerrainManipulator.cpp index 419fd0c5a..3839309cc 100644 --- a/src/osgGA/TerrainManipulator.cpp +++ b/src/osgGA/TerrainManipulator.cpp @@ -211,8 +211,8 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix) const osg::BoundingSphere& bs = _node->getBound(); float distance = (eye-bs.center()).length() + _node->getBound().radius(); - osg::Vec3 start_segment = eye; - osg::Vec3 end_segment = eye + lookVector*distance; + osg::Vec3d start_segment = eye; + osg::Vec3d end_segment = eye + lookVector*distance; //CoordinateFrame coordinateFrame = getCoordinateFrame(_center.x(), _center.y(), _center.z()); //osg::notify(INFO)<<"start="<getXnormalized()-_ga_t1->getXnormalized(); - float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized(); + double dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized(); + double dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized(); // return if there is no movement. @@ -373,13 +364,13 @@ bool TerrainManipulator::calcMovement() { // rotate camera. osg::Vec3 axis; - float angle; + double angle; - float px0 = _ga_t0->getXnormalized(); - float py0 = _ga_t0->getYnormalized(); + double px0 = _ga_t0->getXnormalized(); + double py0 = _ga_t0->getYnormalized(); - float px1 = _ga_t1->getXnormalized(); - float py1 = _ga_t1->getYnormalized(); + double px1 = _ga_t1->getXnormalized(); + double py1 = _ga_t1->getYnormalized(); trackball(axis,angle,px1,py1,px0,py0); @@ -394,15 +385,15 @@ bool TerrainManipulator::calcMovement() osg::Matrix rotation_matrix; rotation_matrix.set(_rotation); - osg::Vec3 lookVector = -getUpVector(rotation_matrix); - osg::Vec3 sideVector = getSideVector(rotation_matrix); - osg::Vec3 upVector = getFrontVector(rotation_matrix); + osg::Vec3d lookVector = -getUpVector(rotation_matrix); + osg::Vec3d sideVector = getSideVector(rotation_matrix); + osg::Vec3d upVector = getFrontVector(rotation_matrix); - CoordinateFrame coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]); - osg::Vec3 localUp = getUpVector(coordinateFrame); + CoordinateFrame coordinateFrame = getCoordinateFrame(_center); + osg::Vec3d localUp = getUpVector(coordinateFrame); - osg::Vec3 forwardVector = localUp^sideVector; + osg::Vec3d forwardVector = localUp^sideVector; sideVector = forwardVector^localUp; forwardVector.normalize(); @@ -425,44 +416,41 @@ bool TerrainManipulator::calcMovement() { // pan model. - float scale = -0.5f*_distance; + double scale = -0.5f*_distance; osg::Matrix rotation_matrix; rotation_matrix.set(_rotation); // compute look vector. - osg::Vec3 lookVector = -getUpVector(rotation_matrix); - osg::Vec3 sideVector = getSideVector(rotation_matrix); - osg::Vec3 upVector = getFrontVector(rotation_matrix); + osg::Vec3d lookVector = -getUpVector(rotation_matrix); + osg::Vec3d sideVector = getSideVector(rotation_matrix); + osg::Vec3d upVector = getFrontVector(rotation_matrix); - CoordinateFrame coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]); - osg::Vec3 localUp = getUpVector(coordinateFrame); + CoordinateFrame coordinateFrame = getCoordinateFrame(_center); + osg::Vec3d localUp = getUpVector(coordinateFrame); - osg::Vec3 forwardVector =localUp^sideVector; + osg::Vec3d forwardVector =localUp^sideVector; sideVector = forwardVector^localUp; forwardVector.normalize(); sideVector.normalize(); - osg::Vec3 dv = forwardVector * (dy*scale) + sideVector * (dx*scale); + osg::Vec3d dv = forwardVector * (dy*scale) + sideVector * (dx*scale); - _center[0] += dv.x(); - _center[1] += dv.y(); - _center[2] += dv.z(); + _center += dv; // need to recompute the itersection point along the look vector. // now reorientate the coordinate frame to the frame coords. - coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]); + coordinateFrame = getCoordinateFrame(_center); // need to reintersect with the terrain osgUtil::IntersectVisitor iv; - float distance = _node->getBound().radius(); - osg::Vec3 start_segment = osg::Vec3(_center[0],_center[1],_center[2]) + getUpVector(coordinateFrame) * distance; - osg::Vec3 end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance); - //end_segment.set(0.0f,0.0f,0.0f); + double distance = _node->getBound().radius(); + osg::Vec3d start_segment = osg::Vec3d(_center[0],_center[1],_center[2]) + getUpVector(coordinateFrame) * distance; + osg::Vec3d end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance); osg::notify(INFO)<<"start="<getCoordindateSystemNodePath(); @@ -202,7 +202,7 @@ public: osg::CoordinateSystemNode* csn = dynamic_cast(tmpPath.back()); if (csn) { - coordinateFrame = csn->computeLocalCoordinateFrame(X,Y,Z)* osg::computeLocalToWorld(tmpPath); + coordinateFrame = csn->computeLocalCoordinateFrame(position)* osg::computeLocalToWorld(tmpPath); } else { @@ -212,7 +212,7 @@ public: } else { - return osg::Matrixd::translate(X,Y,Z); + return osg::Matrixd::translate(position); } } diff --git a/src/osgProducer/ViewerEventHandler.cpp b/src/osgProducer/ViewerEventHandler.cpp index 1f1a19407..c9471b488 100644 --- a/src/osgProducer/ViewerEventHandler.cpp +++ b/src/osgProducer/ViewerEventHandler.cpp @@ -718,7 +718,7 @@ ViewerEventHandler::ViewerEventHandler(OsgCameraGroup* cg): if (cfg->getNumberOfCameras()==1) { - SnapImageDrawCallback* snapImageDrawCallback = new SnapImageDrawCallback("saved_image.jpg"); + SnapImageDrawCallback* snapImageDrawCallback = new SnapImageDrawCallback("saved_image.dds"); cam->addPostDrawCallback(snapImageDrawCallback); _snapImageDrawCallbackList.push_back(snapImageDrawCallback); }