| 1 | |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <osgViewer/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 | #include <iostream> |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #include "../../src/osgPlugins/geo/osgGeoAnimation.h" |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | class geodemoEventHandler : public osgGA::GUIEventHandler |
|---|
| 33 | { |
|---|
| 34 | public: |
|---|
| 35 | |
|---|
| 36 | geodemoEventHandler( ) { mouse_x=mouse_y=0;} |
|---|
| 37 | virtual ~geodemoEventHandler( ) {} |
|---|
| 38 | |
|---|
| 39 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) |
|---|
| 40 | { |
|---|
| 41 | mouse_x=ea.getX(); |
|---|
| 42 | mouse_y=ea.getY(); |
|---|
| 43 | return false; |
|---|
| 44 | |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | inline float getMouseX(void) {return mouse_x;}; |
|---|
| 48 | inline float getMouseY(void) {return mouse_y;}; |
|---|
| 49 | |
|---|
| 50 | private: |
|---|
| 51 | float mouse_x, mouse_y; |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | static geodemoEventHandler *ghand=NULL; |
|---|
| 55 | inline double DEG2RAD(const double val) { return val*0.0174532925199432957692369076848861;} |
|---|
| 56 | inline double RAD2DEG(const double val) { return val*57.2957795130823208767981548141052;} |
|---|
| 57 | |
|---|
| 58 | double dodynamics(const double , const double val, const std::string name) |
|---|
| 59 | { |
|---|
| 60 | |
|---|
| 61 | static double heading,speed; |
|---|
| 62 | if (name == "xpos") { |
|---|
| 63 | return (val+speed*sin(heading)); |
|---|
| 64 | |
|---|
| 65 | } else if (name == "ypos") { |
|---|
| 66 | return (val+speed*cos(heading)); |
|---|
| 67 | |
|---|
| 68 | } else if (name == "sped") { |
|---|
| 69 | speed=(0.00025*(ghand->getMouseY()-300)); |
|---|
| 70 | return (speed); |
|---|
| 71 | } else if (name == "heading") { |
|---|
| 72 | heading-= 0.01*DEG2RAD(ghand->getMouseX()-400); |
|---|
| 73 | return (RAD2DEG(heading)); |
|---|
| 74 | } else if (name == "conerot") { |
|---|
| 75 | return ((ghand->getMouseX()-400)); |
|---|
| 76 | } else if (name == "planrot") { |
|---|
| 77 | return ((ghand->getMouseY()-300)/200.0); |
|---|
| 78 | } else if (name == "secint" || name == "minutehand"|| name == "hourhand") { |
|---|
| 79 | |
|---|
| 80 | } |
|---|
| 81 | return val; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | int main( int argc, char **argv ) |
|---|
| 85 | { |
|---|
| 86 | |
|---|
| 87 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | osgViewer::Viewer viewer; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
|---|
| 94 | if (!rootnode) |
|---|
| 95 | { |
|---|
| 96 | osg::notify(osg::NOTICE)<<"Please specify and geo model filename on the command line."<<std::endl; |
|---|
| 97 | return 1; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | osgUtil::Optimizer optimzer; |
|---|
| 102 | optimzer.optimize(rootnode); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | viewer.setSceneData( rootnode ); |
|---|
| 106 | |
|---|
| 107 | geoHeader *gh = dynamic_cast<geoHeader *>(rootnode); |
|---|
| 108 | if (gh) |
|---|
| 109 | { |
|---|
| 110 | ghand=new geodemoEventHandler(); |
|---|
| 111 | gh->setUserUpdate(dodynamics); |
|---|
| 112 | viewer.addEventHandler(ghand); |
|---|
| 113 | } |
|---|
| 114 | else |
|---|
| 115 | { |
|---|
| 116 | osg::Group *gpall=dynamic_cast<osg::Group *>(rootnode); |
|---|
| 117 | if (gpall) |
|---|
| 118 | { |
|---|
| 119 | int nchild=gpall->getNumChildren(); |
|---|
| 120 | for (int i=0; i<nchild; i++) |
|---|
| 121 | { |
|---|
| 122 | osg::Node *nod=gpall->getChild(i); |
|---|
| 123 | gh = dynamic_cast<geoHeader *>(nod); |
|---|
| 124 | if (gh) |
|---|
| 125 | { |
|---|
| 126 | ghand=new geodemoEventHandler(); |
|---|
| 127 | gh->setUserUpdate(dodynamics); |
|---|
| 128 | viewer.addEventHandler(ghand); |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | return viewer.run(); |
|---|
| 135 | } |
|---|