/*----------------------------------------------------------------------------
 *      req.c
 *  
 *     This file contains the stucture declarations and initializations
 * required by the pop-up requesters.  The requesters contain gadgets that 
 * accept user input.
 *     Two types of gadgets are used here, boolean gadgets and proportional
 *  gadgets.
 *     Proportional gadgets allow the conversion of a slider setting into
 * a floating point number usable by the program.  Proportional gadgets
 * also display to the user the current setting of this variable.  In this
 * case the current joint angles for each link are displayed for the user.
 *     Boolean gadgets simply note the request made based on what gadget
 * was selected.
 *----------------------------------------------------------------------------
*/

#include   <exec/types.h>
#include   <intuition/intuition.h>
#include   "defs.h"
#include   "ds.h"

extern struct TextAttr  prog_font ;
extern struct Window    *window ;
extern ROTATION_INFO    rot_info ;


struct Requester  get_shoulder_angles,
                  get_elbow_angle,
                  get_wrist_angles,
                  anim_info,
                  anim_cancel_set,
                  anim_cancel_rot,
                  no_change,
                  author_info,
                  req_rot_info ;
                  

struct Gadget     x_shoulder_angle,  x_elbow_angle,  x_wrist_angle,
                  y_shoulder_angle,  y_wrist_angle,
                  z_shoulder_angle,  z_wrist_angle,
                  req_cancel_elbow,  req_test_elbow,  req_ok_elbow,
                  req_cancel_wrist,  req_test_wrist,  req_ok_wrist,
                  req_cancel_shoulder,  req_test_shoulder,  req_ok_shoulder,
                  gadg_anim_cancel_set_yes,  gadg_anim_cancel_set_no,
                  gadg_anim_cancel_rot_yes,  gadg_anim_cancel_rot_no,
                  gadg_anim_info,  gadg_no_change, gadg_rot_info ;

struct IntuiText  req_ok_text,  req_test_text,  req_cancel_text, 
                  req_shoulder_text,  req_elbow_text,  req_wrist_text,
                  anim_info_text,  no_change_text,  anim_cancel_text, 
                  anim1_info_text,  no_change1_text,  anim_cancel1_text, 
                  y_angle_shoulder_text,  y_angle_wrist_text, 
                  z_angle_shoulder_text,  z_angle_wrist_text, 
                  x_angle_shoulder_text,  x_angle_wrist_text, 
                  x_angle_elbow_text,  rot_info_text,  rot1_info_text,
                  rot2_info_text,  yes_text,  no_text,  ok_text,
                  author_text,  author1_text,  author2_text,  author3_text ;

USHORT            x_sh_hpot  = 0xffff / 2,
                  y_sh_hpot  = (0xffff / 3) * 2,
                  z_sh_hpot  = 0xffff / 2, 
                  x_wr_hpot  = (0xffff / 3) * 2,
                  y_wr_hpot  = 0xffff / 2,
                  z_wr_hpot  = 0xffff / 4, 
                  x_el_hpot  = 0xffff ;

struct PropInfo   x_shoulder_prop,  x_elbow_prop,  x_wrist_prop,
                  y_shoulder_prop,  y_wrist_prop,
                  z_shoulder_prop,  z_wrist_prop ;

struct Image      x_shoulder_image,  x_wrist_image,  x_elbow_image,
                  y_shoulder_image,  y_wrist_image,
                  z_shoulder_image,  z_wrist_image ;

struct Border     req_border_sh,  req_border_wr,  req_border_el, 
                  x_zero_sh,  y_zero_sh,  z_zero_sh, 
                  x_zero_wr,  y_zero_wr,  z_zero_wr, 
                  x_zero_el,  req_gadget_border,
                  query_border,  query_border1,   ok_border,  ok_border1 ;

SHORT  gadget_border_outline []     = {0,0, 51,0, 51,9, 0,9, 0,0} ;
SHORT  ok_border1_outline []        = {-5,-3, 35,-3, 35,12, -5,12, -5,-3} ;
SHORT  ok_border_outline []         = {-2,-1, 32,-1, 32,10, -2,10, -2,-1} ;
SHORT  req_border_outline []        = {0,0, 239,0, 239,85, 0,85, 0,0} ;
SHORT  req_border_outline_elbow []  = {0,0, 239,0, 239,47, 0,47, 0,0} ;
SHORT  query_border_outline []      = {0,0, 311,0, 311,43, 0,43, 0,0} ;
SHORT  query_border1_outline []     = {4,2, 307,2, 307,41, 4,41, 4,2} ;
SHORT  zero_line  []                = {0,0, 10,0} ; 


initialize_requesters ()
{
 /*---------------------------------------------------------------------------
  *    Initialize all the structures required by the requesters and hook them
  * together with pointers for use by Intuition.
  *---------------------------------------------------------------------------
 */
 init_borders (114, 69, 7, &z_zero_sh, 2, zero_line, NULL) ;
 init_borders (148, 50, 7, &y_zero_sh, 2, zero_line, &z_zero_sh) ;
 init_borders (114, 31, 7, &x_zero_sh, 2, zero_line, &y_zero_sh) ;
 init_borders ( 63, 69, 7, &z_zero_wr, 2, zero_line, NULL) ;
 init_borders (114, 50, 7, &y_zero_wr, 2, zero_line, &z_zero_wr) ;
 init_borders (148, 31, 7, &x_zero_wr, 2, zero_line, &y_zero_wr) ;
 init_borders (215, 31, 7, &x_zero_el, 2, zero_line, NULL) ;
 init_borders (0, 0, 1, &req_gadget_border, 5, gadget_border_outline, NULL) ;
 init_borders (0, 0, 6, &query_border, 5, &query_border_outline,
                                                         &query_border1) ;       
 init_borders (0, 0, 4, &query_border1, 5, &query_border1_outline, NULL) ;
                                               
 init_borders (0, 0, 1, &ok_border, 5, &ok_border_outline, &ok_border1) ;
 init_borders (0, 0, 7, &ok_border1, 5, &ok_border1_outline, NULL) ;
 init_borders (0, 0, 1, &req_border_sh, 5, req_border_outline, &x_zero_sh) ;
 init_borders (0, 0, 1, &req_border_wr, 5, req_border_outline, &x_zero_wr) ;
 init_borders (0, 0, 1, &req_border_el, 5, req_border_outline_elbow,
                                                           &x_zero_el) ;

 init_req_text (&req_ok_text, 14, 1, "use", NULL, COLOR7) ;
 init_req_text (&req_test_text, 10, 1, "test", NULL, COLOR7) ;
 init_req_text (&req_cancel_text, 2, 1, "cancel", NULL, COLOR7) ;

 init_req_text (&z_angle_shoulder_text, 6, -9, "-60       z axis       +60",
                                                               NULL, COLOR7) ;
 init_req_text (&z_angle_wrist_text, 6, -9, "-30       z axis       +90",
                                                               NULL, COLOR7) ;
 init_req_text (&y_angle_shoulder_text, 6, -9, "-90       y axis       +45",
                                                               NULL, COLOR7) ;
 init_req_text (&y_angle_wrist_text, 6, -9, "-30       y axis       +30",
                                                               NULL, COLOR7) ;
 init_req_text (&x_angle_shoulder_text, 6, -9, "-90       x axis       +90",
                                                               NULL, COLOR7) ;
 init_req_text (&x_angle_elbow_text, 6, -9, "-145       x axis        0",
                                                               NULL, COLOR7) ;
 init_req_text (&x_angle_wrist_text, 6, -9, "-90       x axis       +45",
                                                               NULL, COLOR7) ;
 init_req_text (&author_text, 47, 5,   "     Bob Laughlin",
                                                      &author1_text, COLOR1) ;
 init_req_text (&author1_text, 44, 14, "   1244 E. 13th Ave.",
                                                      &author2_text, COLOR1) ;
 init_req_text (&author2_text, 42, 22, "Vancouver B.C. V5T 2M1",
                                                      &author3_text, COLOR1) ;
 init_req_text (&author3_text, 43, 31, " phone (604) 873-3130",
                                                               NULL, COLOR1) ;
 init_req_text (&anim_info_text, 24, 12, "Select \"arm\" on the Animate",
                                                   &anim1_info_text, COLOR1) ;              
 init_req_text (&anim1_info_text, 24, 24, "menu to see the results",
                                                               NULL, COLOR1) ;
 init_req_text (&rot_info_text, 18, 7, "Positive rotations are",
                                                    &rot1_info_text, COLOR1) ;              
 init_req_text (&rot1_info_text, 18, 18, "clockwise when looking along",
                                                    &rot2_info_text, COLOR1) ;
 init_req_text (&rot2_info_text, 18, 29, "that axis towards the other 2",
                                                               NULL, COLOR1) ;
 init_req_text (&no_change_text, 18, 12, "You did not specify any angle",
                                                   &no_change1_text, COLOR1) ;
 init_req_text (&no_change1_text, 18, 24, "changes with \"set all joints\"",
                                                               NULL, COLOR1) ;
 init_req_text (&anim_cancel_text, 28, 12, "Do you want to cancel your",
                                                 &anim_cancel1_text, COLOR1) ;
 init_req_text (&anim_cancel1_text, 28, 24, "previous joint settings ?",
                                                               NULL, COLOR1) ;
 init_req_text (&yes_text, 4, 1, "yes", NULL, COLOR7) ; 
 init_req_text (&no_text, 8, 1, "no", NULL, COLOR7) ; 
 init_req_text (&ok_text, 8, 1, "ok", NULL, COLOR7) ; 

 init_req_text (&req_shoulder_text, 24, 3, "shoulder rotation angles",
                                                               NULL, COLOR7) ;                                        
 init_req_text (&req_elbow_text, 36, 3, "elbow rotation angles",
                                                               NULL, COLOR7) ; 
 init_req_text (&req_wrist_text, 36, 3, "wrist rotation angles",
                                                               NULL, COLOR7) ;    
   
    
init_prop_info (&x_shoulder_prop, x_sh_hpot) ;
init_prop_info (&x_elbow_prop, x_el_hpot) ;
init_prop_info (&x_wrist_prop, x_wr_hpot) ;
init_prop_info (&y_shoulder_prop, y_sh_hpot) ;
init_prop_info (&y_wrist_prop, y_wr_hpot) ;
init_prop_info (&z_shoulder_prop, z_sh_hpot) ;
init_prop_info (&z_wrist_prop, z_wr_hpot) ;


init_gadget (&gadg_anim_info, NULL, 262, 17, 30, 10, RELVERIFY | ENDGADGET,
             BOOLGADGET | REQGADGET, (APTR) &ok_border, 
             &ok_text, NULL, ANIM_INFO) ;

init_gadget (&gadg_rot_info, NULL, 262, 17, 30, 10, RELVERIFY | ENDGADGET,
             BOOLGADGET | REQGADGET, (APTR) &ok_border, 
             &ok_text, NULL, ROT_INFO) ;

init_gadget (&gadg_no_change, NULL, 262, 17, 30, 10, RELVERIFY | ENDGADGET,
             BOOLGADGET | REQGADGET, (APTR) &ok_border, 
             &ok_text, NULL, NO_CHANGE) ;

init_gadget (&gadg_anim_cancel_set_yes, NULL, 262, 8, 30, 10,
             RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET,
            (APTR) &ok_border, &yes_text, NULL, ANIM_CANCEL_SET_YES) ;

init_gadget (&gadg_anim_cancel_set_no, &gadg_anim_cancel_set_yes,
             262, 26, 30, 10, RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET,
            (APTR) &ok_border, &no_text, NULL, ANIM_CANCEL_SET_NO);

init_gadget (&gadg_anim_cancel_rot_yes, NULL, 262, 8, 30, 10,
             RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET,
            (APTR) &ok_border, &yes_text, NULL, ANIM_CANCEL_ROT_YES) ;

init_gadget (&gadg_anim_cancel_rot_no, &gadg_anim_cancel_rot_yes,
             262, 26, 30, 10, RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET,
            (APTR) &ok_border, &no_text, NULL, ANIM_CANCEL_ROT_NO);


init_gadget (&req_ok_shoulder, &x_shoulder_angle, 167, 72, 52, 10, RELVERIFY 
            | ENDGADGET, BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_ok_text, NULL, REQ_SHOULDER_OK) ;

init_gadget (&req_test_shoulder, &req_ok_shoulder, 94, 72, 52, 10, RELVERIFY,
             BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_test_text, NULL, REQ_SHOULDER_TEST) ;

init_gadget (&req_cancel_shoulder, &req_test_shoulder, 21, 72, 52, 10,
             RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET, 
             (APTR) &req_gadget_border, &req_cancel_text,
             NULL, REQ_SHOULDER_CANCEL) ;


init_gadget (&req_ok_elbow, &x_elbow_angle, 167, 34, 52, 10, RELVERIFY | ENDGADGET,
             BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_ok_text, NULL, REQ_ELBOW_OK) ;

init_gadget (&req_test_elbow, &req_ok_elbow, 94, 34, 52, 10, RELVERIFY,
             BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_test_text, NULL, REQ_ELBOW_TEST) ;

init_gadget (&req_cancel_elbow, &req_test_elbow, 21, 34, 52, 10, RELVERIFY |
              ENDGADGET, BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_cancel_text, NULL, REQ_ELBOW_CANCEL) ;


init_gadget (&req_ok_wrist, &x_wrist_angle, 167, 72, 52, 10, RELVERIFY | ENDGADGET,
             BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_ok_text, NULL, REQ_WRIST_OK) ;

init_gadget (&req_test_wrist, &req_ok_wrist, 94, 72, 52, 10, RELVERIFY,
             BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_test_text, NULL, REQ_WRIST_TEST) ;

init_gadget (&req_cancel_wrist, &req_test_wrist, 21, 72, 52, 10, RELVERIFY |
              ENDGADGET, BOOLGADGET | REQGADGET, (APTR) &req_gadget_border, 
             &req_cancel_text, NULL, REQ_WRIST_CANCEL) ;


init_gadget (&z_shoulder_angle, NULL, 10, 61, 220, 8,
             RELVERIFY, PROPGADGET | REQGADGET, (APTR) &z_shoulder_image,
             &z_angle_shoulder_text, (APTR)&z_shoulder_prop, Z_SHOULDER_ANGLE);

init_gadget (&y_shoulder_angle, &z_shoulder_angle, 10, 42, 220, 8, RELVERIFY,
             PROPGADGET | REQGADGET, (APTR) &y_shoulder_image,
             &y_angle_shoulder_text, (APTR)&y_shoulder_prop, Y_SHOULDER_ANGLE);

init_gadget (&x_shoulder_angle, &y_shoulder_angle, 10, 23, 220, 8, RELVERIFY,
             PROPGADGET | REQGADGET, (APTR) &x_shoulder_image,
             &x_angle_shoulder_text, (APTR)&x_shoulder_prop, X_SHOULDER_ANGLE);


init_gadget (&z_wrist_angle, NULL, 10, 61, 220, 8, RELVERIFY,
             PROPGADGET | REQGADGET, (APTR) &z_wrist_image,
             &z_angle_wrist_text, (APTR)&z_wrist_prop, Z_WRIST_ANGLE);

init_gadget (&y_wrist_angle, &z_wrist_angle, 10, 42, 220, 8, RELVERIFY,
             PROPGADGET | REQGADGET, (APTR) &y_wrist_image,
             &y_angle_wrist_text, (APTR)&y_wrist_prop, Y_WRIST_ANGLE);

init_gadget (&x_wrist_angle, &y_wrist_angle, 10, 23, 220, 8, RELVERIFY,
             PROPGADGET | REQGADGET, (APTR) &x_wrist_image,
             &x_angle_wrist_text, (APTR)&x_wrist_prop, X_WRIST_ANGLE); 


init_gadget (&x_elbow_angle, NULL, 10, 23, 220, 8, RELVERIFY, 
             PROPGADGET | REQGADGET, (APTR) &x_elbow_image,
             &x_angle_elbow_text, (APTR)&x_elbow_prop, X_ELBOW_ANGLE); 


init_requester (&get_shoulder_angles, 388, 1, 240, 86, &req_cancel_shoulder,
                &req_border_sh, &req_shoulder_text, COLOR2) ;

init_requester (&get_wrist_angles, 388, 1, 240, 86, &req_cancel_wrist,
                &req_border_wr, &req_wrist_text, COLOR2) ;

init_requester (&get_elbow_angle, 388, 1, 240, 48, &req_cancel_elbow,
                &req_border_el, &req_elbow_text, COLOR2) ;

init_requester (&anim_info, 313, 3, 312, 44, &gadg_anim_info,
                &query_border, &anim_info_text, COLOR2) ;

init_requester (&author_info, 9, 3, 312, 44, &gadg_anim_info,
                &query_border, &author_text, COLOR2) ;

init_requester (&req_rot_info, 313, 3, 312, 44, &gadg_rot_info,
                &query_border, &rot_info_text, COLOR2) ;

init_requester (&no_change, 313, 3, 312, 44, &gadg_no_change,
                &query_border, &no_change_text, COLOR2) ;

init_requester (&anim_cancel_set, 313, 3, 312, 44, &gadg_anim_cancel_set_no,
                &query_border, &anim_cancel_text, COLOR2) ;

init_requester (&anim_cancel_rot, 313, 3, 312, 44, &gadg_anim_cancel_rot_no,
                &query_border, &anim_cancel_text, COLOR2) ;


/* the test gadgets on the joint angle requesters are currently disabled */
/*  since not yet implemented */
OffGadget (&req_test_shoulder, window, &get_shoulder_angles) ;
OffGadget (&req_test_elbow, window, &get_elbow_angle) ;
OffGadget (&req_test_wrist, window, &get_wrist_angles) ;
}


init_borders (left, top, color, border, count,  points, next)

SHORT          left,  top,  color ;
struct Border  *border ;
SHORT          *points ;
struct Border  *next ;
{
 /*---------------------------------------------------------------------------
  *   Initialize the border (line) information used in requesters.
  *---------------------------------------------------------------------------
 */
 border->LeftEdge    = left ;          /* left start posn of lines */           
 border->TopEdge     = top ;           /* top start posn of lines */   
 border->FrontPen    = color ;         /* pen color */
 border->BackPen     = COLOR1 ;        /* background fill - not implemented */
 border->DrawMode    = JAM1 ;          /* write lines in FrontPen color */
                                       /* (XOR inverts background for line) */
 border->Count       = count ;         /* number of points */    
 border->XY          = points ;        /* 2-D array of coordinate points */
 border->NextBorder  = next ;          /* next border to be drawn */
}


init_req_text (intuitext, left, top, text, next, color)

struct IntuiText  *intuitext ;
SHORT             left,  top ;
UBYTE             *text ;
struct IntuiText  *next ;
UBYTE             color ;
{
 /*---------------------------------------------------------------------------
  *   Initialize the text information used in requesters.
  *---------------------------------------------------------------------------
 */
 intuitext->FrontPen   = color ;          /* text color */
 intuitext->BackPen    = COLOR0 ;          /* fill color for JAM2 */
 intuitext->DrawMode   = JAM1 ;            /* leave backgound alone */ 
 intuitext->LeftEdge   = left ;            /* left start posn of text */
 intuitext->TopEdge    = top ;             /* top start posn of text */
 intuitext->ITextFont  = &prog_font ;      /* font in use */
 intuitext->IText      = text ;            /* actual text to be drawn */
 intuitext->NextText   = next ;
}


init_prop_info (prop, horiz_pot)

struct PropInfo  *prop ;
USHORT           horiz_pot ;
{
 /*---------------------------------------------------------------------------
  *   Initialize the proportional gadget information used in requesters.
  *---------------------------------------------------------------------------
 */
 prop->Flags      = AUTOKNOB | FREEHORIZ ;     /* default knob image */
                                               /* and slider is horizontal */
 prop->HorizPot   = horiz_pot ;                /* original horiz slider posn */
 prop->VertPot    = 0 ;                        /* original vert slider posn */                 
 prop->HorizBody  = 0xffff / 24 ;              /* slider horiz increments */
 prop->VertBody   = 0xffff ;                   /* slider vert increments */
}


init_gadget (gadget, next_gadget, left, top, width, height, activate_flags,
             type_flags, border, text, special_info, gadget_id)

struct Gadget     *gadget,  *next_gadget ;
SHORT             left,  top,  width,  height ;
USHORT            activate_flags,  type_flags, gadget_id ;   
APTR              border,  special_info ;
struct IntuiText  *text ;
{
 /*---------------------------------------------------------------------------
  *   Initialize the requester gadgets.
  *---------------------------------------------------------------------------
 */
 gadget->NextGadget     = next_gadget ;     /* pointer to next gadget */
 gadget->LeftEdge       = left ;            /* position and size of gadget */   
 gadget->TopEdge        = top ;
 gadget->Width          = width ;
 gadget->Height         = height ;
 gadget->Flags          = GADGHBOX ;        /* selection highlight of gadget */
 gadget->Activation     = activate_flags ;  /* Intuition response */
 gadget->GadgetType     = type_flags ;      /* boolean, string, int, or prop */
 gadget->GadgetRender   = border ;          /* border image for gadget */
 gadget->SelectRender   = NULL ;            /* selected border image */
 gadget->GadgetText     = text ;            /* text for gadget */
 gadget->MutualExclude  = NULL ;            /* exclude other gadgets */
 gadget->SpecialInfo    = special_info ;    /* field for prop or str gadgets */
 gadget->GadgetID       = gadget_id ;       /* my handle for gadget */
 gadget->UserData       = NULL ;            /* any other relevant data */
}


init_requester (requester, left, top, width, height,
                gadg_1st, border, text, backfill)

struct Requester  *requester ;
SHORT             left,  top,  width,  height ;
struct Gadget     *gadg_1st ;
struct Border     *border ;
UBYTE             backfill ;
struct IntuiText  *text ;
{
 /*---------------------------------------------------------------------------
  *   Initialize the requesters.
  *---------------------------------------------------------------------------
 */
 requester->OlderRequest  = NULL ;     /* previous requester - maintained */
                                       /* by Intuition */
 requester->LeftEdge      = left ;     /* absolute left start posn */
 requester->TopEdge       = top ;      /* absolute top start posn */
 requester->Width         = width ;    /* requester width */
 requester->Height        = height ;   /* requester height */
 requester->RelLeft       = 0 ;        /* posn not relative to pointer */
 requester->RelTop        = 0 ;
 requester->ReqGadget     = gadg_1st ; /* pointer to 1st gadget in requester */
 requester->ReqBorder     = border ;   /* border image for requester */
 requester->ReqText       = text ;     /* text for requester */
 requester->Flags         = NULL ;     /* mostly set by Intuition */
 requester->BackFill      = backfill ; /* pen color to fill requester area */
 requester->ReqLayer      = NULL ;     /* address of layer struct */
 requester->ImageBMap     = NULL ;     /* no custom bitmap image */
 requester->RWindow       = NULL ;     /* system variable */
}


reinitialize_angle_pots ()
{
 /*---------------------------------------------------------------------------
  *   Initialize the joint slider pot settings to the zero angle position.
  * This may be in a different position for different joint axes.
  *---------------------------------------------------------------------------
 */
 ModifyProp (&x_shoulder_angle, window, &get_shoulder_angles,
             AUTOKNOB | FREEHORIZ, x_sh_hpot, 0, 0xffff / 24, 0xffff) ;
 ModifyProp (&y_shoulder_angle, window, &get_shoulder_angles,
             AUTOKNOB | FREEHORIZ, y_sh_hpot, 0, 0xffff / 24, 0xffff) ;
 ModifyProp (&z_shoulder_angle, window, &get_shoulder_angles,
             AUTOKNOB | FREEHORIZ, z_sh_hpot, 0, 0xffff / 24, 0xffff) ;
 ModifyProp (&x_elbow_angle, window, &get_elbow_angle, 
             AUTOKNOB | FREEHORIZ, x_el_hpot, 0, 0xffff / 24, 0xffff) ;
 ModifyProp (&x_wrist_angle, window, &get_wrist_angles, 
             AUTOKNOB | FREEHORIZ, x_wr_hpot, 0, 0xffff / 24, 0xffff) ;
 ModifyProp (&y_wrist_angle, window, &get_wrist_angles,
             AUTOKNOB | FREEHORIZ, y_wr_hpot, 0, 0xffff / 24, 0xffff) ;
 ModifyProp (&z_wrist_angle, window, &get_wrist_angles,
             AUTOKNOB | FREEHORIZ, z_wr_hpot, 0, 0xffff / 24, 0xffff) ;
}


restore_pot_value (joint, axis, old_pot)

int      joint,  axis ;
USHORT   old_pot ;
{
 /*---------------------------------------------------------------------------
  *   When the user cancels a previously altered joint angle, this routine
  * is called to restore the original slider pot setting.
  *---------------------------------------------------------------------------
 */
 if (joint == SH)   {
    switch (axis)    {
      case  X:   ModifyProp (&x_shoulder_angle, window, &get_shoulder_angles,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
                 break ;
      case  Y:   ModifyProp (&y_shoulder_angle, window, &get_shoulder_angles,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
                 break ;
      case  Z:   ModifyProp (&z_shoulder_angle, window, &get_shoulder_angles,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
                 break ;
      default:   close_down ("Error: in restore pot values\n") ;
                 break ;
    }
 }
 if (joint == WR)   {
    switch (axis)    {
      case  X:   ModifyProp (&x_wrist_angle, window, &get_wrist_angles,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
                 break ;
      case  Y:   ModifyProp (&y_wrist_angle, window, &get_wrist_angles,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
                 break ;
      case  Z:   ModifyProp (&z_wrist_angle, window, &get_wrist_angles,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
                 break ;
      default:   close_down ("Error: in restore pot values\n") ;
                 break ;
    }
 }
 if (joint == EL) 
     ModifyProp (&x_elbow_angle, window, &get_elbow_angle,
                      AUTOKNOB | FREEHORIZ, old_pot, 0, 0xffff / 24, 0xffff) ;
}


initialize_link_rotation_info ()
{
 /*---------------------------------------------------------------------------
  *   Initialize the angle information and transformations required for
  * keeping track of current user selected joint angle settings, and for
  * carrying out the transformations and animation.
  *---------------------------------------------------------------------------
*/
 int  temp_trans [4][4] ;
 int  i,  j ;

 rot_info.max_angle_change  = ffp.zero.i ;
 rot_info.num_frames        = ffp.zero.i ;

 for ( i = 0;  i < NUM_LINKS;  ++i)  {
     rot_info.test_mode [i]  = NO ;

     for ( j = X;  j <= Z ;  ++j)  {
         rot_info.angle [i][j].changed  = NO ;
         rot_info.angle [i][j].start    = ffp.zero.i ;
         rot_info.angle [i][j].final    = ffp.zero.i ;
         rot_info.angle [i][j].current  = ffp.zero.i ;
     }
 }
 for (i = 0;  i < NUM_LINKS;  ++i)  {

    set_to_identity_matrix (rot_info.arm_trans [i]) ;
    set_to_identity_matrix (rot_info.trans_to_origin [i]) ;
    set_to_identity_matrix (rot_info.trans_back [i]) ;

    rot_info.trans_to_origin [i] [3][Z]  = SPNeg (ffp.incr_z [i].i) ;
    rot_info.trans_back [i] [3][Z]       = ffp.incr_z [i].i ;

    matrix_mult
         (rot_info.trans_to_origin [i],  rot_info.arm_trans [i],  temp_trans) ;
    matrix_mult (temp_trans, rot_info.trans_back [i], rot_info.arm_trans [i]) ;
 }

 rot_info.angle [SH][X].old_pot  = 0xffff / 2 ;
 rot_info.angle [SH][Y].old_pot  = (0xffff / 3) * 2 ;
 rot_info.angle [SH][Z].old_pot  = 0xffff / 2 ;

 rot_info.angle [WR][X].old_pot  = (0xffff / 3) * 2 ;
 rot_info.angle [WR][Y].old_pot  = 0xffff / 2 ;
 rot_info.angle [WR][Z].old_pot  = 0xffff / 4 ;

 rot_info.angle [EL][X].old_pot  = 0xffff ;
} 
