10#include "skyglpainter.h"
13#include <Eigen/Geometry>
19#include "kstarsdata.h"
22#include "texturemanager.h"
24#include "skycomponents/linelist.h"
25#include "skycomponents/skiphashlist.h"
26#include "skycomponents/linelistlabel.h"
27#include "skycomponents/skymapcomposite.h"
28#include "skycomponents/flagcomponent.h"
29#include "skycomponents/satellitescomponent.h"
30#include "skycomponents/supernovaecomponent.h"
31#include "skycomponents/constellationartcomponent.h"
32#include "skyobjects/kscomet.h"
33#include "skyobjects/ksasteroid.h"
34#include "skyobjects/trailobject.h"
35#include "skyobjects/satellite.h"
36#include "skyobjects/supernova.h"
37#include "skyobjects/constellationsart.h"
39Eigen::Vector2f SkyGLPainter::m_vertex[NUMTYPES][6 * BUFSIZE];
40Eigen::Vector2f SkyGLPainter::m_texcoord[NUMTYPES][6 * BUFSIZE];
41Eigen::Vector3f SkyGLPainter::m_color[NUMTYPES][6 * BUFSIZE];
42int SkyGLPainter::m_idx[NUMTYPES];
43bool SkyGLPainter::m_init =
false;
45SkyGLPainter::SkyGLPainter(QGLWidget *widget) :
SkyPainter()
50 qDebug() <<
"Initializing texcoord arrays...\n";
51 for (
int i = 0; i < NUMTYPES; ++i)
54 for (
int j = 0;
j < BUFSIZE; ++
j)
56 m_texcoord[i][6 *
j + 0] = Eigen::Vector2f(0, 0);
57 m_texcoord[i][6 *
j + 1] = Eigen::Vector2f(1, 0);
58 m_texcoord[i][6 *
j + 2] = Eigen::Vector2f(0, 1);
59 m_texcoord[i][6 *
j + 3] = Eigen::Vector2f(0, 1);
60 m_texcoord[i][6 *
j + 4] = Eigen::Vector2f(1, 0);
61 m_texcoord[i][6 *
j + 5] = Eigen::Vector2f(1, 1);
69void SkyGLPainter::drawBuffer(
int type)
72 if (type > SkyObject::TYPE_UNKNOWN)
73 type = SkyObject::TYPE_UNKNOWN;
84 TextureManager::bindTexture(
"open-cluster", m_widget);
87 TextureManager::bindTexture(
"globular-cluster", m_widget);
90 TextureManager::bindTexture(
"planetary-nebula", m_widget);
95 TextureManager::bindTexture(
"gaseous-nebula", m_widget);
99 TextureManager::bindTexture(
"galaxy", m_widget);
102 TextureManager::bindTexture(
"galaxy-cluster", m_widget);
107 TextureManager::bindTexture(
"star", m_widget);
122 glDrawArrays(GL_TRIANGLES, 0, 6 * m_idx[type]);
130bool SkyGLPainter::addItem(
SkyPoint *p,
int type,
float width,
char sp)
132 bool visible =
false;
133 Eigen::Vector2f
vec = m_proj->toScreenVec(p,
true, &visible);
138 if (type > SkyObject::TYPE_UNKNOWN)
139 type = SkyObject::TYPE_UNKNOWN;
142 if (m_idx[type] == BUFSIZE)
147 int i = 6 * m_idx[
type];
148 float w = width / 2.;
150 m_vertex[
type][i + 0] =
vec + Eigen::Vector2f(-w, -w);
151 m_vertex[
type][i + 1] =
vec + Eigen::Vector2f(w, -w);
152 m_vertex[
type][i + 2] =
vec + Eigen::Vector2f(-w, w);
153 m_vertex[
type][i + 3] =
vec + Eigen::Vector2f(-w, w);
154 m_vertex[
type][i + 4] =
vec + Eigen::Vector2f(w, -w);
155 m_vertex[
type][i + 5] =
vec + Eigen::Vector2f(w, w);
157 Eigen::Vector3f c(1., 1., 1.);
158 if (sp !=
'x' && Options::starColorMode() != 0)
161 switch (Options::starColorMode())
164 c = Eigen::Vector3f(255. / 255., 0., 0.);
167 c = Eigen::Vector3f(0., 0., 0.);
170 c = Eigen::Vector3f(1., 1., 1.);
210 starColor.setRgb(m_pen[0] * 255, m_pen[1] * 255, m_pen[2] * 255);
220 s = (Options::starColorIntensity() / 10.) *
227 for (
int j = 0;
j < 6; ++
j)
229 m_color[
type][i +
j] = c;
236void SkyGLPainter::drawTexturedRectangle(
const QImage &
img,
const Eigen::Vector2f &pos,
const float angle,
const float sizeX,
243 TextureManager::bindFromImage(
img, m_widget);
275 if (!m_proj->checkVisibility(planet))
278 float zoom = Options::zoomFactor();
292 else if (planet->
name() ==
xi18n(
"Mars"))
310 bool visible =
false;
311 Eigen::Vector2f pos = m_proj->toScreenVec(planet,
true, &visible);
316 if (planet->
name() ==
"Saturn")
319 drawTexturedRectangle(planet->
image(), pos, m_proj->findPA(planet, pos.x(), pos.y()), size, size);
324bool SkyGLPainter::drawPointSource(
const SkyPoint *
loc,
float mag,
char sp)
327 if (!m_proj->checkVisibility(
loc))
329 return addItem(
loc, SkyObject::STAR,
starWidth(mag), sp);
332void SkyGLPainter::drawSkyPolygon(
LineList *list)
343 polygon.reserve(points->size());
344 for (
int i = 0; i < points->size(); ++i)
347 Eigen::Vector2f
oThis = m_proj->toScreenVec(
pThis,
true, &isVisible);
349 isVisible &= m_proj->checkVisibility(
pThis);
374#define KSTARS_ASSUME_CONVEXITY false
377 drawPolygon(polygon, KSTARS_ASSUME_CONVEXITY);
386 for (
int i = 0; i < NUMTYPES; ++i)
397 glColorMask(0, 0, 0, 0);
405 glDrawArrays(GL_TRIANGLE_FAN, 0, polygon.size());
410 glColorMask(1, 1, 1, 1);
415 glVertex2f(m_widget->width(), m_widget->height());
438 drawPolygon(
ground,
false,
false);
446 glDrawArrays(GL_LINE_LOOP, 0,
ground.size());
453void SkyGLPainter::drawSkyPolyline(
LineList *list, SkipHashList *skipList, LineListLabel *label)
468 for (
int i = 1; i < points->size(); ++i)
470 Eigen::Vector2f
oThis = m_proj->toScreenVec(points->at(i),
true, &isVisible);
472 isVisible &= m_proj->checkVisibility(points->at(i));
474 bool doSkip = (skipList ? skipList->skip(i) :
false);
491 Eigen::Vector2f
oMid = m_proj->clipLineVec(points->at(i - 1), points->at(i));
499 Eigen::Vector2f
oMid = m_proj->clipLineVec(points->at(i), points->at(i - 1));
530 if (!m_proj->checkVisibility(obj))
533 Eigen::Vector2f
vec = m_proj->toScreenVec(obj,
true, &visible);
534 if (!visible || !m_proj->onScreen(
vec))
536 const float size = 30.;
542void SkyGLPainter::drawFlags()
548 bool visible =
false;
552 for (i = 0; i < data->
skyComposite()->flags()->size(); i++)
558 point->EquatorialToHorizontal(data->
lst(), data->
geo()->
lat());
561 vec = m_proj->toScreenVec(point,
true, &visible);
564 if (!visible || !m_proj->onScreen(
vec))
570 drawTexturedRectangle(
img,
vec, 0,
img.width(),
img.height());
576void SkyGLPainter::drawText(
int x,
int y,
const QString text,
QFont font,
QColor color)
611 float vx = x + 0.5 * w + 10;
613 drawTexturedRectangle(
text_image, Eigen::Vector2f(
vx,
vy), 0, w, h);
653void SkyGLPainter::drawSkyBackground()
656 QColor bg = KStarsData::Instance()->colorScheme()->colorNamed(
"SkyColor");
661void SkyGLPainter::end()
663 for (
int i = 0; i < NUMTYPES; ++i)
669void SkyGLPainter::begin()
671 m_proj =
m_sm->projector();
674 glViewport(0, 0, m_widget->width(), m_widget->height());
677 glOrtho(0, m_widget->width(), m_widget->height(), 0, -1, 1);
688 glDepthMask(GL_FALSE);
699void SkyGLPainter::setBrush(
const QBrush &brush)
709void SkyGLPainter::setPen(
const QPen &pen)
714 glLineWidth(pen.
widthF());
725void SkyGLPainter::drawSatellite(
Satellite *sat)
728 bool visible =
false;
729 Eigen::Vector2f pos,
vertex;
733 pos = m_proj->toScreenVec(sat,
true, &visible);
735 if (!visible || !m_proj->onScreen(pos))
738 if (Options::drawSatellitesLikeStars())
740 drawPointSource(sat, 3.5,
'B');
753 vertex = pos + Eigen::Vector2f(-1.0, -1.0);
755 vertex = pos + Eigen::Vector2f(1.0, -1.0);
757 vertex = pos + Eigen::Vector2f(1.0, 1.0);
759 vertex = pos + Eigen::Vector2f(-1.0, 1.0);
765 if (Options::showSatellitesLabels())
772 bool visible =
false;
773 Eigen::Vector2f pos,
vertex;
775 sup->HorizontalToEquatorial(data->
lst(), data->
geo()->
lat());
777 pos = m_proj->toScreenVec(
sup,
true, &visible);
779 if (!visible || !m_proj->onScreen(pos))
787 vertex = pos + Eigen::Vector2f(2.0, 0.0);
789 vertex = pos + Eigen::Vector2f(-2.0, 0.0);
794 vertex = pos + Eigen::Vector2f(0.0, 2.0);
796 vertex = pos + Eigen::Vector2f(0.0, -2.0);
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Information about a ConstellationsArt object.
QColor labelColor(int index)
Get label color.
QString label(int index)
Get label.
QString imageName(int index)
Get image name.
QImage image(int index)
Get image.
const CachingDms * lat() const
A subclass of TrailObject that provides additional information needed for most solar system objects.
const QImage & image() const
KStarsData is the backbone of KStars.
ColorScheme * colorScheme()
SkyMapComposite * skyComposite()
A simple data container used by LineListIndex.
Represents an artificial satellites.
void drawLabel(Satellite *sat, const QPointF &pos)
Draw label of a satellite.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
virtual QString name(void) const
Draws things on the sky, without regard to backend.
float starWidth(float mag) const
Get the width of a star of magnitude mag.
The sky coordinates of a point in the sky.
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates,...
Represents the supernova object.
static const QImage & getImage(const QString &name)
Return texture image.
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
QString xi18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
QString label(StandardShortcut id)
float alphaF() const const
float blueF() const const
float greenF() const const
const_reference at(qsizetype i) const const
QColor color() const const
Qt::PenStyle style() const const
qreal widthF() const const
bool isEmpty() const const