| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | #include <osgUtil/UpdateVisitor> |
|---|
| 10 | |
|---|
| 11 | #include <osgDB/ReadFile> |
|---|
| 12 | |
|---|
| 13 | #include <osg/ShapeDrawable> |
|---|
| 14 | #include <osg/PositionAttitudeTransform> |
|---|
| 15 | |
|---|
| 16 | #include <osgProducer/Viewer> |
|---|
| 17 | |
|---|
| 18 | #include "DepthPartitionNode.h" |
|---|
| 19 | |
|---|
| 20 | const double r_earth = 6378.137; |
|---|
| 21 | const double r_sun = 695990.0; |
|---|
| 22 | const double AU = 149697900.0; |
|---|
| 23 | |
|---|
| 24 | osg::Node* createScene() |
|---|
| 25 | { |
|---|
| 26 | |
|---|
| 27 | osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable; |
|---|
| 28 | osg::Sphere* earth_sphere = new osg::Sphere; |
|---|
| 29 | earth_sphere->setRadius(r_earth); |
|---|
| 30 | earth_sd->setShape(earth_sphere); |
|---|
| 31 | earth_sd->setColor(osg::Vec4(0, 0, 1.0, 1.0)); |
|---|
| 32 | |
|---|
| 33 | osg::Geode* earth = new osg::Geode; |
|---|
| 34 | earth->setName("earth"); |
|---|
| 35 | earth->addDrawable(earth_sd); |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable; |
|---|
| 39 | osg::Sphere* sun_sphere = new osg::Sphere; |
|---|
| 40 | sun_sphere->setRadius(r_sun); |
|---|
| 41 | sun_sd->setShape(sun_sphere); |
|---|
| 42 | sun_sd->setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0)); |
|---|
| 43 | |
|---|
| 44 | osg::Geode* sun = new osg::Geode; |
|---|
| 45 | sun->setName("sun"); |
|---|
| 46 | sun->addDrawable(sun_sd); |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform; |
|---|
| 50 | pat->setPosition(osg::Vec3d(0.0, AU, 0.0)); |
|---|
| 51 | |
|---|
| 52 | osg::Group* scene = new osg::Group; |
|---|
| 53 | scene->addChild(earth); |
|---|
| 54 | scene->addChild(pat); |
|---|
| 55 | pat->addChild(sun); |
|---|
| 56 | |
|---|
| 57 | return scene; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | int main( int argc, char **argv ) |
|---|
| 61 | { |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 68 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard example of using osgProducer::CameraGroup."); |
|---|
| 69 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] ..."); |
|---|
| 70 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | osgProducer::Viewer viewer(arguments); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 80 | { |
|---|
| 81 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 82 | return 1; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | if (arguments.errors()) |
|---|
| 90 | { |
|---|
| 91 | arguments.writeErrorMessages(std::cout); |
|---|
| 92 | return 1; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | bool needToSetHomePosition = false; |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | if (!scene) |
|---|
| 103 | { |
|---|
| 104 | scene = createScene(); |
|---|
| 105 | needToSetHomePosition = true; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | osg::ref_ptr<DepthPartitionNode> dpn = new DepthPartitionNode; |
|---|
| 110 | dpn->addChild(scene.get()); |
|---|
| 111 | dpn->setActive(true); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | viewer.setSceneData(dpn.get()); |
|---|
| 115 | |
|---|
| 116 | if (needToSetHomePosition) |
|---|
| 117 | { |
|---|
| 118 | viewer.getKeySwitchMatrixManipulator()->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)); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | viewer.realize(); |
|---|
| 123 | |
|---|
| 124 | while( !viewer.done() ) |
|---|
| 125 | { |
|---|
| 126 | |
|---|
| 127 | viewer.sync(); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | viewer.update(); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | viewer.frame(); |
|---|
| 135 | |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | viewer.sync(); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | viewer.cleanup_frame(); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | viewer.sync(); |
|---|
| 146 | |
|---|
| 147 | return 0; |
|---|
| 148 | } |
|---|