Kstars

planetnode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
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 {
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);
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
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}
A subclass of TrailObject that provides additional information needed for most solar system objects.
const QImage & image() const
double angSize() const
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
label_t
The label_t enum.
Definition labelsitem.h:62
void showPlanetPic()
hides m_point and shows m_planetPic
void setPlanetPicSize(float size)
updates the size of m_planetPic
virtual void changePos(QPointF pos) override
changePos changes the position m_point and m_planetPic
void setPointSize(float size)
updates the size of m_point
void showPoint()
hides m_planetPic and shows m_point
virtual void update() override
PlanetNode(KSPlanetBase *pb, RootNode *parentNode, LabelsItem::label_t labelType=LabelsItem::label_t::PLANET_LABEL)
Constructor.
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
SkyOpacityNode derived class that represents stars and planets using cached QSGTexture.
Definition pointnode.h:25
void setSize(float size)
setSize update size of PointNode with the given parameter
Definition pointnode.cpp:23
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
Provides virtual functions for update of coordinates and nodes hiding.
Definition skynode.h:28
SkyObject * skyObject() const
returns SkyObject associated with this SkyNode
Definition skynode.h:86
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition skynode.cpp:21
bool visible()
Definition skynode.cpp:44
virtual QString name(void) const
Definition skyobject.h:145
float mag() const
Definition skyobject.h:206
A wrapper for QSGOpacityNode that provides hide() and show() functions.
virtual void show()
makes this node visible
virtual void hide()
hides this node
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:385
QString i18n(const char *text, const TYPE &arg...)
qreal x() const const
qreal y() const const
QSizeF size() const const
void appendChildNode(QSGNode *node)
void markDirty(DirtyState bits)
QRectF rect() const const
void setOwnsTexture(bool owns)
void setRect(const QRectF &r)
void setTexture(QSGTexture *texture)
void setMatrix(const QMatrix4x4 &matrix)
qreal height() const const
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.