Kstars

constellationartnode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 #include "skyobject.h"
6 #include "Options.h"
7 
8 #include <QQuickWindow>
9 #include <QSGSimpleTextureNode>
10 
11 #include "constellationartnode.h"
12 #include "constellationsart.h"
13 #include "nodes/pointnode.h"
14 
15 #include "../rootnode.h"
16 #include "../labelsitem.h"
17 #include "labelnode.h"
18 
20  : SkyNode(obj), m_art(obj), m_texture(new QSGSimpleTextureNode)
21 {
22  m_texture->setTexture(
23  SkyMapLite::Instance()->window()->createTextureFromImage(m_art->image(), QQuickWindow::TextureCanUseAtlas));
24  m_texture->setFiltering(QSGTexture::Linear);
25  m_opacity->appendChildNode(m_texture);
26  update();
27 }
28 
30 {
31  double zoom = Options::zoomFactor();
32 
33  const Projector *m_proj = SkyMapLite::Instance()->projector();
34  if (!m_proj->checkVisibility(m_art))
35  {
36  hide();
37  return;
38  }
39 
40  bool visible = false;
41  m_art->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
42  QPointF constellationmidpoint = m_proj->toScreen(m_art, true, &visible);
43 
44  if (!visible || !m_proj->onScreen(constellationmidpoint))
45  {
46  hide();
47  return;
48  }
49 
50  m_opacity->setOpacity(0.7);
51 
52  //qDebug() << "o->pa() " << obj->pa();
53  float positionangle = m_proj->findPA(m_art, constellationmidpoint.x(), constellationmidpoint.y());
54  //qDebug() << " final PA " << positionangle;
55 
56  float w = m_art->getWidth() * 60 * dms::PI * zoom / 10800;
57  float h = m_art->getHeight() * 60 * dms::PI * zoom / 10800;
58 
59  m_texture->setRect(0, 0, w, h);
60 
61  changePos(constellationmidpoint, positionangle);
62 }
63 
64 void ConstellationArtNode::changePos(QPointF pos, double positionangle)
65 {
66  QSizeF size = m_texture->rect().size();
67  QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
68  m.rotate(positionangle, 0, 0, 1);
69  m.translate(-0.5 * size.width(), -0.5 * size.height());
70 
71  setMatrix(m);
73 }
74 
76 {
77  //m_point->hide();
78  SkyNode::hide();
79 }
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
Definition: dms.h:380
qreal height() const const
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
double findPA(const SkyObject *o, float x, float y) const
Determine the on-screen position angle of a SkyObject.
Definition: projector.cpp:265
void changePos(QPointF pos, double positionangle)
changePos change the position of this node
void appendChildNode(QSGNode *node)
void setRect(const QRectF &r)
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition: skypoint.cpp:77
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
virtual void update() override
Updates coordinate of the object on SkyMapLite.
void setOpacity(qreal opacity)
QRectF rect() const const
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
bool visible()
Definition: skynode.cpp:44
void setMatrix(const QMatrix4x4 &matrix)
void markDirty(QSGNode::DirtyState bits)
const QImage & image()
qreal x() const const
qreal y() const const
void rotate(float angle, const QVector3D &vector)
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition: projector.cpp:93
QSizeF size() const const
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
ConstellationArtNode(ConstellationsArt *obj)
Constructor.
void setTexture(QSGTexture *texture)
void translate(const QVector3D &vector)
Information about a ConstellationsArt object. This class represents a constellation image.
void setFiltering(QSGTexture::Filtering filtering)
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:183
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.