osg学习第一篇:矩阵

基础的物体的移动,调用translate进行平移操作,调用setUpdateCallback回调函数在每一帧调用的时候更新。

AnimationPathCallback为setUpdateCallbac中的一个绕轴旋转的函数

效果图如下:

#include <iostream>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventAdapter>
#include <osgViewer/ViewerEventHandlers>
#include <osg/MatrixTransform>

osg::ref_ptr<osg::Node> MatrixOperation()
{
	osg::ref_ptr<osg::Group> group =  new osg::Group;
	osg::ref_ptr<osg::MatrixTransform> max = new osg::MatrixTransform; 
	osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("glider.osg");
	osg::ref_ptr<osg::MatrixTransform> max1 = new osg::MatrixTransform;
	osg::ref_ptr<osg::MatrixTransform> max2 = new osg::MatrixTransform;
	osg::ref_ptr<osg::MatrixTransform> max3 = new osg::MatrixTransform;

	max1->addChild(node.get());
	max1->setMatrix(osg::Matrix::translate(5.0,0,0));
	max->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(5.0,0,0),osg::Z_AXIS,2.0));
	max->addChild(max1.get());

	max3->addChild(node.get());
	max2->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(0,0,0),osg::Z_AXIS,5.0));
	max2->addChild(max3.get());

//	group->addChild(node.get());
	group->addChild(max.get());
	group->addChild(max2.get());
	return group;
}

int main()
{
	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
	viewer->setSceneData(MatrixOperation().get());
	return viewer->run();
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值