Skip to content

Commit 9a76121

Browse files
committed
Calendar on ecliptic and ecliptic J2000
1 parent 8e6104e commit 9a76121

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

src/core/modules/GridLinesMgr.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,107 @@ void SkyLine::draw(StelCore *core) const
12291229
part30.transfo4d(rotZ1);
12301230
part30l.transfo4d(rotZ1);
12311231
}
1232+
1233+
// Get current year and make date caption on ecliptic
1234+
int year, month, day;
1235+
StelUtils::getDateFromJulianDay(core->getJD(), &year, &month, &day);
1236+
double newyearJD;
1237+
partAxis.set(1,0,0);
1238+
1239+
if(StelUtils::getJDFromDate(&newyearJD, year, 1, 1, 0, 0, 0))
1240+
{
1241+
int daysOfYear = StelUtils::isLeapYear(year) ? 366 : 365;
1242+
1243+
newyearJD = newyearJD + core->getUTCOffset(newyearJD)/24;
1244+
Vec3d partNewYear=earth->getEclipticPos(newyearJD + core->computeDeltaT(newyearJD)/86400.0)*-1;
1245+
Vec3d partDay=partNewYear;
1246+
partDay.transfo4d(Mat4d::rotation(partAxis, -0.1*M_PI/180));
1247+
Vec3d partDayl=partNewYear;
1248+
partDayl.transfo4d(Mat4d::rotation(partAxis, -0.175*M_PI/180));
1249+
Vec3d partWeek=partNewYear;
1250+
partWeek.transfo4d(Mat4d::rotation(partAxis, -0.25*M_PI/180));
1251+
Vec3d partMonth=partNewYear;
1252+
partMonth.transfo4d(Mat4d::rotation(partAxis, -0.75*M_PI/180));
1253+
Vec3d partMonthl=partNewYear;
1254+
partMonthl.transfo4d(Mat4d::rotation(partAxis, -0.775*M_PI/180));
1255+
1256+
if(line_type == SkyLine::ECLIPTIC_OF_DATE || line_type == SkyLine::ECLIPTIC_J2000)
1257+
{
1258+
int month = 0;
1259+
int monthDays = 0;
1260+
QString monthNames[] =
1261+
{
1262+
qc_("Jan","short month name"),
1263+
qc_("Feb","short month name"),
1264+
qc_("Mar","short month name"),
1265+
qc_("Apr","short month name"),
1266+
qc_("May","short month name"),
1267+
qc_("Jun","short month name"),
1268+
qc_("Jul","short month name"),
1269+
qc_("Aug","short month name"),
1270+
qc_("Sep","short month name"),
1271+
qc_("Oct","short month name"),
1272+
qc_("Nov","short month name"),
1273+
qc_("Dec","short month name")
1274+
};
1275+
for(int i = 0,d = 0; i < daysOfYear; ++i, ++d)
1276+
{
1277+
if(d >= monthDays)
1278+
{
1279+
d = 0;
1280+
++month;
1281+
monthDays = StelUtils::numberOfDaysInMonthInYear(month, year);
1282+
sPainter.drawGreatCircleArc(partNewYear, partMonth, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
1283+
QString label = QString("%1").arg(monthNames[month - 1]);
1284+
if(showLabel)
1285+
{
1286+
float shiftx = static_cast<float>(sPainter.getFontMetrics().boundingRect(label).width()) * -1.0f;
1287+
float shifty = static_cast<float>(sPainter.getFontMetrics().height()) * 0.25f;
1288+
Vec3d screenPosTgt, screenPosTgtL;
1289+
prj->project(partMonth, screenPosTgt);
1290+
prj->project(partMonthl, screenPosTgtL);
1291+
double dx=screenPosTgtL[0] - screenPosTgt[0];
1292+
double dy=screenPosTgtL[1] - screenPosTgt[1];
1293+
float textAngle=static_cast<float>(atan2(dy, dx));
1294+
sPainter.drawText(partMonthl, label, textAngle*M_180_PIf - 90, shiftx, shifty, false);
1295+
}
1296+
}
1297+
else
1298+
{
1299+
sPainter.drawGreatCircleArc(partNewYear, partDay, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
1300+
if(showLabel && d % 5 == 0 && (monthDays > 30 || d != 30))
1301+
{
1302+
QString label = QString("%1").arg(d);
1303+
float shiftx = static_cast<float>(sPainter.getFontMetrics().boundingRect(label).width()) * -1.0f;
1304+
float shifty = static_cast<float>(sPainter.getFontMetrics().height()) * 0.2f;
1305+
Vec3d screenPosTgt, screenPosTgtL;
1306+
prj->project(partDay, screenPosTgt);
1307+
prj->project(partDayl, screenPosTgtL);
1308+
double dx = screenPosTgtL[0] - screenPosTgt[0];
1309+
double dy = screenPosTgtL[1] - screenPosTgt[1];
1310+
float textAngle=static_cast<float>(atan2(dy, dx));
1311+
sPainter.drawText(partDayl, label, textAngle*M_180_PIf-90, shiftx, shifty, false);
1312+
}
1313+
}
1314+
double step;
1315+
if(i<81||i>268)
1316+
{
1317+
step = 1.0*M_PI/(daysOfYear - 187.);
1318+
}
1319+
else
1320+
{
1321+
step = 1.0*M_PI/187.;
1322+
}
1323+
const Mat4d& rotZ1 = Mat4d::rotation(partZAxis, step);
1324+
partNewYear.transfo4d(rotZ1);
1325+
partDay.transfo4d(rotZ1);
1326+
partDayl.transfo4d(rotZ1);
1327+
partWeek.transfo4d(rotZ1);
1328+
partMonth.transfo4d(rotZ1);
1329+
partMonthl.transfo4d(rotZ1);
1330+
}
1331+
}
1332+
}
12321333
sPainter.setLineWidth(lineThickness);
12331334
}
12341335

0 commit comments

Comments
 (0)