1、字符串转double、float

double osg::asciiToFloat(const char* str);//位于\src\osg\Math.h
double osg::asciiToDouble(const char* str);//位于\src\osg\Math.cpp

2、快速生成Geometry、Geode

Geode* osg::createGeodeForImage(osg::Image* image);//位于\src\osg\image.cpp
Geometry* osg::createTexturedQuadGeometry(const Vec3&corner, const Vec3& widthVec,const Vec3& heightVec,float s=1.0f, flaot t=1.0f);//位于\src\osg\Geometry
osg::Geode* geode = new osg::Geode();
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(1,1,1), 1));
geode->addDrawable(drawable);
_root->addChild(geode);

3、检测一个路径是否是网络路径

bool osgDB::containsServerAddress( const std::string& filename);//位于\src\osgDB\FileNameUtils.cpp

相关函数:获取网络协议和网络地址:getServerProtocol()和getServerAddress()

4、文件、文件夹操作。osgEarth处理XML文档

osgDB\FileUtils.h//新建目录
extern bool makeDirectory(const std::string &directiryPath);
//判断一个文件路径是否存在
extern bool fileExists(const std::string &fileName);
//获取一个目录下的文件列表
typedef std::vector<std::string> DirectoryContents;
extern DirectoryContents getDirectoryContents(const std::string &dirName);
//判断一个filename是文件还是目录
enum FileType{ FILE_NOT_FOUND, REGULAR_FILE, DIRECTORY};
extern FileType fileType(const std::string& filename);
//读取XML文档,osgEarth/XmlUtils
osgEarth::XmlDocument* doc=new osgEarth::XmlDocument::load(const std::string &xmlfile);
osgEarth::Config docConfig=doc->getConfig();
if(!config.empty())
{std::string name=config.value("name");int age=config.value<int>("age",0);//需要注意的是key字符串必须都是小写,例如源XML中为MySet标签,只能写config.find("myset");不能 写config.find("MySet");osgEarth::Config* mySet=config.find("myset");if(config.hasChild("child1")){osgEarth::Config child=config.child("child1");}
}

5、在地球上放置模型

注意从osgEarth2.4版本开始,删除了osgEarth::Util::ObjectPlacer类,

以下代码适用于2.3之前的版本

osgEarth::Map* map = new osgEarth::Map();
osgEarth::MapNode* mapNode = new osgEarth::MapNode(map);
osgEarth::Util::ObjectPlacer* objPlacer = new osgEarth::Util::ObjectPlacer( mapNode );
osg::Node* model = osgDB::readNodeFile("teapot.3ds");
osg::Node* modelOnEarth = objPlacer->placeNode( model, lat, lon, elevation );//lat,lon表示模型在地球的纬度和经度,elevation是海拔
root->addChild( modelOnEarth );//添加到场景的根

对于2.4版本

osgEarth::GeoPoint point(mapNode->getMapSRS(), lon, lat, elevation, osgEarth::ALTMODE_ABSLOTE);
osg::Matrix m;
point.createLocalToWorld(m);
osg::MatrixTransform* mt = new osg::MatrixTransform(m);
mt->addChild(model);

6、获取地球半径

double equatorRadius=map->getSRS()->getEllipsoid()->getRadiusEquator();//6378137.0赤道半径

7、设定Home视点

osgEarth::Util::EarthManipulator* em = new osgEarth::Util::EarthManipulator();
em->setHomeViewpoint( osgEarth::Util::Viewpoint(116,40,0,0,-90,equqtorRadius*4);//正对北京地面,视点高度离地面高度为4个地球半径
viewer->setCameraManipulator(em);
//设置初始视点
em->setViewpoint(osgEarth::Util::Viewpoint(126,43,0,0,-90,5e4), 5);//5s,定位大东北

8、视点经过屏幕鼠标的射线与远、近裁剪面的交点

#include <osgManipulator/Dragger>osgManipulator::PointerInfo pi;
pi.setCamera(camera);
pi.setMousePosition(x,y);//x,y非归一化坐标,例如(10,30)
osg::Vec3 nearPoint,farPoint;//射线和远近裁剪面的交点
pi.getNearFarPoints(nearPoint,farPoint);

9、OSG三个坐标轴向量

osg\Vec3f文件末尾,直接使用,例如osg::Vec3f v=osg::X_AXIS;
const Vec3f X_AXIS(1.0,0.0,0.0);
const Vec3f Y_AXIS(0.0,1.0,0.0);
const Vec3f Z_AXIS(0.0,0.0,1.0);

10、反锯齿

osg::DisplaySettings::instance()->setNumMultiSamples(4);

11、PageLOD最大节点数量(默认是300)

viewer->getDatabasePager()->setTargetMaximumNumbeOfPageLOD(100);

12、获取摄像机(视点)在世界坐标中的位置

osg::Vec3 vPosEye, vCenter, vUp;
camera->getViewMatrixAsLookAt( vPosEye, vCenter, vUp);osg::ref_ptr<osg::Camera> cameraMaster = viewer->getCamera();
osg::Matrix _inverseMV;
_inverseMV.invert( cameraMaster->getViewMatrix());
osg::Vec3 ptEye= osg::Vec3(  0, 0, 0) * _inverseMV;
/*获取世界坐标系下的视点坐标:世界坐标系中某点Pworld在视点坐标系中为Pview,则Pview= Pworld * MV。则Pworld=Pview * MV逆,则视点坐标系下的视点(0,0,0)在世界坐标系下为:ptEye=(0,0,0)* MV逆。

13、(x,y,z)<-->(lon, lat, elevation)

mapNode->getMapSRS()->getEllipsoid()->convertLatLongHeightToXYZ( osg::DegreesToRadians( lat ), osg::DegreesToRadians( lon), alt, x, y, z);//To Map coordinates
GeoPoint map;
map.fromWorld( mapNode->getMapSRS(), x, y, z );//map.xyz is now lon, lat, alt //To world coordinates
GeoPoint map( mapNode->getMapSRS(), lon, lat, alt, ALTMODE_ABSOLUTE);
osg::Vec3d world;
map.toWorld( world );

14、使用osgEarth::ModelLayer添加模型

osgEarth::Drivers::SimpleModelOptions opt;
opt.url()="c:/glider.osg";
opt.location()=osg::Vec3d(lon, lat, elevation);//lon和lat单位是度,elevation单位是米,例如(112, 36, 1000)
map->addModelLayer(new osgEarth::ModelLayer("model", opt));

OSG/osgEarth相关功能函数汇总相关推荐

  1. gensim相关功能函数及其案例

    目录 一.gensim介绍 二.训练模型 相关转换 词频-逆文档频(Term Frequency * Inverse Document Frequency, Tf-Idf) 潜在语义索引(Latent ...

  2. powershell_功能扩展模块PSReadline(psReadlinekeyhandler)相关功能函数以及快捷键绑定情况(by official document)

    文章目录 快捷键 Fuction 使用补全功能后vscode背景配色(对于白色主题的优化) 快捷键 Get-PSReadLineKeyHandler (PSReadLine) - PowerShell ...

  3. pythonsave函数_Python常用功能函数

    Python常用功能函数汇总 1.按行写字符串到文件中 import sys, os, time, json def saveContext(filename,*name): format = '^' ...

  4. 个人永久性免费-Excel催化剂功能第56波-获取Excel对象属性相关自定义函数

    之前零散开发过一些自定义函数获取Excel对象属性,此次再细细地把有价值的属性都一一给开发完成,某些场景下,有这些小函数还是可以比较方便地实现一些通过Excel界面没法轻松获取到的信息. 修复与更新 ...

  5. [OSG]OSG的相关扩展

    参考:osg官网 http://www.osgchina.org/index.php?view=article&id=176 http://trac.openscenegraph.org/pr ...

  6. string.h包含哪些函数_Excel进行数据分析常用方法及函数汇总—【杏花开生物医药统计】...

    Excel是数据分析工作中经常使用的一种工具,经常包含着大量的原始数据,它功能十分强大,除了能录入.整理数据之外,还能进行一些常规的基础的数据分析,那么这里面就需要用到很多函数,今天就来给大家介绍一些 ...

  7. Oracle 21C 新特性:数据泵相关新特性汇总

    墨墨导读:本文来自墨天轮用户"JiekeXu"投稿,墨天轮主页:https://www.modb.pro/u/434,本文分享Oracle 21c 新特性:数据泵相关新特性汇总. ...

  8. 3-3 uniapp、HTML5+、Native.js 功能代码汇总

    3-3 uniapp.HTML5+.Native.js 功能代码汇总 本文只适用于 APP 代码汇总 Android平台 监听手机锁屏,解锁,开屏 var receiver; mui.plusRead ...

  9. 《数字图像处理》冈萨雷斯,Matlab函数汇总 .

    <数字图像处理>冈萨雷斯,Matlab函数汇总 . 图像显示 colorbar 显示彩条 getimage 由坐标轴得到图像数据 ice(DIPUM) 交互彩色编辑 image 创建和显示 ...

最新文章

  1. Java项目:无库版银行管理系统(java+Gui+文档)
  2. ORA-01589: 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项
  3. ig信息增益 java_文本分类综述
  4. saltstack 主题说明
  5. python求出五位数的回文数_python之递归
  6. java实现定时任务 Schedule
  7. 高考志愿填报:java 软件 程序员 目前的就业现状
  8. 博图导入的程序用step7读出_博图软件TIA STEP7 V16 上载程序方法
  9. Flutter自定义iconfont字体图标
  10. 【spring系列】spring注解解析原理
  11. 威纶通触摸屏上传错误_威纶通触摸屏程序怎么上传?
  12. 盛德奇嘉提醒冬季对爱车养护全攻略:保养洗车均要注意
  13. MySQL业务账号需要哪些权限_MySQL 日常运维业务账号权限的控制
  14. C#自制坦克大战小游戏
  15. 给跪了!见过最高逼格的项目总结报告!
  16. 叉积 微分 恒等式_单摆-微分方程浅谈
  17. Brotli压缩算法
  18. 妙不可言,这4款小众良心软件,值得你用心体会
  19. 数据可视化之excel和finebi报表实现对比
  20. 安卓数据转移到iphone老是中断_关于iPhone手机之间数据转移的几种方式

热门文章

  1. 包信封问题 以及 最长有序子序列问题
  2. linux下bus、devices和platform的基础模型 【转】
  3. oracle默认的优化器,Oracle优化器相关参数设置
  4. 我插计算机英语,帮我翻译以下计算机英语的句子
  5. java 方法的重载_Java中的方法和方法重载
  6. springBoot国际化多语言开发配置,中文OR英文支持一键切换
  7. 今天,我们考大学是为了什么?
  8. strongswan 配置文件 /etc/ipsec.conf 速查手册1
  9. Unity Occlusion Culling 遮挡剔除研究
  10. [荐] 微信小程序模板源码合集