.TH Animation
 6 "IRIT Version 7.0" 
.SH NAME
Animation



The animation tool adds the capability of animating objects using
forward kinematics, exploiting animation curves.  Each object has
different attributes, that prescribe its motion, scale, and visibility
as a function of time. Every attribute has a name, which designates
it's role. For instance an attribute animation curve named MOV_X
describes a translation motion along the X axis.

.SH How to create animation curves in IRIT



Let OBJ be an object in IRIT to animate.

Animation curves are either scalar (E1/P1) curves or three dimensional
(E3/P3) curves with one of the following name prefixes:

     MOV_X, MOV_Y, MOV_Z            Translation along one axis 
     MOV_XYZ                        Arbitrary translation along all three axes
     ROT_X, ROT_Y, ROT_Z            Rotating around a single axis (degrees)
     SCL_X, SCL_Y, SCL_Z            Scale along a single axis  
     SCL                            Global scale               
     VISIBLE                        Visibility                 


The visibility curve is a scalar curve that enables the display of
the object if the visibility curve is positive at time t and disables
the display (hide) the object if the visibility curve is negative at
time t.

The animation curves are all attached as an attribute named "animation"
to the object OBJ.

Example:
    mov_x = cbezier( ctlpt( E1, 0.0 ),
                     ctlpt( E1, 1.0 ) );
    scl   = cbezier( ctlpt( E1, 1.0 ),
                     ctlpt( E1, 0.1 ) );
    rot_y = cbezier( ctlpt( E1, 0.0 ),
                     ctlpt( E1, 0.0 ) );
                     ctlpt( E1, 360.0 ) );
    attrib(OBJ, "animation", list( mov_x, scl, rot_y ) );

To animate OBJ between time zero and one (Bezier curves are always
between zero and one), by moving it a unit size in the X direction,
scaling it to %10 of its original size and rotating it at increasing
angular speed from zero to 360 degrees.

OBJ can now be save into a file or displayed via one of the regular
viewing commands in IRIT (i.e. VIEWOBJ).

Animation is not always between zero and one. To that end, one can
apply the CREPARAM function to modify the parametric domain of the
animation curve. The convention is that if the time is below the
starting value of the parametric domain, the starting value of the
curve is used.  Similarly if the time is beyond the end of the
parameter domain of the animation curve, the end value of the
animation curve is used.

Example:
    CREPARAM( mov_x, 3.0, 5.0 );

to set the time of the motion in the x axis to be from t = 3 to
t = 5.  for t < 3, mov_x(3) is used, and for t > 5, mov_x(5) is
employed.

the animation curves are regular objects in the IRIT system. Hence,
only one object named mov_x or scl can exist at one time. If you
create a new object named mov_x, the old one is overwritten! To
preserve old animation curves you can detach the old ones by executing
'free(mov_x)' that removes the object named mov_x from IRIT's object
list but not from its previous used locations within other list
objects, if any.  A different way to it call this animation curves
mov_x1, mov_x2 etc. as only the prefix of the name is verified.

For example:

    mov_x = cbezier( ctlpt( E1, 0.0 ),
                     ctlpt( E1, 1.0 ) );
    attrib(obj1, "animation", list( mov_x ) );
    free(mov_x);

    mov_x1 = cbezier( ctlpt( E1, 2.0 ),
                      ctlpt( E1, 3.0 ) );
    mov_x2 = cbezier( ctlpt( E1, 2.0 ),
                      ctlpt( E1, 3.0 ) );
    attrib(obj2, "animation", list( mov_x1, mov_x2 ) );
    free(mov_x);

notice the way we have two animation curves translating obj2 in x.
This is somewhat artificial but might make more sense if other
transformations would appear in between.

.SH A more complete animation example



  a = box( vector( 0, 0, 0 ), 1, 1, 1 );
  b = box( vector( 0, 0, 0 ), 1, 1, 1 );
  c = box( vector( 0, 0, 0 ), 1, 1, 1 );
  d = sphere( vector( 0, 0, 0), 0.7 );
  
  pt0   =  ctlpt( e1,  0.0 );
  pt1   =  ctlpt( e1,  1.0 );
  pt2   =  ctlpt( e1,  2.0 );
  pt6   =  ctlpt( e1,  6.0 );
  pt360 =  ctlpt( e1,  360.0 );
  
  pt10 = ctlpt( e1, -4.0 );
  pt11 = ctlpt( e1,  1.0 );
  pt12 = ctlpt( e1,  4.0 );
  pt13 = ctlpt( e1, -1.0 );
  
  visible = creparam( cbezier( list( pt10,  pt11 ) ), 0.0, 5.0 );
  mov_x   = creparam( cbezier( list( pt0, pt6, pt2 ) ), 0.0, 1.2 );
  mov_y   = mov_x;
  mov_z   = mov_x;
  rot_x   = creparam( cbspline( 2,
                                list( pt0, pt360, pt0 ),
                                list( KV_OPEN ) ),
                      1.2, 2.5 ); 
  rot_y   = rot_x;
  rot_z   = rot_x;
  scl     = creparam( cbezier( list( pt1, pt2, pt1, pt2, pt1 ) ),
                      2.5, 4.0 );
  scl_x   = scl;
  scl_y   = scl;
  scl_z   = scl;
  mov_xyz = creparam( circle( vector( 0, 0, 0 ), 2.0 ), 4.0, 5.0 );
  
  attrib( d, "animation", list( mov_xyz, visible ) );
  free( visible );
  
  visible = creparam( cbezier( list( pt12,  pt13 ) ), 0.0, 5.0 );
  
  attrib( a, "animation", list( rot_x, mov_x, scl, scl_x, visible ) );
  attrib( b, "animation", list( rot_y, mov_y, scl, scl_y, visible ) );
  attrib( c, "animation", list( rot_z, mov_z, scl, scl_z, visible ) );
  
  color( a, red );
  color( b, green );
  color( c, blue );
  color( d, cyan );
  
  demo = list( a, b, c, d );
  
  interact( demo );
  viewanim( 0, 5, 0.01 );

In this example, we create four objects, three cubes and one sphere.
Animation curves to translate the three cubes along the three axes for
the time period of t = 0 to t = 1.2 are created. Rotation curves to
rotate the three cubes along the three axes are then created for time
period of t = 1.2 to t = 2.5. Finally, for the time period of t = 2.5
to t = 4.0. the cubes are (not only) unifomly scaled. For the time
period of t = 4 to t = 5, the cubes become invisible and the sphere,
that becomes visible, is rotated along a circle of radius 2.

.SH Another complete animation example



This example demonstrates the ability to put "animation" attributes
on internal nodes of a hierarchy, affecting the entire set of objects
in the hierachy.   Herein, we present an robotic arm with three edges
and two joints.

    BoxLength = 2;
    BoxWidth = 2;
    BoxHeight = 10;
    
    LowerBox = box( vector( -BoxLength / 2, -BoxWidth / 2, 0 ),
                    BoxLength, BoxWidth, BoxHeight);
    MiddleBox = box( vector( -BoxLength / 2, -BoxWidth / 2, 0 ),
                     BoxLength, BoxWidth, BoxHeight);
    UpperBox = box( vector( -BoxLength / 2, -BoxWidth / 2, 0 ),
                    BoxLength, BoxWidth, BoxHeight);
    Cn1 = cone( vector( 0, 0, 0 ), vector( 0, BoxHeight / 3, 0 ), 1 );
    
    color( LowerBox, magenta );
    color( MiddleBox, yellow );
    color( UpperBox, cyan );
    color( Cn1, green );
    
    rot_x1 = creparam( cbspline( 3,
                                 list( ctlpt( E1,  0 ),
                                       ctlpt( E1,  -200 ),
                                       ctlpt( E1,  200 ),
                                              ctlpt( E1,  0 ) ),
                                 list( KV_OPEN ) ),
                       0, 3 );
    rot_x2 = creparam( cbspline( 4,
                                 list( ctlpt( E1,  0 ),
                                       ctlpt( E1,  400 ),
                                       ctlpt( E1,  -400 ),
                                              ctlpt( E1,  0 ) ),
                                 list( KV_OPEN ) ),
                       0, 3 );
    rot_y = creparam( cbspline( 2,
                                list( ctlpt( E1,  0 ),
                                      ctlpt( E1,  100 ),
                                      ctlpt( E1, -100 ),
                                      ctlpt( E1,  0 ) ),
                                list( KV_OPEN ) ),
                      0, 3 );
    rot_z = creparam( cbspline( 2,
                                list( ctlpt( E1,  0 ),
                                      ctlpt( E1,  1440 ) ),
                                list( KV_OPEN ) ),
                      0, 3 );
    Translate = trans( vector( 0, 0, BoxHeight ) );
    
    attrib( Cn1, "animation", list( rot_z, Translate ) );
    
    Upr = list( Cn1, UpperBox );
    attrib( Upr, "animation", list( rot_y, Translate ) );
    
    Mid = list( Upr, MiddleBox );
    attrib( Mid, "animation", list( rot_x2, Translate ) );
    
    rbt_hand = list( Mid, LowerBox );
    attrib( rbt_hand, "animation", list( rot_x1 ) );
    
    view( rbt_hand, 1 );

In this example, we create four objects, three cubes and one cone,
simulating a robotic hand with three edges an a gripper (the cone).
The animation is define hierarchically, making it very easy to model
the robot.
