| 1 | |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <osgProducer/Viewer> |
|---|
| 5 | |
|---|
| 6 | #include <osg/Node> |
|---|
| 7 | #include <osg/Notify> |
|---|
| 8 | |
|---|
| 9 | #include <osgDB/Registry> |
|---|
| 10 | #include <osgDB/ReadFile> |
|---|
| 11 | |
|---|
| 12 | #include <osgGA/TrackballManipulator> |
|---|
| 13 | #include <osgGA/FlightManipulator> |
|---|
| 14 | #include <osgGA/DriveManipulator> |
|---|
| 15 | #include <osgGA/AnimationPathManipulator> |
|---|
| 16 | |
|---|
| 17 | #include <osgDB/WriteFile> |
|---|
| 18 | #include <osgDB/FileUtils> |
|---|
| 19 | #include <osgDB/FileNameUtils> |
|---|
| 20 | |
|---|
| 21 | #include <osgUtil/Optimizer> |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | #include "../../src/osgPlugins/geo/osgGeoAnimation.h" |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | class geodemoEventHandler : public osgGA::GUIEventHandler |
|---|
| 31 | { |
|---|
| 32 | public: |
|---|
| 33 | |
|---|
| 34 | geodemoEventHandler( ) { mouse_x=mouse_y=0;} |
|---|
| 35 | virtual ~geodemoEventHandler( ) {} |
|---|
| 36 | |
|---|
| 37 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) |
|---|
| 38 | { |
|---|
| 39 | mouse_x=ea.getX(); |
|---|
| 40 | mouse_y=ea.getY(); |
|---|
| 41 | return false; |
|---|
| 42 | |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | virtual void accept(osgGA::GUIEventHandlerVisitor& v) |
|---|
| 46 | { |
|---|
| 47 | v.visit(*this); |
|---|
| 48 | } |
|---|
| 49 | inline int getMouseX(void) {return mouse_x;}; |
|---|
| 50 | inline int getMouseY(void) {return mouse_y;}; |
|---|
| 51 | |
|---|
| 52 | private: |
|---|
| 53 | int mouse_x, mouse_y; |
|---|
| 54 | }; |
|---|
| 55 | |
|---|
| 56 | static geodemoEventHandler *ghand=NULL; |
|---|
| 57 | inline double DEG2RAD(const double val) { return val*0.0174532925199432957692369076848861;} |
|---|
| 58 | inline double RAD2DEG(const double val) { return val*57.2957795130823208767981548141052;} |
|---|
| 59 | |
|---|
| 60 | double dodynamics(const double , const double val, const std::string name) |
|---|
| 61 | { |
|---|
| 62 | |
|---|
| 63 | static double heading,speed; |
|---|
| 64 | if (name == "xpos") { |
|---|
| 65 | return (val+speed*sin(heading)); |
|---|
| 66 | |
|---|
| 67 | } else if (name == "ypos") { |
|---|
| 68 | return (val+speed*cos(heading)); |
|---|
| 69 | |
|---|
| 70 | } else if (name == "sped") { |
|---|
| 71 | speed=(0.00025*(ghand->getMouseY()-300)); |
|---|
| 72 | return (speed); |
|---|
| 73 | } else if (name == "heading") { |
|---|
| 74 | heading-= 0.01*DEG2RAD(ghand->getMouseX()-400); |
|---|
| 75 | return (RAD2DEG(heading)); |
|---|
| 76 | } else if (name == "conerot") { |
|---|
| 77 | return ((ghand->getMouseX()-400)); |
|---|
| 78 | } else if (name == "planrot") { |
|---|
| 79 | return ((ghand->getMouseY()-300)/200.0); |
|---|
| 80 | } else if (name == "secint" || name == "minutehand"|| name == "hourhand") { |
|---|
| 81 | |
|---|
| 82 | } |
|---|
| 83 | return val; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | int main( int argc, char **argv ) |
|---|
| 87 | { |
|---|
| 88 | |
|---|
| 89 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); |
|---|
| 93 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 94 | arguments.getApplicationUsage()->addCommandLineOption("--fov <float>","Set the Field of View"); |
|---|
| 95 | |
|---|
| 96 | float camera_fov=-1; |
|---|
| 97 | while (arguments.read("--fov",camera_fov)) {} |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | osgProducer::Viewer viewer(arguments); |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 110 | { |
|---|
| 111 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 112 | return 1; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | if (arguments.errors()) |
|---|
| 120 | { |
|---|
| 121 | arguments.writeErrorMessages(std::cout); |
|---|
| 122 | return 1; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
|---|
| 128 | if (!rootnode) |
|---|
| 129 | { |
|---|
| 130 | return 1; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | osgUtil::Optimizer optimzer; |
|---|
| 135 | optimzer.optimize(rootnode); |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | viewer.setSceneData( rootnode ); |
|---|
| 139 | |
|---|
| 140 | geoHeader *gh = dynamic_cast<geoHeader *>(rootnode); |
|---|
| 141 | if (gh) |
|---|
| 142 | { |
|---|
| 143 | ghand=new geodemoEventHandler(); |
|---|
| 144 | gh->setUserUpdate(dodynamics); |
|---|
| 145 | viewer.getEventHandlerList().push_front(ghand); |
|---|
| 146 | } |
|---|
| 147 | else |
|---|
| 148 | { |
|---|
| 149 | osg::Group *gpall=dynamic_cast<osg::Group *>(rootnode); |
|---|
| 150 | if (gpall) |
|---|
| 151 | { |
|---|
| 152 | int nchild=gpall->getNumChildren(); |
|---|
| 153 | for (int i=0; i<nchild; i++) |
|---|
| 154 | { |
|---|
| 155 | osg::Node *nod=gpall->getChild(i); |
|---|
| 156 | gh = dynamic_cast<geoHeader *>(nod); |
|---|
| 157 | if (gh) |
|---|
| 158 | { |
|---|
| 159 | ghand=new geodemoEventHandler(); |
|---|
| 160 | gh->setUserUpdate(dodynamics); |
|---|
| 161 | viewer.getEventHandlerList().push_front(ghand); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 169 | |
|---|
| 170 | while( !viewer.done() ) |
|---|
| 171 | { |
|---|
| 172 | |
|---|
| 173 | viewer.sync(); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | viewer.update(); |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | viewer.frame(); |
|---|
| 181 | |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | return 0; |
|---|
| 185 | } |
|---|