root/OpenSceneGraph/trunk/examples/osglightpoint/osglightpoint.cpp @ 1815

Revision 1815, 5.6 kB (checked in by robert, 11 years ago)

Added the usage report to the examples for when no arguments are passed
to the examples.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
21void 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
50osg::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//     osgSim::BlinkSequence* bs = new osgSim::BlinkSequence;
70//     bs->addPulse(1.0,osg::Vec4(1.0f,0.0f,0.0f,1.0f));
71//     bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
72//     bs->addPulse(1.5,osg::Vec4(1.0f,1.0f,0.0f,1.0f));
73//     bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
74//     bs->addPulse(1.0,osg::Vec4(1.0f,1.0f,1.0f,1.0f));
75//     bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
76   
77
78//    osgSim::Sector* sector = new osgSim::ConeSector(osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0),osg::inDegrees(45.0));
79//    osgSim::Sector* sector = new osgSim::ElevationSector(-osg::inDegrees(45.0),osg::inDegrees(45.0),osg::inDegrees(45.0));
80//    osgSim::Sector* sector = new osgSim::AzimSector(-osg::inDegrees(45.0),osg::inDegrees(45.0),osg::inDegrees(90.0));
81//     osgSim::Sector* sector = new osgSim::AzimElevationSector(osg::inDegrees(180),osg::inDegrees(90), // azim range
82//                                                                 osg::inDegrees(0.0),osg::inDegrees(90.0), // elevation range
83//                                                                 osg::inDegrees(5.0));
84
85    for(int i=0;i<noStepsY;++i)
86    {
87
88//         osgSim::BlinkSequence* local_bs = new osgSim::BlinkSequence(*bs);
89//         local_bs->setSequenceGroup(new osgSim::BlinkSequence::SequenceGroup((double)i*0.1));       
90//         start._blinkSequence = local_bs;
91
92//        start._sector = sector;
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
111int main( int argc, char **argv )
112{
113
114    // use an ArgumentParser object to manage the program arguments.
115    osg::ArgumentParser arguments(&argc,argv);
116
117    // set up the usage document, in case we need to print out how to use this program.
118    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
119    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
120
121    // construct the viewer.
122    osgProducer::Viewer viewer(arguments);
123
124    // set up the value with sensible default event handlers.
125    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
126
127    // get details on keyboard and mouse bindings used by the viewer.
128    viewer.getUsage(*arguments.getApplicationUsage());
129
130    // if user request help write it out to cout.
131    if (arguments.read("-h") || arguments.read("--help"))
132    {
133        arguments.getApplicationUsage()->write(std::cout);
134        return 1;
135    }
136
137    // any option left unread are converted into errors to write out later.
138    arguments.reportRemainingOptionsAsUnrecognized();
139
140    // report any errors if they have occured when parsing the program aguments.
141    if (arguments.errors())
142    {
143        arguments.writeErrorMessages(std::cout);
144        return 1;
145    }
146   
147    osg::Group* rootnode = new osg::Group;
148
149    // load the nodes from the commandline arguments.
150    rootnode->addChild(osgDB::readNodeFiles(arguments));
151    rootnode->addChild(createLightPointsDatabase());
152   
153   
154    // run optimization over the scene graph
155    osgUtil::Optimizer optimzer;
156    optimzer.optimize(rootnode);
157     
158    // add a viewport to the viewer and attach the scene graph.
159    viewer.setSceneData( rootnode );
160   
161    // create the windows and run the threads.
162    viewer.realize(Producer::CameraGroup::ThreadPerCamera);
163
164    while( !viewer.done() )
165    {
166        // wait for all cull and draw threads to complete.
167        viewer.sync();
168
169        // update the scene by traversing it with the the update visitor which will
170        // call all node update callbacks and animations.
171        viewer.update();
172         
173        // fire off the cull and draw traversals of the scene.
174        viewer.frame();
175       
176    }
177   
178    // wait for all cull and draw threads to complete before exit.
179    viewer.sync();
180
181    return 0;
182}
Note: See TracBrowser for help on using the browser.