forked from hyperyoda/netrek-client-brmh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.c
76 lines (63 loc) · 1.2 KB
/
rotate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* rotate.c
*
*/
#include "copyright2.h"
#include <stdio.h>
#include <math.h>
#include "netrek.h"
#ifdef ROTATERACE
void
rotate_dir(d, r)
unsigned char *d;
int r;
{
(*d) += r;
}
/* general rotation */
void
rotate_coord(x, y, d, cx, cy)
int *x, *y; /* values used and returned */
int d; /* degree (pi == 128) */
int cx, cy; /* around center point */
{
register
int ox, oy;
ox = *x;
oy = *y;
switch (d) {
case 0:
return;
case 64:
case -192:
*x = cy - oy + cx;
*y = ox - cx + cy;
break;
case 128:
case -128:
*x = cx - ox + cx;
*y = cy - oy + cy;
break;
case 192:
case -64:
*x = oy - cy + cx;
*y = cx - ox + cy;
break;
default:{
/* do it the hard way */
double dir;
double r, dx, dy;
double rd = (double) d * 3.1415927 / 128.;
if (*x != cx || *y != cy) {
dx = (double) (*x - cx);
dy = (double) (cy - *y);
dir = atan2(dx, dy) - 3.1415927 / 2.;
r = hypot(dx, dy);
dir += rd;
*x = (int) (r * cos(dir) + cx);
*y = (int) (r * sin(dir) + cy);
}
}
}
}
#endif