2
This file is part of Caelum.
3
See http://www.ogre3d.org/wiki/index.php/Caelum
5
Copyright (c) 2006-2008 Caelum team. See Contributors.txt for details.
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.
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.
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/>.
21
#include "CaelumPrecompiled.h"
22
#include "UniversalClock.h"
23
#include "Astronomy.h"
27
const caelum::LongReal UniversalClock::SECONDS_PER_DAY = 86400.0;
29
UniversalClock::UniversalClock () {
30
setJulianDay (Astronomy::J2000);
33
// The above call does forceUpdate but let's be explicit for clarity.
37
void UniversalClock::setJulianDay (caelum::LongReal value) {
38
mJulianDayBase = value;
43
void UniversalClock::setGregorianDateTime(
44
int year, int month, int day,
45
int hour, int minute, double second)
47
int fpmode = Astronomy::enterHighPrecissionFloatingPointMode ();
48
setJulianDay(Astronomy::getJulianDayFromGregorianDateTime(year, month, day, hour, minute, second));
49
Astronomy::restoreFloatingPointMode(fpmode);
52
caelum::LongReal UniversalClock::getJulianDay () const
54
int fpmode = Astronomy::enterHighPrecissionFloatingPointMode ();
55
caelum::LongReal res = mJulianDayBase + mCurrentTime / SECONDS_PER_DAY;
56
Astronomy::restoreFloatingPointMode(fpmode);
60
caelum::LongReal UniversalClock::getJulianDayDifference () const {
61
return (mCurrentTime - mLastUpdateTime) / SECONDS_PER_DAY;
64
caelum::LongReal UniversalClock::getJulianSecond () const {
65
int fpmode = Astronomy::enterHighPrecissionFloatingPointMode ();
66
caelum::LongReal res = mJulianDayBase * SECONDS_PER_DAY + mCurrentTime;
67
Astronomy::restoreFloatingPointMode(fpmode);
71
caelum::LongReal UniversalClock::getJulianSecondDifference () const {
72
return mCurrentTime - mLastUpdateTime;
75
void UniversalClock::setTimeScale (const Ogre::Real scale) {
79
Ogre::Real UniversalClock::getTimeScale () const {
83
void UniversalClock::setUpdateRate (const Ogre::Real rate) {
86
if (mUpdateRate < 0) {
93
Ogre::Real UniversalClock::getUpdateRate () const {
97
bool UniversalClock::update (const Ogre::Real time) {
98
mTimeSinceLastUpdate += time;
100
if (mTimeSinceLastUpdate > mUpdateRate) {
101
mLastUpdateTime = mCurrentTime;
102
mCurrentTime += mTimeSinceLastUpdate * mTimeScale;
103
mTimeSinceLastUpdate = 0;
110
void UniversalClock::forceUpdate () {
111
mTimeSinceLastUpdate = mUpdateRate;
114
} // namespace caelum