5 #include "SunLocator.h"
7 #include "MarbleGlobal.h"
8 #include "MarbleClock.h"
10 #include "MarbleMath.h"
12 #include "MarbleDebug.h"
23 class 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;
46 SunLocator::SunLocator(
const MarbleClock *clock,
const Planet *planet )
48 d( new SunLocatorPrivate( clock, planet ))
52 SunLocator::~SunLocator()
57 qreal SunLocator::shading(qreal lon, qreal a, qreal c)
const
60 qreal b = sin((lon-d->m_lon)/2.0);
63 qreal h = (a*a) + c * (b*b);
73 if ( h <= 0.5 - d->m_twilightZone / 2.0 )
75 else if ( h >= 0.5 + d->m_twilightZone / 2.0 )
78 brightness = ( 0.5 + d->m_twilightZone/2.0 - h ) / d->m_twilightZone;
83 void SunLocator::shadePixel(QRgb &pixcol, qreal brightness)
86 if ( brightness > 0.99999 )
89 if ( brightness < 0.00001 ) {
93 pixcol = qRgb(qRed(pixcol) * 0.35, qGreen(pixcol) * 0.35, qBlue(pixcol) * 0.35);
97 int r = qRed( pixcol );
98 int g = qGreen( pixcol );
99 int b = qBlue( pixcol );
100 qreal d = 0.65 * brightness + 0.35;
101 pixcol = qRgb((
int)(d * r), (
int)(d * g), (
int)(d * b));
105 void SunLocator::shadePixelComposite(QRgb &pixcol,
const QRgb &dpixcol,
109 if ( brightness > 0.99999 )
112 if ( brightness < 0.00001 ) {
117 qreal& d = brightness;
119 int r = qRed( pixcol );
120 int g = qGreen( pixcol );
121 int b = qBlue( pixcol );
123 int dr = qRed( dpixcol );
124 int dg = qGreen( dpixcol );
125 int db = qBlue( dpixcol );
127 pixcol = qRgb( (
int)( d * r + (1 - d) * dr ),
128 (
int)( d * g + (1 - d) * dg ),
129 (
int)( d * b + (1 - d) * db ) );
133 void SunLocator::update()
135 d->m_planet->sunPosition(d->m_lon, d->m_lat, d->m_clock->dateTime());
137 emit positionChanged( getLon(), getLat() );
140 void SunLocator::setPlanet(
const Planet *planet )
150 const Planet *previousPlanet = d->m_planet;
152 mDebug() <<
"SunLocator::setPlanet(Planet*)";
153 d->m_planet = planet;
154 d->m_twilightZone = planet->twilightZone();
155 planet->sunPosition(d->m_lon, d->m_lat, d->m_clock->dateTime());
160 if ( !previousPlanet->id().isEmpty() ) {
161 emit positionChanged( getLon(), getLat() );
165 qreal SunLocator::getLon()
const
167 return d->m_lon * RAD2DEG;
170 qreal SunLocator::getLat()
const
172 return d->m_lat * RAD2DEG;
177 #include "moc_SunLocator.cpp"