查看: 1309|回复: 1

用TRIANGLE_FAN绘制三角扇面问题

[复制链接]

该用户从未签到

发表于 2010-8-26 15:25:28 | 显示全部楼层 |阅读模式
osg::ref_ptr<osg:rawElementsUshort> draw = new osg::DrawElementsUshort(osg:rimitiveset::TRIANGLE_FAN);
draw->push_back(0);
......
geometry->SetPrimitiveset(draw.get());


为什么生成的图形不是面而是用线连接的呢?

该用户从未签到

发表于 2010-8-26 16:27:05 | 显示全部楼层
可能您的程序设置的问题,给您一段代码,,您对比下:

  1. #include <osg/Node>
  2. #include <osg/Group>
  3. #include <osg/Geode>
  4. #include <osg/Geometry>
  5. #include <osg/Texture2D>
  6. #include <osgDB/ReadFile>
  7. #include <osgViewer/Viewer>
  8. #include <osg/PositionAttitudeTransform>
  9. #include <osgGA/TrackballManipulator>
  10. int main()
  11. {
  12.         osgViewer::Viewer viewer;
  13.         osg::Group* root = new osg::Group();
  14.         osg::Geode* pyramidGeode = new osg::Geode();
  15.         osg::Geometry* pyramidGeometry = new osg::Geometry();

  16.         pyramidGeode->addDrawable(pyramidGeometry);
  17.         root->addChild(pyramidGeode);

  18.         osg::Vec3Array* pyramidVertices = new osg::Vec3Array;
  19.         pyramidVertices->push_back( osg::Vec3( 0, 0, 0) );
  20.         pyramidVertices->push_back( osg::Vec3(10, 0, 0) );
  21.         pyramidVertices->push_back( osg::Vec3(10,10, 0) );
  22.         pyramidVertices->push_back( osg::Vec3( 0,10, 0) );
  23.         pyramidVertices->push_back( osg::Vec3( 5, 5,10) );

  24.         pyramidGeometry->setVertexArray( pyramidVertices );


  25.         osg::DrawElementsUShort* pyramidBase =
  26.                 new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_FAN);
  27.         pyramidBase->push_back(4);
  28.         pyramidBase->push_back(3);
  29.         pyramidBase->push_back(2);
  30.         pyramidBase->push_back(1);
  31.         pyramidBase->push_back(0);
  32.         pyramidGeometry->addPrimitiveSet(pyramidBase);

  33.         viewer.setSceneData( root );;

  34.         viewer.setCameraManipulator(new osgGA::TrackballManipulator());
  35.         viewer.realize();

  36.         while( !viewer.done() )
  37.         {
  38.                 viewer.frame();
  39.         }

  40.         return 0;
  41. }


复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表