#include<windows.h>
#include <osgViewer/Viewer>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osg/ShapeDrawable>
#include <osgEarthUtil/EarthManipulator>
#include <osg/MatrixTransform>
#include <osgEarthFeatures/ConvertTypeFilter>
#include <osgEarthDrivers/model_simple/SimpleModelOptions>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator> #ifdef _DEBUG
#pragma comment(lib, "osgd.lib")
//#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgGAd.lib")
#pragma comment(lib, "osgEarthd.lib")
#pragma comment(lib, "osgEarthUtild.lib")
#else
#pragma comment(lib, "osg.lib")
#pragma comment(lib, "osgDB.lib")
#pragma comment(lib, "osgViewer.lib")
#pragma comment(lib, "osgGA.lib")
#endif // DEBUG // lonlat1:雷达波圆锥顶点
// lonlat2:轨迹点
void rotateCone(osg::MatrixTransform* mt, const osgEarth::SpatialReference* sr, osg::Vec3d lonlat1, osg::Vec3d lonlat2)
{
// 雷达波模型所在位置
osgEarth::GeoPoint geoPoint1(
sr,
lonlat1.x(),
lonlat1.y(),
lonlat1.z(),
osgEarth::ALTMODE_ABSOLUTE);
osg::Matrixd matrix1;
// 获取雷达波模型从原点变换到lonlat1位置的变换矩阵
geoPoint1.createLocalToWorld(matrix1);
// 经纬度高程到xyz的变换
osg::Vec3d world1, world2;
// geoPoint1.toWorld(world1);//等同于 sr->transformToWorld(lonlat1,world1);
sr->transformToWorld(lonlat2, world2);
// 计算轨迹点在雷达波模型坐标系下的位置
osg::Vec3 point2InRadarCoordinateSystem = world2*osg::Matrix::inverse(matrix1);
// 在雷达波模型坐标系下,对Z轴进行旋转,与连接原点指向轨迹点方向的矢量重合,计算出此旋转矩阵
osg::Matrixd rotMat = osg::Matrixd::rotate(osg::Z_AXIS, point2InRadarCoordinateSystem-osg::Vec3(,,));
// 将计算出的旋转矩阵赋给雷达波模型所在的mt
mt->setMatrix(rotMat);
}
int main(int argc, char** argv)
{
osgViewer::Viewer viewer;
std::string world_tif = "data/world.tif";
osgEarth::Map* map = new osgEarth::Map();
// Start with a basemap imagery layer; we'll be using the GDAL driver
// to load a local GeoTIFF file:
osgEarth::Drivers::GDALOptions basemapOpt;
basemapOpt.url() = world_tif;
map->addImageLayer(new osgEarth::ImageLayer(osgEarth::ImageLayerOptions("basemap", basemapOpt))); osgEarth::MapNodeOptions mapNodeOptions;
mapNodeOptions.enableLighting() = false;
osgEarth::MapNode* mapNode = new osgEarth::MapNode(map, mapNodeOptions); osgEarth::Drivers::SimpleModelOptions opt;
opt.location() = osg::Vec3(, , );
//opt.url() = "cow.osg.1000,1000,1000.scale";
osg::Geode* geode = new osg::Geode;
osg::ShapeDrawable* cone = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(), , ));
//osg::ShapeDrawable* cone = new osg::ShapeDrawable(new osg::Box(osg::Vec3(), 50000));
geode->addDrawable(cone);
osg::MatrixTransform* mtCone = new osg::MatrixTransform;
mtCone->addChild(geode);
opt.node() = mtCone;
map->addModelLayer(new osgEarth::ModelLayer("", opt)); rotateCone(mtCone, map->getProfile()->getSRS(), osg::Vec3(, , ), osg::Vec3(, , )); osg::Group* root = new osg::Group();
root->addChild(mapNode);
viewer.setSceneData(root);
viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator()); // Process cmdline args
//MapNodeHelper().parse(mapNode, arguments, &viewer, root, new LabelControl("Features Demo")); //视点定位模型所在位置
osgEarth::Viewpoint vp("", , , 1000.0, -2.50, -90.0, 1.5e6);
(dynamic_cast<osgEarth::Util::EarthManipulator*>(viewer.getCameraManipulator()))->setViewpoint(vp); // add some stock OSG handlers:
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
viewer.setUpViewInWindow(, , , );
return viewer.run();
}

osgEarth设置模型旋转角度的更多相关文章

  1. xBIM WeXplorer 设置模型颜色

    目录 基础 xBIM WeXplorer 简要介绍 xBIM WeXplorer xViewer 基本应用 xBIM WeXplorer xViewer 浏览器检查 xBIM WeXplorer xV ...

  2. xBIM 基础13 WeXplorer 设置模型颜色

    系列目录    [已更新最新开发文章,点击查看详细]  默认情况下模型具有合理的图形表示.这是从IFC模型中获取的,它应该在所有工具中看起来相同,它应该与您或您的用户的创作环境中的相同.但有时候能够改 ...

  3. [原][osgearth]设置OE的高程,高度场的数据。修改设置高度值

    ; row < hf->getNumRows(); ++row ) { ; col < hf->getNumColumns(); ++col ) { float val = h ...

  4. fluent批量处理——模型参数的设置

    对于常见的工程应用来说,计算的工况很多,尤其优化工作,少则几百,多则上千,面对如此之多的case文件要写,假如按照一个一个的读写的话,相信你一定会为这么机械的工作烦躁,甚至影响今后好几天的心情,那么有 ...

  5. WebGL或OpenGL关于模型视图投影变换的设置技巧

    目录 1. 具体实例 2. 解决方案 1) Cube.html 2) Cube.js 3) 运行结果 3. 详细讲解 1) 模型变换 2) 视图变换 3) 投影变换 4) 模型视图投影矩阵 4. 存在 ...

  6. xBIM 实战02 在浏览器中加载IFC模型文件并设置特效

    系列目录    [已更新最新开发文章,点击查看详细]  在模型浏览器中加载模型后,可以对模型做一些特殊操作.下图是常用的设置. 都是通过 xbim-viewer.js 中的 API 来设置以达到一定的 ...

  7. [源码解析] 模型并行分布式训练 Megatron (4) --- 如何设置各种并行

    [源码解析] 模型并行分布式训练 Megatron (4) --- 如何设置各种并行 目录 [源码解析] 模型并行分布式训练 Megatron (4) --- 如何设置各种并行 0x00 摘要 0x0 ...

  8. WebGL three.js学习笔记 加载外部模型以及Tween.js动画

    WebGL three.js学习笔记 加载外部模型以及Tween.js动画 本文的程序实现了加载外部stl格式的模型,以及学习了如何把加载的模型变为一个粒子系统,并使用Tween.js对该粒子系统进行 ...

  9. MVC4做网站六后台管理:6.2网站信息设置

    用来实现网站标题.名称.关键字.描述.版权等信息的设置. 模型字段: 网站的设置信息前后台都要用到,所以要把模型方式Ninesky/Models文件夹中,代码如下: ///////////////// ...

随机推荐

  1. Simple Path Data Resources that I Add to Every WPF and Silverlight Project

    Here’s a little time saver. I sort of have a routine that I go through when I create a new WPF proje ...

  2. nodemon是个好东西

    不说话,直接上图: 安装 使用

  3. 第三百七十七节,Django+Xadmin打造上线标准的在线教育平台—apps目录建立,以及数据表生成

    第三百七十七节,Django+Xadmin打造上线标准的在线教育平台—apps目录建立,以及数据表生成 apps目录建立 我们创建一个apps目录,将所有的app放到apps目录里去,这样方便管理,也 ...

  4. JDBC PrepareStatement对象执行批量处理实例

    以下是使用PrepareStatement对象进行批处理的典型步骤顺序 - 使用占位符创建SQL语句. 使用prepareStatement()方法创建PrepareStatement对象. 使用se ...

  5. R绘图系统中的坐标系

    在R语言中,对于图中的点来说,有很多种坐标系来进行定位 举个例子: par(omi = c(1, 1, 1, 1), mai = c(1, 1, 1, 1), mfrow = c(1, 2)) plo ...

  6. c#中//注释和///注释的区别 智能注释 显示换行

    ///会被编译,//不会所以使用///会减慢编译的速度(但不会影响执行速度)///会在其它的人调用你的代码时提供智能感知 也是一种注释,但是这种注释主要有两种作用:1.这些注释能够生成一个XML文件. ...

  7. Springmvc 的post请求的json格式参数

    背景: 这两天在项目中遇到了一个问题.我的环境是springmvc4.1.9,写了几个可以用ajax请求的接口(ajax.jsonp 调用正常).突然一时兴起就用 HTTP 请求的工具(比如火狐浏览器 ...

  8. Ubuntu14.04下安装Libsvm,并使用Libsvm

    (1)Ubuntu14.04下安装Libsvm 转载:https://blog.csdn.net/katrinawj/article/details/78915874 一.下载: 网址:http:// ...

  9. iOS: hide UITextField Cursor

    Simply subclass UITextField and override caretRectForPosition (继承 UITextField 并且重写 [UITextField care ...

  10. ios模拟器已安装但xcode无法显示

    最近把系统抹盘重装了, 然后用Time Machine恢复到原始状态, 一切安好, 但是使用xcode的时候发现一个模拟器都没有了: 各种折腾, 重装SDK啊, 重装xcode啊,最后发现, 如果你的 ...