MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getSunDirection

Method getSunDirection

src/Geoscape/Globe.cpp:1126–1173  ·  view source on GitHub ↗

* Get position of sun from point on globe * @param lon longitude of position * @param lat latitude of position * @return position of sun */

Source from the content-addressed store, hash-verified

1124 * @return position of sun
1125 */
1126Cord Globe::getSunDirection(double lon, double lat) const
1127{
1128 const double curTime = _game->getSavedGame()->getTime()->getDaylight();
1129 const double rot = curTime * 2*M_PI;
1130 double sun;
1131
1132 if (Options::globeSeasons)
1133 {
1134 const int MonthDays1[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
1135 const int MonthDays2[] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
1136
1137 int year=_game->getSavedGame()->getTime()->getYear();
1138 int month=_game->getSavedGame()->getTime()->getMonth()-1;
1139 int day=_game->getSavedGame()->getTime()->getDay()-1;
1140
1141 double tm = (double)(( _game->getSavedGame()->getTime()->getHour() * 60
1142 + _game->getSavedGame()->getTime()->getMinute() ) * 60
1143 + _game->getSavedGame()->getTime()->getSecond() ) / 86400; //day fraction is also taken into account
1144
1145 double CurDay;
1146 if (year%4 == 0 && !(year%100 == 0 && year%400 != 0))
1147 CurDay = (MonthDays2[month] + day + tm )/366 - 0.219; //spring equinox (start of astronomic year)
1148 else
1149 CurDay = (MonthDays1[month] + day + tm )/365 - 0.219;
1150 if (CurDay<0) CurDay += 1.;
1151
1152 sun = -0.261 * sin(CurDay*2*M_PI);
1153 }
1154 else
1155 sun = 0;
1156
1157 Cord sun_direction(cos(rot+lon), sin(rot+lon)*-sin(lat), sin(rot+lon)*cos(lat));
1158
1159 Cord pole(0, cos(lat), sin(lat));
1160
1161 if (sun>0)
1162 sun_direction *= 1. - sun;
1163 else
1164 sun_direction *= 1. + sun;
1165
1166 pole *= sun;
1167 sun_direction += pole;
1168 double norm = sun_direction.norm();
1169 //norm should be always greater than 0
1170 norm = 1./norm;
1171 sun_direction *= norm;
1172 return sun_direction;
1173}
1174
1175
1176void Globe::drawShadow()

Callers

nothing calls this directly

Calls 10

getDaylightMethod · 0.80
getSavedGameMethod · 0.80
getYearMethod · 0.80
getMonthMethod · 0.80
getDayMethod · 0.80
getHourMethod · 0.80
getMinuteMethod · 0.80
getSecondMethod · 0.80
normMethod · 0.80
getTimeMethod · 0.45

Tested by

no test coverage detected