Hi all,

I've created terrain using osgTerrain::Terrain, way simialr to that:

osgTerrain::Terrain* Terrain = new osgTerrain::Terrain;
osg::Image* high_map = osgDB::readImageFile( "height.bmp" );
osg::HeightField*  heightmap1 = new osg::HeightField;

heightmap1->allocate( RES_X, RES_Y );
heightmap1->setXInterval(10.0f);
heightmap1->setYInterval(10.0f);

for( int z = 0; z < RES_X; z++ )
  for( int x = 0; x < RES_Y; x++ )   
    heightmap1->setHeight( x, z, (float) *high_map->data( x, z ) );

 osg::ref_ptr<osgTerrain::Locator> Locator1 = new osgTerrain::Locator;
 Locator1->setCoordinateSystemType( osgTerrain::Locator::PROJECTED );
 Locator1->setTransformAsExtents( 0.0, 0.0, 2560.0, 2560.0 );

osg::ref_ptr<osgTerrain::HeightFieldLayer> HeightFieldLayer1 = new 
osgTerrain::HeightFieldLayer( heightmap1.get() );
HeightFieldLayer1->setLocator( Locator1.get() );

osg::ref_ptr<osgTerrain::TerrainTile> TerrainTile1 = new 
osgTerrain::TerrainTile;
TerrainTile1->setElevationLayer( HeightFieldLayer1.get() );
Terrain->setSampleRatio( 1.0f );

osg::ref_ptr<osg::StateSet> m_TerrainStateSet = Terrain->getOrCreateStateSet();
Terrain->addChild( TerrainTile1.get() );

Now i want to create manipulator, which could detect collisions of line segment 
with my terrain. I found sample named "pick", where collisions are detected in 
pick handler, but it is using computeIntersections() method  from Viewer class. 
I've tried to analyze computeIntersections() method but i think this is far 
ahead of my knowledge of OSG, so i would like to get some explanations or way 
how to do that. I'm trying to get terrain geometry (i don't know how :/), than 
use osgUtil::IntersectVisitor, but i cannot detect any collisions.

osg::LineSegment*  segment = new osg::LineSegment( vec, vec1 );
osgUtil::IntersectVisitor    visitor;
osgUtil::Hit                      hit;
osgUtil::IntersectVisitor::HitList  hits;

visitor.addLineSegment( segment );
Terrain->accept( visitor );
hits = visitor.getHitList( segment );

Thank you!

Cheers,
Robert

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32594#32594





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to