osg::NotifyHandler

本文介绍了一种解决MFC程序中osg调试信息无法正常显示的问题的方法。通过定义一个自定义通知处理器类MyNotifyHandler并设置调试级别,使得调试信息能够被正确地输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MFC程序 osg的调试信息 OSG_INFO等打印不出,可以按如下:

class MyNotifyHandler : public osg::NotifyHandler
{
public:
void notify(osg::NotifySeverity severity, const char *message)
{
TRACE( “\n MyNotifyHandler) ” message);
}
};

osg::setNotifyHandler(new MyNotifyHandler);
osg::setNotifyLevel(osg::NOTICE);
#include "OsgEarthWidget.h" #include <osgEarth/MapNode> #include <osgEarth/EarthManipulator> #include <osgEarth/ImageLayer> #include <osgEarth/GDAL> #include <osgEarth/GeoTransform> #include <osgViewer/Viewer> #include <osgDB/ReadFile> #include <osg/MatrixTransform> #include <osgEarth/Map> #include <osg/GraphicsContext> #include <osg/Material> void OsgEarthWidget::initializeGL() { if (!isValid()) { qWarning() << "OpenGL 上下文未正确初始化!"; return; } // 确保 OpenGL 上下文有效 makeCurrent(); // 初始化 osgEarth osgEarth::initialize(); // 创建地图和 MapNode osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(); osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map); // 添加 TMS 图层 auto imagery = new osgEarth::GDALImageLayer(); imagery->setName("MyGeoTiff"); imagery->setURL("D:\\Map\\tif\\map3.tif"); mapNode->getMap()->addLayer(imagery); // 创建根节点组 osg::ref_ptr<osg::Group> root = new osg::Group(); root->addChild(mapNode); // 加载 .ive 模型 osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("D:\\Source\\moxing\\IVE\\feiji\\F-16.ive"); if (model) { // 创建红色材质使模型更醒目 osg::ref_ptr<osg::Material> mat = new osg::Material(); mat->setDiffuse(osg::Material::FRONT, osg::Vec4(1.0, 0.0, 0.0, 1.0)); model->getOrCreateStateSet()->setAttributeAndModes(mat); // 放大模型(XYZ 轴各放大 50 倍) osg::ref_ptr<osg::MatrixTransform> scaleTransform = new osg::MatrixTransform(); scaleTransform->setMatrix(osg::Matrix::scale(90000.0, 90000.0, 90000.0)); scaleTransform->addChild(model); // 设置模型地理坐标 osgEarth::GeoTransform* geoTransform = new osgEarth::GeoTransform(); geoTransform->setPosition( osgEarth::GeoPoint( osgEarth::SpatialReference::get("wgs84"), 116.39, // 经度 39.9, // 纬度 100000.0 // 海拔高度(米) ) ); geoTransform->addChild(scaleTransform); root->addChild(geoTransform); } else { osg::notify(osg::WARN) << "无法加载 .ive 模型文件" << std::endl; } // 配置 Viewer _viewer->setSceneData(root); // 创建并设置 EarthManipulator osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator(); _viewer->setCameraManipulator(manip); // 设置初始视点(观察地球中心) osgEarth::Viewpoint viewpoint; viewpoint.setFocalPoint(osgEarth::GeoPoint( osgEarth::SpatialReference::get("earth"), // 使用 ECEF 坐标系 0.0, 0.0, 0.0 // 地球中心坐标为 (0,0,0) )); viewpoint.setRange(osgEarth::Distance(30000000.0, osgEarth::Units::METERS)); // 视距足够远 viewpoint.setPitch(osgEarth::Angle(-30.0, osgEarth::Units::DEGREES)); // 俯仰角 manip->setViewpoint(viewpoint, 3.0); // 平滑过渡 // 调整操作器设置 osgEarth::Util::EarthManipulator::Settings* settings = manip->getSettings(); settings->setArcViewpointTransitions(true); // 平滑过渡 settings->setSingleAxisRotation(false); // 允许多轴旋转(关键!) settings->setThrowingEnabled(false); // 禁用惯性滑动 // 优化渲染上下文 osg::ref_ptr<osg::GraphicsContext> gc = _viewer->getCamera()->getGraphicsContext(); if (gc) { gc->getState()->setUseModelViewAndProjectionUniforms(true); gc->getState()->setUseVertexAttributeAliasing(true); } // 完成初始化 _viewer->realize(); osg::notify(osg::INFO) << "场景初始化完成,地球绕球心旋转" << std::endl; }我的是基于VS的Qt工程,要怎么改才能点击飞机出现一个新的Qt界面
最新发布
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值