28 #define M_PI 3.14159265358979323846264338327950288419717
51 class SunLocatorPrivate
72 d( new SunLocatorPrivate( clock, planet ))
81 void SunLocator::updatePosition()
83 if( d->m_planet->id() ==
"moon" ) {
85 qreal days = (qreal)d->m_clock->dateTime().date().toJulianDay() + d->m_clock->dayFraction() -
MOON_EPOCH;
91 days = days - (int)days;
97 mDebug() <<
"MOON:" << (int)(days*100) <<
"% of orbit completed and"
98 << (int)(
abs((days-0.5)*2) * 100) <<
"% illuminated";
100 d->m_lon = (1-days) * 2*
M_PI;
109 long day = d->m_clock->dateTime().date().toJulianDay() -
J2000;
113 qreal M = d->m_planet->M_0() + d->m_planet->M_1()*day;
116 qreal C = d->m_planet->C_1()*sin(M) + d->m_planet->C_2()*sin(2*M)
117 + d->m_planet->C_3()*sin(3*M) + d->m_planet->C_4()*sin(4*M)
118 + d->m_planet->C_5()*sin(5*M) + d->m_planet->C_6()*sin(6*M);
124 qreal lambda_sun = nu + d->m_planet->Pi() +
M_PI;
127 qreal delta_sun = asin(sin(d->m_planet->epsilon())*sin(lambda_sun));
130 qreal alpha_sun = atan2(cos(d->m_planet->epsilon())*sin(lambda_sun), cos(lambda_sun));
133 qreal theta = alpha_sun;
136 d->m_lon =
M_PI - (d->m_planet->theta_0() + d->m_planet->theta_1()
137 * (day + d->m_clock->dayFraction()) - theta);
142 d->m_lat = delta_sun;
149 qreal b = sin((lon-d->m_lon)/2.0);
152 qreal h = (a*a) + c * (b*b);
161 qreal twilightZone = 0.0;
163 if ( d->m_planet->id() ==
"earth" || d->m_planet->id() ==
"venus" ) {
168 if ( h <= 0.5 - twilightZone / 2.0 )
170 else if ( h >= 0.5 + twilightZone / 2.0 )
173 brightness = ( 0.5 + twilightZone/2.0 - h ) / twilightZone;
181 if ( brightness > 0.99999 )
184 if ( brightness < 0.00001 ) {
188 pixcol = qRgb(qRed(pixcol) * 0.35, qGreen(pixcol) * 0.35, qBlue(pixcol) * 0.35);
192 int r = qRed( pixcol );
193 int g = qGreen( pixcol );
194 int b = qBlue( pixcol );
195 qreal d = 0.65 * brightness + 0.35;
196 pixcol = qRgb((
int)(d * r), (
int)(d * g), (
int)(d * b));
201 qreal brightness)
const
204 if ( brightness > 0.99999 )
207 if ( brightness < 0.00001 ) {
212 qreal& d = brightness;
214 int r = qRed( pixcol );
215 int g = qGreen( pixcol );
216 int b = qBlue( pixcol );
218 int dr = qRed( dpixcol );
219 int dg = qGreen( dpixcol );
220 int db = qBlue( dpixcol );
222 pixcol = qRgb( (
int)( d * r + (1 - d) * dr ),
223 (
int)( d * g + (1 - d) * dg ),
224 (
int)( d * b + (1 - d) * db ) );
245 const Planet *previousPlanet = d->m_planet;
247 mDebug() <<
"SunLocator::setPlanet(Planet*)";
248 d->m_planet = planet;
254 if ( !previousPlanet->
id().isEmpty() ) {
271 #include "SunLocator.moc"
QString id() const
The internal, nonlocalized name of the planet.
const int update_interval
const qreal MOON_SYNODIC_PERIOD
void setPlanet(const Planet *planet)
qreal shading(qreal lon, qreal a, qreal c) const
double abs(const Vec3 &c)
void shadePixelComposite(QRgb &pixcol, const QRgb &dpixcol, qreal shade) const
void shadePixel(QRgb &pixcol, qreal shade) const
SunLocator(const MarbleClock *clock, const Planet *planet)
void positionChanged(qreal lon, qreal lat)
QDebug mDebug()
a function to replace qDebug() in Marble library code