Skip to content
Snippets Groups Projects
Commit 3d9d9818 authored by Oliver Bock's avatar Oliver Bock
Browse files

Added proper timing

* For sphere rotation
* For observatory positioning

Note: the original code seems to have a bug which explains a slight discrepancy between this new and the original visualisation.
In the original code gmt_dtime() is used to get the GMT time, but this function is a mere #define of dtime() under unix, hence any
difference of dtime() and gmt_dtime() will result in 0 instead of the real UTC/GMT offset.

Note: dtime() returns local time...
parent 9095e470
No related branches found
No related tags found
No related merge requests found
......@@ -27,10 +27,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);
......
......@@ -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 */
......
......@@ -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 {
......
......@@ -8,6 +8,8 @@
#include <SDL.h>
#include <util.h>
#include "AbstractGraphicsEngine.h"
using namespace std;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment