1 /* -*-c++-*- */
2 /* osgEarth - Geospatial SDK for OpenSceneGraph
3 * Copyright 2019 Pelican Mapping
4 * http://osgearth.org
5 *
6 * osgEarth is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
16 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
17 * IN THE SOFTWARE.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>
21 */
22
23 #include <osgViewer/Viewer>
24 #include <osg/CullFace>
25 #include <osgEarth/Notify>
26 #include <osgEarthUtil/ExampleResources>
27 #include "SkyManipulator"
28
29
30 #define LC "[viewer] "
31
32 using namespace osgEarth;
33 using namespace osgEarth::Util;
34
35 int
usage(const char * name)36 usage(const char* name)
37 {
38 OE_NOTICE
39 << "\nUsage: " << name << " file.earth" << std::endl
40 << MapNodeHelper().usage() << std::endl;
41
42 return 0;
43 }
44
45 int
main(int argc,char ** argv)46 main(int argc, char** argv)
47 {
48 osg::ArgumentParser arguments(&argc,argv);
49
50 // help?
51 if ( arguments.read("--help") )
52 return usage(argv[0]);
53
54 // Increase the fov to provide a more immersive experience.
55 float vfov = 100.0f;
56 arguments.read("--vfov", vfov);
57
58 // create a viewer:
59 osgViewer::Viewer viewer(arguments);
60
61 // Tell the database pager to not modify the unref settings
62 viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( false, false );
63
64 // thread-safe initialization of the OSG wrapper manager. Calling this here
65 // prevents the "unsupported wrapper" messages from OSG
66 osgDB::Registry::instance()->getObjectWrapperManager()->findWrapper("osg::Image");
67
68 // disable the small-feature culling
69 viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
70
71 // set a near/far ratio that is smaller than the default. This allows us to get
72 // closer to the ground without near clipping. If you need more, use --logdepth
73 viewer.getCamera()->setNearFarRatio(0.0001);
74
75 if ( vfov > 0.0 )
76 {
77 double fov, ar, n, f;
78 viewer.getCamera()->getProjectionMatrixAsPerspective(fov, ar, n, f);
79 viewer.getCamera()->setProjectionMatrixAsPerspective(vfov, ar, n, f);
80 }
81
82 // load an earth file, and support all or our example command-line options
83 // and earth file <external> tags
84 osg::Node* node = MapNodeHelper().load( arguments, &viewer );
85
86 //Set our custom manipulator
87 viewer.setCameraManipulator(new SkyManipulator());
88 //viewer.setCameraManipulator( new osgGA::FirstPersonManipulator() );
89
90
91
92 if ( node )
93 {
94 // Disable backface culling
95 node->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
96
97
98 viewer.setSceneData( node );
99 while(!viewer.done())
100 {
101 viewer.frame();
102 }
103 }
104 else
105 {
106 return usage(argv[0]);
107 }
108 }
109