Hey all I need a little help.  I'm still having a problem with my trees.
They are still floating. Here's the code for my trees:

osg::ref_ptr<osg::StateSet>sset = new osg::StateSet;
    osg::ref_ptr<osg::Texture2D> tex = new osg::Texture2D;
    tex->setImage( osgDB::readImageFile( "tree0.rgba" ));
    tex->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );
    tex->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP );
    tex->setFilter( osg::Texture2D::MIN_FILTER,
osg::Texture2D::LINEAR_MIPMAP_LINEAR );
    tex->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
    sset->setTextureAttributeAndModes( 0, tex.get() );
//**********************************************************************
****
    osg::ref_ptr<osg::Billboard> bb = new osg::Billboard;
    bb->setStateSet( sset.get() );
        int _error=0, y = 10, x = 10, _tim = 0;

        osg::Vec3d lv = osg::Vec3d(0.0,0.0,-1.0);
        osg::Vec3d up = osg::Vec3d(0.0,1.0,0.0);

        std::cout << "Creating Tree Locations ... ";
    for( int treeNum = 0; treeNum < 5000; treeNum++ )
    {
        // Place this tree at a random X,Y location   
                x =  rand()%1000;
                y =      rand()%1000;
        // Give it a random height
        float h = 2.0 + float(rand()%400)/100.0;

///////////////// Intersect Visitor section of code
////////////////////////


                osgUtil::IntersectVisitor isectVis;
                osgUtil::IntersectVisitor;

isectVis.setLODSelectionMode(osgUtil::IntersectVisitor::USE_SEGMENT_STAR
T_POINT_AS_EYE_POINT_FOR_LOD_LEVEL_SELECTION);
                osg::ref_ptr<osg::LineSegment> lineSeg = new
osg::LineSegment;

                //calculate distance 
                osg::Vec3d lv2;
                osg::Vec3d center(0.0,0.0,0.0);
                lv2.set( osg::Vec3d(x,y,50000) - center);
 
                double _distance = lv2.length();


                lineSeg->set(osg::Vec3d(x,y,50000),osg::Vec3d(x,y,50000)
+ lv *          _distance);

        isectVis.addLineSegment(lineSeg.get());
        terrain->accept(isectVis);

                        if (isectVis.hits())
            {
                                osgUtil::IntersectVisitor::HitList&
hitList = isectVis.getHitList(lineSeg.get());
                if (!hitList.empty())
                {
                    osg::Vec3 ip =
hitList.front().getWorldIntersectPoint();
                    osg::Vec3 np =
hitList.front().getWorldIntersectNormal();

                                        bb->addDrawable( tree(h).get()
);
                                        bb->setPosition( _tim, ip);
                }
            }
                _tim++;

        }
        std::cout << "Done" << std::endl;
    return bb.get(); 
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to