Advertisement
Guest User

Untitled

a guest
May 27th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.03 KB | None | 0 0
  1. int     cross(double x1, double x2, double x3, double x4, double y1, double y2, double y3, double y4)
  2. {
  3.     double      a1;
  4.     double      b1;
  5.     double      a2;
  6.     double      b2;
  7.     double      res;
  8.  
  9.     if (x1 != x2 && x4 != x3)
  10.     {
  11.         a1 = (y2 - y1) / (x2 - x1);
  12.         a2 = (y4 - y3) / (x4 - x3);
  13.         if (a1 == a2)
  14.             return (0);
  15.         b1 = y1 - (a1 * x1);
  16.         b2 = y3 - (a2 * x3);
  17.         res = (b2 - b1) / (a1 - a2);
  18.         if (((res >= x1 && res <= x2) || (res >= x2 && res <= x1)) && ((res > x3 && res < x4) || (res > x4 && res < x3)))
  19.                return (1);
  20.     }
  21.     else
  22.     {
  23.         if (x1 == x2 && x3 == x4)
  24.             return (0);
  25.         else if (x1 == x2)
  26.         {
  27.             a2 = (y4 - y3) / (x4 - x3);
  28.             b2 = y3 - (a2 * x3);
  29.             res = a2 * x1 + b2;
  30.         }
  31.         else if (x3 == x4)
  32.         {
  33.             a1 = (y2 - y1) / (x2 - x1);
  34.             b1 = y1 - (a1 * x1);
  35.             res = a1 * x3 + b1;
  36.         }
  37.         if (((res >= y1 && res <= y2) || (res >= y2 && res <= y1)) && ((res > y3 && res < y4) || (res > y4 && res < x3)))
  38.                 return (1);
  39.     }
  40.     return (0);
  41. }
  42.  
  43. void    sprite(t_env *w, t_map *m)
  44. {
  45.     int     x;
  46.     int     y;
  47.     int         z;
  48.     double  v1x;
  49.     double  v1y;
  50.     double  t1x;
  51.     double  t1z;
  52.     double  xscale1;
  53.     double  x1;
  54.     double  y1a;
  55.     double  yscale1;
  56.     int     d;
  57.     int     i;
  58.     int         l;
  59.     int         h;
  60.     double      diffx;
  61.     double      diffy;
  62.     double      range;
  63.     int         g;
  64.     t_coor      p;
  65.     t_draw      work;
  66.  
  67.     d = 0;
  68.     (void)work;
  69.  
  70.     hand(m, w);
  71.     while (d < WIDTH)
  72.     {
  73.         work.ytop[d] = 0;
  74.         work.ybot[d] = HEIGHT - 1;
  75.         d++;
  76.     }
  77.     d = 0;
  78.     x = 40;
  79.     y = 4;
  80.     z = 32;
  81.     v1x = x - PL_X;
  82.     v1y = y - PL_Y;
  83.     t1x = v1x * PL_AS - v1y * PL_AC;
  84.     t1z = v1x * PL_AC + v1y * PL_AS;
  85.     xscale1 = m->player.field_of_vision_h / t1z;
  86.     yscale1 = m->player.field_of_vision_v / t1z;
  87.     x1 = WIDTH / 2 - (int)(t1x * xscale1);
  88.     y1a = HEIGHT / 2 - (int)(yaw((m->sector[3].floor - m->player.coor.z), t1z, m) * yscale1) - 64;
  89.     x1 = x1 - 32;
  90.     diffx = fabs(m->player.coor.x - x);
  91.     diffy = fabs(m->player.coor.y - y);
  92.     range = sqrt((diffx * diffx) + (diffy * diffy)) / 100;
  93.     range = 0.5 / range;
  94.     if (range < 1)
  95.         range = 1;
  96.     else if (range < 2)
  97.         y1a = y1a - (64 * fmod(range, 1));
  98.     else
  99.        y1a = y1a - (64 * ((int)range - 1 + fmod(range, 1)));
  100.     g = 1;
  101.     p.x = x;
  102.     p.y = y;
  103.     if (z > m->sector[m->player.sector].ceiling)
  104.         g = 0;
  105.     while (i < m->sector_count)
  106.     {
  107.         while (h < m->sector[i].wall_count)
  108.         {
  109.             if (m->visible[i].wall[h] == 1 && m->sector[i].network[h] < 0)
  110.                 if (pointside(p, m->sector[i].dot[h].x , m->sector[i].dot[h].y, m->sector[i].dot[h + 1].x, m->sector[i].dot[h + 1].y) <= 0)
  111.                 {
  112.                     if (cross(m->player.coor.x, x, m->sector[i].dot[h].x, m->sector[i].dot[h + 1].x, m->player.coor.y, y, m->sector[i].dot[h].y, m->sector[i].dot[h + 1].y) == 1)
  113.                         g = 0;
  114.                 }
  115.             h++;
  116.         }
  117.         h = 0;
  118.         i++;
  119.     }
  120.     if (t1z > 0 && g == 1)
  121.     {
  122.         while (d < 64)
  123.         {
  124.             i = 0;
  125.             while (i < 64)
  126.             {
  127.                 h = 0;
  128.                 while (h < range)
  129.                 {
  130.                     l = 0;
  131.                     while (l < range)
  132.                     {
  133.                         if (w->sprite[0].pix[d * 64 + i] != 4288151688 && (y1a + h >= 0 && y1a + h < HEIGHT) && (x1 + l >= 0 && x1 + l < WIDTH))
  134.                             w->pix[(int)(y1a + h) * WIDTH + (int)(x1 + l)] = w->sprite[0].pix[d * 64 + i];
  135.                          l++;
  136.                     }
  137.                     h++;
  138.                 }
  139.                 x1 += range;
  140.                 i++;
  141.             }
  142.             x1 -= 64 * range;
  143.             y1a += range;
  144.             d++;
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement