指北针设置
来源:互联网 发布:mac ssh客户端工具 编辑:程序博客网 时间:2024/05/19 17:10
头文件:compass.h
class Compass : public osg::Camera{public: Compass(); Compass( const Compass& copy, osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY ); META_Node( osg, Compass ); void setPlate( osg::MatrixTransform* plate ) { _plateTransform = plate; } osg::MatrixTransform* getPlate() { return _plateTransform.get(); } const osg::MatrixTransform* getPlate() const { return _plateTransform.get(); } void setNeedle( osg::MatrixTransform* needle ) { _needleTransform = needle; } osg::MatrixTransform* getNeedle() { return _needleTransform.get(); } const osg::MatrixTransform* getNeedle() const { return _needleTransform.get(); } void setMainCamera( osg::Camera* camera ) { _mainCamera = camera; } osg::Camera* getMainCamera() { return _mainCamera.get(); } const osg::Camera* getMainCamera() const { return _mainCamera.get(); }void setWidthHeight(int x, int y, int width, int height){ m_xx = x; m_yy = y; m_width = width; m_height = height; }; virtual void traverse( osg::NodeVisitor& nv ); protected: virtual ~Compass();int m_width, m_height;int m_x, m_y, m_xx, m_yy; osg::ref_ptr<osg::MatrixTransform> _plateTransform; osg::ref_ptr<osg::MatrixTransform> _needleTransform; osg::observer_ptr<osg::Camera> _mainCamera;};
源文件:compass.cpp
Compass::Compass(){}Compass::Compass( const Compass& copy, osg::CopyOp copyop ): osg::Camera(copy, copyop), _plateTransform(copy._plateTransform), _needleTransform(copy._needleTransform), _mainCamera(copy._mainCamera){}Compass::~Compass(){}void Compass::traverse( osg::NodeVisitor& nv ){ if ( _mainCamera.valid() && nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR ) { osg::Matrix matrix = _mainCamera->getViewMatrix(); matrix.setTrans( osg::Vec3() ); osg::Vec3 northVec = osg::Z_AXIS * matrix; northVec.z() = 0.0f; northVec.normalize(); osg::Vec3 axis = osg::Y_AXIS ^ northVec; float angle = atan2(axis.length(), osg::Y_AXIS*northVec); axis.normalize(); if ( _plateTransform.valid() ) _plateTransform->setMatrix( osg::Matrix::rotate(angle, axis) );
<span style="white-space:pre"></span>//自动根据窗口大小设置位置,默认右上角if (m_x != _mainCamera->getViewport()->width() || _mainCamera->getViewport()->height() != m_y){m_x = _mainCamera->getViewport()->width();m_y = _mainCamera->getViewport()->height();this->setViewport(_mainCamera->getViewport()->width()-m_width-m_xx, _mainCamera->getViewport()->height()-m_height-m_yy, m_width, m_height);}} _plateTransform->accept( nv ); _needleTransform->accept( nv ); osg::Camera::traverse( nv );}
调用方法:
osg::ref_ptr<Compass> compass = new Compass;compass->setProjectionMatrix(osg::Matrixd::ortho(-1.5, 1.5, -1.5, 1.5, -10.0, 10.0));compass->setPlate(SELibrary::getInstance()->createCompassPart(m_strRootPath + "\\images\\compass_plate.png", 1.5f, -1.0f)); //圆盘图片compass->setNeedle(SELibrary::getInstance()->createCompassPart(m_strRootPath + "\\images\\compass_needle.png", 1.5f, 0.0f));//指针图片compass->setWidthHeight(x,y,width,height); //起始点、宽高compass->setMainCamera(m_pEarthViewer->getCamera());compass->setRenderOrder(osg::Camera::POST_RENDER);compass->setClearMask(GL_DEPTH_BUFFER_BIT);compass->setAllowEventFocus(false);compass->setReferenceFrame(osg::Transform::ABSOLUTE_RF);compass->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);compass->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);root->addChild(compass); //加入跟节点
0 0
- 指北针设置
- ArcGIS 生成指北针
- 磁场传感器(指北针)
- 指南针为什么不叫指北针
- startUpdatingHeading开发一个指北针
- 出图时加上指北针的代码
- GlobeControl轨道飞行工具和显示指北针
- AE+C#向IPageLayout增加指北针
- Arcgis pagelayout 实现添加图名,比例尺,指北针
- AE c# 添加比例尺和指北针
- AE开发输出地图添加指北针
- 鼠标拖动添加指北针,鼠标拖动的范围为指北针的范围
- ArcGIS Engine自定义工具类,实现添加图名,比例尺,指北针
- [ArcEngine地图制图系列]—添加地图指北针
- Windows下的指北针(指南针)--OpenGL版 Compass
- ArcEngine添加指北针、比例尺、图例(注意UID值)
- 功能实现_实现指北针(UI图片)效果
- 实现在PageLayout控件中添加了图例、指北针或比例
- Python为什么要self
- tjut 3474
- X.utiles框架的使用简介
- Android N 行为变更
- 解决使用BottomSheetDialog时状态栏变黑的问题
- 指北针设置
- Spring MVC自定义错误页面
- .Net语言 APP开发平台——Smobiler学习日志:如何在手机上实现条形图的展示
- html5获取地理位置 利用百度地图JavaScript API标注
- 使用Xcode和Instruments调试解决iOS内存泄露
- 致雅嵌入式工作室——串口属性设置代码
- javascript 设计模式 学习笔记(一)--基础(this)
- 大数据_Kafka_Storm_整合_Could not initialize class org.apache.log4j.Log4
- ubuntu java环境配置及mysql安装