Changeset 8254

Show
Ignore:
Timestamp:
04/28/08 20:23:18
Author:
robert
Message:

Set up camera exercise

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/06_nodes/6i_Camera/6i_Camera.cpp

    r8120 r8254  
    11#include <osg/Group> 
    2 #include <osg/ClipNode> 
    3 #include <osg/PositionAttitudeTransform> 
     2#include <osg/Geometry> 
    43 
    54#include <osgDB/ReadFile> 
     
    109int main( int argc, char **argv ) 
    1110{ 
    12     std::cout<<"TODO "<<argv[0]<<std::endl; 
     11 
     12    // This exercises introduces you to using osg::Camera in the scene graph. 
     13    //  
     14    // Camera's define a local projection, view matrix, and control the 
     15    // rendering order, viewport, buffer clears/colours and contain the subgraph to 
     16    // render.  Camera's can be used to render to texture directly or to 
     17    // overlay the existing scene graph 
     18    //  
     19    // Create a scene graph that renders the cow.osg to a texture using  
     20    // a RTT osg::Camera, and then use to texture to render to quad geometry. 
     21    // 
     22    //  
     23     
     24 
     25    // create a group to place the camera and the quad geometry 
     26    osg::ref_ptr<osg::Group> group = new osg::Group; 
     27 
     28    // load the scene graph we want to render to texture 
     29    osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg"); 
     30    if (!cow) 
     31    { 
     32        std::cout<<"Error: could not load 'cow.osg'."<<std::endl; 
     33        return 1; 
     34    } 
     35 
     36     
     37     
     38    // add the quad to the scene graph 
     39    osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
     40    osg::ref_ptr<osg::Geometry> geom = osg::createTexturedQuadGeometry( 
     41                                            osg::Vec3(0.0f,0.0f,0.0f), 
     42                                            osg::Vec3(1.0f,0.0f,0.0f),  
     43                                            osg::Vec3(0.0f,0.0f,1.0f) ); 
     44    geode->addDrawable(geom.get()); 
     45    group->addChild(geode.get()); 
     46     
     47    { 
     48        // Create a camera, add it to group 
     49        // Set the camera up to view cow scene graph 
     50        // Create a texture and attach it to the Camera's colour buffer 
     51        // Attach this texture to geom's StateSet. 
     52    } 
     53     
     54     
     55    // run viewer 
     56    osgViewer::Viewer viewer; 
     57    viewer.setSceneData(group.get()); 
     58    return viewer.run(); 
     59 
    1360}