| 1 | #include <osg/GL> |
|---|
| 2 | #include <osgProducer/Viewer> |
|---|
| 3 | |
|---|
| 4 | #include <osg/Transform> |
|---|
| 5 | #include <osg/Billboard> |
|---|
| 6 | #include <osg/Geode> |
|---|
| 7 | #include <osg/Group> |
|---|
| 8 | #include <osg/Notify> |
|---|
| 9 | |
|---|
| 10 | #include <osgDB/Registry> |
|---|
| 11 | #include <osgDB/ReadFile> |
|---|
| 12 | |
|---|
| 13 | #include <osgGA/TrackballManipulator> |
|---|
| 14 | #include <osgGA/FlightManipulator> |
|---|
| 15 | #include <osgGA/DriveManipulator> |
|---|
| 16 | |
|---|
| 17 | #include <osgUtil/Optimizer> |
|---|
| 18 | |
|---|
| 19 | #include <osgSim/LightPointNode> |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #define INTERPOLATE(member) lp.member = start.member*rstart + end.member*rend; |
|---|
| 23 | |
|---|
| 24 | void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,osgSim::LightPoint& end,unsigned int noSteps) |
|---|
| 25 | { |
|---|
| 26 | if (noSteps<=1) |
|---|
| 27 | { |
|---|
| 28 | lpn.addLightPoint(start); |
|---|
| 29 | return; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | float rend = 0.0f; |
|---|
| 33 | float rdelta = 1.0f/((float)noSteps-1.0f); |
|---|
| 34 | |
|---|
| 35 | lpn._lightPointList.reserve(noSteps); |
|---|
| 36 | |
|---|
| 37 | for(unsigned int i=0;i<noSteps;++i,rend+=rdelta) |
|---|
| 38 | { |
|---|
| 39 | float rstart = 1.0f-rend; |
|---|
| 40 | osgSim::LightPoint lp(start); |
|---|
| 41 | INTERPOLATE(_position) |
|---|
| 42 | INTERPOLATE(_intensity); |
|---|
| 43 | INTERPOLATE(_color); |
|---|
| 44 | INTERPOLATE(_radius); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | lpn.addLightPoint(lp); |
|---|
| 50 | |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | #undef INTERPOLATE |
|---|
| 55 | |
|---|
| 56 | osg::Node* createLightPointsDatabase() |
|---|
| 57 | { |
|---|
| 58 | osgSim::LightPoint start; |
|---|
| 59 | osgSim::LightPoint end; |
|---|
| 60 | |
|---|
| 61 | start._position.set(0.0f,0.0f,0.0f); |
|---|
| 62 | start._color.set(1.0f,0.0f,0.0f,1.0f); |
|---|
| 63 | |
|---|
| 64 | end._position.set(1000.0f,0.0f,0.0f); |
|---|
| 65 | end._color.set(1.0f,1.0f,1.0f,1.0f); |
|---|
| 66 | |
|---|
| 67 | osg::Transform* transform = new osg::Transform; |
|---|
| 68 | |
|---|
| 69 | osg::Vec3 start_delta(0.0f,10.0f,0.0f); |
|---|
| 70 | osg::Vec3 end_delta(0.0f,10.0f,1.0f); |
|---|
| 71 | |
|---|
| 72 | int noStepsX = 100; |
|---|
| 73 | int noStepsY = 100; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | for(int i=0;i<noStepsY;++i) |
|---|
| 92 | { |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | osgSim::LightPointNode* lpn = new osgSim::LightPointNode; |
|---|
| 101 | addToLightPointNode(*lpn,start,end,noStepsX); |
|---|
| 102 | |
|---|
| 103 | start._position += start_delta; |
|---|
| 104 | end._position += end_delta; |
|---|
| 105 | |
|---|
| 106 | transform->addChild(lpn); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | osg::Group* group = new osg::Group; |
|---|
| 110 | group->addChild(transform); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | return group; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | int main( int argc, char **argv ) |
|---|
| 118 | { |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); |
|---|
| 125 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | osgProducer::Viewer viewer(arguments); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 138 | { |
|---|
| 139 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 140 | return 1; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | if (arguments.errors()) |
|---|
| 148 | { |
|---|
| 149 | arguments.writeErrorMessages(std::cout); |
|---|
| 150 | return 1; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | osg::Group* rootnode = new osg::Group; |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | rootnode->addChild(osgDB::readNodeFiles(arguments)); |
|---|
| 158 | rootnode->addChild(createLightPointsDatabase()); |
|---|
| 159 | if (!rootnode) |
|---|
| 160 | { |
|---|
| 161 | return 1; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | osgUtil::Optimizer optimzer; |
|---|
| 166 | optimzer.optimize(rootnode); |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | viewer.setSceneData( rootnode ); |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 173 | |
|---|
| 174 | while( !viewer.done() ) |
|---|
| 175 | { |
|---|
| 176 | |
|---|
| 177 | viewer.sync(); |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | viewer.update(); |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | viewer.frame(); |
|---|
| 185 | |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | return 0; |
|---|
| 189 | } |
|---|