1/* drawline using simple DDA */
2void DrawLine(int x1, int y1, int x2, int y2)
3{
4 int x, y, hm=1, vm=1, sw=0, t;
5 double dx, edx, dy, edy, eps;
6 x = x2-x1;
7 y = y2-y1;
8 if (x < 0)
9 {
10 x = -x;
11 hm = -1;
12 }
13 if (y < 0)
14 {
15 y = -y;
16 vm = -1;
17 }
18 if (x < y)
19 {
20 sw = 1;
21 t = x;
22 x = y;
23 y = t;
24 }
25 eps = 1./x;
26 edx = eps*x;
27 edy = eps*y;
28
29 dx = dy = 0.5;
30 if (sw == 0)
31 SetPixel((int)dx*hm+x1, (int)dy*vm+y1);
32 else
33 SetPixel((int)dy*hm+x1, (int)dx*vm+y1);
34 while (dx < x)
35 {
36 dx += edx;
37 dy += edy;
38 if (sw == 0)
39 SetPixel((int)dx*hm+x1, (int)dy*vm+y1);
40 else
41 SetPixel((int)dy*hm+x1, (int)dx*vm+y1);
42 }
43}
44
2void DrawLine(int x1, int y1, int x2, int y2)
3{
4 int x, y, hm=1, vm=1, sw=0, t;
5 double dx, edx, dy, edy, eps;
6 x = x2-x1;
7 y = y2-y1;
8 if (x < 0)
9 {
10 x = -x;
11 hm = -1;
12 }
13 if (y < 0)
14 {
15 y = -y;
16 vm = -1;
17 }
18 if (x < y)
19 {
20 sw = 1;
21 t = x;
22 x = y;
23 y = t;
24 }
25 eps = 1./x;
26 edx = eps*x;
27 edy = eps*y;
28
29 dx = dy = 0.5;
30 if (sw == 0)
31 SetPixel((int)dx*hm+x1, (int)dy*vm+y1);
32 else
33 SetPixel((int)dy*hm+x1, (int)dx*vm+y1);
34 while (dx < x)
35 {
36 dx += edx;
37 dy += edy;
38 if (sw == 0)
39 SetPixel((int)dx*hm+x1, (int)dy*vm+y1);
40 else
41 SetPixel((int)dy*hm+x1, (int)dx*vm+y1);
42 }
43}
44