~ubuntu-branches/ubuntu/trusty/netrek-client-cow/trusty

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
77
78
79
80
81
82
83
84
85
86
87
#include "config.h"
#include "copyright2.h"

#include INC_MACHINE_ENDIAN

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include INC_NETINET_IN
#include INC_NETINET_TCP
#include <netdb.h>
#include <math.h>
#include <errno.h>
#include "Wlib.h"
#include "defs.h"
#include "struct.h"
#include "data.h"
#include "packets.h"

#include "rotate.h"

#ifdef ROTATERACE
void rotate_dir(unsigned char *d, int r)
{
  (*d) += r;
}

/* general rotation */

void rotate_coord(int *x, int *y, int d, int cx, int cy)

/* values used and returned */
/* degree (pi == 128) */
/* 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