OSG学习:使用已有回调示例
回调的类型有很多种,一般很容易就想到的是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();
}
结果图:
OSG学习:使用已有回调示例的更多相关文章
- OSG学习:转动的小汽车示例
由于只是简单的示例,所以小汽车的模型也比较简单,是由简单的几何体组成. 代码如下: #include <osg\ShapeDrawable> #include <osg\Animat ...
- OSG学习:响应键盘鼠标示例
示例功能:示例里面有两个模型,一个是牛,另一个是飞机.鼠标右键时牛和飞机都隐藏,鼠标左键双击时牛和飞机都显示,按键盘上面的LEFT键,显示牛,按键盘上面的RIGHT键显示飞机.其中显示与隐藏节点使用的 ...
- OSG学习:基本几何体绘制示例
绘制并渲染几何体主要有如下3大步骤: 1.创建各种向量数据,如顶点.纹理坐标.颜色和法线等.需要注意的是,添加顶点数据时主要按照逆时针顺序添加, 以确保背面剔除的正确. 2.实例化一个几何体对象(os ...
- OSG学习:位置变换节点示例
osg::PositionAttitudeTransform节点. #include <osgViewer\Viewer> #include <osg\Node> #inclu ...
- osg学习示例之遇到问题四骨骼动画编译osgCal
osg学习示例之遇到问题四骨骼动画编译osgCal 转自:http://blog.csdn.net/wuwangrun/article/details/8239451 今天学到书<OpenSce ...
- 对“demo!demo.Index+HookProc::Invoke”垃圾收集的类型已委托回调。这可能会导致应用程序崩溃、损坏和数据丢失。当传递委托给非托管代码,托管应用程序必须让这些委托保持活着
对"demo!demo.Index+HookProc::Invoke"垃圾收集的类型已委托回调.这可能会导致应用程序崩溃.损坏和数据丢失.当传递委托给非托管代码,托管应用程序必须承 ...
- MOOS学习笔记2——HelloWorld回调
MOOS学习笔记2--HelloWorld回调 例程 #include "MOOS/libMOOS/Comms/MOOSAsyncCommClient.h" bool OnConn ...
- OSG学习:使用OSG中预定义的几何体
常用的内嵌几何体包括: osg::Box //正方体 osg::Capsule //太空舱 osg::Cone //椎体 osg::Cylinder //柱体 osg::HeightField //高 ...
- OSG学习:阴影代码示例
效果图: 代码示例: #include <osgViewer/Viewer> #include <osg/Node> #include <osg/Geode> #i ...
随机推荐
- MapReduce之Map Join
一 介绍 之所以存在Reduce Join,是因为在map阶段不能获取所有需要的join字段,即:同一个key对应的字段可能位于不同map中.Reduce side join是非常低效的,因为shuf ...
- openssl windows平台编译库
首先感谢http://blog.csdn.net/YAOJINGKAO/article/details/53041165?locationNum=10&fps=1和https://www.cn ...
- python学习笔记:第19天 类的约束、异常、MD5和logging
目录 一.类的约束 二.异常处理: 三.MD5加密 四.日志(logging模块) 一.类的约束 真正写写项目的代码时都是多人协作的,所以有些地方需要约束程序的结构.也就是说,在分配任务之前就应该把功 ...
- 解决区间第K大的问题的各种方法
例题:http://poj.org/problem?id=2104 最近可能是念念不忘,必有回响吧,总是看到区间第k大的问题,第一次看到是在知乎上有人面试被弄懵了后来又多次在比赛中看到.以前大概是知道 ...
- 武汉Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 全球订单最多的成都优步推出"南北通勤线"业务
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Web服务器、Web容器、Application服务器、反向代理服务器的区别与联系
在Web开发中,经常会听到Web服务器(Web Server).Web容器(Web Container).应用服务器(Application Server).反向代理服务器(Reverse Proxy ...
- libevent学习五(Helper functions and types for Libevent)
基础类型 #ifdef WIN32 #define evutil_socket_t intptr_t #else #define evutil_socket_t int #endif ev_ssi ...
- Android性能测试 | 启动时间篇
[转载]原文地址:http://www.51testing.com/html/93/n-3724593.html 背景介绍 Android用户也许会经常碰到以下的问题: 1)应用后台开着,手机很快没电 ...
- InnoDB锁冲突案例演示
Preface As we know,InnoDB is index organized table.InnoDB engine supports row-level lock bas ...