We are developing an osg-based application which requires the use of various 
vehicle models, which we have modeled at several levels-of-detail.

The highest level of detail for each of these vehicle models include 
articulated parts such as turrets that move in azimuth and guns that move in 
elevation (e.g. tanks).

Because the osg file is somewhat substantial, we do not want to load the same 
osg file for each entity in our simulation. If we had ten tanks to render, 
loading and using ten duplicate osg files wouldn't be so bad, but we need to 
support rendering dozens of different vehicle types with hundreds upon hundreds 
of vehicles of each type.

Therefore we took the advice found in the OpenSceneGraph beginners guide (page 
101 and 102) and have implemented a system whereby one detailed osg model is 
made the shared child of dozens or hundreds of parents (each of which is an 
osg::MatrixTransformation). During execution, we simply update the 
rotation/translation or these MatrixTransformation nodes and our single model 
is displayed in dozens or hundreds of unique locations and orientations.

But we also need this single model to be posed in a different way for each of 
the represented players: Tank1's turret and gun are at different angles than 
Tank2's turret and gun, etc.

So I have attempted to implement UpdateCallbacks in order to pose my tank model 
each time it needs to be rendered for a given player.

On the matrixTransform for each entity, I call setUserData() with some 
entity-specific data, then call setUpdateCallback with a callback object 
descended from NodeCallback:


Code:

class articulatedIconCallback : public osg::NodeCallback
{
public:
// called every time a player's matrixTransform node is updated during update 
traversal
virtual void operator()(osg::Node* n, osg::NodeVisitor* nv)
{
osg::ref_ptr<articulatedIconDataType> iconData = 
dynamic_cast<articulatedIconDataType*> ( n->getUserData() );
if (iconData)
{
iconData->updateIcon();
}
traverse(n,nv);
}
};




In my implementation of updateIcon(), the code retrieves the entity-specific 
data (MatrixTransformation->getUserData) in order to determine the turret and 
gun angles for that unique player, then proceeds to descend into the node 
hierarchy of the osg model, looking for nodes with specific names which mark 
them as an articulation point. For instance, we look for a matrixTransform node 
(internal to the osg model hierarchy) with the name "TURRET_AZIMUTH". If we 
find it, we set the matrix accordingly. We carry on and do the same for gun 
elevation and other articulated parts.

The problem is that this appears not to be working. All the player models are 
positioned and oriented correctly, but each and every player which shares an 
osg model shares the same turrent/gun angles, as if the last player processed 
is applying his data to all the players.

In general, am I correct in expecting setUpdateCallback to behave this way? Is 
there something specific I need to do to in order for this approach to work? Is 
there a different, preferred approach I should be using? Any help will be 
greatly appreciated!

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





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

Reply via email to