00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CaelumPrecompiled.h"
00022 #include "SolarSystemModel.h"
00023 #include "UniversalClock.h"
00024 #include "Astronomy.h"
00025
00026 using Ogre::Degree;
00027 using Ogre::Radian;
00028 using Ogre::Math;
00029 using Ogre::Real;
00030
00031 namespace caelum
00032 {
00033 SolarSystemModel::SolarSystemModel (
00034 Ogre::Degree longitude, Ogre::Degree latitude):
00035 mObserverLatitude(latitude), mObserverLongitude(longitude)
00036 {
00037 }
00038
00039 const Ogre::Vector3 SolarSystemModel::makeDirection (
00040 Ogre::Degree azimuth, Ogre::Degree altitude)
00041 {
00042 Ogre::Vector3 res;
00043 res.z = -Math::Cos (azimuth) * Math::Cos (altitude);
00044 res.x = Math::Sin (azimuth) * Math::Cos (altitude);
00045 res.y = -Math::Sin (altitude);
00046 return res;
00047 }
00048
00049 const Ogre::Vector3 SolarSystemModel::getSunDirection (LongReal jday)
00050 {
00051 int fpmode = Astronomy::enterHighPrecissionFloatingPointMode ();
00052
00053 Degree azimuth;
00054 Degree altitude;
00055 Astronomy::getHorizontalSunPosition(jday,
00056 getObserverLongitude(), getObserverLatitude(),
00057 azimuth, altitude);
00058 Ogre::Vector3 res = makeDirection(azimuth, altitude);
00059
00060 Astronomy::restoreFloatingPointMode(fpmode);
00061 return res;
00062 }
00063
00064 const Ogre::Vector3 SolarSystemModel::getMoonDirection (LongReal jday) {
00065 int fpmode = Astronomy::enterHighPrecissionFloatingPointMode ();
00066
00067 Ogre::Degree azimuth, altitude;
00068 Astronomy::getHorizontalMoonPosition(jday,
00069 getObserverLongitude (), getObserverLatitude (),
00070 azimuth, altitude);
00071
00072 Ogre::Vector3 res = makeDirection(azimuth, altitude);
00073
00074 Astronomy::restoreFloatingPointMode(fpmode);
00075 return res;
00076 }
00077
00078 const Ogre::Real SolarSystemModel::getMoonPhase (LongReal jday)
00079 {
00080
00081
00082 LongReal T = (jday - 2454488.0665L) / 29.531026L;
00083
00084 T = fabs(fmod(T, 1));
00085 return -fabs(-4 * T + 2) + 2;
00086 }
00087 }