Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison rotate.c @ 3:5a977ccbc7a9 default tip
Empty changelog
author | darius |
---|---|
date | Sat, 06 Dec 1997 05:41:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fba0b6e6cdc7 | 3:5a977ccbc7a9 |
---|---|
1 /* $Id: rotate.c,v 1.1.1.1 1997/12/06 05:41:30 darius Exp $ */ | |
2 | |
3 /* | |
4 * rotate.c | |
5 * | |
6 */ | |
7 #include "copyright2.h" | |
8 | |
9 #include <stdio.h> | |
10 #include <sys/types.h> | |
11 #ifndef AMIGA /* not that this file needs any network | |
12 stuff... -JR */ | |
13 #include <sys/socket.h> | |
14 #include <sys/time.h> | |
15 #include <netinet/in.h> | |
16 #include <netinet/tcp.h> | |
17 #include <netdb.h> | |
18 #endif | |
19 #include <math.h> | |
20 #include <errno.h> | |
21 #include "Wlib.h" | |
22 #include "defs.h" | |
23 #include "struct.h" | |
24 #include "data.h" | |
25 #include "packets.h" | |
26 | |
27 #ifdef ROTATERACE | |
28 | |
29 void | |
30 rotate_dir(d, r) | |
31 unsigned char *d; | |
32 int r; | |
33 { | |
34 (*d) += r; | |
35 } | |
36 | |
37 /* general rotation */ | |
38 | |
39 void | |
40 rotate_coord(x, y, d, cx, cy) | |
41 int *x, *y; /* values used and returned */ | |
42 int d; /* degree (pi == 128) */ | |
43 int cx, cy; /* around center point */ | |
44 { | |
45 register | |
46 int ox, oy; | |
47 | |
48 ox = *x; | |
49 oy = *y; | |
50 | |
51 switch (d) { | |
52 | |
53 case 0: | |
54 return; | |
55 | |
56 case 64: | |
57 case -192: | |
58 *x = cy - oy + cx; | |
59 *y = ox - cx + cy; | |
60 break; | |
61 | |
62 case 128: | |
63 case -128: | |
64 *x = cx - ox + cx; | |
65 *y = cy - oy + cy; | |
66 break; | |
67 | |
68 case 192: | |
69 case -64: | |
70 *x = oy - cy + cx; | |
71 *y = cx - ox + cy; | |
72 break; | |
73 | |
74 default:{ | |
75 /* do it the hard way */ | |
76 /* | |
77 there is another way to do this, by using the cos(d) and | |
78 sin(d) and the stock rotation matrix from linear algebra. | |
79 */ | |
80 double dir; | |
81 double r, dx, dy; | |
82 double rd = (double) d * 3.1415927 / 128.; | |
83 | |
84 if (*x != cx || *y != cy) { | |
85 dx = (double) (*x - cx); | |
86 dy = (double) (cy - *y); | |
87 dir = atan2(dx, dy) - 3.1415927 / 2.; | |
88 r = hypot(dx, dy); | |
89 dir += rd; | |
90 *x = (int) (r * cos(dir) + cx); | |
91 *y = (int) (r * sin(dir) + cy); | |
92 } | |
93 } | |
94 } | |
95 } | |
96 | |
97 void | |
98 rotate_gcenter(x, y) | |
99 int *x, *y; /* values used and returned */ | |
100 { | |
101 rotate_coord(x, y, rotate_deg, blk_gwidth / 2, blk_gwidth / 2); | |
102 } | |
103 | |
104 #endif | |
105 | |
106 void rotate_all() | |
107 { | |
108 register i; | |
109 register struct planet *l; | |
110 register struct player *j; | |
111 | |
112 int nplan = (paradise) ? nplanets : 40; | |
113 int old_rotate_deg = rotate_deg; | |
114 | |
115 redrawall = 1; | |
116 reinitPlanets = 1; | |
117 | |
118 rotate_deg = -old_rotate_deg + rotate * 64; | |
119 | |
120 for (i = 0, l = planets; i < nplan; i++, l++) { | |
121 rotate_gcenter(&l->pl_x, &l->pl_y); | |
122 } | |
123 | |
124 for (i=0, j = players; i < nplayers; i++, j++) { | |
125 rotate_gcenter(&j->p_x, &j->p_y); | |
126 rotate_dir(&j->p_dir, rotate_deg); | |
127 } | |
128 | |
129 rotate_deg = rotate * 64; | |
130 } |