Provided by: liballegro-doc_4.2.2-3_all bug


       exspline - Constructing smooth movement paths from spline curves. Allegro game programming


       #include <allegro.h>

       Example exspline


       This program demonstrates the use of spline curves to create  smooth  paths  connecting  a
       number  of  node  points.  This  can  be  useful  for  constructing  realistic  motion and

       The technique is to connect the series of guide points p1..p(n) with  spline  curves  from
       p1-p2,  p2-p3, etc. Each spline must pass though both of its guide points, so they must be
       used as the first and fourth of the spline control points. The fun bit is coming  up  with
       sensible  values  for  the  second  and  third spline control points, such that the spline
       segments will have equal gradients where they meet. I came up with the following solution:

       For each guide point p(n), calculate the desired tangent to the curve  at  that  point.  I
       took  this  to  be  the  vector  p(n-1) -> p(n+1), which can easily be calculated with the
       inverse tangent function, and gives decent looking results. One  implication  of  this  is
       that  two  dummy  guide  points are needed at each end of the curve, which are used in the
       tangent calculations but not connected to the set of splines.

       Having got these tangents, it becomes fairly easy to calculate the spline control  points.
       For a spline between guide points p(a) and p(b), the second control point should lie along
       the positive tangent from p(a), and the third control point should lie along the  negative
       tangent  from p(b). How far they are placed along these tangents controls the shape of the
       curve: I found that applying a 'curviness' scaling factor to the distance between p(a) and
       p(b) works well.

       One  thing  to  note  about  splines is that the generated points are not all equidistant.
       Instead they tend to bunch up nearer to the ends of the spline, which means you will  need
       to  apply  some fudges to get an object to move at a constant speed. On the other hand, in
       situations where the curve has a noticeable change of direction at each guide  point,  the
       effect can be quite nice because it makes the object slow down for the curve.


       END_OF_MAIN(3alleg),      SCREEN_W(3alleg),     acquire_screen(3alleg),     alert(3alleg),
       allegro_error(3alleg), allegro_init(3alleg), allegro_message(3alleg), calc_spline(3alleg),
       circlefill(3alleg), clear_keybuf(3alleg), clear_to_color(3alleg), desktop_palette(3alleg),
       fixatan2(3alleg),   fixcos(3alleg),   fixed(3alleg),    fixmul(3alleg),    fixsin(3alleg),
       fixsqrt(3alleg),    fixtof(3alleg),    fixtoi(3alleg),    font(3alleg),    ftofix(3alleg),
       install_keyboard(3alleg),  install_mouse(3alleg),  install_timer(3alleg),  itofix(3alleg),
       key(3alleg),    keypressed(3alleg),    line(3alleg),   makecol(3alleg),   mouse_b(3alleg),
       mouse_x(3alleg),     mouse_y(3alleg),      palette_color(3alleg),      poll_mouse(3alleg),
       readkey(3alleg),     release_screen(3alleg),     screen(3alleg),     set_gfx_mode(3alleg),
       set_palette(3alleg),   show_mouse(3alleg),   spline(3alleg),    textout_centre_ex(3alleg),
       textprintf_centre_ex(3alleg), textprintf_ex(3alleg), vsync(3alleg), xor_mode(3alleg)