Mark,

I have very similar requirements as you.  In order to keep the model HAT in 
sync with the terrain, I use a ReadFileCallback.

class MyReadFileCallback
        : public osgDB::Registry::ReadFileCallback
{
public:
        virtual osgDB::ReaderWriter::ReadResult
                readNode
                (
                        const std::string& fileName,
                        const osgDB::ReaderWriter::Options* options
                )
        {
                osgDB::ReaderWriter::ReadResult result =
                        
osgDB::Registry::instance()->readNodeImplementation(fileName, options);
                if (result.validNode())
                {
                        const osg::BoundingSphere& 
bs(result.getNode()->getBound());
                        MySceneManager::instance().updateHeights(bs);
                }

                return result;
        }
};

// Register the callback
osgDB::Registry::instance()->setReadFileCallback(new MyReadFileCallback());

The ReadFileCallback is called everytime a file is read by OSG.  This includes 
paged terrain files.  In MyReadFileCallback, I pass the newly-loaded file's 
bounding sphere into a scene manager.  In my case, I have a singleton that 
manages the scene graphs.

The scene manager is responsible for knowing which models are tied to the 
ground.  The following pseudocode describes what updateHeights does:

        // Quick filter
        // See if the latest loaded file is likely to be a terrain file
        //     (i.e. small models need not apply here)
        if (bounding sphere radius < 100)
                return;

        // See if any models are within range of the latest loaded file
        foreach model that is tied to the ground
                calculate horizontal distance from model to bounding sphere 
center
                if (horizontal distance < bounding sphere radius)
                        queue a line segment for the IntersectionVisitor

        // Update the model heights
        if (at least one line segment was queued to the IntersectionVisitor)
                apply the intersection visitor to the terrain to obtain heights
                foreach line segment
                        get the intersection point
                        update the height for the appropriate model

With large terrains, the intersection visitor can be time-consuming; 
therefore, we want to minimize the number of times an intersection visitor is 
applied to the terrain.  This process should only update heights for models 
that are specifically affected by the newly-loaded file.

Hope This Helps,
Justin

On Friday 09 November 2007 19:54:27 Mark Hurry wrote:
> I’m trying to position 30 - 40 models on a large terrapage (.txp)  terrain
> database, approximately 300miles x 500miles.
>
> All the models are scattered around the terrain.  The terrain is obviously
> not present all at one go for me to get all the HAT values I need.
>
> What I have done is move to each model position and wait for the HAT test
> to return a valid result. However my problem is that I think I am probably
> picking up a low level LOD intersection, so that when I eventually go and
> view the positioned model it can sometimes float above, sink below, or sit
> on the terrain.
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to