Show
Ignore:
Timestamp:
09/06/05 22:28:53 (9 years ago)
Author:
robert
Message:

Added a grid of lines into the OverlaySubgraph? to demonstate use the
OverlayNode? for applying general drawing onto terrain.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgspheresegment/osgspheresegment.cpp

    r4506 r4508  
    77#include <osg/PositionAttitudeTransform> 
    88#include <osg/MatrixTransform> 
     9#include <osg/Geometry> 
    910 
    1011#include <osgDB/ReadFile> 
     
    139140} 
    140141 
     142osg::Group* createOverlay(const osg::Vec3& center, float radius) 
     143{ 
     144    osg::Group* group = new osg::Group; 
     145     
     146    // create a grid of lines. 
     147    { 
     148        osg::Geometry* geom = new osg::Geometry; 
     149         
     150        unsigned int num_rows = 10; 
     151 
     152        osg::Vec3 left = center+osg::Vec3(-radius,-radius,0.0f); 
     153        osg::Vec3 right = center+osg::Vec3(radius,-radius,0.0f); 
     154        osg::Vec3 delta_row = osg::Vec3(0.0f,2.0f*radius/float(num_rows-1),0.0f); 
     155 
     156        osg::Vec3 top = center+osg::Vec3(-radius,radius,0.0f); 
     157        osg::Vec3 bottom = center+osg::Vec3(-radius,-radius,0.0f); 
     158        osg::Vec3 delta_column = osg::Vec3(2.0f*radius/float(num_rows-1),0.0f,0.0f); 
     159 
     160        osg::Vec3Array* vertices = new osg::Vec3Array; 
     161        for(unsigned int i=0; i<num_rows; ++i) 
     162        { 
     163            vertices->push_back(left); 
     164            vertices->push_back(right); 
     165            left += delta_row; 
     166            right += delta_row; 
     167 
     168            vertices->push_back(top); 
     169            vertices->push_back(bottom); 
     170            top += delta_column; 
     171            bottom += delta_column; 
     172        } 
     173         
     174        geom->setVertexArray(vertices); 
     175        geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,vertices->getNumElements()));  
     176 
     177        osg::Geode* geode = new osg::Geode; 
     178        geode->addDrawable(geom); 
     179        group->addChild(geode);         
     180    } 
     181     
     182    return group; 
     183} 
    141184 
    142185osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y) 
     
    231274 
    232275#if 1 
     276 
     277 
    233278    osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode; 
    234     overlayNode->setOverlaySubgraph(ss.get()); 
     279 
     280    const osg::BoundingSphere& bs = terrainGeode->getBound(); 
     281    osg::Group* overlaySubgraph = createOverlay(bs.center(), bs.radius()*0.5f); 
     282    overlaySubgraph->addChild(ss.get()); 
     283    overlayNode->setOverlaySubgraph(overlaySubgraph); 
    235284    overlayNode->setOverlayTextureSizeHint(2048); 
    236285    overlayNode->addChild(terrainGeode.get());