diff options
author | Kenneth Graunke <kenneth@whitecape.org> | 2010-10-20 22:10:20 -0700 |
---|---|---|
committer | Kenneth Graunke <kenneth@whitecape.org> | 2010-10-21 00:30:57 -0700 |
commit | ea3656422bf5b0f3e7961052b55343cf91e4935f (patch) | |
tree | 777bfbd68dba9e60bab8fce17ae65cc9d029135e | |
parent | 09b288fa25f47975a9cb7159936fe55654f07277 (diff) |
Implement G1 and C1 curve conversion.
-rwxr-xr-x | src/main.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/main.cpp b/src/main.cpp index c658614..f5ee54a 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -306,8 +306,8 @@ void make_curves_G1(const bezier_curve &s0, const bezier_curve &s1, bezier_curve &d0, bezier_curve &d1) { - /* FINISHME: Implement this function. - */ + GLUvec4 moved_point = s1[0] + (s0[3] - s0[2]); + d1 = bezier_curve(s1[0], moved_point, s1[2], s1[3]); } @@ -327,8 +327,25 @@ void make_curves_C1(const bezier_curve &s0, const bezier_curve &s1, bezier_curve &d0, bezier_curve &d1) { - /* FINISHME: Implement this function. + /* The derivative of s0 at t = 1.0 is: + * 3(s0[3] - s0[2]) + * + * The derivative of s1 at t = 0.0 is: + * 3(s1[1] - s1[0]) + * + * To achieve C1 continuity, we need to make the curve differentiable + * everywhere (in particular, at the joint point between these curves). + * To do so, the two derivatives must be equal: + * + * 3(s1[1] - s1[0]) = 3(s0[3] - s0[2]) + * s1[1] - s1[0] = s0[3] - s0[2] + * + * Notably since s0[3] = s1[0] + * s1[1] - s1[0] = s1[0] - s0[2] + * s1[1] = 2*s1[0] - s0[2] */ + GLUvec4 moved_point = s1[0] + 2*s1[0] - s0[2]; + d1 = bezier_curve(s1[0], moved_point, s1[2], s1[3]); } @@ -368,11 +385,19 @@ Init(void) " c: Re-load and compile shader program code.\n" " ESC: Exit program.\n"); - /* FINISHME: Invoke make_curves_G1 here to fix the basic curves. - */ + for (int i = 0; i < 3; i++) { + camera_curves_G1[i] = camera_curves[i]; + camera_curves_C1[i] = camera_curves[i]; + } - /* FINISHME: Invoke make_curves_C1 here to fix the basic curves. - */ + for (int i = 0; i < 3; i++) { + int next = (i + 1) % 3; + make_curves_G1(camera_curves_G1[i], camera_curves_G1[next], + camera_curves_G1[i], camera_curves_G1[next]); + + make_curves_C1(camera_curves_C1[i], camera_curves_C1[next], + camera_curves_C1[i], camera_curves_C1[next]); + } } |