// SimpleSkyView by Doug Cox jdmcox@jdmcox.com using equations from Celestial Calculations by J. L. Lawence // In Project Properties: // I changed Character Set in the General subdirectory to Not Set // I added _CRT_SECURE_NO_WARNINGS to -C++ -Preprocessor Definitions to continue to use my old standard C stuff // I changed -C++ -Code Generation -Runtime Library from -MD to -MT to avoid the need for users to have a Visual Studio 2008 runtime library #include #include #include #include #define TAB 9 #define AU 92955807.2730255 // 1 astronomical unit in miles #define PI 3.141592653589793 #define DEG2RAD 0.017453292519943295 // PI/180.0 #define RAD2DEG 57.295779513082323 // 180.0/PI #define SunsEccentricity 0.016708 #define SunsEclipticLongitudeAtEpoch 280.466069 #define SunsEclipticLongitudeAtPerigeeAtEpoch 282.938346 #define MoonsEclipticLongitudeAtEpoch 218.316433 #define MoonsEclipticLongitudeAtPerigeeAtEpoch 83.353451 #define InclinationofMoonsOrbitVsEcliptic 5.1453964 #define EclipticObliquityOfEpoch2000 23.439292 #define EccentricityOfMoonsOrbit 0.0549 #define MoonsSemiMajorAxis 384400 // km #define EccentricityOfSunsOrbit 0.016708 #define SunsSemiMajorAxis 149598500 // km #define TOTALSTARS 21 //double bmi; char LatLon[] = "C:\\Users\\Public\\LatLon.txt"; //char ConstellationFile[] = "C:\\Users\\Public\\Constellations.dta"; char ConstellationFile[] = "C:\\Users\\Public\\Constellations.txt"; struct { char Name[32]; char Constellation[32]; double ApparentMagnitude; double RightAscension; double Declination; BOOL showing; } Stars[TOTALSTARS]; char ch, ch2; char Buf[20480]; // for raw data of 88 constellations double hour, minute, second, deg, min, sec; BOOL itsnegative, negvismag; struct { char Constellation[20]; double RightAscension[8]; double Declination[8]; double Azimuth; double Altitude; double VisMag[8]; int Brightness[8]; int horiz[8]; int vert[8]; int minVert; int maxVert; int minHoriz; int maxHoriz; BOOL showing; BOOL showbox; } Constellations[88]; // max number of constellations int TotalConstellations, TheConstellation = 0xFF, ConstellationsX, ConstellationsShowing; int Brightness[7] = {5,4,3,2,1,0,-1}; double EarthMeanAnomoly, EarthTrueAnomoly, EarthEquationOfTheCenter, EarthHeliocentricEclipticLongitude, EarthEclipticLongitudeAtPerihelion, EarthHeliocentricEclipticLatitude, EarthRadiusVectorLength; double MeanAnomoly[4], EquationOfTheCenter[4], TrueAnomoly[4], HeliocentricEclipticLongitude[4], HeliocentricEclipticLatitude[4], RadiusVectorLength[4], Adjustment[4], GeocentricEclipticLongitude[4], GeocentricEclipticLatitude[4], HeliocentricEclipticLatitude[4]; double PlanetAltitude[4], PlanetAzimuth[4], PlanetPhaseAngle[4], PlanetRadiusVectorLength[4], PlanetApparentMagnitude[4], StarAltitude[TOTALSTARS], StarAzimuth[TOTALSTARS]; int vertPlanet[4], horizPlanet[4], vertStar[TOTALSTARS], horizStar[TOTALSTARS]; // planet data (0=Venus, 1=Saturn, 2=Jupiter, 3=Mars): double Tau[4] = {0.615197, 29.447498, 11.862615, 1.880848}; // orbital period in tropical years double m[4] = {0.814998, 95.160904, 317.828133,0.107447}; // mass relative to Earth double r[4] = {6051.8, 58232, 69911, 3389.5}; // radius in km //Length of day = {243.018, 0.44401, 0.41354, 1.025957} double e[4] = {0.0067767, 0.053862, 0.048393, 0.093394}; // orbital eccentricity double a[4] = {0.723336, 9.536676, 5.202887, 1.523710};// length of the orbital semi-major axis in AUs double theta[4] = {16.92, 165.60, 196.74, 9.36}; // angular diameter at 1 AU double V[4] = {-4.40, -8.88, -9.40, -1.52};// visual magnitude at 1 AU double mu[4] = {324.860, 37931000, 126687000, 42828}; // standard gravitational parameter in km /s double iota[4] = {3.394676, 2.485992, 1.3043975, 1.849691}; // inclination of th orbital plane w.r.t. the eclipse double epsilon[4] = {181.979100, 49.954244, 34.396441, -4.553432}; // ecliptic longitude at the epoch double omega[4] = {131.602467, 92.598878, 14.728480, -23.943630}; // ecliptic longitude at perihelion double Omega[4] = {76.679843, 113.662424,100.473909,49.559539}; // ecliptic longitude of the ascending node at epoch double RadiusOfEarth = 6378.14*0.62137119224; // miles double RadiusOfMoon = 1738.1*0.62137119224; double RadiusOfSun = 695700*0.62137119224; double DistanceToEarth[4]; double DistanceToSun[5]; double Rotation = 0.0, N = 90.0, E = 0.0, S = 270.0, W = 180.0; double DistanceFromCenter; double rad, D, LonSign, dDay, dHour, dMinute, dSecond, DecimalHour, DecimalDay, JD, JD0, Days, dT, dR, dB, dT0, UT, GST, Adjust, LST; double Epoch2000, EpochDecimalDay, DaysFromEpoch2000, SunsMeanAnomaly, SunsEquationOfTheCenter, SunsTrueAnomaly, SunsEclipticLongitude; double MoonsMeanEclipticLongitude, MoonsMeanEclipticLongitudeAscendingNodeAtEpoch, MoonsMeanEclipticLongitudeAscendingNode, MoonsMeanAnomaly; double AnnualEquation, Evection, MeanAnomalyCorrection, MoonsTrueAnomaly, VariationCorrection, MoonsEclipticLongitude, Y, X, T, MoonsEclipticLatitude; double MoonsAge, PhaseAngle, PercentIllumination, DistanceToMoon, EarthDistanceToSun, SunAltitude, SunAzimuth, MoonAltitude, MoonAzimuth, VenusAltitude, VenusAzimuth; double Declination, RightAscension, Azimuth, Altitude, HourAngle, T0, T1, T2, Latitude = 37.407367, Longitude = -122.116302; int xCenter, yCenter, y20, UToffset, xCenterSun, yCenterSun, vertSun, horizSun, vertMoon, horizMoon, vertN, horizN, vertE, horizE, vertS, horizS, vertW, horizW, chars, leftright = 0; int C, c, p, s, w, x, y, z, num, plus, LonDeg, m2, Year, Month, Day, OrigDay, Hour, H, Minute, Second, A = 0, B = 0, EpochYear, EpochMonth; // 0 because Year is never < 0 and never < Oct 15, 1582; int maxVert, minVert, maxHoriz, minHoriz, xLoc, yLoc; DaysInYearMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; DaysInLeapYearMonths[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; DWORD fileSize, dwBytesRead; BOOL first = TRUE, goback, showsun, showmoon, showplanet[4], showstars = FALSE, showconstellations = FALSE, showanytime = FALSE, showillumination = FALSE, showplanetmagnitude = FALSE, showstarmagnitude = FALSE, showmagnitude = FALSE; char String[64]; BYTE ConstellationData[4096], red, green, blue; char cLatitude[32]; char cLongitude[32]; char szAppName[] = "SimpleSkyView"; time_t rawtime; // for timeinfo struct tm *timeinfo; // includes daylight savings time SYSTEMTIME SystemTime; HANDLE hFile, hFile2; HWND hwnd, hwndYES, hwndNO; HINSTANCE hInstance; HBRUSH hBrush, hDaySkyBrush, hNightSkyBrush, hSunBrush, hMoonBrush, hCenterBrush, hStarBrush[10]; HPEN hPen, hSunPen, hMoonPen, hStarPen[10]; HGDIOBJ hOldPen, hOldBrush; HDC hdc, hdcMem; HBITMAP hBitmap; PAINTSTRUCT ps; RECT rect; int CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; WNDCLASS wndclass; hBrush = CreateSolidBrush(0xF0F0F0); wndclass.style = CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = hBrush; // (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) return 0; hwnd = CreateWindow(szAppName, szAppName, // WS_POPUP, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, SW_SHOWMAXIMIZED); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } /* void format_commas(int n, char *out) { int c; char buf[20]; char *p; sprintf(buf, "%d", n); c = 2 - strlen(buf) % 3; for (p = buf; *p != 0; p++) { *out++ = *p; if (c == 1) *out++ = ','; c = (c + 1) % 3; } *--out = 0; } */ double CorrectTo360(double d) { x = (int)d; if (x < 0) { while (x < 0) { x += 360; d += 360.0; }; } else if (x >= 360) { while (x >= 360) { x -= 360; d -= 360.0; }; } return d; } void ConvertEclipticToEquatorial(double MoonsEclipticLatitude, double MoonsEclipticLongitude) { // eclipticlongitude is lamda AND eclipticlatitude is Beta AND obliquity of the ecliptic is epsilon Declination = RAD2DEG*asin(sin(MoonsEclipticLatitude*DEG2RAD)*cos(EclipticObliquityOfEpoch2000*DEG2RAD) + cos(MoonsEclipticLatitude*DEG2RAD)*sin(EclipticObliquityOfEpoch2000*DEG2RAD)*sin(MoonsEclipticLongitude*DEG2RAD)); Y = ((sin(MoonsEclipticLongitude*DEG2RAD))*cos(EclipticObliquityOfEpoch2000*DEG2RAD)) - (tan(MoonsEclipticLatitude*DEG2RAD)*sin(EclipticObliquityOfEpoch2000*DEG2RAD)); X = cos(MoonsEclipticLongitude*DEG2RAD); RightAscension = RAD2DEG*atan(Y/X); if ((X < 0) && (Y > 0)) RightAscension += 180.0; else if ((X < 0.0) && (Y < 0.0)) RightAscension += 180.0; else if ((X > 0.0) && (Y < 0.0)) RightAscension += 360.0; RightAscension /= 15.0; // convert to hours } void ConvertEquatorialToHorizon(double Declination, double HourAngle) { T0 = (sin(Declination*DEG2RAD)*sin(Latitude*DEG2RAD)) + (cos(Declination*DEG2RAD)*cos(Latitude*DEG2RAD)*cos(HourAngle*DEG2RAD)); Altitude = RAD2DEG*asin(T0); T1 = (sin(Declination*DEG2RAD) - (sin(Latitude*DEG2RAD)*sin(Altitude*DEG2RAD))); T2 = T1 / (cos(Latitude*DEG2RAD)*cos(Altitude*DEG2RAD)); Azimuth = RAD2DEG*acos(T2); D = sin(HourAngle*DEG2RAD); if (D > 0.0) Azimuth = 360.0 - Azimuth; } double GetJulianDay(double DecimalDay, int Year, int Month) { if (Month > 2) { y = Year; m2 = Month; } else { y = Year - 1; m2 = Month + 12; } A = y / 100; B = 2 - A + (A / 4); D = (double)(B + (int)(365.25*(double)y) + (int)(30.6001*((double)(m2+1))) + DecimalDay + 1720994.5); return D; } double UTtoGST(double UT, int Year, int Month) { double jd; jd = GetJulianDay(dDay, Year, Month); JD0 = GetJulianDay(0.0, Year, 1); Days = jd-JD0; dT = (JD0-2415020.0)/36525.0; dR = 6.6460656+(2400.051262*dT)+(0.00002581*dT*dT); dB = 24.0-dR+(double)(24*(Year-1900)); dT0 = (0.0657098*Days)-dB; return (dT0+(1.002738*UT)); } void ShowStars(void) { y = 20; for (z = 0; z < TOTALSTARS; z++) { RightAscension = Stars[z].RightAscension; Declination = Stars[z].Declination; HourAngle = LST - RightAscension; if (HourAngle < 0.0) HourAngle = HourAngle + 24.0; HourAngle = HourAngle*15.0; // change from hours to degrees ConvertEquatorialToHorizon(Declination, HourAngle); // get Altitude & Azimuth StarAltitude[z] = Altitude; StarAzimuth[z] = 360.0-Azimuth; if (Altitude >= 0.0) { Stars[z].showing = TRUE; DistanceFromCenter = yCenter * ((90.0-StarAltitude[z])/90.0); rad = (StarAzimuth[z]+Rotation-90.0) * DEG2RAD; vertStar[z] = (int)(DistanceFromCenter * sin(rad)); horizStar[z] = (int)(DistanceFromCenter * cos(rad)); if (!showsun) hOldPen = SelectObject(hdcMem, hMoonPen); hOldBrush = SelectObject(hdcMem, hBrush); Ellipse(hdcMem, xCenter+horizStar[z]-2, yCenter+vertStar[z]-2, xCenter+horizStar[z]+2, yCenter+vertStar[z]+2); // STAR SelectObject(hdcMem, hOldBrush); if (!showsun) SelectObject(hdcMem, hOldPen); TextOut(hdcMem, xCenter+horizStar[z]+5, yCenter+vertStar[z]-10, Stars[z].Name, 32); } else Stars[z].showing = FALSE; } } void ShowConstellations(void) { int x, z; minVert = rect.bottom; maxVert = rect.top; minHoriz = rect.right; maxHoriz = rect.left; ConstellationsShowing = TotalConstellations; for (z = 0; z < TotalConstellations; z++) { Constellations[z].minVert = rect.bottom; Constellations[z].maxVert = rect.top; Constellations[z].minHoriz = rect.right; Constellations[z].maxHoriz = rect.left; Constellations[z].showing = TRUE; for (x = 0; (x < 8) && (Constellations[z].RightAscension[x]); x++) { Constellations[z].vert[x] = 0; Constellations[z].horiz[x] = 0; RightAscension = Constellations[z].RightAscension[x]; Declination = Constellations[z].Declination[x]; HourAngle = LST - RightAscension; if (HourAngle < 0.0) HourAngle = HourAngle + 24.0; HourAngle = HourAngle*15.0; // change from hours to degrees ConvertEquatorialToHorizon(Declination, HourAngle); // get Altitude & Azimuth Constellations[z].Altitude = Altitude; Constellations[z].Azimuth = 360.0-Azimuth; if (Altitude >= 0.0) { DistanceFromCenter = yCenter * ((90.0-Constellations[z].Altitude)/90.0); rad = (Constellations[z].Azimuth+Rotation-90.0) * DEG2RAD; Constellations[z].vert[x] = yCenter+(int)(DistanceFromCenter * sin(rad)); if (Constellations[z].vert[x] < Constellations[z].minVert) Constellations[z].minVert = Constellations[z].vert[x]; if (Constellations[z].vert[x] > Constellations[z].maxVert) Constellations[z].maxVert = Constellations[z].vert[x]; Constellations[z].horiz[x] = xCenter+(int)(DistanceFromCenter * cos(rad)); if (Constellations[z].horiz[x] < Constellations[z].minHoriz) Constellations[z].minHoriz = Constellations[z].horiz[x]; if (Constellations[z].horiz[x] > Constellations[z].maxHoriz) Constellations[z].maxHoriz = Constellations[z].horiz[x]; if (!showsun) hOldPen = SelectObject(hdcMem, hMoonPen); hOldBrush = SelectObject(hdcMem, hStarBrush[Constellations[z].Brightness[x]]); hOldPen = SelectObject(hdcMem, hStarPen[Constellations[z].Brightness[x]]); Ellipse(hdcMem, Constellations[z].horiz[x]-2, Constellations[z].vert[x]-2, Constellations[z].horiz[x]+2, Constellations[z].vert[x]+2); // all stars that show SelectObject(hdcMem, hOldPen); SelectObject(hdcMem, hOldBrush); if (!showsun) SelectObject(hdcMem, hOldPen); } else Constellations[z].showing = FALSE; // all stars in constellation have to show } // end of for (x = 0; if (!Constellations[z].showing) ConstellationsShowing--; } // end of for (z = 0; } void GetAltitudeAzimuth(void) { dDay = (double)Day; if (timeinfo->tm_isdst) { H = Hour-1;// H is NOT daylight savings time -- H is used in calculations -- Hour is displayed if (H == -1) { H = 23; dDay--; } if (H == 24) { H = 0; dDay++; } } else H = Hour; dHour = (double)H; dMinute = (double)Minute; dSecond = (double)Second; DecimalHour = dHour + (dMinute/60.0) + (dSecond/3600.0); LonDeg = abs((int)Longitude); if (Longitude < 0.0) // West UToffset = (int)(LonDeg / 15.0); // doesn't account for daylight savings time, so don't send daylight savings time! else // East UToffset = (int)((360.0 - LonDeg) / 15.0); DecimalDay = dDay + (DecimalHour/24.0) + (UToffset/24.0); UT = DecimalHour + UToffset; if (UT >= 24.0) UT -= 24.0; // UT += 63.8/3600.0; // rough correction to seconds since Epoch Year 2000 JD = GetJulianDay(DecimalDay, Year, Month); GST = UTtoGST(UT, Year, Month); if (GST < 1.0) { D = 24.0; GST = D + GST; } Adjust = Longitude / 15.0; LST = GST + Adjust; if (LST < 1.0) LST = LST + 24.0; else if (LST > 24.0) LST = LST - 24.0; EpochDecimalDay = 1.5; EpochMonth = 1; EpochYear = 2000; Epoch2000 = GetJulianDay(EpochDecimalDay, EpochYear, EpochMonth); DaysFromEpoch2000 = JD - Epoch2000; // SUN SunsMeanAnomaly = ((360.0*DaysFromEpoch2000)/365.242191) + SunsEclipticLongitudeAtEpoch - SunsEclipticLongitudeAtPerigeeAtEpoch; SunsMeanAnomaly = CorrectTo360(SunsMeanAnomaly); // Msun SunsEquationOfTheCenter = (360.0/PI)*SunsEccentricity*sin(SunsMeanAnomaly*DEG2RAD); SunsTrueAnomaly = SunsMeanAnomaly + SunsEquationOfTheCenter; SunsTrueAnomaly = CorrectTo360(SunsTrueAnomaly); SunsEclipticLongitude = SunsTrueAnomaly + SunsEclipticLongitudeAtPerigeeAtEpoch; SunsEclipticLongitude = CorrectTo360(SunsEclipticLongitude); //Lsun ConvertEclipticToEquatorial(0.0, SunsEclipticLongitude); // get Suns RightAscension & Declination HourAngle = LST - RightAscension; if (HourAngle < 0.0) HourAngle = HourAngle + 24.0; HourAngle = HourAngle*15.0; // change from hours to degrees ConvertEquatorialToHorizon(Declination, HourAngle); // get Altitude & Azimuth Azimuth = 360.0-Azimuth; SunAltitude = Altitude; SunAzimuth = Azimuth; if (Altitude >= 0.0) showsun = TRUE; else { showsun = FALSE; // Twilight: over 16 degrees of altitude, between the sky colors of 0x2F2F2F and 0xFFDFBF, red changes 90, green changes 110, blue changes 130 if (SunAltitude > -16.0) { // Twilight D = SunAltitude+16.0; red = 0x2F+(int)((9.0*D) + 0.5); // 0.5 to possibly round up green = 0x2F+(int)((11.0*D) + 0.5); blue = 0x2F+(int)((13.0*D) + 0.5); hNightSkyBrush = CreateSolidBrush(red + (green<<8) + (blue<<16)); } else hNightSkyBrush = CreateSolidBrush(0x2F2F2F); } DistanceFromCenter = yCenter * ((90.0-Altitude)/90.0); rad = (Azimuth+Rotation-90.0) * DEG2RAD; vertSun = (int)(DistanceFromCenter * sin(rad)); horizSun = (int)(DistanceFromCenter * cos(rad)); EarthDistanceToSun = (SunsSemiMajorAxis * (1 - (EccentricityOfSunsOrbit*EccentricityOfSunsOrbit))) / (1 + (EccentricityOfSunsOrbit*cos(SunsTrueAnomaly*DEG2RAD))); EarthDistanceToSun *= 0.62137119223; DistanceToSun[4] = EarthDistanceToSun / AU; // MOON MoonsMeanEclipticLongitude = (13.176339686*DaysFromEpoch2000) + MoonsEclipticLongitudeAtEpoch; MoonsMeanEclipticLongitude = CorrectTo360(MoonsMeanEclipticLongitude); MoonsMeanEclipticLongitudeAscendingNodeAtEpoch = 125.044522; // Table 7.1 MoonsMeanEclipticLongitudeAscendingNode = MoonsMeanEclipticLongitudeAscendingNodeAtEpoch - (0.0529539*DaysFromEpoch2000); MoonsMeanEclipticLongitudeAscendingNode = CorrectTo360(MoonsMeanEclipticLongitudeAscendingNode); MoonsMeanAnomaly = MoonsMeanEclipticLongitude - (0.1114041*DaysFromEpoch2000) - MoonsEclipticLongitudeAtPerigeeAtEpoch; MoonsMeanAnomaly = CorrectTo360(MoonsMeanAnomaly); // 12. AnnualEquation = 0.1858*sin(SunsMeanAnomaly*DEG2RAD); // 13. Evection = 1.2739*sin(((2*(MoonsMeanEclipticLongitude-SunsEclipticLongitude))-MoonsMeanAnomaly)*DEG2RAD); MeanAnomalyCorrection = MoonsMeanAnomaly + Evection - AnnualEquation - (0.37*sin(SunsMeanAnomaly*DEG2RAD)); MoonsTrueAnomaly = (6.2886*sin(MeanAnomalyCorrection*DEG2RAD)) + (0.214*sin(2*MeanAnomalyCorrection*DEG2RAD)); MoonsMeanEclipticLongitude = (MoonsMeanEclipticLongitude + MoonsTrueAnomaly + Evection - AnnualEquation); // 7.3.9 lamda prime VariationCorrection = 0.6583*sin(2.0*(MoonsMeanEclipticLongitude-SunsEclipticLongitude)*DEG2RAD); MoonsEclipticLongitude = MoonsMeanEclipticLongitude + VariationCorrection; MoonsMeanEclipticLongitudeAscendingNode -= 0.16*sin(SunsMeanAnomaly*DEG2RAD); MoonsMeanEclipticLongitudeAscendingNode = CorrectTo360(MoonsMeanEclipticLongitudeAscendingNode); Y = sin((MoonsEclipticLongitude-MoonsMeanEclipticLongitudeAscendingNode)*DEG2RAD)*cos(InclinationofMoonsOrbitVsEcliptic*DEG2RAD); X = cos((MoonsEclipticLongitude-MoonsMeanEclipticLongitudeAscendingNode)*DEG2RAD); T = RAD2DEG*atan(Y/X); if ((X < 0) && (Y > 0)) T = T + 180.0; else if ((X < 0.0) && (Y < 0.0)) T = T + 180.0; else if ((X > 0.0) && (Y < 0.0)) T = T + 360.0; MoonsEclipticLongitude = MoonsMeanEclipticLongitudeAscendingNode + T; MoonsEclipticLongitude = CorrectTo360(MoonsEclipticLongitude); // Lmoon MoonsEclipticLatitude = RAD2DEG*asin(sin((MoonsEclipticLongitude-MoonsMeanEclipticLongitudeAscendingNode)*DEG2RAD)*sin(InclinationofMoonsOrbitVsEcliptic*DEG2RAD)); // Bmoon ConvertEclipticToEquatorial(MoonsEclipticLatitude, MoonsEclipticLongitude); // get Declination degrees and RightAscension hours HourAngle = LST - RightAscension; if (HourAngle < 0.0) HourAngle = HourAngle + 24.0; HourAngle = HourAngle*15.0; // change from hours to degrees ConvertEquatorialToHorizon(Declination, HourAngle); // get Altitude & Azimuth Azimuth = 360.0-Azimuth; if (Altitude >= 0.0) { showmoon = TRUE; MoonAltitude = Altitude; MoonAzimuth = Azimuth; } else showmoon = FALSE; DistanceFromCenter = yCenter * ((90.0-Altitude)/90.0); rad = (Azimuth+Rotation-90.0) * DEG2RAD; vertMoon = (int)(DistanceFromCenter * sin(rad)); horizMoon = (int)(DistanceFromCenter * cos(rad)); MoonsAge = RAD2DEG*acos(cos((MoonsEclipticLongitude-SunsEclipticLongitude)*DEG2RAD)*cos(DEG2RAD)); PhaseAngle = 180.0 - MoonsAge - 0.1468*(((1 - (0.0549*sin(MoonsMeanAnomaly*DEG2RAD))))/(1 - (0.0167*sin(MoonsMeanAnomaly*DEG2RAD))))*sin(MoonsAge*DEG2RAD); PercentIllumination = 100.0 * ((1.0 + cos(PhaseAngle*DEG2RAD))/2.0); DistanceToMoon = (MoonsSemiMajorAxis * (1 - (EccentricityOfMoonsOrbit*EccentricityOfMoonsOrbit))) / (1 + (EccentricityOfMoonsOrbit*cos(MoonsTrueAnomaly*DEG2RAD))); DistanceToMoon *= 0.62137119223; // PLANETS for (z = 0; z < 4; z++) { MeanAnomoly[z] = ((360.0*DaysFromEpoch2000)/(365.242191*Tau[z]))+epsilon[z]-omega[z]; if (MeanAnomoly[z] >= 360.0) { do { MeanAnomoly[z] -= 360.0; } while (MeanAnomoly[z] >= 360.0); } EquationOfTheCenter[z] = (360.0/PI)*e[z]*sin(MeanAnomoly[z]*DEG2RAD); // E TrueAnomoly[z] = MeanAnomoly[z] + EquationOfTheCenter[z]; // upsilon (like small v) HeliocentricEclipticLongitude[z] = TrueAnomoly[z] + omega[z]; // L HeliocentricEclipticLatitude[z] = RAD2DEG*asin(sin((HeliocentricEclipticLongitude[z]-Omega[z])*DEG2RAD)*sin(iota[z]*DEG2RAD)); // upside-down V (Lamda) RadiusVectorLength[z] = (a[z]*(1-(e[z]*e[z]))) / (1+(e[z]*cos(TrueAnomoly[z]*DEG2RAD))); // R } EarthMeanAnomoly = ((360.0*DaysFromEpoch2000)/(365.242191*1.000017))+100.464572-102.937682; // M if (EarthMeanAnomoly >= 360.0) { do { EarthMeanAnomoly -= 360.0; } while (EarthMeanAnomoly > 360.0); } EarthEquationOfTheCenter = (360.0/PI)*0.0167112*sin(EarthMeanAnomoly*DEG2RAD); // E EarthTrueAnomoly = EarthMeanAnomoly + EarthEquationOfTheCenter; // upsilon (like small v) EarthHeliocentricEclipticLongitude = EarthTrueAnomoly + 102.937682; // L EarthHeliocentricEclipticLatitude = RAD2DEG*asin(sin((EarthHeliocentricEclipticLongitude)*DEG2RAD)*sin(-0.000015*DEG2RAD)); // upside-down V (Lamda) if (EarthHeliocentricEclipticLatitude < 0.0) { do { EarthHeliocentricEclipticLatitude += 360.0; } while (EarthHeliocentricEclipticLatitude < 0.0); } EarthRadiusVectorLength = (1.000003*(1-(0.0167112*0.0167112))) / (1+(0.0167112*cos(EarthTrueAnomoly*DEG2RAD)));//R for (z = 0; z < 4; z++) { // steps 23 thru 27: Y = (sin((HeliocentricEclipticLongitude[z]-Omega[z])*DEG2RAD)*cos(iota[z]*DEG2RAD)); X = cos((HeliocentricEclipticLongitude[z]-Omega[z])*DEG2RAD); T = RAD2DEG*atan(Y/X); if ((X < 0) && (Y > 0)) T = T + 180.0; else if ((X < 0.0) && (Y < 0.0)) T = T + 180.0; else if ((X > 0.0) && (Y < 0.0)) T = T + 360.0; Adjustment[z] = Omega[z] + T; // L prime // steps 28 thru 32 Y = RadiusVectorLength[z]*cos(HeliocentricEclipticLatitude[z]*DEG2RAD)*sin((EarthHeliocentricEclipticLongitude-Adjustment[z])*DEG2RAD); X = EarthRadiusVectorLength-(RadiusVectorLength[z]*cos(HeliocentricEclipticLatitude[z]*DEG2RAD)*cos((EarthHeliocentricEclipticLongitude-Adjustment[z])*DEG2RAD)); T = RAD2DEG*atan(Y/X); if ((X < 0) && (Y > 0)) T = T + 180.0; else if ((X < 0.0) && (Y < 0.0)) T = T + 180.0; else if ((X > 0.0) && (Y < 0.0)) T = T + 360.0; GeocentricEclipticLongitude[z] = 180.0 + EarthHeliocentricEclipticLongitude + T; // Lamda symbol if (GeocentricEclipticLongitude[z] >= 360.0) { do { GeocentricEclipticLongitude[z] -= 360.0; } while (GeocentricEclipticLongitude[z] >= 360.0); } // step 33 (equation 8.6.10) Y = RadiusVectorLength[z]*cos(HeliocentricEclipticLatitude[z]*DEG2RAD)*tan(HeliocentricEclipticLatitude[z]*DEG2RAD)*sin((GeocentricEclipticLongitude[z]-Adjustment[z])*DEG2RAD); X = EarthRadiusVectorLength*sin((Adjustment[z]-EarthHeliocentricEclipticLongitude)*DEG2RAD); GeocentricEclipticLatitude[z] = RAD2DEG*atan(Y/X); // Beta symbol // Convert Ecliptic To Equatorial eclipticlongitude is lamda AND eclipticlatitude is Beta AND obliquity of the ecliptic is epsilon Declination = RAD2DEG*asin(sin(GeocentricEclipticLatitude[z]*DEG2RAD)*cos(EclipticObliquityOfEpoch2000*DEG2RAD) + cos(GeocentricEclipticLatitude[z]*DEG2RAD)*sin(EclipticObliquityOfEpoch2000*DEG2RAD)*sin(GeocentricEclipticLongitude[z]*DEG2RAD)); Y = ((sin(GeocentricEclipticLongitude[z]*DEG2RAD))*cos(EclipticObliquityOfEpoch2000*DEG2RAD)) - (tan(GeocentricEclipticLatitude[z]*DEG2RAD)*sin(EclipticObliquityOfEpoch2000*DEG2RAD)); X = cos(GeocentricEclipticLongitude[z]*DEG2RAD); RightAscension = RAD2DEG*atan(Y/X); // RightAscension is alpha symbol if ((X < 0) && (Y > 0)) RightAscension += 180.0; else if ((X < 0.0) && (Y < 0.0)) RightAscension += 180.0; else if ((X > 0.0) && (Y < 0.0)) RightAscension += 360.0; RightAscension /= 15.0; // convert to hours (alpha symbol) HourAngle = LST - RightAscension; // (delta symbol) if (HourAngle < 0.0) HourAngle = HourAngle + 24.0; HourAngle = HourAngle*15.0; // change from hours to degrees ConvertEquatorialToHorizon(Declination, HourAngle); // get Altitude & Azimuth Azimuth = 360-Azimuth; if ((!showsun || showanytime) && (Altitude >= 0.0)) { showplanet[z] = TRUE; PlanetAltitude[z] = Altitude; PlanetAzimuth[z] = Azimuth; } else showplanet[z] = FALSE; // (0=Venus, 1=Saturn, 2=Jupiter, 3=Mars) DistanceFromCenter = yCenter * ((90.0-PlanetAltitude[z])/90.0); rad = (PlanetAzimuth[z]+Rotation-90.0) * DEG2RAD; DistanceToSun[z] = (a[z] * (1 - (e[z]*e[z]))) / (1 + (e[z]*cos(a[z]*DEG2RAD))); DistanceToEarth[z] = sqrt((EarthRadiusVectorLength*EarthRadiusVectorLength) + (RadiusVectorLength[z]*RadiusVectorLength[z]) - ((2.0*EarthRadiusVectorLength*RadiusVectorLength[z])*cos((HeliocentricEclipticLongitude[z]-EarthHeliocentricEclipticLongitude)*DEG2RAD))); // in AUs vertPlanet[z] = (int)(DistanceFromCenter * sin(rad)); horizPlanet[z] = (int)(DistanceFromCenter * cos(rad)); PlanetPhaseAngle[z] = (1+cos((GeocentricEclipticLongitude[z]-HeliocentricEclipticLongitude[z])*DEG2RAD)) / 2.0; PlanetRadiusVectorLength[z] = (a[z]*(1-(e[z]*e[z]))) / (1+e[z]*cos(TrueAnomoly[z]*DEG2RAD)); PlanetApparentMagnitude[z] = V[z]+(5*log10((PlanetRadiusVectorLength[z]*DistanceToEarth[z])) / sqrt(PlanetPhaseAngle[z])); } // end of for (z = 0; z < 4; z++) } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: // bmi = (181.5 * 0.453592) / pow((71.5 * 0.254), 2); // weight and height in kilograms and meters if (INVALID_HANDLE_VALUE != (hFile = CreateFile(LatLon, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))) { if (fileSize = GetFileSize(hFile, NULL)) { ReadFile(hFile, String, fileSize, &dwBytesRead, NULL); // current engine name CloseHandle(hFile); for (x = 0, y = 0; (x < (int)fileSize) && (String[x] != ','); x++, y++) cLatitude[y] = String[x]; cLatitude[y] = 0; for (x += 2, y = 0; x < (int)fileSize; x++, y++) cLongitude[y] = String[x]; cLongitude[y] = 0; Latitude = atof(cLatitude); Longitude = atof(cLongitude); x=x; } } /* if (INVALID_HANDLE_VALUE != (hFile2 = CreateFile(ConstellationFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))) { if (fileSize = GetFileSize(hFile2, NULL)) { ReadFile(hFile2, ConstellationData, fileSize, &dwBytesRead, NULL); for (x = 0, z = 0; z < TotalConstellations; z++) { for (y = 0; (y < 8); y++) { // && (ConstellationData[x]) if (ConstellationData[x]) { Constellations[z].RightAscension[y] = *(double*)&ConstellationData[x]; x += 10; // past a double and " " Constellations[z].Declination[y] = *(double*)&ConstellationData[x]; x += 10; // past a double and \0xD\0xA } else x += 20; } y = ConstellationData[x-1]; // trick strcpy(Constellations[z].Constellation, ConstellationNames[y-1]); } CloseHandle(hFile2); } } */ Buf[0] = 0; hFile = CreateFile(ConstellationFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { ReadFile(hFile, Buf, fileSize, &dwBytesRead, NULL); for (w = 0, x = 0; x < (int)fileSize; w++) { for (z = 0; Buf[x] != '\xD'; x++, z++) Constellations[w].Constellation[z] = Buf[x]; Constellations[w].Constellation[z] = 0; x += 2; // past line feed & carriage return for (y = 0; (y < 8) && (x < (int)fileSize); y++) { x += 2; // past line number and space if ((Buf[x+1] != 13) || (Buf[x+2] != 10) || (Buf[x] != '0')) { // empty line hour = (double)((Buf[x]-'0')*10) + (Buf[x+1]-'0'); x += 4; minute = (double)((Buf[x]-'0')*10) + (Buf[x+1]-'0'); x += 4; second = (double)((Buf[x]-'0')*10) + (Buf[x+1]-'0'); Constellations[w].RightAscension[y] = hour+(minute/60.0)+(second/3600.0); x += 7; // to just past tab if (Buf[x] == '+') { itsnegative = FALSE; x++; } else { itsnegative = TRUE; x += 3; } deg = (double)((Buf[x]-'0')*10) + (Buf[x+1]-'0'); x += 5; min = (double)((Buf[x]-'0')*10) + (Buf[x+1]-'0'); x += 6; sec = (double)((Buf[x]-'0')*10) + (Buf[x+1]-'0'); if (itsnegative) Constellations[w].Declination[y] = -(deg+(min/60.0)+(sec/3600.0)); else Constellations[w].Declination[y] = deg+(min/60.0)+(sec/3600.0); x += 7; if (Buf[x] == TAB) { if (*(DWORD*)&Buf[x] == 0x9288E209) { // a tab and a minus sign in Wikipedia negvismag = TRUE; x += 4; // to Apparent Visual Magnitude } else { negvismag = FALSE; x++; // to Apparent Visual Magnitude } ch = Buf[x+4]; Buf[x+4] = 0; if ((Buf[x+2] < '5')) num = Buf[x]-'0'; else num = (Buf[x]-'0')+1; if (negvismag) num = -num; for (s = 0; s < 7; s++) { if (Brightness[s] == num) { //convert the magnitude in Brightness to s Constellations[w].Brightness[y] = s; // 0,1,2,3,4,5,6 for putting in break; } } Constellations[w].VisMag[y] = atof(&Buf[x]); // e.g. -2.99 if ((negvismag && (Constellations[w].Brightness[y]) != 0)) Constellations[w].VisMag[y] = -Constellations[w].VisMag[y]; Buf[x+4] = ch; x += 6; } else x += 2; } else { Constellations[w].RightAscension[y] = 0.0; Constellations[w].Declination[y] = 0.0; x += 3; } } // end of for (y = 0; } // end of for (w = 0; TotalConstellations = w; } CloseHandle(hFile); } GetLocalTime(&SystemTime); Year = SystemTime.wYear; Month = SystemTime.wMonth; Day = SystemTime.wDay; OrigDay = Day; Hour = SystemTime.wHour; Minute = SystemTime.wMinute; Second = SystemTime.wSecond; time(&rawtime); timeinfo = localtime(&rawtime); strcpy(Stars[0].Name, "Achenar"); strcpy(Stars[0].Constellation, "Eridanus"); Stars[0].RightAscension = 1.0+(37.0/60.0)+(42.75/3600.0); Stars[0].Declination = -(57.0+(14.0/60.0)+(12.0/3600.0)); Stars[0].ApparentMagnitude = 0.45; strcpy(Stars[1].Name, "Aldebaran"); strcpy(Stars[1].Constellation, "Taurus (The Bull)"); Stars[1].RightAscension = 4.0+(35.0/60.0)+(55.2/3600.0); Stars[1].Declination = 16.0+(30.0/60.0)+(35.1/3600.0); Stars[1].ApparentMagnitude = 0.87; strcpy(Stars[2].Name, "Alpha Centauri"); strcpy(Stars[2].Constellation, "Centaurus"); Stars[2].RightAscension = 14.0+(39.0/60.0)+(40.9/3600.0); Stars[2].Declination = -(60.0+(50.0/60.0)+(6.5/3600.0)); Stars[2].ApparentMagnitude = -0.01; strcpy(Stars[3].Name, "Altair"); strcpy(Stars[3].Constellation, "Aquila (The Eagle)"); Stars[3].RightAscension = 19.0+(50.0/60.0)+(46.68/3600.0); Stars[3].Declination = 8.0+(52.0/60.0)+(2.6/3600.0); Stars[3].ApparentMagnitude = 0.76; strcpy(Stars[4].Name, "Andromeda Galaxy"); strcpy(Stars[4].Constellation, ""); Stars[4].RightAscension = 0.0+(42.0/60.0)+(44.31/3600.0); Stars[4].Declination = 41.0+(16.0/60.0)+(9.4/3600.0); Stars[4].ApparentMagnitude = 3.44; strcpy(Stars[5].Name, "Antares"); strcpy(Stars[5].Constellation, "Scorpius (The Scorpion)"); Stars[5].RightAscension = 16.0+(29.0/60.0)+(24.47/3600.0); Stars[5].Declination = -(26.0+(25.0/60.0)+(55.0/3600.0)); Stars[5].ApparentMagnitude = 0.91; strcpy(Stars[6].Name, "Arcturus"); strcpy(Stars[6].Constellation, "Bootes (The Herdsman)"); Stars[6].RightAscension = 14.0+(15.0/60.0)+(40.35/3600.0); Stars[6].Declination = 19.0+(11.0/60.0)+(14.2/3600.0); Stars[6].ApparentMagnitude = -0.05; strcpy(Stars[7].Name, "Beta centauri"); strcpy(Stars[7].Constellation, "Centaurus"); Stars[7].RightAscension = 14.0+(3.0/60.0)+(49.44/3600.0); Stars[7].Declination = -(60.0+(22.0/60.0)+(22.7/3600.0)); Stars[7].ApparentMagnitude = 0.61; strcpy(Stars[8].Name, "Betelgeuse"); strcpy(Stars[8].Constellation, "Orion"); Stars[8].RightAscension = 5.0+(55.0/60.0)+(10.29/3600.0); Stars[8].Declination = 7.0+(24.0/60.0)+(25.3/3600.0); Stars[8].ApparentMagnitude = 0.42; strcpy(Stars[9].Name, "Canopus"); strcpy(Stars[9].Constellation, "Carina"); Stars[9].RightAscension = 6.0+(23.0/60.0)+(52.09/3600.0); Stars[9].Declination = -(52.0+(41.0/60.0)+(44.6/3600.0)); Stars[9].ApparentMagnitude = -0.72; strcpy(Stars[10].Name, "Capella"); strcpy(Stars[10].Constellation, "Aruiga (The Charioteer)"); Stars[10].RightAscension = 5.0+(16.0/60.0)+(41.3/3600.0); Stars[10].Declination = 45.0+(59.0/60.0)+(56.5/3600.0); Stars[10].ApparentMagnitude = 0.08; strcpy(Stars[11].Name, "Deneb"); strcpy(Stars[11].Constellation, "Cygnus (The Swan)"); Stars[11].RightAscension = 20.0+(41.0/60.0)+(25.91/3600.0); Stars[11].Declination = 45.0+(16.0/60.0)+(49.2/3600.0); Stars[11].ApparentMagnitude = 1.25; strcpy(Stars[12].Name, "Formalhaut"); strcpy(Stars[12].Constellation, "Piscis Austrinus"); Stars[12].RightAscension = 22.0+(57.0/60.0)+(38.83/3600.0); Stars[12].Declination = -(29.0+(37.0/60.0)+(18.6/3600.0)); Stars[12].ApparentMagnitude = 1.17; strcpy(Stars[13].Name, "Polaris"); strcpy(Stars[13].Constellation, "Ursa Minor"); Stars[13].RightAscension = 2.0+(31.0/60.0)+(47.08/3600.0); Stars[13].Declination = 89.0+(15.0/60.0)+(50.9/3600.0); Stars[13].ApparentMagnitude = 1.97; strcpy(Stars[14].Name, "Pollux"); strcpy(Stars[14].Constellation, "Gemini (The Twins)"); Stars[14].RightAscension = 7.0+(45.0/60.0)+(19.36/3600.0); Stars[14].Declination = 28.0+(1.0/60.0)+(34.7/3600.0); Stars[14].ApparentMagnitude = 1.16; strcpy(Stars[15].Name, "Procyon"); strcpy(Stars[15].Constellation, "Canis Minor"); Stars[15].RightAscension = 7.0+(39.0/60.0)+(18.54/3600.0); Stars[15].Declination = 5.0+(13.0/60.0)+(39.0/3600.0); Stars[15].ApparentMagnitude = 0.34; strcpy(Stars[16].Name, "Regulus"); strcpy(Stars[16].Constellation, "Leo (The Lion)"); Stars[16].RightAscension = 10.0+(8.0/60.0)+(22.46/3600.0); Stars[16].Declination = 11.0+(58.0/60.0)+(1.9/3600.0); Stars[16].ApparentMagnitude = 1.36; strcpy(Stars[17].Name, "Rigel"); strcpy(Stars[17].Constellation, "Orion"); Stars[17].RightAscension = 5.0+(14.0/60.0)+(32.27/3600.0); Stars[17].Declination = -8.0+(12.0/60.0)+(5.9/3600.0); Stars[17].ApparentMagnitude = 0.18; strcpy(Stars[18].Name, "Sirius"); strcpy(Stars[18].Constellation, "Canis Major"); Stars[18].RightAscension = 6.0+(45.0/60.0)+(9.0/3600.0); Stars[18].Declination = -(16.0+(42.0/60.0)+(58.0/3600.0)); Stars[18].ApparentMagnitude = -1.46; strcpy(Stars[19].Name, "Spica"); strcpy(Stars[19].Constellation, "Virgo (The Virgin)"); Stars[19].RightAscension = 13.0+(25.0/60.0)+(11.60/3600.0); Stars[19].Declination = -(11.0+(9.0/60.0)+(40.5/3600.0)); Stars[19].ApparentMagnitude = 0.98; strcpy(Stars[20].Name, "Vega"); strcpy(Stars[20].Constellation, "Lyra"); Stars[20].RightAscension = 18.0+(36.0/60.0)+(56.19/3600.0); Stars[20].Declination = 38.0+(46.0/60.0)+(58.8/3600.0); Stars[20].ApparentMagnitude = 0.03; hStarBrush[0] = CreateSolidBrush(0x484848); hStarBrush[1] = CreateSolidBrush(0x5F5F5F); hStarBrush[2] = CreateSolidBrush(0x7F7F7F); hStarBrush[3] = CreateSolidBrush(0x9F9F9F); hStarBrush[4] = CreateSolidBrush(0xBFBFBF); hStarBrush[5] = CreateSolidBrush(0xDFDFDF); hStarBrush[6] = CreateSolidBrush(0xFFFFFF); hStarPen[0] = CreatePen(PS_SOLID, 1, 0x484848); hStarPen[1] = CreatePen(PS_SOLID, 1, 0x5F5F5F); hStarPen[2] = CreatePen(PS_SOLID, 1, 0x7F7F7F); hStarPen[3] = CreatePen(PS_SOLID, 1, 0x9F9F9F); hStarPen[4] = CreatePen(PS_SOLID, 1, 0xBFBFBF); hStarPen[5] = CreatePen(PS_SOLID, 1, 0xDFDFDF); hStarPen[6] = CreatePen(PS_SOLID, 1, 0xFFFFFF); hDaySkyBrush = CreateSolidBrush(0xFFDFBF); hPen = CreatePen(PS_SOLID, 1, 0); hSunBrush = CreateSolidBrush(0x00E0F0); hSunPen = CreatePen(PS_SOLID, 1, 0x00E0F0); hMoonBrush = CreateSolidBrush(0xFFFFFF); hMoonPen = CreatePen(PS_SOLID, 1, 0xFFFFFF); hCenterBrush = CreateSolidBrush(0); break; case WM_KEYDOWN: if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) goback = TRUE; else goback = FALSE; if (wParam == VK_DOWN) { if (Latitude > -80.0) { Latitude -= 10.0; InvalidateRect(hwnd, &rect, FALSE); } break; } else if (wParam == VK_UP) { if (Latitude < 80.0) { Latitude += 10.0; InvalidateRect(hwnd, &rect, FALSE); } break; } /* else if (wParam == VK_LEFT) { if (leftright > -12) { leftright--; Longitude -= 15.0; if (Longitude < 0.0) { if (Longitude < -180.0) Longitude = -Longitude; } else if (Longitude > 180.0) Longitude = -Longitude; InvalidateRect(hwnd, &rect, FALSE); } break; } else if (wParam == VK_RIGHT) { if (leftright < 12) { leftright++; Longitude += 15.0; if (Longitude > 0.0) { if (Longitude > 180.0) Longitude = -Longitude; } else if (Longitude < -180.0) Longitude = -Longitude; InvalidateRect(hwnd, &rect, FALSE); } break; } */ if (wParam == VK_ESCAPE) { DestroyWindow(hwnd); break; } if (wParam == 'M') { if (goback) { if (Minute > 0) Minute--; else { Minute = 59; wParam = 'H'; } } else { if (Minute < 59) Minute++; else { Minute = 0; wParam = 'H'; // trick } } InvalidateRect(hwnd, &rect, FALSE); } if (wParam == 'H') { if (goback) { if (Hour > 0) Hour--; else { Hour = 23; wParam = 'D'; // trick } } else { if (Hour < 23) Hour++; else { Hour = 0; wParam = 'D'; // trick } } InvalidateRect(hwnd, &rect, FALSE); } if (wParam == 'D') { if (goback) { if (Day > 1) Day--; else { if (Year % 4) Day = DaysInLeapYearMonths[Month]; else Day = DaysInYearMonths[Month]; Month--; if (Month == 0) { Day = 31; Month = 12; Year--; } } } else { if ((Year % 4) && (Day < DaysInYearMonths[Month])) Day++; else if ((0 == (Year % 4)) && ((Day) < DaysInLeapYearMonths[Month])) Day++; else { Day = 1; Month++; if (Month == 13) { Day = 1; Month = 1; Year++; } } } InvalidateRect(hwnd, &rect, FALSE); } if (wParam == 'R') { if (goback) Rotation -= 10.0; else Rotation += 10.0; InvalidateRect(hwnd, &rect, FALSE); } else if (wParam == 'S') { if (showstars) showstars = FALSE; else showstars = TRUE; InvalidateRect(hwnd, &rect, FALSE); } else if (wParam == 'C') { if (showconstellations) showconstellations = FALSE; else showconstellations = TRUE; InvalidateRect(hwnd, &rect, FALSE); } else if (wParam == 'A') { if (showanytime) showanytime = FALSE; else showanytime = TRUE; InvalidateRect(hwnd, &rect, FALSE); } break; case WM_LBUTTONDOWN: if ((showconstellations && !showsun) || (showconstellations & showanytime)) { xLoc = (lParam & 0xFFFF); yLoc = (lParam >> 16) & 0xFFFF; for (z = 0; z < TotalConstellations; z++) { if (Constellations[z].showing && (xLoc > Constellations[z].minHoriz) && (xLoc < Constellations[z].maxHoriz) && (yLoc > Constellations[z].minVert) && (yLoc < Constellations[z].maxVert)) { Constellations[z].showbox = TRUE; break; } } if (z == TotalConstellations) { if ((xLoc >= 1650) && (yLoc > ConstellationsX) && (yLoc < (ConstellationsX+(ConstellationsShowing*20)))){ // at constellation names x = (yLoc-ConstellationsX)/20; for (y = 0, z = 0; z < TotalConstellations; z++) { if (Constellations[z].showing) { // && !Constellations[z].showbox if (x == y) Constellations[z].showbox = TRUE; y++; } } } else { for (y = 0, z = 0; z < TotalConstellations; z++) Constellations[z].showbox = FALSE; } } InvalidateRect(hwnd, &rect, FALSE); } break; case WM_MOUSEMOVE: xLoc = (lParam & 0xFFFF); yLoc = (lParam >> 16) & 0xFFFF; showillumination = FALSE; showplanetmagnitude = FALSE; showstarmagnitude = FALSE; showmagnitude = FALSE; if ((xLoc >= (xCenter+horizMoon-10)) && (xLoc <= (xCenter+horizMoon+10)) && (yLoc >= (yCenter+vertMoon-10)) && (yLoc <= (yCenter+vertMoon+10))) showillumination = TRUE; for (p = 0; p < 4; p++) { if ((xLoc >= (xCenter+horizPlanet[p]-5)) && (xLoc <= (xCenter+horizPlanet[p]+5)) && (yLoc >= (yCenter+vertPlanet[p]-5)) && (yLoc <= (yCenter+vertPlanet[p]+5))) { showplanetmagnitude = TRUE; break; } } if (showconstellations) { for (C = 0; C < TotalConstellations; C++) { for (c = 0; c < 8; c++) { if (Constellations[C].showing && (xLoc >= (Constellations[C].horiz[c]-5)) && (xLoc <= (Constellations[C].horiz[c]+5)) && (yLoc >= (Constellations[C].vert[c]-5)) && (yLoc <= (Constellations[C].vert[c]+5))) { showmagnitude = TRUE; break; } } if (showmagnitude) break; } } for (s = 0; s < 21; s++) { if ((xLoc >= (xCenter+horizStar[s]-5)) && (xLoc <= (xCenter+horizStar[s]+5)) && (yLoc >= (yCenter+vertStar[s]-5)) && (yLoc <= (yCenter+vertStar[s]+5))) { showstarmagnitude = TRUE; break; } } InvalidateRect(hwnd, &rect, FALSE); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); if (first) { first = FALSE; rect = ps.rcPaint; xCenter = rect.right/2; yCenter = rect.bottom/2; hdcMem = CreateCompatibleDC(hdc); hBitmap = CreateCompatibleBitmap(hdc, rect.right, rect.bottom); SelectObject(hdcMem, hBitmap); SetBkMode(hdcMem, TRANSPARENT); } FillRect(hdcMem, &rect, hBrush); /* See SimpleSkyView in the jdmcox.com website to read how and where to download Constellations.txt. Then to add a new constellation's stars, open Constellations.txt in Notepad, and enter the name of the new constellation in it. Then copy the existing format of numbers 1 thru 8 with a space after the number. Then copy and paste the three columns, RA, Dec, and vis.mag. from the List of stars in Lists of stars by constellation - Wikipedia into Constellations.txt. Put a zero after any number and space where you don't want to copy a star's data. The format has to exactly match the format of existing constellations, and copy and paste is necessary because the original formatting and font type is used. */ TextOut(hdcMem, 20, 20, "The Latitude and Longitude selected is mine, so change it.", 58); TextOut(hdcMem, 20, 40, "In Google Maps, right-click on the desired location,", 52); TextOut(hdcMem, 20, 60, "and select 'What's Here'.", 25); TextOut(hdcMem, 20, 80, "you'll see the latitude, longitude at the bottom of the map", 59); TextOut(hdcMem, 20, 100, "-which you can't copy- so left-click on it to see it again", 58); TextOut(hdcMem, 20, 120, "in another box, which you can copy and then paste", 49); TextOut(hdcMem, 20, 140, "into a file in C:\\Users\\Public named LatLon.txt", 48); TextOut(hdcMem, 20, 160, "and if that file doesn't exist create it in Notepad.", 52); TextOut(hdcMem, 20, 190, "This is what you'd see lying on your back.", 42); TextOut(hdcMem, 20, 210, "Press Esc to exit", 17); TextOut(hdcMem, 20, 230, "Press D, H, or M to go forward in time, or with Shift key to go back", 68); TextOut(hdcMem, 20, 250, "Press the up or down Arrow key to change Latitude", 49); TextOut(hdcMem, 20, 270, "Press R or Shift/Ctrl-R to rotate North", 39); TextOut(hdcMem, 20, 290, "Press S to show/not show brightest stars at night", 49); TextOut(hdcMem, 20, 310, "Press C to show/not show constellations at night", 48); TextOut(hdcMem, 20, 330, "Press A to show/not show anytime, day or night", 46); if (showanytime) TextOut(hdcMem, 20, 350, "***ShowAnytime ON***", 20); else TextOut(hdcMem, 20, 350, "***ShowAnytime OFF***", 21); TextOut(hdcMem, 20, 370, "You can see the Apparent Magnitude of any planet or star", 56); TextOut(hdcMem, 20, 390, "by moving the mouse pointer over it.", 36); TextOut(hdcMem, 20, 410, "It's a measure of how bright a planet or star appears.", 54); TextOut(hdcMem, 20, 430, "The brightest one has the biggest negative number,", 50); TextOut(hdcMem, 20, 450, "and the dimmest has the biggest positive number.", 48); TextOut(hdcMem, 20, 470, "mag: 0.00 would indicate a fairly bright one.", 45); TextOut(hdcMem, 20, 490, "Moving the mouse pointer over the moon", 38); TextOut(hdcMem, 20, 510, "would show what percentage it's illuminated.", 44); chars = sprintf_s(String, 64, "%.6f, %.6f", Latitude, Longitude); TextOut(hdcMem, 20, 540, String, chars); chars = sprintf_s(String, 64, "%i/%i/%i", Month, Day, Year); TextOut(hdcMem, 20, 560, String, chars); chars = sprintf_s(String, 64, "%2i:%2i", Hour, Minute); TextOut(hdcMem, 20, 580, String, chars); ////////////////// GetAltitudeAzimuth(); ////////////////// x = 440; // don't use this x in ShowStars or ShowConstellations if (showsun) { hOldBrush = SelectObject(hdcMem, hDaySkyBrush); Ellipse(hdcMem, xCenter-(rect.bottom/2), 0, xCenter+yCenter, rect.bottom); // horizon SelectObject(hdcMem, hOldBrush); hOldPen = SelectObject(hdcMem, hSunPen); hOldBrush = SelectObject(hdcMem, hSunBrush); Ellipse(hdcMem, xCenter+horizSun-10, yCenter+vertSun-10, xCenter+horizSun+10, yCenter+vertSun+10); // SUN SelectObject(hdcMem, hOldBrush); SelectObject(hdcMem, hOldPen); hOldPen = SelectObject(hdcMem, hPen); hOldBrush = SelectObject(hdcMem, hCenterBrush); MoveToEx(hdcMem, xCenter-2, yCenter, NULL); LineTo(hdcMem, xCenter+3, yCenter); MoveToEx(hdcMem, xCenter, yCenter-2, NULL); LineTo(hdcMem, xCenter, yCenter+3); SelectObject(hdcMem, hOldBrush); SelectObject(hdcMem, hOldPen); if (showanytime && showstars) ShowStars(); if (showanytime && showconstellations) { ShowConstellations(); if (TheConstellation != 0xFF) TextOut(hdcMem, xLoc, yLoc, Constellations[TheConstellation].Constellation, 20); } } else { // NIGHT hOldBrush = SelectObject(hdcMem, hNightSkyBrush); Ellipse(hdcMem, xCenter-(rect.bottom/2), 0, xCenter+yCenter, rect.bottom); // horizon SelectObject(hdcMem, hOldBrush); DeleteObject(hNightSkyBrush); hOldPen = SelectObject(hdcMem, hMoonPen); hOldBrush = SelectObject(hdcMem, hMoonBrush); MoveToEx(hdcMem, xCenter-2, yCenter, NULL); LineTo(hdcMem, xCenter+3, yCenter); MoveToEx(hdcMem, xCenter, yCenter-2, NULL); LineTo(hdcMem, xCenter, yCenter+3); SelectObject(hdcMem, hOldBrush); SelectObject(hdcMem, hOldPen); if (showstars) ShowStars(); if (showconstellations) ShowConstellations(); if (TheConstellation != 0xFF) TextOut(hdcMem, xLoc, yLoc, Constellations[TheConstellation].Constellation, 20); } if (showmoon) { hOldPen = SelectObject(hdcMem, hMoonPen); hOldBrush = SelectObject(hdcMem, hMoonBrush); Ellipse(hdcMem, xCenter+horizMoon-10, yCenter+vertMoon-10, xCenter+horizMoon+10, yCenter+vertMoon+10); // MOON SelectObject(hdcMem, hOldBrush); SelectObject(hdcMem, hOldPen); // TextOut(hdcMem, 20, x, "Moon's bearing, angle up", 24); // x += 20; // chars = sprintf_s(String, 64, " %.1f degrees, %.1f degrees", 360.0-MoonAzimuth, MoonAltitude); // TextOut(hdcMem, 20, x, String, chars); // x += 20; // chars = sprintf_s(String, 64, " Percent Illuminated: %.0f", PercentIllumination); // TextOut(hdcMem, 20, x, String, chars); // x += 20; } if (showplanet[0]) { hOldBrush = SelectObject(hdcMem, hBrush); Ellipse(hdcMem, xCenter+horizPlanet[0]-3, yCenter+vertPlanet[0]-3, xCenter+horizPlanet[0]+3, yCenter+vertPlanet[0]+3); SelectObject(hdcMem, hOldBrush); TextOut(hdcMem, xCenter+horizPlanet[0]+5, yCenter+vertPlanet[0]-10, "Venus", 5); // TextOut(hdcMem, 20, x, "Venus' bearing, angle up", 25); // x += 20; // chars = sprintf_s(String, 64, " %.1f degrees, %.1f degrees", 360.0-PlanetAzimuth[0], PlanetAltitude[0]); // TextOut(hdcMem, 20, x, String, chars); // x += 20; } if (showplanet[1]) { hOldBrush = SelectObject(hdcMem, hBrush); Ellipse(hdcMem, xCenter+horizPlanet[1]-3, yCenter+vertPlanet[1]-3, xCenter+horizPlanet[1]+3, yCenter+vertPlanet[1]+3); SelectObject(hdcMem, hOldBrush); TextOut(hdcMem, xCenter+horizPlanet[1]+5, yCenter+vertPlanet[1]-10, "Saturn", 6); // TextOut(hdcMem, 20, x, "Saturn's bearing, angle up", 27); // x += 20; // chars = sprintf_s(String, 64, " %.1f degrees, %.1f degrees", 360.0-PlanetAzimuth[1], PlanetAltitude[1]); // TextOut(hdcMem, 20, x, String, chars); // x += 20; } if (showplanet[2]) { hOldBrush = SelectObject(hdcMem, hBrush); Ellipse(hdcMem, xCenter+horizPlanet[2]-3, yCenter+vertPlanet[2]-3, xCenter+horizPlanet[2]+3, yCenter+vertPlanet[2]+3); SelectObject(hdcMem, hOldBrush); TextOut(hdcMem, xCenter+horizPlanet[2]+5, yCenter+vertPlanet[2]-10, "Jupiter", 7); // TextOut(hdcMem, 20, x, "Jupiter's bearing, angle up", 28); // x += 20; // chars = sprintf_s(String, 64, " %.1f degrees, %.1f degrees", 360.0-PlanetAzimuth[2], PlanetAltitude[2]); // TextOut(hdcMem, 20, x, String, chars); // x += 20; } if (showplanet[3]) { hOldBrush = SelectObject(hdcMem, hBrush); Ellipse(hdcMem, xCenter+horizPlanet[3]-3, yCenter+vertPlanet[3]-3, xCenter+horizPlanet[3]+3, yCenter+vertPlanet[3]+3); SelectObject(hdcMem, hOldBrush); TextOut(hdcMem, xCenter+horizPlanet[3]+5, yCenter+vertPlanet[3]-10, "Mars", 4); // TextOut(hdcMem, 20, x, "Mars' bearing, angle up", 24); // x += 20; // chars = sprintf_s(String, 64, " %.1f degrees, %.1f degrees", 360.0-PlanetAzimuth[3], PlanetAltitude[3]); // TextOut(hdcMem, 20, x, String, chars); // x += 20; } if ((showconstellations && !showsun) || (showconstellations & showanytime)) { x = 20; TextOut(hdcMem, 1500, x, "CONSTELLATIONS", 14); x += 20; TextOut(hdcMem, 1500, x, "Left-click on a fully visible constellation to put a box around it", 66); x += 20; TextOut(hdcMem, 1500, x, "Left-click on a name below to put a box around it", 49); x += 20; TextOut(hdcMem, 1500, x, "Left-click NOT on a name below to remove all boxes", 50); x += 20; ConstellationsX = x; for (z = 0; z < TotalConstellations; z++) { if (Constellations[z].showing) { TextOut(hdcMem, 1650, x, Constellations[z].Constellation, 20); x += 20; if (Constellations[z].showbox) { MoveToEx(hdcMem, Constellations[z].minHoriz, Constellations[z].minVert, NULL); // put square around constellation LineTo(hdcMem, Constellations[z].minHoriz, Constellations[z].maxVert); LineTo(hdcMem, Constellations[z].maxHoriz, Constellations[z].maxVert); LineTo(hdcMem, Constellations[z].maxHoriz, Constellations[z].minVert); LineTo(hdcMem, Constellations[z].minHoriz, Constellations[z].minVert); SetBkMode(hdcMem, TRANSPARENT); TextOut(hdcMem, Constellations[z].minHoriz, Constellations[z].minVert-20, Constellations[z].Constellation, lstrlen(Constellations[z].Constellation)); } } } } y20 = yCenter-20; rad = (N+Rotation) * DEG2RAD; vertN = yCenter-(int)(y20 * sin(rad)); horizN = xCenter-(int)(y20 * cos(rad)); rad = (E+Rotation) * DEG2RAD; vertE = yCenter-(int)(y20 * sin(rad)); horizE = xCenter-(int)(y20 * cos(rad)); rad = (W+Rotation) * DEG2RAD; vertW = yCenter-(int)(y20 * sin(rad)); horizW = xCenter-(int)(y20 * cos(rad)); rad = (S+Rotation) * DEG2RAD; vertS = yCenter-(int)(y20 * sin(rad)); horizS = xCenter-(int)(y20 * cos(rad)); TextOut(hdcMem, horizN, vertN, TEXT("N"), 1); TextOut(hdcMem, horizE, vertE, TEXT("E"), 1); TextOut(hdcMem, horizS, vertS, TEXT("S"), 1); TextOut(hdcMem, horizW, vertW, TEXT("W"), 1); if (showillumination) { chars = sprintf_s(String, 64, "%.0f percent illuminated", PercentIllumination); TextOut(hdcMem, xCenter+horizMoon, yCenter+vertMoon-30, String, chars); } if (showplanetmagnitude) { chars = sprintf_s(String, 64, "mag: %.1f", PlanetApparentMagnitude[p]); TextOut(hdcMem, xCenter+horizPlanet[p], yCenter+vertPlanet[p]-20, String, chars); } if ((showstarmagnitude) && ((horizStar[s]) || (vertStar[s]))) { chars = sprintf_s(String, 64, "mag: %.1f", Stars[s].ApparentMagnitude); TextOut(hdcMem, xCenter+horizStar[s], yCenter+vertStar[s]-20, String, chars); } if (showmagnitude) { chars = sprintf_s(String, 64, "mag: %.1f", Constellations[C].VisMag[c]); TextOut(hdcMem, Constellations[C].horiz[c], Constellations[C].vert[c]-20, String, chars); } BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hwnd, message, wParam, lParam); }