annotate rotate.c @ 3:5a977ccbc7a9 default tip

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