SimsWorld/ComponentBasic/SurfaceMotion.cpp

159 lines
4.9 KiB
C++
Raw Normal View History

2025-06-22 02:05:31 +00:00
#include "SurfaceMotion.h"
2025-06-21 07:56:59 +00:00
2025-06-22 02:05:31 +00:00
SurfaceMotionPlugin::SurfaceMotionPlugin()
2025-06-21 07:56:59 +00:00
{
}
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::recoveryFrom(const QJsonObject& obj)
2025-06-21 07:56:59 +00:00
{
}
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::saveTo(QJsonObject& obj) const
2025-06-21 07:56:59 +00:00
{
}
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::execute(std::shared_ptr<Immediate> map,
2025-06-21 07:56:59 +00:00
std::shared_ptr<const HorizontalArcMotion> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto exec_result = std::make_shared<RespondDefault>();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
if (_current_cmd) {
auto exec = std::make_shared<MotionDeduceRequest>();
exec->reset(in->targetEntity(), in->sourceEntity());
exec->_target_time = _current_cmd->startTimepoint();
map->execute(exec);
}
auto req = std::make_shared<Get3DBox>();
req->reset(this->_bind_entity.lock()->entityID(), this->_bind_entity.lock()->entityID());
auto rst = map->execute<Get3DBox, Box3DDesc>(req);
if (rst.size()) {
// <20><><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD>
this->_current_cmd = in;
// <20><><EFBFBD>»<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
auto item_result = rst.first();
this->_start_lla = item_result->_lla_pos;
this->_start_posture = item_result->_posture_d3;
exec_result->_success_mark = true;
}
else {
exec_result->_reason_text = QString(u8"<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>ʵ<EFBFBD>壨id=%1<><31><EFBFBD><EFBFBD>ȡ%2<><32>Ϣ<EFBFBD><CFA2><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
.arg(this->_bind_entity.lock()->entityID()).arg(Box3DDesc().topicString());
2025-06-21 07:56:59 +00:00
}
out << exec_result;
}
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::execute(std::shared_ptr<Immediate> map,
2025-06-21 07:56:59 +00:00
std::shared_ptr<const StrightLineMotion> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto exec_result = std::make_shared<RespondDefault>();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
if (_current_cmd) {
auto exec = std::make_shared<MotionDeduceRequest>();
exec->reset(in->targetEntity(), in->sourceEntity());
exec->_target_time = _current_cmd->startTimepoint();
map->execute(exec);
}
// <20><>ȡ<EFBFBD><C8A1>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>״̬
auto req = std::make_shared<Get3DBox>();
req->reset(this->_bind_entity.lock()->entityID(), this->_bind_entity.lock()->entityID());
auto rst = map->execute<Get3DBox, Box3DDesc>(req);
if (rst.size()) {
// <20><><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD>
this->_current_cmd = in;
// <20><><EFBFBD>»<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
auto item_result = rst.first();
this->_start_lla = item_result->_lla_pos;
this->_start_posture = item_result->_posture_d3;
exec_result->_success_mark = true;
}
else {
exec_result->_reason_text = QString(u8"<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>ʵ<EFBFBD>壨id=%1<><31><EFBFBD><EFBFBD>ȡ%2<><32>Ϣ<EFBFBD><CFA2><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
.arg(this->_bind_entity.lock()->entityID()).arg(Box3DDesc().topicString());
2025-06-21 07:56:59 +00:00
}
out << exec_result;
}
#include <QMatrix4x4>
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::execute(std::shared_ptr<Immediate> map,
2025-06-21 07:56:59 +00:00
std::shared_ptr<const SyncRequest> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto reqs = std::make_shared<MotionDeduceRequest>();
reqs->reset(in->targetEntity(), in->sourceEntity());
reqs->_target_time = in->_time_current;
for (auto rst : map->execute(reqs)) {
auto conv = std::dynamic_pointer_cast<RespondDefault>(rst);
if (conv) out << conv;
}
}
#include <cmath>
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::execute(std::shared_ptr<Immediate> map,
2025-06-21 07:56:59 +00:00
std::shared_ptr<const MotionDeduceRequest> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto rst = std::make_shared<RespondDefault>();
rst->reset(in->targetEntity(), in->sourceEntity());
if (_current_cmd) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>
2025-06-22 02:34:20 +00:00
auto pos_d3 = _current_cmd->posAtTimeSpan(in->_target_time - _current_cmd->startTimepoint());
auto pos_p3 = _current_cmd->speedAtTimeSpan(in->_target_time - _current_cmd->startTimepoint());
2025-06-21 07:56:59 +00:00
QMatrix4x4 t;
t.rotate(-_start_posture._azimuth_deg, QVector3D(0, 0, 1));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>
auto conv_pos = pos_d3 * t;
auto conv_psr = pos_p3 * t;
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>
auto azimuth_target_cos = QVector3D::dotProduct(conv_pos.normalized(), QVector3D(0, 1, 0));
auto azimuth_target = rad2d(std::acos(azimuth_target_cos));
if (QVector3D::crossProduct(conv_pos.normalized(), QVector3D(0, 1, 0)).z() < 0)
azimuth_target = 360 - azimuth_target;
LonLatAlt deduce_lla;
StandardGlobe::getLLAWithDistance(_start_lla, conv_pos.length(), azimuth_target, deduce_lla);
2025-06-21 07:56:59 +00:00
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>λ<EFBFBD><CEBB>
auto azimuth_self_cos = QVector3D::dotProduct(conv_psr.normalized(), QVector3D(0, 1, 0));
auto azimuth_self = rad2d(std::acos(azimuth_self_cos));
if (QVector3D::crossProduct(conv_psr.normalized(), QVector3D(0, 1, 0)).z() < 0)
azimuth_self = 360 - azimuth_self;
auto setpos = std::make_shared<Set3DBoxLLAPos>();
setpos->_lla_pos = deduce_lla;
map->execute(setpos);
auto setpsr = std::make_shared<Set3DBoxPosture>();
setpsr->_posture_d3._azimuth_deg = azimuth_self;
map->execute(setpsr);
rst->_success_mark = true;
}
else {
rst->_reason_text = QString("ʵ<EFBFBD><EFBFBD>%1δ<31><CEB4><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>Ӧ<EFBFBD><D3A6>%2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>")
.arg(this->_bind_entity.lock()->entityID()).arg(in->topicString());
}
out << rst;
}
2025-06-22 02:05:31 +00:00
std::shared_ptr<WsComponent> SurfaceMotionPlugin::defaultNew() const
2025-06-21 07:56:59 +00:00
{
2025-06-22 02:05:31 +00:00
return std::make_shared<SurfaceMotionPlugin>();
2025-06-21 07:56:59 +00:00
}
2025-06-22 02:05:31 +00:00
void SurfaceMotionPlugin::bindEntity(std::weak_ptr<WsEntity> host)
2025-06-21 07:56:59 +00:00
{
this->_bind_entity = host;
}
2025-06-22 02:05:31 +00:00
QString SurfaceMotionPlugin::name() const
2025-06-21 07:56:59 +00:00
{
2025-06-22 02:05:31 +00:00
return NAME(SurfaceMotionPlugin);
2025-06-21 07:56:59 +00:00
}