osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthUtil/SkyNode

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003 * Copyright 2008-2010 Pelican Mapping
00004 * http://osgearth.org
00005 *
00006 * osgEarth is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU Lesser General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU Lesser General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU Lesser General Public License
00017 * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018 */
00019 #ifndef OSGEARTHUTIL_SKY_NODE
00020 #define OSGEARTHUTIL_SKY_NODE
00021 
00022 #include <osgEarthUtil/Common>
00023 #include <osgEarth/Map>
00024 #include <osg/MatrixTransform>
00025 #include <osg/Uniform>
00026 #include <osg/Group>
00027 #include <osg/View>
00028 
00029 namespace osgEarth { namespace Util 
00030 {
00031     using namespace osgEarth;
00032 
00036     class OSGEARTHUTIL_EXPORT SkyNode : public osg::Group
00037     {
00038     public:
00040         SkyNode( Map* map, const std::string& starFile="" );
00041 
00043         void attach( osg::View* view, int lightNum =0 );
00044 
00046         void setSunPosition( const osg::Vec3& pos, osg::View* view =0L );
00047 
00049         void setSunPosition( double lat_degrees, double lon_degrees, osg::View* view =0L );
00050         
00052         void setDateTime( int year, int month, int date, double hoursUTC, osg::View* view =0L );
00053 
00055         void setAmbientBrightness( float value, osg::View* view =0L );
00056         float getAmbientBrightness( osg::View* view =0L ) const;
00057 
00059         void setStarsVisible( bool value, osg::View* view =0L );
00060         bool getStarsVisible( osg::View* view =0L ) const;
00061 
00062     public:
00063         //override
00064         virtual void traverse( osg::NodeVisitor& nv );
00065 
00066         //override
00067         virtual osg::BoundingSphere computeBound() const;
00068 
00069     private:
00070         struct StarData
00071         {
00072             std::string name;
00073             double right_ascension;
00074             double declination;
00075             double magnitude;
00076             
00077             StarData() { }
00078             StarData( std::stringstream &ss );
00079         };
00080 
00081         struct PerViewData
00082         {
00083             osg::Vec3f                         _lightPos;
00084             osg::ref_ptr<osg::Light>           _light;
00085             osg::ref_ptr<osg::Uniform>         _lightPosUniform;
00086             osg::Matrixd                       _sunMatrix;            
00087             osg::Matrixd                       _starsMatrix;
00088             bool                               _starsVisible;
00089 
00090             // only available in per-view structures..not default
00091             osg::ref_ptr<osg::Group>           _cullContainer;
00092             osg::ref_ptr<osg::MatrixTransform> _sunXform;
00093             osg::ref_ptr<osg::MatrixTransform> _starsXform;
00094         };
00095 
00096         PerViewData _defaultPerViewData;
00097         typedef std::map<osg::View*, PerViewData> PerViewDataMap;
00098         PerViewDataMap _perViewData;
00099 
00100         float _innerRadius, _outerRadius, _sunDistance, _starRadius;
00101         osg::ref_ptr<osg::Node> _sun, _stars, _atmosphere;
00102         osg::ref_ptr<osg::Uniform> _starAlpha;
00103         osg::ref_ptr<osg::Uniform> _starPointSize;
00104 
00105         osg::ref_ptr< const osg::EllipsoidModel > _ellipsoidModel;
00106 
00107         void makeAtmosphere( const osg::EllipsoidModel* );
00108         void makeSun();
00109 
00110         void makeStars(const std::string& starFile);
00111         osg::Geode* buildStarGeometry(const std::vector<StarData>& stars);
00112         void getDefaultStars(std::vector<StarData>& out_stars);
00113         bool parseStarFile(const std::string& starFile, std::vector<StarData>& out_stars);
00114 
00115         void setAmbientBrightness( PerViewData& data, float value );
00116         void setSunPosition( PerViewData& data, const osg::Vec3& pos );
00117     };
00118 
00119 } } // namespace osgEarth::Util
00120 
00121 #endif //OSGEARTHUTIL_SKY_NODE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines