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 "UniversalClock.h"
00023 #include "Astronomy.h"
00024
00025 namespace Caelum
00026 {
00027 const Caelum::LongReal UniversalClock::SECONDS_PER_DAY = 86400.0;
00028
00029 UniversalClock::UniversalClock () {
00030 setJulianDay (Astronomy::J2000);
00031 setTimeScale (1.0);
00032 }
00033
00034 void UniversalClock::setJulianDay (Caelum::LongReal value) {
00035 mJulianDayBase = value;
00036 mCurrentTime = 0;
00037 mLastUpdateTime = 0;
00038 }
00039
00040 void UniversalClock::setGregorianDateTime(
00041 int year, int month, int day,
00042 int hour, int minute, double second)
00043 {
00044 ScopedHighPrecissionFloatSwitch precissionSwitch;
00045 setJulianDay(Astronomy::getJulianDayFromGregorianDateTime(year, month, day, hour, minute, second));
00046 }
00047
00048 LongReal UniversalClock::getJulianDay () const
00049 {
00050 ScopedHighPrecissionFloatSwitch precissionSwitch;
00051 Caelum::LongReal res = mJulianDayBase + mCurrentTime / SECONDS_PER_DAY;
00052 return res;
00053 }
00054
00055 LongReal UniversalClock::getJulianDayDifference () const {
00056 ScopedHighPrecissionFloatSwitch precissionSwitch;
00057 return (mCurrentTime - mLastUpdateTime) / SECONDS_PER_DAY;
00058 }
00059
00060 LongReal UniversalClock::getJulianSecond () const {
00061 ScopedHighPrecissionFloatSwitch precissionSwitch;
00062 LongReal res = mJulianDayBase * SECONDS_PER_DAY + mCurrentTime;
00063 return res;
00064 }
00065
00066 LongReal UniversalClock::getJulianSecondDifference () const {
00067 ScopedHighPrecissionFloatSwitch precissionSwitch;
00068 return mCurrentTime - mLastUpdateTime;
00069 }
00070
00071 void UniversalClock::setTimeScale (const Ogre::Real scale) {
00072 mTimeScale = scale;
00073 }
00074
00075 Ogre::Real UniversalClock::getTimeScale () const {
00076 return mTimeScale;
00077 }
00078
00079 void UniversalClock::update (const Ogre::Real time) {
00080 mLastUpdateTime = mCurrentTime;
00081 mCurrentTime += time * mTimeScale;
00082 }
00083 }
00084