File indexing completed on 2024-04-28 03:44:24

0001 /*
0002     SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #include "skyobject.h"
0006 #include "Options.h"
0007 
0008 #include <QQuickWindow>
0009 #include <QSGSimpleTextureNode>
0010 
0011 #include "constellationartnode.h"
0012 #include "constellationsart.h"
0013 #include "nodes/pointnode.h"
0014 
0015 #include "../rootnode.h"
0016 #include "../labelsitem.h"
0017 #include "labelnode.h"
0018 
0019 ConstellationArtNode::ConstellationArtNode(ConstellationsArt *obj)
0020     : SkyNode(obj), m_art(obj), m_texture(new QSGSimpleTextureNode)
0021 {
0022     m_texture->setTexture(
0023         SkyMapLite::Instance()->window()->createTextureFromImage(m_art->image(), QQuickWindow::TextureCanUseAtlas));
0024     m_texture->setFiltering(QSGTexture::Linear);
0025     m_opacity->appendChildNode(m_texture);
0026     update();
0027 }
0028 
0029 void ConstellationArtNode::update()
0030 {
0031     double zoom = Options::zoomFactor();
0032 
0033     const Projector *m_proj = SkyMapLite::Instance()->projector();
0034     if (!m_proj->checkVisibility(m_art))
0035     {
0036         hide();
0037         return;
0038     }
0039 
0040     bool visible = false;
0041     m_art->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
0042     QPointF constellationmidpoint = m_proj->toScreen(m_art, true, &visible);
0043 
0044     if (!visible || !m_proj->onScreen(constellationmidpoint))
0045     {
0046         hide();
0047         return;
0048     }
0049 
0050     m_opacity->setOpacity(0.7);
0051 
0052     //qDebug() << "o->pa() " << obj->pa();
0053     float positionangle = m_proj->findPA(m_art, constellationmidpoint.x(), constellationmidpoint.y());
0054     //qDebug() << " final PA " << positionangle;
0055 
0056     float w = m_art->getWidth() * 60 * dms::PI * zoom / 10800;
0057     float h = m_art->getHeight() * 60 * dms::PI * zoom / 10800;
0058 
0059     m_texture->setRect(0, 0, w, h);
0060 
0061     changePos(constellationmidpoint, positionangle);
0062 }
0063 
0064 void ConstellationArtNode::changePos(QPointF pos, double positionangle)
0065 {
0066     QSizeF size = m_texture->rect().size();
0067     QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
0068     m.rotate(positionangle, 0, 0, 1);
0069     m.translate(-0.5 * size.width(), -0.5 * size.height());
0070 
0071     setMatrix(m);
0072     markDirty(QSGNode::DirtyMatrix);
0073 }
0074 
0075 void ConstellationArtNode::hide()
0076 {
0077     //m_point->hide();
0078     SkyNode::hide();
0079 }