Kstars

planetnode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include <QSGSimpleTextureNode>
7 #include <QImage>
8 
9 #include <QQuickWindow>
10 #include "skymaplite.h"
11 #include "ksplanetbase.h"
12 #include "Options.h"
13 #include "projections/projector.h"
14 #include "../rootnode.h"
15 
16 #include "planetnode.h"
17 #include "nodes/pointnode.h"
18 #include "labelnode.h"
19 
21  : SkyNode(pb), m_planetPic(new QSGSimpleTextureNode), m_planetOpacity(new SkyOpacityNode)
22 {
23  // Draw them as bright stars of appropriate color instead of images
24  char spType;
25  //FIXME: do these need i18n?
26  if (pb->name() == i18n("Mars"))
27  {
28  spType = 'K';
29  }
30  else if (pb->name() == i18n("Jupiter") || pb->name() == i18n("Mercury") || pb->name() == i18n("Saturn"))
31  {
32  spType = 'F';
33  }
34  else
35  {
36  spType = 'B';
37  }
38 
39  m_point = new PointNode(parentNode, spType);
40  appendChildNode(m_point);
41  appendChildNode(m_planetOpacity);
42 
43  //Add planet to opacity node so that we could hide the planet
44  m_planetOpacity->appendChildNode(m_planetPic);
45  m_planetPic->setTexture(
46  SkyMapLite::Instance()->window()->createTextureFromImage(pb->image(), QQuickWindow::TextureCanUseAtlas));
47  m_planetPic->setOwnsTexture(true);
48  m_label = parentNode->labelsItem()->addLabel(pb, labelType);
49 }
50 
52 {
53  KSPlanetBase *planet = static_cast<KSPlanetBase *>(skyObject());
54  const Projector *proj = projector();
55 
56  if (!proj->checkVisibility(planet))
57  {
58  hide();
59  return;
60  }
61 
62  bool visible = false;
63  QPointF pos = proj->toScreen(planet, true, &visible);
64 
65  if (!visible || !proj->onScreen(pos))
66  {
67  hide();
68  return;
69  }
70 
71  //Set new position of the label
72  m_label->setLabelPos(pos);
73 
74  float fakeStarSize = (10.0 + log10(Options::zoomFactor()) - log10(MINZOOM)) * (10 - planet->mag()) / 10;
75  if (fakeStarSize > 15.0)
76  fakeStarSize = 15.0;
77 
78  float size = planet->angSize() * dms::PI * Options::zoomFactor() / 10800.0;
79  if (size < fakeStarSize && planet->name() != "Sun" && planet->name() != "Moon")
80  {
81  setPointSize(fakeStarSize);
82  changePos(pos);
83  showPoint();
84  }
85  else
86  {
87  float sizemin = 1.0;
88  if (planet->name() == "Sun" || planet->name() == "Moon")
89  sizemin = 8.0;
90 
91  float size = planet->angSize() * dms::PI * Options::zoomFactor() / 10800.0;
92  if (size < sizemin)
93  size = sizemin;
94  //Options::showPlanetImages() &&
95  if (!planet->image().isNull())
96  {
97  //Because Saturn has rings, we inflate its image size by a factor 2.5
98  if (planet->name() == "Saturn")
99  size = int(2.5 * size);
100  // Scale size exponentially so it is visible at large zooms
101  else if (planet->name() == "Pluto")
102  size = int(size * exp(1.5 * size));
103 
104  setPlanetPicSize(size);
105  showPlanetPic();
106  changePos(pos);
107  }
108  else //Otherwise, draw a simple circle. Do we need it?
109  {
110  //drawEllipse( pos, size, size );
111  }
112  }
113 }
114 
115 void PlanetNode::setPointSize(float size)
116 {
117  m_point->setSize(size);
118 }
119 
121 {
122  m_planetPic->setRect(QRect(0, 0, size, size));
124 }
125 
127 {
128  m_planetOpacity->hide();
129  m_point->show();
130 }
131 
133 {
134  m_planetOpacity->show();
135  m_point->hide();
136 }
137 
139 {
140  m_planetOpacity->hide();
141  m_point->hide();
142  m_label->hide();
143 }
144 
146 {
147  QSizeF size;
148  //Check the bug with planet
149  QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
150 
151  if (m_planetOpacity->visible())
152  {
153  size = m_planetPic->rect().size();
154  //Matrix has to be rotated between assigning x and y and translating it by the half
155  //of size of the planet. Otherwise the image will don't rotate at all or rotate around
156  //the top-left corner
157  m.rotate(projector()->findPA(skyObject(), pos.x(), pos.y()), 0, 0, 1);
158  }
159  else
160  {
161  size = m_point->size();
162  }
163 
164  m.translate(-0.5 * size.width(), -0.5 * size.height());
165 
166  setMatrix(m);
168 }
SkyOpacityNode derived class that represents stars and planets using cached QSGTexture.
Definition: pointnode.h:24
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
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
virtual void show()
makes this node visible
void appendChildNode(QSGNode *node)
void setRect(const QRectF &r)
virtual QString name(void) const
Definition: skyobject.h:145
void showPlanetPic()
hides m_point and shows m_planetPic
Definition: planetnode.cpp:132
float mag() const
Definition: skyobject.h:206
void setPlanetPicSize(float size)
updates the size of m_planetPic
Definition: planetnode.cpp:120
void setPointSize(float size)
updates the size of m_point
Definition: planetnode.cpp:115
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
QString i18n(const char *text, const TYPE &arg...)
const QImage & image() const
Definition: ksplanetbase.h:127
QRectF rect() const const
void setSize(float size)
setSize update size of PointNode with the given parameter
Definition: pointnode.cpp:23
label_t
The label_t enum.
Definition: labelsitem.h:61
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
Definition: planetnode.cpp:138
bool isNull() const const
bool visible()
Definition: skynode.cpp:44
void setOwnsTexture(bool owns)
void setMatrix(const QMatrix4x4 &matrix)
A wrapper for QSGOpacityNode that provides hide() and show() functions. If node is invisible (opacity...
void markDirty(QSGNode::DirtyState bits)
double angSize() const
Definition: ksplanetbase.h:184
SkyObject * skyObject() const
returns SkyObject associated with this SkyNode
Definition: skynode.h:86
qreal x() const const
qreal y() const const
void showPoint()
hides m_planetPic and shows m_point
Definition: planetnode.cpp:126
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
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
Definition: labelnode.cpp:123
PlanetNode(KSPlanetBase *pb, RootNode *parentNode, LabelsItem::label_t labelType=LabelsItem::label_t::PLANET_LABEL)
Constructor.
Definition: planetnode.cpp:20
QSizeF size() const const
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
void setTexture(QSGTexture *texture)
void translate(const QVector3D &vector)
virtual void changePos(QPointF pos) override
changePos changes the position m_point and m_planetPic
Definition: planetnode.cpp:145
virtual void hide()
hides this node
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
Definition: labelsitem.cpp:111
virtual void update() override
Definition: planetnode.cpp:51
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
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 8 2022 04:13:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.