home *** CD-ROM | disk | FTP | other *** search
/ Adventures in Heaven 2 / adventuresinheaven2powergamesfordosandwindows.iso / windows / arcade / cbzone / c_draw.c < prev    next >
C/C++ Source or Header  |  1992-05-27  |  13KB  |  380 lines

  1. #include "c_includ.h"
  2. /*
  3.  * c_draw.c
  4.  * Todd W Mummert, CMU, January 1991
  5.  *
  6.  * This is an attempt at cleaning up the drawing routines.
  7.  */
  8.  
  9. /*
  10.  * this routine is for points which cannot change their bearing and have
  11.  * no moving parts; i.e., blocks.
  12.  */
  13. void calcpointsI(dc, method, index, g, pl)
  14.      DCp dc;
  15.      Methodp method;
  16.      int index;
  17.      Genericp g, pl;
  18. {
  19.   int i;
  20.   float xpoff, ypoff, prx, pry, prz, dx, dy;
  21.   Coord2dp new;
  22.   Coord3dp old;
  23.  
  24.   old = dc->s->object+index;
  25.   new = dc->points+index;
  26.   dx = pl->x - dc->pos.x;
  27.   dy = pl->y - dc->pos.y;
  28.   for (i=0; i<method->num; i++, old++, new++) {
  29.       xpoff = old->x - dx;
  30.       ypoff = old->y - dy;
  31.       prx =  xpoff * pl->ca + ypoff * pl->sa;
  32.       pry = -xpoff * pl->sa + ypoff * pl->ca;
  33.       if (pry < 10.0)
  34.         pry = 10.0;
  35.       prz = old->z + dc->pos.z;
  36.       new->x = 500 + prx / pry * 450;
  37.       new->y = 260 - prz / pry * 450;
  38.     }
  39. }
  40.  
  41. /*
  42.  * this routine is for points which may change their bearing, but do not
  43.  * have moving parts.
  44.  */
  45. void calcpointsII(dc, method, index, g, pl)
  46.      DCp dc;
  47.      Methodp method;
  48.      int index;
  49.      Genericp g, pl;
  50. {
  51.   int i;
  52.   float csa, ssa, dx, dy, xn, yn, cn, sn, prx, pry, prz, rx, ry;
  53.   Coord2dp new;
  54.   Coord3dp old;
  55.  
  56.   old = dc->s->object+index;
  57.   new = dc->points+index;
  58.  
  59.   csa = cos(g->azm);
  60.   ssa = sin(g->azm);
  61.   dx = pl->x - dc->pos.x;
  62.   dy = pl->y - dc->pos.y;
  63.   xn =  dx * csa + dy * ssa;
  64.   yn = -dx * ssa + dy * csa;
  65.   cn = pl->ca * csa + pl->sa * ssa;
  66.   sn = pl->sa * csa - ssa * pl->ca;
  67.   for (i=0; i<method->num; i++, old++, new++) {
  68.     rx =  old->x - xn;
  69.     ry =  old->y - yn;
  70.     prx =  rx * cn + ry * sn;
  71.     pry = -rx * sn + ry * cn;
  72.     if (pry < 10.0)
  73.       pry = 10.0;
  74.     prz = old->z + dc->pos.z;
  75.     new->x = 500 + prx / pry * 450;
  76.     new->y = 260 - prz / pry * 450;
  77.   }
  78. }
  79.  
  80. /*
  81.  * this routine is for points which do not change their bearing,
  82.  * but have moving parts which rotate around the center of the
  83.  * object.
  84.  */
  85. void calcpointsIII(dc, method, index, g, pl)
  86.      DCp dc;
  87.      Methodp method;
  88.      int index;
  89.      Genericp g, pl;
  90. {
  91.   int i;
  92.   float temp, dx, dy, xn, yn, cn, sn, prx, pry, prz, rx, ry;
  93.   Coord2dp new;
  94.   Coord3dp old;
  95.  
  96.   old = dc->s->object+index;
  97.   new = dc->points+index;
  98.   temp = dc->cta;
  99.   dc->cta = dc->cta * method->vars[0] - dc->sta * method->vars[1];
  100.   dc->sta = dc->sta * method->vars[0] + temp * method->vars[1];
  101.   dx = pl->x - dc->pos.x;
  102.   dy = pl->y - dc->pos.y;
  103.   xn =  dx * dc->cta + dy * dc->sta;
  104.   yn = -dx * dc->sta + dy * dc->cta;
  105.   cn = pl->ca * dc->cta + pl->sa * dc->sta;
  106.   sn = pl->sa * dc->cta - pl->ca * dc->sta;
  107.   for (i=0; i<method->num; i++, old++, new++) {
  108.     rx =  old->x - xn;
  109.     ry =  old->y - yn;
  110.     prx =  rx * cn + ry * sn;
  111.     pry = -rx * sn + ry * cn;
  112.     if (pry < 10.0)
  113.       pry = 10.0;
  114.     prz = old->z + dc->pos.z;
  115.     new->x = 500 + prx / pry * 450;
  116.     new->y = 260 - prz / pry * 450;
  117.   }
  118. }
  119.  
  120. /*
  121.  * this routine is for points which do change their bearing,
  122.  * and have moving parts which do not rotate around the center of the
  123.  * object.  an example is the offset radar dish of the normal tanks.
  124.  */
  125. void calcpointsIV(dc, method, index, g, pl)
  126.      DCp dc;
  127.      Methodp method;
  128.      int index;
  129.      Genericp g, pl;
  130. {
  131.   int i;
  132.   float temp, dx, dy, xn, yn, cn, sn, prx, pry, prz, rx, ry, csa, ssa;
  133.   Coord2dp new;
  134.   Coord3dp old;
  135.   Float2d pivot;
  136.  
  137.   old = dc->s->object+index;
  138.   new = dc->points+index;
  139.   temp = dc->cta;
  140.   dc->cta = dc->cta * method->vars[0] - dc->sta * method->vars[1];
  141.   dc->sta = dc->sta * method->vars[0] + temp * method->vars[1];
  142.   csa = cos(g->azm);
  143.   ssa = sin(g->azm);
  144.   dx = pl->x - dc->pos.x;
  145.   dy = pl->y - dc->pos.y;
  146.   xn =  dx * csa + dy * ssa;
  147.   yn = -dx * ssa + dy * csa;
  148.   cn = pl->ca * csa + pl->sa * ssa;
  149.   sn = pl->sa * csa - ssa * pl->ca;
  150.   pivot.x = method->vars[2] - xn;
  151.   pivot.y = method->vars[3] - yn;
  152.   for (i=0; i<method->num; i++, old++, new++) {
  153.     rx = old->x * dc->cta - old->y * dc->sta + pivot.x;
  154.     ry = old->x * dc->sta + old->y * dc->cta + pivot.y;
  155.     prx =  rx * cn + ry * sn;
  156.     pry = -rx * sn + ry * cn;
  157.     if (pry < 10.0)
  158.       pry = 10.0;
  159.     prz = old->z + dc->pos.z;
  160.     new->x = 500 + prx / pry * 450;
  161.     new->y = 260 - prz / pry * 450;
  162.   }
  163. }
  164.  
  165. /*
  166.  * draw plines and mlines
  167.  *
  168.  */
  169. void displayobject(dc)
  170.      DCp dc;
  171. {
  172.   Coord2dp point;
  173.   int *i;
  174.  
  175.   point=dc->points;
  176.   for (i=dc->s->pnum; *i; i++) {
  177.     polyline(point, *i);
  178.     point += *i;
  179.   }
  180.   for (i=dc->s->mnum; *i; i++) {
  181.     multiline(point, *i>>1);
  182.     point += *i;
  183.   }
  184. }
  185.  
  186. void drawobject(g, pl)
  187.      Genericp g, pl;
  188. {
  189.   static Coord3d cube[] = {
  190.     -40,  40, -40,   -40,  40,  40,    40,  40,  40,    40,  40, -40,
  191.     -40,  40, -40,   -40, -40, -40,    40, -40, -40,    40, -40,  40,
  192.     -40, -40,  40,   -40, -40, -40,   -40, -40,  40,   -40,  40,  40,
  193.      40, -40,  40,    40,  40,  40,    40, -40, -40,    40,  40, -40};
  194.   static int cubepnum[] = {10, 0};
  195.   static int cubemnum[] = {6, 0};
  196.   static Method cubemethods[] = {16, calcpointsI, NULL,
  197.                                    0, NULL, NULL};
  198.  
  199.   static Coord3d pyramid[] = {
  200.     -40,  40, -40,    40,  40, -40,     40, -40, -40,     40,  40, -40,
  201.       0,   0,  40,   -40,  40, -40,    -40, -40, -40,      0,   0,  40,
  202.      40, -40, -40,   -40, -40, -40};
  203.   static int pyramidpnum[] = {10, 0};
  204.   static int pyramidmnum[] = {0};
  205.   static Method pyramidmethods[] = {10, calcpointsI, NULL,
  206.                                       0, NULL, NULL};
  207.  
  208.   static Coord3d salvo[] = {
  209.       0, -10,  -8,     8, -10,   0,      0, -10,   8,      8, -10,   0,
  210.       0,  10,   0,     0, -10,   8,     -8, -10,   0,      0,  10,   0,
  211.       0, -10,  -8,    -8, -10,   0};
  212.   static int salvopnum[] = {10, 0};
  213.   static int salvomnum[] = {0};
  214.   static Method salvomethods[] = {10, calcpointsII, NULL,
  215.                                     0, NULL, NULL};
  216.  
  217.   static Coord3d lander[] = {
  218.       0,   0,  20,     80,   0, -20,     40,   0, -40,    -40,   0, -40,
  219.     -80,   0, -20,      0,   0,  20,      0,  80, -20,      0,  40, -40,
  220.       0, -40, -40,      0, -80, -20,      0,   0,  20,    -57, -57, -20,
  221.     -28, -28, -40,     28,  28, -40,     57,  57, -20,      0,   0,  20,
  222.      57, -57, -20,     28, -28, -40,    -28,  28, -40,    -57,  57, -20,
  223.       0,   0,  20};
  224.   static int landerpnum[] = {21, 0};
  225.   static int landermnum[] = {0};
  226.   static float landervars[] =  {0.996195, 0.087156};
  227.   static Method landermethods[] = {21, calcpointsIII, landervars,
  228.                                     0, NULL, NULL};
  229.  
  230.   static Coord3d missile[] = {
  231.      15, -30, -25,     25, -30,   0,      0, -45,   0,     15, -30, -25,
  232.     -15, -30, -25,      0, -45,   0,     15, -30,  25,    -15, -30,  25,
  233.       0, -45,   0,    -25, -30,   0,    -15, -30,  25,     15, -30, -25,
  234.       0,  50,   0,     25, -30,   0,     15, -30,  25,      0,  50,   0,
  235.     -15, -30, -25,    -25, -30,   0,      0,  50,   0,    -15, -30,  25,
  236.      13, -17, -21,     15, -30, -25,     23, -38, -40,     23,   0, -40,
  237.      13, -17, -21,    -13, -17, -21,    -15, -30, -25,    -23, -38, -40,
  238.     -23,   0, -40,    -13, -17, -21};
  239.   static int missilepnum[] = {11, 9, 5, 5, 0};
  240.   static int missilemnum[] = {0};
  241.   static Method missilemethods[] = {30, calcpointsII, NULL,
  242.                                     0, NULL, NULL};
  243.  
  244.   static Coord3d copter[] = {
  245.        6,  100,   30,     -6, -100,   30,      6, -100,   30,
  246.       -6,  100,   30,      6,  100,   30,      0, -114,  -10,
  247.        7,  -30,  -34,     10,  -34,  -14,      0, -116,    0,
  248.        0, -134,   28,      0, -144,   28,      0, -130,  -10,
  249.        0, -114,  -10,     -7,  -30,  -34,    -10,  -34,  -14,
  250.        0, -116,    0,    -14,   34,  -34,     14,   34,  -34,
  251.        0,   60,  -14,    -14,   34,  -34,     -7,  -30,  -34,
  252.        7,  -30,  -34,     14,   34,  -34,     26,   34,  -14,
  253.        0,   60,  -14,    -26,   34,  -14,    -10,  -34,  -14,
  254.       10,  -34,  -14,     26,   34,  -14,      4,   20,   16,
  255.        0,   22,   16,     -4,   20,   16,     -4,  -22,   16,
  256.        4,  -22,   16,      4,   20,   16,      0,    0,   16,
  257.        0,    0,   36,    -14,  -30,  -40,    -14,   40,  -40,
  258.      -14,   40,  -40,    -14,   44,  -36,     14,  -30,  -40,
  259.       14,   40,  -40,     14,   40,  -40,     14,   44,  -36,
  260.      -10,  -34,  -14,     -4,  -22,   16,     10,  -34,  -14,
  261.        4,  -22,   16,      0,   22,   16,      0,   60,  -14,
  262.      -14,   34,  -34,    -26,   34,  -14,    -26,   34,  -14,
  263.       -4,   20,   16};
  264.   static int copterpnum[] = {5, 11, 19, 0};
  265.   static int coptermnum[] = {10, 10, 0};
  266.   static float coptervars[] = {0.819152, 0.573576};
  267.   static Method coptermethods[] = {5, calcpointsIII, coptervars,
  268.                                      50, calcpointsII, NULL,
  269.                                      0, NULL, NULL};
  270.  
  271.   static Coord3d super[] = {
  272.       3,  55,  -6,     3,  55,   0,    -3,  55,   0,    -3,  55,  -6,
  273.       3,  55,  -6,     0,  35, -33,    13, -60,  -6,    11, -60,   4,
  274.      11, -25,   4,     0,  35, -33,   -13, -60,  -6,   -11, -60,   4,
  275.     -11, -25,   4,     0,  35, -33,    15,  60, -40,    30, -60, -40,
  276.      30, -60,  -6,    15,  60, -40,   -15,  60, -40,   -30, -60, -40,
  277.     -30, -60,  -6,   -15,  60, -40,    22, -52,  -8,    22, -52,  28,
  278.       3, -17,   0,     3,  55,   0,    -3, -17,   0,    -3,  55,   0,
  279.       3,  -8,  -6,     3,  55,  -6,    -3,  -8,  -6,    -3,  55,  -6,
  280.      11, -60,   4,   -11, -60,   4,    11, -25,   4,   -11, -25,   4,
  281.     -30, -60,  -6,    30, -60,  -6,   -30, -60, -40,    30, -60, -40};
  282.   static int superpnum[] = {5, 9, 8, 0};
  283.   static int supermnum[] = {2, 8, 4, 4, 0};
  284.   static Method supermethods[] = {40, calcpointsII, NULL,
  285.                                     0, NULL, NULL};
  286.  
  287.   static Coord3d tank[] = {
  288.       3,   0,  13,     5,   3,  15,     5,   3,  19,     3,   0,  21,
  289.      -3,   0,  21,    -5,   3,  19,    -5,   3,  15,    -3,   0,  13,
  290.       3,   0,  13,    -3,  60,  -3,     3,  60,  -3,     3,  60,   3,
  291.      -3,  60,   3,    -3,  60,  -3,   -10, -45,  10,   -10, -13,  10,
  292.      10, -13,  10,    10, -45,  10,    25, -50, -11,    25,  60, -20,
  293.      10, -13,  10,   -10, -13,  10,   -25,  60, -20,   -25, -50, -11,
  294.     -10, -45,  10,    10, -45,  10,    30, -53, -40,    35, -60, -10,
  295.      35,  60, -20,    30,  37, -40,   -30,  37, -40,   -35,  60, -20,
  296.     -35, -60, -10,   -30, -53, -40,    30, -53, -40,    30,  37, -40,
  297.       5, -40,  10,     5, -40,  13,     3,   4,   3,     3,  60,   3,
  298.      -3,   4,   3,    -3,  60,   3,    -3,  19,  -3,    -3,  60,  -3,
  299.       3,  19,  -3,     3,  60,  -3,    35, -60, -10,   -35, -60, -10,
  300.      35,  60, -20,   -35,  60, -20,   -30, -53, -40,   -30, 37, -40};
  301.   static int tankpnum[] = {9, 5, 12, 10, 0};
  302.   static int tankmnum[] = {2, 8, 6, 0};
  303.   static float tankvars[] = {0.996195, 0.087156, 5, -40};
  304.   static Method tankmethods[] = {9, calcpointsIV, tankvars,
  305.                                    43, calcpointsII, NULL,
  306.                                    0, NULL, NULL};
  307.  
  308.   static StaticDC staticdcs[] = {
  309.     pyramid, pyramidpnum, pyramidmnum, pyramidmethods, COLOR_PYRAMID,
  310.     cube, cubepnum, cubemnum, cubemethods, COLOR_CUBE,
  311.     tank, tankpnum, tankmnum, tankmethods, COLOR_TANK,
  312.     super, superpnum, supermnum, supermethods, COLOR_SUPER,
  313.     missile, missilepnum, missilemnum, missilemethods, COLOR_MISSILE,
  314.     copter, copterpnum, coptermnum, coptermethods, COLOR_COPTER,
  315.     lander, landerpnum, landermnum, landermethods, COLOR_LANDER,
  316.     salvo, salvopnum, salvomnum, salvomethods, COLOR_ESALVO };
  317.  
  318.   int color, i;
  319.   DCp dc;
  320.   Methodp methods;
  321.  
  322.   dc = &g->dc[0];
  323.   if (dc->last) {
  324.     gprsetdrawvalue(opt->cpi[COLOR_BG]);
  325.     displayobject(dc);
  326.   }
  327.   if (g->attr & ERASE) return;
  328.  
  329.   if (!(g->attr & HAS_DC)) {
  330.     g->attr |= HAS_DC;
  331.     dc->s = staticdcs+g->lntype;
  332.  
  333.     switch (g->type) {
  334.     case IS_CUBE:
  335.     case IS_PYRAMID:
  336.     case IS_LANDER:
  337.     case IS_MISSILE:
  338.     case IS_COPTER:
  339.     case IS_SUPER:
  340.     case IS_TANK:
  341.       dc->fades = opt->fading_colors - 1;
  342.       dc->basecolor = dc->s->basecolor;
  343.       break;
  344.     case IS_SALVO:
  345.       dc->fades = False;
  346.       if (g->salvo == pl)
  347.         dc->basecolor = COLOR_PSALVO;
  348.       else
  349.         dc->basecolor = COLOR_ESALVO;
  350.       break;
  351.     }
  352.   }
  353.  
  354.   if (dc->seen) {
  355.     if (dc->fades) {
  356.       color = g->range/OUT_OF_DRAWING_RANGE * opt->fading_colors;
  357.       if (color >= opt->fading_colors)
  358.         color = opt->fading_colors-1;
  359.     }
  360.     else
  361.       color = 0;
  362.     gprsetdrawvalue(color + opt->cpi[dc->basecolor]);
  363.  
  364.     dc->pos.x = g->x;
  365.     dc->pos.y = g->y;
  366.     dc->pos.z = g->z;
  367.  
  368.     methods = dc->s->methods;
  369.     for (i=0; methods->num; methods++) {
  370.       methods->calc(dc, methods, i, g, pl);
  371.       i += methods->num;
  372.     }
  373.  
  374.     displayobject(dc);
  375.     dc->last = True;
  376.   }
  377.   else
  378.     dc->last = False;
  379. }
  380.