root/OpenSceneGraph/trunk/examples/osgspheresegment/osgspheresegment.cpp @ 2215

Revision 2215, 4.6 kB (checked in by robert, 11 years ago)

Fixes for Win32.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osg/Geode>
2#include <osg/ShapeDrawable>
3#include <osg/Material>
4#include <osg/Texture2D>
5#include <osg/Geometry>
6#include <osg/MatrixTransform>
7#include <osg/PositionAttitudeTransform>
8#include <osg/BlendFunc>
9#include <osg/ClearNode>
10
11#include <osgUtil/Tesselator>
12#include <osgUtil/TransformCallback>
13#include <osgUtil/CullVisitor>
14
15#include <osgText/Text>
16
17#include <osgGA/TrackballManipulator>
18#include <osgProducer/Viewer>
19#include <osgDB/ReadFile>
20
21#include <osgSim/SphereSegment>
22
23using namespace osgSim;
24
25class MyNodeCallback: public osg::NodeCallback
26{
27    void operator()(osg::Node*,osg::NodeVisitor*);
28};
29
30// void MyNodeCallback::operator()(osg::Node* n,osg::NodeVisitor* nv)
31// {
32//     if(osgSim::SphereSegment* ss=dynamic_cast<osgSim::SphereSegment*>(n))
33//      {
34//              osg::Vec3 vec;
35//          float azRange, elevRange;
36//          ss->getArea(vec,azRange,elevRange);
37//
38//              float azRangeDeg = osg::RadiansToDegrees(azRange);
39//
40//              static bool azAscending = false;
41//
42//         if(azAscending){
43//                  azRangeDeg += 1.0f;
44//                      if(azRangeDeg>89.0f) azAscending = false;
45//              }else{
46//                  azRangeDeg -= 1.0f;
47//                      if(azRangeDeg<2.0f) azAscending = true;
48//              }
49//
50//              ss->setArea(vec,osg::DegreesToRadians(azRangeDeg),elevRange);
51//
52//      }
53//     traverse(n,nv);
54// }
55
56void MyNodeCallback::operator()(osg::Node* n,osg::NodeVisitor* nv)
57{
58    if(osgSim::SphereSegment* ss=dynamic_cast<osgSim::SphereSegment*>(n))
59        {
60                osg::Vec3 vec;
61            float azRange, elevRange;
62            ss->getArea(vec,azRange,elevRange);
63
64        static float angle = 0.0f;
65                if(++angle > 359.0f) angle = 0.0f;
66                vec.set(sin(osg::DegreesToRadians(angle)),cos(osg::DegreesToRadians(angle)),0.0f);
67
68        std::cout<<"angle "<<angle<<" degrees, vec is "<<vec
69                                <<", azRange is "<<osg::RadiansToDegrees(azRange)
70                                                <<", elevRange is "<<osg::RadiansToDegrees(elevRange)
71                                                <<std::endl;
72
73                ss->setArea(vec,azRange,elevRange);
74        }
75    traverse(n,nv);
76}
77
78osg::Node* createSphereSegment()
79{
80        SphereSegment* ss = new SphereSegment(osg::Vec3(0.0f,0.0f,0.0f), 1.0f,
81                                        osg::Vec3(0.0f,1.0f,0.0f),
82                                        osg::DegreesToRadians(90.0f),
83                                        osg::DegreesToRadians(45.0f),
84                                        60);
85        ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
86        ss->setSideColor(osg::Vec4(0.0f,0.0f,1.0f,0.1f));
87        //ss->setDrawMask(SphereSegment::DrawMask(SphereSegment::SPOKES | SphereSegment::EDGELINE));
88
89    //ss->setUpdateCallback(new MyNodeCallback);
90
91    return ss;
92}
93
94int main( int argc, char **argv )
95{
96    // use an ArgumentParser object to manage the program arguments.
97    osg::ArgumentParser arguments(&argc,argv);
98
99    // set up the usage document, in case we need to print out how to use this program.
100    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo..");
101    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
102    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
103    arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo");
104
105    // construct the viewer.
106    osgProducer::Viewer viewer(arguments);
107
108    // set up the value with sensible default event handlers.
109    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
110
111    // get details on keyboard and mouse bindings used by the viewer.
112    viewer.getUsage(*arguments.getApplicationUsage());
113
114    // if user request help write it out to cout.
115    if (arguments.read("-h") || arguments.read("--help"))
116    {
117        arguments.getApplicationUsage()->write(std::cout);
118        return 1;
119    }
120
121    // any option left unread are converted into errors to write out later.
122    arguments.reportRemainingOptionsAsUnrecognized();
123
124    // report any errors if they have occured when parsing the program aguments.
125    if (arguments.errors())
126    {
127        arguments.writeErrorMessages(std::cout);
128        return 1;
129    }
130
131    osg::Node* node = createSphereSegment();
132
133    // add model to viewer.
134    viewer.setSceneData( node );
135
136    // create the windows and run the threads.
137    viewer.realize();
138
139    while( !viewer.done() )
140    {
141        // wait for all cull and draw threads to complete.
142        viewer.sync();
143
144        // update the scene by traversing it with the the update visitor which will
145        // call all node update callbacks and animations.
146        viewer.update();
147
148        // fire off the cull and draw traversals of the scene.
149        viewer.frame();
150    }
151
152    // wait for all cull and draw threads to complete before exit.
153    viewer.sync();
154
155    return 0;
156}
Note: See TracBrowser for help on using the browser.