#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. Java调用SQL Server存储过程

    1.调用普通存储过程(1)创建存储过程CREATE Procedure [dbo].[GetContactListByName]  /*根据联系人姓名获取联系人信息*/@Name nvarchar(5 ...

  2. Qt 程序打包发布总结

    1.  概述 当我们用QT写好了一个软件,要把你的程序分享出去的时候,不可能把编译的目录拷贝给别人去运行.编译好的程序应该是一个主程序,加一些资源文件,再加一些动态链接库,高大上一些的还可以做一个安装 ...

  3. 函数式编程——C#理解

    转自:http://www.cnblogs.com/xiaozhi_5638/p/4762846.html 目录 一个问题 函数式编程中的函数 数学与函数式编程 混合式编程风格 一个问题 假设现在我们 ...

  4. pandas 带有重复值的轴索引

  5. 无法定位序数 12384 于动态链接库 mfc90.dll

    场景: 运行 vs2008 编译生成的一个 exe 错误: 无法定位序数 12384 于动态链接库 mfc90.dll 原因: 缺少vc++ 2008 运行库. vcredist 全称Microsof ...

  6. Linux下的rename命令

    Dos/Windows下,对文件改名用rename.而书上说,Linux下对文件或目录改名该用mv.我一直也是这样做的,却忽略了Linux下也有个叫rename的命令.都是rename,但功能上就有点 ...

  7. Yii2 响应部分 response

    当应用完成处理一个请求后, 会生成一个yii\web\Response响应对象并发送给终端用户 响应对象包含的信息有HTTP状态码,HTTP头和主体内容等, 网页应用开发的最终目的本质上就是根据不同的 ...

  8. c++ String去除头尾空格

    1.使用string的find_first_not_of,和find_last_not_of方法 #include <iostream> #include <string> s ...

  9. 谈谈Android中的Rect类——奇葩的思维

    最近在工作中遇到了一些问题,总结下来就是Android中Rect这个类造成的.不得不说,不知道Android SDK的开发人员是怎么想的, 这个类设计的太奇葩了.首先介绍一下Rect类:Rect类主要 ...

  10. asp.net操作cookie类,包含datatable批量存入cookie

    以下是类: public class CookieMgr { #region 快速储存Cookie /// <summary> /// 快速储存Cookie /// </summar ...