修改跟踪和位置初始位置

This commit is contained in:
brige 2025-06-18 02:05:47 +08:00
parent 4acbf05ae0
commit a3fc986d4e
6 changed files with 83 additions and 45 deletions

View File

@ -48,8 +48,6 @@ void OEScene::AttachView(osgViewer::View* view) {
skyDome_->getSunLight()->setAmbient(osg::Vec4(0.5,0.5,0.5,1.0));
addChild(skyDome_);
view->setCameraManipulator( new osgEarth::Util::EarthManipulator() );
skyDome_->setDateTime(osgEarth::DateTime(2024, 12, 24, 3));
view->setSceneData(this);
@ -68,33 +66,18 @@ bool OEScene::AddToScene(osg::Node* node) const {
void OEScene::SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint, double duration_s) {
dyt_check(nullptr != earthManipulator_);
earthManipulator_->setViewpoint(viewpoint, duration_s);
earthManipulator_->setHomeViewpoint(viewpoint, duration_s);
//earthManipulator_->setHomeViewpoint(viewpoint, duration_s);
}
//
// void OEScene::InitEventHandle(osgViewer::View* view) {
// if (nullptr == view) {
// LOG_WARN("view is nullptr");
// return;
// }
//
// //view->GetView()->addEventHandler(new osgEarth::Util::EarthManipulator());
//
// view->addEventHandler(new osgViewer::HelpHandler);
// view->addEventHandler(new osgViewer::StatsHandler);
// }
// void OEScene::DetachView(osgViewer::View* view) {
// if (nullptr != earthRootNode_) {
// std::vector<osg::Group*> parents = earthRootNode_->getParents();
// for (const auto& parent : parents) {
// parent->removeChild(earthRootNode_);
// }
// }
// logarithmicDepthBuffer_->uninstall(view->getCamera());
// view->setSceneData(nullptr);
//
// }
bool OEScene::TrackEntity(osg::Node* entity, bool track) const {
dyt_check(nullptr != earthManipulator_);
if (track) {
earthManipulator_->setTetherNode(entity, 5.0);
} else {
earthManipulator_->clearViewpoint();
}
return true;
}
OESceneUI* OEScene::GetOrCreateSceneUI() {
if (sceneUI_) {
@ -130,6 +113,8 @@ void OEScene::Init() {
g_srs_ = earthMapNode_->getMapSRS();
earthManipulator_ = new osgEarth::Util::EarthManipulator();
earthManipulator_->getSettings()->setMinMaxPitch(-90.0, -10.0);
entityRoot_ = new osg::Group;
addChild(entityRoot_);

View File

@ -23,6 +23,7 @@ public:
bool AddToScene(osg::Node* node) const;
void SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint, double duration_s);
bool TrackEntity(osg::Node* entity, bool track) const;
osgEarth::MapNode* GetMapNode(void) const {
dyt_check(earthMapNode_.valid());

View File

@ -636,57 +636,57 @@
<context>
<name>ModelTreeWidget</name>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="96"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="97"/>
<source>Release Track</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="112"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="113"/>
<source>Add boke Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="119"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="120"/>
<source>Add lsjhqt Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="126"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="127"/>
<source>Add nimizi Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="133"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="134"/>
<source>Add tkdlj Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="140"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="141"/>
<source>Add jiaofan Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="147"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="148"/>
<source>Add satellite Entity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="249"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="250"/>
<source>Track</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="256"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="257"/>
<source>Add Mesh Component</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="259"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="260"/>
<source>Add Path Component</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="266"/>
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="267"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>

View File

@ -16,6 +16,7 @@
#include "viewer/OsgCameraManipulator.h"
#include "viewer/CameraControlManipulator.h"
#include "ui/ModelBrowser/EntityConstent.h"
#include "workspace/WorkSpaceManager.h"
ModelTreeWidget::ModelTreeWidget(QWidget* parent)
@ -91,7 +92,7 @@ void ModelTreeWidget::OnEntityRemoved(Entity* entity) {
void ModelTreeWidget::contextMenuEvent(QContextMenuEvent* event) {
QTreeWidgetItem* item = itemAt(event->pos());
if (nullptr == item) {
if (nullptr != item) {
QMenu menu(this);
QAction* addEntiy = new QAction(tr("Release Track"), this);
connect(addEntiy, &QAction::triggered, [this]() {
@ -320,6 +321,21 @@ void ModelTreeWidget::OnAddSatelliteEntity() {
}
void ModelTreeWidget::OnTrackEntity(Entity* entity) {
auto workspace = WorkSpaceManager::Get().GetCurrent();
if (!workspace){
LOG_WARN("scene is nullptr");
return;
}
if (nullptr == entity) {
LOG_WARN("entity is nullptr, clear camera manipulator");
return;
}
workspace->TrackEntity(entity);
//scene->Track
//MainWindow::
//OsgCameraManipulator* manipulator = OsgViewer::Get().GetView()->GetCameraManipulator();
//if (nullptr == manipulator) {
// LOG_WARN("manipulator is nullptr");

View File

@ -59,16 +59,48 @@ void WorkSpace::RemoveEntity(Entity* entity) {
}
}
bool WorkSpace::TrackEntity(Entity* entity) {
dyt_check(nullptr != entity);
if (trackedEntity_ == entity) {
LOG_INFO("entity already tracked: {}", entity->GetName().toStdString());
return true;
}
if (nullptr == scene_) {
LOG_WARN("scene is nullptr, cannot track entity: {}", entity->GetName().toStdString());
return false;
}
if (trackedEntity_ != entity) {
UntrackEntity();
}
trackedEntity_ = entity;
auto mt = entity->GetRootComponent()->GetMatrixTransform();
LOG_INFO("track entity: {}", entity->GetName().toStdString());
return scene_->TrackEntity(mt, true);
}
void WorkSpace::UntrackEntity() {
if (trackedEntity_ != nullptr) {
if (scene_ != nullptr) {
LOG_INFO("untrack entity: {}", trackedEntity_->GetName().toStdString());
auto mt = trackedEntity_->GetRootComponent()->GetMatrixTransform();
scene_->TrackEntity(mt, false);
}
}
trackedEntity_ = nullptr;
}
void WorkSpace::SetActiveScene(OEScene* scene) {
dyt_check(nullptr != scene);
scene_ = scene;
osgEarth::Viewpoint vp;
vp.name() = "home";
vp.focalPoint()->set(scene->GetSrs(), -121.488, 46.2054, 0, osgEarth::AltitudeMode::ALTMODE_ABSOLUTE);
vp.pitch() = -50.0;
vp.range() = 100000;
homeViewpoint_ = vp;
//osgEarth::Viewpoint vp;
//vp.name() = "home";
//vp.focalPoint()->set(scene->GetSrs(), -121.488, 46.2054, 0, osgEarth::AltitudeMode::ALTMODE_ABSOLUTE);
//vp.pitch() = -50.0;
//vp.range() = 100000;
//homeViewpoint_ = vp;
}
bool WorkSpace::SetTimestep(Timestep* timestep) {

View File

@ -83,6 +83,7 @@ public:
inline void SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint) {
homeViewpoint_ = viewpoint;
homeViewpoint_.setHeading(0.0); // Ensure heading is set to 0.0
}
inline const osgEarth::Viewpoint& GetHomeViewpoint() const {
return homeViewpoint_;
@ -115,6 +116,8 @@ public:
void AddEntity(class Entity* entity);
void RemoveEntity(class Entity* entity);
bool TrackEntity(class Entity* entity);
void UntrackEntity();
bool Save(const QString& path);
bool Save();
@ -153,5 +156,6 @@ private:
OEScene* scene_{ nullptr };
class Timestep* timestep_{ nullptr };
class LampStatus* lampStatus_{ nullptr };
class Entity* trackedEntity_{ nullptr };
};