|
我买了OpenSceneGraph三维渲染引擎编程指南,其中程序清单4-6中,关于delaunay三角的绘制中,
为什么我用三角网会这样呢 中间被灰色填充了 也是这本书上的程序啊……
求帮助!!!!!!!!!!!!
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Geometry>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgGA/StateSetManipulator>
#include <osgUtil/Optimizer>
#include <osgUtil/DelaunayTriangulator>
//#include "Tex.h"//用的是\examples\osghangglide\terrain_coords.h里的数据
#terrain_coords.h
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer=new osgViewer::Viewer();
viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()));
osg::ref_ptr<osg::Group>root=new osg::Group();
osg::ref_ptr<osg::Vec3Array>coords=new osg::Vec3Array();
unsigned int n= sizeof(vertex)/sizeof(float[3]);
for(unsigned int i=0;i<n;i++)
{
coords->push_back(osg::Vec3(vertex[0],vertex[1],vertex[2]));
}
osg::ref_ptr<osgUtil:elaunayTriangulator>dt=new osgUtil:elaunayTriangulator();
dt->triangulate();
osg::ref_ptr<osg::Geometry>geometry -new osg::Geometry();
geometry->setVertexArray(coords.get());
geometry->addPrimitiveSet(dt->getTriangles());
osg::ref_ptr<osg::Geode>geode=new osg::Geode();
geode->addDrawable(geometry.get());
root->addChild(geode.get());
osgUtil::Optimizer op;
op.optimize(root.get());
viewer->setSceneData(root.get());
viewer->realize();
viewer->run();
return 0;
} |
|