OpenXcom
1.0
Open-source clone of the original X-Com
src
Geoscape
Cord.h
1
#pragma once
2
/*
3
* Copyright 2010-2016 OpenXcom Developers.
4
*
5
* This file is part of OpenXcom.
6
*
7
* OpenXcom is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* OpenXcom is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
#include "../fmath.h"
21
22
namespace
OpenXcom
23
{
24
25
struct
Cord;
26
27
struct
CordPolar
28
{
29
double
lon, lat;
30
31
inline
CordPolar
(
double
plon,
double
plat)
32
{
33
lon = plon;
34
lat = plat;
35
}
36
inline
CordPolar
(
const
CordPolar
& pol)
37
{
38
lon = pol.lon;
39
lat = pol.lat;
40
}
41
inline
CordPolar
()
42
{
43
lon = 0;
44
lat = 0;
45
}
46
explicit
inline
CordPolar
(
const
Cord
&);
47
};
48
49
struct
Cord
50
{
51
double
x, y, z;
52
53
inline
Cord
(
double
px,
double
py,
double
pz)
54
{
55
x = px;
56
y = py;
57
z = pz;
58
}
59
inline
Cord
(
const
Cord
& c)
60
{
61
x = c.x;
62
y = c.y;
63
z = c.z;
64
}
65
inline
Cord
()
66
{
67
x = 0.0;
68
y = 0.0;
69
z = 0.0;
70
}
71
explicit
inline
Cord
(
const
CordPolar
&);
72
73
inline
Cord
operator +()
74
{
75
return
*
this
;
76
}
77
inline
Cord
operator -()
78
{
79
return
Cord
(-x, -y, -z);
80
}
81
inline
Cord
& operator *=(
double
d)
82
{
83
x *= d;
84
y *= d;
85
z *= d;
86
return
*
this
;
87
}
88
inline
Cord
& operator /=(
double
d)
89
{
90
double
re = 1./d;
91
x *= re;
92
y *= re;
93
z *= re;
94
return
*
this
;
95
}
96
inline
Cord
& operator +=(
const
Cord
& c)
97
{
98
x += c.x;
99
y += c.y;
100
z += c.z;
101
return
*
this
;
102
}
103
inline
Cord
& operator -=(
const
Cord
& c)
104
{
105
x -= c.x;
106
y -= c.y;
107
z -= c.z;
108
return
*
this
;
109
}
110
inline
bool
operator ==(
const
Cord
& c)
111
{
112
return
AreSame(x, c.x) && AreSame(y, c.y) && AreSame(z, c.z);
113
}
114
115
inline
double
norm()
const
116
{
117
return
std::sqrt(x*x + y*y + z*z);
118
}
119
};
120
121
inline
Cord::Cord(
const
CordPolar
& pol)
122
{
123
x = std::sin(pol.lon) * std::cos(pol.lat);
124
y = std::sin(pol.lat);
125
z = std::cos(pol.lon) * std::cos(pol.lat);
126
}
127
128
inline
CordPolar::CordPolar(
const
Cord& c)
129
{
130
double
inv = 1/c.norm();
131
lat = asin(c.y * inv);
132
lon = atan2(c.x, c.z);
133
}
134
135
}
//namespace OpenXcom
OpenXcom::CordPolar
Definition:
Cord.h:27
OpenXcom::Cord
Definition:
Cord.h:49
Generated by
1.8.15