osg--几种效果

本文介绍了osg库中的一些特效使用,包括Billboard用于绘制小草,osgText模块用于创建2D和3D文字,osgParticle模块实现粒子系统如烟雾和爆炸,以及osgShadow模块如何创建阴影效果。此外,还提到了osgFX库中的特殊效果应用。
摘要由CSDN通过智能技术生成

billboards

适用于小草等的绘制

osg::BillBoard继承自osg::Geode,其下所有osg::Drawable面向观察者。旋转行为通过setMode()设置,分别为

  • POINT_ROT_EYE 几何体z轴旋转到窗口y轴
  • POINT_ROT_WORLD
  • AXIAL_ROT
    • setAxis()

锚点

billboard->addDrawable( child, osg::Vec3(1.0f, 0.0f, 0.0f) );

正向

setNormal()

默认法线是几何体的-y轴

示例

#include <osg/Billboard>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

osg::Geometry* createQuad()
{
	osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
	osg::ref_ptr<osg::Image> image =
		osgDB::readImageFile("Images/osg256.png");
	texture->setImage(image.get());

	osg::ref_ptr<osg::Geometry> quad =
		osg::createTexturedQuadGeometry(
			osg::Vec3(-0.5f, 0.0f, -0.5f),
			osg::Vec3(1.0f, 0.0f, 0.0f),
			osg::Vec3(0.0f, 0.0f, 1.0f));
	osg::StateSet* ss = quad->getOrCreateStateSet();
	ss->setTextureAttributeAndModes(0, texture.get());
	return quad.release();
}
int main(int argc, char** argv)
{
	osg::ref_ptr<osg::Billboard> geode = new osg::Billboard;
	geode->setMode(osg::Billboard::POINT_ROT_EYE);

	osg::Geometry* quad = createQuad();
	for (unsigned int i = 0; i<10; ++i)
	{
		float id = (float)i;
		geode->addDrawable(quad, osg::Vec3(-2.5f + 0.2f*id, id, 0.0f));
		geode->addDrawable(quad, osg::Vec3(2.5f - 0.2f*id, id, 0.0f));
	}

	osg::StateSet* ss = geode->getOrCreateStateSet();
	ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

	osgViewer::Viewer viewer;
	viewer.setSceneData(geode.get());
	return viewer.run();
}

说明

几何体z轴旋转到窗口y轴,几何体-y轴旋转到与视线重合

文字

osgText::Font

osg::ref_ptr<osgText::Font> g_font = osgText::readFontFile("fonts/arial.ttf");

osgText::Font3D

g_font3D = osgText::readFont3DFile("fonts/arial.ttf");

osgText::Text

继承osgText::TextBase,继承osg::Drawable

  • setFont()
  • setPosition()
  • setCharacterSize()
  • setText()
    • wchar_t*和string都可以
  • setAxisAlignment( osgText::TextBase::XY_PLANE )

osgText::Text3D

继承osgText::TextBase,继承osg::Drawable

示例–osgText::Text

#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgText/Font>
#include <osgText/Text>
#include <osgViewer/Viewer>
osg::ref_ptr<osgText::Font> g_font;
osg::Camera* createHUDCamera(double left, double right,
	double bottom, double top)
{
	osg::ref_ptr<osg::Camera> camera = new osg::Camera;
	camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
	camera->setClearMask(GL_DEPTH_BUFFER_BIT);
	camera->setRenderOrder(osg::Camera::POST_RENDER);
	camera->setAllowEventFocus(false);
	camera->s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值