⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readerwritergeo.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                case DB_DSK_RANGE_ACTION:                case DB_DSK_ROTATE_ACTION:                case DB_DSK_TRANSLATE_ACTION:                case DB_DSK_SCALE_ACTION:                case DB_DSK_ARITHMETIC_ACTION:                case DB_DSK_LOGIC_ACTION:                case DB_DSK_CONDITIONAL_ACTION:                case DB_DSK_LOOPING_ACTION:                case DB_DSK_COMPARE_ACTION:                case DB_DSK_VISIBILITY_ACTION:                case DB_DSK_STRING_CONTENT_ACTION:                case DB_DSK_COLOR_RAMP_ACTION:                case DB_DSK_LINEAR_ACTION:                case DB_DSK_TASK_ACTION:                case DB_DSK_PERIODIC_ACTION:#ifdef DB_DSK_PERIODIC2_ACTION                case DB_DSK_PERIODIC2_ACTION:#endif                case DB_DSK_TRIG_ACTION:                case DB_DSK_DISCRETE_ACTION:                case DB_DSK_INVERSE_ACTION:                case DB_DSK_TRUNCATE_ACTION:                case DB_DSK_ABS_ACTION:                case DB_DSK_IF_THEN_ELSE_ACTION:                case DB_DSK_DCS_ACTION:                case DB_DSK_SQRT_ACTION:    // an action                    if (curparent->getType()==DB_DSK_HEADER)                        curparent->addBehaviourRecord(&(*itr));                    else {                        class georecord *cp=curparent->getLastChild();                        if (cp) cp->addBehaviourRecord(&(*itr));                    }                    break;                case DB_DSK_PERSPECTIVE_GRID_INFO: // Feb 2003 not sure what this is yet!                    (curparent)->addchild(&(*itr));                    break;                case DB_DSK_PLANE_TEXTURE_MAPPING_INFO: // not needed for real time                case DB_DSK_CYLINDER_TEXTURE_MAPPING_INFO:    // not implemented in 1.0                case DB_DSK_SPHERE_TEXTURE_MAPPING_INFO:    // not implemented in 1.0                case DB_DSK_GRID_TEXTURE_MAPPING_INFO:    // not implemented in 1.0                    (curparent->getLastChild())->addMappingRecord(&(*itr));                    break;                default:                    if (curparent) {                        (*itr).setparent(curparent);                        curparent->addchild(&(*itr));                    }                     break;                }            }            return sorted;        }        void outputPrim(const georecord *grec, osgDB::Output &fout) { // output to file for debug            const std::vector<georecord *> gr=grec->getchildren();            if (gr.size()>0) {                for (std::vector<georecord *>::const_iterator itr=gr.begin();                    itr!=gr.end();                    ++itr) {                    fout << *(*itr) << std::endl;                }            }        } /*       bool allOneSided(const georecord *grec)    {            bool one=false;            const std::vector<georecord *> gr=grec->getchildren();            if (gr.size()>0) {                for (std::vector<georecord *>::const_iterator itr=gr.begin();                itr!=gr.end() && !one;                ++itr) {                    if ((*itr)->getType()==DB_DSK_POLYGON) {                        const geoField *gfd=(*itr)->getField(GEO_DB_POLY_DSTYLE);                        if (gfd) {                            int dstyle=gfd->getInt();                            one=(dstyle==GEO_POLY_DSTYLE_SOLID_BOTH_SIDES);                        }                    }                }            }            return one;        }*/        osg::Geometry *makeNewGeometry(const georecord *grec, geoInfo &ginf, int imat) {            const int shademodel=ginf.getShademodel();            const int bothsides=ginf.getBothsides();            osg::Geometry *nug;            int txidx=ginf.getTexture();            nug=new osg::Geometry;            const vertexInfo *vinf=ginf.getVinf();            nug->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);            nug->setVertexArray(vinf->getCoords());            StateSet *dstate=new StateSet;            if (bothsides==0) {                osg::CullFace *cf = new osg::CullFace; // to define non-default culling                cf->setMode(osg::CullFace::BACK);                dstate->setAttributeAndModes(cf,osg::StateAttribute::ON);            }            else if (bothsides==1) {                osg::CullFace *cf = new osg::CullFace; // to define non-default culling                cf->setMode(osg::CullFace::FRONT);                dstate->setAttributeAndModes(cf,osg::StateAttribute::ON);            }            else if (bothsides==2) {                osg::CullFace *cf = new osg::CullFace; // to define non-default culling                dstate->setAttributeAndModes(cf,osg::StateAttribute::OFF);            }            Point *pt=new Point;            pt->setSize(4);            dstate->setAttribute(pt);            if (txidx>=0 && (unsigned int)txidx<txlist.size()) {                dstate->setTextureAttribute(0, txenvlist[txidx] );                dstate->setTextureAttributeAndModes(0,txlist[txidx],osg::StateAttribute::ON);                const Image *txim=txlist[txidx]->getImage();                if (txim) {                    GLint icm=txim->computeNumComponents(txim->getPixelFormat());                    if (icm ==2 || icm==4) { // an alpha texture                        dstate->setMode(GL_BLEND,StateAttribute::ON);                        dstate->setRenderingHint(StateSet::TRANSPARENT_BIN);                    }                }            }            if (imat<0 || imat>=(int)matlist.size()) imat=0;            const geoField *gfd=grec->getField(GEO_DB_POLY_USE_MATERIAL_DIFFUSE); // true: use material...            bool usemat= gfd ? gfd->getBool() : false;            if (!usemat) {                matlist[imat]->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);                dstate->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::ON);            }            dstate->setAttribute(matlist[imat]);            Vec4 col=matlist[imat]->getAmbient(Material::FRONT);            if (col[3]<0.99) {                dstate->setMode(GL_BLEND,StateAttribute::ON);                dstate->setRenderingHint(StateSet::TRANSPARENT_BIN);            }            if (shademodel==GEO_POLY_SHADEMODEL_LIT ||                shademodel==GEO_POLY_SHADEMODEL_LIT_GOURAUD) dstate->setMode( GL_LIGHTING, osg::StateAttribute::ON );            else                 dstate->setMode( GL_LIGHTING, osg::StateAttribute::OFF );            { // reclaim the colours                gfd=grec->getField(GEO_DB_POLY_USE_MATERIAL_DIFFUSE); // true: use material...                bool usemat= gfd ? gfd->getBool() : false;                if (!usemat) { // get the per vertex colours OR per face colours.                    gfd=grec->getField(GEO_DB_POLY_USE_VERTEX_COLORS); // true: use material...                    bool usevert=gfd ? gfd->getBool() : false;                    if (usevert || shademodel==GEO_POLY_SHADEMODEL_GOURAUD) {                        Vec4Array *cls=vinf->getColors();                        if (cls) {                            nug->setColorArray(cls);                            nug->setColorBinding(osg::Geometry::BIND_PER_VERTEX);                        }                    } else {                        if (shademodel==GEO_POLY_SHADEMODEL_LIT_GOURAUD) {                            nug->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);                        } else if (shademodel==GEO_POLY_SHADEMODEL_LIT) {                            nug->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);                        }                        osg::Vec4Array *polycols=vinf->getPolcolours();                        nug->setColorArray(polycols);                        nug->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);                    }                }            }            osg::LineWidth *lw=new osg::LineWidth;            lw->setWidth(ginf.getlinewidth());            dstate->setAttributeAndModes(lw,osg::StateAttribute::ON);            nug->setStateSet( dstate );            ginf.setGeom(nug);            return nug;        }        int getprim(const georecord *grec, geoInfo &gi)        { // fills vinf with txcoords = texture coordinates, txindex=txindex etc            // for one primitive (one tri, quad, pol, tristrip....            vertexInfo *vinf=gi.getVinf();            int nv=0;            const std::vector<georecord *> gr=grec->getchildren();            const geoField *gfd=grec->getField(GEO_DB_POLY_PACKED_COLOR); // the colour            float defcol[4]; // a default colour for vertices            defcol[0]=defcol[1]=defcol[2]=defcol[3]=1.0f;            if (gfd) {                unsigned char *cls=gfd->getUCh4Arr();                defcol[0]=cls[0]/255.0f;                defcol[1]=cls[1]/255.0f;                defcol[2]=cls[2]/255.0f;                defcol[3]=1.0f;            } else {                gfd=grec->getField(GEO_DB_POLY_COLOR_INDEX); // the colour                if (gfd) {                    int icp= gfd ? gfd->getInt() : 0;                    theHeader->getPalette(icp,defcol);                } else {                    defcol[0]=defcol[1]=defcol[2]=defcol[3]=1.0f;                }            }            if (gr.size()>0) {                vinf->addFlat(grec); // for flat normal shading                for (std::vector<georecord *>::const_iterator itr=gr.begin();                    itr!=gr.end();                    ++itr) {                    vinf->addIndices((*itr), theHeader.get(), defcol, grec);                    nv++;                }            }            return nv;        }        void outputGeode(georecord grec, osgDB::Output &fout) { //             const std::vector<georecord *> gr=grec.getchildren();            if (gr.size()>0) {                fout.moveIn();                for (std::vector<georecord *>::const_iterator itr=gr.begin();                itr!=gr.end();                ++itr) {                    fout.indent() << *(*itr) << std::endl;                    if ((*itr)->getType()==DB_DSK_POLYGON) {                        outputPrim((*itr),fout);                    }                }                 fout.moveOut();            }        }        osg::MatrixTransform *makeText(georecord *gr) { // make transform, geode & text            osg::MatrixTransform *numt=NULL;            std::string    ttfPath("fonts/times.ttf");            // unused            //int    gFontSize1=2;            osgText::Text *text= new  osgText::Text;            text->setFont(ttfPath);            const geoField *gfd=gr->getField(GEO_DB_NODE_NAME);            const char *name=gfd ? gfd->getChar() : "a text";            gfd=gr->getField(GEO_DB_TEXT_STRING);            const char *content=gfd ? gfd->getChar() : " ";            text->setText(std::string(content));            gfd=gr->getField(GEO_DB_TEXT_SCALE_X);            //const float scx=gfd ? gfd->getFloat() : 1.0f;            gfd=gr->getField(GEO_DB_TEXT_SCALE_Y);            //const float scy=gfd ? gfd->getFloat() : 1.0f;            gfd=gr->getField(GEO_DB_TEXT_JUSTIFICATION); // GEO_DB_TEXT_DIRECTION);            int tjus=gfd? gfd->getInt() : GEO_TEXT_LEFT_JUSTIFY;            switch(tjus) {                case GEO_TEXT_LEFT_JUSTIFY:  text->setAlignment(osgText::Text::LEFT_BOTTOM); break;                case GEO_TEXT_CENTER_JUSTIFY:  text->setAlignment(osgText::Text::CENTER_BOTTOM); break;                case GEO_TEXT_RIGHT_JUSTIFY:  text->setAlignment(osgText::Text::RIGHT_BOTTOM); break;            }            gfd=gr->getField(GEO_DB_TEXT_PACKED_COLOR);            if (gfd) {                unsigned char *cp=gfd->getUCh4Arr();                float red=(float)cp[0]/255.0f;                float green=(float)cp[1]/255.0f;                float blue=(float)cp[2]/255.0f;                text->setColor(osg::Vec4(red,green,blue,1.0f));            } else { // lok for a colour index (exclusive!)                gfd=gr->getField(GEO_DB_TEXT_COLOR_INDEX);                if (gfd) {                    int icp=gfd->getInt();                    float col[4];                    theHeader->getPalette(icp,col);                    text->setColor(osg::Vec4(col[0],col[1],col[2],1.0));                }            }            osg::Geode *geod=new osg::Geode;            osg::StateSet *textState = new osg::StateSet();            textState->setMode(GL_LIGHTING, osg::StateAttribute::OFF);            geod->setStateSet( textState );            numt=new osg::MatrixTransform;            numt->setName(name);            gfd=gr->getField(GEO_DB_TEXT_MATRIX);            if (gfd) {                float *fmat=gfd->getMat44Arr();                            // text->setPosition(osg::Vec3(fmat[12],fmat[13],fmat[14]));                numt->setMatrix(Matrix(fmat));            }            numt->addChild(geod);            geod->addDrawable(text);            {                std::vector< georecord *>bhv=gr->getBehaviour();                if (!bhv.empty()) { // then check for a string content/colour.. action                    bool ok=false;                    geoBehaviourDrawableCB *gcb=new geoBehaviourDrawableCB;                    text->setUpdateCallback(gcb);                    for (std::vector< georecord *>::const_iterator rcitr=bhv.begin();                    rcitr!=bhv.end();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -