创建一个四边形节点需要的步骤:
- 创建一个geode对象
- 创建一个geometry对象
- 创建顶点数组并加入数据
- 把顶点数组设置为geometry对象的顶点数据
- 创建纹理坐标数组并加入数据
- 把纹理数组设置为geometry对象的纹理坐标数据
- 创建颜色数组并加入数据
- 把颜色数组设置为geometry对象的颜色数据
- 设置颜色的绑定方式为单个顶点
- 创建法线数组并加入数据
- 把法线数组设置为geometry对象的法线数据
- 设置法线的绑定方式为全部顶点
- 设置geometry对象图元为四边形
- 将geometry对象添加到geode节点
- 返回geode
#include<osgViewer/Viewer>
#include<osg/Node>
#include<osg/Geode>
#include<osg/Group>
#include<osgDB/ReadFile>
#include<osgDB/WriteFile>
#include<osgUtil/Optimizer>
osg::ref_ptr<osg::Node> createQuad()
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array();
v->push_back(osg::Vec3(0, 0, 0));
v->push_back(osg::Vec3(1.0f, 0, 0));
v->push_back(osg::Vec3(1.0f, 0