X-Git-Url: https://eleni.mutantstargoat.com/git/?a=blobdiff_plain;f=src%2Fmain.cc;h=64ce2fc2e3a7bfac01dce7f27f276cfc79f87fde;hb=08dfe45a9c75333375791380ed5ed44ceda1e904;hp=669ede3f0a4e0ba1d6fd73b265cd74d9f3940b58;hpb=e288b11ca263beae92f508ca53e1500f0ce68377;p=faros-demo diff --git a/src/main.cc b/src/main.cc index 669ede3..64ce2fc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,6 +3,7 @@ #include #include +#include #include "sdr.h" @@ -15,6 +16,17 @@ #define BEAM_RMIN 0.01 #define BEAM_RMAX 0.125 #define BEAM_ENERGY 0.02 +#define BEAM_LEN 16.0 + +#define BEAM_START_ANGLE 180 +#define BEAM_STOP_ANGLE 359 + +enum State { + ST_DEFAULT, + ST_CAM_WAIT, + ST_CAM_STOP, + ST_XLOGO +}; static bool init(); static void cleanup(); @@ -23,6 +35,9 @@ static void faros(); static void light(); static void ground(); static void backdrop(); +static void xlogo(); + +static void update_anim(); static void display(); static void idle(); @@ -31,10 +46,21 @@ static void keyboard(unsigned char c, int x, int y); static void mbutton(int bn, int state, int x, int y); static void mmotion(int x, int y); +static inline float smoothstep(float a, float b, float x); + static float cam_theta = 45, cam_phi, cam_dist = 10; static unsigned int sdr_curve_top, sdr_beam, sdr_sky; -static unsigned int start_time; -static float beam_rot_speed = 0.1; +static long start_time; +static float anim_speed = 1.0; +static long anim_stop_time; +static long tmsec; +static float beam_speed = 0.1; +static float beam_angle; +static float prev_beam_angle; +static State state; + +static const float sil_color[] = {0.05, 0.02, 0.1, 1.0}; +static const float beam_color[] = {0.5, 0.4, 0.2, 1.0}; int main(int argc, char **argv) { @@ -94,7 +120,7 @@ static void cleanup() static void faros() { - glColor3f(0, 0, 0); + glColor3fv(sil_color); // kormos glPushMatrix(); @@ -171,7 +197,7 @@ static void faros() glScalef(1, 1, 0.45); glutSolidCylinder(1, 1, 4, 16); glPopMatrix(); - + bind_program(0); } @@ -184,6 +210,7 @@ static void light() glTranslatef(0, 4.65, 0.2); bind_program(sdr_beam); + set_uniform_float(sdr_beam, "beam_len", BEAM_LEN); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); @@ -191,11 +218,11 @@ static void light() for(int i=0; i= BEAM_START_ANGLE && prev_beam_angle < BEAM_START_ANGLE) { + state = ST_CAM_STOP; + printf("func: %s\n", __func__); + printf("state from wait to stop (ba: %f)\n", beam_angle); + beam_start_time = tmsec; + beam_stop_interval = beam_angle / beam_speed; // 400 / beam_speed; + printf(" stop interval: %f\n", beam_stop_interval); + } + } + if(state == ST_CAM_STOP) { + float t = smoothstep(beam_start_time, beam_start_time + beam_stop_interval, tmsec); + prev_beam_angle = beam_angle; + beam_angle = BEAM_START_ANGLE + (BEAM_STOP_ANGLE - BEAM_START_ANGLE) * t; + + if(t >= 1) { + printf("state from stop to xlogo\n"); + state = ST_XLOGO; + } + } else if(state == ST_XLOGO) { + + } else { + prev_beam_angle = beam_angle; + beam_angle = fmod(tanim * beam_speed * 360, 360.0); + } +} + +static void display() +{ + if(anim_stop_time > 0) { + tmsec = anim_stop_time - start_time; + } else { + tmsec = (long)glutGet(GLUT_ELAPSED_TIME) - start_time; + } + + update_anim(tmsec); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); backdrop(); @@ -247,8 +321,6 @@ static void display() glPushMatrix(); - float beam_angle = tsec * beam_rot_speed * 360; - glRotatef(beam_angle, 0, 1, 0); light(); @@ -272,11 +344,61 @@ static void reshape(int x, int y) gluPerspective(50, (float)x / (float)y, 0.5, 500); } +static long calc_timeshift(float prev_speed, float speed) +{ + long delta = tmsec * speed - tmsec * prev_speed; + return delta / speed; +} + +#define ANIM_DELTA 0.5 + static void keyboard(unsigned char c, int x, int y) { + float prev_anim_speed; + switch(c) { case 27: exit(0); + + case ' ': + if(anim_stop_time > 0) { + start_time += glutGet(GLUT_ELAPSED_TIME) - anim_stop_time; + anim_stop_time = 0; + } else { + anim_stop_time = glutGet(GLUT_ELAPSED_TIME); + } + break; + + case '=': + start_time += calc_timeshift(anim_speed, anim_speed + ANIM_DELTA); + anim_speed += ANIM_DELTA; + break; + + case '-': + prev_anim_speed = anim_speed; + anim_speed -= ANIM_DELTA; + if(anim_speed < 0) + anim_speed = 0; + start_time += calc_timeshift(prev_anim_speed, anim_speed); + break; + + case '\n': + case '\r': + switch(state) { + case ST_DEFAULT: + state = ST_CAM_WAIT; + prev_beam_angle = beam_angle; + printf("from default to cam_wait\n"); + break; + case ST_XLOGO: + printf("from xlogo to default\n"); + state = ST_DEFAULT; + start_time = tmsec; + break; + default: + break; + } + break; default: break; } @@ -322,3 +444,12 @@ static void mmotion(int x, int y) cam_dist = 0; } } + +static inline float smoothstep(float a, float b, float x) +{ + if(x < a) return 0.0f; + if(x >= b) return 1.0f; + + x = (x - a) / (b - a); + return x * x * (3.0f - 2.0f * x); +}