/*----------------------------------------------------------------------------
 *      ds.h
 *
 *   This file contains the arm data structure information, as well as
 * all the typedef's used in the program.
 *----------------------------------------------------------------------------
*/


#define   MAX_VERTICES       10  /* max number of vertices for a link face */
#define   MAX_FACES          16   /* max number of faces for an arm link */
#define   NUM_LINKS          3   /* number of links in arm */

#define   X                  0  /* homogeneous coordinates for a point */
#define   Y                  1
#define   Z                  2
#define   W                  3

#define   ORIGIN             3  /* origin of a link's proximal joint */

#define   UPPER              0  /* arm links */
#define   LOWER              1
#define   HAND               2


typedef float       POINT [4] ;
typedef POINT       *POINT_PTR ;

typedef int         FFP_POINT [4] ;     /* transfer floats to FFP ints */
typedef FFP_POINT   *FFP_POINT_PTR ;    /* for faster floating point arith */

typedef struct  {
                  POINT      vertex [MAX_VERTICES] ;
                  FFP_POINT  ffp_orig_vertex [MAX_VERTICES] ;
                  FFP_POINT  ffp_curr_vertex [MAX_VERTICES] ;
                  int        x [MAX_VERTICES] ;      /* x screen coordinate */
                  int        y [MAX_VERTICES] ;      /* y screen coordinate */
                  short      num_vertices ;
                  int        plane_eqn [4] ;
                  short      visible ;
                  short      color ;
                  int        fmax [3] ;              /* maximum and minimum */
                  int        fmin [3] ;              /* coords for each face */
                }
                  FACE,  *FACE_PTR ;


typedef struct  {
                  FACE       face [MAX_FACES] ;
                  short      num_faces ;
                  int        lmax [3] ;              /* maximum and minimum */
                  int        lmin [3] ;              /* coords for each link */
                  int        f_order [MAX_FACES] ;   /* for hidden surfaces */
                }
                  LINK,  *LINK_PTR ;


typedef struct  {
                  LINK   link [NUM_LINKS] ;
                  int    amax [3] ;                 /* maximum and minimum */
                  int    amin [3] ;                 /* coords for arm */
                  int    l_order [NUM_LINKS] ;      /* for hidden surfaces */                  
                }
                  ARM ;

extern ARM  arm ;


typedef struct  {
                 short  render ;         /* keep track of users menu choices */
                 short  viewpoint ; 
                 short  viewtype ;
                 short  goaltype ;
                 short  colors ;
                 short  ref_axes ;
                }
                 MENU_CHOICES ;

extern MENU_CHOICES  menu_choices ;


typedef struct  { 
                  float  front  [3] ;     /* viewpoints on the scene */
                  float  top    [3] ;
                  float  side   [3] ;
                  float  angle1 [3] ;
                  float  angle2 [3] ;
                  float  angle3 [3] ;
                }
                  VIEWPOINT ;


typedef struct  {
                  int  front   [4][4] ;   /* store viewing transformations */
                  int  top     [4][4] ;
                  int  side    [4][4] ;
                  int  angle1  [4][4] ;
                  int  angle2  [4][4] ;
                  int  angle3  [4][4] ;
                }
                  VIEW_TRANS ;


typedef struct  {
                 USHORT    start      [NUM_COLORS] ;  /* color settings used */
                 USHORT    set1       [NUM_COLORS] ;  /* to load color */
                 USHORT    set2       [NUM_COLORS] ;  /* registers */
                 USHORT    set3       [NUM_COLORS] ;
                 USHORT    clr_screen [NUM_COLORS] ;
                }
                 COLORTABLE ;


typedef  union  {                 /*    This is a used for a major hack */
                 int    i;        /* that fools Lattice C into using the */
                 float  f ;       /* the Motorola Fast Floating Point (FFP) */
                }                 /* routines.  The Motorola routines are */
                 FFP ;            /* _10_ times faster than Lattice's */
                                  /* equivalent FP routines. */
                                  /*    A float is stored in the "f" portion */   
                                  /* of an FFP variable, and passed to */
                                  /* Lattice as an "int".  This way Lattice */
                                  /* will not convert it to a double and */
                                  /* screw up the calculation - the Motorola */
                                  /* routines require a float value */


typedef struct  {                 /* More FFP hacks */
                 FFP  zero ;      /* Keep useful FP constants in FFP format */
                 FFP  two ;
                 FFP  screen_scale_x ;
                 FFP  incr_z [NUM_LINKS] ;
                 FFP  one ;
                 FFP  neg_one ;
                 FFP  test_pt [4] ;
                 FFP  telephoto_aperture ;
                 FFP  wide_angle_aperture ;
                 FFP  large_num ;
                 FFP  small_num ;
                 FFP  screen_fill_x ;
                 FFP  screen_fill_y ;
                 FFP  pi ;
                 FFP  one_eighty ;
                 int  radians ;
                 FFP  min_angle_change ;
                 FFP  axes_length ;
                }
                  FFP_CONSTANTS ;

extern FFP_CONSTANTS  ffp ;

extern float  SPTieee() ;         /* converts from Motorola format to float */


typedef struct  {                      /* angle information to keep track */
                  int     start ;      /* of current settings for each */
                  int     final ;      /* joint axis */
                  int     change ;
                  int     current ;
                  int     incr ;
                  int     changed ;
                  USHORT  old_pot ;
                  USHORT  new_pot ;
                }
                  ANGLE_INFO ;


                   /* rotation information to keep track of current */
                   /* joint transformations, number of animation frames */
                   /* req'd etc... */
typedef struct  {
                  ANGLE_INFO  angle            [NUM_LINKS][3] ;
                  int         arm_trans        [NUM_LINKS] [4][4] ;
                  int         trans_to_origin  [NUM_LINKS] [4][4] ;
                  int         trans_back       [NUM_LINKS] [4][4] ;
                  int         *curr_view_trans ;
                  int         num_frames ;
                  int         max_angle_change ;
                  short       test_mode [NUM_LINKS] ;
                }
                  ROTATION_INFO ;


typedef struct  {
                  FFP_POINT  orig_coord [4] ;    /* store the original and */
                  FFP_POINT  curr_coord [4] ;    /* current reference axes */
                  int        scrn_x [4] ;        /* coordinates */
                  int        scrn_y [4] ;
                }
                  REF_AXES ;
