Caelum
UniversalClock.cpp
1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 2006-2008 Caelum team. See Contributors.txt for details.
6 
7 Caelum is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Caelum is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with Caelum. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "CaelumPrecompiled.h"
22 #include "UniversalClock.h"
23 #include "Astronomy.h"
24 
25 namespace Caelum
26 {
27  const Caelum::LongReal UniversalClock::SECONDS_PER_DAY = 86400.0;
28 
31  setTimeScale (1.0);
32  }
33 
34  void UniversalClock::setJulianDay (Caelum::LongReal value) {
35  mJulianDayBase = value;
36  mCurrentTime = 0;
37  mLastUpdateTime = 0;
38  }
39 
41  int year, int month, int day,
42  int hour, int minute, double second)
43  {
44  ScopedHighPrecissionFloatSwitch precissionSwitch;
45  setJulianDay(Astronomy::getJulianDayFromGregorianDateTime(year, month, day, hour, minute, second));
46  }
47 
48  LongReal UniversalClock::getJulianDay () const
49  {
50  ScopedHighPrecissionFloatSwitch precissionSwitch;
51  Caelum::LongReal res = mJulianDayBase + mCurrentTime / SECONDS_PER_DAY;
52  return res;
53  }
54 
56  ScopedHighPrecissionFloatSwitch precissionSwitch;
57  return (mCurrentTime - mLastUpdateTime) / SECONDS_PER_DAY;
58  }
59 
60  LongReal UniversalClock::getJulianSecond () const {
61  ScopedHighPrecissionFloatSwitch precissionSwitch;
62  LongReal res = mJulianDayBase * SECONDS_PER_DAY + mCurrentTime;
63  return res;
64  }
65 
67  ScopedHighPrecissionFloatSwitch precissionSwitch;
68  return mCurrentTime - mLastUpdateTime;
69  }
70 
71  void UniversalClock::setTimeScale (const Ogre::Real scale) {
72  mTimeScale = scale;
73  }
74 
75  Ogre::Real UniversalClock::getTimeScale () const {
76  return mTimeScale;
77  }
78 
79  void UniversalClock::update (const Ogre::Real time) {
80  mLastUpdateTime = mCurrentTime;
81  mCurrentTime += time * mTimeScale;
82  }
83 }
84 
Dummy class to increase floting point precission in a block This class will raise precission in the c...
Definition: Astronomy.h:217
void update(const Ogre::Real time)
Updates the clock.
UniversalClock()
Constructor.
static const LongReal J2000
January 1, 2000, noon.
Definition: Astronomy.h:68
LongReal getJulianDayDifference() const
Get the difference in julian day between this and the last update.
LongReal getJulianSecondDifference() const
Get the difference in seconds between this and the last update.
static LongReal getJulianDayFromGregorianDateTime(int year, int month, int day, int hour, int minute, LongReal second)
Get astronomical julian day from normal gregorian calendar.
Definition: Astronomy.cpp:270
LongReal getJulianDay() const
Get current julian day.
LongReal getJulianSecond() const
Get the current julian second (getJulianDay * SECONDS_PER_DAY) This is most likely very very large an...
void setGregorianDateTime(int year, int month, int day, int hour, int minute, double second)
Set the current time as a gregorian date.
void setTimeScale(const Ogre::Real scale)
Sets the time scale.
void setJulianDay(LongReal value)
Set the current time as a julian day.
static const LongReal SECONDS_PER_DAY
Number of seconds per day; exactly 60*60*24.
Ogre::Real getTimeScale() const
Gets the time scale.
Caelum namespace.
Definition: Astronomy.cpp:24