7#include "MarbleClock.h"
8#include "MarbleGlobal.h"
12#include "MarbleDebug.h"
23class SunLocatorPrivate
26 SunLocatorPrivate(
const MarbleClock *clock,
const Planet *planet)
29 , m_twilightZone(planet->twilightZone())
33 planet->sunPosition(m_lon, m_lat, clock->dateTime());
41 const MarbleClock *
const m_clock;
42 const Planet *m_planet;
45SunLocator::SunLocator(
const MarbleClock *clock,
const Planet *planet)
47 , d(new SunLocatorPrivate(clock, planet))
51SunLocator::~SunLocator()
56qreal SunLocator::shading(qreal lon, qreal a, qreal c)
const
59 qreal b = sin((lon - d->m_lon) / 2.0);
62 qreal h = (a * a) + c * (b * b);
72 if (h <= 0.5 - d->m_twilightZone / 2.0)
74 else if (h >= 0.5 + d->m_twilightZone / 2.0)
77 brightness = (0.5 + d->m_twilightZone / 2.0 - h) / d->m_twilightZone;
82void SunLocator::shadePixel(QRgb &pixcol, qreal brightness)
85 if (brightness > 0.99999)
88 if (brightness < 0.00001) {
92 pixcol = qRgb(qRed(pixcol) * 0.35, qGreen(pixcol) * 0.35, qBlue(pixcol) * 0.35);
97 int g = qGreen(pixcol);
98 int b = qBlue(pixcol);
99 qreal d = 0.65 * brightness + 0.35;
100 pixcol = qRgb((
int)(d * r), (
int)(d * g), (
int)(d * b));
104void SunLocator::shadePixelComposite(QRgb &pixcol,
const QRgb &dpixcol, qreal brightness)
107 if (brightness > 0.99999)
110 if (brightness < 0.00001) {
115 qreal &d = brightness;
117 int r = qRed(pixcol);
118 int g = qGreen(pixcol);
119 int b = qBlue(pixcol);
121 int dr = qRed(dpixcol);
122 int dg = qGreen(dpixcol);
123 int db = qBlue(dpixcol);
125 pixcol = qRgb((
int)(d * r + (1 - d) * dr), (
int)(d * g + (1 - d) * dg), (
int)(d * b + (1 - d) * db));
129void SunLocator::update()
131 d->m_planet->sunPosition(d->m_lon, d->m_lat, d->m_clock->dateTime());
133 Q_EMIT positionChanged(getLon(), getLat());
136void SunLocator::setPlanet(
const Planet *planet)
146 const Planet *previousPlanet = d->m_planet;
148 mDebug() <<
"SunLocator::setPlanet(Planet*)";
149 d->m_planet = planet;
150 d->m_twilightZone = planet->twilightZone();
151 planet->sunPosition(d->m_lon, d->m_lat, d->m_clock->dateTime());
156 if (!previousPlanet->id().isEmpty()) {
157 Q_EMIT positionChanged(getLon(), getLat());
161qreal SunLocator::getLon()
const
163 return d->m_lon * RAD2DEG;
166qreal SunLocator::getLat()
const
168 return d->m_lat * RAD2DEG;
173#include "moc_SunLocator.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.