1 #include "config.h"
2 #include "copyright2.h"
3
4 #include INC_MACHINE_ENDIAN
5
6 #include <stdio.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <sys/time.h>
10 #include INC_NETINET_IN
11 #include INC_NETINET_TCP
12 #include <netdb.h>
13 #include <math.h>
14 #include <errno.h>
15 #include "Wlib.h"
16 #include "defs.h"
17 #include "struct.h"
18 #include "data.h"
19 #include "packets.h"
20
21 #include "rotate.h"
22
23 #ifdef ROTATERACE
rotate_dir(unsigned char * d,int r)24 void rotate_dir(unsigned char *d, int r)
25 {
26 (*d) += r;
27 }
28
29 /* general rotation */
30
rotate_coord(int * x,int * y,int d,int cx,int cy)31 void rotate_coord(int *x, int *y, int d, int cx, int cy)
32
33 /* values used and returned */
34 /* degree (pi == 128) */
35 /* around center point */
36 {
37 register
38 int ox, oy;
39
40 ox = *x;
41 oy = *y;
42
43 switch (d)
44 {
45
46 case 0:
47 return;
48
49 case 64:
50 case -192:
51 *x = cy - oy + cx;
52 *y = ox - cx + cy;
53 break;
54
55 case 128:
56 case -128:
57 *x = cx - ox + cx;
58 *y = cy - oy + cy;
59 break;
60
61 case 192:
62 case -64:
63 *x = oy - cy + cx;
64 *y = cx - ox + cy;
65 break;
66
67 default:
68 {
69 /* do it the hard way */
70 double dir;
71 double r, dx, dy;
72 double rd = (double) d * 3.1415927 / 128.;
73
74 if (*x != cx || *y != cy)
75 {
76 dx = (double) (*x - cx);
77 dy = (double) (cy - *y);
78 dir = atan2(dx, dy) - 3.1415927 / 2.;
79 r = hypot(dx, dy);
80 dir += rd;
81 *x = (int) (r * cos(dir) + cx);
82 *y = (int) (r * sin(dir) + cy);
83 }
84 }
85 }
86 }
87 #endif
88