osg入门系列12-多边形分格
来源:互联网 发布:手机数据接口 type-c 编辑:程序博客网 时间:2024/04/29 00:46
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/ShapeDrawable>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osgUtil/Tessellator>
osg::ref_ptr<osg::Geode> tesslatorGeometry()
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
geode->addDrawable(geom.get());
const float wall[5][3] =
{
{2200.0f, 0.0f, 1130.0f},
{2600.0f, 0.0f, 1130.0f},
{2600.0f, 0.0f, 1340.0f},
{2400.0f, 0.0f, 1440.0f},
{2200.0f, 0.0f, 1340.0f}
};
const float door[4][3] =
{
{2360.0f, 0.0f, 1130.0f},
{2440.0f, 0.0f, 1130.0f},
{2440.0f, 0.0f, 1230.0f},
{2360.0f, 0.0f, 1230.0f}
};
const float windows[8][3] =
{
{2240.0f, 0.0f, 1180.0f},
{2330.0f, 0.0f, 1180.0f},
{2330.0f, 0.0f, 1220.0f},
{2240.0f, 0.0f, 1220.0f},
{2460.0f, 0.0f, 1180.0f},
{2560.0f, 0.0f, 1180.0f},
{2560.0f, 0.0f, 1220.0f},
{2460.0f, 0.0f, 1220.0f}
};
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array();
geom->setVertexArray(coords.get());
osg::ref_ptr<osg::Vec3Array> normal = new osg::Vec3Array();
normal->push_back(osg::Vec3(0.0f, -1.0f, 0.0f));
geom->setNormalArray(normal.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
for(int i =0 ; i< 5; i++)
{
coords->push_back(osg::Vec3(wall[i][0], wall[i][1], wall[i][2]));
}
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, 5));
for(int i =0; i<4; i++)
{
coords->push_back(osg::Vec3(door[i][0], door[i][1], door[i][2]));
}
for (int i =0; i<8; i++)
{
coords->push_back(osg::Vec3(windows[i][0], windows[i][1], windows[i][2]));
}
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 5, 12));
osg::ref_ptr<osgUtil::Tessellator> tscx = new osgUtil::Tessellator();
tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
tscx->setBoundaryOnly(false);
tscx->setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
tscx->retessellatePolygons(*(geom.get()));
return geode.get();
}
#include <iostream>
using namespace std;
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
osg::ref_ptr<osg::Group> root = new osg::Group();
osg::ref_ptr<osg::Geode> geode = tesslatorGeometry();
root->addChild(geode.get());
osgUtil::Optimizer optimizer;
optimizer.optimize(root.get());
viewer->setSceneData(root.get());
viewer->realize();
viewer->run();
return 0;
}
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/ShapeDrawable>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osgUtil/Tessellator>
osg::ref_ptr<osg::Geode> tesslatorGeometry()
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
geode->addDrawable(geom.get());
const float wall[5][3] =
{
{2200.0f, 0.0f, 1130.0f},
{2600.0f, 0.0f, 1130.0f},
{2600.0f, 0.0f, 1340.0f},
{2400.0f, 0.0f, 1440.0f},
{2200.0f, 0.0f, 1340.0f}
};
const float door[4][3] =
{
{2360.0f, 0.0f, 1130.0f},
{2440.0f, 0.0f, 1130.0f},
{2440.0f, 0.0f, 1230.0f},
{2360.0f, 0.0f, 1230.0f}
};
const float windows[8][3] =
{
{2240.0f, 0.0f, 1180.0f},
{2330.0f, 0.0f, 1180.0f},
{2330.0f, 0.0f, 1220.0f},
{2240.0f, 0.0f, 1220.0f},
{2460.0f, 0.0f, 1180.0f},
{2560.0f, 0.0f, 1180.0f},
{2560.0f, 0.0f, 1220.0f},
{2460.0f, 0.0f, 1220.0f}
};
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array();
geom->setVertexArray(coords.get());
osg::ref_ptr<osg::Vec3Array> normal = new osg::Vec3Array();
normal->push_back(osg::Vec3(0.0f, -1.0f, 0.0f));
geom->setNormalArray(normal.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
for(int i =0 ; i< 5; i++)
{
coords->push_back(osg::Vec3(wall[i][0], wall[i][1], wall[i][2]));
}
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, 5));
for(int i =0; i<4; i++)
{
coords->push_back(osg::Vec3(door[i][0], door[i][1], door[i][2]));
}
for (int i =0; i<8; i++)
{
coords->push_back(osg::Vec3(windows[i][0], windows[i][1], windows[i][2]));
}
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 5, 12));
osg::ref_ptr<osgUtil::Tessellator> tscx = new osgUtil::Tessellator();
tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
tscx->setBoundaryOnly(false);
tscx->setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
tscx->retessellatePolygons(*(geom.get()));
return geode.get();
}
#include <iostream>
using namespace std;
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
osg::ref_ptr<osg::Group> root = new osg::Group();
osg::ref_ptr<osg::Geode> geode = tesslatorGeometry();
root->addChild(geode.get());
osgUtil::Optimizer optimizer;
optimizer.optimize(root.get());
viewer->setSceneData(root.get());
viewer->realize();
viewer->run();
return 0;
}
---
0 0
- osg入门系列12-多边形分格
- osg入门系列1 - 初识osg
- OSG MFC入门基础系列
- osg入门系列3 - 开关节点例子
- osg入门系列5-代替节点
- osg入门系列6- 遮挡查询节点
- osg入门系列7- 一个小房子
- osg入门系列8-一个地球
- osg入门系列9-一个正方形
- osg入门系列11- 预订义几何体
- osg入门系列13-几何体简化
- osg入门系列14-狄落泥三角网
- osg入门系列-生成顶点法向量
- osg入门系列-渲染状态实例
- osg入门系列2-公告板的使用
- osg入门系列4- 分页细节层次节点
- osg入门系列10-以索引方式的几何体绘制
- 多边形序列70分
- 图片压缩算法(宽高不变)
- 运行一个EXE文件时,出现下面的文字,但程序能正常跑,请问怎么查找哪地方出现内存溢出?
- 【Python Challenge-6】zip
- 抽象方法不能是static或native或synchroniz 原因及误解
- C语言_预处理命令
- osg入门系列12-多边形分格
- Python Generators(生成器)——yield关键字
- 一个400行代码的网页游戏(二)
- 地理国情普查外业调绘轨迹线的整理方法
- 【数码管识别】感兴趣区域提取和缩放的顺序问题
- OpenCV2.2+CMake2.8.4+VS2010+WIN7
- iOS使用AVCaptureSession自定义相机
- CentOS安装squid代理服务器
- java中使用正则表达式:测试模式