From be97c3231b5f6939cc9341b2e2b7481dcc9c51ed Mon Sep 17 00:00:00 2001 From: jiegeaiai Date: Sun, 29 Dec 2024 10:23:08 +0800 Subject: [PATCH] modify use oe to render --- Source/src/CMakeLists.txt | 2 +- Source/src/scene/OEScene.cpp | 25 +++++--------------- Source/src/translations/Dyt_zh_CN.ts | 4 ++-- Source/src/viewer/OsgView.cpp | 14 ++++++++---- Source/src/viewer/QtOsgViewWidget.cpp | 33 ++++++++++++++++----------- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Source/src/CMakeLists.txt b/Source/src/CMakeLists.txt index 8ef28ef7..bdb289de 100644 --- a/Source/src/CMakeLists.txt +++ b/Source/src/CMakeLists.txt @@ -185,7 +185,7 @@ endif() SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ProjectDIR}/bin) TARGET_LINK_LIBRARIES(${PROJECT_NAME}) -#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE") add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD diff --git a/Source/src/scene/OEScene.cpp b/Source/src/scene/OEScene.cpp index 0adf2df9..053e7b49 100644 --- a/Source/src/scene/OEScene.cpp +++ b/Source/src/scene/OEScene.cpp @@ -24,9 +24,6 @@ OEScene::OEScene() { const std::string& basePath = RecourceHelper::Get().GetBasePath().toStdString(); pathList.push_back(basePath + "/resources/earth/"); pathList.push_back(basePath + "/resources/textures/"); - - - logarithmicDepthBuffer_ = std::make_unique(); } @@ -36,7 +33,7 @@ void OEScene::InitEventHandle(class OsgView* view) { return; } - view->GetView()->addEventHandler(new osgEarth::Util::EarthManipulator()); + //view->GetView()->addEventHandler(new osgEarth::Util::EarthManipulator()); view->GetView()->addEventHandler(new osgViewer::HelpHandler); } @@ -47,21 +44,12 @@ void OEScene::AttachView(OsgView* view) { return; } - //osg::Node* node1 = osgDB::readNodeFile("chaff_bombs.osg"); - //node1->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - //osg::MatrixTransform* mt = new osg::MatrixTransform; - //mt->addChild(node1); - ////GetOceanScene()->addChild(mt); - //entityRoot_->addChild(mt); - //osg::Vec3 eye(0.0f, 60.f, 50.0f); - //mt->setMatrix(osg::Matrix::translate(eye)/* * osg::Matrix::scale(osg::Vec3(10, 10, 10))*/); - //////mt->getOrCreateStateSet()- - earthRootNode_ = osgDB::readNodeFile("triton.earth"); if (!earthRootNode_) { LOG_ERROR("read earth node(triton.earth) failed"); return; } + logarithmicDepthBuffer_ = std::make_unique(); earthMapNode_ = osgEarth::MapNode::get(earthRootNode_); LOG_INFO("earth map node get success: {}", earthMapNode_.valid()); @@ -83,7 +71,7 @@ void OEScene::AttachView(OsgView* view) { osg::Node* node = view->GetView()->getSceneData(); if (nullptr == node) { LOG_INFO("view scene data is nullptr, root valid:{}", skyDome_.valid()); - view->GetView()->setSceneData(earthRootNode_); + view->GetView()->setSceneData(skyDome_); } else { osg::Group* group = node->asGroup(); if (nullptr != group) { @@ -104,19 +92,18 @@ void OEScene::AttachView(OsgView* view) { }*/ - /* skyDome_->attach(view->GetView()); + skyDome_->attach(view->GetView()); skyDome_->setAtmosphereVisible(true); skyDome_->setSunVisible(true); skyDome_->setMoonVisible(true); skyDome_->setStarsVisible(true); - skyDome_->setDateTime(osgEarth::DateTime(2024, 12, 24, 12)); - skyDome_->setSimulationTimeTracksDateTime(true);*/ + skyDome_->setDateTime(osgEarth::DateTime(2024, 12, 24, 3)); + skyDome_->setSimulationTimeTracksDateTime(true); logarithmicDepthBuffer_->install(view->GetView()->getCamera()); - //view->GetView()->setRealizeOperation(new osgEarth::GL3RealizeOperation()); } void OEScene::DetachView(OsgView* view) { diff --git a/Source/src/translations/Dyt_zh_CN.ts b/Source/src/translations/Dyt_zh_CN.ts index 660188d9..b6629a69 100644 --- a/Source/src/translations/Dyt_zh_CN.ts +++ b/Source/src/translations/Dyt_zh_CN.ts @@ -1054,12 +1054,12 @@ QtOsgViewWidget - + notify - + open dyt file failed diff --git a/Source/src/viewer/OsgView.cpp b/Source/src/viewer/OsgView.cpp index 4b2e146b..1d82914c 100644 --- a/Source/src/viewer/OsgView.cpp +++ b/Source/src/viewer/OsgView.cpp @@ -58,8 +58,10 @@ void OsgView::InitGraphiceWindow(int x, int y, int width, int height, #endif graphiceWindow_ = osg::GraphicsContext::createGraphicsContext(traits); - graphiceWindow_->getState()->setUseModelViewAndProjectionUniforms(true); - graphiceWindow_->getState()->setUseVertexAttributeAliasing(true); +#if USE_OCEAN + graphiceWindow_->getState()->setUseModelViewAndProjectionUniforms(false); + graphiceWindow_->getState()->setUseVertexAttributeAliasing(false); +#endif } void OsgView::InitView(osgViewer::View* pView) { @@ -70,11 +72,13 @@ void OsgView::InitView(osgViewer::View* pView) { pCamera->setGraphicsContext(graphiceWindow_); const osg::GraphicsContext::Traits* traits = graphiceWindow_->getTraits(); pCamera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); +#if USE_OCEAN pCamera->setProjectionMatrixAsPerspective(45.0, static_cast(traits->width) / static_cast(traits->height), 0.1, 1000.0); pCamera->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); +#endif view_ = pView; } @@ -94,9 +98,11 @@ void OsgView::Resize(int x, int y, int width, int height) { } osg::Camera* pCamera = view_->getCamera(); pCamera->setViewport(new osg::Viewport(x, y, width, height)); +#if USE_OCEAN pCamera->setProjectionMatrixAsPerspective(45.0, static_cast(width) / static_cast(height), 0.1, 1000.0); +#endif view_->requiresRedraw(); } @@ -150,8 +156,8 @@ void OsgView::Initialize(OsgCameraManipulator* cameraManipulator) { SetCameraManipulator(cameraManipulator); } - view_->addEventHandler(new osgViewer::StatsHandler); - view_->addEventHandler(new osgGA::StateSetManipulator(view_->getCamera()->getOrCreateStateSet())); + //view_->addEventHandler(new osgViewer::StatsHandler); + //view_->addEventHandler(new osgGA::StateSetManipulator(view_->getCamera()->getOrCreateStateSet())); initialized_ = true; } diff --git a/Source/src/viewer/QtOsgViewWidget.cpp b/Source/src/viewer/QtOsgViewWidget.cpp index f6bc22c2..c0336b7d 100644 --- a/Source/src/viewer/QtOsgViewWidget.cpp +++ b/Source/src/viewer/QtOsgViewWidget.cpp @@ -12,6 +12,9 @@ #include #include +#include +#include + #include "app/Application.h" #include "common/SpdLogger.h" #include "viewer/OsgView.h" @@ -66,20 +69,24 @@ void QtOsgViewWidget::Initialize(void) { setMouseTracking(true); - //OsgSceneManipulator* manipulator = new OsgSceneManipulator; - CameraControlManipulator* manipulator = new CameraControlManipulator; - //osg::Vec3f eye(-256.63, 48.57, 82.19); - //osg::Vec3f center(-164.45, 30.05, 48.14); - //osg::Vec3f up(0.33, -0.07, 0.94); + ////OsgSceneManipulator* manipulator = new OsgSceneManipulator; + //CameraControlManipulator* manipulator = new CameraControlManipulator; + ////osg::Vec3f eye(-256.63, 48.57, 82.19); + ////osg::Vec3f center(-164.45, 30.05, 48.14); + ////osg::Vec3f up(0.33, -0.07, 0.94); - osg::Vec3 eye(0.0f, 300.f, 60.0f); - osg::Vec3 center(0.0f, 60.0f, 0.0f); - osg::Vec3 up(0.0f, 0.0f, 1.0f); - manipulator->setHomePosition(eye, center, up); - manipulator->setManipulatorMode(CameraControlManipulator::Roam_ManipulatorMode); - manipulator->setVerticalAxisFixed(true); - manipulator->setRoamCamera(eye, center, up); - manipulator->setDistance(650.0); + //osg::Vec3 eye(0.0f, 300.f, 60.0f); + //osg::Vec3 center(0.0f, 60.0f, 0.0f); + //osg::Vec3 up(0.0f, 0.0f, 1.0f); + //manipulator->setHomePosition(eye, center, up); + //manipulator->setManipulatorMode(CameraControlManipulator::Roam_ManipulatorMode); + //manipulator->setVerticalAxisFixed(true); + //manipulator->setRoamCamera(eye, center, up); + //manipulator->setDistance(650.0); + + osgEarth::Util::EarthManipulator* manipulator = new osgEarth::Util::EarthManipulator; + osgEarth::Viewpoint vp("home", 107.85, 32.35, 100.0, -2.50, -90.0, 1.5e7); + manipulator->setHomeViewpoint(vp, 3.0); OsgCameraManipulator* cameraManipulator = new OsgCameraManipulator(manipulator, this);