osg--几何模型

osg与opengl管理数据存储的区别

  • opengl
    • 即时模式:glBegin()和glEnd()之间的顶点
    • 顶点数组模式:数组在内存
    • 显示列表模式:顶点和像素数据编译后拷贝入显存,重复使用
    • 顶点缓冲数组模式:数组在显存
  • osg
    • 顶点数组模式
    • 显示列表模式

快速绘制

示例

#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osgViewer/Viewer>
int main(int argc, char** argv)
{
	//osg::drawable+osg::shape
	osg::ref_ptr<osg::ShapeDrawable> shape1 = new osg::ShapeDrawable;
	shape1->setShape(new osg::Box(osg::Vec3(-3.0f, 0.0f, 0.0f),
		2.0f, 2.0f, 1.0f));
	osg::ref_ptr<osg::ShapeDrawable> shape2 = new osg::ShapeDrawable;
	shape2->setShape(new osg::Sphere(osg::Vec3(3.0f, 0.0f, 0.0f),
		1.0f));
	shape2->setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
	osg::ref_ptr<osg::ShapeDrawable> shape3 = new osg::ShapeDrawable;
	shape3->setShape(new osg::Cone(osg::Vec3(0.0f, 0.0f, 0.0f),
		1.0f, 1.0f));
	shape3->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));

	//osg::Geode
	osg::ref_ptr<osg::Geode> root = new osg::Geode;
	root->addDrawable(shape1.get());
	root->addDrawable(shape2.get());
	root->addDrawable(shape3.get());

	//osg::viewer
	osgViewer::Viewer viewer;
	viewer.setSceneData(root.get());
	return viewer.run();
}

代码分析

在这里插入图片描述

osg::Array

  • 用于支持顶点数组
  • 子类继承vector模板,支持push_back/pop_back/size操作
    • osg::Vec2Array
    • osg::Vec3Array
    • osg::UIntArray
  • 基本数据类型为osg::Vec2/osg::Vec3,etc
  • 由智能指针申请

osg::Geometry

  • 继承自osg::Drawable
  • 封装opengl的顶点数组绘制

顶点数组管理

在这里插入图片描述

顶点数组辅助函数

  • setColorBinding

  • setNormalBinding

  • setVertexAttribBinding

  • setFogCoordBinding

  • setSecondaryColorBinding

    geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    geom->setColorBinding( osg::Geometry::BIND_OVERALL );

组元管理

  • addPrimitiveSet
  • removePrimitiveSet
  • getPrimitiveSet
  • getNumPrimitiveSets

组元

  • osg::PrimitiveSet
  • 组元不能直接实例化,但是子类封装了opengl的glDrawArrays和glDrawElements
  • 子类osg::DrawArrays和osg::DrawElementsUInt生成一系列组元
  • osg::DrawArrays不用智能指针申请
  • osg::DrawElem
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值