GlobeEngine
AstroCommon.h
Go to the documentation of this file.
1 
11 #ifndef GlobeEngine_AstroCommon_h
12 #define GlobeEngine_AstroCommon_h
13 
14 #include "OpenGL_Includes.h"
15 #include <vmmlib/vector.hpp>
16 
17 
18 namespace geAstro {
19 
21 
22  static UniverseSelectionType getUniversSelectionTypeFromInt(int _id) {
23  switch (_id) {
24  case 0: {return UniverseSelectionType::NONE; break; }
25  case 1: {return UniverseSelectionType::SYSTEMS; break; }
26  case 2: {return UniverseSelectionType::SUNS; break; }
27  case 3: {return UniverseSelectionType::PLANETS; break; }
28  case 4: {return UniverseSelectionType::MOONS; break; }
29  case 5: {return UniverseSelectionType::SMALLBODIES; break; }
30  case 6: {return UniverseSelectionType::ORBITS; break; }
31  default: {return UniverseSelectionType::NONE; break; }
32  }
33  }
34 
36  {
39 
41  selectionType = NONE;
42  selectionIndex = -1;
43  }
44 
45  SystemSelection(UniverseSelectionType _selectionType, int _selectionIndex) :
46  selectionType(_selectionType), selectionIndex(_selectionIndex)
47  {}
48  };
49 
51  {
55 
57  systemInFocus = -1;
58  selectionType = NONE;
59  selectionIndex = -1;
60  }
61 
62  UniverseSelection(int _systemInFocus, UniverseSelectionType _selectionType, int _selectionIndex) :
63  systemInFocus(_systemInFocus), selectionType(_selectionType), selectionIndex(_selectionIndex)
64  {}
65  };
66 
67  static vmml::Vector3i getGregorianDate(double _currentJulianDate){
68 
69  //convert julian day number to gregorian date
70  int a = _currentJulianDate + 32044;
71  int b = (4 * a + 3) / 146097;
72  int c = a - (b * 146097) / 4;
73 
74  int d = (4 * c + 3) / 1461;
75  int e = c - (1461 * d) / 4;
76  int m = (5 * e + 2) / 153;
77 
78  int day = e - (153 * m + 2) / 5 + 1;
79  int month = m + 3 - 12 * (m / 10);
80  int year = b * 100 + d - 4800 + m / 10;
81 
82  return vmml::Vector3i(day, month, year);
83  }
84 
85  //source: https://en.wikipedia.org/wiki/Astronomical_unit
86  const double KMperAU = 149597870.7;
87  const double AUperKm = 0.00000000668459; //source: google
88  const double solarRadiusInAU = 0.0046491; //source: https://en.wikipedia.org/wiki/Solar_radius
89  const double jupiterRadiusInAU = 0.0004673; //source: https://en.wikipedia.org/wiki/Jupiter
90  const double solarMass = 1.989e30; //in kg (source google)
91  const double jupiterMass = 1.898e27; //in kg. source: google
92 
93  const double hoursToDegreesFactor = 15.0;
94  const double minutesToDegreesFactor = 1.0 / 4.0;
95  const double secondsToDegreesFactor = 1.0 / 240.0;
96 
97  const double arcMinutesToDegreesFactor = 1.0 / 60.0;
98  const double arcSecondsToDegreesFactor = 1.0 / 3600.0;
99 
100 
101 
102  static double getAUfromParsec(double distanceInParsec){
103  return distanceInParsec * 206264.806247; //exactly 648000/pi source: https://en.wikipedia.org/wiki/Parsec
104  }
105 
106  static double getKmFromAU(double rad){
107  return rad * KMperAU;
108  }
109 
110  static double getAUFromKm(double rad){
111  return rad * AUperKm;
112  }
113 
114  static double getAUFromSolarRadii(double rad){
115  return rad * solarRadiusInAU;
116  }
117 
118  static double getAUFromJupiterRadii(double rad){
119  return rad * jupiterRadiusInAU;
120  }
121 
122  static double getKgFromSolarMasses(double _mass){
123  return _mass * solarMass;
124  }
125 
126  static double getKgFromJupiterMasses(double _mass){
127  return _mass * jupiterMass;
128  }
129 
130  static double getTonnesFromKg(double _mass){
131  return _mass * 0.001;
132  }
133 
134  static double getDegreesFromHours(double _hours){
135  return _hours * hoursToDegreesFactor;
136  }
137 
138  static double getDegreesFromMinutes(double _minutes){
139  return _minutes * minutesToDegreesFactor;
140  }
141 
142  static double getDegreesFromSeconds(double _seconds){
143  return _seconds * secondsToDegreesFactor;
144  }
145 
146  static double getDegreesFromArcminutes(double _arcminutes){
147  return _arcminutes * arcMinutesToDegreesFactor;
148  }
149 
150  static double getDegreesFromArcseconds(double _arcseconds){
151  return _arcseconds * arcSecondsToDegreesFactor;
152  }
153 
154  static double getRightAscensionFromString(std::string rightAscensionAsString){
155  double rightAscensionHours = atof(rightAscensionAsString.substr(0, 2).c_str());
156  double rightAscensionMinutes = atof(rightAscensionAsString.substr(3, 2).c_str());
157  double rightAscensionSeconds = atof(rightAscensionAsString.substr(6, 2).c_str());
158  double rightAscension = geAstro::getDegreesFromHours(rightAscensionHours) + geAstro::getDegreesFromMinutes(rightAscensionMinutes)
159  + geAstro::getDegreesFromSeconds(rightAscensionSeconds);
160 
161  return rightAscension;
162  }
163 
164  static double getDeclinationFromString(std::string declinationAsString){
165  double declinationSignFactor = declinationAsString.substr(0, 1) == "-" ? -1.0 : 1.0;
166  double declinationDegrees = atof(declinationAsString.substr(1, 2).c_str());
167  double declinationArcMinutes = atof(declinationAsString.substr(4, 2).c_str());
168  double declinationArcSeconds = atof(declinationAsString.substr(7, 2).c_str());
169  double declination = declinationSignFactor * (declinationDegrees + geAstro::getDegreesFromArcminutes(declinationArcMinutes) +
170  geAstro::getDegreesFromArcseconds(declinationArcSeconds));
171  return declination;
172  }//*/
173 
174  static int getTemperatureFromSpectralType(std::string st) {
175  if (st.length() == 0){
176  return 5800; //default value: roughly temperature of the sun.
177  }
178 
179  char letter = st.at(0);
180  int dig = 5;
181  if (st.length() > 1){
182  if (isdigit(st.at(1))){
183  dig = st.at(1) - '0'; // necessary not to read the ascii code but the the real digit.
184  }
185  }
186 
187  //temperatures[K] from wikipedia https://en.wikipedia.org/wiki/Stellar_classification
188  //0 hottest - 9 coldest
189  if (letter == 'O'){ return 30000; }
190  else if (letter == 'B'){ return 10000 + (9 - dig) * (30000 - 10000) / 9; }
191  else if (letter == 'A'){ return 7500 + (9 - dig) * (10000 - 7500) / 9; }
192  else if (letter == 'F'){ return 6000 + (9 - dig) * (7500 - 6000) / 9; }
193  else if (letter == 'G'){ return 5200 + (9 - dig) * (6000 - 5200) / 9; }
194  else if (letter == 'K'){ return 3700 + (9 - dig) * (5200 - 3700) / 9; }
195  else if (letter == 'M'){ return 2400 + (9 - dig) * (3700 - 2400) / 9; }
196  else if (letter == 'T'){ return 700 + (9 - dig) * (1300 - 700) / 9; }
197  else if (letter == 'Y'){ return 350; }
198  return 5800; //roughly temperature of the sun.
199  }
200 }
201 #endif
int selectionIndex
Definition: AstroCommon.h:38
const double AUperKm
Definition: AstroCommon.h:87
Definition: AstroCommon.h:20
Definition: AstroCommon.h:20
const double solarMass
Definition: AstroCommon.h:90
const double arcMinutesToDegreesFactor
Definition: AstroCommon.h:97
const double minutesToDegreesFactor
Definition: AstroCommon.h:94
Definition: AstroCommon.h:20
Definition: AstroCommon.h:50
UniverseSelectionType
Definition: AstroCommon.h:20
Definition: AstroCommon.h:18
const double KMperAU
Definition: AstroCommon.h:86
Definition: AstroCommon.h:20
int systemInFocus
Definition: AstroCommon.h:52
Definition: AstroCommon.h:20
Definition: AstroCommon.h:20
const double secondsToDegreesFactor
Definition: AstroCommon.h:95
const double jupiterRadiusInAU
Definition: AstroCommon.h:89
int selectionIndex
Definition: AstroCommon.h:54
SystemSelection()
Definition: AstroCommon.h:40
const double jupiterMass
Definition: AstroCommon.h:91
UniverseSelectionType selectionType
Definition: AstroCommon.h:37
UniverseSelection()
Definition: AstroCommon.h:56
Definition: AstroCommon.h:20
const double arcSecondsToDegreesFactor
Definition: AstroCommon.h:98
UniverseSelection(int _systemInFocus, UniverseSelectionType _selectionType, int _selectionIndex)
Definition: AstroCommon.h:62
const double solarRadiusInAU
Definition: AstroCommon.h:88
UniverseSelectionType selectionType
Definition: AstroCommon.h:53
const double hoursToDegreesFactor
Definition: AstroCommon.h:93
Definition: AstroCommon.h:35
SystemSelection(UniverseSelectionType _selectionType, int _selectionIndex)
Definition: AstroCommon.h:45