osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthUtil/ObjectLocator

Go to the documentation of this file.
00001 #ifndef OSGEARTH_UTIL_OBJECT_LOCATOR_H
00002 #define OSGEARTH_UTIL_OBJECT_LOCATOR_H
00003 
00004 #include <osgEarthUtil/Common>
00005 #include <osgEarth/Map>
00006 #include <osgEarth/Revisioning>
00007 #include <osg/MatrixTransform>
00008 
00009 namespace osgEarth { namespace Util
00010 {
00011     using namespace osgEarth;
00012 
00016     class OSGEARTHUTIL_EXPORT ObjectLocator : public osgEarth::Revisioned<osg::Referenced>
00017     {
00018     public:
00019 
00021         enum Components {
00022             COMP_NONE           = 0x00,
00023             COMP_POSITION       = 0x01,
00024             COMP_HEADING        = 0x02,
00025             COMP_PITCH          = 0x04,
00026             COMP_ROLL           = 0x08,
00027             COMP_ORIENTATION    = COMP_HEADING | COMP_PITCH | COMP_ROLL,
00028             COMP_ALL            = COMP_POSITION | COMP_ORIENTATION
00029         };
00030 
00032         enum RotationOrder {
00033             HPR,
00034             RPH
00035         };
00036 
00037     public:
00038 
00043         ObjectLocator( const osgEarth::Map* map );
00044 
00049         ObjectLocator(ObjectLocator* parent, unsigned int compsToInherit =COMP_ALL );
00050 
00055         void setPosition( const osg::Vec3d& pos );
00056         const osg::Vec3d& getPosition() const { return _pos; }
00057 
00062         void setOrientation( const osg::Vec3d& hpr_deg );
00063         const osg::Vec3d& getOrientation() const { return _hpr; }
00064 
00069         void setTime( double t ) { _timestamp = t; }
00070         double getTime() const { return _timestamp; }
00071 
00075         void setRotationOrder( RotationOrder value ) { _rotOrder = value; }
00076         RotationOrder getRotationOrder() const { return _rotOrder; }
00077 
00083         void setParentLocator( ObjectLocator* parent, unsigned int componentsToInherit =COMP_ALL );
00084         ObjectLocator* getParentLocator() { return _parentLoc.get(); }
00085         const ObjectLocator* getParentLocator() const { return _parentLoc.get(); }
00086 
00088         void setComponentsToInherit( unsigned int compMask );
00089         unsigned int getComponentsToInherit() const { return _componentsToInherit; }
00090 
00092         const Map* getMap() const { return _map.get(); }
00093 
00095         bool isEmpty() const;
00096 
00098         bool isValid() const { return !_isEmpty && _map.valid(); }
00099 
00100     public:
00101 
00106         bool getLocatorPosition( osg::Vec3d& output ) const;
00107 
00112         bool getPositionMatrix( osg::Matrixd& output ) const;
00113 
00118         bool getLocatorOrientation( osg::Vec3d& output ) const;
00119 
00124         bool getOrientationMatrix( osg::Matrixd& output, unsigned inherit =COMP_ALL ) const;
00125 
00130         bool getLocatorMatrix( osg::Matrixd& output, unsigned components =COMP_ALL ) const;
00131 
00132     public:
00133         //override
00135         virtual bool inSyncWith( int exRev ) const;
00136 
00137     private:
00138         osg::observer_ptr<const osgEarth::Map> _map;
00139         osg::ref_ptr<ObjectLocator> _parentLoc;
00140         unsigned int _componentsToInherit; // Locator::Components mask
00141         RotationOrder _rotOrder;
00142         osg::Vec3d _pos;
00143         osg::Vec3d _hpr;
00144         double _timestamp;
00145         bool _isEmpty;
00146     };
00147 
00148 
00152     class OSGEARTHUTIL_EXPORT ObjectLocatorNode : public osg::MatrixTransform
00153     {
00154     public:
00155         ObjectLocatorNode();
00156         ObjectLocatorNode( ObjectLocator* locator );
00157         ObjectLocatorNode( const Map* map );
00158         ObjectLocatorNode( const ObjectLocatorNode& rhs, const osg::CopyOp& =osg::CopyOp::SHALLOW_COPY );
00159         META_Node(osgEarthUtil, ObjectLocatorNode);
00160 
00161     public:
00165         void setLocator( ObjectLocator* locator );
00166         ObjectLocator* getLocator() { return _locator.get(); }
00167         const ObjectLocator* getLocator() const { return _locator.get(); }
00168 
00169     public:
00171         virtual void update();
00172 
00173         virtual void traverse(osg::NodeVisitor &nv);
00174 
00175     private:
00176         osg::ref_ptr<ObjectLocator> _locator;
00177         osgEarth::Revision _matrixRevision;
00178     };
00179 
00180 } } // namespace osgEarth::Util
00181 
00182 #endif // OSGEARTH_UTIL_OBJECT_LOCATOR_H
00183 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines