OSG中相机参数的更改
- #pragma comment(lib, "osg.lib")
- #pragma comment(lib, "osgDB.lib")
- #pragma comment(lib, "osgViewer.lib")
- #include "osgViewer/Viewer"
- #include "osgDB/ReadFile"
- #include "osg/Node"
- #include "osg/Shape"
- #include "osg/Geode"
- #include "osg/ShapeDrawable"
- int main(){
- //初始化视景器
- osg::ref_ptr<osgViewer::Viewer> viewer=new osgViewer::Viewer;
- //初始化场景根节点
- osg::ref_ptr<osg::Group> root=new osg::Group;
- //场景数据
- osg::ref_ptr<osg::Node> node=osgDB::readNodeFile("glider.osg");
- root->addChild(node);
- //将场景数据加入视景器中
- viewer->setSceneData(root);
- //得到相机默认的参数设置
- osg::Vec3d eye,center,up;
- viewer->getCamera()->getViewMatrixAsLookAt(eye,center,up);
- //将相机参数打印出来
- printf("init eye: %f,%f,%f\n",eye._v[0],eye._v[1],eye._v[2]);
- printf("init center: %f,%f,%f\n",center._v[0],center._v[1],center._v[2]);
- printf("init up: %f,%f,%f\n",up._v[0],up._v[1],up._v[2]);
- //修改相机参数
- eye=osg::Vec3d(0.0,-10.0,0.0);
- center=osg::Vec3d(0.0,0.0,0.0);
- up=osg::Vec3d(0.0,0.0,1.0);
- //将参数设置给相机,并立即获取相机参数
- viewer->getCamera()->setViewMatrixAsLookAt(eye,center,up);
- viewer->getCamera()->getViewMatrixAsLookAt(eye,center,up);
- //将参数打印出来
- printf("eye: %f,%f,%f new\n",eye._v[0],eye._v[1],eye._v[2]);
- printf("center: %f,%f,%f new\n",center._v[0],center._v[1],center._v[2]);
- printf("up: %f,%f,%f new\n",up._v[0],up._v[1],up._v[2]);
- //仿真循环,注意不要使用viewer->run(),如果使用这个参数,上面关于相机的所有更改都会无效
- while(!viewer->done())
- {
- viewer->frame();
- }
- return 1;
- }
结果如图:
上面的代码显示初始的相机参数是:
这个参数默认是看不到东西的,因为OSG中默认的坐标系是这个样子的:
这样,如果eye在原点,center在z轴负半轴的情况下是看不到东西,所以如果不自己手动设置参数是看不到的东西的。如下面的代码将设置相机位置的代码注释掉:
- #pragma comment(lib, "osg.lib")
- #pragma comment(lib, "osgDB.lib")
- #pragma comment(lib, "osgViewer.lib")
- #include "osgViewer/Viewer"
- #include "osgDB/ReadFile"
- #include "osg/Node"
- #include "osg/Shape"
- #include "osg/Geode"
- #include "osg/ShapeDrawable"
- int main(){
- //初始化视景器
- osg::ref_ptr<osgViewer::Viewer> viewer=new osgViewer::Viewer;
- //初始化场景根节点
- osg::ref_ptr<osg::Group> root=new osg::Group;
- //场景数据
- osg::ref_ptr<osg::Node> node=osgDB::readNodeFile("glider.osg");
- root->addChild(node);
- //将场景数据加入视景器中
- viewer->setSceneData(root);
- //得到相机默认的参数设置
- osg::Vec3d eye,center,up;
- viewer->getCamera()->getViewMatrixAsLookAt(eye,center,up);
- //将相机参数打印出来
- printf("init eye: %f,%f,%f\n",eye._v[0],eye._v[1],eye._v[2]);
- printf("init center: %f,%f,%f\n",center._v[0],center._v[1],center._v[2]);
- printf("init up: %f,%f,%f\n",up._v[0],up._v[1],up._v[2]);
- ////修改相机参数
- //eye=osg::Vec3d(0.0,-10.0,0.0);
- //center=osg::Vec3d(0.0,0.0,0.0);
- //up=osg::Vec3d(0.0,0.0,1.0);
- ////将参数设置给相机,并立即获取相机参数
- //viewer->getCamera()->setViewMatrixAsLookAt(eye,center,up);
- //viewer->getCamera()->getViewMatrixAsLookAt(eye,center,up);
- ////将参数打印出来
- //printf("eye: %f,%f,%f new\n",eye._v[0],eye._v[1],eye._v[2]);
- //printf("center: %f,%f,%f new\n",center._v[0],center._v[1],center._v[2]);
- //printf("up: %f,%f,%f new\n",up._v[0],up._v[1],up._v[2]);
- //仿真循环,注意不要使用viewer->run(),如果使用这个参数,上面关于相机的所有更改都会无效
- while(!viewer->done())
- {
- viewer->frame();
- }
- return 1;
- }
在这种情况下的效果如下图,什么都看不到:
使用下面这一组测试数据后:
- //修改相机参数
- eye=osg::Vec3d(-10.0,0.0,0.0);
- center=osg::Vec3d(0.0,0.0,0.0);
- up=osg::Vec3d(0.0,0.0,1.0);
即从x轴负半轴看去,看到的应该是飞机的正面,效果如下图:
正常。在这种情况下场景中是没有漫游器的,也不存在默认的漫游器这个说法,如果需要实现场景漫游,自己加个漫游器就可以了。
注意:如果直接使用:
- viewer->run();
怎么修改相机参数都是无效的,
即使加上
- viewer->setCameraManipulator(NULL);
也是一样,因为在
- viewer->run();
这个函数里会对场景中是否存在漫游器进行判断,如果没有漫游器,它会自己添加一个TrackballManipulator漫游器。
run函数的实现如下:
- int Viewer::run()
- {
- if (!getCameraManipulator() && getCamera()->getAllowEventFocus())
- {
- setCameraManipulator(new osgGA::TrackballManipulator());
- }
- setReleaseContextAtEndOfFrameHint(false);
- return ViewerBase::run();
- }
很容易看出问题所在了。
OSG中相机参数的更改的更多相关文章
- 【学习笔记】OSG中相机参数的更改
#pragma comment(lib, "osg.lib") #pragma comment(lib, "osgDB.lib") #pragma commen ...
- osg设置相机参数,包括初始位置
严重注意!!!以下设置必须在viewer.realize();之后,否则不起作用!!!! 设置相机的位置,可以通过CameraManipulator(一般是osgGA::TrackballManipu ...
- Three.js 中 相机的常用参数含义
Three.js 中相机常用的参数有up.position和lookAt. position是指相机所在的位置,将人头比作相机的话,那么position就是人头的中心的位置: up类似于人的脖子可以调 ...
- OSG使用更新回调来更改模型
OSG使用更新回调来更改模型 转自:http://blog.sina.com.cn/s/blog_668aae7801017gl7.html 使用回调类实现对场景图形节点的更新.本节将讲解如何使用回调 ...
- OSG中的示例程序简介
OSG中的示例程序简介 转自:http://www.cnblogs.com/indif/archive/2011/05/13/2045136.html 1.example_osganimate一)演示 ...
- OSG中的示例程序简介(转)
OSG中的示例程序简介 1.example_osganimate一)演示了路径动画的使用 (AnimationPath.AnimationPathCallback),路径动画回调可以作用在Camera ...
- osg中的视点控制
osg中的视点控制 osg的视点控制基类是CameraManipulator, 它是一个虚基类, 有用的方法都跟home有关. 在这个类里面有三个重要的成员变量: osg::Vec3d _homeEy ...
- ArcEngine中License权限等级更改的问题
曾经认为自己对于ArcGIS 开发许可问题比较理解了,并小结在<ArcEngine10.x开发的许可问题>中. 01.权限问题 今天在调用GP时失败(插值式开发,使用的是他人框架),因为需 ...
- Android AVD创建及设置中各参数详解
设置AVD时有些参数比较模糊,特地找了篇文章,大家参考下! 本文根据如下的模拟器安装做一些解释: Name:自定义虚拟的名称,不能有空格或者其他非法字符,否则不能创建,即Creat AVD不能高亮点击 ...
随机推荐
- C#编程技术层次
不谈具体领域(比如搜索,视频,网络等),单就编程语言这个垂直方向,大体上对它有一个如下的层次划分. 1. 基本运用C#语法,在各种工具和示例代码的支持下,完成一些基本程序任务 2. 熟练掌握面向对象与 ...
- ubuntu 安装配置JDK
总的原则:将压缩包解压至/usr/lib/jdk,设置jdk环境变量并将其修改为系统默认的jdk 1.将jdk-7u5-linux-x64.tar.gz拷贝到/usr/lib/jdk/目录下面,这里如 ...
- Unity Twist Effect Black Hole
Shader "Hidden/Twist Effect" {Properties { _MainTex ("Base (RGB)", 2D) = "w ...
- Oracle表空间扩展
From:http://blog.csdn.net/starnight_cbj/article/details/7398153 1.查看所有表空间使用情况 select b.file_id 文件ID号 ...
- [LeetCode] Largest Rectangle in Histogram 解题思路
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 常见的HTTP状态码深入理解
状态码的职责是当客户端向服务器端发送请求时,描述返回请求结果.借助状态码,用户可以知道服务器端是正常处理了请求,还是出现了什么错误. RFC2616定义的状态码,由3位数字和原因短信组成. 数字中的第 ...
- Spring3 M2 quartz-2.1.7 解决bean不能注入问题
我们要达到这样的效果 public class CancelUnpaidOrderTask implements Job { @Autowired private AppOrderService or ...
- C++ —— 时间与日期
导读 在平时编程中有时需要获取当前的时间或者日期,然而不同的平台不同的场景下,有时使用的API也不尽相同.一般来说,C/C++中关于时间的标准库函数在不同的平台的都可以使用,可一些与平台相关的函数就只 ...
- WebLogic SSRF 漏洞 (简要翻译)
[Ref]http://blog.gdssecurity.com/labs/2015/3/30/weblogic-ssrf-and-xss-cve-2014-4241-cve-2014-4210-cv ...
- 使用PDO连接数据库 查询和插入乱码的解决方法
问题:PDO连接数据库后,查询和插入中文到数据库,出现乱码,如图: 解决方法: 法1: try{ $opts_values = array(PDO::MYSQL_ATTR_INIT_COMMAND=& ...