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

Revision 1747, 5.8 kB (checked in by robert, 11 years ago)

Added a viewer.sync to the end of all the demos.

Removed the Win32 remapping of keycodes from the osgProducer::EventAdapter?.

  • 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/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
24void 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        //INTERPOLATE(_minPixelSize);
46        //INTERPOLATE(_maxPixelSize);
47//        INTERPOLATE(_maxVisibileDistance2);
48
49        lpn.addLightPoint(lp);
50       
51   }
52}
53
54#undef INTERPOLATE
55
56osg::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//     osgSim::BlinkSequence* bs = new osgSim::BlinkSequence;
76//     bs->addPulse(1.0,osg::Vec4(1.0f,0.0f,0.0f,1.0f));
77//     bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
78//     bs->addPulse(1.5,osg::Vec4(1.0f,1.0f,0.0f,1.0f));
79//     bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
80//     bs->addPulse(1.0,osg::Vec4(1.0f,1.0f,1.0f,1.0f));
81//     bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
82   
83
84//    osgSim::Sector* sector = new osgSim::ConeSector(osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0),osg::inDegrees(45.0));
85//    osgSim::Sector* sector = new osgSim::ElevationSector(-osg::inDegrees(45.0),osg::inDegrees(45.0),osg::inDegrees(45.0));
86//    osgSim::Sector* sector = new osgSim::AzimSector(-osg::inDegrees(45.0),osg::inDegrees(45.0),osg::inDegrees(90.0));
87//     osgSim::Sector* sector = new osgSim::AzimElevationSector(osg::inDegrees(180),osg::inDegrees(90), // azim range
88//                                                                 osg::inDegrees(0.0),osg::inDegrees(90.0), // elevation range
89//                                                                 osg::inDegrees(5.0));
90
91    for(int i=0;i<noStepsY;++i)
92    {
93
94//         osgSim::BlinkSequence* local_bs = new osgSim::BlinkSequence(*bs);
95//         local_bs->setSequenceGroup(new osgSim::BlinkSequence::SequenceGroup((double)i*0.1));       
96//         start._blinkSequence = local_bs;
97
98//        start._sector = sector;
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
117int main( int argc, char **argv )
118{
119
120    // use an ArgumentParser object to manage the program arguments.
121    osg::ArgumentParser arguments(&argc,argv);
122
123    // set up the usage document, in case we need to print out how to use this program.
124    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ...");
125    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
126
127    // construct the viewer.
128    osgProducer::Viewer viewer(arguments);
129
130    // set up the value with sensible default event handlers.
131    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
132
133    // get details on keyboard and mouse bindings used by the viewer.
134    viewer.getUsage(*arguments.getApplicationUsage());
135
136    // if user request help write it out to cout.
137    if (arguments.read("-h") || arguments.read("--help"))
138    {
139        arguments.getApplicationUsage()->write(std::cout);
140        return 1;
141    }
142
143    // any option left unread are converted into errors to write out later.
144    arguments.reportRemainingOptionsAsUnrecognized();
145
146    // report any errors if they have occured when parsing the program aguments.
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    // load the nodes from the commandline arguments.
157    rootnode->addChild(osgDB::readNodeFiles(arguments));
158    rootnode->addChild(createLightPointsDatabase());
159    if (!rootnode)
160    {
161        return 1;
162    }
163   
164    // run optimization over the scene graph
165    osgUtil::Optimizer optimzer;
166    optimzer.optimize(rootnode);
167     
168    // add a viewport to the viewer and attach the scene graph.
169    viewer.setSceneData( rootnode );
170   
171    // create the windows and run the threads.
172    viewer.realize(Producer::CameraGroup::ThreadPerCamera);
173
174    while( !viewer.done() )
175    {
176        // wait for all cull and draw threads to complete.
177        viewer.sync();
178
179        // update the scene by traversing it with the the update visitor which will
180        // call all node update callbacks and animations.
181        viewer.update();
182         
183        // fire off the cull and draw traversals of the scene.
184        viewer.frame();
185       
186    }
187   
188    // wait for all cull and draw threads to complete before exit.
189    viewer.sync();
190
191    return 0;
192}
Note: See TracBrowser for help on using the browser.