怎样在osg中动态的设置drawable的最近最远裁剪面
// draw callback that will tweak the far clipping plane just
// before rendering a drawable.
struct OverrideNearFarValuesCallback : public osg::Drawable::DrawCallback
{
OverrideNearFarValuesCallback(double radius)
: _radius(radius) {}
virtual void drawImplementation(osg::RenderInfo& renderInfo,
const osg::Drawable* drawable) const
{
osg::Camera* currentCamera = renderInfo.getCurrentCamera();
if (currentCamera)
{
// Get the current camera position.
osg::Vec3 eye, center, up;
renderInfo.getCurrentCamera()->getViewMatrixAsLookAt( eye, center, up);
// Get the max distance we need the far plane to be at,
// which is the distance between the eye and the origin
// plus the distant from the origin to the object (star sphere
// radius, sun distance etc), and then some.
double distance = eye.length() + _radius*2;
// Save old values.
osg::ref_ptr<osg::RefMatrixd> oldProjectionMatrix = new osg::RefMatrix;
oldProjectionMatrix->set( renderInfo.getState()->getProjectionMatrix());
// Get the individual values
double left, right, bottom, top, zNear, zFar;
oldProjectionMatrix->getFrustum( left, right, bottom, top, zNear, zFar);
// Build a new projection matrix with a modified far plane
osg::ref_ptr<osg::RefMatrixd> projectionMatrix = new osg::RefMatrix;
projectionMatrix->makeFrustum( left, right, bottom, top, zNear, distance );
renderInfo.getState()->applyProjectionMatrix( projectionMatrix.get());
// Draw the drawable
drawable->drawImplementation(renderInfo);
// Reset the far plane to the old value.
renderInfo.getState()->applyProjectionMatrix( oldProjectionMatrix.get() );
}
else
{
drawable->drawImplementation(renderInfo);
}
}
double _radius;
};
struct AddCallbackToDrawablesVisitor : public osg::NodeVisitor
{
AddCallbackToDrawablesVisitor(double radius)
: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_radius(radius) {}
virtual void apply(osg::Geode& node)
{
for (unsigned int i = 0; i < node.getNumDrawables(); i++)
{
node.getDrawable(i)->setDrawCallback( new OverrideNearFarValuesCallback(_radius) );
// Do not use display lists otherwise the callback will only
// be called once on initial compile.
node.getDrawable(i)->setUseDisplayList(false);
}
}
double _radius;
};
调用
***********************************************
AddCallbackToDrawablesVisitor visitor( mpr_innerRadius );
geode->accept( visitor );
**********************************************
怎样在osg中动态的设置drawable的最近最远裁剪面的更多相关文章
- Android代码中动态设置图片的大小(自动缩放),位置
项目中需要用到在代码中动态调整图片的位置和设置图片大小,能自动缩放图片,用ImageView控件,具体做法如下: 1.布局文件 <RelativeLayout xmlns:android=&qu ...
- 在后台代码中动态生成pivot项并设置EventTrigger和Action的绑定
最近在做今日头条WP的过程中,遇到需要动态生成Pivot项的问题.第一个版本是把几个频道写死在xaml里了,事件绑定也写在xaml里,每个频道绑定一个ObservableCollection<A ...
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定). 这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户 ...
- 使用装饰器模式动态设置Drawable的ColorFilter
使用装饰器模式动态设置Drawable的ColorFilter 欢迎各位关注我的新浪微博:微博 转载请标明出处(kifile的博客) 非常多时候我们都希望Android控件点击的时候,有按下效果,选中 ...
- mvc中动态给一个Model类的属性设置验证
原文:mvc中动态给一个Model类的属性设置验证 在mvc中有自带的验证机制,比如如果某个字段的类型是数字或者日期,那么用户在输入汉字或者英文字符时,那么编译器会自动验证并提示用户格式不正确,不过这 ...
- Quartz在Spring中动态设置cronExpression
什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定). 这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户修改配置文 ...
- 微信小程序首页index.js获取不到app.js中动态设置的globalData的原因以及解决方法
前段时间开发了一款微信小程序,运行了也几个月了,在index.js中的onLoad生命周期里获取app.js中onLaunch生命周期中在接口里动态设置的globalData一直没有问题,结果昨天就获 ...
- 分别在javascript和JSP中动态设置下拉列表默认值
一.JavaScript中动态设置select标签中<option>选项的默认值: 比如,要完成下边这个下拉列表的动态显示,并且当进行前后翻页时,下拉列表中的值自动更新为当前页码: 图1 ...
- OSG中的示例程序简介
OSG中的示例程序简介 转自:http://www.cnblogs.com/indif/archive/2011/05/13/2045136.html 1.example_osganimate一)演示 ...
随机推荐
- Domain Name System (DNS)
1.DNS和WINS的作用 DNS:(Domain Name Server,域名服务)用于实现域名和IP地址的相互转换. WINS:(Windows Internet Name Service) 用来 ...
- Winform之SpreadSheetGear转DevExpress.XtraSpreadsheet.v13.2 z
DevExpress.XtraSpreadsheet.v13.2 允许用户创建.管理.打印.转换spreadsheet文件而不需要用户安装Office. 什么是Spreadsheet 可以看到最后就是 ...
- Allegro从.brd文件中导出器件封装
打开.brd文件,File→Export→Libraries,除了No libraries dependencies之外,所有选项都勾选上,设定好存放路径之后,Export. 注意事项: 1. 一般的 ...
- 游戏设计模式:Subclass Sandbox模式,以及功能方法集的设计思考
书中总结出这种 Subclass Sandbox 的设计模式 Game Design Patterns: Subclass Sandbox 这种模式要点有两点: 在基类中实现各种功能性方法供子类调用 ...
- linux 用 SSH2协议远程连接并控制 linux
[参考链接](http://php.net/manual/zh/ssh2.installation.php) ssh2_exec 并不能打印所有的命令的提示信息 如果有返回的字符串信息,可以打印,或重 ...
- 线性方法用于Binary clssification
到现在,我们已经学过三种线性方法:linear classification.Linear Regression.logistic Regression.这三种方法的核心都是,不同点在于:最小化的er ...
- hadoop的压缩解压缩,reduce端join,map端join
hadoop的压缩解压缩 hadoop对于常见的几种压缩算法对于我们的mapreduce都是内置支持,不需要我们关心.经过map之后,数据会产生输出经过shuffle,这个时候的shuffle过程特别 ...
- Memory Cache(内存缓存)
当Google测试了Google Search服务的可用性后,发现速度是最影响Web应用的可用性的因素之一.相对于作用相同但是速度慢的应用,用户更喜欢速度快的应用.多来年,Google已经掌握了如何使 ...
- HDU-4737 A Bit Fun 维护
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737 题意:给一个数列a0, a1 ... , an-1,令 f(i, j) = ai|ai+1|ai ...
- DAG的生成
DAG的生成 原始的RDD(s)通过一系列转换就形成了DAG.RDD之间的依赖关系,包含了RDD由哪些Parent RDD(s)转换而来和它依赖parent RDD(s)的哪些Partitions,是 ...