diff options
-rwxr-xr-x | src/main.cpp | 117 |
1 files changed, 82 insertions, 35 deletions
diff --git a/src/main.cpp b/src/main.cpp index b272f67..c658614 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,41 +45,40 @@ static const GLUvec4 linear_control_points[] = { GLUvec4(0.0, 1.5f, 10.0f, 0.0f), GLUvec4(10.0, 1.5f, 0.0f, 0.0f), GLUvec4(-30.0, 1.5f, -30.0f, 0.0f), - }; /** * Basic C0 cameara control curves that hit the points in linear_control_points - * - * FINISHME: Fill these in. */ -#if 0 static const bezier_curve camera_curves[] = { - bezier_curve(GLUvec4(...), // start point - GLUvec4(...), // control - GLUvec4(...), // control - GLUvec4(...)), // end point - ... + bezier_curve(linear_control_points[0], // start point + GLUvec4(10.0f, 3.5f, 20.0f, 0.0f), // control + GLUvec4(15.0f, 3.5f, 5.0f, 0.0f), // control + linear_control_points[1]), // end point + bezier_curve(linear_control_points[1], + GLUvec4(15.0f, 1.5f, -20.0f, 0.0f), + GLUvec4(-10.0f, 1.5f, -35.0f, 0.0f), + linear_control_points[2]), + bezier_curve(linear_control_points[2], + GLUvec4(-40.0f, -0.5f, -10.0f, 0.0f), + GLUvec4(-25.0f, -0.5f, 12.0f, 0.0f), + linear_control_points[0]), + }; -#endif /** * Control curves from camera_curves "fixed" to be G1. * * \sa make_curves_g1 */ -#if 0 static bezier_curve camera_curves_G1[ELEMENTS_OF(camera_curves)]; -#endif /** * Control curves from camera_curves "fixed" to be C1. * * \sa make_curves_c1 */ -#if 0 static bezier_curve camera_curves_C1[ELEMENTS_OF(camera_curves)]; -#endif /** * Positions in 3-space of the spheres. @@ -103,7 +102,8 @@ static float specular_exponent[ELEMENTS_OF(sphere_locations)] = { */ enum { camera_linear, - camera_G0, + camera_C0, + camera_G1, camera_C1, } camera_mode = camera_linear; @@ -162,6 +162,47 @@ Redisplay(const patch_set_info *info) static void +update_camera(float total_t) +{ + /* Figure out which segment is active based on the + * following rules: + * Segment 0 is active from [0, 4) seconds (4 seconds) + * Segment 1 is active from [4, 6) seconds (2 seconds) + * Segment 2 is active from [6, 10) seconds (4 seconds) + * + * Also map the time to the interval [0, 1] (t_segment) + */ + int active_segment; + float t_segment; + if (total_t < 4.0) { + active_segment = 0; + t_segment = total_t / 4.0; + } else if (total_t < 6.0) { + active_segment = 1; + t_segment = (total_t - 4.0) / 2.0; + } else { + active_segment = 2; + t_segment = (total_t - 6.0) / 4.0; + } + + switch (camera_mode) { + case camera_linear: + eye = (1.0 - t_segment) * linear_control_points[active_segment] + t_segment * linear_control_points[(active_segment + 1) % ELEMENTS_OF(linear_control_points)]; + break; + case camera_C0: + eye = camera_curves[active_segment].position(t_segment); + break; + case camera_G1: + eye = camera_curves_G1[active_segment].position(t_segment); + break; + case camera_C1: + eye = camera_curves_C1[active_segment].position(t_segment); + break; + }; +} + + +static void Idle(void) { static Uint32 last_t = ~0; @@ -174,24 +215,10 @@ Idle(void) if (anim) { static float total_t = 0.0; - /* FINISHME: Perform some calculations so that the - * FINISHME: timer wraps around to zero when the last - * FINISHME: segment of the camera track is completed. - */ + // Make the timer wrap around to zero after 10 seconds. total_t = fmod(total_t + dt, 10.0); - /* FINISHME: Based on the timer, determine which - * FINISHME: segment of the camera track is active. - */ - - /* FINISHME: Calculate t_segment as the time within the - * FINISHME: active segment. - */ - - - /* FINISHME: Calculate the camera position from the - * FINISHME: active segement and t_segment. - */ + update_camera(total_t); } } @@ -334,6 +361,10 @@ Init(void) printf("Keyboard input:\n" " f: Toggle fullscreen.\n" " a: Toggle animation of object.\n" + " 1: Use linear interpolation for camera position.\n" + " 2: Use C0 bezier curves for camera position.\n" + " 3: Use G1 bezier curves for camera position.\n" + " 4: Use C1 bezier curves for camera position.\n" " c: Re-load and compile shader program code.\n" " ESC: Exit program.\n"); @@ -370,18 +401,34 @@ Key(SDLKey sym, bool state) if (!state) return; - /* FINISHME: Add controls to cycle through the 3 camera control modes. - */ - switch (sym) { case SDLK_ESCAPE: done = true; break; - case 'f': SDL_WM_ToggleFullScreen(my_surf); break; + case '1': + printf("Switching to linear camera...\n"); + camera_mode = camera_linear; + break; + + case '2': + printf("Switching to C0 camera...\n"); + camera_mode = camera_C0; + break; + + case '3': + printf("Switching to G1 camera...\n"); + camera_mode = camera_G1; + break; + + case '4': + printf("Switching to C1 camera...\n"); + camera_mode = camera_C1; + break; + case ' ': case 'a': anim = !anim; |