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