diff --git a/Starsphere.cpp b/Starsphere.cpp index 67d743bccc7c20e4558a12770f345d70a50ad642..a2e7b2ac73673a3051998a70419809a13341402b 100644 --- a/Starsphere.cpp +++ b/Starsphere.cpp @@ -26,10 +26,6 @@ Starsphere::Starsphere() : AbstractGraphicsEngine() rotation_offset = 0.0; rotation_speed = 180.0; - - /* Time info */ - gmt_offset=0.0; - show_gmt=true; m_RefreshSearchMarker = true; } @@ -224,11 +220,12 @@ void Starsphere::make_obs() GLfloat arm_len_deg=3.000; // lenght of arms, in degrees (not to scale) GLfloat h2=0.400; // slight offset for H2 arms - double obs_gmt_dtime; // current time in GMT to get zenith position - - obs_gmt_dtime = 0.0; //FIXME: gmt_dtime(); // Current GMT time - obs_dtime_drawn = 0.0; //FIXME:dtime(); // dtime() not gmt_dtime(), for difference - gmt_offset = obs_gmt_dtime - obs_dtime_drawn; // save for GMT display + // get current time and UTC offset (for zenith position) + m_ObservatoryDrawTimeLocal = dtime(); + time_t local = m_ObservatoryDrawTimeLocal; + tm *utc = gmtime(&local); + double utcOffset = difftime(local, mktime(utc)); + double observatoryDrawTimeGMT = m_ObservatoryDrawTimeLocal - utcOffset; radius = 1.0*sphRadius; // radius of sphere on which they are drawn @@ -241,7 +238,7 @@ void Starsphere::make_obs() Lat= 30.56377; Lon= 90.77408; - RAdeg= RAofZenith(obs_gmt_dtime, Lon); + RAdeg= RAofZenith(observatoryDrawTimeGMT, Lon); DEdeg= Lat; if (!LLOmarker) @@ -270,7 +267,7 @@ void Starsphere::make_obs() Lat= 46.45510; Lon= 119.40627; - RAdeg= RAofZenith(obs_gmt_dtime, Lon); + RAdeg= RAofZenith(observatoryDrawTimeGMT, Lon); DEdeg= Lat; if (!LHOmarker) @@ -312,7 +309,7 @@ void Starsphere::make_obs() Lon= -9.80683; arm_len_deg=1.50; // not to scale - RAdeg= RAofZenith(obs_gmt_dtime, Lon); + RAdeg= RAofZenith(observatoryDrawTimeGMT, Lon); DEdeg= Lat; if (!GEOmarker) @@ -501,9 +498,6 @@ void Starsphere::resize(const int width, const int height) glLoadIdentity(); gluPerspective(95.0, aspect, 0.50, 25.0); glMatrixMode(GL_MODELVIEW); - - // Update in case time (zone?) change - gmt_offset = 2; //FIXME: gmt_dtime() - dtime(); } /** @@ -661,7 +655,7 @@ void Starsphere::render(const double timeOfDay) if (isFeature(OBSERVATORIES)) { glPushMatrix(); - Zobs = (timeOfDay - obs_dtime_drawn) * 15.0/3600.0; + Zobs = (timeOfDay - m_ObservatoryDrawTimeLocal) * 15.0/3600.0; glRotatef(Zobs, 0.0, 1.0, 0.0); glCallList(LLOmarker); glCallList(LHOmarker); diff --git a/Starsphere.h b/Starsphere.h index ce4431e070cf305ac8d2bb321dfb96209459c94a..ad23c31fab9b61fd1b31fc2e653ca9ae17aba5c9 100644 --- a/Starsphere.h +++ b/Starsphere.h @@ -3,6 +3,7 @@ #include <cmath> #include <cstdio> +#include <ctime> #include <string> #include <iostream> #include <iomanip> @@ -12,6 +13,8 @@ #include <SDL_opengl.h> #include <FTGLPolygonFont.h> +#include <util.h> + #include "AbstractGraphicsEngine.h" /* SIN and COS take arguments in DEGREES */ @@ -93,11 +96,6 @@ private: GLfloat rotation_offset; // so that we can rotate sphere GLfloat rotation_speed; // degrees per minute - /* Time info */ - double obs_dtime_drawn; // dtime() when obs were drawn - double gmt_offset; // dtime() correction to get GMT - bool show_gmt; // show clock or not? - // Graphics state info: float aspect; @@ -139,9 +137,14 @@ private: string m_WUPercentDone; string m_WUCPUTime; + // search marker info double m_CurrentRightAscension; double m_CurrentDeclination; bool m_RefreshSearchMarker; + + // observatory movement + // (in seconds since 1970 with usec precision) + double m_ObservatoryDrawTimeLocal; }; /* Constellation & star coordinates are in starlist.C */ diff --git a/WindowManager.cpp b/WindowManager.cpp index c6e4cf15814a5bedb148bb66ba2c5d4b539830aa..2e7189b50ab6368fa181bb399175b80b2fa2bf6a 100644 --- a/WindowManager.cpp +++ b/WindowManager.cpp @@ -152,17 +152,17 @@ void WindowManager::eventLoop() SDL_Event event; - static double i = 0.0; - while (SDL_WaitEvent(&event) ) { if (event.type == SDL_USEREVENT && event.user.code == RenderEvent) { + static int i = 0; #ifdef DEBUG_VALGRIND - if(i < 12.5) { + if(i < 500) { + i++; #endif // notify our observers (currently exactly one) - eventObservers.front()->render(i += 0.025); + eventObservers.front()->render(dtime()); #ifdef DEBUG_VALGRIND } else { diff --git a/WindowManager.h b/WindowManager.h index af954b881d9126ed1b21dc76e123ce4af2ba007e..2daa714e9391a733303e4074da79699fc8f4cc6d 100644 --- a/WindowManager.h +++ b/WindowManager.h @@ -8,6 +8,8 @@ #include <SDL.h> +#include <util.h> + #include "AbstractGraphicsEngine.h" using namespace std;