(NOTE: I posted this question directly to the forum some time ago, but my
messages sit under moderation for too long to be useful. I decided to attempt
to post via the mailing list)
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 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
rotate/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 entities: 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 entity.
On the matrixTransform for each entity, I call setUserData with some
entity-specific data, then call setUpdateCallback with a callback object
descended from NodeCallback:
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 the articulation point. For instance we look for a matrix transform
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 to not be working. All the player models are
positioned and oriented correctly, but each and every player which shares an
osg model shares the same turret/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?
Any help will be greatly appreciated!
-Mike
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org