Kstars

supernovanode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "supernovanode.h"
7 
8 #include "ksutils.h"
9 #include "linelist.h"
10 #include "Options.h"
11 #include "supernova.h"
12 #include "nodes/pointnode.h"
13 #include "nodes/polynode.h"
14 
15 #include <QSGFlatColorMaterial>
16 
17 SupernovaNode::SupernovaNode(Supernova *snova) : m_snova(snova)
18 {
19 }
20 
22 {
23  KStarsData *data = KStarsData::Instance();
24  const Projector *m_proj = SkyMapLite::Instance()->projector();
25  if (!m_proj->checkVisibility(m_snova))
26  {
27  hide();
28  return;
29  }
30 
31  bool visible = false;
32  QPointF pos = m_proj->toScreen(m_snova, true, &visible);
33  //qDebug()<<"sup->ra() = "<<(sup->ra()).toHMSString()<<"sup->dec() = "<<sup->dec().toDMSString();
34  //qDebug()<<"pos = "<<pos<<"m_proj->onScreen(pos) = "<<m_proj->onScreen(pos);
35  if (!visible || !m_proj->onScreen(pos))
36  {
37  hide();
38  return;
39  }
40 
41  QColor color = data->colorScheme()->colorNamed("SupernovaColor");
42 
43  //Initialize m_lines if not already done
44  if (!m_lines)
45  {
46  m_lines = new QSGGeometryNode;
48  m_lines->setGeometry(m_geometry);
50 
51  m_material = new QSGFlatColorMaterial;
52  m_lines->setOpaqueMaterial(m_material);
54  addChildNode(m_lines);
55 
56  m_geometry->allocate(4);
57  QSGGeometry::Point2D *vertex = m_geometry->vertexDataAsPoint2D();
58 
59  vertex[0].set(-2.0, 0.0);
60  vertex[1].set(2.0, 0.0);
61  vertex[2].set(0.0, -2.0);
62  vertex[3].set(0.0, 2.0);
63  }
64  show();
65  if (m_material->color() != color)
66  {
67  m_material->setColor(color);
69  }
70 
71  changePos(pos);
72 
73  return;
74 }
75 
77 {
78  //QSizeF size = m_point->size();
79  QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
80  //m.translate(-0.5*size.width(), -0.5*size.height());
81 
82  setMatrix(m);
84 }
void set(float x, float y)
void setGeometry(QSGGeometry *geometry)
void setOpaqueMaterial(QSGMaterial *material)
SupernovaNode(Supernova *snova)
Constructor.
const QColor & color() const const
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
const QSGGeometry::AttributeSet & defaultAttributes_Point2D()
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
ColorScheme * colorScheme()
Definition: kstarsdata.h:172
virtual void changePos(QPointF pos) override
changes the position of SkyNode on SkyMapLite.
bool visible()
Definition: skynode.cpp:44
void setMatrix(const QMatrix4x4 &matrix)
void markDirty(QSGNode::DirtyState bits)
void setColor(const QColor &color)
qreal x() const const
qreal y() const const
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
virtual void show()
shows all child nodes (sets opacity of m_opacity to 1)
Definition: skynode.cpp:27
void allocate(int vertexCount, int indexCount)
QSGGeometry::Point2D * vertexDataAsPoint2D()
virtual void update() override
Update position and visibility of supernova.
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:87
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
void setFlag(QSGNode::Flag f, bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 04:02:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.