Compare commits
374 Commits
RELEASE_0_
...
RELEASE_0_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b129b289c | ||
|
|
a89ceb96b9 | ||
|
|
9af5f9f094 | ||
|
|
6776c2e536 | ||
|
|
4c3b4219fe | ||
|
|
a09806bb98 | ||
|
|
e175c8cc4d | ||
|
|
a53faf4565 | ||
|
|
dc653ac46c | ||
|
|
c544777d37 | ||
|
|
93a37df90a | ||
|
|
1da02cca4c | ||
|
|
4b1d777ad4 | ||
|
|
fb0916be0f | ||
|
|
806083cb25 | ||
|
|
5ba74e30b8 | ||
|
|
c39e08cb2a | ||
|
|
e4653be9a1 | ||
|
|
cd5765be1e | ||
|
|
c481b06451 | ||
|
|
91ba4618e7 | ||
|
|
fdc5521389 | ||
|
|
e88c915206 | ||
|
|
1e60698053 | ||
|
|
5702bd7ee8 | ||
|
|
8eef3eb582 | ||
|
|
31db353173 | ||
|
|
2c4a0dd998 | ||
|
|
7d7e41dacc | ||
|
|
453a53b372 | ||
|
|
ef68d18f64 | ||
|
|
ded1d2343f | ||
|
|
e6241a2f73 | ||
|
|
467254ec66 | ||
|
|
135e137921 | ||
|
|
e13a5b57d4 | ||
|
|
f1c00cdd18 | ||
|
|
8c3de351b0 | ||
|
|
0bcdb7eb70 | ||
|
|
a92b71fffc | ||
|
|
89960ab715 | ||
|
|
2a369803ae | ||
|
|
b0134a377e | ||
|
|
502c650cd9 | ||
|
|
a1bf8d2229 | ||
|
|
25b743bdec | ||
|
|
dbf7db02a2 | ||
|
|
8c998659c6 | ||
|
|
4e23b3dff5 | ||
|
|
159d3c4c6c | ||
|
|
612b5ae0bc | ||
|
|
60cbe9c1d4 | ||
|
|
4dadd29727 | ||
|
|
e4610b9baa | ||
|
|
926a0f2437 | ||
|
|
9325ec681e | ||
|
|
af383e6c39 | ||
|
|
b000691ab9 | ||
|
|
22812a0aae | ||
|
|
dda7ebfe0d | ||
|
|
9a211af659 | ||
|
|
82459a2802 | ||
|
|
1774fb2d02 | ||
|
|
f0081c7697 | ||
|
|
1e53bedca5 | ||
|
|
cf1c7e7378 | ||
|
|
5c3b569e97 | ||
|
|
cb29dcc238 | ||
|
|
d48b3f1e9a | ||
|
|
a4d60e7bd6 | ||
|
|
1a6e2509c7 | ||
|
|
8159b749f4 | ||
|
|
bec11c2939 | ||
|
|
8a189b6778 | ||
|
|
93c6845a6d | ||
|
|
b659c805fc | ||
|
|
15eaf8dc84 | ||
|
|
cafe89047c | ||
|
|
b5705ff47a | ||
|
|
1b07b25ad2 | ||
|
|
a46163bcd7 | ||
|
|
6531b1ebbc | ||
|
|
dc7bbdce11 | ||
|
|
a29cbc1112 | ||
|
|
afc2099865 | ||
|
|
7d251444e6 | ||
|
|
1c2289dacd | ||
|
|
044ac5d5d3 | ||
|
|
38167ed273 | ||
|
|
e15ffbc856 | ||
|
|
6cf2716615 | ||
|
|
0468b315d4 | ||
|
|
de66c74a91 | ||
|
|
7db73cd215 | ||
|
|
242eceb1c6 | ||
|
|
c2b84db5a2 | ||
|
|
487bee35ab | ||
|
|
9fabeb77bc | ||
|
|
bfea2dec4d | ||
|
|
2ed07850c6 | ||
|
|
b72d36d96f | ||
|
|
e3ff048ff6 | ||
|
|
ceef43681d | ||
|
|
3ec00676e4 | ||
|
|
e6575fb1db | ||
|
|
fa98d733d6 | ||
|
|
2981a10e62 | ||
|
|
551c06f885 | ||
|
|
a1c59071a1 | ||
|
|
13af443057 | ||
|
|
b8e2b0d0f9 | ||
|
|
53cd776bf6 | ||
|
|
180bba8767 | ||
|
|
377cf1662e | ||
|
|
420c747551 | ||
|
|
7c5b4a87f2 | ||
|
|
7ea241b412 | ||
|
|
1547d4ee2f | ||
|
|
3dde4113e7 | ||
|
|
205e6ef18f | ||
|
|
d53830076b | ||
|
|
296a01b7bd | ||
|
|
f47fdd63f7 | ||
|
|
b0b5f5035a | ||
|
|
629ece6e41 | ||
|
|
4c79263dcf | ||
|
|
856b6201dc | ||
|
|
f2160b1479 | ||
|
|
535f6a13b3 | ||
|
|
2ab760e456 | ||
|
|
8b75fbc1e6 | ||
|
|
82f410e955 | ||
|
|
68a19bd39f | ||
|
|
48689622b4 | ||
|
|
acc2075986 | ||
|
|
1984ae1583 | ||
|
|
427f309aea | ||
|
|
84482ad30d | ||
|
|
09b67e9440 | ||
|
|
80cf74d85f | ||
|
|
17e055a00e | ||
|
|
a8d8c9d24e | ||
|
|
99a59763f1 | ||
|
|
0fa3a329e8 | ||
|
|
5fbe532ec5 | ||
|
|
5f3de889d7 | ||
|
|
a8db14196a | ||
|
|
03b10d64a8 | ||
|
|
86892d87e9 | ||
|
|
41218272c4 | ||
|
|
8b5514fa9f | ||
|
|
f14de56712 | ||
|
|
ecc5c9865b | ||
|
|
929a56a6e8 | ||
|
|
4416df8c39 | ||
|
|
fc80610663 | ||
|
|
cb03bfcb80 | ||
|
|
35ed10e252 | ||
|
|
41fc1621b1 | ||
|
|
9fefaef31e | ||
|
|
689a942f19 | ||
|
|
cb9654f1f4 | ||
|
|
a8f8cef484 | ||
|
|
6cf51c3222 | ||
|
|
0d8ae0cabe | ||
|
|
49d6f93d8b | ||
|
|
5173d709e0 | ||
|
|
778c3ab25c | ||
|
|
aa17d9ac9a | ||
|
|
ffe1d9485e | ||
|
|
71abebe837 | ||
|
|
708e745cfd | ||
|
|
bb882a1239 | ||
|
|
6b2bf2fa8e | ||
|
|
2640b43355 | ||
|
|
d201e9b5c5 | ||
|
|
8f0f79506c | ||
|
|
121d2f92cb | ||
|
|
87e641aeda | ||
|
|
27403e2fef | ||
|
|
b5ceef5e68 | ||
|
|
5d68470c95 | ||
|
|
e176b4d8b6 | ||
|
|
218821f694 | ||
|
|
a8f4a61dc2 | ||
|
|
9221604424 | ||
|
|
5bddbd0ca9 | ||
|
|
f8dde93e05 | ||
|
|
489b562232 | ||
|
|
294a0dde63 | ||
|
|
53fbb98d4f | ||
|
|
8a2c08a0c1 | ||
|
|
b15b40ea10 | ||
|
|
0c865f540f | ||
|
|
ef4a92859c | ||
|
|
2a7b06f648 | ||
|
|
6c2ca22b3f | ||
|
|
592690f8f2 | ||
|
|
1eb87e7c73 | ||
|
|
a0e40c1fc1 | ||
|
|
2c920ae1df | ||
|
|
bbde3b36bf | ||
|
|
88a016c516 | ||
|
|
22d4058564 | ||
|
|
79e6c529ea | ||
|
|
7b22b8cd92 | ||
|
|
bc2ae82e81 | ||
|
|
764f4037b0 | ||
|
|
a60454a786 | ||
|
|
d136ad3e57 | ||
|
|
739588f9c3 | ||
|
|
505de4703b | ||
|
|
236a1f2a2d | ||
|
|
91efc5ad87 | ||
|
|
123c816048 | ||
|
|
fab6d05157 | ||
|
|
3240464c7c | ||
|
|
a2ffd27b7c | ||
|
|
af6c921757 | ||
|
|
180e2188ba | ||
|
|
23fbd5919f | ||
|
|
8aec98017a | ||
|
|
9b4fe7d92d | ||
|
|
99f11a01fc | ||
|
|
b3eacb19f6 | ||
|
|
f12840a72e | ||
|
|
f472bc563d | ||
|
|
3e05a5780d | ||
|
|
2454f8d269 | ||
|
|
b4a913e339 | ||
|
|
b82aef65e5 | ||
|
|
3730ce404f | ||
|
|
d7748704d7 | ||
|
|
1690f5475d | ||
|
|
a644bd2b03 | ||
|
|
62ca2e0227 | ||
|
|
d56289f897 | ||
|
|
aa02e72829 | ||
|
|
a878570a8d | ||
|
|
54352225f1 | ||
|
|
0b7d4c8c1e | ||
|
|
2091bf2144 | ||
|
|
0fec7b2599 | ||
|
|
74d314558c | ||
|
|
4fb45c4783 | ||
|
|
6816ecb3ea | ||
|
|
6766825159 | ||
|
|
3e63d6ca5d | ||
|
|
6ca9596807 | ||
|
|
5695fc84e1 | ||
|
|
2aea6362db | ||
|
|
bb70329c25 | ||
|
|
75bc07dc42 | ||
|
|
bac27f1ce3 | ||
|
|
787591dd79 | ||
|
|
c7c353df05 | ||
|
|
8470a9eda6 | ||
|
|
c5adb85741 | ||
|
|
2f9619f02a | ||
|
|
11cab90ce2 | ||
|
|
9ae48c2d7d | ||
|
|
00fc8205da | ||
|
|
62e85640da | ||
|
|
1b99b2a25d | ||
|
|
605ad52197 | ||
|
|
af80c5e018 | ||
|
|
18ac42b2e4 | ||
|
|
9ea57fcc30 | ||
|
|
7c27474164 | ||
|
|
afdee14332 | ||
|
|
7f5f12d37a | ||
|
|
cea0df71f8 | ||
|
|
aef484d5fc | ||
|
|
dacc051a57 | ||
|
|
e111f530c3 | ||
|
|
c00ca055bc | ||
|
|
305589cd01 | ||
|
|
6610244275 | ||
|
|
e462e64d42 | ||
|
|
39521df546 | ||
|
|
6dd8a1525c | ||
|
|
fca7a8fa47 | ||
|
|
1175179da1 | ||
|
|
06ab581edb | ||
|
|
dbcecbd3b8 | ||
|
|
4205c0a38d | ||
|
|
a76904c314 | ||
|
|
529ca14534 | ||
|
|
7423077f95 | ||
|
|
f116ee7802 | ||
|
|
09cf8c001e | ||
|
|
cfe0e18e4e | ||
|
|
2caad4a27b | ||
|
|
b5e7938ebe | ||
|
|
bd3e280fe5 | ||
|
|
39164d1438 | ||
|
|
a9c068ae3b | ||
|
|
6c7856549b | ||
|
|
d85cbc7b61 | ||
|
|
d8cbac4576 | ||
|
|
c0874a000e | ||
|
|
e317a39b2d | ||
|
|
61d4bd8adf | ||
|
|
a8deedaa66 | ||
|
|
15790ef4b4 | ||
|
|
8cf618ea75 | ||
|
|
5a81c9ecf0 | ||
|
|
4ccc2b3cfc | ||
|
|
ff8845de52 | ||
|
|
e4d4a2d8eb | ||
|
|
5a2a23cc2d | ||
|
|
8a233ddfbb | ||
|
|
2b40dc133d | ||
|
|
b26263c62d | ||
|
|
2df317eb49 | ||
|
|
5eef0e61ba | ||
|
|
021558d6dd | ||
|
|
7a6cab8381 | ||
|
|
1fcb70e553 | ||
|
|
712bbc9085 | ||
|
|
7b2370d608 | ||
|
|
98f398c99a | ||
|
|
e5efd5bf69 | ||
|
|
9d504a9e19 | ||
|
|
e96e09d112 | ||
|
|
28a6ec8065 | ||
|
|
875560b8dc | ||
|
|
fa360360cb | ||
|
|
e543b5228c | ||
|
|
63ea6cd15a | ||
|
|
79a773d25c | ||
|
|
dcc537e040 | ||
|
|
37488d0f7e | ||
|
|
aa645019e9 | ||
|
|
6179ec5319 | ||
|
|
331f91ba43 | ||
|
|
a50203dfec | ||
|
|
b7eab24f14 | ||
|
|
d824ffd02b | ||
|
|
238c6f7c88 | ||
|
|
0dd244fb0c | ||
|
|
61a8afa06a | ||
|
|
ed49eadb6a | ||
|
|
ecf19f8af4 | ||
|
|
9d5eb462c9 | ||
|
|
1088c5fa57 | ||
|
|
ad2bd3db0f | ||
|
|
abbcf855c4 | ||
|
|
83e648b7d6 | ||
|
|
89d049ff73 | ||
|
|
ac3a2bce72 | ||
|
|
ad20c2d242 | ||
|
|
6c9aa9527d | ||
|
|
7ad1e2be73 | ||
|
|
604f038cfb | ||
|
|
b185b1a4d9 | ||
|
|
89a65000a5 | ||
|
|
9c83903c2a | ||
|
|
68af57b759 | ||
|
|
9c4b4abb50 | ||
|
|
233ffb3b10 | ||
|
|
34e2bac4d0 | ||
|
|
6d4c38a3c8 | ||
|
|
b6ec5707e8 | ||
|
|
68d3b7b20c | ||
|
|
b84b36d885 | ||
|
|
f43e375d62 | ||
|
|
ab67fa2c15 | ||
|
|
7aff56c284 | ||
|
|
c13dc3a829 | ||
|
|
baf89c9d63 | ||
|
|
a8b4d21a65 | ||
|
|
6c20288ff1 | ||
|
|
935d4f3bda |
481
COPYING
Normal file
481
COPYING
Normal file
@@ -0,0 +1,481 @@
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
99
Makefile.am
Normal file
99
Makefile.am
Normal file
@@ -0,0 +1,99 @@
|
||||
EXTRA_DIST = mksymlinks.sh acsite.m4 acconfig.h
|
||||
|
||||
SUBDIRS = simgear
|
||||
|
||||
#
|
||||
# Additional all, clean, and distclean rules for additional packages.
|
||||
# We can't just include the additional package dirs in SUBDIRS (which
|
||||
# would be nice because there are then problems with make dist
|
||||
#
|
||||
|
||||
all:
|
||||
@list='@subdirs@'; \
|
||||
target=`echo $@`; \
|
||||
for subdir in $$list; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
dot_seen=yes; \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
|
||||
done
|
||||
|
||||
install:
|
||||
@list='@subdirs@'; \
|
||||
target=`echo $@`; \
|
||||
for subdir in $$list; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
dot_seen=yes; \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
|
||||
done
|
||||
|
||||
clean:
|
||||
@list='@subdirs@'; \
|
||||
target=`echo $@`; \
|
||||
for subdir in $$list; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
dot_seen=yes; \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
|
||||
done
|
||||
|
||||
distclean:
|
||||
@list='@subdirs@'; \
|
||||
target=`echo $@`; \
|
||||
for subdir in $$list; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
dot_seen=yes; \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
|
||||
done
|
||||
|
||||
#
|
||||
# distclean the associated packages and include them in the dist
|
||||
#
|
||||
|
||||
dist-hook:
|
||||
tar cf - simgear/metar | (cd $(distdir); tar xvf -)
|
||||
@list='@subdirs@'; \
|
||||
target=distclean; \
|
||||
for subdir in $$list; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
dot_seen=yes; \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| case "$$amf" in *=*) echo "distclean error ignored...";; *k*) fail=yes;; *) echo "distclean error ignored...";; esac; \
|
||||
done
|
||||
tar cf - simgear/metakit | (cd $(distdir); tar xvf -)
|
||||
|
||||
|
||||
#
|
||||
# Rule to build RPM distribution package
|
||||
#
|
||||
rpm: dist
|
||||
cp $(PACKAGE)-$(VERSION).tar.gz /usr/src/packages/SOURCES
|
||||
rpm -ba @PACKAGE@.spec
|
||||
|
||||
75
NEWS
Normal file
75
NEWS
Normal file
@@ -0,0 +1,75 @@
|
||||
New in 0.0.14
|
||||
* Added a module to manage waypoints and routes, calculate bearing and
|
||||
distance to next waypoint, lateral distance off route, etc.
|
||||
* Moved some of the basic time management code over from flightgear.
|
||||
* Bucket dimensions can be returned in meters
|
||||
* Added SOCK_STREAM (TCP) socket support to the networking code.
|
||||
* Updated random number generator interface so application can provide
|
||||
it's own seed value as well as use the default time seed.
|
||||
* Added a routine to calculate the distance between a point and a line segment.
|
||||
* Updates to the property manager and the property list loader/saver.
|
||||
* Added an explanation of the rational behind our terrain texture coordinate
|
||||
generation code.
|
||||
* Fixed sky dome so that the color at the horizon will always match
|
||||
the specified fog color.
|
||||
* Did a fair amount of fg -> sg name space updating (lots left to do.)
|
||||
* December 14, 2000
|
||||
* Added support for KAI C++ on linux.
|
||||
* MSVC tweaks.
|
||||
* MacOS tweaks.
|
||||
* FreeBSD tweaks.
|
||||
|
||||
New in 0.0.13
|
||||
* September 14, 2000
|
||||
* Added support for reading and writing xml files (easyxml)
|
||||
* Then updates to property manager and xml code.
|
||||
* Update magnetic variation code.
|
||||
* Sky code now uses glPushAttrib and glPopAttrib so it plays better with
|
||||
other ssg based apps.
|
||||
* MacOS tweaks.
|
||||
* MSVC tweaks.
|
||||
|
||||
New in 0.0.12
|
||||
* July 19, 2000
|
||||
* Converted project license from GPL to LGPL.
|
||||
* Moved low level IO (socket, file, serial) code over to SimGear.
|
||||
* Moved ephemeral code into simgear
|
||||
* Moved basic world time code into simgear
|
||||
* Added a property manager (registry)
|
||||
* Some documentation added.
|
||||
|
||||
New in 0.0.11
|
||||
* July 3, 2000
|
||||
* Replaced gdbm with metakit
|
||||
* Added drop in sky (depends on plib)
|
||||
* Added spherical course and dist given two points calculations
|
||||
* MSVC5 fixes
|
||||
* Math/bucket/tiling tweaks from Norman Vine
|
||||
|
||||
New in 0.0.7
|
||||
* March 29, 2000
|
||||
* Added support for RedHat package building contributed by Habibie
|
||||
<habibie@MailandNews.com>
|
||||
* Added gdbm to SimGear. Many systems will already have gdbm installed so
|
||||
it is only built if it doesn't already exist on the user's platform.
|
||||
gdbm is a set of database routines that use extendible hashing and works
|
||||
similar to the standard UNIX dbm routines. This guarantees the availability
|
||||
of gdbm to any application that uses SimGear.
|
||||
* Optimizations and bullet proofing of magnetic variation code by Norman
|
||||
Vine and Ed Williams
|
||||
|
||||
New in 0.0.6
|
||||
* March 27, 2000
|
||||
* Added Nima World Magnetic Model 2000 contributed by Ed Williams
|
||||
* Fixes for MSVC++
|
||||
|
||||
New in 0.0.5
|
||||
* March 17, 2000
|
||||
* Restructured directory layout to facilitate windows/mac IDE builds.
|
||||
|
||||
New in 0.0.4
|
||||
* Removed mat3.h and friends (we now use plib's sg lib for these sorts of
|
||||
things.)
|
||||
|
||||
New in 0.0.3
|
||||
* Release that conincides with FlightGear-0.7.2
|
||||
3
README
Normal file
3
README
Normal file
@@ -0,0 +1,3 @@
|
||||
MSVC5 users:
|
||||
|
||||
Copy simgear/config.h.vc5 to simgear/config.h before building.
|
||||
243
README.metakit
Normal file
243
README.metakit
Normal file
@@ -0,0 +1,243 @@
|
||||
With the author's permission, SimGear now bundles MetaKit. MetaKit is
|
||||
explained
|
||||
|
||||
The MetaKit Library 2.01 March 2000
|
||||
==============================================================================
|
||||
|
||||
|
||||
WHAT IT IS - MetaKit is an embeddable database which runs on Unix, Windows,
|
||||
Macintosh, and other platforms. It lets you build applications which
|
||||
store their data efficiently, in a portable way, and which will not need a
|
||||
complex runtime installation. In terms of the data model, MetaKit takes
|
||||
the middle ground between RDBMS, OODBMS, and flat-file databases - yet it
|
||||
is quite different from each of them.
|
||||
|
||||
WHAT IT ISN'T - MetaKit is not: 1) multi-user/-threading, 2) scalable to
|
||||
gigabytes, 3) proprietary software, 4) full of bugs, 5) just a toy.
|
||||
|
||||
TECHNOLOGY - Everything is stored variable-sized yet with efficient positional
|
||||
row access. Changing an existing datafile structure is as simple as re-
|
||||
opening it with that new structure. All changes are transacted. You can
|
||||
mix and match software written in C++, Python, and Tcl. Things can't get
|
||||
much more flexible...
|
||||
|
||||
CORE - The Metakit core library is written in C++. It has a code footprint of
|
||||
just over 100 Kb on Windows. It can be used as DLL, or linked statically.
|
||||
Debug builds include extensive assertion checks to catch problems early.
|
||||
|
||||
PYTHON - The binding for Python is called "Mk4py". It uses SCXX by Gordon
|
||||
McMillan as C++ glue interface. The source is in directory "python/".
|
||||
|
||||
TCL/TK - The MK extension for Tcl is called "Mk4tcl". It is being used in a
|
||||
number of commercial projects, for in-house use as well as in commercially
|
||||
distributed products. The source is in directory "tcl/".
|
||||
|
||||
LICENSE AND SUPPORT - MetaKit 2.01 is distributed as open source software (the
|
||||
X/MIT-style license is at the end of this document). Commercial support
|
||||
is available through an Enterprise License, see the URL mentioned below.
|
||||
|
||||
DOCUMENTATION - All documentation uses HTML. The main page is "MetaKit.html",
|
||||
which leads to the rest of the documentation in the "doc/" directory.
|
||||
|
||||
WEBSITE URLS - The main pages on the world wide web, for news and downloads:
|
||||
Homepage: http://www.equi4.com/metakit/
|
||||
Python news: http://www.equi4.com/metakit/python.html
|
||||
Tcl/Tk news: http://www.equi4.com/metakit/tcl.html
|
||||
License info: http://www.equi4.com/metakit/license.html
|
||||
Contact info: http://www.equi4.com/contact.html
|
||||
|
||||
|
||||
INSTALLATION
|
||||
============
|
||||
|
||||
Starting with this release, all platform builds and language bindings are now
|
||||
designed to work from a single common "builds/" directory. It turns out to
|
||||
be impossible to keep build side-effects limited to *just* this directory
|
||||
(CodeWarrior can't be told where to place its temp data, and Visual C++ still
|
||||
alters a few files next to the project ".dsw" file, to name two offenders).
|
||||
|
||||
UNIX
|
||||
|
||||
It is no longer advised to build the Unix code in the "unix/" directory.
|
||||
Instead, you should perform the following steps:
|
||||
% cd builds
|
||||
% ../unix/configure
|
||||
% make
|
||||
% make test
|
||||
And optionally (this only installs the core lib, not script extensions):
|
||||
% make install
|
||||
|
||||
By switching to the "builds/" directory, you will keep the distribution
|
||||
directory tree 100% unaltered. All changes are made in this subdir, and
|
||||
all final build results are left behind in this same subdir.
|
||||
|
||||
Nastiness: if you build Mk4tcl, please do a "make Mk4tcl.so" as well.
|
||||
And if you intend to create the Python extension, do a "make Mk4py.so".
|
||||
The "libmk4tcl.so.0.0.0" and "libMk4py.so.0.0.0" targets are bogus ones.
|
||||
|
||||
You will probably have to make changes in the makefile to locate the
|
||||
proper includes and libs for Python (Tcl has been fixed, see "--with-tcl).
|
||||
You probably only need to adjust "CXX_SWITCHES_PY" to find the headers.
|
||||
|
||||
To build with STL containers and strings, you can do the following:
|
||||
make CXXFLAGS='-Dq4_STD' test # add -O3 etc, as needed
|
||||
This passes the test suite on Linux RedHat 5.2 with gcc 2.95-2.
|
||||
|
||||
See below for some platform-specific build notes.
|
||||
|
||||
WINDOWS
|
||||
|
||||
There is a "win/" directory which contains subdirectories for a number of
|
||||
compiler systems. MetaKit has been built with many different compilers
|
||||
in the past (Microsoft, Borland, Watcom, Symantec, Metrowerks, Optima),
|
||||
but to preserve my sanity (there are 12 configurations for MSVC6 alone!),
|
||||
I am limiting myself to MSVC6, MWCW5, Borland C++ Builder 4, and Cygwin.
|
||||
|
||||
The MS Visual C++ 6.0 project is "win/msvc60/mksrc.dsw", with subprojects
|
||||
for the C++ demo (mkdemo), building dll's (mkdll), static libs (mklib),
|
||||
regression tests (mktest), as well as Tcl (mktcl) and Python (mkpython).
|
||||
It has been set up to place all intermediate files and final results in
|
||||
the "builds/" subdirectory, even though you'll launch it from "win/".
|
||||
|
||||
To build with STL containers and strings under MSVC, define "q4_STD".
|
||||
To build with MFC containers and strings under MSVC, define "q4_MFC".
|
||||
|
||||
The Metrowerks Codewarrior project is in the "mac/" directory, and can be
|
||||
used to build both Mac and Windows versions (on either Mac *or* Windows).
|
||||
The core libraries are built with "mac/cw5.mcp", demos / tests are built
|
||||
with "cw5apps.mcp", Tcl is "cw5tcl.mcp", and Python is "cw5python.mcp".
|
||||
|
||||
The Borland C++ Builder projects have not yet been incorporated in this
|
||||
release, but the "KitViewer" application is an example of how to use BCB.
|
||||
|
||||
The Cygwin build (B20.1 / gcc 2.95.2) is different, because it uses the
|
||||
unix autoconf system, and must be launched as described above for UNIX.
|
||||
I have upgraded to the latest development of libtool to be able to build
|
||||
DLL's with Cygwin. You can build the "-mno-cygwin" version by editing
|
||||
the Makefile by hand and adding that option to CXXFLAGS.
|
||||
|
||||
Rob Bloodgood adds that the following GCC options are for maximum code
|
||||
efficiency on x86 hardware: "-O2 -m486 -malign-loops=2 -malign-jumps=2".
|
||||
I have not yet tried this myself, but am passing on the tip.
|
||||
|
||||
MACINTOSH
|
||||
|
||||
The Mac version requires Metrowerks CodeWarrior 5. See the info above
|
||||
in the Windows section (MWCW is multi-platform). The projects are all
|
||||
located in the "mac/" folder, which is also where MWCW will place its own
|
||||
"... Data" folders with intermediate results. As with all other setups,
|
||||
final results are made to end up in the "builds/" directory.
|
||||
|
||||
Static 68K builds appear to work fine, the 68K CFM variants will need
|
||||
some more work (I couldn't get the libraries to export their symbols).
|
||||
|
||||
|
||||
PLATFORM-SPECIFIC NOTES
|
||||
=======================
|
||||
|
||||
* Linux RH 5.2 / gcc 2.95.2
|
||||
|
||||
Builds with gcc 2.95.2 work out of the box. The Tcl extension ends up as
|
||||
".libs/libmk4tcl.so.0.0.0" (to please libtool), and should be renamed to
|
||||
"Mk4tcl.so". Similarly, ".libs/libMk4py.so.0.0.0" is in fact the Python
|
||||
extension, and *must* be renamed to "Mk4py.so" to call it from Python.
|
||||
|
||||
The core MK libs end up as ".libs/libmk4.a" and ".libs/libmk4.so.0.0.0".
|
||||
|
||||
* Solaris 2.6 / gcc 2.8.1
|
||||
|
||||
The Solaris builds are nasty for several reasons:
|
||||
|
||||
- I do not own such a machine, and often have to make arrangements
|
||||
(or fight limited space on one of the machines I can telnet to).
|
||||
- The gcc 2.8.1 optimizer appears to be buggy, I have had to turn off
|
||||
the default "-O3" flag to prevent compiler crashes (several files).
|
||||
This problems appears to be resolved with gcc 2.95.
|
||||
- Locking on Solaris (especially w.r.t NFS) remains a mystery to me.
|
||||
The Tcl and Python extensions both use locking (the core not yet).
|
||||
See tcl/Mk4tcl.cpp around line 520, and python/PyStorage.cpp around
|
||||
line 80 for details. It's all pretty messy, and not 100% correct.
|
||||
|
||||
Despite this, I'm doing my best to resolve these issues. Having a solid
|
||||
build of the core *and* of Tcl / Python extensions is quite important.
|
||||
|
||||
* Other Unix systems
|
||||
|
||||
No further notes, though many systems will build fine out of the box.
|
||||
|
||||
* Windows
|
||||
|
||||
MSVC 6 builds MK as static lib and as DLL (universal config, I have not
|
||||
yet created build versions with MFC or STL, mainly because MK can now be
|
||||
used in all contexts regardless of how it was built). The Python and Tcl
|
||||
extensions build as dynamic extensions (a static build is easy to add).
|
||||
|
||||
MWCW 5 builds MK as static lib and as DLL (interestingly enough, the DLL
|
||||
is slightly smaller than MSVC 6 - 102 vs 108 Kb - when their runtimes are
|
||||
linked in dynamically as well). I have not added Win builds for Tcl or
|
||||
Python, since MSVC 6 has those already.
|
||||
|
||||
Cygwin B20.1, with gcc 2.95.2 ugrade, also builds MK as static lib and as
|
||||
DLL. Both "pure" Cygwin (i.e. requiring cygwin1.dll) and mingw32 (using
|
||||
the -mno-cygwin flag) build, but there are some hairy include issues when
|
||||
it comes to choosing the right locking model for Tcl and Python. These
|
||||
issues have not been resolved fully.
|
||||
|
||||
* Macintosh
|
||||
|
||||
MWCW 5 builds PPC shared libs, PPC static libs, and 68K static libraries.
|
||||
|
||||
Building 68K CFM libraries leads to a "MetaKit 68K.shlb" which comes out
|
||||
of the linker without errors, but the result does not seem to have any
|
||||
export symbols defined (despite the fact that the library is over 200 K).
|
||||
Because of that, I've been unable to build apps or Mk4tcl/Mk4py so far.
|
||||
|
||||
The other three configurations build, but for some reason MK's regression
|
||||
test stops at L03 (everything up to that point looks ok, i.e. over 90%).
|
||||
|
||||
The Mk4tcl PPC extension appears to work (quick manual test), and so does
|
||||
the Python extension, "Mk4py.PPC.slb". I have not yet given these two
|
||||
a serious workout, hoping to have a basic test harness in place soon.
|
||||
|
||||
* VMS, BeOS, ...
|
||||
|
||||
No news yet, please report your findings with any other platform builds.
|
||||
|
||||
|
||||
WHAT'S MISSING HERE
|
||||
===================
|
||||
|
||||
- a section on basic concepts (or maybe it doesn't belong here?)
|
||||
- a section on getting started (C++, Python, Tcl all differ - point to
|
||||
the respective intro pages)
|
||||
- maybe a small sample for each of C++ / Tcl / Python, to give an idea
|
||||
- mention TclKit, scripted docs (WiKit/Tequila?), VFS?
|
||||
- I forgot... please tell me :)
|
||||
|
||||
|
||||
LICENSE AND COPYRIGHT STATEMENT
|
||||
===============================
|
||||
|
||||
Copyright (c) 1996-2000 Jean-Claude Wippler
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
==============================================================================
|
||||
-- Jean-Claude Wippler <jcw@equi4.com>
|
||||
76
SimGear.spec.in
Normal file
76
SimGear.spec.in
Normal file
@@ -0,0 +1,76 @@
|
||||
%define ver @VERSION@
|
||||
%define rel 1
|
||||
%define prefix /usr
|
||||
|
||||
Summary: Simulator Construction Gear.
|
||||
Name: @PACKAGE@
|
||||
Version: %ver
|
||||
Release: %rel
|
||||
Copyright: LGPL
|
||||
Group: Libraries/Graphics
|
||||
Source: %{name}-%{version}.tar.gz
|
||||
#URL:
|
||||
BuildRoot: /tmp/%{name}-%{version}-%{rel}-root
|
||||
Packager: Fill In As You Wish
|
||||
Docdir: %{prefix}/doc
|
||||
|
||||
%description
|
||||
This package contains a tools and libraries useful for constructing
|
||||
simulation and visualization applications such as FlightGear or TerraGear.
|
||||
|
||||
Authors:
|
||||
N/A
|
||||
|
||||
%prep
|
||||
%setup -n %{name}-%{version}
|
||||
|
||||
|
||||
%build
|
||||
# Needed for snapshot releases.
|
||||
if [ ! -f configure ]; then
|
||||
CFLAGS="$RPM_OPT_FLAGS" ./autogen.sh --prefix=%prefix
|
||||
else
|
||||
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix
|
||||
fi
|
||||
|
||||
if [ "$SMP" != "" ]; then
|
||||
JSMP = '"MAKE=make -k -j $SMP"'
|
||||
fi
|
||||
|
||||
make ${JSMP};
|
||||
|
||||
|
||||
%install
|
||||
[ -d ${RPM_BUILD_ROOT} ] && rm -rf ${RPM_BUILD_ROOT}
|
||||
|
||||
make prefix=${RPM_BUILD_ROOT}%{prefix} install
|
||||
|
||||
#
|
||||
# Generating file lists and store them in file-lists
|
||||
# Starting with the directory listings
|
||||
#
|
||||
find ${RPM_BUILD_ROOT}%{prefix}/{bin,include,lib} -type d | sed "s#^${RPM_BUILD_ROOT}#\%attr (-\,root\,root) \%dir #" > file-lists
|
||||
%{?ETCDR:find ${RPM_BUILD_ROOT}%{!?SYSCF:%{prefix}}/etc -type d | sed "s#^${RPM_BUILD_ROOT}#\%attr (-\,root\,root) \%dir #" >> file-lists}
|
||||
|
||||
#
|
||||
# Then, the file listings
|
||||
#
|
||||
echo "%defattr (-, root, root)" >> file-lists
|
||||
%{?ETCDR:find ${RPM_BUILD_ROOT}%{!?SYSCF:%{prefix}}/etc/%{name}.conf -type f | sed -e "s#^${RPM_BUILD_ROOT}#%config #g" >> file-lists}
|
||||
find ${RPM_BUILD_ROOT}%{prefix} -type f | sed -e "s#^${RPM_BUILD_ROOT}##g" >> file-lists
|
||||
|
||||
|
||||
%clean
|
||||
(cd ..; rm -rf %{name}-%{version} ${RPM_BUILD_ROOT})
|
||||
|
||||
|
||||
%files -f file-lists
|
||||
%defattr (-, root, root)
|
||||
%doc AUTHORS
|
||||
%doc COPYING
|
||||
%doc ChangeLog
|
||||
%doc INSTALL
|
||||
%doc NEWS
|
||||
%doc README
|
||||
%doc %{name}.spec.in
|
||||
|
||||
184
Thanks
Normal file
184
Thanks
Normal file
@@ -0,0 +1,184 @@
|
||||
A very special thanks is due to the following people and groups.
|
||||
|
||||
Note: as hard as we've tried, it is impossible to perfectly maintain
|
||||
this file. If you are aware of someone who you think should be
|
||||
included here, PLEASE let me know. Projects like this are made
|
||||
possible only by the help and hard work of others. I want to properly
|
||||
credit everyone who has contributed to this project.
|
||||
|
||||
|
||||
Raul Alonzo <amil@las.es>
|
||||
Mr. Alonzo is the author of Ssystem and provided his kind permission
|
||||
for using the moon texture. I also used parts of his code as a template
|
||||
when adding the texture. Ssystem Homepage can be found at:
|
||||
http://www1.las.es/~amil/ssystem
|
||||
|
||||
|
||||
Paul Bleisch <pbleisch@acm.org>
|
||||
Paul redid the "debug" system so that it would be much more flexible,
|
||||
so it could be easily disabled for production system, and so that
|
||||
messages for certain subsystems could be selectively enabled.
|
||||
Also contributed a first stab at a config file/command line parsing
|
||||
system.
|
||||
|
||||
|
||||
Bernie Bright <bbright@c031.aone.net.au>
|
||||
Many C++ style, usage, and implementation improvements.
|
||||
STL portability, tons o' stuff. :-)
|
||||
Currently trying to get a BeOS port together but life keeps getting
|
||||
in the way!
|
||||
|
||||
|
||||
Gene Buckle <geneb@deltasoft.com>
|
||||
Gene has done a lot of work getting FG to compile with the MSVC++
|
||||
compiler. Also, he has pushed, proded, and bugged me endlessly to
|
||||
do my stuff right. (I mean that in a good way, because sometimes
|
||||
when the little nudge in the right direction isn't working, I need
|
||||
a good hard shove.) :-)
|
||||
|
||||
|
||||
John Check <j4strngs@rockfish.net>
|
||||
Cloud textures
|
||||
|
||||
|
||||
Jean-Francois Doue
|
||||
Vector 2D, 3D, 4D and Matrix 3D and 4D inlined C++ classes. (Based on
|
||||
Graphics Gems IV ed. Paul S. Heckbert)
|
||||
http://www.animats.com/simpleppp/ftp/public_html/topics/developers.html
|
||||
|
||||
|
||||
Bruce Finney <bfinney@gte.net>
|
||||
MSVC5 compatibility.
|
||||
|
||||
|
||||
Jean-loup Gailly and Mark Adler <zlib@gzip.org>
|
||||
Authors of the zlib library. Used for on-the-fly compression and
|
||||
decompression routines.
|
||||
http://www.cdrom.com/pub/infozip/zlib/
|
||||
|
||||
|
||||
Thomas Gellekum <tg@ihf.rwth-aachen.de>
|
||||
Changes and updates for compiling on FreeBSD
|
||||
|
||||
|
||||
Habibie <habibie@MailandNews.com>
|
||||
RedHat package building changes for SimGear.
|
||||
|
||||
|
||||
Bruce Jackson of NASA <e.b.jackson@larc.nasa.gov>
|
||||
Developed the LaRCsim code under funding by NASA which we use to provide
|
||||
the flight model. Bruce has patiently answered my many, many questions.
|
||||
http://dcb.larc.nasa.gov/www/DCBStaff/ebj/ebj.html
|
||||
|
||||
|
||||
Richard Kaszeta <bofh@me.umn.edu>
|
||||
Contributed screen buffer to ppm screen shot routine.
|
||||
Rich has also helped in the early development of the Flight Gear "altitude
|
||||
hold autopilot module" by teaching Curt Olson the basics of Control Theory
|
||||
and helping him code and debug early versions. Curt's "Boss" Bob Hain
|
||||
also contributed <bob@me.umn.edu>. Further details available at:
|
||||
http://www.menet.umn.edu/~curt/fgfs/Docs/Autopilot/AltitudeHold/AltitudeHold.html
|
||||
Rich's Homepage: http://www.menet.umn.edu/~kaszeta
|
||||
|
||||
|
||||
Tom Knienieder <tom@knienieder.com>
|
||||
Ported Steve's Audio library first to OpenBSD and IRIX and
|
||||
after that also to Win32
|
||||
|
||||
|
||||
David Megginson <david@megginson.com>
|
||||
SimGear property manager/registry
|
||||
|
||||
|
||||
Curt Olson <curt@flightgear.org>
|
||||
Curt is responsible for overall project and source code management.
|
||||
He has his hands in many of the areas.
|
||||
|
||||
|
||||
Petter Reinholdtsen <pere@games.no>
|
||||
Incorporated the Gnu automake/autoconf system (with libtool).
|
||||
This should streamline and standardize the build process for all
|
||||
Unix-like platforms. It should have little effect on IDE type
|
||||
environments since the don't use the Unix make system.
|
||||
|
||||
|
||||
Paul Schlyter <pausch@saaf.se>
|
||||
Mr. Schlyter provided Durk Talsma with all the information
|
||||
he needed to write the astro code. Mr. S. is also willing
|
||||
to answer astro-related questions whenever one needs to.
|
||||
http://welcome.to/pausch
|
||||
|
||||
|
||||
Durk Talsma <d.talsma@chello.nl>
|
||||
Accurate Sun, Moon, and Planets.
|
||||
Sun changes color based on position in sky.
|
||||
Moon has correct phase and blends well into the sky.
|
||||
Planets are correctly positioned and have proper magnitude.
|
||||
Added time zone support in the SGTime class.
|
||||
Help with time functions, gui, and other misc stuff.
|
||||
http://people.a2000.nl/dtals
|
||||
|
||||
|
||||
Mark Vallevand <Mark.Vallevand@UNISYS.com>
|
||||
Contributed some METAR parsing code.
|
||||
Contributed some win32 screen printing routines.
|
||||
|
||||
|
||||
Gary R. Van Sickle <tiberius@braemarinc.com>
|
||||
Contributed some initial GameGLUT support and other fixes.
|
||||
Has done some interesting preliminary work on a binary file format
|
||||
http://www.woodsoup.org/projs/ORKiD/fgfs.htm
|
||||
|
||||
Has set up a 'Cygwin Tips' site that has been very helpful to many
|
||||
people in getting a Cygwin Unix-on-Windows build environment set up
|
||||
so they can build FG effectively.
|
||||
http://www.woodsoup.org/projs/ORKiD/cygwin.htm
|
||||
|
||||
|
||||
Norman Vine <nhv@yahoo.com>
|
||||
Provided more than uncountable URL's to the "FlightGear Community".
|
||||
Many performance optimizations throughout the code.
|
||||
Lots of windoze related contributions.
|
||||
Contributed wgs84 distance and course routines.
|
||||
Contributed a great circle route autopilot mode based on wgs84 routines.
|
||||
|
||||
|
||||
Ed Williams <Ed_Williams@compuserve.com>
|
||||
Contributed magnetic variation code (impliments Nima WMM 2000)
|
||||
We've also borrowed from Ed's wonderful aviation formulary at various
|
||||
times as well.
|
||||
http://www.best.com/~williams/index.html
|
||||
|
||||
|
||||
Jean-Claude Wippler <jcw@equi4.com>
|
||||
Author of MetaKit - a portable, embeddible database with a portable
|
||||
data file format. This software is not GPL'd but the author is kindly
|
||||
allowing us to bundle MetaKit with our code. MetaKit has a liberal
|
||||
X/MIT-style license. Please see the following URL for more info:
|
||||
http://www.equi4.com/metakit
|
||||
|
||||
|
||||
WoodSoup Project http://www.woodsoup.org
|
||||
Provided computing resources and services so that the Flight Gear
|
||||
project could have real home. This includes, web services,
|
||||
ftp services, shell accounts, email lists, dns services, etc.
|
||||
|
||||
|
||||
Robert Allan Zeh <raz@cmg.FCNBD.COM>
|
||||
Helped me tremendously in figuring out the Cygnus win32 compiler and
|
||||
how to link with .dll's. With out him the first runable win32
|
||||
version of FG would have been impossible.
|
||||
|
||||
|
||||
|
||||
NOTE:
|
||||
----
|
||||
|
||||
THIS DOCUMENT WAS INITIALLY WRITTEN BY
|
||||
Curt L. Olson <curt@flightgear.org>
|
||||
|
||||
|
||||
05 Jul 2000 Removed non-SimGear entries (CLO)
|
||||
|
||||
08 Mar 2000 CONTENTS RESEARCHED AND UPDATED by
|
||||
Oliver Delise <delise@mail.isis.de>
|
||||
330
acconfig.h
Normal file
330
acconfig.h
Normal file
@@ -0,0 +1,330 @@
|
||||
/* acconfig.h
|
||||
This file is in the public domain.
|
||||
|
||||
Descriptive text for the C preprocessor macros that
|
||||
the distributed Autoconf macros can define.
|
||||
No software package will use all of them; autoheader copies the ones
|
||||
your configure.in uses into your configuration header file templates.
|
||||
|
||||
The entries are in sort -df order: alphabetical, case insensitive,
|
||||
ignoring punctuation (such as underscores). Although this order
|
||||
can split up related entries, it makes it easier to check whether
|
||||
a given entry is in the file.
|
||||
|
||||
Leave the following blank line there!! Autoheader needs it. */
|
||||
|
||||
|
||||
/* Define if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
#undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Define if using alloca.c. */
|
||||
#undef C_ALLOCA
|
||||
|
||||
/* Define if type char is unsigned and you are not using gcc. */
|
||||
#ifndef __CHAR_UNSIGNED__
|
||||
#undef __CHAR_UNSIGNED__
|
||||
#endif
|
||||
|
||||
/* Define if the closedir function returns void instead of int. */
|
||||
#undef CLOSEDIR_VOID
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
#undef const
|
||||
|
||||
/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
|
||||
This function is required for alloca.c support on those systems. */
|
||||
#undef CRAY_STACKSEG_END
|
||||
|
||||
/* Define for DGUX with <sys/dg_sys_info.h>. */
|
||||
#undef DGUX
|
||||
|
||||
/* Define if you have <dirent.h>. */
|
||||
#undef DIRENT
|
||||
|
||||
/* Define to enable audio support */
|
||||
#undef ENABLE_AUDIO_SUPPORT
|
||||
|
||||
/* Define to enable GLUT joystick support (limited to 3 axes) */
|
||||
#undef ENABLE_GLUT_JOYSTICK
|
||||
|
||||
/* Define to enable plib joystick support (recommended) */
|
||||
#undef ENABLE_PLIB_JOYSTICK
|
||||
|
||||
/* Define to eliminate all trace of debugging messages such as for a
|
||||
release build */
|
||||
#undef FG_NDEBUG
|
||||
|
||||
/* Define to include Oliver's networking support */
|
||||
#undef FG_NETWORK_OLK
|
||||
|
||||
/* Define to avoid Christian's new weather code */
|
||||
#undef FG_OLD_WEATHER
|
||||
|
||||
/* Define if we are building FGFS (should always be defined) */
|
||||
#undef FGFS
|
||||
|
||||
/* Define to enable 3dfx/glide render in a window hack under unix.
|
||||
This probably won't work under windows. */
|
||||
#undef XMESA
|
||||
#undef FX
|
||||
|
||||
/* Define to the type of elements in the array set by `getgroups'.
|
||||
Usually this is either `int' or `gid_t'. */
|
||||
#undef GETGROUPS_T
|
||||
|
||||
/* Define if the `getloadavg' function needs to be run setuid or setgid. */
|
||||
#undef GETLOADAVG_PRIVILEGED
|
||||
|
||||
/* Define if the `getpgrp' function takes no argument. */
|
||||
#undef GETPGRP_VOID
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define if you have alloca, as a function or macro. */
|
||||
#undef HAVE_ALLOCA
|
||||
|
||||
/* Define if you have <alloca.h> and it should be used (not on Ultrix). */
|
||||
#undef HAVE_ALLOCA_H
|
||||
|
||||
/* Define if you external variables daylight. */
|
||||
#undef HAVE_DAYLIGHT
|
||||
|
||||
/* Define if you don't have vprintf but do have _doprnt. */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
/* Define if your system has a working fnmatch function. */
|
||||
#undef HAVE_FNMATCH
|
||||
|
||||
/* Define if your system has its own `getloadavg' function. */
|
||||
#undef HAVE_GETLOADAVG
|
||||
|
||||
/* Define if you have getrusage() */
|
||||
#undef HAVE_GETRUSAGE
|
||||
|
||||
/* Define if you have the getmntent function. */
|
||||
#undef HAVE_GETMNTENT
|
||||
|
||||
/* Define if you have the gpc library and headers installed. */
|
||||
#undef HAVE_GPC_H
|
||||
|
||||
/* Define if the `long double' type works. */
|
||||
#undef HAVE_LONG_DOUBLE
|
||||
|
||||
/* Define if you support file names longer than 14 characters. */
|
||||
#undef HAVE_LONG_FILE_NAMES
|
||||
|
||||
/* Define if you have a working `mmap' system call. */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define if system calls automatically restart after interruption
|
||||
by a signal. */
|
||||
#undef HAVE_RESTARTABLE_SYSCALLS
|
||||
|
||||
/* Define if you have rint() which rounds to closest int but returns
|
||||
result as a double data type. */
|
||||
#undef HAVE_RINT
|
||||
|
||||
/* Define if your struct stat has st_blksize. */
|
||||
#undef HAVE_ST_BLKSIZE
|
||||
|
||||
/* Define if your struct stat has st_blocks. */
|
||||
#undef HAVE_ST_BLOCKS
|
||||
|
||||
/* Define if you have the strcoll function and it is properly defined. */
|
||||
#undef HAVE_STRCOLL
|
||||
|
||||
/* Define if your struct stat has st_rdev. */
|
||||
#undef HAVE_ST_RDEV
|
||||
|
||||
/* Define if you have the strftime function. */
|
||||
#undef HAVE_STRFTIME
|
||||
|
||||
/* Define if you have <sys/param.h> */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define if you have <sys/stat.h> that is POSIX.1 compatible. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define if you have timegm() */
|
||||
#undef HAVE_TIMEGM
|
||||
|
||||
/* Define if you external variables timezone. */
|
||||
#undef HAVE_TIMEZONE
|
||||
|
||||
/* Define if your struct tm has tm_zone. */
|
||||
#undef HAVE_TM_ZONE
|
||||
|
||||
/* Define if you don't have tm_zone but do have the external array
|
||||
tzname. */
|
||||
#undef HAVE_TZNAME
|
||||
|
||||
/* Define if you have <unistd.h>. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if utime(file, NULL) sets file's timestamp to the present. */
|
||||
#undef HAVE_UTIME_NULL
|
||||
|
||||
/* Define if you have <vfork.h>. */
|
||||
#undef HAVE_VFORK_H
|
||||
|
||||
/* Define if you have the vprintf function. */
|
||||
#undef HAVE_VPRINTF
|
||||
|
||||
/* Define if you have the wait3 system call. */
|
||||
#undef HAVE_WAIT3
|
||||
|
||||
/* Define if you have gdbm installed system wide. */
|
||||
/* #undef HAVE_GDBM */
|
||||
|
||||
/* Define if you have zlib installed system wide. */
|
||||
#undef HAVE_ZLIB
|
||||
|
||||
/* Define as __inline if that's what the C compiler calls it. */
|
||||
#undef inline
|
||||
|
||||
/* Define if int is 16 bits instead of 32. */
|
||||
#undef INT_16_BITS
|
||||
|
||||
/* Define if long int is 64 bits. */
|
||||
#undef LONG_64_BITS
|
||||
|
||||
/* Define if major, minor, and makedev are declared in <mkdev.h>. */
|
||||
#undef MAJOR_IN_MKDEV
|
||||
|
||||
/* Define if major, minor, and makedev are declared in <sysmacros.h>. */
|
||||
#undef MAJOR_IN_SYSMACROS
|
||||
|
||||
/* Define if on MINIX. */
|
||||
#undef _MINIX
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef mode_t
|
||||
|
||||
/* Define if you don't have <dirent.h>, but have <ndir.h>. */
|
||||
#undef NDIR
|
||||
|
||||
/* Define if you have <memory.h>, and <string.h> doesn't declare the
|
||||
mem* functions. */
|
||||
#undef NEED_MEMORY_H
|
||||
|
||||
/* Define if your struct nlist has an n_un member. */
|
||||
#undef NLIST_NAME_UNION
|
||||
|
||||
/* Define if you have <nlist.h>. */
|
||||
#undef NLIST_STRUCT
|
||||
|
||||
/* Define if your C compiler doesn't accept -c and -o together. */
|
||||
#undef NO_MINUS_C_MINUS_O
|
||||
|
||||
/* Define to `long' if <sys/types.h> doesn't define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to package name */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define if the system does not provide POSIX.1 features except
|
||||
with this defined. */
|
||||
#undef _POSIX_1_SOURCE
|
||||
|
||||
/* Define if you need to in order for stat and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define if the `setpgrp' function takes no argument. */
|
||||
#undef SETPGRP_VOID
|
||||
|
||||
/* Define if the setvbuf function takes the buffering type as its second
|
||||
argument and the buffer pointer as the third, as on System V
|
||||
before release 3. */
|
||||
#undef SETVBUF_REVERSED
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
#undef size_t
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at run-time.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown
|
||||
*/
|
||||
#undef STACK_DIRECTION
|
||||
|
||||
/* Define if the `S_IS*' macros in <sys/stat.h> do not work properly. */
|
||||
#undef STAT_MACROS_BROKEN
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define on System V Release 4. */
|
||||
#undef SVR4
|
||||
|
||||
/* Define if you don't have <dirent.h>, but have <sys/dir.h>. */
|
||||
#undef SYSDIR
|
||||
|
||||
/* Define if you don't have <dirent.h>, but have <sys/ndir.h>. */
|
||||
#undef SYSNDIR
|
||||
|
||||
/* Define if `sys_siglist' is declared by <signal.h>. */
|
||||
#undef SYS_SIGLIST_DECLARED
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define if your <sys/time.h> declares struct tm. */
|
||||
#undef TM_IN_SYS_TIME
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Define for Encore UMAX. */
|
||||
#undef UMAX
|
||||
|
||||
/* Define for Encore UMAX 4.3 that has <inq_status/cpustats.h>
|
||||
instead of <sys/cpustats.h>. */
|
||||
#undef UMAX4_3
|
||||
|
||||
/* Define if you do not have <strings.h>, index, bzero, etc.. */
|
||||
#undef USG
|
||||
|
||||
/* Define to version number */
|
||||
#undef VERSION
|
||||
|
||||
/* Define vfork as fork if vfork does not work. */
|
||||
#undef vfork
|
||||
|
||||
/* Define if the closedir function returns void instead of int. */
|
||||
#undef VOID_CLOSEDIR
|
||||
|
||||
/* Define if compiling on a Winbloze (95, NT, etc.) platform */
|
||||
#undef WIN32
|
||||
|
||||
/* Define if your processor stores words with the most significant
|
||||
byte first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
/* Define if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
/* Define if lex declares yytext as a char * by default, not a char[]. */
|
||||
#undef YYTEXT_POINTER
|
||||
|
||||
|
||||
/* Leave that blank line there!! Autoheader needs it.
|
||||
If you're adding to this file, keep in mind:
|
||||
The entries are in sort -df order: alphabetical, case insensitive,
|
||||
ignoring punctuation (such as underscores). */
|
||||
|
||||
140
aclocal.m4
vendored
Normal file
140
aclocal.m4
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
dnl aclocal.m4 generated automatically by aclocal 1.4
|
||||
|
||||
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl This program is distributed in the hope that it will be useful,
|
||||
dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
dnl PARTICULAR PURPOSE.
|
||||
|
||||
# Do all the work for Automake. This macro actually does too much --
|
||||
# some checks are only needed if your package does certain things.
|
||||
# But this isn't really a big deal.
|
||||
|
||||
# serial 1
|
||||
|
||||
dnl Usage:
|
||||
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
|
||||
|
||||
AC_DEFUN(AM_INIT_AUTOMAKE,
|
||||
[AC_REQUIRE([AC_PROG_INSTALL])
|
||||
PACKAGE=[$1]
|
||||
AC_SUBST(PACKAGE)
|
||||
VERSION=[$2]
|
||||
AC_SUBST(VERSION)
|
||||
dnl test to see if srcdir already configured
|
||||
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
|
||||
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
|
||||
fi
|
||||
ifelse([$3],,
|
||||
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
|
||||
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
|
||||
AC_REQUIRE([AM_SANITY_CHECK])
|
||||
AC_REQUIRE([AC_ARG_PROGRAM])
|
||||
dnl FIXME This is truly gross.
|
||||
missing_dir=`cd $ac_aux_dir && pwd`
|
||||
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
|
||||
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
|
||||
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
|
||||
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
|
||||
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
|
||||
AC_REQUIRE([AC_PROG_MAKE_SET])])
|
||||
|
||||
#
|
||||
# Check to make sure that the build environment is sane.
|
||||
#
|
||||
|
||||
AC_DEFUN(AM_SANITY_CHECK,
|
||||
[AC_MSG_CHECKING([whether build environment is sane])
|
||||
# Just in case
|
||||
sleep 1
|
||||
echo timestamp > conftestfile
|
||||
# Do `set' in a subshell so we don't clobber the current shell's
|
||||
# arguments. Must try -L first in case configure is actually a
|
||||
# symlink; some systems play weird games with the mod time of symlinks
|
||||
# (eg FreeBSD returns the mod time of the symlink's containing
|
||||
# directory).
|
||||
if (
|
||||
set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
|
||||
if test "[$]*" = "X"; then
|
||||
# -L didn't work.
|
||||
set X `ls -t $srcdir/configure conftestfile`
|
||||
fi
|
||||
if test "[$]*" != "X $srcdir/configure conftestfile" \
|
||||
&& test "[$]*" != "X conftestfile $srcdir/configure"; then
|
||||
|
||||
# If neither matched, then we have a broken ls. This can happen
|
||||
# if, for instance, CONFIG_SHELL is bash and it inherits a
|
||||
# broken ls alias from the environment. This has actually
|
||||
# happened. Such a system could not be considered "sane".
|
||||
AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
|
||||
alias in your environment])
|
||||
fi
|
||||
|
||||
test "[$]2" = conftestfile
|
||||
)
|
||||
then
|
||||
# Ok.
|
||||
:
|
||||
else
|
||||
AC_MSG_ERROR([newly created file is older than distributed files!
|
||||
Check your system clock])
|
||||
fi
|
||||
rm -f conftest*
|
||||
AC_MSG_RESULT(yes)])
|
||||
|
||||
dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
|
||||
dnl The program must properly implement --version.
|
||||
AC_DEFUN(AM_MISSING_PROG,
|
||||
[AC_MSG_CHECKING(for working $2)
|
||||
# Run test in a subshell; some versions of sh will print an error if
|
||||
# an executable is not found, even if stderr is redirected.
|
||||
# Redirect stdin to placate older versions of autoconf. Sigh.
|
||||
if ($2 --version) < /dev/null > /dev/null 2>&1; then
|
||||
$1=$2
|
||||
AC_MSG_RESULT(found)
|
||||
else
|
||||
$1="$3/missing $2"
|
||||
AC_MSG_RESULT(missing)
|
||||
fi
|
||||
AC_SUBST($1)])
|
||||
|
||||
# Define a conditional.
|
||||
|
||||
AC_DEFUN(AM_CONDITIONAL,
|
||||
[AC_SUBST($1_TRUE)
|
||||
AC_SUBST($1_FALSE)
|
||||
if $2; then
|
||||
$1_TRUE=
|
||||
$1_FALSE='#'
|
||||
else
|
||||
$1_TRUE='#'
|
||||
$1_FALSE=
|
||||
fi])
|
||||
|
||||
# Like AC_CONFIG_HEADER, but automatically create stamp file.
|
||||
|
||||
AC_DEFUN(AM_CONFIG_HEADER,
|
||||
[AC_PREREQ([2.12])
|
||||
AC_CONFIG_HEADER([$1])
|
||||
dnl When config.status generates a header, we must update the stamp-h file.
|
||||
dnl This file resides in the same directory as the config header
|
||||
dnl that is generated. We must strip everything past the first ":",
|
||||
dnl and everything past the last "/".
|
||||
AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
|
||||
ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
|
||||
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
|
||||
<<am_indx=1
|
||||
for am_file in <<$1>>; do
|
||||
case " <<$>>CONFIG_HEADERS " in
|
||||
*" <<$>>am_file "*<<)>>
|
||||
echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
|
||||
;;
|
||||
esac
|
||||
am_indx=`expr "<<$>>am_indx" + 1`
|
||||
done<<>>dnl>>)
|
||||
changequote([,]))])
|
||||
|
||||
415
acsite.m4
Normal file
415
acsite.m4
Normal file
@@ -0,0 +1,415 @@
|
||||
dnl
|
||||
dnl originally from ncftp 2.3.0
|
||||
dnl added wi_EXTRA_PDIR and wi_ANSI_C
|
||||
dnl $Id$
|
||||
dnl
|
||||
AC_DEFUN(wi_EXTRA_IDIR, [
|
||||
incdir="$1"
|
||||
if test -r $incdir ; then
|
||||
case "$CPPFLAGS" in
|
||||
*-I${incdir}*)
|
||||
# echo " + already had $incdir" 1>&6
|
||||
;;
|
||||
*)
|
||||
if test "$CPPFLAGS" = "" ; then
|
||||
CPPFLAGS="-I$incdir"
|
||||
else
|
||||
CPPFLAGS="$CPPFLAGS -I$incdir"
|
||||
fi
|
||||
echo " + found $incdir" 1>&6
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_EXTRA_LDIR, [
|
||||
mylibdir="$1"
|
||||
if test -r $mylibdir ; then
|
||||
case "$LDFLAGS" in
|
||||
*-L${mylibdir}*)
|
||||
# echo " + already had $mylibdir" 1>&6
|
||||
;;
|
||||
*)
|
||||
if test "$LDFLAGS" = "" ; then
|
||||
LDFLAGS="-L$mylibdir"
|
||||
else
|
||||
LDFLAGS="$LDFLAGS -L$mylibdir"
|
||||
fi
|
||||
echo " + found $mylibdir" 1>&6
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl __FP__
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_EXTRA_PDIR, [
|
||||
progdir="$1"
|
||||
if test -r $progdir ; then
|
||||
case "$PATH" in
|
||||
*:${progdir}*)
|
||||
# echo " + already had $progdir" 1>&6
|
||||
;;
|
||||
*${progdir}:*)
|
||||
# echo " + already had $progdir" 1>&6
|
||||
;;
|
||||
*)
|
||||
if test "$PATH" = "" ; then
|
||||
PATH="$progdir"
|
||||
else
|
||||
PATH="$PATH:$progdir"
|
||||
fi
|
||||
echo " + found $progdir" 1>&6
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl If you want to also look for include and lib subdirectories in the
|
||||
dnl $HOME tree, you supply "yes" as the first argument to this macro.
|
||||
dnl
|
||||
dnl If you want to look for subdirectories in include/lib directories,
|
||||
dnl you pass the names in argument 3, otherwise pass a dash.
|
||||
dnl
|
||||
AC_DEFUN(wi_EXTRA_DIRS, [echo "checking for extra include and lib directories..." 1>&6
|
||||
ifelse([$1], yes, [dnl
|
||||
b1=`cd .. ; pwd`
|
||||
b2=`cd ../.. ; pwd`
|
||||
exdirs="$HOME $j $b1 $b2 $prefix $2"
|
||||
],[dnl
|
||||
exdirs="$prefix $2"
|
||||
])
|
||||
subexdirs="$3"
|
||||
if test "$subexdirs" = "" ; then
|
||||
subexdirs="-"
|
||||
fi
|
||||
for subexdir in $subexdirs ; do
|
||||
if test "$subexdir" = "-" ; then
|
||||
subexdir=""
|
||||
else
|
||||
subexdir="/$subexdir"
|
||||
fi
|
||||
for exdir in $exdirs ; do
|
||||
if test "$exdir" != "/usr" || test "$subexdir" != ""; then
|
||||
incdir="${exdir}/include${subexdir}"
|
||||
wi_EXTRA_IDIR($incdir)
|
||||
|
||||
mylibdir="${exdir}/lib${subexdir}"
|
||||
wi_EXTRA_LDIR($mylibdir)
|
||||
|
||||
progdir="${exdir}/bin${subexdirr}"
|
||||
wi_EXTRA_PDIR($progdir)
|
||||
fi
|
||||
done
|
||||
done
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_HPUX_CFLAGS,
|
||||
[AC_MSG_CHECKING(if HP-UX ansi C compiler flags are needed)
|
||||
AC_REQUIRE([AC_PROG_CC])
|
||||
os=`uname -s | tr '[A-Z]' '[a-z]'`
|
||||
ac_cv_hpux_flags=no
|
||||
if test "$os" = hp-ux ; then
|
||||
if test "$ac_cv_prog_gcc" = yes ; then
|
||||
if test "$CFLAGS" != "" ; then
|
||||
# Shouldn't be in there.
|
||||
CFLAGS=`echo "$CFLAGS" | sed 's/-Aa//g'`
|
||||
fi
|
||||
else
|
||||
# If you're not using gcc, then you better have a cc/c89
|
||||
# that is usable. If you have the barebones compiler, it
|
||||
# won't work. The good compiler uses -Aa for the ANSI
|
||||
# compatible stuff.
|
||||
x=`echo $CFLAGS | grep 'Aa' 2>/dev/null`
|
||||
if test "$x" = "" ; then
|
||||
CFLAGS="$CFLAGS -Aa"
|
||||
fi
|
||||
ac_cv_hpux_flags=yes
|
||||
fi
|
||||
# Also add _HPUX_SOURCE to get the extended namespace.
|
||||
x=`echo $CFLAGS | grep '_HPUX_SOURCE' 2>/dev/null`
|
||||
if test "$x" = "" ; then
|
||||
CFLAGS="$CFLAGS -D_HPUX_SOURCE"
|
||||
fi
|
||||
fi
|
||||
AC_MSG_RESULT($ac_cv_hpux_flags)
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_CFLAGS, [AC_REQUIRE([AC_PROG_CC])
|
||||
wi_HPUX_CFLAGS
|
||||
if test "$CFLAGS" = "" ; then
|
||||
CFLAGS="-O"
|
||||
elif test "$ac_cv_prog_gcc" = "yes" ; then
|
||||
case "$CFLAGS" in
|
||||
*"-g -O"*)
|
||||
#echo "using -g as default gcc CFLAGS" 1>&6
|
||||
CFLAGS=`echo $CFLAGS | sed 's/-g\ -O/-O/'`
|
||||
;;
|
||||
*"-O -g"*)
|
||||
# Leave the -g, but remove all -O options.
|
||||
#echo "using -g as default gcc CFLAGS" 1>&6
|
||||
CFLAGS=`echo $CFLAGS | sed 's/-O\ -g/-O/'`
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_PROTOTYPES, [
|
||||
AC_MSG_CHECKING(if the compiler supports function prototypes)
|
||||
AC_TRY_COMPILE(,[extern void exit(int status);],[wi_cv_prototypes=yes
|
||||
AC_DEFINE(PROTOTYPES)],wi_cv_prototypes=no)
|
||||
AC_MSG_RESULT($wi_cv_prototypes)
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_ANSI_C, [
|
||||
AC_MSG_CHECKING(ANSI-style function definitions)
|
||||
AC_TRY_COMPILE(,[int blubb(int x) { return 0; }],[wi_cv_ansi_funcs=yes
|
||||
AC_DEFINE(ANSI_FUNCS)],wi_cv_ansi_funcs=no)
|
||||
AC_MSG_RESULT($wi_cv_ansi_funcs)
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_HEADER_SYS_SELECT_H, [
|
||||
# See if <sys/select.h> is includable after <sys/time.h>
|
||||
if test "$ac_cv_header_sys_time_h" = no ; then
|
||||
AC_CHECK_HEADERS(sys/time.h sys/select.h)
|
||||
else
|
||||
AC_CHECK_HEADERS(sys/select.h)
|
||||
fi
|
||||
if test "$ac_cv_header_sys_select_h" = yes ; then
|
||||
AC_MSG_CHECKING([if <sys/select.h> is compatible with <sys/time.h>])
|
||||
selecth=yes
|
||||
if test "$ac_cv_header_sys_time_h" = yes ; then
|
||||
AC_TRY_COMPILE([#include <sys/time.h>
|
||||
#include <sys/select.h>],[
|
||||
fd_set a;
|
||||
struct timeval tmval;
|
||||
|
||||
tmval.tv_sec = 0;],selecth=yes,selecth=no)
|
||||
|
||||
if test "$selecth" = yes ; then
|
||||
AC_DEFINE(CAN_USE_SYS_SELECT_H)
|
||||
fi
|
||||
fi
|
||||
AC_MSG_RESULT($selecth)
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_LIB_RESOLV, [
|
||||
# See if we could access two well-known sites without help of any special
|
||||
# libraries, like resolv.
|
||||
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
main()
|
||||
{
|
||||
struct hostent *hp1, *hp2;
|
||||
int result;
|
||||
|
||||
hp1 = gethostbyname("gatekeeper.dec.com");
|
||||
hp2 = gethostbyname("ftp.ncsa.uiuc.edu");
|
||||
result = ((hp1 != (struct hostent *) 0) && (hp2 != (struct hostent *) 0));
|
||||
exit(! result);
|
||||
}],look_for_resolv=no,look_for_resolv=yes,look_for_resolv=yes)
|
||||
|
||||
AC_MSG_CHECKING([if we need to look for -lresolv])
|
||||
AC_MSG_RESULT($look_for_resolv)
|
||||
if test "$look_for_resolv" = yes ; then
|
||||
AC_CHECK_LIB(resolv,main)
|
||||
else
|
||||
ac_cv_lib_resolv=no
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
|
||||
AC_DEFUN(wi_LIB_NSL, [
|
||||
AC_MSG_CHECKING(if we can use -lnsl)
|
||||
ac_save_LIBS="$LIBS";
|
||||
LIBS="$LIBS -lnsl";
|
||||
AC_CACHE_VAL(r_cv_use_libnsl, [
|
||||
AC_TRY_RUN(
|
||||
main() { if (getpwuid(getuid())) exit(0); exit(-1); },
|
||||
nc_cv_use_libnsl=yes, nc_cv_use_libnsl=no, nc_cv_use_libnsl=no)
|
||||
])
|
||||
if test "$nc_cv_use_libnsl" = "no"; then LIBS="$ac_save_LIBS"; fi
|
||||
AC_MSG_RESULT($nc_cv_use_libnsl)
|
||||
])dnl
|
||||
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
|
||||
AC_DEFUN(nc_PATH_PROG_ZCAT, [
|
||||
AC_PATH_PROG(GZCAT,gzcat)
|
||||
AC_PATH_PROG(ZCAT,zcat)
|
||||
if test "x$GZCAT" = x ; then
|
||||
if test "x$ZCAT" != x ; then
|
||||
# See if zcat is really gzcat. gzcat has a --version option, regular
|
||||
# zcat does not.
|
||||
AC_MSG_CHECKING(if zcat is really gzcat in disguise)
|
||||
if $ZCAT --version 2> /dev/null ; then
|
||||
AC_DEFINE_UNQUOTED(GZCAT, "$ZCAT")
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
else
|
||||
AC_DEFINE_UNQUOTED(GZCAT, "$GZCAT")
|
||||
fi
|
||||
|
||||
if test "x$ZCAT" != x ; then
|
||||
AC_DEFINE_UNQUOTED(ZCAT, "$ZCAT")
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_SYSV_EXTRA_DIRS, [
|
||||
# Use System V because their curses extensions are required. This must
|
||||
# be done early so we use the -I and -L in the library checks also.
|
||||
# This is mostly a Solaris/SunOS hack. Note that doing this will also
|
||||
# use all of the other System V libraries and headers.
|
||||
|
||||
AC_MSG_CHECKING(for alternative System V libraries)
|
||||
if test -f /usr/5include/curses.h ; then
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/5include"
|
||||
LDFLAGS="$LDFLAGS -L/usr/5lib"
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_DEFINE_UNAME, [
|
||||
# Get first 127 chars of all uname information. Some folks have
|
||||
# way too much stuff there, so grab only the first 127.
|
||||
unam=`uname -a 2>/dev/null | cut -c1-127`
|
||||
if test "$unam" != "" ; then
|
||||
AC_DEFINE_UNQUOTED(UNAME, "$unam")
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
AC_DEFUN(wi_READLINE_WITH_NCURSES, [
|
||||
# Readline and Ncurses could both define "backspace".
|
||||
# Warn about this if we have both things in our definitions list.
|
||||
|
||||
if test "$ac_cv_lib_readline" = yes && test "$ac_cv_lib_ncurses" = yes ; then
|
||||
|
||||
AC_MSG_CHECKING(if readline and ncurses will link together)
|
||||
j="$LIBS"
|
||||
LIBS="-lreadline -lncurses"
|
||||
AC_TRY_LINK(,[
|
||||
readline("prompt");
|
||||
endwin();
|
||||
],k=yes,k=no)
|
||||
if test "$k" = no ; then
|
||||
AC_MSG_RESULT(no)
|
||||
# Remove '-lreadline' from LIBS.
|
||||
LIBS=`echo $j | sed s/-lreadline//g`
|
||||
ac_cv_lib_readline=no
|
||||
AC_WARN([The versions of GNU readline and ncurses you have installed on this system
|
||||
can't be used together, because they use the same symbol, backspace. If
|
||||
possible, recompile one of the libraries with -Dbackspace=back_space, then
|
||||
re-run configure.])
|
||||
|
||||
else
|
||||
AC_MSG_RESULT(yes)
|
||||
LIBS="$j"
|
||||
fi
|
||||
|
||||
fi
|
||||
])
|
||||
dnl
|
||||
dnl
|
||||
dnl
|
||||
|
||||
dnl AC_EXT_DAYLIGHT
|
||||
dnl Check for an external variable daylight. Stolen from w3c-libwww.
|
||||
AC_DEFUN(AC_EXT_DAYLIGHT,
|
||||
[ AC_MSG_CHECKING(int daylight variable)
|
||||
AC_TRY_COMPILE([#include <time.h>], [return daylight;],
|
||||
have_daylight=yes,
|
||||
have_daylight=no)
|
||||
AC_MSG_RESULT($have_daylight)
|
||||
])dnl
|
||||
|
||||
dnl AC_EXT_TIMEZONE
|
||||
dnl Check for an external variable timezone. Stolen from tcl-8.0.
|
||||
AC_DEFUN(AC_EXT_TIMEZONE,
|
||||
[
|
||||
#
|
||||
# Its important to include time.h in this check, as some systems (like convex)
|
||||
# have timezone functions, etc.
|
||||
#
|
||||
have_timezone=no
|
||||
AC_MSG_CHECKING([long timezone variable])
|
||||
AC_TRY_COMPILE([#include <time.h>],
|
||||
[extern long timezone;
|
||||
timezone += 1;
|
||||
exit (0);],
|
||||
[have_timezone=yes
|
||||
AC_MSG_RESULT(yes)],
|
||||
AC_MSG_RESULT(no))
|
||||
|
||||
#
|
||||
# On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
|
||||
#
|
||||
if test "$have_timezone" = no; then
|
||||
AC_MSG_CHECKING([time_t timezone variable])
|
||||
AC_TRY_COMPILE([#include <time.h>],
|
||||
[extern time_t timezone;
|
||||
timezone += 1;
|
||||
exit (0);],
|
||||
[have_timezone=yes
|
||||
AC_MSG_RESULT(yes)],
|
||||
AC_MSG_RESULT(no))
|
||||
fi
|
||||
])dnl
|
||||
|
||||
## AC_BZ_SET_COMPILER: Addition by Theodore Papadopoulo
|
||||
## Patch by Jim McKelvey: change sed -e 's/ /@/g' to sed -e 's/ /@/'
|
||||
AC_DEFUN(AC_SG_SET_COMPILER,
|
||||
[cxxwith=`echo $1 | sed -e 's/ /@/'`
|
||||
case "$cxxwith" in
|
||||
*:*@*) # Full initialization syntax
|
||||
CXX=`echo "$cxxwith" | sed -n -e 's/.*:\(.*\)@.*/\1/p'`
|
||||
CXXFLAGS=`echo "$cxxwith" | sed -n -e 's/.*:.*@\(.*\)/\1/p'`
|
||||
;;
|
||||
*:*) # Simple initialization syntax
|
||||
CXX=`echo "$cxxwith" | sed -n -e 's/.*:\(.*\)/\1/p'`
|
||||
CXXFLAGS=$3
|
||||
;;
|
||||
*) # Default values
|
||||
CXX=$2
|
||||
CXXFLAGS=$3
|
||||
CC="$2 --c"
|
||||
## CFLAGS=
|
||||
;;
|
||||
esac])
|
||||
322
configure.in
Normal file
322
configure.in
Normal file
@@ -0,0 +1,322 @@
|
||||
dnl Process this file with aclocal ; automake -a ; autoconf to produce a
|
||||
dnl working configure script.
|
||||
dnl
|
||||
dnl $Id$
|
||||
|
||||
AC_INIT(simgear/bucket/newbucket.cxx)
|
||||
|
||||
dnl Initialize the automake stuff
|
||||
AM_INIT_AUTOMAKE(SimGear, 0.0.14)
|
||||
|
||||
dnl Specify KAI C++ compiler and flags.
|
||||
dnl Borrowed with slight modification from blitz distribution.
|
||||
AC_ARG_WITH(cxx,
|
||||
[ --with-cxx=COMPILER[:name-flags] set options for COMPILER (KCC)],
|
||||
[case "$withval" in
|
||||
KCC*) # KAI C++ http://www.kai.com/
|
||||
echo "Configuring for KAI C++"
|
||||
AC_SG_SET_COMPILER($withval,"KCC","--restrict --strict_warnings")
|
||||
CXX_OPTIMIZE_FLAGS=="+K3 -O3"
|
||||
CXX_DEBUG_FLAGS="-g +K0"
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
echo CXX = $CXX
|
||||
echo CC = $CC
|
||||
|
||||
dnl Checks for programs.
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AC_PROG_RANLIB
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
|
||||
if echo $includedir | egrep "simgear$" > /dev/null; then
|
||||
echo "includedir is" $includedir "libdir is" $libdir
|
||||
else
|
||||
includedir="${includedir}/simgear"
|
||||
echo "includedir changed to" $includedir "libdir is" $libdir
|
||||
fi
|
||||
|
||||
|
||||
# set logging default value
|
||||
# with_logging=yes
|
||||
AC_ARG_WITH(logging, [ --with-logging Include logging output (default)])
|
||||
if test "x$with_logging" = "xno" ; then
|
||||
AC_DEFINE(FG_NDEBUG)
|
||||
fi
|
||||
|
||||
dnl specify if we are building with "checker"
|
||||
AC_ARG_WITH(efence, [ --with-efence Specify if we are building with "electric-fence"])
|
||||
|
||||
if test "x$with_efence" = "xyes" ; then
|
||||
echo "Building with efence"
|
||||
LIBS= "$LIBS -lefence"
|
||||
fi
|
||||
|
||||
dnl Check for MS Windows environment
|
||||
AC_CHECK_HEADER(windows.h)
|
||||
|
||||
dnl extra library and include directories
|
||||
EXTRA_DIRS="/usr/local /usr/local/plib /usr/X11R6"
|
||||
|
||||
if test -d /opt/X11R6 ; then
|
||||
EXTRA_DIRS="$EXTRA_DIRS /opt/X11R6"
|
||||
fi
|
||||
|
||||
if test "x$ac_cv_header_windows_h" = "xyes" ; then
|
||||
EXTRA_DIRS="${EXTRA_DIRS} `pwd`/Win32"
|
||||
# elif test `uname -s` = "SunOS" ; then
|
||||
# EXTRA_DIRS="${EXTRA_DIRS} `pwd`/SunOS"
|
||||
fi
|
||||
wi_EXTRA_DIRS(no, ${EXTRA_DIRS})
|
||||
|
||||
dnl Using AM_CONDITIONAL is a step out of the protected little
|
||||
dnl automake fold so it is potentially dangerous. But, we are
|
||||
dnl beginning to run into cases where the standard checks are not
|
||||
dnl enough. AM_CONDITIONALS are then referenced to conditionally
|
||||
dnl build a Makefile.in from a Makefile.am which lets us define custom
|
||||
dnl includes, compile alternative source files, etc.
|
||||
|
||||
dnl Enable serial support on Unix type systems
|
||||
AM_CONDITIONAL(ENABLE_UNIX_SERIAL, true)
|
||||
|
||||
dnl Check for X11 (fancy)
|
||||
AC_PATH_XTRA
|
||||
|
||||
dnl Checks for libraries.
|
||||
|
||||
null_LIBS="$LIBS"
|
||||
|
||||
AC_CHECK_LIB(m, cos)
|
||||
|
||||
base_LIBS="$LIBS"
|
||||
|
||||
AC_CHECK_LIB(socket, socket)
|
||||
AC_CHECK_LIB(X11, XCreateWindow)
|
||||
AC_CHECK_LIB(Xext, XShmCreateImage)
|
||||
AC_CHECK_LIB(Xi, XGetExtensionVersion)
|
||||
AC_CHECK_LIB(ICE, IceOpenConnection)
|
||||
AC_CHECK_LIB(SM, SmcOpenConnection)
|
||||
AC_CHECK_LIB(Xt, XtMalloc)
|
||||
AC_CHECK_LIB(Xmu, XmuLookupStandardColormap)
|
||||
|
||||
dnl check for OpenGL related libraries
|
||||
|
||||
if test "x$ac_cv_header_windows_h" != "xyes" ; then
|
||||
dnl Reasonable stuff for non-windoze variants ... :-)
|
||||
|
||||
AC_CHECK_LIB(GLcore, glNewList)
|
||||
if test "x$ac_cv_lib_GLcore_glNewList" = "xno" ; then
|
||||
dnl if no GLcore, check for GL
|
||||
AC_CHECK_LIB(GL, glNewList)
|
||||
if test "x$ac_cv_lib_GL_glNewList" = "xno" ; then
|
||||
dnl if no GL, check for MesaGL
|
||||
AC_CHECK_LIB(MesaGL, glNewList)
|
||||
fi
|
||||
else
|
||||
dnl if GLcore found, then also check for GL
|
||||
AC_CHECK_LIB(GL, glXCreateContext)
|
||||
fi
|
||||
|
||||
dnl if using mesa, check for xmesa.h
|
||||
if test "x$ac_cv_lib_MesaGL_glNewList" = "xyes" ; then
|
||||
AC_CHECK_HEADER(GL/xmesa.h)
|
||||
if test "x$ac_cv_header_GL_xmesa_h" = "xyes"; then
|
||||
AC_DEFINE( XMESA )
|
||||
AC_DEFINE( FX )
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB(GLU, gluLookAt)
|
||||
if test "x$ac_cv_lib_GLU_gluLookAt" = "xno" ; then
|
||||
dnl if no GLU, check for MesaGLU
|
||||
AC_CHECK_LIB(MesaGLU, gluLookAt)
|
||||
fi
|
||||
|
||||
dnl check for glut
|
||||
AC_CHECK_LIB(glut, glutGetModifiers)
|
||||
|
||||
dnl test for glutGameModeString, but avoid adding glut a second time into
|
||||
dnl the list of libraries
|
||||
save_LIBS="$LIBS"
|
||||
AC_CHECK_LIB(glut, glutGameModeString)
|
||||
LIBS="$save_LIBS"
|
||||
else
|
||||
dnl Win32 is a little wierd because it has to try to handle the various
|
||||
dnl winbloze-isms. We'll just do this manually for now.
|
||||
|
||||
echo Win32 specific hacks...
|
||||
AC_DEFINE(WIN32)
|
||||
|
||||
dnl force a failed check since we will be building under windoze
|
||||
AM_CONDITIONAL(ENABLE_XMESA_FX, test "no" = "yes")
|
||||
|
||||
dnl just define these to true and hope for the best
|
||||
ac_cv_lib_glut_glutGetModifiers="yes"
|
||||
ac_cv_lib_glut_glutGameModeString="yes"
|
||||
|
||||
if test "x$with_sgi_opengl" = "xyes" ; then
|
||||
echo "Building with glut.dll, glu.dll, and opengl.dll"
|
||||
WIN32_GLUT=glut
|
||||
WIN32_GLU=glu
|
||||
WIN32_OPENGL=opengl
|
||||
else
|
||||
echo "Building with glut32.dll, glu32.dll, and opengl32.dll"
|
||||
WIN32_GLUT=glut32
|
||||
WIN32_GLU=glu32
|
||||
WIN32_OPENGL=opengl32
|
||||
fi
|
||||
|
||||
LIBS="$LIBS -l${WIN32_GLUT} -l${WIN32_GLU} -l${WIN32_OPENGL}"
|
||||
LIBS="$LIBS -luser32 -lgdi32"
|
||||
echo "Will link apps with $LIBS"
|
||||
fi
|
||||
|
||||
if test "x$ac_cv_lib_glut_glutGetModifiers" = "xno"; then
|
||||
echo
|
||||
echo "Unable to find the necessary OpenGL or GLUT libraries."
|
||||
echo "See config.log for automated test details and results ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test "x$ac_cv_lib_glut_glutGameModeString" = "xno"; then
|
||||
echo
|
||||
echo "Your version of glut doesn't support game mode."
|
||||
echo "You need to fetch and install the latest version of glut from:"
|
||||
echo
|
||||
echo " http://reality.sgi.com/opengl/glut3/glut3.html"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
opengl_LIBS="$LIBS"
|
||||
LIBS="$base_LIBS"
|
||||
|
||||
AC_SUBST(base_LIBS)
|
||||
AC_SUBST(opengl_LIBS)
|
||||
|
||||
AM_CONDITIONAL(HAVE_XWINDOWS, test "x$ac_cv_lib_X11_XCreateWindow" = "xyes" )
|
||||
|
||||
dnl Check for "plib" without which we cannot go on
|
||||
AC_CHECK_HEADER(plib/pu.h)
|
||||
if test "x$ac_cv_header_plib_pu_h" != "xyes"; then
|
||||
echo
|
||||
echo "You *must* have the plib library installed on your system to build"
|
||||
echo "the FGFS simulator!"
|
||||
echo
|
||||
echo "Please see README.plib for more details."
|
||||
echo
|
||||
echo "configure aborted."
|
||||
exit
|
||||
fi
|
||||
|
||||
# dnl Check for system installed gdbm
|
||||
# AC_CHECK_HEADER(gdbm.h)
|
||||
# if test "x$ac_cv_header_gdbm_h" = "xyes"; then
|
||||
# AC_DEFINE( HAVE_GDBM )
|
||||
# else
|
||||
# echo "no gdbm found, configuring and building."
|
||||
# fi
|
||||
# AM_CONDITIONAL(HAVE_GDBM, test "x$ac_cv_header_gdbm_h" = "xyes" )
|
||||
|
||||
dnl Check for system installed metakit
|
||||
AC_CHECK_HEADER(mk4.h)
|
||||
if test "x$ac_cv_header_mk4_h" != "xyes"; then
|
||||
echo "no metakit found, configuring and building."
|
||||
# Run configure in the metakit subdir
|
||||
AC_CONFIG_SUBDIRS( simgear/metakit/unix )
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_METAKIT, test "x$ac_cv_header_mk4_h" = "xyes" )
|
||||
|
||||
|
||||
dnl Specify if we want logging (testing build) or not (release build)
|
||||
|
||||
dnl Check for system installed zlib
|
||||
AC_CHECK_HEADER(zlib.h)
|
||||
if test "x$ac_cv_header_zlib_h" = "xyes"; then
|
||||
AC_DEFINE( HAVE_ZLIB )
|
||||
else
|
||||
echo "no zlib found, building."
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_ZLIB, test "x$ac_cv_header_zlib_h" = "xyes" )
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS( \
|
||||
fcntl.h getopt.h malloc.h memory.h stdlib.h sys/param.h sys/stat.h \
|
||||
sys/time.h sys/timeb.h unistd.h windows.h winbase.h values.h )
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_TYPE_SIZE_T
|
||||
AC_HEADER_TIME
|
||||
AC_STRUCT_TM
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_TYPE_SIGNAL
|
||||
AC_FUNC_VPRINTF
|
||||
AC_CHECK_FUNCS( ftime gettimeofday timegm memcpy bcopy mktime strstr rand \
|
||||
random setitimer getitimer signal GetLocalTime rint getrusage )
|
||||
|
||||
AM_CONFIG_HEADER(simgear/config.h)
|
||||
|
||||
AC_OUTPUT( \
|
||||
Makefile \
|
||||
SimGear.spec \
|
||||
simgear/Makefile \
|
||||
simgear/version.h \
|
||||
simgear/bucket/Makefile \
|
||||
simgear/camera/Makefile \
|
||||
simgear/debug/Makefile \
|
||||
simgear/ephemeris/Makefile \
|
||||
simgear/io/Makefile \
|
||||
simgear/magvar/Makefile \
|
||||
simgear/math/Makefile \
|
||||
simgear/misc/Makefile \
|
||||
simgear/route/Makefile \
|
||||
simgear/screen/Makefile \
|
||||
simgear/serial/Makefile \
|
||||
simgear/sky/Makefile \
|
||||
simgear/timing/Makefile \
|
||||
simgear/xgl/Makefile \
|
||||
simgear/xml/Makefile \
|
||||
simgear/zlib/Makefile \
|
||||
)
|
||||
|
||||
AC_OUTPUT_COMMANDS([
|
||||
# if test "x$ac_cv_header_windows_h" = "xyes" ; then
|
||||
# cp simgear/gdbm/autoconf.h.cygwin32 simgear/gdbm/autoconf.h
|
||||
# fi
|
||||
])
|
||||
|
||||
echo ""
|
||||
echo "Configure Summary"
|
||||
echo "================="
|
||||
|
||||
echo "Prefix: $prefix"
|
||||
|
||||
if test "x$with_logging" != "x"; then
|
||||
echo "Debug messages: $with_logging"
|
||||
else
|
||||
echo "Debug messages: yes"
|
||||
fi
|
||||
|
||||
if test "x$with_efence" != "x"; then
|
||||
echo "Electric fence: $with_efence"
|
||||
else
|
||||
echo "Electric fence: no"
|
||||
fi
|
||||
|
||||
# if test "x$ac_cv_header_gdbm_h" != "xyes"; then
|
||||
# echo "Building gdbm"
|
||||
# fi
|
||||
|
||||
if test "x$ac_cv_header_mk4_h" != "xyes"; then
|
||||
echo "Building metakit"
|
||||
fi
|
||||
|
||||
if test "x$ac_cv_header_zlib_h" != "xyes"; then
|
||||
echo "Building zlib"
|
||||
fi
|
||||
42
mksymlinks.sh
Executable file
42
mksymlinks.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#! /bin/sh
|
||||
|
||||
echo ""
|
||||
echo "running $0 to rebuild simgear include links"
|
||||
|
||||
# toast the old directory
|
||||
rm -rf src/simgear
|
||||
mkdir src/simgear
|
||||
mkdir src/simgear/bucket
|
||||
mkdir src/simgear/debug
|
||||
mkdir src/simgear/math
|
||||
mkdir src/simgear/misc
|
||||
mkdir src/simgear/screen
|
||||
mkdir src/simgear/serial
|
||||
mkdir src/simgear/xgl
|
||||
mkdir src/simgear/zlib
|
||||
|
||||
# build new links
|
||||
ln -s ../include/compiler.h src/simgear/compiler.h
|
||||
ln -s ../include/constants.h src/simgear/constants.h
|
||||
ln -s ../include/fg_traits.hxx src/simgear/fg_traits.hxx
|
||||
ln -s ../include/fg_zlib.h src/simgear/fg_zlib.h
|
||||
ln -s ../include/version.h src/simgear/version.h
|
||||
|
||||
ln -s ../../bucket/newbucket.hxx src/simgear/bucket/newbucket.hxx
|
||||
|
||||
ln -s ../../debug/debug_types.h src/simgear/debug/debug_types.h
|
||||
ln -s ../../debug/logstream.hxx src/simgear/debug/logstream.hxx
|
||||
|
||||
ln -s ../../math/fg_memory.h src/simgear/math/fg_memory.h
|
||||
ln -s ../../math/fg_types.hxx src/simgear/math/fg_types.hxx
|
||||
ln -s ../../math/point3d.hxx src/simgear/math/point3d.hxx
|
||||
ln -s ../../math/polar3d.hxx src/simgear/math/polar3d.hxx
|
||||
|
||||
ln -s ../../misc/fgpath.hxx src/simgear/misc/fgpath.hxx
|
||||
ln -s ../../misc/fgstream.hxx src/simgear/misc/fgstream.hxx
|
||||
ln -s ../../misc/zfstream.hxx src/simgear/misc/zfstream.hxx
|
||||
|
||||
ln -s ../../xgl/xgl.h src/simgear/xgl/xgl.h
|
||||
|
||||
ln -s ../../zlib/zlib.h src/simgear/zlib/zlib.h
|
||||
ln -s ../../zlib/zconf.h src/simgear/zlib/zconf.h
|
||||
44
simgear/Makefile.am
Normal file
44
simgear/Makefile.am
Normal file
@@ -0,0 +1,44 @@
|
||||
if ENABLE_UNIX_SERIAL
|
||||
SERIAL_DIRS = serial
|
||||
else
|
||||
SERIAL_DIRS =
|
||||
endif
|
||||
|
||||
# if HAVE_GDBM
|
||||
# GDBM_DIRS =
|
||||
# else
|
||||
# GDBM_DIRS = gdbm
|
||||
# endif
|
||||
|
||||
if HAVE_ZLIB
|
||||
ZLIB_DIRS =
|
||||
else
|
||||
ZLIB_DIRS = zlib
|
||||
endif
|
||||
|
||||
METAR_DIRS =
|
||||
# METAR_DIRS = metar
|
||||
|
||||
EXTRA_DIST = version.h.in
|
||||
|
||||
include_HEADERS = \
|
||||
compiler.h constants.h fg_traits.hxx fg_zlib.h inlines.h version.h
|
||||
|
||||
SUBDIRS = \
|
||||
bucket \
|
||||
debug \
|
||||
ephemeris \
|
||||
io \
|
||||
magvar \
|
||||
math \
|
||||
$(METAR_DIRS) \
|
||||
misc \
|
||||
route \
|
||||
screen \
|
||||
$(SERIAL_DIRS) \
|
||||
sky \
|
||||
timing \
|
||||
xgl \
|
||||
xml \
|
||||
$(ZLIB_DIRS)
|
||||
|
||||
17
simgear/bucket/Makefile.am
Normal file
17
simgear/bucket/Makefile.am
Normal file
@@ -0,0 +1,17 @@
|
||||
includedir = @includedir@/bucket
|
||||
|
||||
lib_LIBRARIES = libsgbucket.a
|
||||
|
||||
include_HEADERS = newbucket.hxx
|
||||
|
||||
libsgbucket_a_SOURCES = newbucket.cxx
|
||||
|
||||
# noinst_PROGRAMS = testbucket
|
||||
|
||||
# testbucket_SOURCES = testbucket.cxx
|
||||
|
||||
# testbucket_LDADD = \
|
||||
# $(top_builddir)/bucket/libsgbucket.a \
|
||||
# $(top_builddir)/misc/libsgmisc.a
|
||||
|
||||
INCLUDES += -I$(top_srcdir)
|
||||
296
simgear/bucket/newbucket.cxx
Normal file
296
simgear/bucket/newbucket.cxx
Normal file
@@ -0,0 +1,296 @@
|
||||
/**************************************************************************
|
||||
* newbucket.hxx -- new bucket routines for better world modeling
|
||||
*
|
||||
* Written by Curtis L. Olson, started February 1999.
|
||||
*
|
||||
* Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <simgear/misc/fgpath.hxx>
|
||||
|
||||
#include "newbucket.hxx"
|
||||
|
||||
|
||||
// default constructor
|
||||
SGBucket::SGBucket() {
|
||||
}
|
||||
|
||||
|
||||
// constructor for specified location
|
||||
SGBucket::SGBucket(const double dlon, const double dlat) {
|
||||
set_bucket(dlon, dlat);
|
||||
}
|
||||
|
||||
|
||||
// create an impossible bucket if false
|
||||
SGBucket::SGBucket(const bool is_good) {
|
||||
set_bucket(0.0, 0.0);
|
||||
if ( !is_good ) {
|
||||
lon = -1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Parse a unique scenery tile index and find the lon, lat, x, and y
|
||||
SGBucket::SGBucket(const long int bindex) {
|
||||
long int index = bindex;
|
||||
|
||||
lon = index >> 14;
|
||||
index -= lon << 14;
|
||||
lon -= 180;
|
||||
|
||||
lat = index >> 6;
|
||||
index -= lat << 6;
|
||||
lat -= 90;
|
||||
|
||||
y = index >> 3;
|
||||
index -= y << 3;
|
||||
|
||||
x = index;
|
||||
}
|
||||
|
||||
|
||||
// default destructor
|
||||
SGBucket::~SGBucket() {
|
||||
}
|
||||
|
||||
|
||||
// Set the bucket params for the specified lat and lon
|
||||
void SGBucket::set_bucket( double *lonlat ) {
|
||||
set_bucket( lonlat[0], lonlat[1] );
|
||||
}
|
||||
|
||||
|
||||
// Set the bucket params for the specified lat and lon
|
||||
void SGBucket::set_bucket( double dlon, double dlat ) {
|
||||
//
|
||||
// latitude first
|
||||
//
|
||||
double span = sg_bucket_span( dlat );
|
||||
double diff = dlon - (double)(int)dlon;
|
||||
|
||||
// cout << "diff = " << diff << " span = " << span << endl;
|
||||
|
||||
if ( (dlon >= 0) || (fabs(diff) < FG_EPSILON) ) {
|
||||
lon = (int)dlon;
|
||||
} else {
|
||||
lon = (int)dlon - 1;
|
||||
}
|
||||
|
||||
// find subdivision or super lon if needed
|
||||
if ( span < FG_EPSILON ) {
|
||||
// polar cap
|
||||
lon = 0;
|
||||
x = 0;
|
||||
} else if ( span <= 1.0 ) {
|
||||
x = (int)((dlon - lon) / span);
|
||||
} else {
|
||||
if ( (dlon >= 0) || (fabs(diff) < FG_EPSILON) ) {
|
||||
lon = (int)( (int)(lon / span) * span);
|
||||
} else {
|
||||
// cout << " lon = " << lon
|
||||
// << " tmp = " << (int)((lon-1) / span) << endl;
|
||||
lon = (int)( (int)((lon + 1) / span) * span - span);
|
||||
if ( lon < -180 ) {
|
||||
lon = -180;
|
||||
}
|
||||
}
|
||||
x = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// then latitude
|
||||
//
|
||||
diff = dlat - (double)(int)dlat;
|
||||
|
||||
if ( (dlat >= 0) || (fabs(diff) < FG_EPSILON) ) {
|
||||
lat = (int)dlat;
|
||||
} else {
|
||||
lat = (int)dlat - 1;
|
||||
}
|
||||
y = (int)((dlat - lat) * 8);
|
||||
}
|
||||
|
||||
|
||||
// Build the path name for this bucket
|
||||
string SGBucket::gen_base_path() const {
|
||||
// long int index;
|
||||
int top_lon, top_lat, main_lon, main_lat;
|
||||
char hem, pole;
|
||||
char raw_path[256];
|
||||
|
||||
top_lon = lon / 10;
|
||||
main_lon = lon;
|
||||
if ( (lon < 0) && (top_lon * 10 != lon) ) {
|
||||
top_lon -= 1;
|
||||
}
|
||||
top_lon *= 10;
|
||||
if ( top_lon >= 0 ) {
|
||||
hem = 'e';
|
||||
} else {
|
||||
hem = 'w';
|
||||
top_lon *= -1;
|
||||
}
|
||||
if ( main_lon < 0 ) {
|
||||
main_lon *= -1;
|
||||
}
|
||||
|
||||
top_lat = lat / 10;
|
||||
main_lat = lat;
|
||||
if ( (lat < 0) && (top_lat * 10 != lat) ) {
|
||||
top_lat -= 1;
|
||||
}
|
||||
top_lat *= 10;
|
||||
if ( top_lat >= 0 ) {
|
||||
pole = 'n';
|
||||
} else {
|
||||
pole = 's';
|
||||
top_lat *= -1;
|
||||
}
|
||||
if ( main_lat < 0 ) {
|
||||
main_lat *= -1;
|
||||
}
|
||||
|
||||
sprintf(raw_path, "%c%03d%c%02d/%c%03d%c%02d",
|
||||
hem, top_lon, pole, top_lat,
|
||||
hem, main_lon, pole, main_lat);
|
||||
|
||||
FGPath path( raw_path );
|
||||
|
||||
return path.str();
|
||||
}
|
||||
|
||||
|
||||
// return width of the tile in degrees
|
||||
double SGBucket::get_width() const {
|
||||
return sg_bucket_span( get_center_lat() );
|
||||
}
|
||||
|
||||
|
||||
// return height of the tile in degrees
|
||||
double SGBucket::get_height() const {
|
||||
return SG_BUCKET_SPAN;
|
||||
}
|
||||
|
||||
|
||||
// return width of the tile in meters
|
||||
double SGBucket::get_width_m() const {
|
||||
double clat = (int)get_center_lat();
|
||||
if ( clat > 0 ) {
|
||||
clat = (int)clat + 0.5;
|
||||
} else {
|
||||
clat = (int)clat - 0.5;
|
||||
}
|
||||
double clat_rad = clat * DEG_TO_RAD;
|
||||
double cos_lat = cos( clat_rad );
|
||||
double local_radius = cos_lat * EQUATORIAL_RADIUS_M;
|
||||
double local_perimeter = 2.0 * local_radius * FG_PI;
|
||||
double degree_width = local_perimeter / 360.0;
|
||||
|
||||
return sg_bucket_span( get_center_lat() ) * degree_width;
|
||||
}
|
||||
|
||||
|
||||
// return height of the tile in meters
|
||||
double SGBucket::get_height_m() const {
|
||||
double perimeter = 2.0 * EQUATORIAL_RADIUS_M * FG_PI;
|
||||
double degree_height = perimeter / 360.0;
|
||||
|
||||
return SG_BUCKET_SPAN * degree_height;
|
||||
}
|
||||
|
||||
|
||||
// find the bucket which is offset by the specified tile units in the
|
||||
// X & Y direction. We need the current lon and lat to resolve
|
||||
// ambiguities when going from a wider tile to a narrower one above or
|
||||
// below. This assumes that we are feeding in
|
||||
SGBucket sgBucketOffset( double dlon, double dlat, int dx, int dy ) {
|
||||
SGBucket result( dlon, dlat );
|
||||
double clat = result.get_center_lat() + dy * SG_BUCKET_SPAN;
|
||||
|
||||
// walk dy units in the lat direction
|
||||
result.set_bucket( dlon, clat );
|
||||
|
||||
// find the lon span for the new latitude
|
||||
double span = sg_bucket_span( clat );
|
||||
|
||||
// walk dx units in the lon direction
|
||||
double tmp = dlon + dx * span;
|
||||
while ( tmp < -180.0 ) {
|
||||
tmp += 360.0;
|
||||
}
|
||||
while ( tmp >= 180.0 ) {
|
||||
tmp -= 360.0;
|
||||
}
|
||||
result.set_bucket( tmp, clat );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// calculate the offset between two buckets
|
||||
void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ) {
|
||||
|
||||
// Latitude difference
|
||||
double c1_lat = b1.get_center_lat();
|
||||
double c2_lat = b2.get_center_lat();
|
||||
double diff_lat = c2_lat - c1_lat;
|
||||
|
||||
#ifdef HAVE_RINT
|
||||
*dy = (int)rint( diff_lat / SG_BUCKET_SPAN );
|
||||
#else
|
||||
if ( diff_lat > 0 ) {
|
||||
*dy = (int)( diff_lat / SG_BUCKET_SPAN + 0.5 );
|
||||
} else {
|
||||
*dy = (int)( diff_lat / SG_BUCKET_SPAN - 0.5 );
|
||||
}
|
||||
#endif
|
||||
|
||||
// longitude difference
|
||||
double c1_lon = b1.get_center_lon();
|
||||
double c2_lon = b2.get_center_lon();
|
||||
double diff_lon = c2_lon - c1_lon;
|
||||
double span;
|
||||
if ( sg_bucket_span(c1_lat) <= sg_bucket_span(c2_lat) ) {
|
||||
span = sg_bucket_span(c1_lat);
|
||||
} else {
|
||||
span = sg_bucket_span(c2_lat);
|
||||
}
|
||||
|
||||
#ifdef HAVE_RINT
|
||||
*dx = (int)rint( diff_lon / span );
|
||||
#else
|
||||
if ( diff_lon > 0 ) {
|
||||
*dx = (int)( diff_lon / span + 0.5 );
|
||||
} else {
|
||||
*dx = (int)( diff_lon / span - 0.5 );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
234
simgear/bucket/newbucket.hxx
Normal file
234
simgear/bucket/newbucket.hxx
Normal file
@@ -0,0 +1,234 @@
|
||||
/**************************************************************************
|
||||
* newbucket.hxx -- new bucket routines for better world modeling
|
||||
*
|
||||
* Written by Curtis L. Olson, started February 1999.
|
||||
*
|
||||
* Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef _NEWBUCKET_HXX
|
||||
#define _NEWBUCKET_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/constants.h>
|
||||
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <cmath>
|
||||
# include <cstdio> // sprintf()
|
||||
# include <iostream>
|
||||
#else
|
||||
# include <math.h>
|
||||
# include <stdio.h> // sprintf()
|
||||
# include <iostream.h>
|
||||
#endif
|
||||
|
||||
// I don't understand ... <math.h> or <cmath> should be included
|
||||
// already depending on how you defined FG_HAVE_STD_INCLUDES, but I
|
||||
// can go ahead and add this -- CLO
|
||||
#ifdef __MWERKS__
|
||||
FG_USING_STD(sprintf);
|
||||
FG_USING_STD(fabs);
|
||||
#endif
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
#if ! defined( FG_HAVE_NATIVE_SGI_COMPILERS )
|
||||
FG_USING_STD(ostream);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define SG_BUCKET_SPAN 0.125 // 1/8 of a degree
|
||||
#define SG_HALF_BUCKET_SPAN 0.0625 // 1/2 of 1/8 of a degree = 1/16 = 0.0625
|
||||
|
||||
class SGBucket;
|
||||
ostream& operator<< ( ostream&, const SGBucket& );
|
||||
bool operator== ( const SGBucket&, const SGBucket& );
|
||||
|
||||
|
||||
// return the horizontal tile span factor based on latitude
|
||||
inline double sg_bucket_span( double l ) {
|
||||
if ( l >= 89.0 ) {
|
||||
return 360.0;
|
||||
} else if ( l >= 88.0 ) {
|
||||
return 8.0;
|
||||
} else if ( l >= 86.0 ) {
|
||||
return 4.0;
|
||||
} else if ( l >= 83.0 ) {
|
||||
return 2.0;
|
||||
} else if ( l >= 76.0 ) {
|
||||
return 1.0;
|
||||
} else if ( l >= 62.0 ) {
|
||||
return 0.5;
|
||||
} else if ( l >= 22.0 ) {
|
||||
return 0.25;
|
||||
} else if ( l >= -22.0 ) {
|
||||
return 0.125;
|
||||
} else if ( l >= -62.0 ) {
|
||||
return 0.25;
|
||||
} else if ( l >= -76.0 ) {
|
||||
return 0.5;
|
||||
} else if ( l >= -83.0 ) {
|
||||
return 1.0;
|
||||
} else if ( l >= -86.0 ) {
|
||||
return 2.0;
|
||||
} else if ( l >= -88.0 ) {
|
||||
return 4.0;
|
||||
} else if ( l >= -89.0 ) {
|
||||
return 8.0;
|
||||
} else {
|
||||
return 360.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SGBucket {
|
||||
|
||||
private:
|
||||
double cx, cy; // centerpoint (lon, lat) in degrees of bucket
|
||||
int lon; // longitude index (-180 to 179)
|
||||
int lat; // latitude index (-90 to 89)
|
||||
int x; // x subdivision (0 to 7)
|
||||
int y; // y subdivision (0 to 7)
|
||||
|
||||
public:
|
||||
|
||||
// default constructor
|
||||
SGBucket();
|
||||
|
||||
// constructor for specified location
|
||||
SGBucket(const double dlon, const double dlat);
|
||||
|
||||
// create an impossible bucket if false
|
||||
SGBucket(const bool is_good);
|
||||
|
||||
// Parse a unique scenery tile index and find the lon, lat, x, and y
|
||||
SGBucket(const long int bindex);
|
||||
|
||||
// default destructor
|
||||
~SGBucket();
|
||||
|
||||
// Set the bucket params for the specified lat and lon
|
||||
void set_bucket( double dlon, double dlat );
|
||||
void set_bucket( double *lonlat );
|
||||
|
||||
// create an impossible bucket
|
||||
inline void make_bad( void ) {
|
||||
set_bucket(0.0, 0.0);
|
||||
lon = -1000;
|
||||
}
|
||||
|
||||
// Generate the unique scenery tile index for this bucket
|
||||
//
|
||||
// The index is constructed as follows:
|
||||
//
|
||||
// 9 bits - to represent 360 degrees of longitude (-180 to 179)
|
||||
// 8 bits - to represent 180 degrees of latitude (-90 to 89)
|
||||
//
|
||||
// Each 1 degree by 1 degree tile is further broken down into an 8x8
|
||||
// grid. So we also need:
|
||||
//
|
||||
// 3 bits - to represent x (0 to 7)
|
||||
// 3 bits - to represent y (0 to 7)
|
||||
|
||||
inline long int gen_index() const {
|
||||
return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x;
|
||||
}
|
||||
|
||||
inline string gen_index_str() const {
|
||||
char tmp[20];
|
||||
sprintf(tmp, "%ld",
|
||||
(((long)lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x);
|
||||
return (string)tmp;
|
||||
}
|
||||
|
||||
// Build the path name for this bucket
|
||||
string gen_base_path() const;
|
||||
|
||||
// return the center lon of a tile
|
||||
inline double get_center_lon() const {
|
||||
double span = sg_bucket_span( lat + y / 8.0 + SG_HALF_BUCKET_SPAN );
|
||||
|
||||
if ( span >= 1.0 ) {
|
||||
return lon + span / 2.0;
|
||||
} else {
|
||||
return lon + x * span + span / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
// return the center lat of a tile
|
||||
inline double get_center_lat() const {
|
||||
return lat + y / 8.0 + SG_HALF_BUCKET_SPAN;
|
||||
}
|
||||
|
||||
// return width of the tile in degrees
|
||||
double get_width() const;
|
||||
// return height of the tile in degrees
|
||||
double get_height() const;
|
||||
|
||||
// return width of the tile in meters
|
||||
double get_width_m() const;
|
||||
// return height of the tile in meters
|
||||
double get_height_m() const;
|
||||
|
||||
// Informational methods
|
||||
inline int get_lon() const { return lon; }
|
||||
inline int get_lat() const { return lat; }
|
||||
inline int get_x() const { return x; }
|
||||
inline int get_y() const { return y; }
|
||||
|
||||
// friends
|
||||
friend ostream& operator<< ( ostream&, const SGBucket& );
|
||||
friend bool operator== ( const SGBucket&, const SGBucket& );
|
||||
};
|
||||
|
||||
|
||||
// offset a bucket specified by dlon, dlat by the specified tile units
|
||||
// in the X & Y direction
|
||||
SGBucket sgBucketOffset( double dlon, double dlat, int x, int y );
|
||||
|
||||
|
||||
// calculate the offset between two buckets
|
||||
void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy );
|
||||
|
||||
|
||||
inline ostream&
|
||||
operator<< ( ostream& out, const SGBucket& b )
|
||||
{
|
||||
return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y;
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
operator== ( const SGBucket& b1, const SGBucket& b2 )
|
||||
{
|
||||
return ( b1.lon == b2.lon &&
|
||||
b1.lat == b2.lat &&
|
||||
b1.x == b2.x &&
|
||||
b1.y == b2.y );
|
||||
}
|
||||
|
||||
|
||||
#endif // _NEWBUCKET_HXX
|
||||
|
||||
|
||||
344
simgear/compiler.h
Normal file
344
simgear/compiler.h
Normal file
@@ -0,0 +1,344 @@
|
||||
/**************************************************************************
|
||||
* compiler.h -- C++ Compiler Portability Macros
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef _COMPILER_H
|
||||
#define _COMPILER_H
|
||||
|
||||
// What this file does.
|
||||
// (1) Defines macros for some STL includes which may be affected
|
||||
// by file name length limitations.
|
||||
// (2) Defines macros for some features not supported by all C++ compilers.
|
||||
// (3) Defines 'explicit' as a null macro if the compiler doesn't support
|
||||
// the explicit keyword.
|
||||
// (4) Defines 'typename' as a null macro if the compiler doesn't support
|
||||
// the typename keyword.
|
||||
// (5) Defines bool, true and false if the compiler doesn't do so.
|
||||
// (6) Defines FG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
|
||||
// supports calling a function template by providing its template
|
||||
// arguments explicitly.
|
||||
// (7) Defines FG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
|
||||
// (8) Defines FG_NO_ARROW_OPERATOR if the compiler is unable
|
||||
// to support operator->() for iterators.
|
||||
// (9) Defines FG_USE_EXCEPTIONS if the compiler supports exceptions.
|
||||
// Note: no FlightGear code uses exceptions.
|
||||
// (10) Define FG_NAMESPACES if the compiler supports namespaces.
|
||||
// (11) FG_MATH_FN_IN_NAMESPACE_STD -- not used??
|
||||
// (12) Define FG_HAVE_STD if std namespace is supported.
|
||||
// (13) Defines FG_CLASS_PARTIAL_SPECIALIZATION if the compiler
|
||||
// supports partial specialization of class templates.
|
||||
// (14) Defines FG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
|
||||
// (15) Defines FG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
|
||||
// (16) Define FG_MATH_EXCEPTION_CLASH if math.h defines an exception class
|
||||
// that clashes with the one defined in <stdexcept>.
|
||||
|
||||
#ifdef __GNUC__
|
||||
# if __GNUC__ == 2
|
||||
# if __GNUC_MINOR__ < 8
|
||||
|
||||
// g++-2.7.x
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip.h>
|
||||
# define STL_IOSTREAM <iostream.h>
|
||||
# define STL_FSTREAM <fstream.h>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
# define STL_STRSTREAM <strstream.h>
|
||||
|
||||
# define FG_NEED_AUTO_PTR
|
||||
# define FG_NO_DEFAULT_TEMPLATE_ARGS
|
||||
# define FG_INCOMPLETE_FUNCTIONAL
|
||||
# define FG_NO_ARROW_OPERATOR
|
||||
|
||||
# elif __GNUC_MINOR__ >= 8
|
||||
|
||||
// g++-2.8.x and egcs-1.x
|
||||
# define FG_EXPLICIT_FUNCTION_TMPL_ARGS
|
||||
# define FG_NEED_AUTO_PTR
|
||||
# define FG_MEMBER_TEMPLATES
|
||||
# define FG_NAMESPACES
|
||||
# define FG_HAVE_STD
|
||||
# define FG_HAVE_STREAMBUF
|
||||
# define FG_CLASS_PARTIAL_SPECIALIZATION
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip>
|
||||
# define STL_IOSTREAM <iostream>
|
||||
# define STL_FSTREAM <fstream>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
# define STL_STRSTREAM <strstream>
|
||||
|
||||
# endif
|
||||
# else
|
||||
# error Time to upgrade. GNU compilers < 2.7 not supported
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* KAI C++ */
|
||||
#if defined(__KCC)
|
||||
|
||||
# define FG_NAMESPACES
|
||||
# define FG_HAVE_STD
|
||||
# define FG_HAVE_STREAMBUF
|
||||
# define FG_HAVE_TRAITS
|
||||
# define FG_HAVE_STD_INCLUDES
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip>
|
||||
# define STL_IOSTREAM <iostream>
|
||||
# define STL_FSTREAM <fstream>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
# define STL_STRSTREAM <strstream>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Metrowerks
|
||||
//
|
||||
#if defined(__MWERKS__)
|
||||
/*
|
||||
CodeWarrior compiler from Metrowerks, Inc.
|
||||
*/
|
||||
# define FG_HAVE_TRAITS
|
||||
# define FG_HAVE_STD_INCLUDES
|
||||
# define FG_HAVE_STD
|
||||
# define FG_NAMESPACES
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip>
|
||||
# define STL_IOSTREAM <iostream>
|
||||
# define STL_FSTREAM <fstream>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
|
||||
// Temp:
|
||||
# define bcopy(from, to, n) memcpy(to, from, n)
|
||||
|
||||
// -rp- please use FG_MEM_COPY everywhere !
|
||||
// #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
|
||||
|
||||
// -dw- currently used glut has no game mode stuff
|
||||
# define GLUT_WRONG_VERSION
|
||||
#endif
|
||||
|
||||
//
|
||||
// Microsoft compilers.
|
||||
//
|
||||
#ifdef _MSC_VER
|
||||
# define bcopy(from, to, n) memcpy(to, from, n)
|
||||
# define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
|
||||
|
||||
# if _MSC_VER == 1200 // msvc++ 6.0
|
||||
# define FG_NAMESPACES
|
||||
# define FG_HAVE_STD
|
||||
# define FG_HAVE_STD_INCLUDES
|
||||
# define FG_HAVE_STREAMBUF
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip>
|
||||
# define STL_IOSTREAM <iostream>
|
||||
# define STL_FSTREAM <fstream>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
# define STL_STRSTREAM <strstream>
|
||||
|
||||
# pragma warning(disable: 4786) // identifier was truncated to '255' characters
|
||||
# pragma warning(disable: 4244) // conversion from double to float
|
||||
# pragma warning(disable: 4305) //
|
||||
|
||||
# elif _MSC_VER == 1100 // msvc++ 5.0
|
||||
# define NEEDNAMESPACESTD
|
||||
# define FG_NAMESPACES
|
||||
# define FG_HAVE_STD
|
||||
# define FG_HAVE_STD_INCLUDES
|
||||
# define FG_HAVE_STREAMBUF
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip>
|
||||
# define STL_IOSTREAM <iostream>
|
||||
# define STL_FSTREAM <fstream>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
# define STL_STRSTREAM <strstream>
|
||||
|
||||
# pragma warning(disable: 4786) // identifier was truncated to '255' characters
|
||||
# pragma warning(disable: 4244) // conversion from double to float
|
||||
# pragma warning(disable: 4305) //
|
||||
|
||||
# else
|
||||
# error What version of MSVC++ is this?
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# if defined(HAVE_SGI_STL_PORT)
|
||||
|
||||
// Use quotes around long file names to get around Borland's include hackery
|
||||
|
||||
# define STL_ALGORITHM "algorithm"
|
||||
# define STL_FUNCTIONAL "functional"
|
||||
|
||||
# define FG_MATH_EXCEPTION_CLASH
|
||||
|
||||
# else
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRSTREAM <strstream>
|
||||
|
||||
# define FG_INCOMPLETE_FUNCTIONAL
|
||||
|
||||
# endif // HAVE_SGI_STL_PORT
|
||||
|
||||
# define STL_IOSTREAM <iostream>
|
||||
# define STL_FSTREAM <fstream>
|
||||
# define STL_STRING <string>
|
||||
# define FG_NO_DEFAULT_TEMPLATE_ARGS
|
||||
# define FG_NAMESPACES
|
||||
// # define FG_HAVE_STD
|
||||
|
||||
#endif // __BORLANDC__
|
||||
|
||||
//
|
||||
// Native SGI compilers
|
||||
//
|
||||
|
||||
#if defined ( sgi ) && !defined( __GNUC__ )
|
||||
# define FG_HAVE_NATIVE_SGI_COMPILERS
|
||||
|
||||
# define FG_EXPLICIT_FUNCTION_TMPL_ARGS
|
||||
# define FG_NEED_AUTO_PTR
|
||||
# define FG_MEMBER_TEMPLATES
|
||||
# define FG_NAMESPACES
|
||||
# define FG_HAVE_STD
|
||||
# define FG_CLASS_PARTIAL_SPECIALIZATION
|
||||
|
||||
# define STL_ALGORITHM <algorithm>
|
||||
# define STL_FUNCTIONAL <functional>
|
||||
# define STL_IOMANIP <iomanip.h>
|
||||
# define STL_IOSTREAM <iostream.h>
|
||||
# define STL_FSTREAM <fstream.h>
|
||||
# define STL_STDEXCEPT <stdexcept>
|
||||
# define STL_STRING <string>
|
||||
# define STL_STRSTREAM <strstream>
|
||||
|
||||
#endif // Native SGI compilers
|
||||
|
||||
|
||||
#if defined ( sun )
|
||||
# include <strings.h>
|
||||
# include <memory.h>
|
||||
# if defined ( __cplusplus )
|
||||
// typedef unsigned int size_t;
|
||||
extern "C" {
|
||||
extern void *memmove(void *, const void *, size_t);
|
||||
}
|
||||
# else
|
||||
extern void *memmove(void *, const void *, size_t);
|
||||
# endif // __cplusplus
|
||||
#endif // sun
|
||||
|
||||
//
|
||||
// No user modifiable definitions beyond here.
|
||||
//
|
||||
|
||||
#ifdef FG_NEED_EXPLICIT
|
||||
# define explicit
|
||||
#endif
|
||||
|
||||
#ifdef FG_NEED_TYPENAME
|
||||
# define typename
|
||||
#endif
|
||||
|
||||
#ifdef FG_NEED_MUTABLE
|
||||
# define mutable
|
||||
#endif
|
||||
|
||||
#ifdef FG_NEED_BOOL
|
||||
typedef int bool;
|
||||
# define true 1
|
||||
# define false 0
|
||||
#endif
|
||||
|
||||
#ifdef FG_EXPLICIT_FUNCTION_TMPL_ARGS
|
||||
# define FG_NULL_TMPL_ARGS <>
|
||||
#else
|
||||
# define FG_NULL_TMPL_ARGS
|
||||
#endif
|
||||
|
||||
#ifdef FG_CLASS_PARTIAL_SPECIALIZATION
|
||||
# define FG_TEMPLATE_NULL template<>
|
||||
#else
|
||||
# define FG_TEMPLATE_NULL
|
||||
#endif
|
||||
|
||||
// FG_NO_NAMESPACES is a hook so that users can disable namespaces
|
||||
// without having to edit library headers.
|
||||
#if defined(FG_NAMESPACES) && !defined(FG_NO_NAMESPACES)
|
||||
# define FG_NAMESPACE(X) namespace X {
|
||||
# define FG_NAMESPACE_END }
|
||||
# define FG_USING_NAMESPACE(X) using namespace X
|
||||
# else
|
||||
# define FG_NAMESPACE(X)
|
||||
# define FG_NAMESPACE_END
|
||||
# define FG_USING_NAMESPACE(X)
|
||||
#endif
|
||||
|
||||
# ifdef FG_HAVE_STD
|
||||
# define FG_USING_STD(X) using std::X
|
||||
# define STD std
|
||||
# else
|
||||
# define FG_USING_STD(X)
|
||||
# define STD
|
||||
# endif
|
||||
|
||||
// Additional <functional> implementation from SGI STL 3.11
|
||||
// Adapter function objects: pointers to member functions
|
||||
#ifdef FG_INCOMPLETE_FUNCTIONAL
|
||||
|
||||
template <class _Ret, class _Tp>
|
||||
class const_mem_fun_ref_t
|
||||
#ifndef __BORLANDC__
|
||||
: public unary_function<_Tp,_Ret>
|
||||
#endif // __BORLANDC__
|
||||
{
|
||||
public:
|
||||
explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
|
||||
_Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
|
||||
private:
|
||||
_Ret (_Tp::*_M_f)() const;
|
||||
};
|
||||
|
||||
template <class _Ret, class _Tp>
|
||||
inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
|
||||
{ return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
|
||||
|
||||
#endif // FG_INCOMPLETE_FUNCTIONAL
|
||||
|
||||
#endif // _COMPILER_H
|
||||
208
simgear/config.h.in
Normal file
208
simgear/config.h.in
Normal file
@@ -0,0 +1,208 @@
|
||||
/* simgear/config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
#undef const
|
||||
|
||||
/* Define if you don't have vprintf but do have _doprnt. */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
/* Define if you have the vprintf function. */
|
||||
#undef HAVE_VPRINTF
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define if your <sys/time.h> declares struct tm. */
|
||||
#undef TM_IN_SYS_TIME
|
||||
|
||||
/* Define if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
#undef const
|
||||
|
||||
|
||||
/* Define to eliminate all trace of debugging messages such as for a
|
||||
release build */
|
||||
#undef FG_NDEBUG
|
||||
|
||||
|
||||
/* Define to enable 3dfx/glide render in a window hack under unix.
|
||||
This probably won't work under windows. */
|
||||
#undef XMESA
|
||||
#undef FX
|
||||
|
||||
/* Define if you don't have vprintf but do have _doprnt. */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
/* Define if you have the vprintf function. */
|
||||
#undef HAVE_VPRINTF
|
||||
|
||||
/* Define if you have zlib installed system wide. */
|
||||
#undef HAVE_ZLIB
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define if your <sys/time.h> declares struct tm. */
|
||||
#undef TM_IN_SYS_TIME
|
||||
|
||||
/* Define if compiling on a Winbloze (95, NT, etc.) platform */
|
||||
#undef WIN32
|
||||
|
||||
/* Define if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
/* Define if you have the GetLocalTime function. */
|
||||
#undef HAVE_GETLOCALTIME
|
||||
|
||||
/* Define if you have the bcopy function. */
|
||||
#undef HAVE_BCOPY
|
||||
|
||||
/* Define if you have the ftime function. */
|
||||
#undef HAVE_FTIME
|
||||
|
||||
/* Define if you have the getitimer function. */
|
||||
#undef HAVE_GETITIMER
|
||||
|
||||
/* Define if you have the getrusage function. */
|
||||
#undef HAVE_GETRUSAGE
|
||||
|
||||
/* Define if you have the gettimeofday function. */
|
||||
#undef HAVE_GETTIMEOFDAY
|
||||
|
||||
/* Define if you have the memcpy function. */
|
||||
#undef HAVE_MEMCPY
|
||||
|
||||
/* Define if you have the mktime function. */
|
||||
#undef HAVE_MKTIME
|
||||
|
||||
/* Define if you have the rand function. */
|
||||
#undef HAVE_RAND
|
||||
|
||||
/* Define if you have the random function. */
|
||||
#undef HAVE_RANDOM
|
||||
|
||||
/* Define if you have the rint function. */
|
||||
#undef HAVE_RINT
|
||||
|
||||
/* Define if you have the setitimer function. */
|
||||
#undef HAVE_SETITIMER
|
||||
|
||||
/* Define if you have the signal function. */
|
||||
#undef HAVE_SIGNAL
|
||||
|
||||
/* Define if you have the strstr function. */
|
||||
#undef HAVE_STRSTR
|
||||
|
||||
/* Define if you have the timegm function. */
|
||||
#undef HAVE_TIMEGM
|
||||
|
||||
/* Define if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define if you have the <getopt.h> header file. */
|
||||
#undef HAVE_GETOPT_H
|
||||
|
||||
/* Define if you have the <malloc.h> header file. */
|
||||
#undef HAVE_MALLOC_H
|
||||
|
||||
/* Define if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define if you have the <sys/param.h> header file. */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define if you have the <sys/timeb.h> header file. */
|
||||
#undef HAVE_SYS_TIMEB_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if you have the <values.h> header file. */
|
||||
#undef HAVE_VALUES_H
|
||||
|
||||
/* Define if you have the <winbase.h> header file. */
|
||||
#undef HAVE_WINBASE_H
|
||||
|
||||
/* Define if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* Define if you have the GL library (-lGL). */
|
||||
#undef HAVE_LIBGL
|
||||
|
||||
/* Define if you have the GLU library (-lGLU). */
|
||||
#undef HAVE_LIBGLU
|
||||
|
||||
/* Define if you have the GLcore library (-lGLcore). */
|
||||
#undef HAVE_LIBGLCORE
|
||||
|
||||
/* Define if you have the ICE library (-lICE). */
|
||||
#undef HAVE_LIBICE
|
||||
|
||||
/* Define if you have the MesaGL library (-lMesaGL). */
|
||||
#undef HAVE_LIBMESAGL
|
||||
|
||||
/* Define if you have the MesaGLU library (-lMesaGLU). */
|
||||
#undef HAVE_LIBMESAGLU
|
||||
|
||||
/* Define if you have the SM library (-lSM). */
|
||||
#undef HAVE_LIBSM
|
||||
|
||||
/* Define if you have the X11 library (-lX11). */
|
||||
#undef HAVE_LIBX11
|
||||
|
||||
/* Define if you have the Xext library (-lXext). */
|
||||
#undef HAVE_LIBXEXT
|
||||
|
||||
/* Define if you have the Xi library (-lXi). */
|
||||
#undef HAVE_LIBXI
|
||||
|
||||
/* Define if you have the Xmu library (-lXmu). */
|
||||
#undef HAVE_LIBXMU
|
||||
|
||||
/* Define if you have the Xt library (-lXt). */
|
||||
#undef HAVE_LIBXT
|
||||
|
||||
/* Define if you have the glut library (-lglut). */
|
||||
#undef HAVE_LIBGLUT
|
||||
|
||||
/* Define if you have the m library (-lm). */
|
||||
#undef HAVE_LIBM
|
||||
|
||||
/* Define if you have the socket library (-lsocket). */
|
||||
#undef HAVE_LIBSOCKET
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
154
simgear/config.h.vc5
Normal file
154
simgear/config.h.vc5
Normal file
@@ -0,0 +1,154 @@
|
||||
/* Include/config.h. Generated for MSCV++ 5.0 */
|
||||
|
||||
/* Define if the X Window System is missing or not being used. */
|
||||
#define X_DISPLAY_MISSING 1
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define if you don't have vprintf but do have _doprnt. */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define if you have the vprintf function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to package name */
|
||||
#define PACKAGE "FlightGear"
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
/* #undef TIME_WITH_SYS_TIME */
|
||||
|
||||
/* Define if your <sys/time.h> declares struct tm. */
|
||||
/* #define TM_IN_SYS_TIME 1 */
|
||||
|
||||
/* Define to version number */
|
||||
#define VERSION "0.0.8"
|
||||
|
||||
/* Define if compiling on a Winbloze (95, NT, etc.) platform */
|
||||
#define WIN32 1
|
||||
|
||||
/* Define if you have the GetLocalTime function. */
|
||||
#define HAVE_GETLOCALTIME 1
|
||||
|
||||
/* Define if you have the ftime function. */
|
||||
/* #define HAVE_FTIME 1 */
|
||||
|
||||
/* Define if you have the getitimer function. */
|
||||
/* #define HAVE_GETITIMER 1 */
|
||||
|
||||
/* Define if you have the getrusage function. */
|
||||
/* #define HAVE_GETRUSAGE 1 */
|
||||
|
||||
/* Define if you have the gettimeofday function. */
|
||||
/* #define HAVE_GETTIMEOFDAY 1 */
|
||||
|
||||
/* Define if you have the mktime function. */
|
||||
#define HAVE_MKTIME 1
|
||||
|
||||
/* Define if you have the rand function. */
|
||||
#define HAVE_RAND 1
|
||||
|
||||
/* Define if you have the random function. */
|
||||
#define HAVE_RANDOM 1
|
||||
|
||||
/* Define if you have the rint function. */
|
||||
/* #define HAVE_RINT 1 */
|
||||
|
||||
/* Define if you have the setitimer function. */
|
||||
/* #define HAVE_SETITIMER 1 */
|
||||
|
||||
/* Define if you have the signal function. */
|
||||
#define HAVE_SIGNAL 1
|
||||
|
||||
/* Define if you have the strstr function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define if you have the <getopt.h> header file. */
|
||||
/* #define HAVE_GETOPT_H 1 */
|
||||
|
||||
/* Define if you have the <malloc.h> header file. */
|
||||
#define HAVE_MALLOC_H 1
|
||||
|
||||
/* Define if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define if you have the <sys/time.h> header file. */
|
||||
/* #define HAVE_SYS_TIME_H 1 */
|
||||
|
||||
/* Define if you have the <sys/timeb.h> header file. */
|
||||
#define HAVE_SYS_TIMEB_H 1
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
/* #define HAVE_UNISTD_H 1 */
|
||||
|
||||
/* Define if you have the <values.h> header file. */
|
||||
/* #define HAVE_VALUES_H 1 */
|
||||
|
||||
/* Define if you have the <winbase.h> header file. */
|
||||
#define HAVE_WINBASE_H 1
|
||||
|
||||
/* Define if you have the <windows.h> header file. */
|
||||
#define HAVE_WINDOWS_H 1
|
||||
|
||||
/* Define if you have the GL library (-lGL). */
|
||||
#define HAVE_LIBGL 1
|
||||
|
||||
/* Define if you have the GLU library (-lGLU). */
|
||||
#define HAVE_LIBGLU 1
|
||||
|
||||
/* Define if you have the GLcore library (-lGLcore). */
|
||||
/* #undef HAVE_LIBGLCORE */
|
||||
|
||||
/* Define if you have the ICE library (-lICE). */
|
||||
/* #define HAVE_LIBICE 1 */
|
||||
|
||||
/* Define if you have the MesaGL library (-lMesaGL). */
|
||||
/* #undef HAVE_LIBMESAGL */
|
||||
|
||||
/* Define if you have the MesaGLU library (-lMesaGLU). */
|
||||
/* #undef HAVE_LIBMESAGLU */
|
||||
|
||||
/* Define if you have the SM library (-lSM). */
|
||||
/* #define HAVE_LIBSM 1 */
|
||||
|
||||
/* Define if you have the X11 library (-lX11). */
|
||||
/* #define HAVE_LIBX11 1 */
|
||||
|
||||
/* Define if you have the Xext library (-lXext). */
|
||||
/* #define HAVE_LIBXEXT 1 */
|
||||
|
||||
/* Define if you have the Xi library (-lXi). */
|
||||
/* #define HAVE_LIBXI 1 */
|
||||
|
||||
/* Define if you have the Xmu library (-lXmu). */
|
||||
/* #define HAVE_LIBXMU 1 */
|
||||
|
||||
/* Define if you have the Xt library (-lXt). */
|
||||
/* #define HAVE_LIBXT 1 */
|
||||
|
||||
/* Define if you have the glut library (-lglut). */
|
||||
#define HAVE_LIBGLUT 1
|
||||
|
||||
/* Define if you have the m library (-lm). */
|
||||
#define HAVE_LIBM 1
|
||||
|
||||
/* Define if you have the socket library (-lsocket). */
|
||||
/* #undef HAVE_LIBSOCKET */
|
||||
|
||||
/* Define if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
#define HAVE_MEMCPY 1
|
||||
|
||||
145
simgear/constants.h
Normal file
145
simgear/constants.h
Normal file
@@ -0,0 +1,145 @@
|
||||
// constants.h -- various constant definitions
|
||||
//
|
||||
// Written by Curtis Olson, started February 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_CONSTANTS_H
|
||||
#define _SG_CONSTANTS_H
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <cmath>
|
||||
#else
|
||||
# ifdef FG_MATH_EXCEPTION_CLASH
|
||||
# define exception C_exception
|
||||
# endif
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
|
||||
// Make sure PI is defined in its various forms
|
||||
|
||||
// PI, only PI, and nothing but PI
|
||||
#ifdef M_PI
|
||||
# define FG_PI M_PI
|
||||
#else
|
||||
# define FG_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
// 2 * PI
|
||||
#define FG_2PI 6.28318530717958647692
|
||||
|
||||
// PI / 2
|
||||
#ifdef M_PI_2
|
||||
# define FG_PI_2 M_PI_2
|
||||
#else
|
||||
# define FG_PI_2 1.57079632679489661923
|
||||
#endif
|
||||
|
||||
// PI / 4
|
||||
#define FG_PI_4 0.78539816339744830961
|
||||
|
||||
#ifndef M_E
|
||||
# define M_E 2.7182818284590452354
|
||||
#endif
|
||||
|
||||
// ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator
|
||||
#define ONE_SECOND 4.848136811E-6
|
||||
|
||||
|
||||
// Radius of Earth in kilometers at the equator. Another source had
|
||||
// 6378.165 but this is probably close enough
|
||||
#define EARTH_RAD 6378.155
|
||||
|
||||
|
||||
// Earth parameters for WGS 84, taken from LaRCsim/ls_constants.h
|
||||
|
||||
// Value of earth radius from [8]
|
||||
#define EQUATORIAL_RADIUS_FT 20925650. // ft
|
||||
#define EQUATORIAL_RADIUS_M 6378138.12 // meter
|
||||
// Radius squared
|
||||
#define RESQ_FT 437882827922500. // ft
|
||||
#define RESQ_M 40680645877797.1344 // meter
|
||||
|
||||
#if 0
|
||||
// Value of earth flattening parameter from ref [8]
|
||||
//
|
||||
// Note: FP = f
|
||||
// E = 1-f
|
||||
// EPS = sqrt(1-(1-f)^2)
|
||||
//
|
||||
|
||||
#define FP 0.003352813178
|
||||
#define E 0.996647186
|
||||
#define EPS 0.081819221
|
||||
#define INVG 0.031080997
|
||||
|
||||
// Time Related Parameters
|
||||
|
||||
#define MJD0 2415020.0
|
||||
#define J2000 (2451545.0 - MJD0)
|
||||
#define SIDRATE .9972695677
|
||||
#endif
|
||||
|
||||
// Conversions
|
||||
|
||||
// Degrees to Radians
|
||||
#define DEG_TO_RAD 0.017453292 // deg*pi/180 = rad
|
||||
|
||||
// Radians to Degrees
|
||||
#define RAD_TO_DEG 57.29577951 // rad*180/pi = deg
|
||||
|
||||
// Arc seconds to radians // (arcsec*pi)/(3600*180) = rad
|
||||
#define ARCSEC_TO_RAD 4.84813681109535993589e-06
|
||||
|
||||
// Radians to arc seconds // (rad*3600*180)/pi = arcsec
|
||||
#define RAD_TO_ARCSEC 206264.806247096355156
|
||||
|
||||
// Feet to Meters
|
||||
#define FEET_TO_METER 0.3048
|
||||
|
||||
// Meters to Feet
|
||||
#define METER_TO_FEET 3.28083989501312335958
|
||||
|
||||
// Meters to Nautical Miles, 1 nm = 6076.11549 feet
|
||||
#define METER_TO_NM 0.00053995680
|
||||
|
||||
// Nautical Miles to Meters
|
||||
#define NM_TO_METER 1852.0000
|
||||
|
||||
// Radians to Nautical Miles, 1 nm = 1/60 of a degree
|
||||
#define NM_TO_RAD 0.00029088820866572159
|
||||
|
||||
// Nautical Miles to Radians
|
||||
#define RAD_TO_NM 3437.7467707849392526
|
||||
|
||||
// For divide by zero avoidance, this will be close enough to zero
|
||||
#define FG_EPSILON 0.0000001
|
||||
|
||||
|
||||
#endif // _SG_CONSTANTS_H
|
||||
11
simgear/debug/Makefile.am
Normal file
11
simgear/debug/Makefile.am
Normal file
@@ -0,0 +1,11 @@
|
||||
includedir = @includedir@/debug
|
||||
|
||||
EXTRA_DIST = logtest.cxx
|
||||
|
||||
lib_LIBRARIES = libsgdebug.a
|
||||
|
||||
include_HEADERS = debug_types.h logstream.hxx
|
||||
|
||||
libsgdebug_a_SOURCES = logstream.cxx
|
||||
|
||||
INCLUDES += -I$(top_srcdir)
|
||||
38
simgear/debug/debug_types.h
Normal file
38
simgear/debug/debug_types.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// NB: To add a dbg_class, add it here, and add it to the structure in
|
||||
// fg_debug.c
|
||||
|
||||
typedef enum {
|
||||
FG_NONE = 0x00000000,
|
||||
|
||||
FG_TERRAIN = 0x00000001,
|
||||
FG_ASTRO = 0x00000002,
|
||||
FG_FLIGHT = 0x00000004,
|
||||
FG_INPUT = 0x00000008,
|
||||
FG_GL = 0x00000010,
|
||||
FG_VIEW = 0x00000020,
|
||||
FG_COCKPIT = 0x00000040,
|
||||
FG_GENERAL = 0x00000080,
|
||||
FG_MATH = 0x00000100,
|
||||
FG_EVENT = 0x00000200,
|
||||
FG_AIRCRAFT = 0x00000400,
|
||||
FG_AUTOPILOT = 0x00000800,
|
||||
FG_IO = 0x00001000,
|
||||
FG_CLIPPER = 0x00002000,
|
||||
FG_NETWORK = 0x00004000,
|
||||
FG_UNDEFD = 0x00008000, // For range checking
|
||||
|
||||
FG_ALL = 0xFFFFFFFF
|
||||
} fgDebugClass;
|
||||
|
||||
|
||||
// NB: To add a priority, add it here.
|
||||
typedef enum {
|
||||
FG_BULK, // For frequent messages
|
||||
FG_DEBUG, // Less frequent debug type messages
|
||||
FG_INFO, // Informatory messages
|
||||
FG_WARN, // Possible impending problem
|
||||
FG_ALERT // Very possible impending problem
|
||||
// FG_EXIT, // Problem (no core)
|
||||
// FG_ABORT // Abandon ship (core)
|
||||
} fgDebugPriority;
|
||||
|
||||
64
simgear/debug/logstream.cxx
Normal file
64
simgear/debug/logstream.cxx
Normal file
@@ -0,0 +1,64 @@
|
||||
// Stream based logging mechanism.
|
||||
//
|
||||
// Written by Bernie Bright, 1998
|
||||
//
|
||||
// Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include "logstream.hxx"
|
||||
|
||||
bool logbuf::logging_enabled = true;
|
||||
fgDebugClass logbuf::logClass = FG_NONE;
|
||||
fgDebugPriority logbuf::logPriority = FG_INFO;
|
||||
streambuf* logbuf::sbuf = NULL;
|
||||
|
||||
logbuf::logbuf()
|
||||
{
|
||||
// if ( sbuf == NULL )
|
||||
// sbuf = cerr.rdbuf();
|
||||
}
|
||||
|
||||
logbuf::~logbuf()
|
||||
{
|
||||
if ( sbuf )
|
||||
sync();
|
||||
}
|
||||
|
||||
void
|
||||
logbuf::set_sb( streambuf* sb )
|
||||
{
|
||||
if ( sbuf )
|
||||
sync();
|
||||
|
||||
sbuf = sb;
|
||||
}
|
||||
|
||||
void
|
||||
logbuf::set_log_level( fgDebugClass c, fgDebugPriority p )
|
||||
{
|
||||
logClass = c;
|
||||
logPriority = p;
|
||||
}
|
||||
|
||||
void
|
||||
logstream::setLogLevels( fgDebugClass c, fgDebugPriority p )
|
||||
{
|
||||
logbuf::set_log_level( c, p );
|
||||
}
|
||||
|
||||
219
simgear/debug/logstream.hxx
Normal file
219
simgear/debug/logstream.hxx
Normal file
@@ -0,0 +1,219 @@
|
||||
// Stream based logging mechanism.
|
||||
//
|
||||
// Written by Bernie Bright, 1998
|
||||
//
|
||||
// Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#ifndef _LOGSTREAM_H
|
||||
#define _LOGSTREAM_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <streambuf>
|
||||
# include <iostream>
|
||||
#else
|
||||
# include <iostream.h>
|
||||
# include <simgear/fg_traits.hxx>
|
||||
#endif
|
||||
|
||||
#include <simgear/debug/debug_types.h>
|
||||
|
||||
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
|
||||
FG_USING_STD(streambuf);
|
||||
FG_USING_STD(ostream);
|
||||
FG_USING_STD(cerr);
|
||||
FG_USING_STD(endl);
|
||||
#endif
|
||||
|
||||
#ifdef __MWERKS__
|
||||
FG_USING_STD(iostream);
|
||||
#endif
|
||||
|
||||
//
|
||||
// TODO:
|
||||
//
|
||||
// 1. Change output destination. Done.
|
||||
// 2. Make logbuf thread safe.
|
||||
// 3. Read environment for default debugClass and debugPriority.
|
||||
//
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// logbuf is an output-only streambuf with the ability to disable sets of
|
||||
// messages at runtime. Only messages with priority >= logbuf::logPriority
|
||||
// and debugClass == logbuf::logClass are output.
|
||||
//
|
||||
class logbuf : public streambuf
|
||||
{
|
||||
public:
|
||||
|
||||
#ifndef FG_HAVE_STD_INCLUDES
|
||||
typedef char_traits<char> traits_type;
|
||||
typedef char_traits<char>::int_type int_type;
|
||||
typedef char_traits<char>::pos_type pos_type;
|
||||
typedef char_traits<char>::off_type off_type;
|
||||
#endif
|
||||
// logbuf( streambuf* sb ) : sbuf(sb) {}
|
||||
logbuf();
|
||||
~logbuf();
|
||||
|
||||
// Is logging enabled?
|
||||
bool enabled() { return logging_enabled; }
|
||||
|
||||
// Set the logging level of subsequent messages.
|
||||
void set_log_state( fgDebugClass c, fgDebugPriority p );
|
||||
|
||||
// Set the global logging level.
|
||||
static void set_log_level( fgDebugClass c, fgDebugPriority p );
|
||||
|
||||
//
|
||||
void set_sb( streambuf* sb );
|
||||
|
||||
protected:
|
||||
|
||||
inline virtual int sync();
|
||||
int_type overflow( int ch );
|
||||
// int xsputn( const char* s, istreamsize n );
|
||||
|
||||
private:
|
||||
|
||||
// The streambuf used for actual output. Defaults to cerr.rdbuf().
|
||||
static streambuf* sbuf;
|
||||
|
||||
static bool logging_enabled;
|
||||
static fgDebugClass logClass;
|
||||
static fgDebugPriority logPriority;
|
||||
|
||||
private:
|
||||
|
||||
// Not defined.
|
||||
logbuf( const logbuf& );
|
||||
void operator= ( const logbuf& );
|
||||
};
|
||||
|
||||
inline int
|
||||
logbuf::sync()
|
||||
{
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
return sbuf->pubsync();
|
||||
#else
|
||||
return sbuf->sync();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void
|
||||
logbuf::set_log_state( fgDebugClass c, fgDebugPriority p )
|
||||
{
|
||||
logging_enabled = ((c & logClass) != 0 && p >= logPriority);
|
||||
}
|
||||
|
||||
inline logbuf::int_type
|
||||
logbuf::overflow( int c )
|
||||
{
|
||||
return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// logstream manipulator for setting the log level of a message.
|
||||
//
|
||||
struct loglevel
|
||||
{
|
||||
loglevel( fgDebugClass c, fgDebugPriority p )
|
||||
: logClass(c), logPriority(p) {}
|
||||
|
||||
fgDebugClass logClass;
|
||||
fgDebugPriority logPriority;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// A helper class that ensures a streambuf and ostream are constructed and
|
||||
// destroyed in the correct order. The streambuf must be created before the
|
||||
// ostream but bases are constructed before members. Thus, making this class
|
||||
// a private base of logstream, declared to the left of ostream, we ensure the
|
||||
// correct order of construction and destruction.
|
||||
//
|
||||
struct logstream_base
|
||||
{
|
||||
// logstream_base( streambuf* sb ) : lbuf(sb) {}
|
||||
logstream_base() {}
|
||||
|
||||
logbuf lbuf;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
class logstream : private logstream_base, public ostream
|
||||
{
|
||||
public:
|
||||
// The default is to send messages to cerr.
|
||||
logstream( ostream& out )
|
||||
// : logstream_base(out.rdbuf()),
|
||||
: logstream_base(),
|
||||
ostream(&lbuf) { lbuf.set_sb(out.rdbuf());}
|
||||
|
||||
void set_output( ostream& out ) { lbuf.set_sb( out.rdbuf() ); }
|
||||
|
||||
// Set the global log class and priority level.
|
||||
void setLogLevels( fgDebugClass c, fgDebugPriority p );
|
||||
|
||||
// Output operator to capture the debug level and priority of a message.
|
||||
inline ostream& operator<< ( const loglevel& l );
|
||||
};
|
||||
|
||||
inline ostream&
|
||||
logstream::operator<< ( const loglevel& l )
|
||||
{
|
||||
lbuf.set_log_state( l.logClass, l.logPriority );
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Return the one and only logstream instance.
|
||||
// We use a function instead of a global object so we are assured that cerr
|
||||
// has been initialised.
|
||||
//
|
||||
inline logstream&
|
||||
fglog()
|
||||
{
|
||||
static logstream logstrm( cerr );
|
||||
return logstrm;
|
||||
}
|
||||
|
||||
#ifdef FG_NDEBUG
|
||||
# define FG_LOG(C,P,M)
|
||||
#elif defined( __MWERKS__ )
|
||||
# define FG_LOG(C,P,M) ::fglog() << ::loglevel(C,P) << M << std::endl
|
||||
#else
|
||||
# define FG_LOG(C,P,M) fglog() << loglevel(C,P) << M << endl
|
||||
#endif
|
||||
|
||||
#endif // _LOGSTREAM_H
|
||||
|
||||
34
simgear/debug/logtest.cxx
Normal file
34
simgear/debug/logtest.cxx
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <string>
|
||||
#include "Debug/logstream.hxx"
|
||||
|
||||
int
|
||||
main( int argc, char* argv[] )
|
||||
{
|
||||
fglog().setLogLevels( FG_ALL, FG_INFO );
|
||||
|
||||
FG_LOG( FG_TERRAIN, FG_BULK, "terrain::bulk" ); // shouldnt appear
|
||||
FG_LOG( FG_TERRAIN, FG_DEBUG, "terrain::debug" ); // shouldnt appear
|
||||
FG_LOG( FG_TERRAIN, FG_INFO, "terrain::info" );
|
||||
FG_LOG( FG_TERRAIN, FG_WARN, "terrain::warn" );
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT, "terrain::alert" );
|
||||
|
||||
int i = 12345;
|
||||
long l = 54321L;
|
||||
double d = 3.14159;
|
||||
string s = "Hello world!";
|
||||
|
||||
FG_LOG( FG_EVENT, FG_INFO, "event::info "
|
||||
<< "i=" << i
|
||||
<< ", l=" << l
|
||||
<< ", d=" << d
|
||||
<< ", d*l=" << d*l
|
||||
<< ", s=\"" << s << "\"" );
|
||||
|
||||
// This shouldn't appear in log output:
|
||||
FG_LOG( FG_EVENT, FG_DEBUG, "event::debug "
|
||||
<< "- this should be seen - "
|
||||
<< "d=" << d
|
||||
<< ", s=\"" << s << "\"" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,19 +1,34 @@
|
||||
noinst_LIBRARIES = libAstro.a
|
||||
includedir = @includedir@/ephemeris
|
||||
|
||||
libAstro_a_SOURCES = \
|
||||
celestialBody.cxx celestialBody.hxx \
|
||||
jupiter.cxx jupiter.hxx \
|
||||
mars.cxx mars.hxx \
|
||||
mercury.cxx mercury.hxx \
|
||||
moon.cxx moon.hxx \
|
||||
neptune.cxx neptune.hxx \
|
||||
lib_LIBRARIES = libsgephem.a
|
||||
|
||||
include_HEADERS = \
|
||||
celestialBody.hxx \
|
||||
ephemeris.hxx \
|
||||
jupiter.hxx \
|
||||
mars.hxx \
|
||||
mercury.hxx \
|
||||
moonpos.hxx \
|
||||
neptune.hxx \
|
||||
saturn.hxx \
|
||||
star.hxx \
|
||||
stardata.hxx \
|
||||
uranus.hxx \
|
||||
venus.hxx
|
||||
|
||||
libsgephem_a_SOURCES = \
|
||||
celestialBody.cxx \
|
||||
ephemeris.cxx \
|
||||
jupiter.cxx \
|
||||
mars.cxx \
|
||||
mercury.cxx \
|
||||
moonpos.cxx \
|
||||
neptune.cxx \
|
||||
pluto.hxx \
|
||||
saturn.cxx saturn.hxx \
|
||||
sky.cxx sky.hxx \
|
||||
solarsystem.cxx solarsystem.hxx \
|
||||
star.cxx star.hxx \
|
||||
stars.cxx stars.hxx \
|
||||
uranus.cxx uranus.hxx \
|
||||
venus.cxx venus.hxx
|
||||
saturn.cxx \
|
||||
star.cxx \
|
||||
stardata.cxx \
|
||||
uranus.cxx \
|
||||
venus.cxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
||||
INCLUDES += -I$(top_srcdir)
|
||||
|
||||
@@ -5,24 +5,25 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#ifdef FG_MATH_EXCEPTION_CLASH
|
||||
# define exception c_exception
|
||||
@@ -34,7 +35,7 @@
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* void CelestialBody::updatePosition(fgTIME *t, Star *ourSun)
|
||||
* void CelestialBody::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* Basically, this member function provides a general interface for
|
||||
* calculating the right ascension and declinaion. This function is
|
||||
@@ -45,25 +46,25 @@
|
||||
* position is calculated an a slightly different manner.
|
||||
*
|
||||
* arguments:
|
||||
* fgTIME t: provides the current time.
|
||||
* double mjd: provides the modified julian date.
|
||||
* Star *ourSun: the sun's position is needed to convert heliocentric
|
||||
* coordinates into geocentric coordinates.
|
||||
*
|
||||
* return value: none
|
||||
*
|
||||
*************************************************************************/
|
||||
void CelestialBody::updatePosition(FGTime *t, Star *ourSun)
|
||||
void CelestialBody::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
double eccAnom, v, ecl, actTime,
|
||||
xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
|
||||
|
||||
updateOrbElements(t);
|
||||
actTime = fgCalcActTime(t);
|
||||
updateOrbElements(mjd);
|
||||
actTime = sgCalcActTime(mjd);
|
||||
|
||||
// calcualate the angle bewteen ecliptic and equatorial coordinate system
|
||||
ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 *actTime);
|
||||
|
||||
eccAnom = fgCalcEccAnom(M, e); //calculate the eccentric anomaly
|
||||
eccAnom = sgCalcEccAnom(M, e); //calculate the eccentric anomaly
|
||||
xv = a * (cos(eccAnom) - e);
|
||||
yv = a * (sqrt (1.0 - e*e) * sin(eccAnom));
|
||||
v = atan2(yv, xv); // the planet's true anomaly
|
||||
@@ -87,8 +88,8 @@ void CelestialBody::updatePosition(FGTime *t, Star *ourSun)
|
||||
ze = yg * sin(ecl) + zg * cos(ecl);
|
||||
rightAscension = atan2(ye, xe);
|
||||
declination = atan2(ze, sqrt(xe*xe + ye*ye));
|
||||
FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : "
|
||||
<< rightAscension << " (ra), " << declination << " (dec)" );
|
||||
/* FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : "
|
||||
<< rightAscension << " (ra), " << declination << " (dec)" ); */
|
||||
|
||||
//calculate some variables specific to calculating the magnitude
|
||||
//of the planet
|
||||
@@ -107,10 +108,10 @@ void CelestialBody::updatePosition(FGTime *t, Star *ourSun)
|
||||
}
|
||||
|
||||
FV = RAD_TO_DEG * acos( tmp );
|
||||
};
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* double CelestialBody::fgCalcEccAnom(double M, double e)
|
||||
* double CelestialBody::sgCalcEccAnom(double M, double e)
|
||||
* this private member calculates the eccentric anomaly of a celestial body,
|
||||
* given its mean anomaly and eccentricity.
|
||||
*
|
||||
@@ -135,7 +136,7 @@ void CelestialBody::updatePosition(FGTime *t, Star *ourSun)
|
||||
* the eccentric anomaly
|
||||
*
|
||||
****************************************************************************/
|
||||
double CelestialBody::fgCalcEccAnom(double M, double e)
|
||||
double CelestialBody::sgCalcEccAnom(double M, double e)
|
||||
{
|
||||
double
|
||||
eccAnom, E0, E1, diff;
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -31,15 +32,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <simgear/constants.h>
|
||||
|
||||
class Star;
|
||||
|
||||
class CelestialBody
|
||||
{
|
||||
protected: // make the data protected, in order to give the inherited
|
||||
// classes direct access to the data
|
||||
protected: // make the data protected, in order to give the
|
||||
// inherited classes direct access to the data
|
||||
double NFirst; /* longitude of the ascending node first part */
|
||||
double NSec; /* longitude of the ascending node second part */
|
||||
double iFirst; /* inclination to the ecliptic first part */
|
||||
@@ -60,9 +60,9 @@ protected: // make the data protected, in order to give the inherit
|
||||
double magnitude;
|
||||
double lonEcl, latEcl;
|
||||
|
||||
double fgCalcEccAnom(double M, double e);
|
||||
double fgCalcActTime(FGTime *t);
|
||||
void updateOrbElements(FGTime *t);
|
||||
double sgCalcEccAnom(double M, double e);
|
||||
double sgCalcActTime(double mjd);
|
||||
void updateOrbElements(double mjd);
|
||||
|
||||
public:
|
||||
CelestialBody(double Nf, double Ns,
|
||||
@@ -70,12 +70,21 @@ public:
|
||||
double wf, double ws,
|
||||
double af, double as,
|
||||
double ef, double es,
|
||||
double Mf, double Ms, FGTime *t);
|
||||
double Mf, double Ms, double mjd);
|
||||
CelestialBody(double Nf, double Ns,
|
||||
double If, double Is,
|
||||
double wf, double ws,
|
||||
double af, double as,
|
||||
double ef, double es,
|
||||
double Mf, double Ms);
|
||||
void getPos(double *ra, double *dec);
|
||||
void getPos(double *ra, double *dec, double *magnitude);
|
||||
double getRightAscension();
|
||||
double getDeclination();
|
||||
double getMagnitude();
|
||||
double getLon();
|
||||
double getLat();
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -103,7 +112,7 @@ inline CelestialBody::CelestialBody(double Nf, double Ns,
|
||||
double wf, double ws,
|
||||
double af, double as,
|
||||
double ef, double es,
|
||||
double Mf, double Ms, FGTime *t)
|
||||
double Mf, double Ms, double mjd)
|
||||
{
|
||||
NFirst = Nf; NSec = Ns;
|
||||
iFirst = If; iSec = Is;
|
||||
@@ -111,21 +120,36 @@ inline CelestialBody::CelestialBody(double Nf, double Ns,
|
||||
aFirst = af; aSec = as;
|
||||
eFirst = ef; eSec = es;
|
||||
MFirst = Mf; MSec = Ms;
|
||||
updateOrbElements(t);
|
||||
};
|
||||
updateOrbElements(mjd);
|
||||
}
|
||||
|
||||
inline CelestialBody::CelestialBody(double Nf, double Ns,
|
||||
double If, double Is,
|
||||
double wf, double ws,
|
||||
double af, double as,
|
||||
double ef, double es,
|
||||
double Mf, double Ms)
|
||||
{
|
||||
NFirst = Nf; NSec = Ns;
|
||||
iFirst = If; iSec = Is;
|
||||
wFirst = wf; wSec = ws;
|
||||
aFirst = af; aSec = as;
|
||||
eFirst = ef; eSec = es;
|
||||
MFirst = Mf; MSec = Ms;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* inline void CelestialBody::updateOrbElements(FGTime *t)
|
||||
* inline void CelestialBody::updateOrbElements(double mjd)
|
||||
* given the current time, this private member calculates the actual
|
||||
* orbital elements
|
||||
*
|
||||
* Arguments: FGTime *t: the current time:
|
||||
* Arguments: double mjd: the current modified julian date:
|
||||
*
|
||||
* return value: none
|
||||
***************************************************************************/
|
||||
inline void CelestialBody::updateOrbElements(FGTime *t)
|
||||
inline void CelestialBody::updateOrbElements(double mjd)
|
||||
{
|
||||
double actTime = fgCalcActTime(t);
|
||||
double actTime = sgCalcActTime(mjd);
|
||||
M = DEG_TO_RAD * (MFirst + (MSec * actTime));
|
||||
w = DEG_TO_RAD * (wFirst + (wSec * actTime));
|
||||
N = DEG_TO_RAD * (NFirst + (NSec * actTime));
|
||||
@@ -134,7 +158,7 @@ inline void CelestialBody::updateOrbElements(FGTime *t)
|
||||
a = aFirst + (aSec * actTime);
|
||||
}
|
||||
/*****************************************************************************
|
||||
* inline double CelestialBody::fgCalcActTime(FGTime *t)
|
||||
* inline double CelestialBody::sgCalcActTime(double mjd)
|
||||
* this private member function returns the offset in days from the epoch for
|
||||
* wich the orbital elements are calculated (Jan, 1st, 2000).
|
||||
*
|
||||
@@ -142,9 +166,9 @@ inline void CelestialBody::updateOrbElements(FGTime *t)
|
||||
*
|
||||
* return value: the (fractional) number of days until Jan 1, 2000.
|
||||
****************************************************************************/
|
||||
inline double CelestialBody::fgCalcActTime(FGTime *t)
|
||||
inline double CelestialBody::sgCalcActTime(double mjd)
|
||||
{
|
||||
return (t->getMjd() - 36523.5);
|
||||
return (mjd - 36523.5);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -170,6 +194,10 @@ inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
|
||||
*magn = magnitude;
|
||||
}
|
||||
|
||||
inline double CelestialBody::getRightAscension() { return rightAscension; }
|
||||
inline double CelestialBody::getDeclination() { return declination; }
|
||||
inline double CelestialBody::getMagnitude() { return magnitude; }
|
||||
|
||||
inline double CelestialBody::getLon()
|
||||
{
|
||||
return lonEcl;
|
||||
|
||||
83
simgear/ephemeris/ephemeris.cxx
Normal file
83
simgear/ephemeris/ephemeris.cxx
Normal file
@@ -0,0 +1,83 @@
|
||||
// ephemeris.cxx -- Top level class for calculating current positions of
|
||||
// astronomical objects
|
||||
//
|
||||
// Written by Curtis Olson, started March 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include "ephemeris.hxx"
|
||||
|
||||
|
||||
// Constructor
|
||||
SGEphemeris::SGEphemeris( const string &path ) {
|
||||
our_sun = new Star;
|
||||
moon = new MoonPos;
|
||||
mercury = new Mercury;
|
||||
venus = new Venus;
|
||||
mars = new Mars;
|
||||
jupiter = new Jupiter;
|
||||
saturn = new Saturn;
|
||||
uranus = new Uranus;
|
||||
neptune = new Neptune;
|
||||
stars = new SGStarData( FGPath(path) );
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
SGEphemeris::~SGEphemeris( void ) {
|
||||
delete our_sun;
|
||||
delete moon;
|
||||
delete mercury;
|
||||
delete venus;
|
||||
delete mars;
|
||||
delete jupiter;
|
||||
delete saturn;
|
||||
delete uranus;
|
||||
delete neptune;
|
||||
delete stars;
|
||||
}
|
||||
|
||||
|
||||
// Update (recalculate) the positions of all objects for the specified
|
||||
// time
|
||||
void SGEphemeris::update( double mjd, double lst, double lat ) {
|
||||
// update object positions
|
||||
our_sun->updatePosition( mjd );
|
||||
moon->updatePosition( mjd, lst, lat, our_sun );
|
||||
mercury->updatePosition( mjd, our_sun );
|
||||
venus->updatePosition( mjd, our_sun );
|
||||
mars->updatePosition( mjd, our_sun );
|
||||
jupiter->updatePosition( mjd, our_sun );
|
||||
saturn->updatePosition( mjd, our_sun );
|
||||
uranus->updatePosition( mjd, our_sun );
|
||||
neptune->updatePosition( mjd, our_sun );
|
||||
|
||||
// update planets list
|
||||
nplanets = 7;
|
||||
mercury->getPos( &planets[0][0], &planets[0][1], &planets[0][2] );
|
||||
venus ->getPos( &planets[1][0], &planets[1][1], &planets[1][2] );
|
||||
mars ->getPos( &planets[2][0], &planets[2][1], &planets[2][2] );
|
||||
jupiter->getPos( &planets[3][0], &planets[3][1], &planets[3][2] );
|
||||
saturn ->getPos( &planets[4][0], &planets[4][1], &planets[4][2] );
|
||||
uranus ->getPos( &planets[5][0], &planets[5][1], &planets[5][2] );
|
||||
neptune->getPos( &planets[6][0], &planets[6][1], &planets[6][2] );
|
||||
}
|
||||
|
||||
114
simgear/ephemeris/ephemeris.hxx
Normal file
114
simgear/ephemeris/ephemeris.hxx
Normal file
@@ -0,0 +1,114 @@
|
||||
// ephemeris.hxx -- Top level class for calculating current positions of
|
||||
// astronomical objects
|
||||
//
|
||||
// Top level interface written by Curtis Olson, started March 2000.
|
||||
//
|
||||
// All the core code underneath this is written by Durk Talsma. See
|
||||
// the headers of all the other individual files for details.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _EPHEMERIS_HXX
|
||||
#define _EPHEMERIS_HXX
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <plib/sg.h>
|
||||
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
#include <simgear/ephemeris/moonpos.hxx>
|
||||
#include <simgear/ephemeris/mercury.hxx>
|
||||
#include <simgear/ephemeris/venus.hxx>
|
||||
#include <simgear/ephemeris/mars.hxx>
|
||||
#include <simgear/ephemeris/jupiter.hxx>
|
||||
#include <simgear/ephemeris/saturn.hxx>
|
||||
#include <simgear/ephemeris/uranus.hxx>
|
||||
#include <simgear/ephemeris/neptune.hxx>
|
||||
#include <simgear/ephemeris/stardata.hxx>
|
||||
|
||||
|
||||
class SGEphemeris {
|
||||
|
||||
Star *our_sun;
|
||||
MoonPos *moon;
|
||||
Mercury *mercury;
|
||||
Venus *venus;
|
||||
Mars *mars;
|
||||
Jupiter *jupiter;
|
||||
Saturn *saturn;
|
||||
Uranus *uranus;
|
||||
Neptune *neptune;
|
||||
|
||||
// 9 planets, minus earth, minus pluto which we don't draw = 7
|
||||
// planets[i][0] = Right Ascension
|
||||
// planets[i][1] = Declination
|
||||
// planets[i][2] = Magnitude
|
||||
int nplanets;
|
||||
sgdVec3 planets[7];
|
||||
|
||||
SGStarData *stars;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
SGEphemeris( const string &path );
|
||||
|
||||
// Destructor
|
||||
~SGEphemeris( void );
|
||||
|
||||
// Update (recalculate) the positions of all objects for the
|
||||
// specified time
|
||||
void update(double mjd, double lst, double lat);
|
||||
|
||||
// sun
|
||||
inline Star *get_sun() const { return our_sun; }
|
||||
inline double getSunRightAscension() const {
|
||||
return our_sun->getRightAscension();
|
||||
}
|
||||
inline double getSunDeclination() const {
|
||||
return our_sun->getDeclination();
|
||||
}
|
||||
|
||||
// moon
|
||||
inline MoonPos *get_moon() const { return moon; }
|
||||
inline double getMoonRightAscension() const {
|
||||
return moon->getRightAscension();
|
||||
}
|
||||
inline double getMoonDeclination() const {
|
||||
return moon->getDeclination();
|
||||
}
|
||||
|
||||
// planets
|
||||
inline int getNumPlanets() const { return nplanets; }
|
||||
inline sgdVec3 *getPlanets() { return planets; }
|
||||
|
||||
// planets
|
||||
inline int getNumStars() const { return stars->getNumStars(); }
|
||||
inline sgdVec3 *getStars() { return stars->getStars(); }
|
||||
};
|
||||
|
||||
|
||||
#endif // _EPHEMERIS_HXX
|
||||
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -31,32 +32,42 @@
|
||||
#include "jupiter.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Jupiter::Jupiter(FGTime *t)
|
||||
* Jupiter::Jupiter(double mjd)
|
||||
* Public constructor for class Jupiter
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Jupiter are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Jupiter::Jupiter(FGTime *t) :
|
||||
Jupiter::Jupiter(double mjd) :
|
||||
CelestialBody(100.4542, 2.7685400E-5,
|
||||
1.3030, -1.557E-7,
|
||||
273.8777, 1.6450500E-5,
|
||||
5.2025600, 0.000000,
|
||||
0.048498, 4.469E-9,
|
||||
19.89500, 0.08308530010, t)
|
||||
19.89500, 0.08308530010, mjd)
|
||||
{
|
||||
}
|
||||
|
||||
Jupiter::Jupiter() :
|
||||
CelestialBody(100.4542, 2.7685400E-5,
|
||||
1.3030, -1.557E-7,
|
||||
273.8777, 1.6450500E-5,
|
||||
5.2025600, 0.000000,
|
||||
0.048498, 4.469E-9,
|
||||
19.89500, 0.08308530010)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Jupiter::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Jupiter::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Jupiter, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Jupiter specific equation
|
||||
*************************************************************************/
|
||||
void Jupiter::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Jupiter::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _JUPITER_HXX_
|
||||
#define _JUPITER_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Jupiter : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Jupiter (FGTime *t);
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
Jupiter (double mjd);
|
||||
Jupiter ();
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _JUPITER_HXX_
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -30,30 +31,39 @@
|
||||
#include "mars.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Mars::Mars(FGTime *t)
|
||||
* Mars::Mars(double mjd)
|
||||
* Public constructor for class Mars
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Mars are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Mars::Mars(FGTime *t) :
|
||||
Mars::Mars(double mjd) :
|
||||
CelestialBody(49.55740, 2.1108100E-5,
|
||||
1.8497, -1.78E-8,
|
||||
286.5016, 2.9296100E-5,
|
||||
1.5236880, 0.000000,
|
||||
0.093405, 2.516E-9,
|
||||
18.60210, 0.52402077660, t)
|
||||
18.60210, 0.52402077660, mjd)
|
||||
{
|
||||
}
|
||||
Mars::Mars() :
|
||||
CelestialBody(49.55740, 2.1108100E-5,
|
||||
1.8497, -1.78E-8,
|
||||
286.5016, 2.9296100E-5,
|
||||
1.5236880, 0.000000,
|
||||
0.093405, 2.516E-9,
|
||||
18.60210, 0.52402077660)
|
||||
{
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Mars::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Mars::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Mars, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Mars specific equation
|
||||
*************************************************************************/
|
||||
void Mars::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Mars::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
|
||||
}
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _MARS_HXX_
|
||||
#define _MARS_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Mars : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Mars ( FGTime *t);
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
Mars ( double mjd );
|
||||
Mars ();
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _MARS_HXX_
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -30,31 +31,40 @@
|
||||
#include "mercury.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Mercury::Mercury(FGTime *t)
|
||||
* Mercury::Mercury(double mjd)
|
||||
* Public constructor for class Mercury
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Mercury are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Mercury::Mercury(FGTime *t) :
|
||||
Mercury::Mercury(double mjd) :
|
||||
CelestialBody (48.33130, 3.2458700E-5,
|
||||
7.0047, 5.00E-8,
|
||||
29.12410, 1.0144400E-5,
|
||||
0.3870980, 0.000000,
|
||||
0.205635, 5.59E-10,
|
||||
168.6562, 4.09233443680, t)
|
||||
168.6562, 4.09233443680, mjd)
|
||||
{
|
||||
}
|
||||
Mercury::Mercury() :
|
||||
CelestialBody (48.33130, 3.2458700E-5,
|
||||
7.0047, 5.00E-8,
|
||||
29.12410, 1.0144400E-5,
|
||||
0.3870980, 0.000000,
|
||||
0.205635, 5.59E-10,
|
||||
168.6562, 4.09233443680)
|
||||
{
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Mercury::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Mercury::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Mercury, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Mercury specific equation
|
||||
*************************************************************************/
|
||||
void Mercury::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Mercury::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _MERCURY_HXX_
|
||||
#define _MERCURY_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Mercury : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Mercury ( FGTime *t);
|
||||
void updatePosition(FGTime *t, Star* ourSun);
|
||||
Mercury (double mjd);
|
||||
Mercury ();
|
||||
void updatePosition(double mjd, Star* ourSun);
|
||||
};
|
||||
|
||||
#endif // _MERURY_HXX_
|
||||
|
||||
@@ -1,401 +0,0 @@
|
||||
/**************************************************************************
|
||||
* moon.cxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Main/options.hxx>
|
||||
#include <Misc/fgpath.hxx>
|
||||
#include <Objects/texload.h>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include <FDM/flight.hxx>
|
||||
|
||||
#include "moon.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Moon::Moon(FGTime *t)
|
||||
* Public constructor for class Moon. Initializes the orbital elements and
|
||||
* sets up the moon texture.
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Moon are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Moon::Moon(FGTime *t) :
|
||||
CelestialBody(125.1228, -0.0529538083,
|
||||
5.1454, 0.00000,
|
||||
318.0634, 0.1643573223,
|
||||
60.266600, 0.000000,
|
||||
0.054900, 0.000000,
|
||||
115.3654, 13.0649929509, t)
|
||||
{
|
||||
int width, height;
|
||||
|
||||
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
|
||||
#ifdef GL_VERSION_1_1
|
||||
xglGenTextures(1, &moon_texid);
|
||||
xglBindTexture(GL_TEXTURE_2D, moon_texid);
|
||||
#elif GL_EXT_texture_object
|
||||
xglGenTexturesEXT(1, &moon_texid);
|
||||
xglBindTextureEXT(GL_TEXTURE_2D, moon_texid);
|
||||
#else
|
||||
# error port me
|
||||
#endif
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// load in the texture data
|
||||
FGPath tpath( current_options.get_fg_root() );
|
||||
tpath.append( "Textures" );
|
||||
tpath.append( "moon.rgb" );
|
||||
|
||||
if ( (moon_texbuf = read_rgb_texture(tpath.c_str(), &width, &height))
|
||||
== NULL )
|
||||
{
|
||||
// Try compressed
|
||||
FGPath fg_tpath = tpath;
|
||||
fg_tpath.append( ".gz" );
|
||||
if ( (moon_texbuf = read_rgb_texture(fg_tpath.c_str(), &width, &height))
|
||||
== NULL )
|
||||
{
|
||||
FG_LOG( FG_GENERAL, FG_ALERT,
|
||||
"Error in loading moon texture " << tpath.str() );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
glTexImage2D( GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGB,
|
||||
256, 256,
|
||||
0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE,
|
||||
moon_texbuf);
|
||||
|
||||
// setup the halo texture
|
||||
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
|
||||
#ifdef GL_VERSION_1_1
|
||||
xglGenTextures(1, &moon_halotexid);
|
||||
xglBindTexture(GL_TEXTURE_2D, moon_halotexid);
|
||||
#elif GL_EXT_texture_object
|
||||
xglGenTexturesEXT(1, &moon_halotexid);
|
||||
xglBindTextureEXT(GL_TEXTURE_2D, moon_halotexid);
|
||||
#else
|
||||
# error port me
|
||||
#endif
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
setHalo();
|
||||
glTexImage2D( GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
256, 256,
|
||||
0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
moon_halotexbuf);
|
||||
moonObject = gluNewQuadric();
|
||||
}
|
||||
|
||||
Moon::~Moon()
|
||||
{
|
||||
//delete moonObject;
|
||||
delete moon_texbuf;
|
||||
delete moon_halotexbuf;
|
||||
}
|
||||
|
||||
|
||||
static int texWidth = 256; /* 64x64 is plenty */
|
||||
|
||||
void Moon::setHalo()
|
||||
{
|
||||
int texSize;
|
||||
//void *textureBuf;
|
||||
GLubyte *p;
|
||||
int i,j;
|
||||
double radius;
|
||||
|
||||
texSize = texWidth*texWidth;
|
||||
|
||||
moon_halotexbuf = new GLubyte[texSize*4];
|
||||
if (!moon_halotexbuf)
|
||||
return; // Ugly!
|
||||
|
||||
p = moon_halotexbuf;
|
||||
|
||||
radius = (double)(texWidth / 2);
|
||||
|
||||
for (i=0; i < texWidth; i++) {
|
||||
for (j=0; j < texWidth; j++) {
|
||||
double x, y, d;
|
||||
|
||||
x = fabs((double)(i - (texWidth / 2)));
|
||||
y = fabs((double)(j - (texWidth / 2)));
|
||||
|
||||
d = sqrt((x * x) + (y * y));
|
||||
if (d < radius)
|
||||
{
|
||||
double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
|
||||
// inverse square looks nice
|
||||
*p = (int)((double)0xff * (t * t));
|
||||
*(p+1) = (int)((double) 0xff * (t*t));
|
||||
*(p+2) = (int)((double) 0xff * (t*t));
|
||||
*(p+3) = 0x11;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p = 0x00;
|
||||
*(p+1) = 0x00;
|
||||
*(p+2) = 0x00;
|
||||
*(p+3) = 0x11;
|
||||
}
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
|
||||
// GL_LUMINANCE,
|
||||
// GL_UNSIGNED_BYTE, textureBuf);
|
||||
//free(textureBuf);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* void Moon::updatePosition(FGTime *t, Star *ourSun)
|
||||
* this member function calculates the actual topocentric position (i.e.)
|
||||
* the position of the moon as seen from the current position on the surface
|
||||
* of the moon.
|
||||
****************************************************************************/
|
||||
void Moon::updatePosition(FGTime *t, Star *ourSun)
|
||||
{
|
||||
double
|
||||
eccAnom, ecl, actTime,
|
||||
xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
|
||||
Ls, Lm, D, F, mpar, gclat, rho, HA, g,
|
||||
geoRa, geoDec;
|
||||
|
||||
fgAIRCRAFT *air;
|
||||
FGInterface *f;
|
||||
|
||||
air = ¤t_aircraft;
|
||||
f = air->fdm_state;
|
||||
|
||||
updateOrbElements(t);
|
||||
actTime = fgCalcActTime(t);
|
||||
|
||||
// calculate the angle between ecliptic and equatorial coordinate system
|
||||
// in Radians
|
||||
ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 3.563E-7) * actTime);
|
||||
eccAnom = fgCalcEccAnom(M, e); // Calculate the eccentric anomaly
|
||||
xv = a * (cos(eccAnom) - e);
|
||||
yv = a * (sqrt(1.0 - e*e) * sin(eccAnom));
|
||||
v = atan2(yv, xv); // the moon's true anomaly
|
||||
r = sqrt (xv*xv + yv*yv); // and its distance
|
||||
|
||||
// estimate the geocentric rectangular coordinates here
|
||||
xh = r * (cos(N) * cos (v+w) - sin (N) * sin(v+w) * cos(i));
|
||||
yh = r * (sin(N) * cos (v+w) + cos (N) * sin(v+w) * cos(i));
|
||||
zh = r * (sin(v+w) * sin(i));
|
||||
|
||||
// calculate the ecliptic latitude and longitude here
|
||||
lonEcl = atan2 (yh, xh);
|
||||
latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
|
||||
|
||||
/* Calculate a number of perturbatioin, i.e. disturbances caused by the
|
||||
* gravitational infuence of the sun and the other major planets.
|
||||
* The largest of these even have a name */
|
||||
Ls = ourSun->getM() + ourSun->getw();
|
||||
Lm = M + w + N;
|
||||
D = Lm - Ls;
|
||||
F = Lm - N;
|
||||
|
||||
lonEcl += DEG_TO_RAD * (-1.274 * sin (M - 2*D)
|
||||
+0.658 * sin (2*D)
|
||||
-0.186 * sin(ourSun->getM())
|
||||
-0.059 * sin(2*M - 2*D)
|
||||
-0.057 * sin(M - 2*D + ourSun->getM())
|
||||
+0.053 * sin(M + 2*D)
|
||||
+0.046 * sin(2*D - ourSun->getM())
|
||||
+0.041 * sin(M - ourSun->getM())
|
||||
-0.035 * sin(D)
|
||||
-0.031 * sin(M + ourSun->getM())
|
||||
-0.015 * sin(2*F - 2*D)
|
||||
+0.011 * sin(M - 4*D)
|
||||
);
|
||||
latEcl += DEG_TO_RAD * (-0.173 * sin(F-2*D)
|
||||
-0.055 * sin(M - F - 2*D)
|
||||
-0.046 * sin(M + F - 2*D)
|
||||
+0.033 * sin(F + 2*D)
|
||||
+0.017 * sin(2*M + F)
|
||||
);
|
||||
r += (-0.58 * cos(M - 2*D)
|
||||
-0.46 * cos(2*D)
|
||||
);
|
||||
FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
|
||||
xg = r * cos(lonEcl) * cos(latEcl);
|
||||
yg = r * sin(lonEcl) * cos(latEcl);
|
||||
zg = r * sin(latEcl);
|
||||
|
||||
xe = xg;
|
||||
ye = yg * cos(ecl) -zg * sin(ecl);
|
||||
ze = yg * sin(ecl) +zg * cos(ecl);
|
||||
|
||||
geoRa = atan2(ye, xe);
|
||||
geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
|
||||
|
||||
/* FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"(geocentric) geoRa = (" << (RAD_TO_DEG * geoRa)
|
||||
<< "), geoDec= (" << (RAD_TO_DEG * geoDec) << ")" ); */
|
||||
|
||||
|
||||
// Given the moon's geocentric ra and dec, calculate its
|
||||
// topocentric ra and dec. i.e. the position as seen from the
|
||||
// surface of the earth, instead of the center of the earth
|
||||
|
||||
// First calculate the moon's parrallax, that is, the apparent size of the
|
||||
// (equatorial) radius of the earth, as seen from the moon
|
||||
mpar = asin ( 1 / r);
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "r = " << r << " mpar = " << mpar );
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "lat = " << f->get_Latitude() );
|
||||
|
||||
gclat = f->get_Latitude() - 0.003358 *
|
||||
sin (2 * DEG_TO_RAD * f->get_Latitude() );
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "gclat = " << gclat );
|
||||
|
||||
rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * f->get_Latitude());
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "rho = " << rho );
|
||||
|
||||
if (geoRa < 0)
|
||||
geoRa += (2*FG_PI);
|
||||
|
||||
HA = t->getLst() - (3.8197186 * geoRa);
|
||||
/* FG_LOG( FG_GENERAL, FG_INFO, "t->getLst() = " << t->getLst()
|
||||
<< " HA = " << HA ); */
|
||||
|
||||
g = atan (tan(gclat) / cos ((HA / 3.8197186)));
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "g = " << g );
|
||||
|
||||
rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
|
||||
declination = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
|
||||
|
||||
/* FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"Ra = (" << (RAD_TO_DEG *rightAscension)
|
||||
<< "), Dec= (" << (RAD_TO_DEG *declination) << ")" ); */
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* void Moon::newImage()
|
||||
*
|
||||
* This function regenerates a new visual image of the moon, which is added to
|
||||
* solarSystem display list.
|
||||
*
|
||||
* Arguments: Right Ascension and declination
|
||||
*
|
||||
* return value: none
|
||||
**************************************************************************/
|
||||
void Moon::newImage()
|
||||
{
|
||||
fgLIGHT *l = &cur_light_params;
|
||||
float moon_angle = l->moon_angle;
|
||||
|
||||
/*double x_2, x_4, x_8, x_10;
|
||||
GLfloat ambient;
|
||||
GLfloat amb[4];*/
|
||||
int moonSize = 550;
|
||||
|
||||
GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
|
||||
GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
|
||||
GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};
|
||||
|
||||
if( moon_angle*RAD_TO_DEG < 100 )
|
||||
{
|
||||
FG_LOG( FG_ASTRO, FG_INFO, "Generating Moon Image" );
|
||||
|
||||
xglPushMatrix();
|
||||
{
|
||||
xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
|
||||
xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
|
||||
|
||||
FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"Ra = (" << (RAD_TO_DEG *rightAscension)
|
||||
<< "), Dec= (" << (RAD_TO_DEG *declination) << ")" );
|
||||
xglTranslatef(0.0, 60000.0, 0.0);
|
||||
glEnable(GL_BLEND); // BLEND ENABLED
|
||||
|
||||
// Draw the halo...
|
||||
if (current_options.get_textures())
|
||||
{
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBindTexture(GL_TEXTURE_2D, moon_halotexid);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
xglEnable(GL_LIGHTING); // LIGHTING ENABLED
|
||||
xglEnable( GL_LIGHT0 );
|
||||
// set lighting parameters
|
||||
xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
|
||||
xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
|
||||
// Enable( GL_CULL_FACE );
|
||||
xglMaterialfv(GL_FRONT, GL_AMBIENT, black);
|
||||
xglMaterialfv(GL_FRONT, GL_DIFFUSE, moonColor);
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
// Draw the moon-proper
|
||||
|
||||
if (current_options.get_textures())
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, moon_texid);
|
||||
gluQuadricTexture(moonObject, GL_TRUE );
|
||||
}
|
||||
gluSphere(moonObject, moonSize, 12, 12 );
|
||||
glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
|
||||
glDisable(GL_BLEND); // BLEND DISABLED
|
||||
}
|
||||
xglPopMatrix();
|
||||
glDisable(GL_LIGHTING); // Lighting Disabled.
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/**************************************************************************
|
||||
* moon.hxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _MOON_HXX_
|
||||
#define _MOON_HXX_
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Main/views.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Moon : public CelestialBody
|
||||
{
|
||||
private:
|
||||
void TexInit(); // This should move to the constructor eventually.
|
||||
|
||||
GLUquadricObj *moonObject;
|
||||
GLuint Sphere;
|
||||
GLuint moon_texid;
|
||||
GLuint moon_halotexid;
|
||||
GLubyte *moon_texbuf;
|
||||
GLubyte *moon_halotexbuf;
|
||||
|
||||
void setHalo();
|
||||
public:
|
||||
Moon ( FGTime *t);
|
||||
~Moon();
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
void newImage();
|
||||
};
|
||||
|
||||
|
||||
#endif // _MOON_HXX_
|
||||
191
simgear/ephemeris/moonpos.cxx
Normal file
191
simgear/ephemeris/moonpos.cxx
Normal file
@@ -0,0 +1,191 @@
|
||||
/**************************************************************************
|
||||
* moonpos.cxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/fgpath.hxx>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
// #include <FDM/flight.hxx>
|
||||
|
||||
#include "moonpos.hxx"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* MoonPos::MoonPos(double mjd)
|
||||
* Public constructor for class MoonPos. Initializes the orbital elements and
|
||||
* sets up the moon texture.
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for MoonPos are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
MoonPos::MoonPos(double mjd) :
|
||||
CelestialBody(125.1228, -0.0529538083,
|
||||
5.1454, 0.00000,
|
||||
318.0634, 0.1643573223,
|
||||
60.266600, 0.000000,
|
||||
0.054900, 0.000000,
|
||||
115.3654, 13.0649929509, mjd)
|
||||
{
|
||||
}
|
||||
|
||||
MoonPos::MoonPos() :
|
||||
CelestialBody(125.1228, -0.0529538083,
|
||||
5.1454, 0.00000,
|
||||
318.0634, 0.1643573223,
|
||||
60.266600, 0.000000,
|
||||
0.054900, 0.000000,
|
||||
115.3654, 13.0649929509)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MoonPos::~MoonPos()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* void MoonPos::updatePosition(double mjd, Star *ourSun)
|
||||
* this member function calculates the actual topocentric position (i.e.)
|
||||
* the position of the moon as seen from the current position on the surface
|
||||
* of the moon.
|
||||
****************************************************************************/
|
||||
void MoonPos::updatePosition(double mjd, double lst, double lat, Star *ourSun)
|
||||
{
|
||||
double
|
||||
eccAnom, ecl, actTime,
|
||||
xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
|
||||
Ls, Lm, D, F, mpar, gclat, rho, HA, g,
|
||||
geoRa, geoDec;
|
||||
|
||||
updateOrbElements(mjd);
|
||||
actTime = sgCalcActTime(mjd);
|
||||
|
||||
// calculate the angle between ecliptic and equatorial coordinate system
|
||||
// in Radians
|
||||
ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 3.563E-7) * actTime);
|
||||
eccAnom = sgCalcEccAnom(M, e); // Calculate the eccentric anomaly
|
||||
xv = a * (cos(eccAnom) - e);
|
||||
yv = a * (sqrt(1.0 - e*e) * sin(eccAnom));
|
||||
v = atan2(yv, xv); // the moon's true anomaly
|
||||
r = sqrt (xv*xv + yv*yv); // and its distance
|
||||
|
||||
// estimate the geocentric rectangular coordinates here
|
||||
xh = r * (cos(N) * cos (v+w) - sin (N) * sin(v+w) * cos(i));
|
||||
yh = r * (sin(N) * cos (v+w) + cos (N) * sin(v+w) * cos(i));
|
||||
zh = r * (sin(v+w) * sin(i));
|
||||
|
||||
// calculate the ecliptic latitude and longitude here
|
||||
lonEcl = atan2 (yh, xh);
|
||||
latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
|
||||
|
||||
/* Calculate a number of perturbatioin, i.e. disturbances caused by the
|
||||
* gravitational infuence of the sun and the other major planets.
|
||||
* The largest of these even have a name */
|
||||
Ls = ourSun->getM() + ourSun->getw();
|
||||
Lm = M + w + N;
|
||||
D = Lm - Ls;
|
||||
F = Lm - N;
|
||||
|
||||
lonEcl += DEG_TO_RAD * (-1.274 * sin (M - 2*D)
|
||||
+0.658 * sin (2*D)
|
||||
-0.186 * sin(ourSun->getM())
|
||||
-0.059 * sin(2*M - 2*D)
|
||||
-0.057 * sin(M - 2*D + ourSun->getM())
|
||||
+0.053 * sin(M + 2*D)
|
||||
+0.046 * sin(2*D - ourSun->getM())
|
||||
+0.041 * sin(M - ourSun->getM())
|
||||
-0.035 * sin(D)
|
||||
-0.031 * sin(M + ourSun->getM())
|
||||
-0.015 * sin(2*F - 2*D)
|
||||
+0.011 * sin(M - 4*D)
|
||||
);
|
||||
latEcl += DEG_TO_RAD * (-0.173 * sin(F-2*D)
|
||||
-0.055 * sin(M - F - 2*D)
|
||||
-0.046 * sin(M + F - 2*D)
|
||||
+0.033 * sin(F + 2*D)
|
||||
+0.017 * sin(2*M + F)
|
||||
);
|
||||
r += (-0.58 * cos(M - 2*D)
|
||||
-0.46 * cos(2*D)
|
||||
);
|
||||
// FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
|
||||
xg = r * cos(lonEcl) * cos(latEcl);
|
||||
yg = r * sin(lonEcl) * cos(latEcl);
|
||||
zg = r * sin(latEcl);
|
||||
|
||||
xe = xg;
|
||||
ye = yg * cos(ecl) -zg * sin(ecl);
|
||||
ze = yg * sin(ecl) +zg * cos(ecl);
|
||||
|
||||
geoRa = atan2(ye, xe);
|
||||
geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
|
||||
|
||||
/* FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"(geocentric) geoRa = (" << (RAD_TO_DEG * geoRa)
|
||||
<< "), geoDec= (" << (RAD_TO_DEG * geoDec) << ")" ); */
|
||||
|
||||
|
||||
// Given the moon's geocentric ra and dec, calculate its
|
||||
// topocentric ra and dec. i.e. the position as seen from the
|
||||
// surface of the earth, instead of the center of the earth
|
||||
|
||||
// First calculate the moon's parrallax, that is, the apparent size of the
|
||||
// (equatorial) radius of the earth, as seen from the moon
|
||||
mpar = asin ( 1 / r);
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "r = " << r << " mpar = " << mpar );
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "lat = " << f->get_Latitude() );
|
||||
|
||||
gclat = lat - 0.003358 *
|
||||
sin (2 * DEG_TO_RAD * lat );
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "gclat = " << gclat );
|
||||
|
||||
rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * lat);
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "rho = " << rho );
|
||||
|
||||
if (geoRa < 0)
|
||||
geoRa += (2*FG_PI);
|
||||
|
||||
HA = lst - (3.8197186 * geoRa);
|
||||
/* FG_LOG( FG_GENERAL, FG_INFO, "t->getLst() = " << t->getLst()
|
||||
<< " HA = " << HA ); */
|
||||
|
||||
g = atan (tan(gclat) / cos ((HA / 3.8197186)));
|
||||
// FG_LOG( FG_GENERAL, FG_INFO, "g = " << g );
|
||||
|
||||
rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
|
||||
declination = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
|
||||
|
||||
/* FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"Ra = (" << (RAD_TO_DEG *rightAscension)
|
||||
<< "), Dec= (" << (RAD_TO_DEG *declination) << ")" ); */
|
||||
}
|
||||
61
simgear/ephemeris/moonpos.hxx
Normal file
61
simgear/ephemeris/moonpos.hxx
Normal file
@@ -0,0 +1,61 @@
|
||||
/**************************************************************************
|
||||
* moonpos.hxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _MOONPOS_HXX_
|
||||
#define _MOONPOS_HXX_
|
||||
|
||||
|
||||
#include <simgear/constants.h>
|
||||
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
|
||||
class MoonPos : public CelestialBody
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
// void TexInit(); // This should move to the constructor eventually.
|
||||
|
||||
// GLUquadricObj *moonObject;
|
||||
// GLuint Sphere;
|
||||
// GLuint moon_texid;
|
||||
// GLuint moon_halotexid;
|
||||
// GLubyte *moon_texbuf;
|
||||
// GLubyte *moon_halotexbuf;
|
||||
|
||||
// void setHalo();
|
||||
|
||||
public:
|
||||
|
||||
MoonPos(double mjd);
|
||||
MoonPos();
|
||||
~MoonPos();
|
||||
void updatePosition(double mjd, double lst, double lat, Star *ourSun);
|
||||
// void newImage();
|
||||
};
|
||||
|
||||
|
||||
#endif // _MOONPOS_HXX_
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -30,30 +31,39 @@
|
||||
#include "neptune.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Neptune::Neptune(FGTime *t)
|
||||
* Neptune::Neptune(double mjd)
|
||||
* Public constructor for class Neptune
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Neptune are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Neptune::Neptune(FGTime *t) :
|
||||
Neptune::Neptune(double mjd) :
|
||||
CelestialBody(131.7806, 3.0173000E-5,
|
||||
1.7700, -2.550E-7,
|
||||
272.8461, -6.027000E-6,
|
||||
30.058260, 3.313E-8,
|
||||
0.008606, 2.150E-9,
|
||||
260.2471, 0.00599514700, t)
|
||||
260.2471, 0.00599514700, mjd)
|
||||
{
|
||||
}
|
||||
Neptune::Neptune() :
|
||||
CelestialBody(131.7806, 3.0173000E-5,
|
||||
1.7700, -2.550E-7,
|
||||
272.8461, -6.027000E-6,
|
||||
30.058260, 3.313E-8,
|
||||
0.008606, 2.150E-9,
|
||||
260.2471, 0.00599514700)
|
||||
{
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Neptune::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Neptune::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Neptune, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Neptune specific equation
|
||||
*************************************************************************/
|
||||
void Neptune::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Neptune::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
|
||||
}
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _NEPTUNE_HXX_
|
||||
#define _NEPTUNE_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Neptune : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Neptune ( FGTime *t);
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
Neptune (double mjd);
|
||||
Neptune ();
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _NEPTUNE_HXX_
|
||||
|
||||
@@ -5,32 +5,33 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _PLUTO_HXX_
|
||||
#define _PLUTO_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
|
||||
class Pluto : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Pluto ( FGTime t);
|
||||
Pluto (double mjd);
|
||||
Pluto ();
|
||||
};
|
||||
|
||||
#endif // _PLUTO_HXX_
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -30,34 +31,43 @@
|
||||
#include "saturn.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Saturn::Saturn(FGTime *t)
|
||||
* Saturn::Saturn(double mjd)
|
||||
* Public constructor for class Saturn
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Saturn are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Saturn::Saturn(FGTime *t) :
|
||||
Saturn::Saturn(double mjd) :
|
||||
CelestialBody(113.6634, 2.3898000E-5,
|
||||
2.4886, -1.081E-7,
|
||||
339.3939, 2.9766100E-5,
|
||||
9.5547500, 0.000000,
|
||||
0.055546, -9.499E-9,
|
||||
316.9670, 0.03344422820, t)
|
||||
316.9670, 0.03344422820, mjd)
|
||||
{
|
||||
}
|
||||
Saturn::Saturn() :
|
||||
CelestialBody(113.6634, 2.3898000E-5,
|
||||
2.4886, -1.081E-7,
|
||||
339.3939, 2.9766100E-5,
|
||||
9.5547500, 0.000000,
|
||||
0.055546, -9.499E-9,
|
||||
316.9670, 0.03344422820)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Saturn::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Saturn::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Saturn, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Saturn specific equation
|
||||
*************************************************************************/
|
||||
void Saturn::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Saturn::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
|
||||
double actTime = fgCalcActTime(t);
|
||||
double actTime = sgCalcActTime(mjd);
|
||||
double ir = 0.4897394;
|
||||
double Nr = 2.9585076 + 6.6672E-7*actTime;
|
||||
double B = asin (sin(declination) * cos(ir) -
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _SATURN_HXX_
|
||||
#define _SATURN_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Saturn : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Saturn ( FGTime *t);
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
Saturn (double mjd);
|
||||
Saturn ();
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _SATURN_HXX_
|
||||
|
||||
@@ -1,367 +0,0 @@
|
||||
// sky.cxx -- model sky with an upside down "bowl"
|
||||
//
|
||||
// Written by Curtis Olson, started December 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Main/views.hxx>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Time/event.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#include "sky.hxx"
|
||||
|
||||
|
||||
#ifdef __MWERKS__
|
||||
# pragma global_optimizer off
|
||||
#endif
|
||||
|
||||
|
||||
// in meters of course
|
||||
#define CENTER_ELEV 25000.0
|
||||
|
||||
#define INNER_RADIUS 50000.0
|
||||
#define INNER_ELEV 20000.0
|
||||
|
||||
#define MIDDLE_RADIUS 70000.0
|
||||
#define MIDDLE_ELEV 8000.0
|
||||
|
||||
#define OUTER_RADIUS 80000.0
|
||||
#define OUTER_ELEV 0.0
|
||||
|
||||
#define BOTTOM_RADIUS 50000.0
|
||||
#define BOTTOM_ELEV -2000.0
|
||||
|
||||
|
||||
static float inner_vertex[12][3];
|
||||
static float middle_vertex[12][3];
|
||||
static float outer_vertex[12][3];
|
||||
static float bottom_vertex[12][3];
|
||||
|
||||
static float inner_color[12][4];
|
||||
static float middle_color[12][4];
|
||||
static float outer_color[12][4];
|
||||
|
||||
|
||||
// Calculate the sky structure vertices
|
||||
void fgSkyVerticesInit( void ) {
|
||||
float theta;
|
||||
int i;
|
||||
|
||||
FG_LOG(FG_ASTRO, FG_INFO, " Generating the sky dome vertices.");
|
||||
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
theta = (i * 30.0) * DEG_TO_RAD;
|
||||
|
||||
inner_vertex[i][0] = cos(theta) * INNER_RADIUS;
|
||||
inner_vertex[i][1] = sin(theta) * INNER_RADIUS;
|
||||
inner_vertex[i][2] = INNER_ELEV;
|
||||
|
||||
// printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS,
|
||||
// sin(theta) * INNER_RADIUS);
|
||||
|
||||
middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
|
||||
middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
|
||||
middle_vertex[i][2] = MIDDLE_ELEV;
|
||||
|
||||
outer_vertex[i][0] = cos((double)theta) * OUTER_RADIUS;
|
||||
outer_vertex[i][1] = sin((double)theta) * OUTER_RADIUS;
|
||||
outer_vertex[i][2] = OUTER_ELEV;
|
||||
|
||||
bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
|
||||
bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
|
||||
bottom_vertex[i][2] = BOTTOM_ELEV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// (Re)calculate the sky colors at each vertex
|
||||
void fgSkyColorsInit( void ) {
|
||||
fgLIGHT *l;
|
||||
double sun_angle, diff;
|
||||
double outer_param[3], outer_amt[3], outer_diff[3];
|
||||
double middle_param[3], middle_amt[3], middle_diff[3];
|
||||
int i, j;
|
||||
|
||||
l = &cur_light_params;
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO,
|
||||
" Generating the sky colors for each vertex." );
|
||||
|
||||
// setup for the possibility of sunset effects
|
||||
sun_angle = l->sun_angle * RAD_TO_DEG;
|
||||
// fgPrintf( FG_ASTRO, FG_INFO,
|
||||
// " Sun angle in degrees = %.2f\n", sun_angle);
|
||||
|
||||
if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
|
||||
// 0.0 - 0.4
|
||||
outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
|
||||
outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
|
||||
outer_param[2] = -(10.0 - fabs(90.0 - sun_angle)) / 30.0;
|
||||
// outer_param[2] = 0.0;
|
||||
|
||||
middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
|
||||
middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 80.0;
|
||||
middle_param[2] = 0.0;
|
||||
|
||||
outer_diff[0] = outer_param[0] / 6.0;
|
||||
outer_diff[1] = outer_param[1] / 6.0;
|
||||
outer_diff[2] = outer_param[2] / 6.0;
|
||||
|
||||
middle_diff[0] = middle_param[0] / 6.0;
|
||||
middle_diff[1] = middle_param[1] / 6.0;
|
||||
middle_diff[2] = middle_param[2] / 6.0;
|
||||
} else {
|
||||
outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
|
||||
middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
|
||||
|
||||
outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
|
||||
middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
|
||||
}
|
||||
// printf(" outer_red_param = %.2f outer_red_diff = %.2f\n",
|
||||
// outer_red_param, outer_red_diff);
|
||||
|
||||
// calculate transition colors between sky and fog
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] = outer_param[j];
|
||||
middle_amt[j] = middle_param[j];
|
||||
}
|
||||
|
||||
for ( i = 0; i < 6; i++ ) {
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
diff = l->sky_color[j] - l->fog_color[j];
|
||||
|
||||
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
|
||||
// l->sky_color[j], l->fog_color[j], diff);
|
||||
|
||||
inner_color[i][j] = l->sky_color[j] - diff * 0.3;
|
||||
middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
|
||||
outer_color[i][j] = l->fog_color[j] + outer_amt[j];
|
||||
|
||||
if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
|
||||
if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
|
||||
if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
|
||||
if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
|
||||
if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
|
||||
if ( outer_color[i][j] < 0.10 ) { outer_color[i][j] = 0.10; }
|
||||
}
|
||||
inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
|
||||
l->sky_color[3];
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] -= outer_diff[j];
|
||||
middle_amt[j] -= middle_diff[j];
|
||||
}
|
||||
|
||||
/*
|
||||
printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
|
||||
inner_color[i][1], inner_color[i][2], inner_color[i][3]);
|
||||
printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
middle_color[i][0], middle_color[i][1], middle_color[i][2],
|
||||
middle_color[i][3]);
|
||||
printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
outer_color[i][0], outer_color[i][1], outer_color[i][2],
|
||||
outer_color[i][3]);
|
||||
*/
|
||||
}
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] = 0.0;
|
||||
middle_amt[j] = 0.0;
|
||||
}
|
||||
|
||||
for ( i = 6; i < 12; i++ ) {
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
diff = l->sky_color[j] - l->fog_color[j];
|
||||
|
||||
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
|
||||
// l->sky_color[j], l->fog_color[j], diff);
|
||||
|
||||
inner_color[i][j] = l->sky_color[j] - diff * 0.3;
|
||||
middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
|
||||
outer_color[i][j] = l->fog_color[j] + outer_amt[j];
|
||||
|
||||
if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
|
||||
if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
|
||||
if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
|
||||
if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
|
||||
if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
|
||||
if ( outer_color[i][j] < 0.15 ) { outer_color[i][j] = 0.15; }
|
||||
}
|
||||
inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
|
||||
l->sky_color[3];
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] += outer_diff[j];
|
||||
middle_amt[j] += middle_diff[j];
|
||||
}
|
||||
|
||||
/*
|
||||
printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
|
||||
inner_color[i][1], inner_color[i][2], inner_color[i][3]);
|
||||
printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
middle_color[i][0], middle_color[i][1], middle_color[i][2],
|
||||
middle_color[i][3]);
|
||||
printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
outer_color[i][0], outer_color[i][1], outer_color[i][2],
|
||||
outer_color[i][3]);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialize the sky structure and colors
|
||||
void fgSkyInit( void ) {
|
||||
FG_LOG( FG_ASTRO, FG_INFO, "Initializing the sky" );
|
||||
|
||||
fgSkyVerticesInit();
|
||||
|
||||
// regester fgSkyColorsInit() as an event to be run periodically
|
||||
global_events.Register( "fgSkyColorsInit()", fgSkyColorsInit,
|
||||
fgEVENT::FG_EVENT_READY, 30000);
|
||||
}
|
||||
|
||||
|
||||
// Draw the Sky
|
||||
void fgSkyRender( void ) {
|
||||
FGInterface *f;
|
||||
fgLIGHT *l;
|
||||
float inner_color[4];
|
||||
float middle_color[4];
|
||||
float outer_color[4];
|
||||
double diff;
|
||||
int i;
|
||||
|
||||
f = current_aircraft.fdm_state;
|
||||
l = &cur_light_params;
|
||||
|
||||
// printf("Rendering the sky.\n");
|
||||
|
||||
// calculate the proper colors
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
diff = l->sky_color[i] - l->adj_fog_color[i];
|
||||
|
||||
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
|
||||
// l->sky_color[j], l->adj_fog_color[j], diff);
|
||||
|
||||
inner_color[i] = l->sky_color[i] - diff * 0.3;
|
||||
middle_color[i] = l->sky_color[i] - diff * 0.9;
|
||||
outer_color[i] = l->adj_fog_color[i];
|
||||
}
|
||||
inner_color[3] = middle_color[3] = outer_color[3] = l->adj_fog_color[3];
|
||||
|
||||
xglPushMatrix();
|
||||
|
||||
// Translate to view position
|
||||
Point3D zero_elev = current_view.get_cur_zero_elev();
|
||||
xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
|
||||
// printf(" Translated to %.2f %.2f %.2f\n",
|
||||
// zero_elev.x, zero_elev.y, zero_elev.z );
|
||||
|
||||
// Rotate to proper orientation
|
||||
// printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
|
||||
// FG_Latitude * RAD_TO_DEG);
|
||||
xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 );
|
||||
xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
|
||||
xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 );
|
||||
|
||||
// Draw inner/center section of sky*/
|
||||
xglBegin( GL_TRIANGLE_FAN );
|
||||
xglColor4fv(l->sky_color);
|
||||
xglVertex3f(0.0, 0.0, CENTER_ELEV);
|
||||
for ( i = 11; i >= 0; i-- ) {
|
||||
xglColor4fv( inner_color );
|
||||
xglVertex3fv( inner_vertex[i] );
|
||||
}
|
||||
xglColor4fv( inner_color );
|
||||
xglVertex3fv( inner_vertex[11] );
|
||||
xglEnd();
|
||||
|
||||
// Draw the middle ring
|
||||
xglBegin( GL_TRIANGLE_STRIP );
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
xglColor4fv( middle_color );
|
||||
// printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
// middle_color[i][0], middle_color[i][1], middle_color[i][2],
|
||||
// middle_color[i][3]);
|
||||
// xglColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
xglVertex3fv( middle_vertex[i] );
|
||||
xglColor4fv( inner_color );
|
||||
// printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
// inner_color[i][0], inner_color[i][1], inner_color[i][2],
|
||||
// inner_color[i][3]);
|
||||
// xglColor4f(0.0, 0.0, 1.0, 1.0);
|
||||
xglVertex3fv( inner_vertex[i] );
|
||||
}
|
||||
xglColor4fv( middle_color );
|
||||
// xglColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
xglVertex3fv( middle_vertex[0] );
|
||||
xglColor4fv( inner_color );
|
||||
// xglColor4f(0.0, 0.0, 1.0, 1.0);
|
||||
xglVertex3fv( inner_vertex[0] );
|
||||
xglEnd();
|
||||
|
||||
// Draw the outer ring
|
||||
xglBegin( GL_TRIANGLE_STRIP );
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
xglColor4fv( outer_color );
|
||||
xglVertex3fv( outer_vertex[i] );
|
||||
xglColor4fv( middle_color );
|
||||
xglVertex3fv( middle_vertex[i] );
|
||||
}
|
||||
xglColor4fv( outer_color );
|
||||
xglVertex3fv( outer_vertex[0] );
|
||||
xglColor4fv( middle_color );
|
||||
xglVertex3fv( middle_vertex[0] );
|
||||
xglEnd();
|
||||
|
||||
// Draw the bottom skirt
|
||||
xglBegin( GL_TRIANGLE_STRIP );
|
||||
xglColor4fv( outer_color );
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
xglVertex3fv( bottom_vertex[i] );
|
||||
xglVertex3fv( outer_vertex[i] );
|
||||
}
|
||||
xglVertex3fv( bottom_vertex[0] );
|
||||
xglVertex3fv( outer_vertex[0] );
|
||||
xglEnd();
|
||||
|
||||
xglPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
/**************************************************************************
|
||||
* solarsystem.cxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Time/sunpos.hxx>
|
||||
#include <Time/moonpos.hxx>
|
||||
#include "solarsystem.hxx"
|
||||
|
||||
/***************************************************************************
|
||||
* default constructor for class SolarSystem:
|
||||
* or course there can only be one way to create an entire solar system -:) )
|
||||
* the FGTime argument is needed to properly initialize the the current orbital
|
||||
* elements
|
||||
*************************************************************************/
|
||||
SolarSystem::SolarSystem(FGTime *t)
|
||||
{
|
||||
if (theSolarSystem)
|
||||
{
|
||||
FG_LOG( FG_GENERAL, FG_ALERT, "Error: only one solarsystem allowed" );
|
||||
exit(-1);
|
||||
}
|
||||
theSolarSystem = this;
|
||||
ourSun = new Star(t);
|
||||
earthsMoon = new Moon(t);
|
||||
mercury = new Mercury(t);
|
||||
venus = new Venus(t);
|
||||
mars = new Mars(t);
|
||||
jupiter = new Jupiter(t);
|
||||
saturn = new Saturn(t);
|
||||
uranus = new Uranus(t);
|
||||
neptune = new Neptune(t);
|
||||
|
||||
displayList = 0;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
* the destructor for class SolarSystem;
|
||||
**************************************************************************/
|
||||
SolarSystem::~SolarSystem()
|
||||
{
|
||||
delete ourSun;
|
||||
delete earthsMoon;
|
||||
delete mercury;
|
||||
delete venus;
|
||||
delete mars;
|
||||
delete jupiter;
|
||||
delete saturn;
|
||||
delete uranus;
|
||||
delete neptune;
|
||||
}
|
||||
/****************************************************************************
|
||||
* void SolarSystem::rebuild()
|
||||
*
|
||||
* this member function updates the positions for the sun, moon, and planets,
|
||||
* and then rebuilds the display list.
|
||||
*
|
||||
* arguments: none
|
||||
* return value: none
|
||||
***************************************************************************/
|
||||
void SolarSystem::rebuild()
|
||||
{
|
||||
//fgLIGHT *l = &cur_light_params;
|
||||
FGTime *t = FGTime::cur_time_params;
|
||||
//float x, y, z;
|
||||
//double sun_angle;
|
||||
double ra, dec;
|
||||
//double x_2, x_4, x_8, x_10;*/
|
||||
double magnitude;
|
||||
//GLfloat ambient;
|
||||
//GLfloat amb[4];
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Step 1: update all the positions
|
||||
ourSun->updatePosition(t);
|
||||
earthsMoon->updatePosition(t, ourSun);
|
||||
mercury->updatePosition(t, ourSun);
|
||||
venus->updatePosition(t, ourSun);
|
||||
mars->updatePosition(t, ourSun);
|
||||
jupiter->updatePosition(t, ourSun);
|
||||
saturn->updatePosition(t, ourSun);
|
||||
uranus->updatePosition(t, ourSun);
|
||||
neptune->updatePosition(t, ourSun);
|
||||
|
||||
fgUpdateSunPos(); // get the right sun angle (especially important when
|
||||
// running for the first time).
|
||||
fgUpdateMoonPos();
|
||||
|
||||
if (displayList)
|
||||
xglDeleteLists(displayList, 1);
|
||||
|
||||
displayList = xglGenLists(1);
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO, "Rebuilding astro display list" );
|
||||
|
||||
// Step 2: rebuild the display list
|
||||
xglNewList( displayList, GL_COMPILE);
|
||||
{
|
||||
// Step 2a: Add the moon...
|
||||
// Not that it is preferred to draw the moon first, and the sun next, in order to mime a
|
||||
// solar eclipse. This is yet untested though...
|
||||
// Euhh, actually the ecplise doesn't work...
|
||||
|
||||
earthsMoon->newImage();
|
||||
// Step 2b: Add the sun
|
||||
ourSun->newImage();
|
||||
// Step 2c: Add the planets
|
||||
xglBegin(GL_POINTS);
|
||||
mercury->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
venus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
mars ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
jupiter->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
saturn ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
uranus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
neptune->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
|
||||
xglEnd();
|
||||
xglEnable(GL_LIGHTING);
|
||||
}
|
||||
xglEndList();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* double SolarSystem::scaleMagnitude(double magn)
|
||||
* This private member function rescales the original magnitude, as used in the
|
||||
* astronomical sense of the word, into a value used by OpenGL to draw a
|
||||
* convincing Star or planet
|
||||
*
|
||||
* Argument: the astronomical magnitude
|
||||
*
|
||||
* return value: the rescaled magnitude
|
||||
****************************************************************************/
|
||||
double SolarSystem::scaleMagnitude(double magn)
|
||||
{
|
||||
double magnitude = (0.0 - magn) / 5.0 + 1.0;
|
||||
magnitude = magnitude * 0.7 + (3 * 0.1);
|
||||
if (magnitude > 1.0) magnitude = 1.0;
|
||||
if (magnitude < 0.0) magnitude = 0.0;
|
||||
return magnitude;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* void SolarSytem::addPlanetToList(double ra, double dec, double magn);
|
||||
*
|
||||
* This private member function first causes the magnitude to be properly
|
||||
* rescaled, and then adds the planet to the display list.
|
||||
*
|
||||
* arguments: Right Ascension, declination, and magnitude
|
||||
*
|
||||
* return value: none
|
||||
**************************************************************************/
|
||||
void SolarSystem::addPlanetToList(double ra, double dec, double magn)
|
||||
{
|
||||
double
|
||||
magnitude = scaleMagnitude ( magn );
|
||||
|
||||
fgLIGHT *l = &cur_light_params;
|
||||
|
||||
if ((double) (l->sun_angle - FG_PI_2) >
|
||||
((magnitude - 1.0) * - 20 * DEG_TO_RAD))
|
||||
{
|
||||
xglColor3f (magnitude, magnitude, magnitude);
|
||||
xglVertex3f( 50000.0 * cos (ra) * cos (dec),
|
||||
50000.0 * sin (ra) * cos (dec),
|
||||
50000.0 * sin (dec));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SolarSystem* SolarSystem::theSolarSystem = 0;
|
||||
|
||||
/******************************************************************************
|
||||
* void solarSystemRebuild()
|
||||
* this a just a wrapper function, provided for use as an interface to the
|
||||
* event manager
|
||||
*****************************************************************************/
|
||||
void solarSystemRebuild()
|
||||
{
|
||||
SolarSystem::theSolarSystem->rebuild();
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/**************************************************************************
|
||||
* solarsystem.hxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _SOLARSYSTEM_H_
|
||||
#define _SOLARSYSTEM_H_
|
||||
|
||||
#include <Time/light.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
#include <Main/views.hxx>
|
||||
|
||||
#include "star.hxx"
|
||||
#include "moon.hxx"
|
||||
#include "mercury.hxx"
|
||||
#include "venus.hxx"
|
||||
#include "mars.hxx"
|
||||
#include "jupiter.hxx"
|
||||
#include "saturn.hxx"
|
||||
#include "uranus.hxx"
|
||||
#include "neptune.hxx"
|
||||
#include "pluto.hxx"
|
||||
|
||||
|
||||
class SolarSystem
|
||||
{
|
||||
private:
|
||||
Star* ourSun;
|
||||
Moon* earthsMoon;
|
||||
Mercury* mercury;
|
||||
Venus* venus;
|
||||
Mars* mars;
|
||||
Jupiter* jupiter;
|
||||
Saturn* saturn;
|
||||
Uranus* uranus;
|
||||
Neptune* neptune;
|
||||
//Pluto* pluto;
|
||||
|
||||
GLint displayList;
|
||||
double scaleMagnitude(double magn);
|
||||
void addPlanetToList(double ra, double dec, double magn);
|
||||
|
||||
|
||||
public:
|
||||
SolarSystem(FGTime *t);
|
||||
CelestialBody *getSun();
|
||||
CelestialBody *getMoon();
|
||||
~SolarSystem();
|
||||
|
||||
static SolarSystem *theSolarSystem; // thanks to Bernie Bright!
|
||||
void rebuild();
|
||||
friend void solarSystemRebuild();
|
||||
void draw();
|
||||
};
|
||||
|
||||
inline CelestialBody* SolarSystem::getSun()
|
||||
{
|
||||
return ourSun;
|
||||
}
|
||||
|
||||
inline CelestialBody* SolarSystem::getMoon()
|
||||
{
|
||||
return earthsMoon;
|
||||
}
|
||||
|
||||
inline void SolarSystem::draw()
|
||||
{
|
||||
xglCallList(displayList);
|
||||
}
|
||||
|
||||
extern void solarSystemRebuild();
|
||||
|
||||
#endif // _SOLARSYSTEM_H_
|
||||
@@ -5,35 +5,37 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <Time/sunpos.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Time/light.hxx>
|
||||
#include <Main/options.hxx>
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include "star.hxx"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Star::Star(FGTime *t)
|
||||
* Star::Star(double mjd)
|
||||
* Public constructor for class Star
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements our sun are passed to
|
||||
@@ -41,126 +43,50 @@
|
||||
* note that the word sun is avoided, in order to prevent some compilation
|
||||
* problems on sun systems
|
||||
************************************************************************/
|
||||
Star::Star(FGTime *t) :
|
||||
CelestialBody (0.000000, 0.0000000000,
|
||||
0.0000, 0.00000,
|
||||
282.9404, 4.7093500E-5,
|
||||
1.0000000, 0.000000,
|
||||
0.016709, -1.151E-9,
|
||||
356.0470, 0.98560025850, t)
|
||||
Star::Star(double mjd) :
|
||||
CelestialBody (0.000000, 0.0000000000,
|
||||
0.0000, 0.00000,
|
||||
282.9404, 4.7093500E-5,
|
||||
1.0000000, 0.000000,
|
||||
0.016709, -1.151E-9,
|
||||
356.0470, 0.98560025850, mjd)
|
||||
{
|
||||
|
||||
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Sun Texture");
|
||||
#ifdef GL_VERSION_1_1
|
||||
xglGenTextures(1, &sun_texid);
|
||||
xglBindTexture(GL_TEXTURE_2D, sun_texid);
|
||||
#elif GL_EXT_texture_object
|
||||
xglGenTexturesEXT(1, &sun_texid);
|
||||
xglBindTextureEXT(GL_TEXTURE_2D, sun_texid);
|
||||
#else
|
||||
# error port me
|
||||
#endif
|
||||
distance = 0.0;
|
||||
}
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
setTexture();
|
||||
glTexImage2D( GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
256, 256,
|
||||
0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
sun_texbuf);
|
||||
|
||||
SunObject = gluNewQuadric();
|
||||
if(SunObject == NULL)
|
||||
{
|
||||
printf("gluNewQuadric(SunObject) failed !\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//SunList = 0;
|
||||
distance = 0.0;
|
||||
Star::Star() :
|
||||
CelestialBody (0.000000, 0.0000000000,
|
||||
0.0000, 0.00000,
|
||||
282.9404, 4.7093500E-5,
|
||||
1.0000000, 0.000000,
|
||||
0.016709, -1.151E-9,
|
||||
356.0470, 0.98560025850)
|
||||
{
|
||||
distance = 0.0;
|
||||
}
|
||||
|
||||
Star::~Star()
|
||||
{
|
||||
//delete SunObject;
|
||||
delete [] sun_texbuf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int texWidth = 256; /* 64x64 is plenty */
|
||||
|
||||
void Star::setTexture()
|
||||
{
|
||||
int texSize;
|
||||
//void *textureBuf;
|
||||
GLubyte *p;
|
||||
int i,j;
|
||||
double radius;
|
||||
|
||||
texSize = texWidth*texWidth;
|
||||
|
||||
sun_texbuf = new GLubyte[texSize*4];
|
||||
if (!sun_texbuf)
|
||||
return; // Ugly!
|
||||
|
||||
p = sun_texbuf;
|
||||
|
||||
radius = (double)(texWidth / 2);
|
||||
|
||||
for (i=0; i < texWidth; i++) {
|
||||
for (j=0; j < texWidth; j++) {
|
||||
double x, y, d;
|
||||
|
||||
x = fabs((double)(i - (texWidth / 2)));
|
||||
y = fabs((double)(j - (texWidth / 2)));
|
||||
|
||||
d = sqrt((x * x) + (y * y));
|
||||
if (d < radius)
|
||||
{
|
||||
double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
|
||||
// inverse square looks nice
|
||||
*p = (int)((double)0xff * (t * t));
|
||||
*(p+1) = (int)((double) 0xff * (t*t));
|
||||
*(p+2) = (int)((double) 0xff * (t*t));
|
||||
*(p+3) = (int)((double) 0xff * (t*t));
|
||||
}
|
||||
else
|
||||
{
|
||||
*p = 0x00;
|
||||
*(p+1) = 0x00;
|
||||
*(p+2) = 0x00;
|
||||
*(p+3) = 0x00;
|
||||
}
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
|
||||
// GL_LUMINANCE,
|
||||
// GL_UNSIGNED_BYTE, textureBuf);
|
||||
//free(textureBuf);
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Jupiter::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Star::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of our sun.
|
||||
*************************************************************************/
|
||||
void Star::updatePosition(FGTime *t)
|
||||
void Star::updatePosition(double mjd)
|
||||
{
|
||||
double
|
||||
actTime, eccAnom,
|
||||
xv, yv, v, r,
|
||||
xe, ye, ze, ecl;
|
||||
|
||||
updateOrbElements(t);
|
||||
updateOrbElements(mjd);
|
||||
|
||||
actTime = fgCalcActTime(t);
|
||||
actTime = sgCalcActTime(mjd);
|
||||
ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle in Radians
|
||||
eccAnom = fgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
|
||||
eccAnom = sgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
|
||||
|
||||
xv = cos(eccAnom) - e;
|
||||
yv = sqrt (1.0 - e*e) * sin(eccAnom);
|
||||
@@ -186,86 +112,3 @@ void Star::updatePosition(FGTime *t)
|
||||
rightAscension = atan2 (ye, xe);
|
||||
declination = atan2 (ze, sqrt (xe*xe + ye*ye));
|
||||
}
|
||||
|
||||
void Star::newImage(void)
|
||||
{
|
||||
/*static float stars[3];
|
||||
stars[0] = 0.0;
|
||||
stars[1] = 0.0;
|
||||
stars[2] = 1.0;*/
|
||||
|
||||
fgLIGHT *l = &cur_light_params;
|
||||
float sun_angle = l->sun_angle;
|
||||
|
||||
if( sun_angle*RAD_TO_DEG < 100 ) { // else no need to draw sun
|
||||
|
||||
|
||||
double x_2, x_4, x_8, x_10;
|
||||
GLfloat ambient;
|
||||
GLfloat amb[4];
|
||||
int sun_size = 550;
|
||||
|
||||
// daily variation sun gets larger near horizon
|
||||
/*if(sun_angle*RAD_TO_DEG > 84.0 && sun_angle*RAD_TO_DEG < 95)
|
||||
{
|
||||
double sun_grow = 9*fabs(94-sun_angle*RAD_TO_DEG);
|
||||
sun_size = (int)(sun_size + sun_size * cos(sun_grow*DEG_TO_RAD));
|
||||
}*/
|
||||
x_2 = sun_angle * sun_angle;
|
||||
x_4 = x_2 * x_2;
|
||||
x_8 = x_4 * x_4;
|
||||
x_10 = x_8 * x_2;
|
||||
ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
|
||||
if (ambient < 0.3) ambient = 0.3;
|
||||
if (ambient > 1.0) ambient = 1.0;
|
||||
|
||||
amb[0] = ((ambient * 6.0) - 1.0); // minimum value = 0.8
|
||||
amb[1] = ((ambient * 11.0) - 3.0); // minimum value = 0.3
|
||||
amb[2] = ((ambient * 12.0) - 3.6); // minimum value = 0.0
|
||||
amb[3] = 1.00;
|
||||
|
||||
if (amb[0] > 1.0) amb[0] = 1.0;
|
||||
if (amb[1] > 1.0) amb[1] = 1.0;
|
||||
if (amb[2] > 1.0) amb[2] = 1.0;
|
||||
xglColor3fv(amb);
|
||||
glPushMatrix();
|
||||
{
|
||||
xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
|
||||
xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
|
||||
xglTranslatef(0,60000,0);
|
||||
if (current_options.get_textures())
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
|
||||
glEnable(GL_BLEND); // BLEND ENABLED
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBindTexture(GL_TEXTURE_2D, sun_texid);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
|
||||
glEnd();
|
||||
}
|
||||
xglDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
|
||||
xglDisable(GL_BLEND); // BLEND DISABLED
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
glDisable(GL_LIGHTING); // LIGHTING DISABLED
|
||||
glDisable(GL_BLEND); // BLEND DISABLED
|
||||
glPushMatrix();
|
||||
{
|
||||
xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
|
||||
xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
|
||||
xglColor4fv(amb);
|
||||
xglTranslatef(0,60000,0);
|
||||
gluSphere( SunObject, sun_size, 10, 10 );
|
||||
}
|
||||
glPopMatrix();
|
||||
glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
|
||||
glDisable(GL_BLEND); // BLEND DISABLED
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,54 +5,50 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _STAR_HXX_
|
||||
#define _STAR_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
|
||||
|
||||
class Star : public CelestialBody
|
||||
{
|
||||
|
||||
private:
|
||||
//double longitude; // the sun's true longitude - this is depreciated by
|
||||
// CelestialBody::lonEcl
|
||||
double xs, ys; // the sun's rectangular geocentric coordinates
|
||||
double distance; // the sun's distance to the earth
|
||||
GLUquadricObj *SunObject;
|
||||
GLuint sun_texid;
|
||||
GLubyte *sun_texbuf;
|
||||
|
||||
void setTexture();
|
||||
double xs, ys; // the sun's rectangular geocentric coordinates
|
||||
double distance; // the sun's distance to the earth
|
||||
|
||||
public:
|
||||
Star (FGTime *t);
|
||||
~Star();
|
||||
void updatePosition(FGTime *t);
|
||||
double getM();
|
||||
double getw();
|
||||
//double getLon();
|
||||
double getxs();
|
||||
double getys();
|
||||
double getDistance();
|
||||
void newImage();
|
||||
};
|
||||
|
||||
Star (double mjd);
|
||||
Star ();
|
||||
~Star();
|
||||
void updatePosition(double mjd);
|
||||
double getM();
|
||||
double getw();
|
||||
double getxs();
|
||||
double getys();
|
||||
double getDistance();
|
||||
};
|
||||
|
||||
|
||||
inline double Star::getM()
|
||||
|
||||
122
simgear/ephemeris/stardata.cxx
Normal file
122
simgear/ephemeris/stardata.cxx
Normal file
@@ -0,0 +1,122 @@
|
||||
// stardata.cxx -- manage star data
|
||||
//
|
||||
// Written by Curtis Olson, started March 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/fgstream.hxx>
|
||||
|
||||
#include "stardata.hxx"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
FG_USING_STD(getline);
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
SGStarData::SGStarData() {
|
||||
}
|
||||
|
||||
SGStarData::SGStarData( FGPath path ) {
|
||||
data_path = FGPath( path );
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
SGStarData::~SGStarData() {
|
||||
}
|
||||
|
||||
|
||||
bool SGStarData::load() {
|
||||
|
||||
// -dw- avoid local data > 32k error by dynamic allocation of the
|
||||
// array, problem for some compilers
|
||||
stars = new sgdVec3[SG_MAX_STARS];
|
||||
|
||||
// build the full path name to the stars data base file
|
||||
data_path.append( "stars" );
|
||||
FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << data_path.str() );
|
||||
|
||||
fg_gzifstream in( data_path.str() );
|
||||
if ( ! in.is_open() ) {
|
||||
FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: "
|
||||
<< data_path.str() );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
double ra, dec, mag;
|
||||
char c;
|
||||
string name;
|
||||
|
||||
nstars = 0;
|
||||
|
||||
// read in each line of the file
|
||||
while ( ! in.eof() && nstars < SG_MAX_STARS ) {
|
||||
in >> skipcomment;
|
||||
|
||||
getline( in, name, ',' );
|
||||
// cout << " data = " << name << endl;
|
||||
|
||||
// read name and first comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> ra;
|
||||
|
||||
// read past optional comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> dec;
|
||||
|
||||
// read past optional comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> mag;
|
||||
|
||||
// cout << " star data = " << ra << " " << dec << " " << mag << endl;
|
||||
|
||||
sgdSetVec3( stars[nstars], ra, dec, mag );
|
||||
|
||||
++nstars;
|
||||
}
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO, " Loaded " << nstars << " stars" );
|
||||
|
||||
return true;
|
||||
}
|
||||
62
simgear/ephemeris/stardata.hxx
Normal file
62
simgear/ephemeris/stardata.hxx
Normal file
@@ -0,0 +1,62 @@
|
||||
// stardata.hxx -- manage star data
|
||||
//
|
||||
// Written by Curtis Olson, started March 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_STARDATA_HXX
|
||||
#define _SG_STARDATA_HXX
|
||||
|
||||
|
||||
#include <plib/sg.h>
|
||||
|
||||
#include <simgear/misc/fgpath.hxx>
|
||||
|
||||
|
||||
#define SG_MAX_STARS 850
|
||||
|
||||
|
||||
class SGStarData {
|
||||
|
||||
int nstars;
|
||||
sgdVec3 *stars;
|
||||
|
||||
FGPath data_path;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
SGStarData();
|
||||
SGStarData( FGPath path );
|
||||
|
||||
// Destructor
|
||||
~SGStarData();
|
||||
|
||||
// load the stars database
|
||||
bool load();
|
||||
|
||||
// stars
|
||||
inline int getNumStars() const { return nstars; }
|
||||
inline sgdVec3 *getStars() { return stars; }
|
||||
};
|
||||
|
||||
|
||||
#endif // _SG_STARDATA_HXX
|
||||
@@ -1,267 +0,0 @@
|
||||
// stars.cxx -- data structures and routines for managing and rendering stars.
|
||||
//
|
||||
// Written by Curtis Olson, started August 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
//*************************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "Include/compiler.h"
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <cmath>
|
||||
# include <cstdio>
|
||||
# include <cstring>
|
||||
# include <ctime>
|
||||
#else
|
||||
# include <math.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Misc/fgpath.hxx>
|
||||
#include <Misc/fgstream.hxx>
|
||||
#include <Misc/stopwatch.hxx>
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/views.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "Misc/stopwatch.hxx"
|
||||
|
||||
#include "stars.hxx"
|
||||
|
||||
// FG_USING_STD(getline);
|
||||
|
||||
#define EpochStart (631065600)
|
||||
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
||||
#define FG_MAX_STARS 3500
|
||||
|
||||
// Define four structures, each with varying amounts of stars
|
||||
static GLint stars[FG_STAR_LEVELS];
|
||||
|
||||
|
||||
// Initialize the Star Management Subsystem
|
||||
int fgStarsInit( void ) {
|
||||
// -dw- avoid local data > 32k error by dynamic allocation of the
|
||||
// array, problem for some compilers
|
||||
Point3D *starlist = new Point3D[FG_MAX_STARS];
|
||||
// struct CelestialCoord pltPos;
|
||||
double right_ascension, declination, magnitude;
|
||||
double min_magnitude[FG_STAR_LEVELS];
|
||||
// double ra_save, decl_save;
|
||||
// double ra_save1, decl_save1;
|
||||
int i, j, starcount, count;
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO, "Initializing stars" );
|
||||
|
||||
if ( FG_STAR_LEVELS < 4 ) {
|
||||
FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// build the full path name to the stars data base file
|
||||
FGPath path ( current_options.get_fg_root() );
|
||||
path.append( "Astro/stars" );
|
||||
FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << path.str() );
|
||||
|
||||
fg_gzifstream in( path.str() );
|
||||
if ( ! in ) {
|
||||
FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: " << path.str() );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
starcount = 0;
|
||||
|
||||
StopWatch timer;
|
||||
timer.start();
|
||||
|
||||
// read in each line of the file
|
||||
while ( ! in.eof() && starcount < FG_MAX_STARS )
|
||||
{
|
||||
in >> skipcomment;
|
||||
string name;
|
||||
getline( in, name, ',' );
|
||||
in >> starlist[starcount];
|
||||
++starcount;
|
||||
}
|
||||
|
||||
timer.stop();
|
||||
FG_LOG( FG_ASTRO, FG_INFO,
|
||||
"Loaded " << starcount << " stars in "
|
||||
<< timer.elapsedSeconds() << " seconds" );
|
||||
|
||||
min_magnitude[0] = 4.2;
|
||||
min_magnitude[1] = 3.6;
|
||||
min_magnitude[2] = 3.0;
|
||||
min_magnitude[3] = 2.4;
|
||||
min_magnitude[4] = 1.8;
|
||||
min_magnitude[5] = 1.2;
|
||||
min_magnitude[6] = 0.6;
|
||||
min_magnitude[7] = 0.0;
|
||||
|
||||
// build the various star display lists
|
||||
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
||||
|
||||
stars[i] = xglGenLists(1);
|
||||
xglNewList( stars[i], GL_COMPILE );
|
||||
xglBegin( GL_POINTS );
|
||||
|
||||
count = 0;
|
||||
|
||||
for ( j = 0; j < starcount; j++ ) {
|
||||
magnitude = starlist[j].z();
|
||||
// printf("magnitude = %.2f\n", magnitude);
|
||||
|
||||
if ( magnitude < min_magnitude[i] ) {
|
||||
right_ascension = starlist[j].x();
|
||||
declination = starlist[j].y();
|
||||
|
||||
count++;
|
||||
|
||||
// scale magnitudes to (0.0 - 1.0)
|
||||
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
||||
|
||||
// scale magnitudes again so they look ok
|
||||
if ( magnitude > 1.0 ) { magnitude = 1.0; }
|
||||
if ( magnitude < 0.0 ) { magnitude = 0.0; }
|
||||
// magnitude =
|
||||
// magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.042);
|
||||
|
||||
magnitude = magnitude * 0.9 +
|
||||
(((FG_STAR_LEVELS - 1) - i) * 0.014);
|
||||
// printf(" Found star: %d %s, %.3f %.3f %.3f\n", count,
|
||||
// name, right_ascension, declination, magnitude);
|
||||
|
||||
xglColor3f( magnitude, magnitude, magnitude );
|
||||
//xglColor3f(0,0,0);*/
|
||||
xglVertex3f( 50000.0*cos(right_ascension)*cos(declination),
|
||||
50000.0*sin(right_ascension)*cos(declination),
|
||||
50000.0*sin(declination) );
|
||||
}
|
||||
} // while
|
||||
|
||||
xglEnd();
|
||||
|
||||
/*
|
||||
xglBegin(GL_LINE_LOOP);
|
||||
xglColor3f(1.0, 0.0, 0.0);
|
||||
xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(decl_save-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(decl_save-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(decl_save+0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(decl_save+0.2) );
|
||||
xglEnd();
|
||||
*/
|
||||
|
||||
/*
|
||||
xglBegin(GL_LINE_LOOP);
|
||||
xglColor3f(0.0, 1.0, 0.0);
|
||||
xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(decl_save1-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(decl_save1-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(decl_save1+0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(decl_save1+0.2) );
|
||||
xglEnd();
|
||||
*/
|
||||
|
||||
xglEndList();
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO,
|
||||
" Loading " << count << " stars brighter than "
|
||||
<< min_magnitude[i] );
|
||||
}
|
||||
|
||||
return 1; // OK, we got here because initialization worked.
|
||||
}
|
||||
|
||||
|
||||
// Draw the Stars
|
||||
void fgStarsRender( void ) {
|
||||
FGInterface *f;
|
||||
fgLIGHT *l;
|
||||
FGTime *t;
|
||||
int i;
|
||||
|
||||
f = current_aircraft.fdm_state;
|
||||
l = &cur_light_params;
|
||||
t = FGTime::cur_time_params;
|
||||
|
||||
// FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise
|
||||
|
||||
// t->sun_angle = 3.0; // to force stars to be drawn (for testing)
|
||||
|
||||
// render the stars
|
||||
if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
||||
// determine which star structure to draw
|
||||
if ( l->sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) {
|
||||
i = 0;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
|
||||
i = 1;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
|
||||
i = 2;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
|
||||
i = 3;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
|
||||
i = 4;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
|
||||
i = 5;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
|
||||
i = 6;
|
||||
} else {
|
||||
i = 7;
|
||||
}
|
||||
|
||||
// printf("RENDERING STARS = %d (night)\n", i);
|
||||
|
||||
xglCallList(stars[i]);
|
||||
} else {
|
||||
// printf("not RENDERING STARS (day)\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -30,31 +31,40 @@
|
||||
#include "uranus.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Uranus::Uranus(FGTime *t)
|
||||
* Uranus::Uranus(double mjd)
|
||||
* Public constructor for class Uranus
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Uranus are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Uranus::Uranus(FGTime *t) :
|
||||
Uranus::Uranus(double mjd) :
|
||||
CelestialBody(74.00050, 1.3978000E-5,
|
||||
0.7733, 1.900E-8,
|
||||
96.66120, 3.0565000E-5,
|
||||
19.181710, -1.55E-8,
|
||||
0.047318, 7.450E-9,
|
||||
142.5905, 0.01172580600, t)
|
||||
142.5905, 0.01172580600, mjd)
|
||||
{
|
||||
}
|
||||
Uranus::Uranus() :
|
||||
CelestialBody(74.00050, 1.3978000E-5,
|
||||
0.7733, 1.900E-8,
|
||||
96.66120, 3.0565000E-5,
|
||||
19.181710, -1.55E-8,
|
||||
0.047318, 7.450E-9,
|
||||
142.5905, 0.01172580600)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Uranus::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Uranus::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Uranus, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Uranus specific equation
|
||||
*************************************************************************/
|
||||
void Uranus::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Uranus::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
|
||||
}
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _URANUS_HXX_
|
||||
#define _URANUS_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Uranus : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Uranus ( FGTime *t);
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
Uranus (double mjd);
|
||||
Uranus ();
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _URANUS_HXX_
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
@@ -30,31 +31,40 @@
|
||||
#include "venus.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Venus::Venus(FGTime *t)
|
||||
* Venus::Venus(double mjd)
|
||||
* Public constructor for class Venus
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Venus are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Venus::Venus(FGTime *t) :
|
||||
Venus::Venus(double mjd) :
|
||||
CelestialBody(76.67990, 2.4659000E-5,
|
||||
3.3946, 2.75E-8,
|
||||
54.89100, 1.3837400E-5,
|
||||
0.7233300, 0.000000,
|
||||
0.006773, -1.302E-9,
|
||||
48.00520, 1.60213022440, t)
|
||||
48.00520, 1.60213022440, mjd)
|
||||
{
|
||||
}
|
||||
Venus::Venus() :
|
||||
CelestialBody(76.67990, 2.4659000E-5,
|
||||
3.3946, 2.75E-8,
|
||||
54.89100, 1.3837400E-5,
|
||||
0.7233300, 0.000000,
|
||||
0.006773, -1.302E-9,
|
||||
48.00520, 1.60213022440)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Venus::updatePosition(FGTime *t, Star *ourSun)
|
||||
* void Venus::updatePosition(double mjd, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Venus, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Venus specific equation
|
||||
*************************************************************************/
|
||||
void Venus::updatePosition(FGTime *t, Star *ourSun)
|
||||
void Venus::updatePosition(double mjd, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
CelestialBody::updatePosition(mjd, ourSun);
|
||||
magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
|
||||
}
|
||||
|
||||
@@ -5,34 +5,35 @@
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
#ifndef _VENUS_HXX_
|
||||
#define _VENUS_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <simgear/ephemeris/celestialBody.hxx>
|
||||
#include <simgear/ephemeris/star.hxx>
|
||||
|
||||
class Venus : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Venus ( FGTime *t);
|
||||
void updatePosition(FGTime *t, Star *ourSun);
|
||||
Venus (double mjd);
|
||||
Venus ();
|
||||
void updatePosition(double mjd, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _VENUS_HXX_
|
||||
|
||||
23
simgear/fg_traits.hxx
Normal file
23
simgear/fg_traits.hxx
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _FG_TRAITS_HXX
|
||||
#define _FG_TRAITS_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifndef FG_HAVE_TRAITS
|
||||
|
||||
// Dummy up some char traits for now.
|
||||
template<class charT> struct char_traits{};
|
||||
|
||||
FG_TEMPLATE_NULL
|
||||
struct char_traits<char>
|
||||
{
|
||||
typedef char char_type;
|
||||
typedef int int_type;
|
||||
typedef streampos pos_type;
|
||||
typedef streamoff off_type;
|
||||
|
||||
static int_type eof() { return EOF; }
|
||||
};
|
||||
#endif // FG_HAVE_TRAITS
|
||||
|
||||
#endif // _FG_TRAITS_HXX
|
||||
87
simgear/fg_zlib.h
Normal file
87
simgear/fg_zlib.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************
|
||||
* fg_zlib.h -- a zlib wrapper to replace zlib calls with normal uncompressed
|
||||
* calls for systems that have problems building zlib.
|
||||
*
|
||||
* Written by Curtis Olson, started April 1998.
|
||||
*
|
||||
* Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef _FG_ZLIB_H
|
||||
#define _FG_ZLIB_H
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef AVOID_USING_ZLIB
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define fgFile FILE *
|
||||
|
||||
/* fgFile fgopen(char *filename, const char *flags) */
|
||||
#define fgopen(P, F) (fopen((P), (F)))
|
||||
|
||||
/* int fgseek(fgFile *file, long offset, int whence) */
|
||||
#define fgseek(F, O, W) (fseek((F), (O), (W)))
|
||||
|
||||
/* fgread(fgFile file, void *buf, int size); */
|
||||
#define fgread(F, B, S) (fread((B), (S), 1, (F)))
|
||||
|
||||
/* int fggets(fgFile fd, char *buffer, int len) */
|
||||
#define fggets(F, B, L) (fgets((B), (L), (F)))
|
||||
|
||||
/* int fgclose(fgFile fd) */
|
||||
#define fgclose(F) (fclose((F)))
|
||||
#else
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#include <zlib.h>
|
||||
#else
|
||||
#include <simgear/zlib/zlib.h>
|
||||
#endif
|
||||
|
||||
#define fgFile gzFile
|
||||
|
||||
/* fgFile fgopen(char *filename, const char *flags) */
|
||||
#define fgopen(P, F) (gzopen((P), (F)))
|
||||
|
||||
/* int fgseek(fgFile *file, long offset, int whence) */
|
||||
#define fgseek(F, O, W) (gzseek((F), (O), (W)))
|
||||
|
||||
/* fgread(fgFile file, void *buf, int size); */
|
||||
#define fgread(F, B, S) (gzread((F), (B), (S)))
|
||||
|
||||
/* int fggets(fgFile fd, char *buffer, int len) */
|
||||
#define fggets(F, B, L) (gzgets((F), (B), (L)))
|
||||
|
||||
/* int fgclose(fgFile fd) */
|
||||
#define fgclose(F) (gzclose((F)))
|
||||
|
||||
#endif /* #ifdef AVOID_USING_ZLIB #else #endif */
|
||||
|
||||
|
||||
#endif /* _FG_ZLIB_H */
|
||||
|
||||
|
||||
62
simgear/inlines.h
Normal file
62
simgear/inlines.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// inlines.h -- various inline template definitions
|
||||
//
|
||||
// Written by Norman Vine, started June 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Norman Vine - nhv@cape.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_INLINES_H
|
||||
#define _SG_INLINES_H
|
||||
|
||||
|
||||
template <class T>
|
||||
inline const int SG_SIGN(const T x) {
|
||||
return x < T(0) ? -1 : 1;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline const T SG_MIN(const T a, const T b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
// return the minimum of three values
|
||||
template <class T>
|
||||
inline const T SG_MIN3( const T a, const T b, const T c) {
|
||||
return (a < b ? SG_MIN (a, c) : SG_MIN (b, c));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline const T SG_MAX(const T a, const T b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
// return the maximum of three values
|
||||
template <class T>
|
||||
inline const T SG_MAX3 (const T a, const T b, const T c) {
|
||||
return (a > b ? SG_MAX (a, c) : SG_MAX (b, c));
|
||||
}
|
||||
|
||||
//
|
||||
template <class T>
|
||||
inline void SG_SWAP( T &a, T &b) {
|
||||
T c = a; a = b; b = c;
|
||||
}
|
||||
|
||||
#endif // _SG_INLINES_H
|
||||
25
simgear/io/Makefile.am
Normal file
25
simgear/io/Makefile.am
Normal file
@@ -0,0 +1,25 @@
|
||||
includedir = @includedir@/io
|
||||
|
||||
lib_LIBRARIES = libsgio.a
|
||||
|
||||
include_HEADERS = \
|
||||
iochannel.hxx \
|
||||
sg_file.hxx \
|
||||
sg_serial.hxx \
|
||||
sg_socket.hxx
|
||||
|
||||
libsgio_a_SOURCES = \
|
||||
iochannel.cxx \
|
||||
sg_file.cxx \
|
||||
sg_serial.cxx \
|
||||
sg_socket.cxx
|
||||
|
||||
INCLUDES += -I$(top_srcdir)
|
||||
|
||||
noinst_PROGRAMS = socktest
|
||||
|
||||
socktest_SOURCES = socktest.cxx
|
||||
|
||||
socktest_LDADD = \
|
||||
$(top_builddir)/simgear/io/libsgio.a \
|
||||
$(top_builddir)/simgear/debug/libsgdebug.a
|
||||
74
simgear/io/iochannel.cxx
Normal file
74
simgear/io/iochannel.cxx
Normal file
@@ -0,0 +1,74 @@
|
||||
// iochannel.cxx -- High level IO channel class
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include "iochannel.hxx"
|
||||
// #include "garmin.hxx"
|
||||
// #include "nmea.hxx"
|
||||
|
||||
|
||||
// constructor
|
||||
SGIOChannel::SGIOChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
SGIOChannel::~SGIOChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// dummy configure routine
|
||||
bool SGIOChannel::open( const SGProtocolDir d ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// dummy process routine
|
||||
int SGIOChannel::read( char *buf, int length ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// dummy process routine
|
||||
int SGIOChannel::readline( char *buf, int length ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// dummy process routine
|
||||
int SGIOChannel::write( const char *buf, const int length ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// dummy process routine
|
||||
int SGIOChannel::writestring( const char *str ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// dummy close routine
|
||||
bool SGIOChannel::close() {
|
||||
return false;
|
||||
}
|
||||
84
simgear/io/iochannel.hxx
Normal file
84
simgear/io/iochannel.hxx
Normal file
@@ -0,0 +1,84 @@
|
||||
// iochannel.hxx -- High level IO channel class
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _IOCHANNEL_HXX
|
||||
#define _IOCHANNEL_HXX
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
// #include "protocol.hxx"
|
||||
|
||||
#include STL_STRING
|
||||
#include <vector>
|
||||
|
||||
FG_USING_STD(vector);
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
#define SG_IO_MAX_MSG_SIZE 16384
|
||||
|
||||
enum SGProtocolDir {
|
||||
SG_IO_NONE = 0,
|
||||
SG_IO_IN = 1,
|
||||
SG_IO_OUT = 2,
|
||||
SG_IO_BI = 3
|
||||
};
|
||||
|
||||
|
||||
enum SGChannelType {
|
||||
sgFileType = 0,
|
||||
sgSerialType = 1,
|
||||
sgSocketType = 2
|
||||
};
|
||||
|
||||
class SGIOChannel {
|
||||
|
||||
SGChannelType type;
|
||||
SGProtocolDir dir;
|
||||
bool valid;
|
||||
|
||||
public:
|
||||
|
||||
SGIOChannel();
|
||||
virtual ~SGIOChannel();
|
||||
|
||||
virtual bool open( const SGProtocolDir d );
|
||||
virtual int read( char *buf, int length );
|
||||
virtual int readline( char *buf, int length );
|
||||
virtual int write( const char *buf, const int length );
|
||||
virtual int writestring( const char *str );
|
||||
virtual bool close();
|
||||
|
||||
inline void set_type( SGChannelType t ) { type = t; }
|
||||
inline SGChannelType get_type() const { return type; }
|
||||
|
||||
inline void set_dir( const SGProtocolDir d ) { dir = d; }
|
||||
inline SGProtocolDir get_dir() const { return dir; }
|
||||
inline bool isvalid() const { return valid; }
|
||||
};
|
||||
|
||||
|
||||
#endif // _IOCHANNEL_HXX
|
||||
|
||||
|
||||
134
simgear/io/sg_file.cxx
Normal file
134
simgear/io/sg_file.cxx
Normal file
@@ -0,0 +1,134 @@
|
||||
// sg_file.cxx -- File I/O routines
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include "sg_file.hxx"
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
SGFile::SGFile( const string &file) {
|
||||
set_type( sgFileType );
|
||||
file_name = file;
|
||||
}
|
||||
|
||||
|
||||
SGFile::~SGFile() {
|
||||
}
|
||||
|
||||
|
||||
// open the file based on specified direction
|
||||
bool SGFile::open( const SGProtocolDir d ) {
|
||||
set_dir( d );
|
||||
|
||||
if ( get_dir() == SG_IO_OUT ) {
|
||||
#ifdef _MSC_VER
|
||||
int mode = 00666;
|
||||
#else
|
||||
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||
#endif
|
||||
fp = ::open( file_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC, mode );
|
||||
} else if ( get_dir() == SG_IO_IN ) {
|
||||
fp = ::open( file_name.c_str(), O_RDONLY );
|
||||
} else {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: bidirection mode not available for files." );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( fp == -1 ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error opening file: " << file_name );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// read a block of data of specified size
|
||||
int SGFile::read( char *buf, int length ) {
|
||||
// read a chunk
|
||||
return ::read( fp, buf, length );
|
||||
}
|
||||
|
||||
|
||||
// read a line of data, length is max size of input buffer
|
||||
int SGFile::readline( char *buf, int length ) {
|
||||
// save our current position
|
||||
int pos = lseek( fp, 0, SEEK_CUR );
|
||||
|
||||
// read a chunk
|
||||
int result = ::read( fp, buf, length );
|
||||
|
||||
// find the end of line and reset position
|
||||
int i;
|
||||
for ( i = 0; i < result && buf[i] != '\n'; ++i );
|
||||
if ( buf[i] == '\n' ) {
|
||||
result = i + 1;
|
||||
} else {
|
||||
result = i;
|
||||
}
|
||||
lseek( fp, pos + result, SEEK_SET );
|
||||
|
||||
// just in case ...
|
||||
buf[ result ] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// write data to a file
|
||||
int SGFile::write( const char *buf, const int length ) {
|
||||
int result = ::write( fp, buf, length );
|
||||
if ( result != length ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error writing data: " << file_name );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// write null terminated string to a file
|
||||
int SGFile::writestring( const char *str ) {
|
||||
int length = strlen( str );
|
||||
return write( str, length );
|
||||
}
|
||||
|
||||
|
||||
// close the port
|
||||
bool SGFile::close() {
|
||||
if ( ::close( fp ) == -1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
82
simgear/io/sg_file.hxx
Normal file
82
simgear/io/sg_file.hxx
Normal file
@@ -0,0 +1,82 @@
|
||||
// sg_file.hxx -- File I/O routines
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_FILE_HXX
|
||||
#define _SG_FILE_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/types.h> // for open(), read(), write(), close()
|
||||
#include <sys/stat.h> // for open(), read(), write(), close()
|
||||
#include <fcntl.h> // for open(), read(), write(), close()
|
||||
#if !defined( _MSC_VER )
|
||||
# include <unistd.h> // for open(), read(), write(), close()
|
||||
#endif
|
||||
|
||||
#include "iochannel.hxx"
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
class SGFile : public SGIOChannel {
|
||||
|
||||
string file_name;
|
||||
int fp;
|
||||
|
||||
public:
|
||||
|
||||
SGFile( const string& file );
|
||||
~SGFile();
|
||||
|
||||
// open the file based on specified direction
|
||||
bool open( const SGProtocolDir dir );
|
||||
|
||||
// read a block of data of specified size
|
||||
int read( char *buf, int length );
|
||||
|
||||
// read a line of data, length is max size of input buffer
|
||||
int readline( char *buf, int length );
|
||||
|
||||
// write data to a file
|
||||
int write( const char *buf, const int length );
|
||||
|
||||
// write null terminated string to a file
|
||||
int writestring( const char *str );
|
||||
|
||||
// close file
|
||||
bool close();
|
||||
|
||||
inline string get_file_name() const { return file_name; }
|
||||
};
|
||||
|
||||
|
||||
#endif // _SG_FILE_HXX
|
||||
|
||||
|
||||
157
simgear/io/sg_serial.cxx
Normal file
157
simgear/io/sg_serial.cxx
Normal file
@@ -0,0 +1,157 @@
|
||||
// sg_serial.cxx -- Serial I/O routines
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/serial/serial.hxx>
|
||||
|
||||
#include "sg_serial.hxx"
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
SGSerial::SGSerial( const string& device_name, const string& baud_rate ) :
|
||||
save_len(0)
|
||||
{
|
||||
set_type( sgSerialType );
|
||||
device = device_name;
|
||||
baud = baud_rate;
|
||||
}
|
||||
|
||||
|
||||
SGSerial::~SGSerial() {
|
||||
}
|
||||
|
||||
|
||||
// open the serial port based on specified direction
|
||||
bool SGSerial::open( const SGProtocolDir d ) {
|
||||
set_dir( d );
|
||||
|
||||
if ( ! port.open_port( device ) ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error opening device: " << device );
|
||||
return false;
|
||||
}
|
||||
|
||||
// cout << "fd = " << port.fd << endl;
|
||||
|
||||
if ( ! port.set_baud( atoi( baud.c_str() ) ) ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error setting baud: " << baud );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Read data from port. If we don't get enough data, save what we did
|
||||
// get in the save buffer and return 0. The save buffer will be
|
||||
// prepended to subsequent reads until we get as much as is requested.
|
||||
|
||||
int SGSerial::read( char *buf, int length ) {
|
||||
int result;
|
||||
|
||||
// read a chunk, keep in the save buffer until we have the
|
||||
// requested amount read
|
||||
|
||||
char *buf_ptr = save_buf + save_len;
|
||||
result = port.read_port( buf_ptr, length - save_len );
|
||||
|
||||
if ( result + save_len == length ) {
|
||||
strncpy( buf, save_buf, length );
|
||||
save_len = 0;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// read data from port
|
||||
int SGSerial::readline( char *buf, int length ) {
|
||||
int result;
|
||||
|
||||
// read a chunk, keep in the save buffer until we have the
|
||||
// requested amount read
|
||||
|
||||
char *buf_ptr = save_buf + save_len;
|
||||
result = port.read_port( buf_ptr, SG_IO_MAX_MSG_SIZE - save_len );
|
||||
save_len += result;
|
||||
|
||||
// look for the end of line in save_buf
|
||||
int i;
|
||||
for ( i = 0; i < save_len && save_buf[i] != '\n'; ++i );
|
||||
if ( save_buf[i] == '\n' ) {
|
||||
result = i + 1;
|
||||
} else {
|
||||
// no end of line yet
|
||||
return 0;
|
||||
}
|
||||
|
||||
// we found an end of line
|
||||
|
||||
// copy to external buffer
|
||||
strncpy( buf, save_buf, result );
|
||||
buf[result] = '\0';
|
||||
FG_LOG( FG_IO, FG_INFO, "fg_serial line = " << buf );
|
||||
|
||||
// shift save buffer
|
||||
for ( i = result; i < save_len; ++i ) {
|
||||
save_buf[ i - result ] = save_buf[i];
|
||||
}
|
||||
save_len -= result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// write data to port
|
||||
int SGSerial::write( const char *buf, const int length ) {
|
||||
int result = port.write_port( buf, length );
|
||||
|
||||
if ( result != length ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error writing data: " << device );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// write null terminated string to port
|
||||
int SGSerial::writestring( const char *str ) {
|
||||
int length = strlen( str );
|
||||
return write( str, length );
|
||||
}
|
||||
|
||||
|
||||
// close the port
|
||||
bool SGSerial::close() {
|
||||
if ( ! port.close_port() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
88
simgear/io/sg_serial.hxx
Normal file
88
simgear/io/sg_serial.hxx
Normal file
@@ -0,0 +1,88 @@
|
||||
// sg_serial.hxx -- Serial I/O routines
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_SERIAL_HXX
|
||||
#define _SG_SERIAL_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
// #ifdef FG_HAVE_STD_INCLUDES
|
||||
// # include <ctime>
|
||||
// #else
|
||||
// # include <time.h>
|
||||
// #endif
|
||||
|
||||
#include <simgear/serial/serial.hxx>
|
||||
|
||||
#include "iochannel.hxx"
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
class SGSerial : public SGIOChannel {
|
||||
|
||||
string device;
|
||||
string baud;
|
||||
FGSerialPort port;
|
||||
|
||||
char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
|
||||
int save_len;
|
||||
|
||||
public:
|
||||
|
||||
SGSerial( const string& device_name, const string& baud_rate );
|
||||
~SGSerial();
|
||||
|
||||
// open the serial port based on specified direction
|
||||
bool open( const SGProtocolDir d );
|
||||
|
||||
// read a block of data of specified size
|
||||
int read( char *buf, int length );
|
||||
|
||||
// read a line of data, length is max size of input buffer
|
||||
int readline( char *buf, int length );
|
||||
|
||||
// write data to port
|
||||
int write( const char *buf, const int length );
|
||||
|
||||
// write null terminated string to port
|
||||
int writestring( const char *str );
|
||||
|
||||
// close port
|
||||
bool close();
|
||||
|
||||
inline string get_device() const { return device; }
|
||||
inline string get_baud() const { return baud; }
|
||||
};
|
||||
|
||||
|
||||
#endif // _SG_SERIAL_HXX
|
||||
|
||||
|
||||
547
simgear/io/sg_socket.cxx
Normal file
547
simgear/io/sg_socket.cxx
Normal file
@@ -0,0 +1,547 @@
|
||||
// sg_socket.cxx -- Socket I/O routines
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
# include <sys/time.h> // select()
|
||||
# include <sys/types.h> // socket(), bind(), select(), accept()
|
||||
# include <sys/socket.h> // socket(), bind(), listen(), accept()
|
||||
# include <netinet/in.h> // struct sockaddr_in
|
||||
# include <netdb.h> // gethostbyname()
|
||||
# include <unistd.h> // select(), fsync()/fdatasync(), fcntl()
|
||||
# include <fcntl.h> // fcntl()
|
||||
#endif
|
||||
|
||||
#if defined( sgi )
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include "sg_socket.hxx"
|
||||
|
||||
|
||||
SGSocket::SGSocket( const string& host, const string& port,
|
||||
const string& style ) :
|
||||
hostname(host),
|
||||
port_str(port),
|
||||
save_len(0)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
if (!wsock_init && !wsastartup()) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Winsock not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( style == "udp" ) {
|
||||
sock_style = SOCK_DGRAM;
|
||||
} else if ( style == "tcp" ) {
|
||||
sock_style = SOCK_STREAM;
|
||||
} else {
|
||||
sock_style = SOCK_DGRAM;
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: SGSocket() unknown style = " << style );
|
||||
}
|
||||
|
||||
set_type( sgSocketType );
|
||||
}
|
||||
|
||||
|
||||
SGSocket::~SGSocket() {
|
||||
}
|
||||
|
||||
|
||||
SGSocket::SocketType SGSocket::make_server_socket () {
|
||||
struct sockaddr_in name;
|
||||
|
||||
#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( sgi ) || defined( _MSC_VER )
|
||||
int length;
|
||||
#else
|
||||
socklen_t length;
|
||||
#endif
|
||||
|
||||
// Create the socket.
|
||||
sock = socket (PF_INET, sock_style, 0);
|
||||
if (sock == INVALID_SOCKET) {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: socket() failed in make_server_socket()" );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
// Give the socket a name.
|
||||
name.sin_family = AF_INET;
|
||||
name.sin_addr.s_addr = INADDR_ANY;
|
||||
name.sin_port = htons(port); // set port to zero to let system pick
|
||||
name.sin_addr.s_addr = htonl (INADDR_ANY);
|
||||
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) != 0) {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: bind() failed in make_server_socket()" );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
// Find the assigned port number
|
||||
length = sizeof(struct sockaddr_in);
|
||||
if ( getsockname(sock, (struct sockaddr *) &name, &length) ) {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: getsockname() failed in make_server_socket()" );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
port = ntohs(name.sin_port);
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
||||
SGSocket::SocketType SGSocket::make_client_socket () {
|
||||
struct sockaddr_in name;
|
||||
struct hostent *hp;
|
||||
|
||||
FG_LOG( FG_IO, FG_INFO, "Make client socket()" );
|
||||
|
||||
// Create the socket.
|
||||
sock = socket (PF_INET, sock_style, 0);
|
||||
if (sock == INVALID_SOCKET) {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: socket() failed in make_server_socket()" );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
// specify address family
|
||||
name.sin_family = AF_INET;
|
||||
|
||||
// get the hosts official name/info
|
||||
hp = gethostbyname( hostname.c_str() );
|
||||
|
||||
// Connect this socket to the host and the port specified on the
|
||||
// command line
|
||||
#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ )
|
||||
bcopy(hp->h_addr, (char *)(&(name.sin_addr.s_addr)), hp->h_length);
|
||||
#else
|
||||
bcopy(hp->h_addr, &(name.sin_addr.s_addr), hp->h_length);
|
||||
#endif
|
||||
name.sin_port = htons(port);
|
||||
|
||||
if ( connect(sock, (struct sockaddr *) &name,
|
||||
sizeof(struct sockaddr_in)) != 0 )
|
||||
{
|
||||
closesocket(sock);
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: connect() failed in make_client_socket()" );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
||||
// Wrapper functions
|
||||
size_t SGSocket::readsocket( int fd, void *buf, size_t count ) {
|
||||
#if defined(_MSC_VER)
|
||||
return ::recv( fd, (char *)buf, count, 0 );
|
||||
#else
|
||||
return ::read( fd, buf, count );
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t SGSocket::writesocket( int fd, const void *buf, size_t count ) {
|
||||
#if defined(_MSC_VER)
|
||||
return ::send( fd, (const char*)buf, count, 0 );
|
||||
#else
|
||||
return ::write( fd, buf, count );
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
int SGSocket::closesocket( int fd ) {
|
||||
return ::close( fd );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// If specified as a server (in direction for now) open the master
|
||||
// listening socket. If specified as a client (out direction), open a
|
||||
// connection to a server.
|
||||
bool SGSocket::open( const SGProtocolDir d ) {
|
||||
set_dir( d );
|
||||
|
||||
if ( port_str == "" || port_str == "any" ) {
|
||||
port = 0;
|
||||
} else {
|
||||
port = atoi( port_str.c_str() );
|
||||
}
|
||||
|
||||
// client_connections.clear();
|
||||
|
||||
if ( get_dir() == SG_IO_IN ) {
|
||||
// this means server for now
|
||||
|
||||
// Setup socket to listen on. Set "port" before making this
|
||||
// call. A port of "0" indicates that we want to let the os
|
||||
// pick any available port.
|
||||
sock = make_server_socket();
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "socket creation failed" );
|
||||
return false;
|
||||
}
|
||||
|
||||
FG_LOG( FG_IO, FG_INFO, "socket is connected to port = " << port );
|
||||
|
||||
if ( sock_style == SOCK_DGRAM ) {
|
||||
// Non-blocking UDP
|
||||
nonblock();
|
||||
} else {
|
||||
// Blocking TCP
|
||||
// Specify the maximum length of the connection queue
|
||||
listen( sock, SG_MAX_SOCKET_QUEUE );
|
||||
}
|
||||
|
||||
} else if ( get_dir() == SG_IO_OUT ) {
|
||||
// this means client for now
|
||||
|
||||
sock = make_client_socket();
|
||||
// TODO: check for error.
|
||||
|
||||
if ( sock_style == SOCK_DGRAM ) {
|
||||
// Non-blocking UDP
|
||||
nonblock();
|
||||
}
|
||||
} else if ( get_dir() == SG_IO_BI && sock_style == SOCK_STREAM ) {
|
||||
// this means server for TCP sockets
|
||||
|
||||
// Setup socket to listen on. Set "port" before making this
|
||||
// call. A port of "0" indicates that we want to let the os
|
||||
// pick any available port.
|
||||
sock = make_server_socket();
|
||||
// TODO: check for error.
|
||||
|
||||
FG_LOG( FG_IO, FG_INFO, "socket is connected to port = " << port );
|
||||
|
||||
// Blocking TCP
|
||||
// Specify the maximum length of the connection queue
|
||||
listen( sock, SG_MAX_SOCKET_QUEUE );
|
||||
} else {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: bidirection mode not available for UDP sockets." );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( sock < 0 ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error opening socket: " << hostname
|
||||
<< ":" << port );
|
||||
return false;
|
||||
}
|
||||
|
||||
// extra SOCK_STREAM stuff
|
||||
msgsock = INVALID_SOCKET;
|
||||
first_read = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// read data from socket (server)
|
||||
// read a block of data of specified size
|
||||
int SGSocket::read( char *buf, int length ) {
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
// check for potential input
|
||||
fd_set ready;
|
||||
FD_ZERO(&ready);
|
||||
FD_SET(sock, &ready);
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
// test for any input available on sock (returning immediately, even if
|
||||
// nothing)
|
||||
select(32, &ready, 0, 0, &tv);
|
||||
|
||||
if ( FD_ISSET(sock, &ready) ) {
|
||||
// cout << "data ready" << endl;
|
||||
|
||||
if ( sock_style == SOCK_STREAM ) {
|
||||
if ( msgsock == INVALID_SOCKET ) {
|
||||
msgsock = accept(sock, 0, 0);
|
||||
closesocket(sock);
|
||||
sock = msgsock;
|
||||
} else {
|
||||
result = readsocket( sock, buf, length );
|
||||
}
|
||||
} else {
|
||||
result = readsocket( sock, buf, length );
|
||||
}
|
||||
|
||||
if ( result != length ) {
|
||||
FG_LOG( FG_IO, FG_INFO,
|
||||
"Warning: read() not enough bytes." );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// read a line of data, length is max size of input buffer
|
||||
int SGSocket::readline( char *buf, int length ) {
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cout << "sock = " << sock << endl;
|
||||
|
||||
// check for potential input
|
||||
fd_set ready;
|
||||
FD_ZERO(&ready);
|
||||
FD_SET(sock, &ready);
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
// test for any input read on sock (returning immediately, even if
|
||||
// nothing)
|
||||
int result = select(32, &ready, 0, 0, &tv);
|
||||
// cout << "result = " << result << endl;
|
||||
|
||||
if ( FD_ISSET(sock, &ready) ) {
|
||||
// cout << "fd change state\n";
|
||||
// read a chunk, keep in the save buffer until we have the
|
||||
// requested amount read
|
||||
|
||||
if ( sock_style == SOCK_STREAM ) {
|
||||
// cout << "sock_stream\n";
|
||||
if ( msgsock == INVALID_SOCKET ) {
|
||||
// cout << "msgsock == invalid\n";
|
||||
msgsock = accept(sock, 0, 0);
|
||||
closesocket(sock);
|
||||
sock = msgsock;
|
||||
} else {
|
||||
// cout << "ready to read\n";
|
||||
char *buf_ptr = save_buf + save_len;
|
||||
result = readsocket( sock, buf_ptr, SG_IO_MAX_MSG_SIZE
|
||||
- save_len );
|
||||
// cout << "read result = " << result << endl;
|
||||
|
||||
if ( result > 0 ) {
|
||||
first_read = true;
|
||||
}
|
||||
|
||||
save_len += result;
|
||||
|
||||
// Try and detect that the remote end died. This
|
||||
// could cause problems so if you see connections
|
||||
// dropping for unexplained reasons, LOOK HERE!
|
||||
if ( result == 0 && save_len == 0 && first_read == true ) {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Connection closed by foreign host." );
|
||||
closesocket(sock);
|
||||
open( get_dir() );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char *buf_ptr = save_buf + save_len;
|
||||
result = readsocket( sock, buf_ptr, SG_IO_MAX_MSG_SIZE - save_len );
|
||||
save_len += result;
|
||||
}
|
||||
|
||||
// cout << "current read = " << buf_ptr << endl;
|
||||
// cout << "current save_buf = " << save_buf << endl;
|
||||
// cout << "save_len = " << save_len << endl;
|
||||
} else {
|
||||
// cout << "no data ready\n";
|
||||
}
|
||||
|
||||
// look for the end of line in save_buf
|
||||
int i;
|
||||
for ( i = 0; i < save_len && save_buf[i] != '\n'; ++i );
|
||||
if ( save_buf[i] == '\n' ) {
|
||||
result = i + 1;
|
||||
} else {
|
||||
// no end of line yet
|
||||
// cout << "no eol found" << endl;
|
||||
return 0;
|
||||
}
|
||||
// cout << "line length = " << result << endl;
|
||||
|
||||
// we found an end of line
|
||||
|
||||
// copy to external buffer
|
||||
strncpy( buf, save_buf, result );
|
||||
buf[result] = '\0';
|
||||
// cout << "sg_socket line = " << buf << endl;
|
||||
|
||||
// shift save buffer
|
||||
for ( i = result; i < save_len; ++i ) {
|
||||
save_buf[ i - result ] = save_buf[i];
|
||||
}
|
||||
save_len -= result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// write data to socket (client)
|
||||
int SGSocket::write( const char *buf, const int length ) {
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool error_condition = false;
|
||||
|
||||
if ( writesocket(sock, buf, length) < 0 ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error writing to socket: " << port );
|
||||
error_condition = true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// check for any new client connection requests
|
||||
fd_set ready;
|
||||
FD_ZERO(&ready);
|
||||
FD_SET(sock, &ready);
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
// test for any input on sock (returning immediately, even if
|
||||
// nothing)
|
||||
select(32, &ready, 0, 0, &tv);
|
||||
|
||||
// any new connections?
|
||||
if ( FD_ISSET(sock, &ready) ) {
|
||||
int msgsock = accept(sock, 0, 0);
|
||||
if ( msgsock < 0 ) {
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error: accept() failed in write()" );
|
||||
return 0;
|
||||
} else {
|
||||
client_connections.push_back( msgsock );
|
||||
}
|
||||
}
|
||||
|
||||
FG_LOG( FG_IO, FG_INFO, "Client connections = " <<
|
||||
client_connections.size() );
|
||||
for ( int i = 0; i < (int)client_connections.size(); ++i ) {
|
||||
int msgsock = client_connections[i];
|
||||
|
||||
// read and junk any possible incoming messages.
|
||||
// char junk[ SG_IO_MAX_MSG_SIZE ];
|
||||
// std::read( msgsock, junk, SG_IO_MAX_MSG_SIZE );
|
||||
|
||||
// write the interesting data to the socket
|
||||
if ( writesocket(msgsock, buf, length) == SOCKET_ERROR ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error writing to socket: " << port );
|
||||
error_condition = true;
|
||||
} else {
|
||||
#ifdef _POSIX_SYNCHRONIZED_IO
|
||||
// fdatasync(msgsock);
|
||||
#else
|
||||
// fsync(msgsock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( error_condition ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
// write null terminated string to socket (server)
|
||||
int SGSocket::writestring( const char *str ) {
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int length = strlen( str );
|
||||
return write( str, length );
|
||||
}
|
||||
|
||||
|
||||
// close the port
|
||||
bool SGSocket::close() {
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
closesocket( sock );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// configure the socket as non-blocking
|
||||
bool SGSocket::nonblock() {
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
u_long arg = 1;
|
||||
if (ioctlsocket( sock, FIONBIO, &arg ) != 0) {
|
||||
int error_code = WSAGetLastError();
|
||||
FG_LOG( FG_IO, FG_ALERT,
|
||||
"Error " << error_code << ": unable to set non-blocking mode"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
fcntl( sock, F_SETFL, O_NONBLOCK );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
bool SGSocket::wsock_init = false;
|
||||
|
||||
bool
|
||||
SGSocket::wsastartup() {
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
|
||||
//wVersionRequested = MAKEWORD( 2, 2 );
|
||||
wVersionRequested = MAKEWORD( 1, 1 );
|
||||
int err = WSAStartup( wVersionRequested, &wsaData );
|
||||
if (err != 0)
|
||||
{
|
||||
FG_LOG( FG_IO, FG_ALERT, "Error: Couldn't load winsock" );
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ( LOBYTE( wsaData.wVersion ) != 2 ||
|
||||
HIBYTE( wsaData.wVersion ) != 2 ) {
|
||||
FG_LOG( FG_IO, FG_ALERT, "Couldn't load a suitable winsock");
|
||||
WSACleanup( );
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
wsock_init = true;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
125
simgear/io/sg_socket.hxx
Normal file
125
simgear/io/sg_socket.hxx
Normal file
@@ -0,0 +1,125 @@
|
||||
// sg_socket.hxx -- Socket I/O routines
|
||||
//
|
||||
// Written by Curtis Olson, started November 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_SOCKET_HXX
|
||||
#define _SG_SOCKET_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
#include <simgear/math/sg_types.hxx>
|
||||
#include <simgear/io/iochannel.hxx>
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# include <winsock.h>
|
||||
#endif
|
||||
|
||||
#define SG_MAX_SOCKET_QUEUE 32
|
||||
|
||||
|
||||
class SGSocket : public SGIOChannel {
|
||||
public:
|
||||
#if defined(_MSC_VER)
|
||||
typedef SOCKET SocketType;
|
||||
#else
|
||||
typedef int SocketType;
|
||||
# define INVALID_SOCKET (-1)
|
||||
#endif
|
||||
|
||||
private:
|
||||
string hostname;
|
||||
string port_str;
|
||||
|
||||
char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
|
||||
int save_len;
|
||||
|
||||
SocketType sock;
|
||||
SocketType msgsock;
|
||||
short unsigned int port;
|
||||
int sock_style; // SOCK_STREAM or SOCK_DGRAM
|
||||
|
||||
bool first_read;
|
||||
|
||||
// make a server (master listening) socket
|
||||
SocketType make_server_socket();
|
||||
|
||||
// make a client socket
|
||||
SocketType make_client_socket();
|
||||
|
||||
// wrapper functions
|
||||
size_t readsocket( int fd, void *buf, size_t count );
|
||||
size_t writesocket( int fd, const void *buf, size_t count );
|
||||
#if !defined(_MSC_VER)
|
||||
int closesocket(int fd);
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// Ensure winsock has been initialised.
|
||||
static bool wsock_init;
|
||||
static bool wsastartup();
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
SGSocket( const string& host, const string& port, const string& style );
|
||||
~SGSocket();
|
||||
|
||||
// If specified as a server (in direction for now) open the master
|
||||
// listening socket. If specified as a client (out direction),
|
||||
// open a connection to a server.
|
||||
bool open( const SGProtocolDir d );
|
||||
|
||||
// read data from socket
|
||||
int read( char *buf, int length );
|
||||
|
||||
// read data from socket
|
||||
int readline( char *buf, int length );
|
||||
|
||||
// write data to a socket
|
||||
int write( const char *buf, const int length );
|
||||
|
||||
// write null terminated string to a socket
|
||||
int writestring( const char *str );
|
||||
|
||||
// close file
|
||||
bool close();
|
||||
|
||||
// Enable non-blocking mode.
|
||||
bool nonblock();
|
||||
|
||||
inline string get_hostname() const { return hostname; }
|
||||
inline string get_port_str() const { return port_str; }
|
||||
};
|
||||
|
||||
|
||||
#endif // _SG_SOCKET_HXX
|
||||
|
||||
|
||||
21
simgear/io/socktest.cxx
Normal file
21
simgear/io/socktest.cxx
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sg_socket.hxx"
|
||||
|
||||
int main() {
|
||||
|
||||
SGSocket s( "", "5500", "tcp" );
|
||||
|
||||
if ( !s.open( SG_IO_BI ) ) {
|
||||
cout << "error can't open socket\n";
|
||||
}
|
||||
|
||||
char buf[256];
|
||||
|
||||
while ( true ) {
|
||||
if ( s.readline( buf, 256 ) > 0 ) {
|
||||
cout << "result = " << buf;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
17
simgear/magvar/Makefile.am
Normal file
17
simgear/magvar/Makefile.am
Normal file
@@ -0,0 +1,17 @@
|
||||
includedir = @includedir@/magvar
|
||||
|
||||
lib_LIBRARIES = libsgmagvar.a
|
||||
|
||||
include_HEADERS = magvar.hxx
|
||||
|
||||
libsgmagvar_a_SOURCES = \
|
||||
coremag.hxx coremag.cxx \
|
||||
magvar.cxx
|
||||
|
||||
noinst_PROGRAMS = testmagvar
|
||||
|
||||
testmagvar_SOURCES = testmagvar.cxx
|
||||
|
||||
testmagvar_LDADD = $(top_builddir)/simgear/magvar/libsgmagvar.a
|
||||
|
||||
INCLUDES += -I$(top_srcdir)
|
||||
453
simgear/magvar/coremag.cxx
Normal file
453
simgear/magvar/coremag.cxx
Normal file
@@ -0,0 +1,453 @@
|
||||
// coremag.cxx -- compute local magnetic variation given position,
|
||||
// altitude, and date
|
||||
//
|
||||
// This is an implementation of the NIMA (formerly DMA) WMM2000
|
||||
//
|
||||
// http://www.nima.mil/GandG/ngdc-wmm2000.html
|
||||
//
|
||||
// Copyright (C) 2000 Edward A Williams <Ed_Williams@compuserve.com>
|
||||
//
|
||||
// Adapted from Excel 3.0 version 3/27/94 EAW
|
||||
// Recoded in C++ by Starry Chan
|
||||
// WMM95 added and rearranged in ANSI-C EAW 7/9/95
|
||||
// Put shell around program and made Borland & GCC compatible EAW 11/22/95
|
||||
// IGRF95 added 2/96 EAW
|
||||
// WMM2000 IGR2000 added 2/00 EAW
|
||||
// Released under GPL 3/26/00 EAW
|
||||
// Adaptions and modifications for the SimGear project 3/27/2000 CLO
|
||||
//
|
||||
// Removed all pow() calls and made static roots[][] arrays to
|
||||
// save many sqrt() calls on subsequent invocations
|
||||
// left old code as SGMagVarOrig() for testing purposes
|
||||
// 3/28/2000 Norman Vine -- nhv@yahoo.com
|
||||
//
|
||||
// Put in some bullet-proofing to handle magnetic and geographic poles.
|
||||
// 3/28/2000 EAW
|
||||
|
||||
// The routine uses a spherical harmonic expansion of the magnetic
|
||||
// potential up to twelfth order, together with its time variation, as
|
||||
// described in Chapter 4 of "Geomagnetism, Vol 1, Ed. J.A.Jacobs,
|
||||
// Academic Press (London 1987)". The program first converts geodetic
|
||||
// coordinates (lat/long on elliptic earth and altitude) to spherical
|
||||
// geocentric (spherical lat/long and radius) coordinates. Using this,
|
||||
// the spherical (B_r, B_theta, B_phi) magnetic field components are
|
||||
// computed from the model. These are finally referred to surface (X, Y,
|
||||
// Z) coordinates.
|
||||
//
|
||||
// Fields are accurate to better than 200nT, variation and dip to
|
||||
// better than 0.5 degrees, with the exception of the declination near
|
||||
// the magnetic poles (where it is ill-defined) where the error may reach
|
||||
// 4 degrees or more.
|
||||
//
|
||||
// Variation is undefined at both the geographic and
|
||||
// magnetic poles, even though the field itself is well-behaved. To
|
||||
// avoid the routine blowing up, latitude entries corresponding to
|
||||
// the geographic poles are slightly offset. At the magnetic poles,
|
||||
// the routine returns zero variation.
|
||||
|
||||
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <simgear/constants.h>
|
||||
|
||||
#include "coremag.hxx"
|
||||
|
||||
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
static const double pi = 3.14159265358979;
|
||||
static const double a = 6378.16; /* major radius (km) IAU66 ellipsoid */
|
||||
static const double f = 1.0 / 298.25; /* inverse flattening IAU66 ellipsoid */
|
||||
static const double b = 6378.16 * (1.0 -1.0 / 298.25 );
|
||||
/* minor radius b=a*(1-f) */
|
||||
static const double r_0 = 6371.2; /* "mean radius" for spherical harmonic expansion */
|
||||
|
||||
static double gnm_wmm2000[13][13] =
|
||||
{
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-29616.0, -1722.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-2266.7, 3070.2, 1677.6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{1322.4, -2291.5, 1255.9, 724.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{932.1, 786.3, 250.6, -401.5, 106.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-211.9, 351.6, 220.8, -134.5, -168.8, -13.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{73.8, 68.2, 74.1, -163.5, -3.8, 17.1, -85.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{77.4, -73.9, 2.2, 35.7, 7.3, 5.2, 8.4, -1.5, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{23.3, 7.3, -8.5, -6.6, -16.9, 8.6, 4.9, -7.8, -7.6, 0.0, 0.0, 0.0, 0.0},
|
||||
{5.7, 8.5, 2.0, -9.8, 7.6, -7.0, -2.0, 9.2, -2.2, -6.6, 0.0, 0.0, 0.0},
|
||||
{-2.2, -5.7, 1.6, -3.7, -0.6, 4.1, 2.2, 2.2, 4.6, 2.3, 0.1, 0.0, 0.0},
|
||||
{3.3, -1.1, -2.4, 2.6, -1.3, -1.7, -0.6, 0.4, 0.7, -0.3, 2.3, 4.2, 0.0},
|
||||
{-1.5, -0.2, -0.3, 0.5, 0.2, 0.9, -1.4, 0.6, -0.6, -1.0, -0.3, 0.3, 0.4},
|
||||
};
|
||||
|
||||
static double hnm_wmm2000[13][13]=
|
||||
{
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 5194.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -2484.8, -467.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -224.7, 293.0, -486.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 273.3, -227.9, 120.9, -302.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 42.0, 173.8, -135.0, -38.6, 105.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -17.4, 61.2, 63.2, -62.9, 0.2, 43.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -62.3, -24.5, 8.9, 23.4, 15.0, -27.6, -7.8, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 12.4, -20.8, 8.4, -21.2, 15.5, 9.1, -15.5, -5.4, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -20.4, 13.9, 12.0, -6.2, -8.6, 9.4, 5.0, -8.4, 3.2, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.9, -0.7, 3.9, 4.8, -5.3, -1.0, -2.4, 1.3, -2.3, -6.4, 0.0, 0.0},
|
||||
{0.0, -1.5, 0.7, -1.1, -2.3, 1.3, -0.6, -2.8, -1.6, -0.1, -1.9, 1.4, 0.0},
|
||||
{0.0, -1.0, 0.7, 2.2, -2.5, -0.2, 0.0, -0.2, 0.0, 0.2, -0.9, -0.2, 1.0},
|
||||
};
|
||||
|
||||
static double gtnm_wmm2000[13][13]=
|
||||
{
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{14.7, 11.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-13.6, -0.7, -1.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.3, -4.3, 0.9, -8.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-1.6, 0.9, -7.6, 2.2, -3.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-0.9, -0.2, -2.5, -2.7, -0.9, 1.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{1.2, 0.2, 1.7, 1.6, -0.1, -0.3, 0.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-0.4, -0.8, -0.2, 1.1, 0.4, 0.0, -0.2, -0.2, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{-0.3, 0.6, -0.8, 0.3, -0.2, 0.5, 0.0, -0.6, 0.1, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
};
|
||||
|
||||
static double htnm_wmm2000[13][13]=
|
||||
{
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -20.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -21.5, -9.6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 6.4, -1.3, -13.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 2.3, 0.7, 3.7, -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 2.1, 2.3, 3.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -0.3, -1.7, -0.9, -1.0, -0.1, 1.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 1.4, 0.2, 0.7, 0.4, -0.3, -0.8, -0.1, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, -0.5, 0.1, -0.2, 0.0, 0.1, -0.1, 0.3, 0.2, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
};
|
||||
|
||||
static const int nmax = 12;
|
||||
|
||||
static double P[13][13];
|
||||
static double DP[13][13];
|
||||
static double gnm[13][13];
|
||||
static double hnm[13][13];
|
||||
static double sm[13];
|
||||
static double cm[13];
|
||||
|
||||
static double root[13];
|
||||
static double roots[13][13][2];
|
||||
|
||||
/* Convert date to Julian day 1950-2049 */
|
||||
unsigned long int yymmdd_to_julian_days( int yy, int mm, int dd )
|
||||
{
|
||||
unsigned long jd;
|
||||
|
||||
yy = (yy < 50) ? (2000 + yy) : (1900 + yy);
|
||||
jd = dd - 32075L + 1461L * (yy + 4800L + (mm - 14) / 12 ) / 4;
|
||||
jd = jd + 367L * (mm - 2 - (mm - 14) / 12*12) / 12;
|
||||
jd = jd - 3 * ((yy + 4900L + (mm - 14) / 12) / 100) / 4;
|
||||
|
||||
/* printf("julian date = %d\n", jd ); */
|
||||
return jd;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* return variation (in radians) given geodetic latitude (radians),
|
||||
* longitude(radians), height (km) and (Julian) date
|
||||
* N and E lat and long are positive, S and W negative
|
||||
*/
|
||||
|
||||
double calc_magvar( double lat, double lon, double h, long dat, double* field )
|
||||
{
|
||||
/* output field B_r,B_th,B_phi,B_x,B_y,B_z */
|
||||
int n,m;
|
||||
/* reference dates */
|
||||
long date0_wmm2000 = yymmdd_to_julian_days(0,1,1);
|
||||
|
||||
double yearfrac,sr,r,theta,c,s,psi,fn,fn_0,B_r,B_theta,B_phi,X,Y,Z;
|
||||
double sinpsi, cospsi, inv_s;
|
||||
|
||||
static int been_here = 0;
|
||||
|
||||
double sinlat = sin(lat);
|
||||
double coslat = cos(lat);
|
||||
|
||||
/* convert to geocentric coords: */
|
||||
// sr = sqrt(pow(a*coslat,2.0)+pow(b*sinlat,2.0));
|
||||
sr = sqrt(a*a*coslat*coslat + b*b*sinlat*sinlat);
|
||||
/* sr is effective radius */
|
||||
theta = atan2(coslat * (h*sr + a*a),
|
||||
sinlat * (h*sr + b*b));
|
||||
/* theta is geocentric co-latitude */
|
||||
|
||||
r = h*h + 2.0*h * sr +
|
||||
(a*a*a*a - ( a*a*a*a - b*b*b*b ) * sinlat*sinlat ) /
|
||||
(a*a - (a*a - b*b) * sinlat*sinlat );
|
||||
|
||||
r = sqrt(r);
|
||||
|
||||
/* r is geocentric radial distance */
|
||||
c = cos(theta);
|
||||
s = sin(theta);
|
||||
/* protect against zero divide at geographic poles */
|
||||
inv_s = 1.0 / (s + (s == 0.)*1.0e-8);
|
||||
|
||||
/* zero out arrays */
|
||||
for ( n = 0; n <= nmax; n++ ) {
|
||||
for ( m = 0; m <= n; m++ ) {
|
||||
P[n][m] = 0;
|
||||
DP[n][m] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* diagonal elements */
|
||||
P[0][0] = 1;
|
||||
P[1][1] = s;
|
||||
DP[0][0] = 0;
|
||||
DP[1][1] = c;
|
||||
P[1][0] = c ;
|
||||
DP[1][0] = -s;
|
||||
|
||||
// these values will not change for subsequent function calls
|
||||
if( !been_here ) {
|
||||
for ( n = 2; n <= nmax; n++ ) {
|
||||
root[n] = sqrt((2.0*n-1) / (2.0*n));
|
||||
}
|
||||
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
double mm = m*m;
|
||||
for ( n = max(m + 1, 2); n <= nmax; n++ ) {
|
||||
roots[m][n][0] = sqrt((n-1)*(n-1) - mm);
|
||||
roots[m][n][1] = 1.0 / sqrt( n*n - mm);
|
||||
}
|
||||
}
|
||||
been_here = 1;
|
||||
}
|
||||
|
||||
for ( n=2; n <= nmax; n++ ) {
|
||||
// double root = sqrt((2.0*n-1) / (2.0*n));
|
||||
P[n][n] = P[n-1][n-1] * s * root[n];
|
||||
DP[n][n] = (DP[n-1][n-1] * s + P[n-1][n-1] * c) *
|
||||
root[n];
|
||||
}
|
||||
|
||||
/* lower triangle */
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
// double mm = m*m;
|
||||
for ( n = max(m + 1, 2); n <= nmax; n++ ) {
|
||||
// double root1 = sqrt((n-1)*(n-1) - mm);
|
||||
// double root2 = 1.0 / sqrt( n*n - mm);
|
||||
P[n][m] = (P[n-1][m] * c * (2.0*n-1) -
|
||||
P[n-2][m] * roots[m][n][0]) *
|
||||
roots[m][n][1];
|
||||
|
||||
DP[n][m] = ((DP[n-1][m] * c - P[n-1][m] * s) *
|
||||
(2.0*n-1) - DP[n-2][m] * roots[m][n][0]) *
|
||||
roots[m][n][1];
|
||||
}
|
||||
}
|
||||
|
||||
/* compute gnm, hnm at dat */
|
||||
/* WMM2000 */
|
||||
yearfrac = (dat - date0_wmm2000) / 365.25;
|
||||
for ( n = 1; n <= nmax; n++ ) {
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
gnm[n][m] = gnm_wmm2000[n][m] + yearfrac * gtnm_wmm2000[n][m];
|
||||
hnm[n][m] = hnm_wmm2000[n][m] + yearfrac * htnm_wmm2000[n][m];
|
||||
}
|
||||
}
|
||||
|
||||
/* compute sm (sin(m lon) and cm (cos(m lon)) */
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
sm[m] = sin(m * lon);
|
||||
cm[m] = cos(m * lon);
|
||||
}
|
||||
|
||||
/* compute B fields */
|
||||
B_r = 0.0;
|
||||
B_theta = 0.0;
|
||||
B_phi = 0.0;
|
||||
fn_0 = r_0/r;
|
||||
fn = fn_0 * fn_0;
|
||||
|
||||
for ( n = 1; n <= nmax; n++ ) {
|
||||
double c1_n=0;
|
||||
double c2_n=0;
|
||||
double c3_n=0;
|
||||
for ( m = 0; m <= n; m++ ) {
|
||||
double tmp = (gnm[n][m] * cm[m] + hnm[n][m] * sm[m]);
|
||||
c1_n=c1_n + tmp * P[n][m];
|
||||
c2_n=c2_n + tmp * DP[n][m];
|
||||
c3_n=c3_n + m * (gnm[n][m] * sm[m] - hnm[n][m] * cm[m]) * P[n][m];
|
||||
}
|
||||
// fn=pow(r_0/r,n+2.0);
|
||||
fn *= fn_0;
|
||||
B_r = B_r + (n + 1) * c1_n * fn;
|
||||
B_theta = B_theta - c2_n * fn;
|
||||
B_phi = B_phi + c3_n * fn * inv_s;
|
||||
}
|
||||
|
||||
/* Find geodetic field components: */
|
||||
psi = theta - ((pi / 2.0) - lat);
|
||||
sinpsi = sin(psi);
|
||||
cospsi = cos(psi);
|
||||
X = -B_theta * cospsi - B_r * sinpsi;
|
||||
Y = B_phi;
|
||||
Z = B_theta * sinpsi - B_r * cospsi;
|
||||
|
||||
field[0]=B_r;
|
||||
field[1]=B_theta;
|
||||
field[2]=B_phi;
|
||||
field[3]=X;
|
||||
field[4]=Y;
|
||||
field[5]=Z; /* output fields */
|
||||
|
||||
/* find variation in radians */
|
||||
/* return zero variation at magnetic pole X=Y=0. */
|
||||
/* E is positive */
|
||||
return (X != 0. || Y != 0.) ? atan2(Y, X) : (double) 0.;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST_NHV_HACKS
|
||||
double SGMagVarOrig( double lat, double lon, double h, long dat, double* field )
|
||||
{
|
||||
/* output field B_r,B_th,B_phi,B_x,B_y,B_z */
|
||||
int n,m;
|
||||
/* reference dates */
|
||||
long date0_wmm2000 = yymmdd_to_julian_days(0,1,1);
|
||||
|
||||
double yearfrac,sr,r,theta,c,s,psi,fn,B_r,B_theta,B_phi,X,Y,Z;
|
||||
|
||||
/* convert to geocentric coords: */
|
||||
sr = sqrt(pow(a*cos(lat),2.0)+pow(b*sin(lat),2.0));
|
||||
/* sr is effective radius */
|
||||
theta = atan2(cos(lat) * (h * sr + a * a),
|
||||
sin(lat) * (h * sr + b * b));
|
||||
/* theta is geocentric co-latitude */
|
||||
|
||||
r = h * h + 2.0*h * sr +
|
||||
(pow(a,4.0) - (pow(a,4.0) - pow(b,4.0)) * pow(sin(lat),2.0)) /
|
||||
(a * a - (a * a - b * b) * pow(sin(lat),2.0));
|
||||
|
||||
r = sqrt(r);
|
||||
|
||||
/* r is geocentric radial distance */
|
||||
c = cos(theta);
|
||||
s = sin(theta);
|
||||
|
||||
/* zero out arrays */
|
||||
for ( n = 0; n <= nmax; n++ ) {
|
||||
for ( m = 0; m <= n; m++ ) {
|
||||
P[n][m] = 0;
|
||||
DP[n][m] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* diagonal elements */
|
||||
P[0][0] = 1;
|
||||
P[1][1] = s;
|
||||
DP[0][0] = 0;
|
||||
DP[1][1] = c;
|
||||
P[1][0] = c ;
|
||||
DP[1][0] = -s;
|
||||
|
||||
for ( n = 2; n <= nmax; n++ ) {
|
||||
P[n][n] = P[n-1][n-1] * s * sqrt((2.0*n-1) / (2.0*n));
|
||||
DP[n][n] = (DP[n-1][n-1] * s + P[n-1][n-1] * c) *
|
||||
sqrt((2.0*n-1) / (2.0*n));
|
||||
}
|
||||
|
||||
/* lower triangle */
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
for ( n = max(m + 1, 2); n <= nmax; n++ ) {
|
||||
P[n][m] = (P[n-1][m] * c * (2.0*n-1) - P[n-2][m] *
|
||||
sqrt(1.0*(n-1)*(n-1) - m * m)) /
|
||||
sqrt(1.0* n * n - m * m);
|
||||
DP[n][m] = ((DP[n-1][m] * c - P[n-1][m] * s) *
|
||||
(2.0*n-1) - DP[n-2][m] *
|
||||
sqrt(1.0*(n-1) * (n-1) - m * m)) /
|
||||
sqrt(1.0* n * n - m * m);
|
||||
}
|
||||
}
|
||||
|
||||
/* compute gnm, hnm at dat */
|
||||
/* WMM2000 */
|
||||
yearfrac = (dat - date0_wmm2000) / 365.25;
|
||||
for ( n = 1; n <= nmax; n++ ) {
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
gnm[n][m] = gnm_wmm2000[n][m] + yearfrac * gtnm_wmm2000[n][m];
|
||||
hnm[n][m] = hnm_wmm2000[n][m] + yearfrac * htnm_wmm2000[n][m];
|
||||
}
|
||||
}
|
||||
|
||||
/* compute sm (sin(m lon) and cm (cos(m lon)) */
|
||||
for ( m = 0; m <= nmax; m++ ) {
|
||||
sm[m] = sin(m * lon);
|
||||
cm[m] = cos(m * lon);
|
||||
}
|
||||
|
||||
/* compute B fields */
|
||||
B_r = 0.0;
|
||||
B_theta = 0.0;
|
||||
B_phi = 0.0;
|
||||
|
||||
for ( n = 1; n <= nmax; n++ ) {
|
||||
double c1_n=0;
|
||||
double c2_n=0;
|
||||
double c3_n=0;
|
||||
for ( m = 0; m <= n; m++ ) {
|
||||
c1_n=c1_n + (gnm[n][m] * cm[m] + hnm[n][m] * sm[m]) * P[n][m];
|
||||
c2_n=c2_n + (gnm[n][m] * cm[m] + hnm[n][m] * sm[m]) * DP[n][m];
|
||||
c3_n=c3_n + m * (gnm[n][m] * sm[m] - hnm[n][m] * cm[m]) * P[n][m];
|
||||
}
|
||||
fn=pow(r_0/r,n+2.0);
|
||||
B_r = B_r + (n + 1) * c1_n * fn;
|
||||
B_theta = B_theta - c2_n * fn;
|
||||
B_phi = B_phi + c3_n * fn / s;
|
||||
}
|
||||
|
||||
/* Find geodetic field components: */
|
||||
psi = theta - (pi / 2.0 - lat);
|
||||
X = -B_theta * cos(psi) - B_r * sin(psi);
|
||||
Y = B_phi;
|
||||
Z = B_theta * sin(psi) - B_r * cos(psi);
|
||||
|
||||
field[0]=B_r;
|
||||
field[1]=B_theta;
|
||||
field[2]=B_phi;
|
||||
field[3]=X;
|
||||
field[4]=Y;
|
||||
field[5]=Z; /* output fields */
|
||||
|
||||
/* find variation, leave in radians! */
|
||||
return atan2(Y, X); /* E is positive */
|
||||
}
|
||||
#endif // TEST_NHV_HACKS
|
||||
51
simgear/magvar/coremag.hxx
Normal file
51
simgear/magvar/coremag.hxx
Normal file
@@ -0,0 +1,51 @@
|
||||
// coremag.hxx -- compute local magnetic variation given position,
|
||||
// altitude, and date
|
||||
//
|
||||
// This is an implimentation of the NIMA WMM 2000
|
||||
//
|
||||
// http://www.nima.mil/GandG/ngdc-wmm2000.html
|
||||
//
|
||||
// Copyright (C) 2000 Edward A Williams <Ed_Williams@compuserve.com>
|
||||
//
|
||||
// Adapted from Excel 3.0 version 3/27/94 EAW
|
||||
// Recoded in C++ by Starry Chan
|
||||
// WMM95 added and rearranged in ANSI-C EAW 7/9/95
|
||||
// Put shell around program and made Borland & GCC compatible EAW 11/22/95
|
||||
// IGRF95 added 2/96 EAW
|
||||
// WMM2000 IGR2000 added 2/00 EAW
|
||||
// Released under GPL 3/26/00 EAW
|
||||
// Adaptions and modifications for the SimGear project 3/27/2000 CLO
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef SG_MAGVAR_HXX
|
||||
#define SG_MAGVAR_HXX
|
||||
|
||||
|
||||
/* Convert date to Julian day 1950-2049 */
|
||||
unsigned long int yymmdd_to_julian_days( int yy, int mm, int dd );
|
||||
|
||||
/* return variation (in degrees) given geodetic latitude (radians), longitude
|
||||
(radians) ,height (km) and (Julian) date
|
||||
N and E lat and long are positive, S and W negative
|
||||
*/
|
||||
double calc_magvar( double lat, double lon, double h, long dat, double* field );
|
||||
|
||||
|
||||
#endif // SG_MAGVAR_HXX
|
||||
@@ -1,8 +1,8 @@
|
||||
// stars.hxx -- data structures and routines for managing and rendering stars.
|
||||
// magvar.cxx -- magnetic variation wrapper class
|
||||
//
|
||||
// Written by Curtis Olson, started August 1997.
|
||||
// Written by Curtis Olson, started July 2000.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
@@ -21,27 +21,31 @@
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _STARS_HXX
|
||||
#define _STARS_HXX
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <simgear/misc/fgpath.hxx>
|
||||
#include <simgear/magvar/magvar.hxx>
|
||||
|
||||
#include "coremag.hxx"
|
||||
#include "magvar.hxx"
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
SGMagVar::SGMagVar() {
|
||||
}
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#define FG_STAR_LEVELS 8 // how many star transitions
|
||||
|
||||
// Initialize the Star Management Subsystem
|
||||
int fgStarsInit( void );
|
||||
|
||||
// Draw the Stars
|
||||
void fgStarsRender( void );
|
||||
|
||||
// [no longer used?] extern FGTime cur_time_params;
|
||||
SGMagVar::~SGMagVar() {
|
||||
}
|
||||
|
||||
|
||||
#endif // _STARS_HXX
|
||||
|
||||
void SGMagVar::update( double lon, double lat, double alt_m, double jd ) {
|
||||
// Calculate local magnetic variation
|
||||
double field[6];
|
||||
// cout << "alt_m = " << alt_m << endl;
|
||||
magvar = calc_magvar( lat, lon, alt_m / 1000.0, (long)jd, field );
|
||||
magdip = atan(field[5]/sqrt(field[3]*field[3]+field[4]*field[4]));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// sky.hxx -- model sky with an upside down "bowl"
|
||||
// magvar.hxx -- magnetic variation wrapper class
|
||||
//
|
||||
// Written by Curtis Olson, started December 1997.
|
||||
// Written by Curtis Olson, started July 2000.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
@@ -21,8 +21,8 @@
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SKY_HXX
|
||||
#define _SKY_HXX
|
||||
#ifndef _MAGVAR_HXX
|
||||
#define _MAGVAR_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
@@ -30,24 +30,29 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include <ssg.h> // plib include
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
class fgSky : ssgLeaf
|
||||
{
|
||||
class SGMagVar {
|
||||
|
||||
private:
|
||||
|
||||
double magvar;
|
||||
double magdip;
|
||||
|
||||
public:
|
||||
|
||||
SGMagVar();
|
||||
~SGMagVar();
|
||||
|
||||
// recalculate the magnetic offset and dip
|
||||
void update( double lon, double lat, double alt_m, double jd );
|
||||
|
||||
double get_magvar() const { return magvar; }
|
||||
double get_magdip() const { return magdip; }
|
||||
};
|
||||
|
||||
|
||||
// (Re)generate the display list
|
||||
void fgSkyInit( void );
|
||||
|
||||
// (Re)calculate the sky colors at each vertex
|
||||
void fgSkyColorsInit( void );
|
||||
|
||||
// Draw the Sky
|
||||
void fgSkyRender( void );
|
||||
|
||||
|
||||
#endif // _SKY_HXX
|
||||
|
||||
|
||||
#endif // _LIGHT_HXX
|
||||
58
simgear/magvar/testmagvar.cxx
Normal file
58
simgear/magvar/testmagvar.cxx
Normal file
@@ -0,0 +1,58 @@
|
||||
/* 2/14/00 fixed help message- dip angle (down positive), variation (E positive) */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <simgear/constants.h>
|
||||
|
||||
#include "coremag.hxx"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* args are double lat_deg, double lon_deg, double h,
|
||||
int mm, int dd, int yy,int model */
|
||||
/* output N, E, down components of B (nTesla)
|
||||
dip angle (down positive), variation (E positive) */
|
||||
double lat_deg,lon_deg,h,var;
|
||||
int model,yy,mm,dd;
|
||||
double field[6];
|
||||
|
||||
if ((argc != 8) && (argc !=7)) {
|
||||
fprintf(stdout,"Usage: mag lat_deg lon_deg h mm dd yy [model]\n");
|
||||
fprintf(stdout,"N latitudes, E longitudes positive degrees, h in km, mm dd yy is date\n");
|
||||
fprintf(stdout,"model 1,2,3,4,5,6,7 <=> IGRF90,WMM85,WMM90,WMM95,IGRF95,WMM2000,IGRF2000\n");
|
||||
fprintf(stdout,"Default model is IGRF2000, valid 1/1/00 - 12/31/05\n");
|
||||
fprintf(stdout,"Output Bx (N) By (E) Bz (down) (in nTesla) dip (degrees down positive)\n");
|
||||
fprintf(stdout,"variation (degrees E positive)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
lat_deg=strtod(argv[1],NULL);
|
||||
lon_deg=strtod(argv[2],NULL);
|
||||
h= strtod(argv[3],NULL);
|
||||
mm= (int)strtol(argv[4],NULL,10);
|
||||
dd= (int)strtol(argv[5],NULL,10);
|
||||
yy= (int)strtol(argv[6],NULL,10);
|
||||
if (argc == 8){
|
||||
model= (int)strtol(argv[7],NULL,10);
|
||||
}else{
|
||||
model=7;
|
||||
}
|
||||
|
||||
|
||||
var = calc_magvar( DEG_TO_RAD * lat_deg, DEG_TO_RAD * lon_deg, h,
|
||||
yymmdd_to_julian_days(yy,mm,dd), field );
|
||||
|
||||
fprintf(stdout,"%6.0lf %6.0lf %6.0lf\n", field[0], field[1], field[2] );
|
||||
fprintf(stdout,"%6.0lf %6.0lf %6.0lf\n", field[3], field[4], field[5] );
|
||||
fprintf(stdout,"%6.0lf %6.0lf %6.0lf %4.2lf %4.2lf \n",
|
||||
field[3],field[4],field[5],
|
||||
RAD_TO_DEG * (atan(field[5]/pow(field[3]*field[3]+field[4]*field[4],0.5))),
|
||||
RAD_TO_DEG * var);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
33
simgear/math/Makefile.am
Normal file
33
simgear/math/Makefile.am
Normal file
@@ -0,0 +1,33 @@
|
||||
includedir = @includedir@/math
|
||||
|
||||
if HAVE_ZLIB
|
||||
ZLIB_INCL =
|
||||
else
|
||||
ZLIB_INCL = -I$(top_srcdir)/src/zlib
|
||||
endif
|
||||
|
||||
lib_LIBRARIES = libsgmath.a
|
||||
|
||||
include_HEADERS = \
|
||||
fg_memory.h \
|
||||
interpolater.hxx \
|
||||
leastsqs.hxx \
|
||||
localconsts.hxx \
|
||||
point3d.hxx \
|
||||
polar3d.hxx \
|
||||
sg_geodesy.hxx \
|
||||
sg_random.h \
|
||||
sg_types.hxx \
|
||||
vector.hxx
|
||||
|
||||
EXTRA_DIST = linintp2.h linintp2.inl sphrintp.h sphrintp.inl
|
||||
|
||||
libsgmath_a_SOURCES = \
|
||||
interpolater.cxx \
|
||||
leastsqs.cxx \
|
||||
polar3d.cxx \
|
||||
sg_geodesy.cxx \
|
||||
sg_random.c \
|
||||
vector.cxx
|
||||
|
||||
INCLUDES += -I$(top_srcdir) $(ZLIB_INCL)
|
||||
60
simgear/math/fg_memory.h
Normal file
60
simgear/math/fg_memory.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// fg_memory.h -- memcpy/bcopy portability declarations
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _FG_MEMORY_H
|
||||
#define _FG_MEMORY_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MEMCPY
|
||||
|
||||
# ifdef HAVE_MEMORY_H
|
||||
# include <memory.h>
|
||||
# endif
|
||||
|
||||
# define fgmemcmp memcmp
|
||||
# define fgmemcpy memcpy
|
||||
# define fgmemzero(dest,len) memset(dest,0,len)
|
||||
|
||||
#elif defined(HAVE_BCOPY)
|
||||
|
||||
# define fgmemcmp bcmp
|
||||
# define fgmemcpy(dest,src,n) bcopy(src,dest,n)
|
||||
# define fgmemzero bzero
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Neither memcpy() or bcopy() available.
|
||||
* Use substitutes provided be zlib.
|
||||
*/
|
||||
|
||||
# include <zutil.h>
|
||||
# define fgmemcmp zmemcmp
|
||||
# define fgmemcpy zmemcpy
|
||||
# define fgmemzero zmemzero
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _FG_MEMORY_H
|
||||
|
||||
|
||||
108
simgear/math/interpolater.cxx
Normal file
108
simgear/math/interpolater.cxx
Normal file
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// interpolater.cxx -- routines to handle linear interpolation from a table of
|
||||
// x,y The table must be sorted by "x" in ascending order
|
||||
//
|
||||
// Written by Curtis Olson, started April 1998.
|
||||
//
|
||||
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef __MWERKS__
|
||||
#include <stdlib.h> // for exit()
|
||||
#endif
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
#include <simgear/fg_zlib.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/fgstream.hxx>
|
||||
|
||||
#include "interpolater.hxx"
|
||||
|
||||
|
||||
// Constructor -- loads the interpolation table from the specified
|
||||
// file
|
||||
fgINTERPTABLE::fgINTERPTABLE( const string& file ) {
|
||||
FG_LOG( FG_MATH, FG_INFO, "Initializing Interpolator for " << file );
|
||||
|
||||
fg_gzifstream in( file );
|
||||
if ( !in ) {
|
||||
FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << file );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
size = 0;
|
||||
in >> skipcomment;
|
||||
while ( in ) {
|
||||
if ( size < MAX_TABLE_SIZE ) {
|
||||
in >> table[size][0] >> table[size][1];
|
||||
size++;
|
||||
} else {
|
||||
FG_LOG( FG_MATH, FG_ALERT,
|
||||
"fgInterpolateInit(): Exceed max table size = "
|
||||
<< MAX_TABLE_SIZE );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Given an x value, linearly interpolate the y value from the table
|
||||
double fgINTERPTABLE::interpolate(double x) {
|
||||
int i;
|
||||
double y;
|
||||
|
||||
i = 0;
|
||||
|
||||
while ( (x > table[i][0]) && (i < size) ) {
|
||||
i++;
|
||||
}
|
||||
|
||||
// printf ("i = %d ", i);
|
||||
|
||||
if ( (i == 0) && (x < table[0][0]) ) {
|
||||
FG_LOG( FG_MATH, FG_ALERT,
|
||||
"fgInterpolateInit(): lookup error, x to small = " << x );
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
if ( x > table[i][0] ) {
|
||||
FG_LOG( FG_MATH, FG_ALERT,
|
||||
"fgInterpolateInit(): lookup error, x to big = " << x );
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
// y = y1 + (y0 - y1)(x - x1) / (x0 - x1)
|
||||
y = table[i][1] +
|
||||
( (table[i-1][1] - table[i][1]) *
|
||||
(x - table[i][0]) ) /
|
||||
(table[i-1][0] - table[i][0]);
|
||||
|
||||
return(y);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
fgINTERPTABLE::~fgINTERPTABLE( void ) {
|
||||
}
|
||||
|
||||
|
||||
63
simgear/math/interpolater.hxx
Normal file
63
simgear/math/interpolater.hxx
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// interpolater.hxx -- routines to handle linear interpolation from a table of
|
||||
// x,y The table must be sorted by "x" in ascending order
|
||||
//
|
||||
// Written by Curtis Olson, started April 1998.
|
||||
//
|
||||
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _INTERPOLATER_H
|
||||
#define _INTERPOLATER_H
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
FG_USING_STD(string);
|
||||
|
||||
#define MAX_TABLE_SIZE 32
|
||||
|
||||
|
||||
class fgINTERPTABLE {
|
||||
int size;
|
||||
double table[MAX_TABLE_SIZE][2];
|
||||
|
||||
public:
|
||||
|
||||
// Constructor -- loads the interpolation table from the specified
|
||||
// file
|
||||
fgINTERPTABLE( const string& file );
|
||||
|
||||
// Given an x value, linearly interpolate the y value from the table
|
||||
double interpolate(double x);
|
||||
|
||||
// Destructor
|
||||
~fgINTERPTABLE( void );
|
||||
};
|
||||
|
||||
|
||||
#endif // _INTERPOLATER_H
|
||||
|
||||
|
||||
136
simgear/math/leastsqs.cxx
Normal file
136
simgear/math/leastsqs.cxx
Normal file
@@ -0,0 +1,136 @@
|
||||
// leastsqs.c -- Implements a simple linear least squares best fit routine
|
||||
//
|
||||
// Written by Curtis Olson, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "leastsqs.hxx"
|
||||
|
||||
|
||||
/*
|
||||
Least squares fit:
|
||||
|
||||
y = b0 + b1x
|
||||
|
||||
n*sum(xi*yi) - (sum(xi)*sum(yi))
|
||||
b1 = --------------------------------
|
||||
n*sum(xi^2) - (sum(xi))^2
|
||||
|
||||
|
||||
b0 = sum(yi)/n - b1*(sum(xi)/n)
|
||||
*/
|
||||
|
||||
double sum_xi, sum_yi, sum_xi_2, sum_xi_yi;
|
||||
int sum_n;
|
||||
|
||||
void least_squares(double *x, double *y, int n, double *m, double *b) {
|
||||
int i;
|
||||
|
||||
sum_xi = sum_yi = sum_xi_2 = sum_xi_yi = 0.0;
|
||||
sum_n = n;
|
||||
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
sum_xi += x[i];
|
||||
sum_yi += y[i];
|
||||
sum_xi_2 += x[i] * x[i];
|
||||
sum_xi_yi += x[i] * y[i];
|
||||
}
|
||||
|
||||
/* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n",
|
||||
sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */
|
||||
|
||||
*m = ( (double)sum_n * sum_xi_yi - sum_xi * sum_yi ) /
|
||||
( (double)sum_n * sum_xi_2 - sum_xi * sum_xi );
|
||||
*b = (sum_yi / (double)sum_n) - (*m) * (sum_xi / (double)sum_n);
|
||||
|
||||
/* printf("slope = %.2f intercept = %.2f\n", *m, *b); */
|
||||
}
|
||||
|
||||
|
||||
/* incrimentally update existing values with a new data point */
|
||||
void least_squares_update(double x, double y, double *m, double *b) {
|
||||
++sum_n;
|
||||
|
||||
sum_xi += x;
|
||||
sum_yi += y;
|
||||
sum_xi_2 += x * x;
|
||||
sum_xi_yi += x * y;
|
||||
|
||||
/* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n",
|
||||
sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */
|
||||
|
||||
*m = ( (double)sum_n * sum_xi_yi - sum_xi * sum_yi ) /
|
||||
( (double)sum_n * sum_xi_2 - sum_xi * sum_xi );
|
||||
*b = (sum_yi / (double)sum_n) - (*m) * (sum_xi / (double)sum_n);
|
||||
|
||||
/* printf("slope = %.2f intercept = %.2f\n", *m, *b); */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
return the least squares error:
|
||||
|
||||
(y[i] - y_hat[i])^2
|
||||
-------------------
|
||||
n
|
||||
*/
|
||||
double least_squares_error(double *x, double *y, int n, double m, double b) {
|
||||
int i;
|
||||
double error, sum;
|
||||
|
||||
sum = 0.0;
|
||||
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
error = y[i] - (m * x[i] + b);
|
||||
sum += error * error;
|
||||
// printf("%.2f %.2f\n", error, sum);
|
||||
}
|
||||
|
||||
return ( sum / (double)n );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
return the maximum least squares error:
|
||||
|
||||
(y[i] - y_hat[i])^2
|
||||
*/
|
||||
double least_squares_max_error(double *x, double *y, int n, double m, double b){
|
||||
int i;
|
||||
double error, max_error;
|
||||
|
||||
max_error = 0.0;
|
||||
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
error = y[i] - (m * x[i] + b);
|
||||
error = error * error;
|
||||
if ( error > max_error ) {
|
||||
max_error = error;
|
||||
}
|
||||
}
|
||||
|
||||
return ( max_error );
|
||||
}
|
||||
|
||||
|
||||
74
simgear/math/leastsqs.hxx
Normal file
74
simgear/math/leastsqs.hxx
Normal file
@@ -0,0 +1,74 @@
|
||||
// leastsqs.h -- Implements a simple linear least squares best fit routine
|
||||
//
|
||||
// Written by Curtis Olson, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
///
|
||||
|
||||
|
||||
#ifndef _LEASTSQS_H
|
||||
#define _LEASTSQS_H
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Least squares fit:
|
||||
|
||||
y = b0 + b1x
|
||||
|
||||
n*sum(xi*yi) - (sum(xi)*sum(yi))
|
||||
b1 = --------------------------------
|
||||
n*sum(xi^2) - (sum(xi))^2
|
||||
|
||||
|
||||
b0 = sum(yi)/n - b1*(sum(xi)/n)
|
||||
*/
|
||||
|
||||
void least_squares(double *x, double *y, int n, double *m, double *b);
|
||||
|
||||
/* incrimentally update existing values with a new data point */
|
||||
void least_squares_update(double x, double y, double *m, double *b);
|
||||
|
||||
|
||||
/*
|
||||
return the least squares error:
|
||||
|
||||
(y[i] - y_hat[i])^2
|
||||
-------------------
|
||||
n
|
||||
*/
|
||||
double least_squares_error(double *x, double *y, int n, double m, double b);
|
||||
|
||||
|
||||
/*
|
||||
return the maximum least squares error:
|
||||
|
||||
(y[i] - y_hat[i])^2
|
||||
*/
|
||||
double least_squares_max_error(double *x, double *y, int n, double m, double b);
|
||||
|
||||
|
||||
#endif // _LEASTSQS_H
|
||||
|
||||
|
||||
110
simgear/math/linintp2.h
Normal file
110
simgear/math/linintp2.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
WARNING - Do not remove this header.
|
||||
|
||||
This code is a templated version of the 'magic-software' spherical
|
||||
interpolation code by Dave Eberly. The original (un-hacked) code can be
|
||||
obtained from here: http://www.magic-software.com/gr_appr.htm
|
||||
This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
|
||||
|
||||
Dave Eberly says that the conditions for use are:
|
||||
|
||||
* You may distribute the original source code to others at no charge.
|
||||
|
||||
* You may modify the original source code and distribute it to others at
|
||||
no charge. The modified code must be documented to indicate that it is
|
||||
not part of the original package.
|
||||
|
||||
* You may use this code for non-commercial purposes. You may also
|
||||
incorporate this code into commercial packages. However, you may not
|
||||
sell any of your source code which contains my original and/or modified
|
||||
source code. In such a case, you need to factor out my code and freely
|
||||
distribute it.
|
||||
|
||||
* The original code comes with absolutely no warranty and no guarantee is
|
||||
made that the code is bug-free.
|
||||
|
||||
This does not seem incompatible with GPL - so this modified version
|
||||
is hereby placed under GPL along with the rest of FlightGear.
|
||||
|
||||
Christian Mayer
|
||||
*/
|
||||
|
||||
#ifndef LININTP2_H
|
||||
#define LININTP2_H
|
||||
|
||||
template<class T>
|
||||
class mgcLinInterp2D
|
||||
{
|
||||
public:
|
||||
mgcLinInterp2D (int _numPoints, double* x, double* y, T* _f);
|
||||
|
||||
~mgcLinInterp2D ();
|
||||
|
||||
double XMin () { return xmin; }
|
||||
double XMax () { return xmax; }
|
||||
double XRange () { return xmax-xmin; }
|
||||
double YMin () { return ymin; }
|
||||
double YMax () { return ymax; }
|
||||
double YRange () { return ymax-ymin; }
|
||||
|
||||
int PointCount () { return numPoints; }
|
||||
void GetPoint (int i, double& x, double& y);
|
||||
|
||||
int EdgeCount () { return numEdges; }
|
||||
void GetEdge (int i, double& x0, double& y0, double& x1, double& y1);
|
||||
|
||||
int TriangleCount () { return numTriangles; }
|
||||
void GetTriangle (int i, double& x0, double& y0, double& x1, double& y1,
|
||||
double& x2, double& y2);
|
||||
|
||||
int Evaluate (double x, double y, T& F);
|
||||
|
||||
private:
|
||||
typedef struct
|
||||
{
|
||||
double x, y;
|
||||
}
|
||||
Vertex;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int vertex[3]; // listed in counterclockwise order
|
||||
|
||||
int adj[3];
|
||||
// adj[0] points to triangle sharing edge (vertex[0],vertex[1])
|
||||
// adj[1] points to triangle sharing edge (vertex[1],vertex[2])
|
||||
// adj[2] points to triangle sharing edge (vertex[2],vertex[0])
|
||||
}
|
||||
Triangle;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int vertex[2];
|
||||
int triangle[2];
|
||||
int index[2];
|
||||
}
|
||||
Edge;
|
||||
|
||||
int numPoints;
|
||||
double** point;
|
||||
double** tmppoint;
|
||||
T* f;
|
||||
|
||||
double xmin, xmax, ymin, ymax;
|
||||
|
||||
|
||||
int numEdges;
|
||||
Edge* edge;
|
||||
|
||||
int numTriangles;
|
||||
Triangle* triangle;
|
||||
|
||||
int Delaunay2D ();
|
||||
void ComputeBarycenter (Vertex& v0, Vertex& v1, Vertex& v2, Vertex& ver,
|
||||
double c[3]);
|
||||
int InTriangle (Vertex& v0, Vertex& v1, Vertex& v2, Vertex& test);
|
||||
};
|
||||
|
||||
#include "linintp2.inl"
|
||||
|
||||
#endif
|
||||
540
simgear/math/linintp2.inl
Normal file
540
simgear/math/linintp2.inl
Normal file
@@ -0,0 +1,540 @@
|
||||
/*
|
||||
WARNING - Do not remove this header.
|
||||
|
||||
This code is a templated version of the 'magic-software' spherical
|
||||
interpolation code by Dave Eberly. The original (un-hacked) code can be
|
||||
obtained from here: http://www.magic-software.com/gr_appr.htm
|
||||
This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
|
||||
|
||||
Dave Eberly says that the conditions for use are:
|
||||
|
||||
* You may distribute the original source code to others at no charge.
|
||||
|
||||
* You may modify the original source code and distribute it to others at
|
||||
no charge. The modified code must be documented to indicate that it is
|
||||
not part of the original package.
|
||||
|
||||
* You may use this code for non-commercial purposes. You may also
|
||||
incorporate this code into commercial packages. However, you may not
|
||||
sell any of your source code which contains my original and/or modified
|
||||
source code. In such a case, you need to factor out my code and freely
|
||||
distribute it.
|
||||
|
||||
* The original code comes with absolutely no warranty and no guarantee is
|
||||
made that the code is bug-free.
|
||||
|
||||
This does not seem incompatible with GPL - so this modified version
|
||||
is hereby placed under GPL along with the rest of FlightGear.
|
||||
|
||||
Christian Mayer
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "linintp2.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
mgcLinInterp2D<T>::mgcLinInterp2D (int _numPoints, double* x, double* y,
|
||||
T* _f)
|
||||
{
|
||||
if ( (numPoints = _numPoints) < 3 )
|
||||
{
|
||||
point = 0;
|
||||
edge = 0;
|
||||
triangle = 0;
|
||||
numTriangles = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "[ 20%] allocating memory \r";
|
||||
|
||||
point = new double*[numPoints];
|
||||
tmppoint = new double*[numPoints+3];
|
||||
f = new T[numPoints];
|
||||
int i;
|
||||
for (i = 0; i < numPoints; i++)
|
||||
point[i] = new double[2];
|
||||
for (i = 0; i < numPoints+3; i++)
|
||||
tmppoint[i] = new double[2];
|
||||
for (i = 0; i < numPoints; i++)
|
||||
{
|
||||
point[i][0] = tmppoint[i][0] = x[i];
|
||||
point[i][1] = tmppoint[i][1] = y[i];
|
||||
|
||||
f[i] = _f[i];
|
||||
}
|
||||
|
||||
cout << "[ 30%] creating delaunay diagram \r";
|
||||
|
||||
Delaunay2D();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
mgcLinInterp2D<T>::~mgcLinInterp2D ()
|
||||
{
|
||||
if ( numPoints < 3 )
|
||||
return;
|
||||
|
||||
int i;
|
||||
|
||||
if ( point )
|
||||
{
|
||||
for (i = 0; i < numPoints; i++)
|
||||
delete[] point[i];
|
||||
delete[] point;
|
||||
}
|
||||
if ( tmppoint )
|
||||
{
|
||||
for (i = 0; i < numPoints+3; i++)
|
||||
delete[] tmppoint[i];
|
||||
delete[] tmppoint;
|
||||
}
|
||||
|
||||
delete[] f;
|
||||
delete[] edge;
|
||||
delete[] triangle;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
void mgcLinInterp2D<T>::ComputeBarycenter (Vertex& v0, Vertex& v1, Vertex& v2,
|
||||
Vertex& ver, double c[3])
|
||||
{
|
||||
double A0 = v0.x-v2.x, B0 = v0.y-v2.y;
|
||||
double A1 = v1.x-v2.x, B1 = v1.y-v2.y;
|
||||
double A2 = ver.x-v2.x, B2 = ver.y-v2.y;
|
||||
|
||||
double m00 = A0*A0+B0*B0, m01 = A0*A1+B0*B1, m11 = A1*A1+B1*B1;
|
||||
double r0 = A2*A0+B2*B0, r1 = A2*A1+B2*B1;
|
||||
double det = m00*m11-m01*m01;
|
||||
|
||||
c[0] = (m11*r0-m01*r1)/det;
|
||||
c[1] = (m00*r1-m01*r0)/det;
|
||||
c[2] = 1-c[0]-c[1];
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
int mgcLinInterp2D<T>::InTriangle (Vertex& v0, Vertex& v1, Vertex& v2,
|
||||
Vertex& test)
|
||||
{
|
||||
const double eps = 1e-08;
|
||||
double tx, ty, nx, ny;
|
||||
|
||||
// test against normal to first edge
|
||||
tx = test.x - v0.x;
|
||||
ty = test.y - v0.y;
|
||||
nx = v0.y - v1.y;
|
||||
ny = v1.x - v0.x;
|
||||
if ( tx*nx + ty*ny < -eps )
|
||||
return 0;
|
||||
|
||||
// test against normal to second edge
|
||||
tx = test.x - v1.x;
|
||||
ty = test.y - v1.y;
|
||||
nx = v1.y - v2.y;
|
||||
ny = v2.x - v1.x;
|
||||
if ( tx*nx + ty*ny < -eps )
|
||||
return 0;
|
||||
|
||||
// test against normal to third edge
|
||||
tx = test.x - v2.x;
|
||||
ty = test.y - v2.y;
|
||||
nx = v2.y - v0.y;
|
||||
ny = v0.x - v2.x;
|
||||
if ( tx*nx + ty*ny < -eps )
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
int mgcLinInterp2D<T>::Evaluate (double x, double y, T& F)
|
||||
{
|
||||
Vertex ver = { x, y };
|
||||
// determine which triangle contains the target point
|
||||
|
||||
int i;
|
||||
Vertex v0, v1, v2;
|
||||
for (i = 0; i < numTriangles; i++)
|
||||
{
|
||||
Triangle& t = triangle[i];
|
||||
v0.x = point[t.vertex[0]][0];
|
||||
v0.y = point[t.vertex[0]][1];
|
||||
v1.x = point[t.vertex[1]][0];
|
||||
v1.y = point[t.vertex[1]][1];
|
||||
v2.x = point[t.vertex[2]][0];
|
||||
v2.y = point[t.vertex[2]][1];
|
||||
|
||||
if ( InTriangle(v0,v1,v2,ver) )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( i == numTriangles ) // point is outside interpolation region
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Triangle& t = triangle[i]; // (x,y) is in this triangle
|
||||
|
||||
// compute barycentric coordinates with respect to subtriangle
|
||||
double bary[3];
|
||||
ComputeBarycenter(v0,v1,v2,ver,bary);
|
||||
|
||||
// compute barycentric combination of function values at vertices
|
||||
F = bary[0]*f[t.vertex[0]]+bary[1]*f[t.vertex[1]]+bary[2]*f[t.vertex[2]];
|
||||
|
||||
return 1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
int mgcLinInterp2D<T>::Delaunay2D ()
|
||||
{
|
||||
int result;
|
||||
|
||||
const double EPSILON = 1e-12;
|
||||
const int TSIZE = 75;
|
||||
const double RANGE = 10.0;
|
||||
|
||||
xmin = tmppoint[0][0];
|
||||
xmax = xmin;
|
||||
ymin = tmppoint[0][1];
|
||||
ymax = ymin;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < numPoints; i++)
|
||||
{
|
||||
double value = tmppoint[i][0];
|
||||
if ( xmax < value )
|
||||
xmax = value;
|
||||
if ( xmin > value )
|
||||
xmin = value;
|
||||
|
||||
value = tmppoint[i][1];
|
||||
if ( ymax < value )
|
||||
ymax = value;
|
||||
if ( ymin > value )
|
||||
ymin = value;
|
||||
}
|
||||
|
||||
double xrange = xmax-xmin, yrange = ymax-ymin;
|
||||
double maxrange = xrange;
|
||||
if ( maxrange < yrange )
|
||||
maxrange = yrange;
|
||||
|
||||
// need to scale the data later to do a correct triangle count
|
||||
double maxrange2 = maxrange*maxrange;
|
||||
|
||||
// tweak the points by very small random numbers
|
||||
double bgs = EPSILON*maxrange;
|
||||
srand(367);
|
||||
for (i = 0; i < numPoints; i++)
|
||||
{
|
||||
tmppoint[i][0] += bgs*(0.5 - rand()/double(RAND_MAX));
|
||||
tmppoint[i][1] += bgs*(0.5 - rand()/double(RAND_MAX));
|
||||
}
|
||||
|
||||
double wrk[2][3] =
|
||||
{
|
||||
{ 5*RANGE, -RANGE, -RANGE },
|
||||
{ -RANGE, 5*RANGE, -RANGE }
|
||||
};
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
tmppoint[numPoints+i][0] = xmin+xrange*wrk[0][i];
|
||||
tmppoint[numPoints+i][1] = ymin+yrange*wrk[1][i];
|
||||
}
|
||||
|
||||
int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i11;
|
||||
int nts, ii[3];
|
||||
double xx;
|
||||
|
||||
int tsz = 2*TSIZE;
|
||||
int** tmp = new int*[tsz+1];
|
||||
tmp[0] = new int[2*(tsz+1)];
|
||||
for (i0 = 1; i0 < tsz+1; i0++)
|
||||
tmp[i0] = tmp[0] + 2*i0;
|
||||
i1 = 2*(numPoints + 2);
|
||||
|
||||
int* id = new int[i1];
|
||||
for (i0 = 0; i0 < i1; i0++)
|
||||
id[i0] = i0;
|
||||
|
||||
int** a3s = new int*[i1];
|
||||
a3s[0] = new int[3*i1];
|
||||
for (i0 = 1; i0 < i1; i0++)
|
||||
a3s[i0] = a3s[0] + 3*i0;
|
||||
a3s[0][0] = numPoints;
|
||||
a3s[0][1] = numPoints+1;
|
||||
a3s[0][2] = numPoints+2;
|
||||
|
||||
double** ccr = new double*[i1]; // circumscribed centers and radii
|
||||
ccr[0] = new double[3*i1];
|
||||
for (i0 = 1; i0 < i1; i0++)
|
||||
ccr[i0] = ccr[0] + 3*i0;
|
||||
ccr[0][0] = 0.0;
|
||||
ccr[0][1] = 0.0;
|
||||
ccr[0][2] = FLT_MAX;
|
||||
|
||||
nts = 1; // number of triangles
|
||||
i4 = 1;
|
||||
|
||||
cout << "[ 40%] create triangulation \r";
|
||||
|
||||
// compute triangulation
|
||||
for (i0 = 0; i0 < numPoints; i0++)
|
||||
{
|
||||
i1 = i7 = -1;
|
||||
i9 = 0;
|
||||
for (i11 = 0; i11 < nts; i11++)
|
||||
{
|
||||
i1++;
|
||||
while ( a3s[i1][0] < 0 )
|
||||
i1++;
|
||||
xx = ccr[i1][2];
|
||||
for (i2 = 0; i2 < 2; i2++)
|
||||
{
|
||||
double z = tmppoint[i0][i2]-ccr[i1][i2];
|
||||
xx -= z*z;
|
||||
if ( xx < 0 )
|
||||
goto Corner3;
|
||||
}
|
||||
i9--;
|
||||
i4--;
|
||||
id[i4] = i1;
|
||||
for (i2 = 0; i2 < 3; i2++)
|
||||
{
|
||||
ii[0] = 0;
|
||||
if (ii[0] == i2)
|
||||
ii[0]++;
|
||||
for (i3 = 1; i3 < 2; i3++)
|
||||
{
|
||||
ii[i3] = ii[i3-1] + 1;
|
||||
if (ii[i3] == i2)
|
||||
ii[i3]++;
|
||||
}
|
||||
if ( i7 > 1 )
|
||||
{
|
||||
i8 = i7;
|
||||
for (i3 = 0; i3 <= i8; i3++)
|
||||
{
|
||||
for (i5 = 0; i5 < 2; i5++)
|
||||
if ( a3s[i1][ii[i5]] != tmp[i3][i5] )
|
||||
goto Corner1;
|
||||
for (i6 = 0; i6 < 2; i6++)
|
||||
tmp[i3][i6] = tmp[i8][i6];
|
||||
i7--;
|
||||
goto Corner2;
|
||||
Corner1:;
|
||||
}
|
||||
}
|
||||
if ( ++i7 > tsz )
|
||||
{
|
||||
// temporary storage exceeded, increase TSIZE
|
||||
result = 0;
|
||||
goto ExitDelaunay;
|
||||
}
|
||||
for (i3 = 0; i3 < 2; i3++)
|
||||
tmp[i7][i3] = a3s[i1][ii[i3]];
|
||||
Corner2:;
|
||||
}
|
||||
a3s[i1][0] = -1;
|
||||
Corner3:;
|
||||
}
|
||||
|
||||
for (i1 = 0; i1 <= i7; i1++)
|
||||
{
|
||||
for (i2 = 0; i2 < 2; i2++)
|
||||
for (wrk[i2][2] = 0, i3 = 0; i3 < 2; i3++)
|
||||
{
|
||||
wrk[i2][i3] = tmppoint[tmp[i1][i2]][i3]-tmppoint[i0][i3];
|
||||
wrk[i2][2] +=
|
||||
0.5*wrk[i2][i3]*(tmppoint[tmp[i1][i2]][i3]+
|
||||
tmppoint[i0][i3]);
|
||||
}
|
||||
|
||||
xx = wrk[0][0]*wrk[1][1]-wrk[1][0]*wrk[0][1];
|
||||
ccr[id[i4]][0] = (wrk[0][2]*wrk[1][1]-wrk[1][2]*wrk[0][1])/xx;
|
||||
ccr[id[i4]][1] = (wrk[0][0]*wrk[1][2]-wrk[1][0]*wrk[0][2])/xx;
|
||||
|
||||
for (ccr[id[i4]][2] = 0, i2 = 0; i2 < 2; i2++)
|
||||
{
|
||||
double z = tmppoint[i0][i2]-ccr[id[i4]][i2];
|
||||
ccr[id[i4]][2] += z*z;
|
||||
a3s[id[i4]][i2] = tmp[i1][i2];
|
||||
}
|
||||
|
||||
a3s[id[i4]][2] = i0;
|
||||
i4++;
|
||||
i9++;
|
||||
}
|
||||
nts += i9;
|
||||
}
|
||||
|
||||
// count the number of triangles
|
||||
cout << "[ 50%] count the number of triangles \r";
|
||||
|
||||
numTriangles = 0;
|
||||
i0 = -1;
|
||||
for (i11 = 0; i11 < nts; i11++)
|
||||
{
|
||||
i0++;
|
||||
while ( a3s[i0][0] < 0 )
|
||||
i0++;
|
||||
if ( a3s[i0][0] < numPoints )
|
||||
{
|
||||
for (i1 = 0; i1 < 2; i1++)
|
||||
for (i2 = 0; i2 < 2; i2++)
|
||||
wrk[i1][i2] =
|
||||
tmppoint[a3s[i0][i1]][i2]-tmppoint[a3s[i0][2]][i2];
|
||||
|
||||
if ( fabs(wrk[0][0]*wrk[1][1]-wrk[0][1]*wrk[1][0]) > EPSILON*maxrange2 )
|
||||
numTriangles++;
|
||||
}
|
||||
}
|
||||
|
||||
// create the triangles
|
||||
cout << "[ 60%] create the triangles \r";
|
||||
|
||||
triangle = new Triangle[numTriangles];
|
||||
|
||||
numTriangles = 0;
|
||||
i0 = -1;
|
||||
for (i11 = 0; i11 < nts; i11++)
|
||||
{
|
||||
i0++;
|
||||
while ( a3s[i0][0] < 0 )
|
||||
i0++;
|
||||
if ( a3s[i0][0] < numPoints )
|
||||
{
|
||||
for (i1 = 0; i1 < 2; i1++)
|
||||
for (i2 = 0; i2 < 2; i2++)
|
||||
wrk[i1][i2] =
|
||||
tmppoint[a3s[i0][i1]][i2]-tmppoint[a3s[i0][2]][i2];
|
||||
xx = wrk[0][0]*wrk[1][1]-wrk[0][1]*wrk[1][0];
|
||||
if ( fabs(xx) > EPSILON*maxrange2 )
|
||||
{
|
||||
int delta = xx < 0 ? 1 : 0;
|
||||
Triangle& tri = triangle[numTriangles];
|
||||
tri.vertex[0] = a3s[i0][0];
|
||||
tri.vertex[1] = a3s[i0][1+delta];
|
||||
tri.vertex[2] = a3s[i0][2-delta];
|
||||
tri.adj[0] = -1;
|
||||
tri.adj[1] = -1;
|
||||
tri.adj[2] = -1;
|
||||
numTriangles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// build edge table
|
||||
cout << "[ 70%] build the edge table \r";
|
||||
|
||||
numEdges = 0;
|
||||
edge = new Edge[3*numTriangles];
|
||||
|
||||
int j, j0, j1;
|
||||
for (i = 0; i < numTriangles; i++)
|
||||
{
|
||||
if ( (i%500) == 0)
|
||||
cout << "[ 7" << 10*i/numTriangles << "%] build the edge table \r";
|
||||
|
||||
Triangle& t = triangle[i];
|
||||
|
||||
for (j0 = 0, j1 = 1; j0 < 3; j0++, j1 = (j1+1)%3)
|
||||
{
|
||||
for (j = 0; j < numEdges; j++)
|
||||
{
|
||||
Edge& e = edge[j];
|
||||
if ( (t.vertex[j0] == e.vertex[0]
|
||||
&& t.vertex[j1] == e.vertex[1])
|
||||
|| (t.vertex[j0] == e.vertex[1]
|
||||
&& t.vertex[j1] == e.vertex[0]) )
|
||||
break;
|
||||
}
|
||||
if ( j == numEdges ) // add edge to table
|
||||
{
|
||||
edge[j].vertex[0] = t.vertex[j0];
|
||||
edge[j].vertex[1] = t.vertex[j1];
|
||||
edge[j].triangle[0] = i;
|
||||
edge[j].index[0] = j0;
|
||||
edge[j].triangle[1] = -1;
|
||||
numEdges++;
|
||||
}
|
||||
else // edge already exists, add triangle to table
|
||||
{
|
||||
edge[j].triangle[1] = i;
|
||||
edge[j].index[1] = j0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// establish links between adjacent triangles
|
||||
cout << "[ 80%] establishing links between adjacent triangles \r";
|
||||
|
||||
for (i = 0; i < numEdges; i++)
|
||||
{
|
||||
if ( edge[i].triangle[1] != -1 )
|
||||
{
|
||||
j0 = edge[i].triangle[0];
|
||||
j1 = edge[i].triangle[1];
|
||||
triangle[j0].adj[edge[i].index[0]] = j1;
|
||||
triangle[j1].adj[edge[i].index[1]] = j0;
|
||||
}
|
||||
}
|
||||
|
||||
result = 1;
|
||||
|
||||
ExitDelaunay:;
|
||||
delete[] tmp[0];
|
||||
delete[] tmp;
|
||||
delete[] id;
|
||||
delete[] a3s[0];
|
||||
delete[] a3s;
|
||||
delete[] ccr[0];
|
||||
delete[] ccr;
|
||||
|
||||
cout << "[ 90%] finsishes delauney triangulation \r";
|
||||
|
||||
return result;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
void mgcLinInterp2D<T>::GetPoint (int i, double& x, double& y)
|
||||
{
|
||||
// assumes i is valid [can use PointCount() before passing i]
|
||||
x = point[i][0];
|
||||
y = point[i][1];
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
void mgcLinInterp2D<T>::GetEdge (int i, double& x0, double& y0, double& x1,
|
||||
double& y1)
|
||||
{
|
||||
// assumes i is valid [can use EdgeCount() before passing i]
|
||||
int v0 = edge[i].vertex[0], v1 = edge[i].vertex[1];
|
||||
|
||||
x0 = point[v0][0];
|
||||
y0 = point[v0][1];
|
||||
x1 = point[v1][0];
|
||||
y1 = point[v1][1];
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
void mgcLinInterp2D<T>::GetTriangle (int i, double& x0, double& y0, double& x1,
|
||||
double& y1, double& x2, double& y2)
|
||||
{
|
||||
// assumes i is valid [can use TriangleCount() before passing i]
|
||||
int v0 = triangle[i].vertex[0];
|
||||
int v1 = triangle[i].vertex[1];
|
||||
int v2 = triangle[i].vertex[2];
|
||||
|
||||
x0 = point[v0][0];
|
||||
y0 = point[v0][1];
|
||||
x1 = point[v1][0];
|
||||
y1 = point[v1][1];
|
||||
x2 = point[v2][0];
|
||||
y2 = point[v2][1];
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
42
simgear/math/localconsts.hxx
Normal file
42
simgear/math/localconsts.hxx
Normal file
@@ -0,0 +1,42 @@
|
||||
// localconsts.hxx -- various constant that are shared
|
||||
//
|
||||
// Written by Curtis Olson, started September 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_LOCAL_CONSTS_HXX
|
||||
#define _SG_LOCAL_CONSTS_HXX
|
||||
|
||||
|
||||
// Value of earth flattening parameter from ref [8]
|
||||
//
|
||||
// Note: FP = f
|
||||
// E = 1-f
|
||||
// EPS = sqrt(1-(1-f)^2)
|
||||
//
|
||||
|
||||
static const double FP = 0.003352813178;
|
||||
static const double E = 0.996647186;
|
||||
static const double EPS = 0.081819221;
|
||||
static const double INVG = 0.031080997;
|
||||
|
||||
|
||||
#endif // _SG_LOCAL_CONSTS_HXX
|
||||
344
simgear/math/point3d.hxx
Normal file
344
simgear/math/point3d.hxx
Normal file
@@ -0,0 +1,344 @@
|
||||
// point3d.hxx -- a 3d point class.
|
||||
//
|
||||
// Adapted from algebra3 by Jean-Francois Doue, started October 1998.
|
||||
//
|
||||
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _POINT3D_HXX
|
||||
#define _POINT3D_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef FG_MATH_EXCEPTION_CLASH
|
||||
# define exception c_exception
|
||||
#endif
|
||||
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <iostream>
|
||||
# include <cassert>
|
||||
# include <cmath>
|
||||
#else
|
||||
# include <iostream.h>
|
||||
# include <assert.h>
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/math/localconsts.hxx>
|
||||
|
||||
// I don't understand ... <math.h> or <cmath> should be included
|
||||
// already depending on how you defined FG_HAVE_STD_INCLUDES, but I
|
||||
// can go ahead and add this -- CLO
|
||||
#ifdef __MWERKS__
|
||||
FG_USING_NAMESPACE(std);
|
||||
#endif
|
||||
|
||||
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
|
||||
FG_USING_STD(ostream);
|
||||
FG_USING_STD(istream);
|
||||
#endif
|
||||
|
||||
|
||||
const double fgPoint3_Epsilon = 0.0000001;
|
||||
|
||||
enum {PX, PY, PZ}; // axes
|
||||
|
||||
// Kludge for msvc++ 6.0 - requires forward decls of friend functions.
|
||||
class Point3D;
|
||||
istream& operator>> ( istream&, Point3D& );
|
||||
ostream& operator<< ( ostream&, const Point3D& );
|
||||
Point3D operator- (const Point3D& p); // -p1
|
||||
bool operator== (const Point3D& a, const Point3D& b); // p1 == p2?
|
||||
|
||||
|
||||
///////////////////////////
|
||||
//
|
||||
// 3D Point
|
||||
//
|
||||
///////////////////////////
|
||||
|
||||
class Point3D {
|
||||
|
||||
protected:
|
||||
|
||||
double n[3];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Point3D();
|
||||
Point3D(const double x, const double y, const double z);
|
||||
explicit Point3D(const double d);
|
||||
Point3D(const Point3D &p);
|
||||
|
||||
// Assignment operators
|
||||
|
||||
Point3D& operator = ( const Point3D& p ); // assignment of a Point3D
|
||||
Point3D& operator += ( const Point3D& p ); // incrementation by a Point3D
|
||||
Point3D& operator -= ( const Point3D& p ); // decrementation by a Point3D
|
||||
Point3D& operator *= ( const double d ); // multiplication by a constant
|
||||
Point3D& operator /= ( const double d ); // division by a constant
|
||||
|
||||
void setx(const double x);
|
||||
void sety(const double y);
|
||||
void setz(const double z);
|
||||
|
||||
// Queries
|
||||
|
||||
double& operator [] ( int i); // indexing
|
||||
double operator[] (int i) const; // read-only indexing
|
||||
|
||||
inline const double *get_n() const { return n; };
|
||||
double x() const; // cartesian x
|
||||
double y() const; // cartesian y
|
||||
double z() const; // cartesian z
|
||||
|
||||
double lon() const; // polar longitude
|
||||
double lat() const; // polar latitude
|
||||
double radius() const; // polar radius
|
||||
double elev() const; // geodetic elevation (if specifying a surface point)
|
||||
|
||||
// friends
|
||||
friend Point3D operator - (const Point3D& p); // -p1
|
||||
friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2?
|
||||
friend istream& operator>> ( istream&, Point3D& );
|
||||
friend ostream& operator<< ( ostream&, const Point3D& );
|
||||
|
||||
// Special functions
|
||||
double distance3D(const Point3D& a) const; // distance between
|
||||
double distance3Dsquared(const Point3D& a) const; // distance between ^ 2
|
||||
};
|
||||
|
||||
|
||||
// input from stream
|
||||
inline istream&
|
||||
operator >> ( istream& in, Point3D& p)
|
||||
{
|
||||
char c;
|
||||
|
||||
in >> p.n[PX];
|
||||
|
||||
// read past optional comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> p.n[PY];
|
||||
|
||||
// read past optional comma
|
||||
while ( in.get(c) ) {
|
||||
if ( (c != ' ') && (c != ',') ) {
|
||||
// push back on the stream
|
||||
in.putback(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in >> p.n[PZ];
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
inline ostream&
|
||||
operator<< ( ostream& out, const Point3D& p )
|
||||
{
|
||||
return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ];
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
//
|
||||
// Point3D Member functions
|
||||
//
|
||||
///////////////////////////
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
inline Point3D::Point3D() {}
|
||||
|
||||
inline Point3D::Point3D(const double x, const double y, const double z)
|
||||
{
|
||||
n[PX] = x; n[PY] = y; n[PZ] = z;
|
||||
}
|
||||
|
||||
inline Point3D::Point3D(const double d)
|
||||
{
|
||||
n[PX] = n[PY] = n[PZ] = d;
|
||||
}
|
||||
|
||||
inline Point3D::Point3D(const Point3D& p)
|
||||
{
|
||||
n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ];
|
||||
}
|
||||
|
||||
// ASSIGNMENT OPERATORS
|
||||
|
||||
inline Point3D& Point3D::operator = (const Point3D& p)
|
||||
{
|
||||
n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ]; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator += ( const Point3D& p )
|
||||
{
|
||||
n[PX] += p.n[PX]; n[PY] += p.n[PY]; n[PZ] += p.n[PZ]; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator -= ( const Point3D& p )
|
||||
{
|
||||
n[PX] -= p.n[PX]; n[PY] -= p.n[PY]; n[PZ] -= p.n[PZ]; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator *= ( const double d )
|
||||
{
|
||||
n[PX] *= d; n[PY] *= d; n[PZ] *= d; return *this;
|
||||
}
|
||||
|
||||
inline Point3D& Point3D::operator /= ( const double d )
|
||||
{
|
||||
double d_inv = 1./d; n[PX] *= d_inv; n[PY] *= d_inv; n[PZ] *= d_inv;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Point3D::setx(const double x) {
|
||||
n[PX] = x;
|
||||
}
|
||||
|
||||
inline void Point3D::sety(const double y) {
|
||||
n[PY] = y;
|
||||
}
|
||||
|
||||
inline void Point3D::setz(const double z) {
|
||||
n[PZ] = z;
|
||||
}
|
||||
|
||||
// QUERIES
|
||||
|
||||
inline double& Point3D::operator [] ( int i)
|
||||
{
|
||||
assert(! (i < PX || i > PZ));
|
||||
return n[i];
|
||||
}
|
||||
|
||||
inline double Point3D::operator [] ( int i) const {
|
||||
assert(! (i < PX || i > PZ));
|
||||
return n[i];
|
||||
}
|
||||
|
||||
|
||||
inline double Point3D::x() const { return n[PX]; }
|
||||
|
||||
inline double Point3D::y() const { return n[PY]; }
|
||||
|
||||
inline double Point3D::z() const { return n[PZ]; }
|
||||
|
||||
inline double Point3D::lon() const { return n[PX]; }
|
||||
|
||||
inline double Point3D::lat() const { return n[PY]; }
|
||||
|
||||
inline double Point3D::radius() const { return n[PZ]; }
|
||||
|
||||
inline double Point3D::elev() const { return n[PZ]; }
|
||||
|
||||
|
||||
// FRIENDS
|
||||
|
||||
inline Point3D operator - (const Point3D& a)
|
||||
{
|
||||
return Point3D(-a.n[PX],-a.n[PY],-a.n[PZ]);
|
||||
}
|
||||
|
||||
inline Point3D operator + (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return Point3D(a) += b;
|
||||
}
|
||||
|
||||
inline Point3D operator - (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return Point3D(a) -= b;
|
||||
}
|
||||
|
||||
inline Point3D operator * (const Point3D& a, const double d)
|
||||
{
|
||||
return Point3D(a) *= d;
|
||||
}
|
||||
|
||||
inline Point3D operator * (const double d, const Point3D& a)
|
||||
{
|
||||
return a*d;
|
||||
}
|
||||
|
||||
inline Point3D operator / (const Point3D& a, const double d)
|
||||
{
|
||||
return Point3D(a) *= (1.0 / d );
|
||||
}
|
||||
|
||||
inline bool operator == (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return
|
||||
fabs(a.n[PX] - b.n[PX]) < fgPoint3_Epsilon &&
|
||||
fabs(a.n[PY] - b.n[PY]) < fgPoint3_Epsilon &&
|
||||
fabs(a.n[PZ] - b.n[PZ]) < fgPoint3_Epsilon;
|
||||
}
|
||||
|
||||
inline bool operator != (const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
// Special functions
|
||||
|
||||
inline double
|
||||
Point3D::distance3D(const Point3D& a ) const
|
||||
{
|
||||
double x, y, z;
|
||||
|
||||
x = n[PX] - a.n[PX];
|
||||
y = n[PY] - a.n[PY];
|
||||
z = n[PZ] - a.n[PZ];
|
||||
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
|
||||
inline double
|
||||
Point3D::distance3Dsquared(const Point3D& a ) const
|
||||
{
|
||||
double x, y, z;
|
||||
|
||||
x = n[PX] - a.n[PX];
|
||||
y = n[PY] - a.n[PY];
|
||||
z = n[PZ] - a.n[PZ];
|
||||
|
||||
return(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
|
||||
#endif // _POINT3D_HXX
|
||||
|
||||
|
||||
62
simgear/math/polar3d.cxx
Normal file
62
simgear/math/polar3d.cxx
Normal file
@@ -0,0 +1,62 @@
|
||||
// polar.cxx -- routines to deal with polar math and transformations
|
||||
//
|
||||
// Written by Curtis Olson, started June 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <simgear/constants.h>
|
||||
|
||||
#include "polar3d.hxx"
|
||||
|
||||
|
||||
// Find the Altitude above the Ellipsoid (WGS84) given the Earth
|
||||
// Centered Cartesian coordinate vector Distances are specified in
|
||||
// meters.
|
||||
double fgGeodAltFromCart(const Point3D& cp)
|
||||
{
|
||||
double t_lat, x_alpha, mu_alpha;
|
||||
double lat_geoc, radius;
|
||||
double result;
|
||||
|
||||
lat_geoc = FG_PI_2 - atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() );
|
||||
radius = sqrt( cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z() );
|
||||
|
||||
if( ( (FG_PI_2 - lat_geoc) < ONE_SECOND ) // near North pole
|
||||
|| ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) // near South pole
|
||||
{
|
||||
result = radius - EQUATORIAL_RADIUS_M*E;
|
||||
} else {
|
||||
t_lat = tan(lat_geoc);
|
||||
x_alpha = E*EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E);
|
||||
mu_alpha = atan2(sqrt(RESQ_M - x_alpha*x_alpha),E*x_alpha);
|
||||
if (lat_geoc < 0) {
|
||||
mu_alpha = - mu_alpha;
|
||||
}
|
||||
result = (radius - x_alpha/cos(lat_geoc))*cos(mu_alpha - lat_geoc);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
159
simgear/math/polar3d.hxx
Normal file
159
simgear/math/polar3d.hxx
Normal file
@@ -0,0 +1,159 @@
|
||||
// polar.hxx -- routines to deal with polar math and transformations
|
||||
//
|
||||
// Written by Curtis Olson, started June 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _POLAR_HXX
|
||||
#define _POLAR_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
|
||||
|
||||
// Find the Altitude above the Ellipsoid (WGS84) given the Earth
|
||||
// Centered Cartesian coordinate vector Distances are specified in
|
||||
// meters.
|
||||
double sgGeodAltFromCart(const Point3D& cp);
|
||||
|
||||
|
||||
// Convert a polar coordinate to a cartesian coordinate. Lon and Lat
|
||||
// must be specified in radians. The SG convention is for distances
|
||||
// to be specified in meters
|
||||
inline Point3D sgPolarToCart3d(const Point3D& p) {
|
||||
double tmp = cos( p.lat() ) * p.radius();
|
||||
|
||||
return Point3D( cos( p.lon() ) * tmp,
|
||||
sin( p.lon() ) * tmp,
|
||||
sin( p.lat() ) * p.radius() );
|
||||
}
|
||||
|
||||
|
||||
// Convert a cartesian coordinate to polar coordinates (lon/lat
|
||||
// specified in radians. Distances are specified in meters.
|
||||
inline Point3D sgCartToPolar3d(const Point3D& cp) {
|
||||
return Point3D( atan2( cp.y(), cp.x() ),
|
||||
FG_PI_2 -
|
||||
atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ),
|
||||
sqrt(cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z()) );
|
||||
}
|
||||
|
||||
|
||||
// calc new lon/lat given starting lon/lat, and offset radial, and
|
||||
// distance. NOTE: starting point is specifed in radians, distance is
|
||||
// specified in meters (and converted internally to radians)
|
||||
// ... assumes a spherical world
|
||||
inline Point3D calc_gc_lon_lat( const Point3D& orig, double course,
|
||||
double dist ) {
|
||||
Point3D result;
|
||||
|
||||
// lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
|
||||
// IF (cos(lat)=0)
|
||||
// lon=lon1 // endpoint a pole
|
||||
// ELSE
|
||||
// lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
|
||||
// ENDIF
|
||||
|
||||
// printf("calc_lon_lat() offset.theta = %.2f offset.dist = %.2f\n",
|
||||
// offset.theta, offset.dist);
|
||||
|
||||
dist *= METER_TO_NM * NM_TO_RAD;
|
||||
|
||||
result.sety( asin( sin(orig.y()) * cos(dist) +
|
||||
cos(orig.y()) * sin(dist) * cos(course) ) );
|
||||
|
||||
if ( cos(result.y()) < FG_EPSILON ) {
|
||||
result.setx( orig.x() ); // endpoint a pole
|
||||
} else {
|
||||
result.setx(
|
||||
fmod(orig.x() - asin( sin(course) * sin(dist) /
|
||||
cos(result.y()) ) + FG_PI, FG_2PI) - FG_PI );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// calc course/dist
|
||||
inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
|
||||
double *course, double *dist ) {
|
||||
// d = 2*asin(sqrt((sin((lat1-lat2)/2))^2 +
|
||||
// cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
|
||||
double tmp1 = sin( (start.y() - dest.y()) / 2 );
|
||||
double tmp2 = sin( (start.x() - dest.x()) / 2 );
|
||||
double d = 2.0 * asin( sqrt( tmp1 * tmp1 +
|
||||
cos(start.y()) * cos(dest.y()) * tmp2 * tmp2));
|
||||
|
||||
// We obtain the initial course, tc1, (at point 1) from point 1 to
|
||||
// point 2 by the following. The formula fails if the initial
|
||||
// point is a pole. We can special case this with:
|
||||
//
|
||||
// IF (cos(lat1) < EPS) // EPS a small number ~ machine precision
|
||||
// IF (lat1 > 0)
|
||||
// tc1= pi // starting from N pole
|
||||
// ELSE
|
||||
// tc1= 0 // starting from S pole
|
||||
// ENDIF
|
||||
// ENDIF
|
||||
//
|
||||
// For starting points other than the poles:
|
||||
//
|
||||
// IF sin(lon2-lon1)<0
|
||||
// tc1=acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
|
||||
// ELSE
|
||||
// tc1=2*pi-acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
|
||||
// ENDIF
|
||||
|
||||
double tc1;
|
||||
|
||||
if ( cos(start.y()) < FG_EPSILON ) {
|
||||
// EPS a small number ~ machine precision
|
||||
if ( start.y() > 0 ) {
|
||||
tc1 = FG_PI; // starting from N pole
|
||||
} else {
|
||||
tc1 = 0; // starting from S pole
|
||||
}
|
||||
}
|
||||
|
||||
// For starting points other than the poles:
|
||||
|
||||
double tmp3 = sin(d)*cos(start.y());
|
||||
double tmp4 = sin(dest.y())-sin(start.y())*cos(d);
|
||||
double tmp5 = acos(tmp4/tmp3);
|
||||
if ( sin( dest.x() - start.x() ) < 0 ) {
|
||||
tc1 = tmp5;
|
||||
} else {
|
||||
tc1 = 2 * FG_PI - tmp5;
|
||||
}
|
||||
|
||||
*course = tc1;
|
||||
*dist = d * RAD_TO_NM * NM_TO_METER;
|
||||
}
|
||||
|
||||
#endif // _POLAR_HXX
|
||||
451
simgear/math/sg_geodesy.cxx
Normal file
451
simgear/math/sg_geodesy.cxx
Normal file
@@ -0,0 +1,451 @@
|
||||
// sg_geodesy.cxx -- routines to convert between geodetic and geocentric
|
||||
// coordinate systems.
|
||||
//
|
||||
// Copied and adapted directly from LaRCsim/ls_geodesy.c
|
||||
//
|
||||
// See below for the complete original LaRCsim comments.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <cmath>
|
||||
# include <cerrno>
|
||||
#else
|
||||
# include <math.h>
|
||||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include "point3d.hxx"
|
||||
#include "sg_geodesy.hxx"
|
||||
#include "localconsts.hxx"
|
||||
|
||||
|
||||
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
|
||||
FG_USING_STD(cout);
|
||||
#endif
|
||||
|
||||
// ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator
|
||||
#define ONE_SECOND 4.848136811E-6
|
||||
|
||||
|
||||
// sgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
|
||||
// INPUTS:
|
||||
// lat_geoc Geocentric latitude, radians, + = North
|
||||
// radius C.G. radius to earth center (meters)
|
||||
//
|
||||
// OUTPUTS:
|
||||
// lat_geod Geodetic latitude, radians, + = North
|
||||
// alt C.G. altitude above mean sea level (meters)
|
||||
// sea_level_r radius from earth center to sea level at
|
||||
// local vertical (surface normal) of C.G. (meters)
|
||||
|
||||
|
||||
void sgGeocToGeod( double lat_geoc, double radius, double
|
||||
*lat_geod, double *alt, double *sea_level_r )
|
||||
{
|
||||
double t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha;
|
||||
double sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl;
|
||||
|
||||
if( ( (FG_PI_2 - lat_geoc) < ONE_SECOND ) // near North pole
|
||||
|| ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) // near South pole
|
||||
{
|
||||
*lat_geod = lat_geoc;
|
||||
*sea_level_r = EQUATORIAL_RADIUS_M*E;
|
||||
*alt = radius - *sea_level_r;
|
||||
} else {
|
||||
// cout << " lat_geoc = " << lat_geoc << endl;
|
||||
t_lat = tan(lat_geoc);
|
||||
// cout << " tan(t_lat) = " << t_lat << endl;
|
||||
x_alpha = E*EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E);
|
||||
// cout << " x_alpha = " << x_alpha << endl;
|
||||
double tmp = RESQ_M - x_alpha * x_alpha;
|
||||
if ( tmp < 0.0 ) { tmp = 0.0; }
|
||||
mu_alpha = atan2(sqrt(tmp),E*x_alpha);
|
||||
if (lat_geoc < 0) mu_alpha = - mu_alpha;
|
||||
sin_mu_a = sin(mu_alpha);
|
||||
delt_lambda = mu_alpha - lat_geoc;
|
||||
r_alpha = x_alpha/cos(lat_geoc);
|
||||
l_point = radius - r_alpha;
|
||||
*alt = l_point*cos(delt_lambda);
|
||||
|
||||
// check for domain error
|
||||
if ( errno == EDOM ) {
|
||||
FG_LOG( FG_GENERAL, FG_ALERT, "Domain ERROR in fgGeocToGeod!!!!" );
|
||||
*alt = 0.0;
|
||||
}
|
||||
|
||||
denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
|
||||
rho_alpha = EQUATORIAL_RADIUS_M*(1-EPS)/
|
||||
(denom*denom*denom);
|
||||
delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt);
|
||||
*lat_geod = mu_alpha - delt_mu;
|
||||
lambda_sl = atan( E*E * tan(*lat_geod) ); // SL geoc. latitude
|
||||
sin_lambda_sl = sin( lambda_sl );
|
||||
*sea_level_r =
|
||||
sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
|
||||
|
||||
// check for domain error
|
||||
if ( errno == EDOM ) {
|
||||
FG_LOG( FG_GENERAL, FG_ALERT, "Domain ERROR in sgGeocToGeod!!!!" );
|
||||
*sea_level_r = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// sgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
|
||||
// INPUTS:
|
||||
// lat_geod Geodetic latitude, radians, + = North
|
||||
// alt C.G. altitude above mean sea level (meters)
|
||||
//
|
||||
// OUTPUTS:
|
||||
// sl_radius SEA LEVEL radius to earth center (meters)
|
||||
// (add Altitude to get true distance from earth center.
|
||||
// lat_geoc Geocentric latitude, radians, + = North
|
||||
//
|
||||
|
||||
|
||||
void sgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
|
||||
double *lat_geoc )
|
||||
{
|
||||
double lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py;
|
||||
|
||||
lambda_sl = atan( E*E * tan(lat_geod) ); // sea level geocentric latitude
|
||||
sin_lambda_sl = sin( lambda_sl );
|
||||
cos_lambda_sl = cos( lambda_sl );
|
||||
sin_mu = sin(lat_geod); // Geodetic (map makers') latitude
|
||||
cos_mu = cos(lat_geod);
|
||||
*sl_radius =
|
||||
sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
|
||||
py = *sl_radius*sin_lambda_sl + alt*sin_mu;
|
||||
px = *sl_radius*cos_lambda_sl + alt*cos_mu;
|
||||
*lat_geoc = atan2( py, px );
|
||||
}
|
||||
|
||||
|
||||
// Direct and inverse distance functions
|
||||
//
|
||||
// Proceedings of the 7th International Symposium on Geodetic
|
||||
// Computations, 1985
|
||||
//
|
||||
// "The Nested Coefficient Method for Accurate Solutions of Direct and
|
||||
// Inverse Geodetic Problems With Any Length"
|
||||
//
|
||||
// Zhang Xue-Lian
|
||||
// pp 747-763
|
||||
//
|
||||
// modified for FlightGear to use WGS84 only -- Norman Vine
|
||||
|
||||
#define GEOD_INV_PI FG_PI
|
||||
|
||||
// s == distance
|
||||
// az = azimuth
|
||||
|
||||
// for WGS_84 a = 6378137.000, rf = 298.257223563;
|
||||
|
||||
static double M0( double e2 ) {
|
||||
//double e4 = e2*e2;
|
||||
return GEOD_INV_PI*(1.0 - e2*( 1.0/4.0 + e2*( 3.0/64.0 +
|
||||
e2*(5.0/256.0) )))/2.0;
|
||||
}
|
||||
|
||||
|
||||
// given, alt, lat1, lon1, az1 and distance (s), calculate lat2, lon2
|
||||
// and az2. Lat, lon, and azimuth are in degrees. distance in meters
|
||||
int geo_direct_wgs_84 ( double alt, double lat1, double lon1, double az1,
|
||||
double s, double *lat2, double *lon2, double *az2 )
|
||||
{
|
||||
double a = 6378137.000, rf = 298.257223563;
|
||||
double RADDEG = (GEOD_INV_PI)/180.0, testv = 1.0E-10;
|
||||
double f = ( rf > 0.0 ? 1.0/rf : 0.0 );
|
||||
double b = a*(1.0-f);
|
||||
double e2 = f*(2.0-f);
|
||||
double phi1 = lat1*RADDEG, lam1 = lon1*RADDEG;
|
||||
double sinphi1 = sin(phi1), cosphi1 = cos(phi1);
|
||||
double azm1 = az1*RADDEG;
|
||||
double sinaz1 = sin(azm1), cosaz1 = cos(azm1);
|
||||
|
||||
|
||||
if( fabs(s) < 0.01 ) { // distance < centimeter => congruency
|
||||
*lat2 = lat1;
|
||||
*lon2 = lon1;
|
||||
*az2 = 180.0 + az1;
|
||||
if( *az2 > 360.0 ) *az2 -= 360.0;
|
||||
return 0;
|
||||
} else if( cosphi1 ) { // non-polar origin
|
||||
// u1 is reduced latitude
|
||||
double tanu1 = sqrt(1.0-e2)*sinphi1/cosphi1;
|
||||
double sig1 = atan2(tanu1,cosaz1);
|
||||
double cosu1 = 1.0/sqrt( 1.0 + tanu1*tanu1 ), sinu1 = tanu1*cosu1;
|
||||
double sinaz = cosu1*sinaz1, cos2saz = 1.0-sinaz*sinaz;
|
||||
double us = cos2saz*e2/(1.0-e2);
|
||||
|
||||
// Terms
|
||||
double ta = 1.0+us*(4096.0+us*(-768.0+us*(320.0-175.0*us)))/16384.0,
|
||||
tb = us*(256.0+us*(-128.0+us*(74.0-47.0*us)))/1024.0,
|
||||
tc = 0;
|
||||
|
||||
// FIRST ESTIMATE OF SIGMA (SIG)
|
||||
double first = s/(b*ta); // !!
|
||||
double sig = first;
|
||||
double c2sigm, sinsig,cossig, temp,denom,rnumer, dlams, dlam;
|
||||
do {
|
||||
c2sigm = cos(2.0*sig1+sig);
|
||||
sinsig = sin(sig); cossig = cos(sig);
|
||||
temp = sig;
|
||||
sig = first +
|
||||
tb*sinsig*(c2sigm+tb*(cossig*(-1.0+2.0*c2sigm*c2sigm) -
|
||||
tb*c2sigm*(-3.0+4.0*sinsig*sinsig)
|
||||
*(-3.0+4.0*c2sigm*c2sigm)/6.0)
|
||||
/4.0);
|
||||
} while( fabs(sig-temp) > testv);
|
||||
|
||||
// LATITUDE OF POINT 2
|
||||
// DENOMINATOR IN 2 PARTS (TEMP ALSO USED LATER)
|
||||
temp = sinu1*sinsig-cosu1*cossig*cosaz1;
|
||||
denom = (1.0-f)*sqrt(sinaz*sinaz+temp*temp);
|
||||
|
||||
// NUMERATOR
|
||||
rnumer = sinu1*cossig+cosu1*sinsig*cosaz1;
|
||||
*lat2 = atan2(rnumer,denom)/RADDEG;
|
||||
|
||||
// DIFFERENCE IN LONGITUDE ON AUXILARY SPHERE (DLAMS )
|
||||
rnumer = sinsig*sinaz1;
|
||||
denom = cosu1*cossig-sinu1*sinsig*cosaz1;
|
||||
dlams = atan2(rnumer,denom);
|
||||
|
||||
// TERM C
|
||||
tc = f*cos2saz*(4.0+f*(4.0-3.0*cos2saz))/16.0;
|
||||
|
||||
// DIFFERENCE IN LONGITUDE
|
||||
dlam = dlams-(1.0-tc)*f*sinaz*(sig+tc*sinsig*
|
||||
(c2sigm+
|
||||
tc*cossig*(-1.0+2.0*
|
||||
c2sigm*c2sigm)));
|
||||
*lon2 = (lam1+dlam)/RADDEG;
|
||||
if (*lon2 > 180.0 ) *lon2 -= 360.0;
|
||||
if (*lon2 < -180.0 ) *lon2 += 360.0;
|
||||
|
||||
// AZIMUTH - FROM NORTH
|
||||
*az2 = atan2(-sinaz,temp)/RADDEG;
|
||||
if ( fabs(*az2) < testv ) *az2 = 0.0;
|
||||
if( *az2 < 0.0) *az2 += 360.0;
|
||||
return 0;
|
||||
} else { // phi1 == 90 degrees, polar origin
|
||||
double dM = a*M0(e2) - s;
|
||||
double paz = ( phi1 < 0.0 ? 180.0 : 0.0 );
|
||||
return geo_direct_wgs_84( alt, 0.0, lon1, paz, dM,lat2,lon2,az2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// given alt, lat1, lon1, lat2, lon2, calculate starting and ending
|
||||
// az1, az2 and distance (s). Lat, lon, and azimuth are in degrees.
|
||||
// distance in meters
|
||||
int geo_inverse_wgs_84( double alt, double lat1, double lon1, double lat2,
|
||||
double lon2, double *az1, double *az2, double *s )
|
||||
{
|
||||
double a = 6378137.000, rf = 298.257223563;
|
||||
int iter=0;
|
||||
double RADDEG = (GEOD_INV_PI)/180.0, testv = 1.0E-10;
|
||||
double f = ( rf > 0.0 ? 1.0/rf : 0.0 );
|
||||
double b = a*(1.0-f);
|
||||
// double e2 = f*(2.0-f); // unused in this routine
|
||||
double phi1 = lat1*RADDEG, lam1 = lon1*RADDEG;
|
||||
double sinphi1 = sin(phi1), cosphi1 = cos(phi1);
|
||||
double phi2 = lat2*RADDEG, lam2 = lon2*RADDEG;
|
||||
double sinphi2 = sin(phi2), cosphi2 = cos(phi2);
|
||||
|
||||
if( (fabs(lat1-lat2) < testv &&
|
||||
( fabs(lon1-lon2) < testv) || fabs(lat1-90.0) < testv ) )
|
||||
{
|
||||
// TWO STATIONS ARE IDENTICAL : SET DISTANCE & AZIMUTHS TO ZERO */
|
||||
*az1 = 0.0; *az2 = 0.0; *s = 0.0;
|
||||
return 0;
|
||||
} else if( fabs(cosphi1) < testv ) {
|
||||
// initial point is polar
|
||||
int k = geo_inverse_wgs_84( alt, lat2,lon2,lat1,lon1, az1,az2,s );
|
||||
k = k; // avoid compiler error since return result is unused
|
||||
b = *az1; *az1 = *az2; *az2 = b;
|
||||
return 0;
|
||||
} else if( fabs(cosphi2) < testv ) {
|
||||
// terminal point is polar
|
||||
int k = geo_inverse_wgs_84( alt, lat1,lon1,lat1,lon1+180.0,
|
||||
az1,az2,s );
|
||||
k = k; // avoid compiler error since return result is unused
|
||||
*s /= 2.0;
|
||||
*az2 = *az1 + 180.0;
|
||||
if( *az2 > 360.0 ) *az2 -= 360.0;
|
||||
return 0;
|
||||
} else if( (fabs( fabs(lon1-lon2) - 180 ) < testv) &&
|
||||
(fabs(lat1+lat2) < testv) )
|
||||
{
|
||||
// Geodesic passes through the pole (antipodal)
|
||||
double s1,s2;
|
||||
geo_inverse_wgs_84( alt, lat1,lon1, lat1,lon2, az1,az2, &s1 );
|
||||
geo_inverse_wgs_84( alt, lat2,lon2, lat1,lon2, az1,az2, &s2 );
|
||||
*az2 = *az1;
|
||||
*s = s1 + s2;
|
||||
return 0;
|
||||
} else {
|
||||
// antipodal and polar points don't get here
|
||||
double dlam = lam2 - lam1, dlams = dlam;
|
||||
double sdlams,cdlams, sig,sinsig,cossig, sinaz,
|
||||
cos2saz, c2sigm;
|
||||
double tc,temp, us,rnumer,denom, ta,tb;
|
||||
double cosu1,sinu1, sinu2,cosu2;
|
||||
|
||||
// Reduced latitudes
|
||||
temp = (1.0-f)*sinphi1/cosphi1;
|
||||
cosu1 = 1.0/sqrt(1.0+temp*temp);
|
||||
sinu1 = temp*cosu1;
|
||||
temp = (1.0-f)*sinphi2/cosphi2;
|
||||
cosu2 = 1.0/sqrt(1.0+temp*temp);
|
||||
sinu2 = temp*cosu2;
|
||||
|
||||
do {
|
||||
sdlams = sin(dlams), cdlams = cos(dlams);
|
||||
sinsig = sqrt(cosu2*cosu2*sdlams*sdlams+
|
||||
(cosu1*sinu2-sinu1*cosu2*cdlams)*
|
||||
(cosu1*sinu2-sinu1*cosu2*cdlams));
|
||||
cossig = sinu1*sinu2+cosu1*cosu2*cdlams;
|
||||
|
||||
sig = atan2(sinsig,cossig);
|
||||
sinaz = cosu1*cosu2*sdlams/sinsig;
|
||||
cos2saz = 1.0-sinaz*sinaz;
|
||||
c2sigm = (sinu1 == 0.0 || sinu2 == 0.0 ? cossig :
|
||||
cossig-2.0*sinu1*sinu2/cos2saz);
|
||||
tc = f*cos2saz*(4.0+f*(4.0-3.0*cos2saz))/16.0;
|
||||
temp = dlams;
|
||||
dlams = dlam+(1.0-tc)*f*sinaz*
|
||||
(sig+tc*sinsig*
|
||||
(c2sigm+tc*cossig*(-1.0+2.0*c2sigm*c2sigm)));
|
||||
if (fabs(dlams) > GEOD_INV_PI && iter++ > 50) {
|
||||
return iter;
|
||||
}
|
||||
} while ( fabs(temp-dlams) > testv);
|
||||
|
||||
us = cos2saz*(a*a-b*b)/(b*b); // !!
|
||||
// BACK AZIMUTH FROM NORTH
|
||||
rnumer = -(cosu1*sdlams);
|
||||
denom = sinu1*cosu2-cosu1*sinu2*cdlams;
|
||||
*az2 = atan2(rnumer,denom)/RADDEG;
|
||||
if( fabs(*az2) < testv ) *az2 = 0.0;
|
||||
if(*az2 < 0.0) *az2 += 360.0;
|
||||
|
||||
// FORWARD AZIMUTH FROM NORTH
|
||||
rnumer = cosu2*sdlams;
|
||||
denom = cosu1*sinu2-sinu1*cosu2*cdlams;
|
||||
*az1 = atan2(rnumer,denom)/RADDEG;
|
||||
if( fabs(*az1) < testv ) *az1 = 0.0;
|
||||
if(*az1 < 0.0) *az1 += 360.0;
|
||||
|
||||
// Terms a & b
|
||||
ta = 1.0+us*(4096.0+us*(-768.0+us*(320.0-175.0*us)))/
|
||||
16384.0;
|
||||
tb = us*(256.0+us*(-128.0+us*(74.0-47.0*us)))/1024.0;
|
||||
|
||||
// GEODETIC DISTANCE
|
||||
*s = b*ta*(sig-tb*sinsig*
|
||||
(c2sigm+tb*(cossig*(-1.0+2.0*c2sigm*c2sigm)-tb*
|
||||
c2sigm*(-3.0+4.0*sinsig*sinsig)*
|
||||
(-3.0+4.0*c2sigm*c2sigm)/6.0)/
|
||||
4.0));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
|
||||
TITLE: ls_geodesy
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
FUNCTION: Converts geocentric coordinates to geodetic positions
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
MODULE STATUS: developmental
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
DESIGNED BY: E. B. Jackson
|
||||
|
||||
CODED BY: E. B. Jackson
|
||||
|
||||
MAINTAINED BY: E. B. Jackson
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
MODIFICATION HISTORY:
|
||||
|
||||
DATE PURPOSE BY
|
||||
|
||||
930208 Modified to avoid singularity near polar region. EBJ
|
||||
930602 Moved backwards calcs here from ls_step. EBJ
|
||||
931214 Changed erroneous Latitude and Altitude variables to
|
||||
*lat_geod and *alt in routine ls_geoc_to_geod. EBJ
|
||||
940111 Changed header files from old ls_eom.h style to ls_types,
|
||||
and ls_constants. Also replaced old DATA type with new
|
||||
SCALAR type. EBJ
|
||||
|
||||
CURRENT RCS HEADER:
|
||||
|
||||
$Header$
|
||||
* Revision 1.5 1994/01/11 18:47:05 bjax
|
||||
* Changed include files to use types and constants, not ls_eom.h
|
||||
* Also changed DATA type to SCALAR type.
|
||||
*
|
||||
* Revision 1.4 1993/12/14 21:06:47 bjax
|
||||
* Removed global variable references Altitude and Latitude. EBJ
|
||||
*
|
||||
* Revision 1.3 1993/06/02 15:03:40 bjax
|
||||
* Made new subroutine for calculating geodetic to geocentric; changed name
|
||||
* of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
|
||||
*
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
REFERENCES:
|
||||
|
||||
[ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
|
||||
Control and Simulation", Wiley and Sons, 1992.
|
||||
ISBN 0-471-61397-5
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
CALLED BY: ls_aux
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
CALLS TO:
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
INPUTS:
|
||||
lat_geoc Geocentric latitude, radians, + = North
|
||||
radius C.G. radius to earth center, ft
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
OUTPUTS:
|
||||
lat_geod Geodetic latitude, radians, + = North
|
||||
alt C.G. altitude above mean sea level, ft
|
||||
sea_level_r radius from earth center to sea level at
|
||||
local vertical (surface normal) of C.G.
|
||||
|
||||
--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
175
simgear/math/sg_geodesy.hxx
Normal file
175
simgear/math/sg_geodesy.hxx
Normal file
@@ -0,0 +1,175 @@
|
||||
// sg_geodesy.hxx -- routines to convert between geodetic and geocentric
|
||||
// coordinate systems.
|
||||
//
|
||||
// Copied and adapted directly from LaRCsim/ls_geodesy.c
|
||||
//
|
||||
// See below for the complete original LaRCsim comments.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_GEODESY_HXX
|
||||
#define _SG_GEODESY_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include <simgear/math/polar3d.hxx>
|
||||
|
||||
|
||||
// sgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
|
||||
// INPUTS:
|
||||
// lat_geoc Geocentric latitude, radians, + = North
|
||||
// radius C.G. radius to earth center (meters)
|
||||
//
|
||||
// OUTPUTS:
|
||||
// lat_geod Geodetic latitude, radians, + = North
|
||||
// alt C.G. altitude above mean sea level (meters)
|
||||
// sea_level_r radius from earth center to sea level at
|
||||
// local vertical (surface normal) of C.G. (meters)
|
||||
|
||||
void sgGeocToGeod( double lat_geoc, double radius, double
|
||||
*lat_geod, double *alt, double *sea_level_r );
|
||||
|
||||
|
||||
// sgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
|
||||
// INPUTS:
|
||||
// lat_geod Geodetic latitude, radians, + = North
|
||||
// alt C.G. altitude above mean sea level (meters)
|
||||
//
|
||||
// OUTPUTS:
|
||||
// sl_radius SEA LEVEL radius to earth center (meters)
|
||||
// (add Altitude to get true distance from earth center.
|
||||
// lat_geoc Geocentric latitude, radians, + = North
|
||||
//
|
||||
|
||||
void sgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
|
||||
double *lat_geoc );
|
||||
|
||||
|
||||
// convert a geodetic point lon(radians), lat(radians), elev(meter) to
|
||||
// a cartesian point
|
||||
|
||||
inline Point3D sgGeodToCart(const Point3D& geod) {
|
||||
double gc_lon, gc_lat, sl_radius;
|
||||
|
||||
// printf("A geodetic point is (%.2f, %.2f, %.2f)\n",
|
||||
// geod[0], geod[1], geod[2]);
|
||||
|
||||
gc_lon = geod.lon();
|
||||
sgGeodToGeoc(geod.lat(), geod.radius(), &sl_radius, &gc_lat);
|
||||
|
||||
// printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon,
|
||||
// gc_lat, sl_radius+geod[2]);
|
||||
|
||||
Point3D pp = Point3D( gc_lon, gc_lat, sl_radius + geod.radius());
|
||||
return sgPolarToCart3d(pp);
|
||||
}
|
||||
|
||||
|
||||
// given, alt, lat1, lon1, az1 and distance (s), calculate lat2, lon2
|
||||
// and az2. Lat, lon, and azimuth are in degrees. distance in meters
|
||||
int geo_direct_wgs_84 ( double alt, double lat1, double lon1, double az1,
|
||||
double s, double *lat2, double *lon2, double *az2 );
|
||||
|
||||
|
||||
// given alt, lat1, lon1, lat2, lon2, calculate starting and ending
|
||||
// az1, az2 and distance (s). Lat, lon, and azimuth are in degrees.
|
||||
// distance in meters
|
||||
int geo_inverse_wgs_84( double alt, double lat1, double lon1, double lat2,
|
||||
double lon2, double *az1, double *az2, double *s );
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
|
||||
TITLE: ls_geodesy
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
FUNCTION: Converts geocentric coordinates to geodetic positions
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
MODULE STATUS: developmental
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
DESIGNED BY: E. B. Jackson
|
||||
|
||||
CODED BY: E. B. Jackson
|
||||
|
||||
MAINTAINED BY: E. B. Jackson
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
MODIFICATION HISTORY:
|
||||
|
||||
DATE PURPOSE BY
|
||||
|
||||
930208 Modified to avoid singularity near polar region. EBJ
|
||||
930602 Moved backwards calcs here from ls_step. EBJ
|
||||
931214 Changed erroneous Latitude and Altitude variables to
|
||||
*lat_geod and *alt in routine ls_geoc_to_geod. EBJ
|
||||
940111 Changed header files from old ls_eom.h style to ls_types,
|
||||
and ls_constants. Also replaced old DATA type with new
|
||||
SCALAR type. EBJ
|
||||
|
||||
CURRENT RCS HEADER:
|
||||
|
||||
$Header$
|
||||
|
||||
* Revision 1.5 1994/01/11 18:47:05 bjax
|
||||
* Changed include files to use types and constants, not ls_eom.h
|
||||
* Also changed DATA type to SCALAR type.
|
||||
*
|
||||
* Revision 1.4 1993/12/14 21:06:47 bjax
|
||||
* Removed global variable references Altitude and Latitude. EBJ
|
||||
*
|
||||
* Revision 1.3 1993/06/02 15:03:40 bjax
|
||||
* Made new subroutine for calculating geodetic to geocentric; changed name
|
||||
* of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
|
||||
*
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
REFERENCES:
|
||||
|
||||
[ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
|
||||
Control and Simulation", Wiley and Sons, 1992.
|
||||
ISBN 0-471-61397-5
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
CALLED BY: ls_aux
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
CALLS TO:
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
INPUTS:
|
||||
lat_geoc Geocentric latitude, radians, + = North
|
||||
radius C.G. radius to earth center, ft
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
OUTPUTS:
|
||||
lat_geod Geodetic latitude, radians, + = North
|
||||
alt C.G. altitude above mean sea level, ft
|
||||
sea_level_r radius from earth center to sea level at
|
||||
local vertical (surface normal) of C.G.
|
||||
|
||||
--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif // _SG_GEODESY_HXX
|
||||
81
simgear/math/sg_random.c
Normal file
81
simgear/math/sg_random.c
Normal file
@@ -0,0 +1,81 @@
|
||||
// sg_random.c -- routines to handle random number generation
|
||||
//
|
||||
// Written by Curtis Olson, started July 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // for random(), srandom()
|
||||
#include <time.h> // for time() to seed srandom()
|
||||
|
||||
#include "sg_random.h"
|
||||
|
||||
#ifndef HAVE_RAND
|
||||
# ifdef sgi
|
||||
# undef RAND_MAX
|
||||
# define RAND_MAX 2147483647
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __SUNPRO_CC
|
||||
extern "C" {
|
||||
long int random(void);
|
||||
void srandom(unsigned int seed);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Seed the random number generater with time() so we don't see the
|
||||
// same sequence every time
|
||||
void sg_srandom_time(void) {
|
||||
#ifdef HAVE_RAND
|
||||
srand(time(NULL));
|
||||
#else
|
||||
srandom(time(NULL));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Seed the random number generater with your own seed so can set up
|
||||
// repeatable randomization.
|
||||
void sg_srandom( unsigned int seed ) {
|
||||
#ifdef HAVE_RAND
|
||||
srand( seed );
|
||||
#else
|
||||
srandom( seed );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// return a random number between [0.0, 1.0)
|
||||
double sg_random(void) {
|
||||
#ifdef HAVE_RAND
|
||||
return(rand() / (double)RAND_MAX);
|
||||
#else
|
||||
return(random() / (double)RAND_MAX);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
53
simgear/math/sg_random.h
Normal file
53
simgear/math/sg_random.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// sg_random.h -- routines to handle random number generation
|
||||
//
|
||||
// Written by Curtis Olson, started July 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_RANDOM_H
|
||||
#define _SG_RANDOM_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Seed the random number generater with time() so we don't see the
|
||||
// same sequence every time
|
||||
void sg_srandom_time(void);
|
||||
|
||||
// Seed the random number generater with your own seed so can set up
|
||||
// repeatable randomization.
|
||||
void sg_srandom( unsigned int seed );
|
||||
|
||||
// return a random number between [0.0, 1.0)
|
||||
double sg_random(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _SG_RANDOM_H
|
||||
|
||||
|
||||
74
simgear/math/sg_types.hxx
Normal file
74
simgear/math/sg_types.hxx
Normal file
@@ -0,0 +1,74 @@
|
||||
// fg_types.hxx -- commonly used types I don't want to have to keep redefining
|
||||
//
|
||||
// Written by Curtis Olson, started March 1999.
|
||||
//
|
||||
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _FG_TYPES_HXX
|
||||
#define _FG_TYPES_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
#include <vector>
|
||||
|
||||
#include <simgear/math/point3d.hxx>
|
||||
|
||||
FG_USING_STD(vector);
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
typedef vector < int > int_list;
|
||||
typedef int_list::iterator int_list_iterator;
|
||||
typedef int_list::const_iterator const_int_list_iterator;
|
||||
|
||||
typedef vector < Point3D > point_list;
|
||||
typedef point_list::iterator point_list_iterator;
|
||||
typedef point_list::const_iterator const_point_list_iterator;
|
||||
|
||||
typedef vector < string > string_list;
|
||||
typedef string_list::iterator string_list_iterator;
|
||||
typedef string_list::const_iterator const_string_list_iterator;
|
||||
|
||||
|
||||
class point2d {
|
||||
public:
|
||||
union {
|
||||
double x;
|
||||
double dist;
|
||||
double lon;
|
||||
};
|
||||
union {
|
||||
double y;
|
||||
double theta;
|
||||
double lat;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif // _FG_TYPES_HXX
|
||||
|
||||
78
simgear/math/sphrintp.h
Normal file
78
simgear/math/sphrintp.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
WARNING - Do not remove this header.
|
||||
|
||||
This code is a templated version of the 'magic-software' spherical
|
||||
interpolation code by Dave Eberly. The original (un-hacked) code can be
|
||||
obtained from here: http://www.magic-software.com/gr_appr.htm
|
||||
This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
|
||||
|
||||
Dave Eberly says that the conditions for use are:
|
||||
|
||||
* You may distribute the original source code to others at no charge.
|
||||
|
||||
* You may modify the original source code and distribute it to others at
|
||||
no charge. The modified code must be documented to indicate that it is
|
||||
not part of the original package.
|
||||
|
||||
* You may use this code for non-commercial purposes. You may also
|
||||
incorporate this code into commercial packages. However, you may not
|
||||
sell any of your source code which contains my original and/or modified
|
||||
source code. In such a case, you need to factor out my code and freely
|
||||
distribute it.
|
||||
|
||||
* The original code comes with absolutely no warranty and no guarantee is
|
||||
made that the code is bug-free.
|
||||
|
||||
This does not seem incompatible with GPL - so this modified version
|
||||
is hereby placed under GPL along with the rest of FlightGear.
|
||||
|
||||
Christian Mayer
|
||||
*/
|
||||
|
||||
#ifndef SPHRINTP_H
|
||||
#define SPHRINTP_H
|
||||
|
||||
#include "linintp2.h"
|
||||
#include <plib/sg.h>
|
||||
|
||||
template<class T>
|
||||
class SphereInterpolate
|
||||
{
|
||||
public:
|
||||
SphereInterpolate (int n, const double* x, const double* y,
|
||||
const double* z, const T* f);
|
||||
SphereInterpolate (int n, const sgVec2* p, const T* f);
|
||||
|
||||
~SphereInterpolate ();
|
||||
|
||||
void GetSphericalCoords (const double x, const double y, const double z,
|
||||
double& thetaAngle, double& phiAngle) const;
|
||||
|
||||
int Evaluate (const double x, const double y, const double z, T& f) const;
|
||||
int Evaluate (const double thetaAngle, const double phiAngle, T& f) const;
|
||||
|
||||
T Evaluate(const sgVec2& p) const
|
||||
{
|
||||
T retval;
|
||||
Evaluate(p[1], p[0], retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
T Evaluate(const sgVec3& p) const
|
||||
{
|
||||
T retval;
|
||||
Evaluate(p[1], p[0], retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
protected:
|
||||
int numPoints;
|
||||
double* theta;
|
||||
double* phi;
|
||||
T* func;
|
||||
mgcLinInterp2D<T>* pInterp;
|
||||
};
|
||||
|
||||
#include "sphrintp.inl"
|
||||
|
||||
#endif
|
||||
172
simgear/math/sphrintp.inl
Normal file
172
simgear/math/sphrintp.inl
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
WARNING - Do not remove this header.
|
||||
|
||||
This code is a templated version of the 'magic-software' spherical
|
||||
interpolation code by Dave Eberly. The original (un-hacked) code can be
|
||||
obtained from here: http://www.magic-software.com/gr_appr.htm
|
||||
This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
|
||||
|
||||
Dave Eberly says that the conditions for use are:
|
||||
|
||||
* You may distribute the original source code to others at no charge.
|
||||
|
||||
* You may modify the original source code and distribute it to others at
|
||||
no charge. The modified code must be documented to indicate that it is
|
||||
not part of the original package.
|
||||
|
||||
* You may use this code for non-commercial purposes. You may also
|
||||
incorporate this code into commercial packages. However, you may not
|
||||
sell any of your source code which contains my original and/or modified
|
||||
source code. In such a case, you need to factor out my code and freely
|
||||
distribute it.
|
||||
|
||||
* The original code comes with absolutely no warranty and no guarantee is
|
||||
made that the code is bug-free.
|
||||
|
||||
This does not seem incompatible with GPL - so this modified version
|
||||
is hereby placed under GPL along with the rest of FlightGear.
|
||||
|
||||
Christian Mayer
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "sphrintp.h"
|
||||
|
||||
static const double PI = 4.0*atan(1.0);
|
||||
static const double TWOPI = 2.0*PI;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
SphereInterpolate<T>::SphereInterpolate (int n, const double* x,
|
||||
const double* y, const double* z,
|
||||
const T* f)
|
||||
{
|
||||
// Assumes (x[i],y[i],z[i]) is unit length for all 0 <= i < n.
|
||||
// For complete spherical coverage, include the two antipodal points
|
||||
// (0,0,1,f(0,0,1)) and (0,0,-1,f(0,0,-1)) in the data set.
|
||||
|
||||
cout << "Initialising spherical interpolator.\n";
|
||||
cout << "[ 0%] Allocating memory \r";
|
||||
|
||||
theta = new double[3*n];
|
||||
phi = new double[3*n];
|
||||
func = new T[3*n];
|
||||
|
||||
// convert data to spherical coordinates
|
||||
int i;
|
||||
T empty;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
GetSphericalCoords(x[i],y[i],z[i],theta[i],phi[i]);
|
||||
func[i] = f[i];
|
||||
}
|
||||
|
||||
// use periodicity to get wrap-around in the Delaunay triangulation
|
||||
cout << "[ 10%] copying vertices for wrap-around\r";
|
||||
int j, k;
|
||||
for (i = 0, j = n, k = 2*n; i < n; i++, j++, k++)
|
||||
{
|
||||
theta[j] = theta[i]+TWOPI;
|
||||
theta[k] = theta[i]-TWOPI;
|
||||
phi[j] = phi[i];
|
||||
phi[k] = phi[i];
|
||||
func[j] = func[i];
|
||||
func[k] = func[i];
|
||||
}
|
||||
|
||||
pInterp = new mgcLinInterp2D<T>(3*n,theta,phi,func);
|
||||
|
||||
cout << "[100%] Finished initialising spherical interpolator. \n";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
SphereInterpolate<T>::SphereInterpolate (int n, const sgVec2* p, const T* f)
|
||||
{
|
||||
// Assumes (x[i],y[i],z[i]) is unit length for all 0 <= i < n.
|
||||
// For complete spherical coverage, include the two antipodal points
|
||||
// (0,0,1,f(0,0,1)) and (0,0,-1,f(0,0,-1)) in the data set.
|
||||
cout << "Initialising spherical interpolator.\n";
|
||||
cout << "[ 0%] Allocating memory \r";
|
||||
|
||||
theta = new double[3*n];
|
||||
phi = new double[3*n];
|
||||
func = new T[3*n];
|
||||
|
||||
// convert data to spherical coordinates
|
||||
cout << "[ 10%] copying vertices for wrap-around \r";
|
||||
|
||||
int i, j, k;
|
||||
for (i = 0, j = n, k = 2*n; i < n; i++, j++, k++)
|
||||
{
|
||||
phi[i] = p[i][0];
|
||||
theta[i] = p[i][1];
|
||||
func[i] = f[i];
|
||||
|
||||
// use periodicity to get wrap-around in the Delaunay triangulation
|
||||
phi[j] = phi[i];
|
||||
phi[k] = phi[i];
|
||||
theta[j] = theta[i]+TWOPI;
|
||||
theta[k] = theta[i]-TWOPI;
|
||||
func[j] = func[i];
|
||||
func[k] = func[i];
|
||||
}
|
||||
|
||||
pInterp = new mgcLinInterp2D<T>(3*n,theta,phi,func);
|
||||
|
||||
cout << "[100%] Finished initialising spherical interpolator. \n";
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
SphereInterpolate<T>::~SphereInterpolate ()
|
||||
{
|
||||
delete pInterp;
|
||||
delete[] theta;
|
||||
delete[] phi;
|
||||
delete[] func;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
void SphereInterpolate<T>::GetSphericalCoords (const double x, const double y, const double z,
|
||||
double& thetaAngle,
|
||||
double& phiAngle) const
|
||||
{
|
||||
// Assumes (x,y,z) is unit length. Returns -PI <= thetaAngle <= PI
|
||||
// and 0 <= phiAngle <= PI.
|
||||
|
||||
if ( z < 1.0f )
|
||||
{
|
||||
if ( z > -1.0f )
|
||||
{
|
||||
thetaAngle = atan2(y,x);
|
||||
phiAngle = acos(z);
|
||||
}
|
||||
else
|
||||
{
|
||||
thetaAngle = -PI;
|
||||
phiAngle = PI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
thetaAngle = -PI;
|
||||
phiAngle = 0.0f;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
int SphereInterpolate<T>::Evaluate (const double x, const double y, const double z, T& f) const
|
||||
{
|
||||
// assumes (x,y,z) is unit length
|
||||
|
||||
double thetaAngle, phiAngle;
|
||||
GetSphericalCoords(x,y,z,thetaAngle,phiAngle);
|
||||
return pInterp->Evaluate(thetaAngle,phiAngle,f);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
int SphereInterpolate<T>::Evaluate (const double thetaAngle, const double phiAngle, T& f) const
|
||||
{
|
||||
return pInterp->Evaluate(thetaAngle,phiAngle,f);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
137
simgear/math/vector.cxx
Normal file
137
simgear/math/vector.cxx
Normal file
@@ -0,0 +1,137 @@
|
||||
// vector.cxx -- additional vector routines
|
||||
//
|
||||
// Written by Curtis Olson, started December 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// #include <Include/fg_types.h>
|
||||
|
||||
#include "vector.hxx"
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the closest point (p1) on the line
|
||||
void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d ) {
|
||||
|
||||
sgVec3 u, u1;
|
||||
|
||||
// u = p - p0
|
||||
sgSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
|
||||
sgScaleVec3( u1, d, sgScalarProductVec3(u,d) / sgScalarProductVec3(d,d) );
|
||||
|
||||
// calculate the point p1 along the line that is closest to p
|
||||
// p0 = p1 + u1
|
||||
sgAddVec3(p1, p0, u1);
|
||||
}
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the closest point (p1) on the line
|
||||
void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d ) {
|
||||
|
||||
sgdVec3 u, u1;
|
||||
|
||||
// u = p - p0
|
||||
sgdSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
|
||||
double ud = sgdScalarProductVec3(u, d);
|
||||
double dd = sgdScalarProductVec3(d, d);
|
||||
double tmp = ud / dd;
|
||||
|
||||
sgdScaleVec3(u1, d, tmp);;
|
||||
|
||||
// calculate the point p1 along the line that is closest to p
|
||||
// p0 = p1 + u1
|
||||
sgdAddVec3(p1, p0, u1);
|
||||
}
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the shortest distance (squared) from the point to the line
|
||||
double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d ) {
|
||||
|
||||
sgVec3 u, u1, v;
|
||||
|
||||
// u = p - p0
|
||||
sgSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
|
||||
sgScaleVec3( u1, d, sgScalarProductVec3(u,d) / sgScalarProductVec3(d,d) );
|
||||
|
||||
// v = u - u1 = vector from closest point on line, p1, to the
|
||||
// original point, p.
|
||||
sgSubVec3(v, u, u1);
|
||||
|
||||
return ( sgScalarProductVec3(v, v) );
|
||||
}
|
||||
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the shortest distance (squared) from the point to the line
|
||||
double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d ) {
|
||||
|
||||
sgdVec3 u, u1, v;
|
||||
|
||||
// u = p - p0
|
||||
sgdSubVec3(u, p, p0);
|
||||
|
||||
// calculate the projection, u1, of u along d.
|
||||
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
|
||||
double ud = sgdScalarProductVec3(u, d);
|
||||
double dd = sgdScalarProductVec3(d, d);
|
||||
double tmp = ud / dd;
|
||||
|
||||
sgdScaleVec3(u1, d, tmp);;
|
||||
|
||||
// v = u - u1 = vector from closest point on line, p1, to the
|
||||
// original point, p.
|
||||
sgdSubVec3(v, u, u1);
|
||||
|
||||
return ( sgdScalarProductVec3(v, v) );
|
||||
}
|
||||
|
||||
|
||||
// This is a quicker form of
|
||||
// sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
|
||||
// sgPostMultMat4( sgMat, sgTRANS );
|
||||
void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans )
|
||||
{
|
||||
for( int i=0; i<4; i++) {
|
||||
for( int j=0; j<3; j++ ) {
|
||||
src[i][j] += (src[i][3] * trans[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
122
simgear/math/vector.hxx
Normal file
122
simgear/math/vector.hxx
Normal file
@@ -0,0 +1,122 @@
|
||||
// vector.hxx -- additional vector routines
|
||||
//
|
||||
// Written by Curtis Olson, started December 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _VECTOR_HXX
|
||||
#define _VECTOR_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <plib/sg.h>
|
||||
|
||||
|
||||
inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
|
||||
sgVec3 v0,
|
||||
sgVec3 vec,
|
||||
sgVec3 result )
|
||||
{
|
||||
sgVec3 u1, v, tmp;
|
||||
|
||||
// calculate a vector "u1" representing the shortest distance from
|
||||
// the plane specified by normal and v0 to a point specified by
|
||||
// "vec". "u1" represents both the direction and magnitude of
|
||||
// this desired distance.
|
||||
|
||||
// u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
|
||||
|
||||
sgScaleVec3( u1,
|
||||
normal,
|
||||
( sgScalarProductVec3(normal, vec) /
|
||||
sgScalarProductVec3(normal, normal)
|
||||
)
|
||||
);
|
||||
|
||||
// printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]);
|
||||
// printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]);
|
||||
// printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]);
|
||||
|
||||
// calculate the vector "v" which is the vector "vec" mapped onto
|
||||
// the plane specified by "normal" and "v0".
|
||||
|
||||
// v = v0 + vec - u1
|
||||
|
||||
sgAddVec3(tmp, v0, vec);
|
||||
sgSubVec3(v, tmp, u1);
|
||||
// printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
|
||||
|
||||
// Calculate the vector "result" which is "v" - "v0" which is a
|
||||
// directional vector pointing from v0 towards v
|
||||
|
||||
// result = v - v0
|
||||
|
||||
sgSubVec3(result, v, v0);
|
||||
// printf(" result = %.2f, %.2f, %.2f\n",
|
||||
// result[0], result[1], result[2]);
|
||||
}
|
||||
|
||||
|
||||
inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src )
|
||||
{
|
||||
dst [ 0 ] = -src [ 0 ] ;
|
||||
dst [ 1 ] = -src [ 1 ] ;
|
||||
dst [ 2 ] = -src [ 2 ] ;
|
||||
dst [ 3 ] = -src [ 3 ] ;
|
||||
}
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the closest point (p1) on the line
|
||||
void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d );
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the closest point (p1) on the line
|
||||
void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d );
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the shortest distance (squared) from the point to the line
|
||||
double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0,
|
||||
const sgVec3 d );
|
||||
|
||||
// Given a point p, and a line through p0 with direction vector d,
|
||||
// find the shortest distance (squared) from the point to the line
|
||||
double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
|
||||
const sgdVec3 d );
|
||||
|
||||
// This is same as
|
||||
// sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
|
||||
// sgPostMultMat4( sgMat, sgTRANS );
|
||||
void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans );
|
||||
|
||||
#endif // _VECTOR_HXX
|
||||
|
||||
|
||||
73
simgear/metar/Antoi.cpp
Normal file
73
simgear/metar/Antoi.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma comment(compiler)
|
||||
#pragma comment(date)
|
||||
#pragma comment(timestamp)
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#pragma title("antoi - char array to integer")
|
||||
#pragma pagesize (80)
|
||||
|
||||
#pragma page(1)
|
||||
/********************************************************************/
|
||||
/* */
|
||||
/* Title: antoi */
|
||||
/* Date: Jan 28, 1991 */
|
||||
/* Organization: W/OSO242 - Graphics and Display Section */
|
||||
/* Programmer: Allan Darling */
|
||||
/* Language: C/370 */
|
||||
/* */
|
||||
/* Abstract: This function will convert a character array */
|
||||
/* (string) of length (len) into an integer. */
|
||||
/* The integer is created via a call to the */
|
||||
/* function atoi. This function extends the */
|
||||
/* functionality of atoi by removing the */
|
||||
/* requirement for a sentinal delimited string */
|
||||
/* as input. */
|
||||
/* */
|
||||
/* Input: - Pointer to an array of characters. */
|
||||
/* - Integer indicating the number of character to include */
|
||||
/* in the conversion. */
|
||||
/* */
|
||||
/* Output:- An integer corresponding to the value in the character */
|
||||
/* array or MAXNEG (-2147483648) if the function is */
|
||||
/* unable to acquire system storage. */
|
||||
/* */
|
||||
/* Modification History: */
|
||||
/* None */
|
||||
/* */
|
||||
/********************************************************************/
|
||||
|
||||
int antoi(char * string, int len)
|
||||
{
|
||||
|
||||
/*******************/
|
||||
/* local variables */
|
||||
/*******************/
|
||||
|
||||
char * tmpstr;
|
||||
int i,
|
||||
retval;
|
||||
|
||||
|
||||
/*****************/
|
||||
/* function body */
|
||||
/*****************/
|
||||
|
||||
tmpstr = (char *)malloc((len+1) * sizeof(char));
|
||||
|
||||
if (tmpstr == NULL) return (-2147483648);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
tmpstr[i] = string[i];
|
||||
|
||||
tmpstr[len] = '\0';
|
||||
|
||||
retval = atoi(tmpstr);
|
||||
|
||||
free(tmpstr);
|
||||
|
||||
return(retval);
|
||||
|
||||
} /* end antoi */
|
||||
|
||||
#pragma page(1)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user