OSG学习笔记(一)应用基础

1.OSG屏幕坐标系:

x轴:默认屏幕水平向右方向。

y轴:垂直屏幕向里。

z轴:垂直向上。

2.隐藏模型

模型仍在渲染当中,损耗并未减少,适用于小模型。

osg::ref_ptr<osg::Node> osgcool = osgDB::readNodeFile("glider.osg");
oc->setNodeMask(0);

3.节点开关

在内存中消失,需要时显示出来,适用于使用频率较低的模型。

#include <osg/Switch>

osg::ref_ptr<osg::Group> group = new osg::Group;	

osg::Switch *sw = new osg::Switch();
sw->addChild(osgDB::readNodeFile("glider.osg"),false);

group->addChild(sw);

4.模型变换

平移旋转缩放,通过矩阵相乘来实现。

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osg/Switch>
#include <osg/MatrixTransform>//矩阵变换

int main()
{
	osg::ref_ptr<osg::Group> group = new osg::Group;


	osg::ref_ptr<osg::Node> osgcool = osgDB::readNodeFile("glider.osg");

	osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform;
	trans->setMatrix(osg::Matrix::translate(0, 0, 2));
	trans->addChild(osgcool.get());

	osg::ref_ptr<osg::MatrixTransform> scale = new osg::MatrixTransform;
	scale->setMatrix(osg::Matrix::scale(0.5, 0.5, 0.5)*osg::Matrix::translate(0, 0, -2));
	scale->addChild(osgcool.get()); 
	
	osg::ref_ptr<osg::MatrixTransform> rot = new osg::MatrixTransform;
	rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(45.0), 1, 0, 0)*osg::Matrix::scale(0.5, 0.5, 0.5)*osg::Matrix::translate(4, 0, -2));
	rot->addChild(osgcool.get());

	group->addChild(osgcool.get());
	group->addChild(trans.get());
	group->addChild(scale.get());
	group->addChild(rot.get());

	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
	viewer->setSceneData(group.get());
	viewer->addEventHandler(new osgViewer::WindowSizeHandler);	
	viewer->run();

	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值