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