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

Revision 1844, 5.7 kB (checked in by robert, 11 years ago)

Added desciptions to all the demos.

  • 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()->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    // construct the viewer.
123    osgProducer::Viewer viewer(arguments);
124
125    // set up the value with sensible default event handlers.
126    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
127
128    // get details on keyboard and mouse bindings used by the viewer.
129    viewer.getUsage(*arguments.getApplicationUsage());
130
131    // if user request help write it out to cout.
132    if (arguments.read("-h") || arguments.read("--help"))
133    {
134        arguments.getApplicationUsage()->write(std::cout);
135        return 1;
136    }
137
138    // any option left unread are converted into errors to write out later.
139    arguments.reportRemainingOptionsAsUnrecognized();
140
141    // report any errors if they have occured when parsing the program aguments.
142    if (arguments.errors())
143    {
144        arguments.writeErrorMessages(std::cout);
145        return 1;
146    }
147   
148    osg::Group* rootnode = new osg::Group;
149
150    // load the nodes from the commandline arguments.
151    rootnode->addChild(osgDB::readNodeFiles(arguments));
152    rootnode->addChild(createLightPointsDatabase());
153   
154   
155    // run optimization over the scene graph
156    osgUtil::Optimizer optimzer;
157    optimzer.optimize(rootnode);
158     
159    // add a viewport to the viewer and attach the scene graph.
160    viewer.setSceneData( rootnode );
161   
162    // create the windows and run the threads.
163    viewer.realize();
164
165    while( !viewer.done() )
166    {
167        // wait for all cull and draw threads to complete.
168        viewer.sync();
169
170        // update the scene by traversing it with the the update visitor which will
171        // call all node update callbacks and animations.
172        viewer.update();
173         
174        // fire off the cull and draw traversals of the scene.
175        viewer.frame();
176       
177    }
178   
179    // wait for all cull and draw threads to complete before exit.
180    viewer.sync();
181
182    return 0;
183}
Note: See TracBrowser for help on using the browser.