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

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

Added support for min pixel size, max pixel size and max visable distance to
osgSim::LightPointNode?, the max pixel size from was originally in osg::LightPoint?.

Added additional get/set methods to osg::LightPointNode?.

Increased the compute pixel size by a ratio 1.41 (sqrtf(2)) to correlate the
computed size with the actual size seen on screen.

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