root/OpenSceneGraph/trunk/examples/osgdistortion/osgdistortion.cpp @ 6245

Revision 6245, 21.6 kB (checked in by robert, 7 years ago)

Further work on dome RTT

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osg/GLExtensions>
2#include <osg/Node>
3#include <osg/Geometry>
4#include <osg/Notify>
5#include <osg/MatrixTransform>
6#include <osg/Texture2D>
7#include <osg/Stencil>
8#include <osg/ColorMask>
9#include <osg/Depth>
10#include <osg/Billboard>
11#include <osg/Material>
12#include <osg/Projection>
13#include <osg/TextureCubeMap>
14#include <osg/io_utils>
15
16#include <osgGA/TrackballManipulator>
17#include <osgGA/FlightManipulator>
18#include <osgGA/DriveManipulator>
19#include <osgGA/StateSetManipulator>
20
21#include <osgUtil/SmoothingVisitor>
22
23#include <osgDB/Registry>
24#include <osgDB/ReadFile>
25
26#include <osgViewer/Viewer>
27#include <osgViewer/StatsHandler>
28#include <osgViewer/HelpHandler>
29
30using namespace osg;
31
32osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearColour)
33{
34    osg::Group* distortionNode = new osg::Group;
35   
36    unsigned int tex_width = 1024;
37    unsigned int tex_height = 1024;
38   
39    osg::Texture2D* texture = new osg::Texture2D;
40    texture->setTextureSize(tex_width, tex_height);
41    texture->setInternalFormat(GL_RGBA);
42    texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
43    texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
44   
45    // set up the render to texture camera.
46    {
47        osg::Camera* camera = new osg::Camera;
48
49        // set clear the color and depth buffer
50        camera->setClearColor(clearColour);
51        camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
52
53        // just inherit the main cameras view
54        camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
55        camera->setProjectionMatrix(osg::Matrixd::identity());
56        camera->setViewMatrix(osg::Matrixd::identity());
57
58        // set viewport
59        camera->setViewport(0,0,tex_width,tex_height);
60
61        // set the camera to render before the main camera.
62        camera->setRenderOrder(osg::Camera::PRE_RENDER);
63
64        // tell the camera to use OpenGL frame buffer object where supported.
65        camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
66
67        // attach the texture and use it as the color buffer.
68        camera->attach(osg::Camera::COLOR_BUFFER, texture);
69
70        // add subgraph to render
71        camera->addChild(subgraph);
72       
73        distortionNode->addChild(camera);
74   }
75   
76    // set up the hud camera
77    {
78        // create the quad to visualize.
79        osg::Geometry* polyGeom = new osg::Geometry();
80
81        polyGeom->setSupportsDisplayList(false);
82
83        osg::Vec3 origin(0.0f,0.0f,0.0f);
84        osg::Vec3 xAxis(1.0f,0.0f,0.0f);
85        osg::Vec3 yAxis(0.0f,1.0f,0.0f);
86        osg::Vec3 zAxis(0.0f,0.0f,1.0f);
87        float height = 1024.0f;
88        float width = 1280.0f;
89        int noSteps = 50;
90
91        osg::Vec3Array* vertices = new osg::Vec3Array;
92        osg::Vec2Array* texcoords = new osg::Vec2Array;
93        osg::Vec4Array* colors = new osg::Vec4Array;
94
95        osg::Vec3 bottom = origin;
96        osg::Vec3 dx = xAxis*(width/((float)(noSteps-1)));
97        osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
98
99        osg::Vec2 bottom_texcoord(0.0f,0.0f);
100        osg::Vec2 dx_texcoord(1.0f/(float)(noSteps-1),0.0f);
101        osg::Vec2 dy_texcoord(0.0f,1.0f/(float)(noSteps-1));
102
103        osg::Vec3 cursor = bottom;
104        osg::Vec2 texcoord = bottom_texcoord;
105        int i,j;
106        for(i=0;i<noSteps;++i)
107        {
108            osg::Vec3 cursor = bottom+dy*(float)i;
109            osg::Vec2 texcoord = bottom_texcoord+dy_texcoord*(float)i;
110            for(j=0;j<noSteps;++j)
111            {
112                vertices->push_back(cursor);
113                texcoords->push_back(osg::Vec2((sin(texcoord.x()*osg::PI-osg::PI*0.5)+1.0f)*0.5f,(sin(texcoord.y()*osg::PI-osg::PI*0.5)+1.0f)*0.5f));
114                colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
115
116                cursor += dx;
117                texcoord += dx_texcoord;
118            }
119        }
120
121        // pass the created vertex array to the points geometry object.
122        polyGeom->setVertexArray(vertices);
123
124        polyGeom->setColorArray(colors);
125        polyGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
126
127        polyGeom->setTexCoordArray(0,texcoords);
128
129
130        for(i=0;i<noSteps-1;++i)
131        {
132            osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP);
133            for(j=0;j<noSteps;++j)
134            {
135                elements->push_back(j+(i+1)*noSteps);
136                elements->push_back(j+(i)*noSteps);
137            }
138            polyGeom->addPrimitiveSet(elements);
139        }
140
141
142        // new we need to add the texture to the Drawable, we do so by creating a
143        // StateSet to contain the Texture StateAttribute.
144        osg::StateSet* stateset = polyGeom->getOrCreateStateSet();
145        stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
146        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
147
148        osg::Geode* geode = new osg::Geode();
149        geode->addDrawable(polyGeom);
150
151        // set up the camera to render the textured quad
152        osg::Camera* camera = new osg::Camera;
153
154        // just inherit the main cameras view
155        camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
156        camera->setViewMatrix(osg::Matrix::identity());
157        camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
158
159        // set the camera to render before the main camera.
160        camera->setRenderOrder(osg::Camera::NESTED_RENDER);
161
162        // add subgraph to render
163        camera->addChild(geode);
164       
165        distortionNode->addChild(camera);
166    }
167    return distortionNode;
168}
169
170void setDomeFaces(osgViewer::Viewer& viewer, osg::ArgumentParser& /*arguments*/)
171{
172 
173    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
174    if (!wsi)
175    {
176        osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
177        return;
178    }
179
180    unsigned int width, height;
181    wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
182
183    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
184    traits->x = 0;
185    traits->y = 0;
186    traits->width = width;
187    traits->height = height;
188    traits->windowDecoration = true;
189    traits->doubleBuffer = true;
190    traits->sharedContext = 0;
191
192    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
193    if (!gc)
194    {
195        osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
196        return;
197    }
198
199
200    int center_x = width/2;
201    int center_y = height/2;
202    int camera_width = 256;
203    int camera_height = 256;
204
205    // front face
206    {
207        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
208        camera->setGraphicsContext(gc.get());
209        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y, camera_width, camera_height));
210        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
211        camera->setDrawBuffer(buffer);
212        camera->setReadBuffer(buffer);
213
214        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
215    }
216   
217    // top face
218    {
219        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
220        camera->setGraphicsContext(gc.get());
221        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y+camera_height, camera_width, camera_height));
222        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
223        camera->setDrawBuffer(buffer);
224        camera->setReadBuffer(buffer);
225
226        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0));
227    }
228
229    // left face
230    {
231        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
232        camera->setGraphicsContext(gc.get());
233        camera->setViewport(new osg::Viewport(center_x-camera_width*3/2, center_y, camera_width, camera_height));
234        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
235        camera->setDrawBuffer(buffer);
236        camera->setReadBuffer(buffer);
237
238        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0));
239    }
240
241    // right face
242    {
243        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
244        camera->setGraphicsContext(gc.get());
245        camera->setViewport(new osg::Viewport(center_x+camera_width/2, center_y, camera_width, camera_height));
246        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
247        camera->setDrawBuffer(buffer);
248        camera->setReadBuffer(buffer);
249
250        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0));
251    }
252
253    // bottom face
254    {
255        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
256        camera->setGraphicsContext(gc.get());
257        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-camera_height, camera_width, camera_height));
258        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
259        camera->setDrawBuffer(buffer);
260        camera->setReadBuffer(buffer);
261
262        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0));
263    }
264
265    // back face
266    {
267        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
268        camera->setGraphicsContext(gc.get());
269        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-2*camera_height, camera_width, camera_height));
270        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
271        camera->setDrawBuffer(buffer);
272        camera->setReadBuffer(buffer);
273
274        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-180.0f), 1.0,0.0,0.0));
275    }
276   
277    viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
278
279    viewer.assignSceneDataToCameras();
280}
281
282struct DrawCallback : public osg::Drawable::DrawCallback
283{
284
285    DrawCallback() {}
286
287    virtual void drawImplementation(osg::State& state,const osg::Drawable* drawable) const
288    {
289        osg::notify(osg::NOTICE)<<"I am here"<<std::endl;
290        osg::notify(osg::NOTICE)<<"  Projection matrix "<<state.getProjectionMatrix()<<std::endl;
291        osg::notify(osg::NOTICE)<<"  ModelView matrix "<<state.getModelViewMatrix()<<std::endl;
292       
293        drawable->drawImplementation(state);
294    }
295};
296
297
298void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& /*arguments*/)
299{
300 
301    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
302    if (!wsi)
303    {
304        osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
305        return;
306    }
307
308    unsigned int width, height;
309    wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
310
311    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
312    traits->x = 0;
313    traits->y = 0;
314    traits->width = width;
315    traits->height = height;
316    traits->windowDecoration = false;
317    traits->doubleBuffer = true;
318    traits->sharedContext = 0;
319
320    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
321    if (!gc)
322    {
323        osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
324        return;
325    }
326
327    gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
328    gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
329
330
331    int center_x = width/2;
332    int center_y = height/2;
333    int camera_width = 256;
334    int camera_height = 256;
335   
336    int tex_width = 256;
337    int tex_height = 256;
338   
339    osg::TextureCubeMap* texture = new osg::TextureCubeMap;
340    texture->setTextureSize(tex_width, tex_height);
341    texture->setInternalFormat(GL_RGB);
342    texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
343    texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
344    texture->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
345    texture->setFilter(osg::TextureCubeMap::MIN_FILTER,osg::TextureCubeMap::LINEAR);
346    texture->setFilter(osg::TextureCubeMap::MAG_FILTER,osg::TextureCubeMap::LINEAR);
347
348    // front face
349    {
350        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
351        camera->setName("Front face camera");
352        camera->setGraphicsContext(gc.get());
353        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y, camera_width, camera_height));
354        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
355        camera->setDrawBuffer(buffer);
356        camera->setReadBuffer(buffer);
357       
358        // attach the texture and use it as the color buffer.
359        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z);
360
361        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
362    }
363   
364    // top face
365    {
366        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
367        camera->setName("Top face camera");
368        camera->setGraphicsContext(gc.get());
369        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y+camera_height, camera_width, camera_height));
370        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
371        camera->setDrawBuffer(buffer);
372        camera->setReadBuffer(buffer);
373
374        // attach the texture and use it as the color buffer.
375        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);
376
377        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0));
378    }
379
380    // left face
381    {
382        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
383        camera->setName("Left face camera");
384        camera->setGraphicsContext(gc.get());
385        camera->setViewport(new osg::Viewport(center_x-camera_width*3/2, center_y, camera_width, camera_height));
386        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
387        camera->setDrawBuffer(buffer);
388        camera->setReadBuffer(buffer);
389
390        // attach the texture and use it as the color buffer.
391        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);
392
393        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0));
394    }
395
396    // right face
397    {
398        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
399        camera->setName("Right face camera");
400        camera->setGraphicsContext(gc.get());
401        camera->setViewport(new osg::Viewport(center_x+camera_width/2, center_y, camera_width, camera_height));
402        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
403        camera->setDrawBuffer(buffer);
404        camera->setReadBuffer(buffer);
405
406        // attach the texture and use it as the color buffer.
407        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);
408
409        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0));
410    }
411
412    // bottom face
413    {
414        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
415        camera->setGraphicsContext(gc.get());
416        camera->setName("Bottom face camera");
417        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-camera_height, camera_width, camera_height));
418        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
419        camera->setDrawBuffer(buffer);
420        camera->setReadBuffer(buffer);
421
422        // attach the texture and use it as the color buffer.
423        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y);
424
425        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0));
426    }
427
428    // back face
429    {
430        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
431        camera->setName("Back face camera");
432        camera->setGraphicsContext(gc.get());
433        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-2*camera_height, camera_width, camera_height));
434        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
435        camera->setDrawBuffer(buffer);
436        camera->setReadBuffer(buffer);
437
438        // attach the texture and use it as the color buffer.
439        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z);
440
441        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-180.0f), 1.0,0.0,0.0));
442    }
443   
444    viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
445
446
447    viewer.assignSceneDataToCameras();
448
449
450    // distortion correction set up.
451    {
452       
453        // create the quad to visualize.
454        osg::Geometry* polyGeom = new osg::Geometry();
455
456        polyGeom->setSupportsDisplayList(false);
457
458        osg::Vec3 origin(0.0f,0.0f,0.0f);
459        osg::Vec3 xAxis(1.0f,0.0f,0.0f);
460        osg::Vec3 yAxis(0.0f,1.0f,0.0f);
461        osg::Vec3 zAxis(0.0f,0.0f,1.0f);
462        float height = 1024.0f;
463        float width = 1280.0f;
464        int noSteps = 50;
465
466        osg::Vec3Array* vertices = new osg::Vec3Array;
467        osg::Vec2Array* texcoords = new osg::Vec2Array;
468        osg::Vec4Array* colors = new osg::Vec4Array;
469
470        osg::Vec3 bottom = origin;
471        osg::Vec3 dx = xAxis*(width/((float)(noSteps-1)));
472        osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
473
474        osg::Vec2 bottom_texcoord(0.0f,0.0f);
475        osg::Vec2 dx_texcoord(1.0f/(float)(noSteps-1),0.0f);
476        osg::Vec2 dy_texcoord(0.0f,1.0f/(float)(noSteps-1));
477
478        osg::Vec3 cursor = bottom;
479        osg::Vec2 texcoord = bottom_texcoord;
480        int i,j;
481        for(i=0;i<noSteps;++i)
482        {
483            osg::Vec3 cursor = bottom+dy*(float)i;
484            osg::Vec2 texcoord = bottom_texcoord+dy_texcoord*(float)i;
485            for(j=0;j<noSteps;++j)
486            {
487                vertices->push_back(cursor);
488                texcoords->push_back(osg::Vec2((sin(texcoord.x()*osg::PI-osg::PI*0.5)+1.0f)*0.5f,(sin(texcoord.y()*osg::PI-osg::PI*0.5)+1.0f)*0.5f));
489                colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
490
491                cursor += dx;
492                texcoord += dx_texcoord;
493            }
494        }
495
496        // pass the created vertex array to the points geometry object.
497        polyGeom->setVertexArray(vertices);
498
499        polyGeom->setColorArray(colors);
500        polyGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
501
502        polyGeom->setTexCoordArray(0,texcoords);
503       
504        polyGeom->setDrawCallback(new DrawCallback);
505
506
507        for(i=0;i<noSteps-1;++i)
508        {
509            osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP);
510            for(j=0;j<noSteps;++j)
511            {
512                elements->push_back(j+(i+1)*noSteps);
513                elements->push_back(j+(i)*noSteps);
514            }
515            polyGeom->addPrimitiveSet(elements);
516        }
517
518
519        // new we need to add the texture to the Drawable, we do so by creating a
520        // StateSet to contain the Texture StateAttribute.
521        osg::StateSet* stateset = polyGeom->getOrCreateStateSet();
522        stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
523        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
524
525        osg::Geode* geode = new osg::Geode();
526        geode->addDrawable(polyGeom);
527
528        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
529        camera->setGraphicsContext(gc.get());
530        camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
531        camera->setClearColor( osg::Vec4(0.1,0.1,1.0,1.0) );
532        camera->setViewport(new osg::Viewport(0, 0, width/2, height/2));
533        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
534        camera->setDrawBuffer(buffer);
535        camera->setReadBuffer(buffer);
536        camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
537        //camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE);
538        //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
539       
540        camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
541        camera->setViewMatrix(osg::Matrix::identity());
542
543        // add subgraph to render
544        camera->addChild(geode);
545       
546        camera->setName("DistortionCorrectionCamera");
547
548        osg::notify(osg::NOTICE)<<"Original Projection matrix "<<camera->getProjectionMatrix()<<std::endl;
549        osg::notify(osg::NOTICE)<<"  View matrix "<<camera->getViewMatrix()<<std::endl;
550
551
552        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
553    }
554}
555
556
557int main(int argc, char** argv)
558{
559    // use an ArgumentParser object to manage the program arguments.
560    osg::ArgumentParser arguments(&argc,argv);
561
562    // construct the viewer.
563    osgViewer::Viewer viewer;
564   
565    // load the nodes from the commandline arguments.
566    osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
567    if (!loadedModel)
568    {
569        osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."<<std::endl;
570        return 1;
571    }
572
573    if (arguments.read("--dome"))
574    {   
575        viewer.setSceneData( loadedModel );
576
577        setDomeCorrection(viewer, arguments);
578   
579    }
580    else if (arguments.read("--faces"))
581    {   
582        viewer.setSceneData( loadedModel );
583
584        setDomeFaces(viewer, arguments);
585   
586    }
587    else
588    {
589        osg::Node* distortionNode = createDistortionSubgraph(loadedModel, viewer.getCamera()->getClearColor());
590
591        // add model to the viewer.
592        viewer.setSceneData( distortionNode );
593    }
594
595    viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
596
597    // add the state manipulator
598    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
599   
600    // add the stats handler
601    viewer.addEventHandler(new osgViewer::StatsHandler);
602
603    return viewer.run();
604}
605;
Note: See TracBrowser for help on using the browser.