virtual void apply(osg::MatrixTransform& xform) { const trpgHeader* header = _archive->GetHeader(); trpgHeader::trpgTileType tileType; header->GetTileOriginType(tileType); const osg::Referenced* ref = xform.getUserData(); const TileIdentifier* tileID = dynamic_cast<const txp::TileIdentifier*>(ref); if(!tileID) return; // bail early - this isn't a loaded model if(tileType == trpgHeader::TileLocal && tileID->lod == 9999) { trpg2dPoint tileExtents; header->GetTileSize(0, tileExtents); osg::BoundingBox bbox; _archive->getExtents(bbox); osg::Vec3 offset(xform.getMatrix().getTrans()); offset[0] -= bbox._min[0]; offset[1] -= bbox._min[1]; trpg2dPoint offsetXY, tileID(_tileInfo.x,_tileInfo.y); int divider = (0x01 << _tileInfo.lod); // calculate which tile model is located in tileExtents.x /= divider; tileExtents.y /= divider; offset[0] -= tileID.x*tileExtents.x; offset[1] -= tileID.y*tileExtents.y; osg::Matrix mat(xform.getMatrix()); mat.setTrans(offset); xform.setMatrix(mat); } }
void FltExportVisitor::apply( osg::MatrixTransform& node ) { // Importer reads a Matrix record and inserts a MatrixTransform above // the current node. We need to do the opposite: Write a Matrix record // as an ancillary record for each child. We do that by storing the // MatrixTransform in each child's UserData. Each child then checks // UserData and writes a Matrix record if UserData is a MatrixTransform. _firstNode = false; ScopedStatePushPop guard( this, node.getStateSet() ); osg::ref_ptr< osg::RefMatrix > m = new osg::RefMatrix; m->set( node.getMatrix() ); if (node.getUserData()) { const osg::RefMatrix* rm = dynamic_cast<const osg::RefMatrix*>( node.getUserData() ); if (rm) (*m) *= *rm; } typedef std::vector< osg::ref_ptr< osg::Referenced > > UserDataList; UserDataList saveUserDataList( node.getNumChildren() ); unsigned int idx; for( idx=0; idx<node.getNumChildren(); ++idx ) { saveUserDataList[ idx ] = node.getChild( idx )->getUserData(); node.getChild( idx )->setUserData( m.get() ); } traverse( (osg::Node&)node ); // Restore saved UserData. for( idx=0; idx< node.getNumChildren(); ++idx ) { node.getChild( idx )->setUserData( saveUserDataList[ idx ].get() ); } }