1 /*
2     OpenUniverse 1.0
3     Copyright (C) 2000  Raul Alonso <amil@las.es>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 /* Macros used to scale down distances/radii so we can reduce the
21   jerkiness effect in outter bodies */
22 #define RADIUSSCALE(x) ((x)*6.378)
23 #define DISTCORRECTION(x) ((x) * AU)
24 
25 /* Need no comment ;-) */
26 #define DEG2RAD(x) ((x)*M_PI/180.0)
27 #define RAD2DEG(x) ((x)*180.0/M_PI)
28 #define DISTANCE(x,y,z) sqrt((x)*(x)+(y)*(y)+(z)*(z))
29 #define CLAMP( X, MIN, MAX )  ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
30 #define CLAMP_SELF(x, mn, mx)  \
31    ( (x)<(mn) ? ((x) = (mn)) : ((x)>(mx) ? ((x)=(mx)) : (x)) )
32 
33 #define LOG(m,f) \
34         log(m); \
35         f; \
36         log(" ... OK\n"); \
37 
38 /* Vector macros */
39 
40 #define INITVECTOR( A, x, y, z)                 \
41 do {						\
42    (A)[0] = (x);                                \
43    (A)[1] = (y);                                \
44    (A)[2] = (z);                                \
45 } while (0)
46 
47 
48 #define COPYVECTOR( A, B )                  \
49 do {						\
50    (A)[0] = (B)[0];                         \
51    (A)[1] = (B)[1];                         \
52    (A)[2] = (B)[2];                         \
53 } while (0)
54 
55 
56 #define SAMEVECTOR( A, B )                  \
57 ( ((A)[0] == (B)[0]) ? (( ((A)[1] == (B)[1]) ? (( ((A)[2] == (B)[2]) ? (1) : 0)) : 0 )) : 0 )
58 
59 
60 
61 #define MODULE(V) sqrt(V[0]*V[0]+V[1]*V[1]+V[2]*V[2])
62 
63 #define NORMALIZE(V)                            \
64 do {                                            \
65    double d=MODULE(V);                          \
66    (V)[0]/=d;                                   \
67    (V)[1]/=d;                                   \
68    (V)[2]/=d;                                   \
69 } while (0)
70 
71 
72 #define ADDVECTORS( A, B, C )                   \
73 do {						\
74       (A)[0] = (B)[0] + (C)[0];                 \
75       (A)[1] = (B)[1] + (C)[1];                 \
76       (A)[2] = (B)[2] + (C)[2];                 \
77 } while (0)
78 
79 
80 #define SUBVECTORS( A, B, C )                   \
81 do {						\
82       (A)[0] = (B)[0] - (C)[0];                 \
83       (A)[1] = (B)[1] - (C)[1];                 \
84       (A)[2] = (B)[2] - (C)[2];                 \
85 } while (0)
86 
87 
88 #define MULTVECTOR( A, B, K )                   \
89 do {						\
90       (A)[0] = (B)[0] * (K);                      \
91       (A)[1] = (B)[1] * (K);                      \
92       (A)[2] = (B)[2] * (K);                      \
93 } while (0)
94 
95 
96 #define DIVVECTOR( A, B, K )                    \
97 do {                                            \
98       (A)[0] = (B)[0] / (K);                      \
99       (A)[1] = (B)[1] / (K);                      \
100       (A)[2] = (B)[2] / (K);                      \
101 } while (0)
102 
103 
104 #define DOTPRODUCT( A, B )  ( (A)[0]*(B)[0] + (A)[1]*(B)[1] + (A)[2]*(B)[2] )
105 
106 #define CROSSPRODUCT(A, B, C)                         \
107 do {						\
108    double x,y,z;                                \
109    x = (B)[1]*(C)[2] - (B)[2]*(C)[1];           \
110    y = (B)[2]*(C)[0] - (B)[0]*(C)[2];           \
111    z = (B)[0]*(C)[1] - (B)[1]*(C)[0];           \
112    (A)[0] = x;                                  \
113    (A)[1] = y;                                  \
114    (A)[2] = z;                                  \
115 } while (0)
116 
117 #define ISASPACECRAFT(S) ((planets[S].Type==SPACESHIP) || (planets[S].Type==ORBITER))
118