Project

General

Profile

SO3Engine
SO3UniversalClock.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26Taken from Caelum (http://www.ogre3d.org/wiki/index.php/Caelum)
27*/
28
31
32namespace SO3
33{
34
35const double SUniversalClock::SECONDS_PER_DAY = 86400.0;
36
42
43void SUniversalClock::SetGregorianDateTime(const int& year, const int& month, const int& day, const int& hour, const int& minute, const double& second)
44{
45 ScopedHighPrecissionFloatSwitch precissionSwitch;
46 SetJulianDay(SAstronomy::GetJulianDayFromGregorianDateTime(year, month, day, hour, minute, second));
47}
48
49void SUniversalClock::GetGregorianDateTime(int& year, int& month, int& day, int& hour, int& minute, double& second)
50{
51 ScopedHighPrecissionFloatSwitch precissionSwitch;
52 SAstronomy::GetGregorianDateTimeFromJulianDay(GetJulianDay(), year, month, day, hour, minute, second);
53}
54
55void SUniversalClock::SetJulianDay(const double& value)
56{
57 mJulianDayBase = value;
58 mCurrentTime = 0;
59 mLastUpdateTime = 0;
60}
61
63{
64 ScopedHighPrecissionFloatSwitch precissionSwitch;
65 double res = mJulianDayBase + mCurrentTime / SECONDS_PER_DAY;
66 return res;
67}
68
70{
71 ScopedHighPrecissionFloatSwitch precissionSwitch;
72 return (mCurrentTime - mLastUpdateTime) / SECONDS_PER_DAY;
73}
74
76{
77 ScopedHighPrecissionFloatSwitch precissionSwitch;
78 double res = mJulianDayBase * SECONDS_PER_DAY + mCurrentTime;
79 return res;
80}
81
83{
84 ScopedHighPrecissionFloatSwitch precissionSwitch;
85 return mCurrentTime - mLastUpdateTime;
86}
87
88void SUniversalClock::SetTimeScale(const float& scale)
89{
90 mTimeScale = scale;
91}
92
94{
95 return mTimeScale;
96}
97
98void SUniversalClock::Update(const float& time)
99{
100 mLastUpdateTime = mCurrentTime;
101 mCurrentTime += time * mTimeScale;
102}
103
104}
static void GetGregorianDateTimeFromJulianDay(const double &julianDay, int &year, int &month, int &day, int &hour, int &minute, double &second)
static const double J2000
January 1, 2000, noon.
static double GetJulianDayFromGregorianDateTime(const int &year, const int &month, const int &day, const int &hour, const int &minute, const double &second)
double GetJulianSecond() const
void SetJulianDay(const double &value)
void SetTimeScale(const float &scale)
double GetJulianSecondDifference() const
void GetGregorianDateTime(int &year, int &month, int &day, int &hour, int &minute, double &second)
void Update(const float &time)
void SetGregorianDateTime(const int &year, const int &month, const int &day, const int &hour, const int &minute, const double &second)
static const double SECONDS_PER_DAY
Number of seconds per day; exactly 60*60*24.
double GetJulianDayDifference() const