Learning OSG programing---osgAnimation(3)
接下来是用createModel函数创建模型:
osg::ref_ptr<osg::Group> createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique technique)
{
osg::Vec3 center(0.0f,0.0f,0.0f);
float radius = 100.0f; osg::ref_ptr<osg::Group> root = new osg::Group; float baseHeight = center.z()-radius*0.5;
osg::ref_ptr<osg::Node> baseModel = createBase(osg::Vec3(center.x(), center.y(), baseHeight),radius);
osg::ref_ptr<osg::Node> movingModel = createMovingModel(center,radius*0.8f); if (overlay)
{
osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode(technique);
overlayNode->setContinuousUpdate(true);
overlayNode->setOverlaySubgraph(movingModel);
overlayNode->setOverlayBaseHeight(baseHeight-0.01);
overlayNode->addChild(baseModel);
root->addChild(overlayNode);
}
else
{ root->addChild(baseModel);
} root->addChild(movingModel); return root;
}
这个函数首先根据前面定义的函数,创建方格地板和运动模型。根据函数的参数overlay决定是否建立重叠效果。
若指定创建重叠效果,则根据函数的参数technique创建重叠节点,并将运动模型movingModel设为其重叠的模型。将方格地板加入到重叠节点,并将重叠节点加入到根节点中。
如未指定创建重叠模式,则直接将方格地板和运动模型添加到根节点返回。
最后是主函数代码:
int main( int argc, char **argv )
{ bool overlay = false;
osg::ArgumentParser arguments(&argc,argv);
while (arguments.read("--overlay")) overlay = true; osgSim::OverlayNode::OverlayTechnique technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY;
while (arguments.read("--object")) { technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; overlay=true; }
while (arguments.read("--ortho") || arguments.read("--orthographic")) { technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; overlay=true; }
while (arguments.read("--persp") || arguments.read("--perspective")) { technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY; overlay=true; } // initialize the viewer.
osgViewer::Viewer viewer; // load the nodes from the commandline arguments.
osg::ref_ptr<osg::Group> model = createModel(overlay, technique);
if (!model)
{
return ;
} // tilt the scene so the default eye position is looking down on the model.
osg::ref_ptr<osg::MatrixTransform> rootnode = new osg::MatrixTransform;
rootnode->setMatrix(osg::Matrix::rotate(osg::inDegrees(30.0f),1.0f,0.0f,0.0f));
rootnode->addChild(model); // run optimization over the scene graph
osgUtil::Optimizer optimzer;
optimzer.optimize(rootnode); std::string filename;
if (arguments.read("-o",filename))
{
osgDB::writeNodeFile(*rootnode, filename);
return ;
} // set the scene to render
viewer.setSceneData(rootnode); viewer.setCameraManipulator(new osgGA::TrackballManipulator()); // viewer.setUpViewOnSingleScreen(1); #if 0 // use of custom simulation time. viewer.realize(); double simulationTime = 0.0; while (!viewer.done())
{
viewer.frame(simulationTime);
simulationTime += 0.001;
} return ;
#else // normal viewer usage.
return viewer.run(); #endif
}
主函数中,根据运行程序时指定的命令行参数,用createModel函数创建不同的节点对象。最后对生成的节点进行选转,优化等操作。在运行程序时,若在命令行中输入 -o选项,并在其后指定文件名,则程序可将生成的模型保存在指定的文件中。
运行程序,分别指定和不指定overlay选项时,产生不同的效果。
overlay

可以看到地板上会有模型的投影。
nonOverlay

Enjoy!
Learning OSG programing---osgAnimation(3)的更多相关文章
- Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现(转)
Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文, ...
- Deep Learning论文笔记之(八)Deep Learning最新综述
Deep Learning论文笔记之(八)Deep Learning最新综述 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文,但老感觉看完 ...
- Deep Learning论文笔记之(六)Multi-Stage多级架构分析
Deep Learning论文笔记之(六)Multi-Stage多级架构分析 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些 ...
- Learning Cocos2d-x for WP8(2)——深入刨析Hello World
原文:Learning Cocos2d-x for WP8(2)--深入刨析Hello World cocos2d-x框架 在兄弟篇Learning Cocos2d-x for XNA(1)——小窥c ...
- Learning Cocos2d-x for WP8(1)——创建首个项目
原文:Learning Cocos2d-x for WP8(1)--创建首个项目 Cocos2d-x for WP8开发语言是C++,系列文章将参考兄弟篇Learning Cocos2d-x for ...
- Learning Cocos2d-x for WP8(9)——Sprite到哪,我做主
原文:Learning Cocos2d-x for WP8(9)--Sprite到哪,我做主 工程文件TouchesTest.h和TouchesTest.cpp 相关素材文件 事件驱动同样适用于coc ...
- Learning Cocos2d-x for WP8(8)——动作Action
原文:Learning Cocos2d-x for WP8(8)--动作Action 游戏很大程度上是由动作画面支撑起来的. 动作分为两大类:瞬间动作和延时动作. 瞬间动作基本等同于设置节点的属性,延 ...
- Learning Cocos2d-x for WP8(7)——让Sprite动起来
原文:Learning Cocos2d-x for WP8(7)--让Sprite动起来 C#(wp7)兄弟篇Learning Cocos2d-x for XNA(7)——让Sprite动起来 本讲将 ...
- Learning Cocos2d-x for WP8(6)——场景切换和场景过渡效果
原文:Learning Cocos2d-x for WP8(6)--场景切换和场景过渡效果 C#(wp7)兄弟篇 Learning Cocos2d-x for XNA(6)——场景切换和场景过渡效果 ...
- Learning Cocos2d-x for WP8(5)——详解Menu菜单
原文:Learning Cocos2d-x for WP8(5)--详解Menu菜单 C#(wp7)兄弟篇Learning Cocos2d-x for XNA(5)——详解Menu菜单 菜单是游戏必不 ...
随机推荐
- EOJ Monthly 2019.2 A. 回收卫星
题目传送门 题意: 你可以询问一个三维坐标,机器会告诉你这个坐标在不在目标圆中, 并且(0,0,0)是一定在圆上的,叫你求出圆心坐标 思路: 因为(0,0,0)一定在圆上,所以我们可以把圆心分成3个坐 ...
- C# ListView添加DragDrop
先建立好ListView,ImageList,然后编写一个比较类在就是添加DragDrop事件了具体实现看代码吧 public partial class Form1 : Form { public ...
- OGG-00664
参数SID写错了 GGSCI (t2) > edit param exta extract exta setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) se ...
- java 简单工厂&抽象工厂
工厂模式:就是提供一个实例化对象的接口,让子类去决定实现哪个具体对象 1:简单工厂 public abstract class Person { } public class XiaoLi exten ...
- CSS3 Transform实例
移动translate <!doctype html> <html> <head> <meta charset="utf-8"> & ...
- js undefined三目运算
js ajax传值中 "id":$('#id').val(), 如果#id不存在,使用$('#id').val()||‘’,可避免向后台传入undefined
- redis不重启之rdb数据切换到aof数据
温馨提示: 要实现不重启从rdb切换到aof,redis的版本必须要在2.2以上. [root@pyyuc /data ::]#redis-server -v Redis server v= sha= ...
- Julia 语言
同时安装多个库 Pkg.add.(["IJulia", "Combinatorics", "Plots", "TaylorSeri ...
- php中ajax的使用实例讲解
一.总结 1.多复习:代码都挺简单的,就是需要复习,要多看 2.ajax原理:ajax就是部分更新页面,其实还在的html页面监听到事件后,然后传给服务器进行操作,这里用的是get方式来传值到服务器, ...
- sed进阶
下面这些命令未必经常会用到,但当需要时,知道这些肯定是件好事. 一.多行命令 sed命令通常是对一行数据进行处理,然后下一行重复处理. sed编辑器包含了三个可用来处理多行文本的特殊命令 N:将数据流 ...