Kstars

supernovanode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
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
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}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
ColorScheme * colorScheme()
Definition kstarsdata.h:174
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
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
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition projector.cpp:98
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
virtual void show()
shows all child nodes (sets opacity of m_opacity to 1)
Definition skynode.cpp:27
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 void changePos(QPointF pos) override
changes the position of SkyNode on SkyMapLite.
SupernovaNode(Supernova *snova)
Constructor.
virtual void update() override
Update position and visibility of supernova.
Represents the supernova object.
Definition supernova.h:34
qreal x() const const
qreal y() const const
void setGeometry(QSGGeometry *geometry)
const QColor & color() const const
void setColor(const QColor &color)
void set(float x, float y)
void allocate(int vertexCount, int indexCount)
const AttributeSet & defaultAttributes_Point2D()
Point2D * vertexDataAsPoint2D()
void setOpaqueMaterial(QSGMaterial *material)
void markDirty(DirtyState bits)
void setFlag(Flag f, bool enabled)
void setMatrix(const QMatrix4x4 &matrix)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:53:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.