root/OpenSceneGraph/trunk/examples/osgdepthpartition/osgdepthpartition.cpp @ 5923

Revision 5923, 2.7 kB (checked in by robert, 8 years ago)

Ported osgcopy, osgcubemap, osgdelaunay, osgdepthpartion, osgdistortion, osgfadetext, osgforest and osgfxbrowser to osgViewer

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osgUtil/UpdateVisitor>
2
3#include <osgDB/ReadFile>
4
5#include <osg/ShapeDrawable>
6#include <osg/PositionAttitudeTransform>
7
8#include <osgGA/TrackballManipulator>
9
10#include <osgViewer/Viewer>
11
12#include "DepthPartitionNode.h"
13
14const double r_earth = 6378.137;
15const double r_sun = 695990.0;
16const double AU = 149697900.0;
17
18osg::Node* createScene()
19{
20    // Create the Earth, in blue
21    osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable;
22    osg::Sphere* earth_sphere = new osg::Sphere;
23    earth_sphere->setRadius(r_earth);
24    earth_sd->setShape(earth_sphere);
25    earth_sd->setColor(osg::Vec4(0, 0, 1.0, 1.0));
26
27    osg::Geode* earth = new osg::Geode;
28    earth->setName("earth");
29    earth->addDrawable(earth_sd);
30
31    // Create the Sun, in yellow
32    osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable;
33    osg::Sphere* sun_sphere = new osg::Sphere;
34    sun_sphere->setRadius(r_sun);
35    sun_sd->setShape(sun_sphere);
36    sun_sd->setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0));
37
38    osg::Geode* sun_geode = new osg::Geode;
39    sun_geode->setName("sun");
40    sun_geode->addDrawable(sun_sd);
41
42    // Move the sun behind the earth
43    osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform;
44    pat->setPosition(osg::Vec3d(0.0, AU, 0.0));
45
46    osg::Group* scene = new osg::Group;
47    scene->addChild(earth);
48    scene->addChild(pat);
49    pat->addChild(sun_geode);
50
51    return scene;
52}
53
54int main( int argc, char **argv )
55{
56
57    // use an ArgumentParser object to manage the program arguments.
58    osg::ArgumentParser arguments(&argc,argv);
59
60    // construct the viewer.
61    osgViewer::Viewer viewer;
62
63    bool needToSetHomePosition = false;
64
65    // read the scene from the list of file specified commandline args.
66    osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
67
68    // if one hasn't been loaded create an earth and sun test model.
69    if (!scene)
70    {
71        scene = createScene();
72        needToSetHomePosition = true;
73    }
74   
75    // Create a DepthPartitionNode to manage partitioning of the scene
76    osg::ref_ptr<DepthPartitionNode> dpn = new DepthPartitionNode;
77    dpn->addChild(scene.get());
78    dpn->setActive(true); // Control whether the node analyzes the scene
79       
80    // pass the loaded scene graph to the viewer.
81    viewer.setSceneData(dpn.get());
82
83    viewer.setCameraManipulator(new osgGA::TrackballManipulator);
84
85    if (needToSetHomePosition)
86    {
87        viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0));
88    }
89   
90    // depth partion node is only supports single window/single threaded at present.
91    viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
92
93    return viewer.run();
94}
Note: See TracBrowser for help on using the browser.