#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventAdapter>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgUtil/Optimizer>
#include <iostream>
#include <math.h>
#include <osg/LineWidth>
using namespace std;
static const double PI = 3.1415926535898;
//创建简单图元
osg::ref_ptr<osg::Node> CreateSimple()
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
//申请一些顶点
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
//申请颜色
osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array;
//申请法向量
osg::ref_ptr<osg::Vec3Array> lawline = new osg::Vec3Array;
//限制线宽
osg::ref_ptr<osg::LineWidth> width = new osg::LineWidth;
//设置顶点
geom->setVertexArray(coords.get());
//设置顶点联系方式
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));
//设置顶点颜色
geom->setColorArray(color.get());
geom->setColorBinding(osg::Geometry::AttributeBinding::BIND_PER_VERTEX);
//设置法向量
geom->setNormalArray(lawline.get());
geom->setNormalBinding(osg::Geometry::AttributeBinding::BIND_OVERALL);
//法向量
评论0