回调的类型有很多种,一般很容易就想到的是UpdateCallBack,或者EventCallBack,回调的意思就是说,你可以规定在某件事情发生时启动一个函数,这个函数可能做一些事情。这个函数就叫做回调函数。

#include<osg\MatrixTransform>
#include<osg\PositionAttitudeTransform>
#include<osg\Geode>
#include<osgDB\Registry>
#include<osgDB\ReadFile>
#include<osgGA\TrackballManipulator>
#include<osgViewer\Viewer> //创建一条路径
osg::AnimationPath* createAnimationPath(const osg::Vec3& center, float radius, double looptime)
{
//路径实体
osg::AnimationPath* animationPath = new osg::AnimationPath;
//设置循环模式为LOOP
animationPath->setLoopMode(osg::AnimationPath::LOOP);
//设置关键点数
int numSamples = 40;
float yaw = 0.0f;
float yaw_delta = 2.0f*osg::PI / ((float)numSamples - 1.0f);
float roll = osg::inDegrees(30.0f);
//设置时间间隔
double time = 0.0f;
double time_delta = looptime / (double)numSamples;
//插入关键点与时间以及旋转角度和位置
for (int i = 0; i < numSamples; ++i)
{
osg::Vec3 position(0, 0, 0);
osg::Quat rotation(osg::Quat(roll, osg::Vec3(0.0, 1.0, 0.0))*osg::Quat(-(yaw + osg::inDegrees(90.0f)), osg::Vec3(0.0, 0.0, 1.0)));
//具体插入操作
animationPath->insert(time, osg::AnimationPath::ControlPoint(position, rotation));
yaw += yaw_delta;
time += time_delta;
}
return animationPath;
}
//创建移动模型
osg::Node* createMovingModel(const osg::Vec3& center, float radius)
{
float animationLength = 10.0f;
//创建的路径
osg::AnimationPath* animationPath = createAnimationPath(center, radius, animationLength);
osg::Group* model = new osg::Group;
//读取模型,并隐藏它下面的第一个节点
osg::Node* fountain = osgDB::readNodeFile("fountain.osgt");
fountain->asGroup()->getChild(0)->setNodeMask(0);
//如果读取成功,则更新赋予它的路径
if (fountain)
{
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
//设置更新回调
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath, 0.0, 1.0));
//加入子模型节点
xform->addChild(fountain);
model->addChild(xform);
}
return model;
}
//创建模型
osg::Node* createModel()
{
osg::Vec3 center(0.0f, 0.0f, 0.0f);
float radius = 1.0f;
osg::Group* root = new osg::Group;
//创建移动的节点,以radius为半径转圈
osg::Node* movingModel = createMovingModel(center, radius*0.8f); //把节点加入到root中并返回
root->addChild(movingModel);
return root;
}
//主函数
int main(int argc, char** argv)
{
osgViewer::Viewer viewer;
//创建模型
osg::Node* model = createModel();
viewer.setSceneData(model);
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.realize();
return viewer.run();
}

结果图:

最新文章

  1. C# 注册 Windows 热键
  2. 浅析py-faster-rcnn中不同版本caffe的安装及其对应不同版本cudnn的解决方案
  3. 【MongoDB】2.可视化工具的安装和使用
  4. Discuz2 x3深入研究内容资料
  5. 544B. Sea and Islands
  6. lintcode:Flip Bits 将整数A转换为B
  7. 几个.net的GUI控件库
  8. JAVA中,JSON MAP LIST的相互转换
  9. mac环境下安装xampp
  10. 基于Spring的Appium配置应用
  11. Linux第六节随笔 输入输出重定向 、管道、通配符、wc / grep / tr / sort / cut / which /whereis /locate /find /
  12. XML解析的四种方法 建议使用demo4j解析 测试可以用
  13. 《程序猿闭门造车》之NBPM工作流引擎 - 项目整体架构
  14. cdnbest的proxy里api用法案例:
  15. C++中overload(重载),override(覆盖),overwrite(重写/覆写)的区别
  16. SVN下载项目导入到eclipse中出现错误解决办法:
  17. iOS边练边学--plist文件,懒加载,模型初使用--补充instancetype
  18. Android开发利用Volley框架下载和缓存网络图片
  19. EmWebAdmin 导航栏分析
  20. jpa双向一对一关联外键映射

热门文章

  1. 【Android】添加依赖包
  2. 使用bison和yacc制作脚本语言(4)
  3. java语言描述 用递归打印字符串
  4. linux线程篇 (三) 线程的同步
  5. SQL Server服务器角色和数据库角色描述
  6. ioc解析
  7. [python]安装wxpython的时候遇到问题记录
  8. stm32中如何进行printf重定向用于串口调试输出
  9. dubbo之监控中心(monitor)
  10. 机器学习的5种“兵法&quot;