zoukankan      html  css  js  c++  java
  • osg绘制一个球体

    //By smells2 at Lab 2012-02-21
    #include <osg/Group>
    #include <osg/Geode>
    #include <osg/ShapeDrawable>
    #include <osg/Texture2D>
    #include <osgViewer/Viewer>
    #include <osgDB/readfile>

    #include <osg/PositionAttitudeTransform>
    #include <osg/TexEnv>
    #include <osg/Texture2D>
    #include <iostream>
    int main()
    {
    osg::ref_ptr<osg::Group> root = new osg::Group;
    osgViewer::Viewer myViewer;

    //Declear Sphere instance,the constructor takes an osg::vec3 to define
    //center and a float to define the radius.
    //Then we declear the ShapDrawable instance that derive from Drawable .We should
    //initalize it with the shape we create above .
    osg::ref_ptr<osg::Geode> unitSphere = new osg::Geode;
    osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(osg::Vec3(0,0,0), 1.0f);
    osg::ref_ptr<osg::ShapeDrawable> shapeDrawable = new osg::ShapeDrawable(sphere.get());
    unitSphere->addDrawable(shapeDrawable.get());
    osg::ref_ptr<osg::PositionAttitudeTransform> sphereForm = new osg::PositionAttitudeTransform;
    sphereForm->setPosition(osg::Vec3(2.5,0.0,0.0));
    sphereForm->addChild(unitSphere.get());
    root->addChild(sphereForm.get());

    //load image from the file
    osg::ref_ptr<osg::Texture2D> earthTexture = new osg::Texture2D;
    earthTexture->setDataVariance(osg::Object::DYNAMIC);
    osg::ref_ptr<osg::Image> earthImage = osgDB::readImageFile("D:\OSG\osg2.9\OpenSceneGraph2.9.5\data\Images\land_shallow_topo_2048.jpg");
    if (!earthImage.get())
    {
    std::cout<<"load texture failed !"<<std::endl;
    return -1;
    }

    //assign the texture from the image file
    earthTexture->setImage(earthImage.get());

    //set the stateset for decal texture
    osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv;
    osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
    texenv->setMode(osg::TexEnv::DECAL);
    stateset->setTextureAttributeAndModes(0,earthTexture.get(),osg::StateAttribute::ON);
    stateset->setTextureAttribute(0,texenv.get());

    //realize
    root->setStateSet(stateset.get());
    myViewer.setSceneData(root.get());
    myViewer.realize();
    myViewer.run();
    }

  • 相关阅读:
    Android 自定义seekbar中,thumb被覆盖掉一部分问题
    Android SeekBar实现音量调节
    Android 设置thumb图片大小
    Android 图片处理方法
    Android 三档自定义滑动开关,禁止点击功能的实现,用默认的seekbar组件实现
    Android SeekBar自定义使用图片和颜色显示
    Android 使控件各占屏幕的一半
    Android ExpandableListView使用+获取SIM卡状态信息
    Android的5样的调试信息
    Js创建对象的做法
  • 原文地址:https://www.cnblogs.com/coolbear/p/3977579.html
Copyright © 2011-2022 走看看