Exemplo n.º 1
0
    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);
        }
    }