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