#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. Claims-Based Authentication and Authorization

    Introduction You can download the Visual Studio solutions for this article at this location. With al ...

  2. Qt中与文件目录相关操作

    一.与文件目录操作有关操作. Qt中与文件目录相关的操作在QDir中,需加入#include <QDir>语句. QDir::drives()是列出电脑根目录下的所有目录,返回的是QFil ...

  3. Build 2016上一些令人兴奋的东西

    本来应该要更新Windows IOT开发入门的,但是由于Build 2016刚刚过去,不得不将一些令人兴奋的东西给大家进行分享. 首先对于错过这次直播的,可以在以下链接再次看到观看: https:// ...

  4. mxnet卷积神经网络训练MNIST数据集测试

    mxnet框架下超全手写字体识别—从数据预处理到网络的训练—模型及日志的保存 import numpy as np import mxnet as mx import logging logging. ...

  5. mysql 5.7.10 启动多实例笔记

    1. 复制配置文件 cp /etc/my.cnf /etc/my3308.cnf 2. 修改配置文件 3. 创建目录, 并赋予权限 4. 初始化数据库 ---> 有报错 2018-01-03T0 ...

  6. html全选和取消全选JS

    <html> <body> <table border="1"> <tr> <th><input type=&qu ...

  7. InnoDB和MyISAM的区别与选择

    MyISAM 性能(适合小项目,读快速)MyISAM 是MySQL中默认的存储引擎,比如适合新闻系统,读为主.InnoDB 事务或外键支持(适合大项目,高并发读写)活跃用户20多万时候,也能很轻松应付 ...

  8. (原)关于sdl在部分机器上做视频显示,改变显示窗口大小会崩溃

    今天测试人员反应,之前做的视频绘图显示,会在她机器上,会出现崩溃现象,最后我在她机器上对代码进行跟踪,发现在某种情况,确实会崩溃. 最主要的原因是,视频显示窗口变成非活动窗口的时候,sdl内部会循环消 ...

  9. 本机IP、127.0.0.1和0.0.0.0的区别

    本机ip.127.0.0.1和0.0.0.0区别   网络java IP地址的记法: IP地址由四个字节构成,为了方便阅读和书写,每个字节用0-255的数字表示,字节之间用’.'分割,如: 10.10 ...

  10. Python——pyiso8601

    该模块不是Python内建的模块,为Python补充了 ISO 8601 解析——将常见的 ISO 8601 日期字符创转化为 Python 的 datetime 对象. 安装 $ pip insta ...