osg模型部分節點旋轉


 

osg::ref_ptr<osg::Geode> CreateBox()
{
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
    hints->setDetailRatio(0.5);

    osg::ref_ptr<osg::Material> material = new osg::Material;
    material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    material->setShininess(osg::Material::FRONT_AND_BACK, 60);

    osg::ref_ptr<osg::Texture2D> texture2D = new osg::Texture2D;
    //設置紋理
    osg::ref_ptr<osg::Image> image = osgDB::readImageFile("D:\\image_1\\arm1.jpg");
    if (image.valid())
    {
        texture2D->setImage(image.get());
    }

    osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0, 0.0, 0.0), 1.0, 1.0, 1.0), hints.get());
    shape->setColor(osg::Vec4(100.0f, 255.0f, 0.0f, 0.6));

    geode->getOrCreateStateSet()->setAttributeAndModes(material.get(), osg::StateAttribute::ON);
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture2D, osg::StateAttribute::ON);
    geode->addDrawable(shape.get());

    return geode;
}

 

osg::ref_ptr<osg::Geode> CreateSphere()
{
    osg::ref_ptr<osg::Group> _root = new osg::Group;

    //創建一個葉結點對象
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;

    //設置半徑和高度
    float _radius = 0.6f;
    float _height = 1.0f;

    //創建精細度對象,精細度越高,細分就越多
    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
    hints->setDetailRatio(0.9f);

    //添加一個球體,第一個參數是預定義的幾何體對象,第二個是精細度默認為1
    geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), _radius), hints));

    //_root->addChild(geode);

    return geode.get();
}
 
        

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM