Compare commits

..

47 Commits

Author SHA1 Message Date
curt
180bba8767 Updated. 2000-03-29 21:28:14 +00:00
curt
377cf1662e For building redhat packages. 2000-03-29 00:00:46 +00:00
curt
420c747551 Ed Williams: Added some bulletproofing at the poles. 2000-03-28 22:08:31 +00:00
curt
7c5b4a87f2 Added gdbm 2000-03-28 22:06:34 +00:00
curt
7ea241b412 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.
2000-03-28 21:37:36 +00:00
curt
1547d4ee2f RedHat package building changes contributed by Habibie <habibie@MailandNews.com> 2000-03-28 19:49:07 +00:00
curt
3dde4113e7 Optimizations by Norman Vine:
Classic space vs time seemed worth it in that we get a ~3 fold speedup
  for ~5% space increase here.  Also pow() is an expensive Fortran to C
  translation in just about all the old government code I see :))
2000-03-28 15:20:20 +00:00
curt
205e6ef18f Bump up version # 2000-03-28 15:19:28 +00:00
curt
d53830076b Ready for 0.0.6 release. 2000-03-27 22:34:59 +00:00
curt
296a01b7bd Removed autogen file. 2000-03-27 22:30:32 +00:00
curt
f47fdd63f7 Return result in radians. 2000-03-27 22:30:11 +00:00
curt
b0b5f5035a Updated ... 2000-03-27 22:29:59 +00:00
curt
629ece6e41 Added. 2000-03-27 20:39:10 +00:00
curt
4c79263dcf Added simgear/magvar which impliments WMM 2000 world magnetic variance model.
contributed by Ed Williams.
Some additional internal rearrangement of code.
2000-03-27 20:36:26 +00:00
curt
856b6201dc #include "config.h" 2000-03-26 14:04:03 +00:00
curt
f2160b1479 MSVC++ tweaks contributed by Christian Mayer. 2000-03-21 21:06:07 +00:00
curt
535f6a13b3 Fixes for MSVC++. 2000-03-21 20:38:52 +00:00
curt
2ab760e456 Updates for next version. 2000-03-21 20:38:44 +00:00
curt
8b75fbc1e6 Update for next (0.0.6) release. 2000-03-17 22:20:32 +00:00
curt
82f410e955 Changed directory structure a bit to facilitate building for windows. 2000-03-17 22:12:16 +00:00
curt
68a19bd39f Rendering tweaks. 2000-03-17 05:16:15 +00:00
curt
48689622b4 Updated. 2000-03-16 22:44:50 +00:00
curt
acc2075986 Update star repainting to fade as the day get's brighter, also reworked
coloring just a bit.
2000-03-16 22:02:47 +00:00
curt
1984ae1583 Removed solarsystem.* replaced mostly with ephemeris.* which is similar
but not rendering oriented.
Added star database management class.
2000-03-16 22:00:53 +00:00
curt
427f309aea Complete overhaul of the sky/sun/moon/stars/planets. It is now an ssg
model that get's inserted into the scene graph.
2000-03-16 03:17:04 +00:00
curt
84482ad30d Pass current latitude to moon position calculations to compenstate for it's
parallax.
2000-03-16 03:14:23 +00:00
curt
09b67e9440 Updated to eliminate rendering component and allow initialization without a
known time.
2000-03-16 03:00:58 +00:00
curt
80cf74d85f Initial revision. 2000-03-07 00:47:37 +00:00
curt
17e055a00e Working on ssg-ifying sky. 2000-03-06 22:29:21 +00:00
curt
a8d8c9d24e Working on ssg-ifying the sky dome. Added the moon and other various tweaks. 2000-03-06 22:27:52 +00:00
curt
99a59763f1 Working on drawing sun and sun halo. 2000-03-02 23:07:25 +00:00
curt
0fa3a329e8 Fixed a typo in the sky dome painting code. 2000-03-02 19:06:28 +00:00
curt
5fbe532ec5 Sun now correctly placed in sky and correctly colored. 2000-03-02 18:20:52 +00:00
curt
5f3de889d7 Added top level ephemeris class. 2000-03-02 15:06:14 +00:00
curt
a8db14196a Working on separating out ephemeris code from the actual rendering code
which I am trying to ssg-ify at the same time.
2000-03-02 12:51:30 +00:00
curt
03b10d64a8 Separating out the Sky rendering as a separate unit and ssg-ifying it. 2000-03-02 02:03:18 +00:00
curt
86892d87e9 Starting to work on an independent sky implimentation that can be used by
any ssg application and can have it's components driven realistically based
on time.
2000-03-02 00:56:35 +00:00
curt
41218272c4 Working on skydome ... some actual progress has been made. :-) Still
something goofy with sunrise, sunset effects.
2000-02-29 23:31:32 +00:00
curt
8b5514fa9f Continuing work on ssg-ifying the sky dome. 2000-02-29 16:13:02 +00:00
curt
f14de56712 Further work on ssg-ifying the sky dome. (not tested) but I can build the
structures and update the colors.  I still need to set up the transforms
properly and connect it into the scene graph.
2000-02-28 23:04:07 +00:00
curt
ecc5c9865b Beginning work on a restructure of the sky code. 2000-02-28 12:58:41 +00:00
curt
929a56a6e8 Updated to 0.0.4 2000-02-22 16:21:15 +00:00
curt
4416df8c39 Added an include file that reports the current SimGear version. 2000-02-22 04:32:16 +00:00
curt
fc80610663 Removed mat3.h et. al. plib/sg.h provides a superset of mat3.h, has a
cleaner design, and is something that we are already linking in.
2000-02-19 20:58:58 +00:00
curt
cb03bfcb80 Fixed a warning message. 2000-02-19 02:28:58 +00:00
curt
35ed10e252 Updates. 2000-02-19 02:22:47 +00:00
curt
41fc1621b1 Updates .. 2000-02-17 16:04:35 +00:00
84 changed files with 4362 additions and 2430 deletions

View File

@@ -1,6 +1,14 @@
EXTRA_DIST = mksymlinks.sh
EXTRA_DIST = mksymlinks.sh acsite.m4 acconfig.h
SUBDIRS = simgear
#
# Rule to build RPM distribution package
#
rpm: dist
cp $(PACKAGE)-$(VERSION).tar.gz /usr/src/packages/SOURCES
rpm -ba @PACKAGE@.spec
dist-hook:
tar cf - src/metar | (cd $(distdir); tar xvf -)
tar cf - simgear/metar | (cd $(distdir); tar xvf -)
SUBDIRS = src

27
NEWS
View File

@@ -0,0 +1,27 @@
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

76
SimGear.spec.in Normal file
View 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

View File

@@ -1 +0,0 @@
@VERSION@

View File

@@ -181,6 +181,12 @@
/* 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

21
aclocal.m4 vendored
View File

@@ -1,7 +1,7 @@
dnl aclocal.m4 generated automatically by aclocal 1.3
dnl aclocal.m4 generated automatically by aclocal 1.4
dnl Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
dnl This Makefile.in is free software; the Free Software Foundation
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.
@@ -20,7 +20,7 @@ dnl Usage:
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
AC_DEFUN(AM_INIT_AUTOMAKE,
[AC_REQUIRE([AM_PROG_INSTALL])
[AC_REQUIRE([AC_PROG_INSTALL])
PACKAGE=[$1]
AC_SUBST(PACKAGE)
VERSION=[$2]
@@ -30,8 +30,8 @@ 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")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION"))
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.
@@ -43,15 +43,6 @@ AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
AC_REQUIRE([AC_PROG_MAKE_SET])])
# serial 1
AC_DEFUN(AM_PROG_INSTALL,
[AC_REQUIRE([AC_PROG_INSTALL])
test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
AC_SUBST(INSTALL_SCRIPT)dnl
])
#
# Check to make sure that the build environment is sane.
#

View File

@@ -3,10 +3,10 @@ dnl working configure script.
dnl
dnl $Id$
AC_INIT(src/bucket/newbucket.cxx)
AC_INIT(simgear/bucket/newbucket.cxx)
dnl Initialize the automake stuff
AM_INIT_AUTOMAKE(SimGear, 0.0.1)
AM_INIT_AUTOMAKE(SimGear, 0.0.7)
dnl Checks for programs.
AC_PROG_MAKE_SET
@@ -24,6 +24,10 @@ else
fi
dnl Run configure in the gdbm subdir
dnl AC_CONFIG_SUBDIRS( simgear/gdbm )
dnl Specify if we want logging (testing build) or not (release build)
# set logging default value
# with_logging=yes
@@ -196,9 +200,20 @@ if test "x$ac_cv_header_plib_pu_h" != "xyes"; then
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 zlib
AC_CHECK_HEADER(zlib.h)
if test "x$ac_cv_header_zlib_h" != "xyes"; then
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" )
@@ -221,24 +236,26 @@ AC_FUNC_VPRINTF
AC_CHECK_FUNCS( ftime gettimeofday timegm memcpy bcopy mktime strstr rand \
random setitimer getitimer signal GetLocalTime rint getrusage )
AM_CONFIG_HEADER(src/include/config.h)
AM_CONFIG_HEADER(simgear/config.h)
AC_OUTPUT( \
VERSION \
Makefile \
src/Makefile \
src/include/Makefile \
src/bucket/Makefile \
src/debug/Makefile \
src/math/Makefile \
src/misc/Makefile \
src/screen/Makefile \
src/serial/Makefile \
src/xgl/Makefile \
src/zlib/Makefile \
SimGear.spec \
simgear/Makefile \
simgear/version.h \
simgear/bucket/Makefile \
simgear/debug/Makefile \
simgear/gdbm/Makefile \
simgear/magvar/Makefile \
simgear/math/Makefile \
simgear/misc/Makefile \
simgear/screen/Makefile \
simgear/serial/Makefile \
simgear/xgl/Makefile \
simgear/zlib/Makefile \
)
AC_OUTPUT_COMMANDS([./mksymlinks.sh])
# AC_OUTPUT_COMMANDS([./mksymlinks.sh])
echo ""
echo "Configure Summary"
@@ -257,3 +274,11 @@ if test "x$with_efence" != "x"; then
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_zlib_h" != "xyes"; then
echo "Building zlib"
fi

View File

@@ -20,6 +20,7 @@ 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
@@ -28,7 +29,6 @@ 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/mat3.h src/simgear/math/mat3.h
ln -s ../../math/point3d.hxx src/simgear/math/point3d.hxx
ln -s ../../math/polar3d.hxx src/simgear/math/polar3d.hxx
@@ -37,3 +37,6 @@ 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

View File

@@ -4,6 +4,12 @@ else
SERIAL_DIRS =
endif
if HAVE_GDBM
GDBM_DIRS =
else
GDBM_DIRS = gdbm
endif
if HAVE_ZLIB
ZLIB_DIRS =
else
@@ -13,10 +19,15 @@ endif
METAR_DIRS =
# METAR_DIRS = metar
EXTRA_DIST = version.h.in
include_HEADERS = compiler.h constants.h fg_traits.hxx fg_zlib.h version.h
SUBDIRS = \
include \
bucket \
debug \
$(GDBM_DIRS) \
magvar \
math \
$(METAR_DIRS) \
misc \

View File

@@ -14,4 +14,4 @@ libsgbucket_a_SOURCES = newbucket.cxx
# $(top_builddir)/bucket/libsgbucket.a \
# $(top_builddir)/misc/libsgmisc.a
INCLUDES += -I$(top_builddir)/src
INCLUDES += -I$(top_builddir)

303
simgear/compiler.h Normal file
View File

@@ -0,0 +1,303 @@
/**************************************************************************
* compiler.h -- C++ Compiler Portability Macros
*
* 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 _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
//
// 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
# 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
# error MSVC++ 5.0 still to be supported...
# 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

212
simgear/config.h Normal file
View File

@@ -0,0 +1,212 @@
/* simgear/config.h. Generated automatically by configure. */
/* 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. */
#define HAVE_VPRINTF 1
/* 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>. */
#define TIME_WITH_SYS_TIME 1
/* 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. */
#define HAVE_VPRINTF 1
/* Define if you have gdbm installed system wide. */
#define HAVE_GDBM 1
/* Define if you have zlib installed system wide. */
#define HAVE_ZLIB 1
/* 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>. */
#define TIME_WITH_SYS_TIME 1
/* 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. */
#define HAVE_BCOPY 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 memcpy function. */
#define HAVE_MEMCPY 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 timegm function. */
#define HAVE_TIMEGM 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 <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_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. */
/* #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). */
#define HAVE_LIBGL 1
/* 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). */
#define HAVE_LIBICE 1
/* Define if you have the MesaGL library (-lMesaGL). */
/* #undef HAVE_LIBMESAGL */
/* Define if you have the MesaGLU library (-lMesaGLU). */
#define HAVE_LIBMESAGLU 1
/* 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 */
/* Name of package */
#define PACKAGE "SimGear"
/* Version number of package */
#define VERSION "0.0.7"

211
simgear/config.h.in Normal file
View File

@@ -0,0 +1,211 @@
/* 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 gdbm installed system wide. */
#undef HAVE_GDBM
/* 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

143
simgear/constants.h Normal file
View File

@@ -0,0 +1,143 @@
// constants.h -- various constant definitions
//
// Written by Curtis Olson, started February 2000.
//
// 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
// 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 _SUPPORTGEAR_CONSTANTS_H
#define _SUPPORTGEAR_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
// 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
// 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 // _SUPPORTGEAR_CONSTANTS_H

View File

@@ -8,4 +8,4 @@ include_HEADERS = debug_types.h logstream.hxx
libsgdebug_a_SOURCES = logstream.cxx
INCLUDES += -I$(top_builddir)/src
INCLUDES += -I$(top_builddir)

View File

@@ -1,7 +1,8 @@
noinst_LIBRARIES = libAstro.a
noinst_LIBRARIES = libEphemeris.a
libAstro_a_SOURCES = \
libEphemeris_a_SOURCES = \
celestialBody.cxx celestialBody.hxx \
ephemeris.cxx ephemeris.hxx \
jupiter.cxx jupiter.hxx \
mars.cxx mars.hxx \
mercury.cxx mercury.hxx \
@@ -9,8 +10,6 @@ libAstro_a_SOURCES = \
neptune.cxx neptune.hxx \
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 \

View File

@@ -87,8 +87,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

View File

@@ -39,8 +39,8 @@ 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 */
@@ -72,8 +72,17 @@ public:
double af, double as,
double ef, double es,
double Mf, double Ms, FGTime *t);
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);
@@ -115,6 +124,21 @@ inline CelestialBody::CelestialBody(double Nf, double Ns,
updateOrbElements(t);
};
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)
* given the current time, this private member calculates the actual
@@ -171,6 +195,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;

View File

@@ -0,0 +1,82 @@
// 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 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 "ephemeris.hxx"
// Constructor
FGEphemeris::FGEphemeris( const string &path ) {
our_sun = new Star;
moon = new Moon;
mercury = new Mercury;
venus = new Venus;
mars = new Mars;
jupiter = new Jupiter;
saturn = new Saturn;
uranus = new Uranus;
neptune = new Neptune;
stars = new FGStars( FGPath(path) );
}
// Destructor
FGEphemeris::~FGEphemeris( 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 FGEphemeris::update( FGTime *t, double lat ) {
// update object positions
our_sun->updatePosition( t );
moon->updatePosition( t, lat, our_sun );
mercury->updatePosition( t, our_sun );
venus->updatePosition( t, our_sun );
mars->updatePosition( t, our_sun );
jupiter->updatePosition( t, our_sun );
saturn->updatePosition( t, our_sun );
uranus->updatePosition( t, our_sun );
neptune->updatePosition( t, 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] );
}

View File

@@ -0,0 +1,108 @@
// ephemeris.hxx -- 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 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 _EPHEMERIS_HXX
#define _EPHEMERIS_HXX
#include <plib/sg.h>
#include <Time/fg_time.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 "stars.hxx"
class FGEphemeris {
Star *our_sun;
Moon *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];
FGStars *stars;
public:
// Constructor
FGEphemeris( const string &path );
// Destructor
~FGEphemeris( void );
// Update (recalculate) the positions of all objects for the
// specified time
void update(FGTime *t, 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 Moon *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

View File

@@ -47,6 +47,16 @@ Jupiter::Jupiter(FGTime *t) :
{
}
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)
*

View File

@@ -32,6 +32,7 @@ class Jupiter : public CelestialBody
{
public:
Jupiter (FGTime *t);
Jupiter ();
void updatePosition(FGTime *t, Star *ourSun);
};

View File

@@ -45,6 +45,15 @@ Mars::Mars(FGTime *t) :
18.60210, 0.52402077660, t)
{
}
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)
*

View File

@@ -32,6 +32,7 @@ class Mars : public CelestialBody
{
public:
Mars ( FGTime *t);
Mars ();
void updatePosition(FGTime *t, Star *ourSun);
};

View File

@@ -45,6 +45,15 @@ Mercury::Mercury(FGTime *t) :
168.6562, 4.09233443680, t)
{
}
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)
*

View File

@@ -32,6 +32,7 @@ class Mercury : public CelestialBody
{
public:
Mercury ( FGTime *t);
Mercury ();
void updatePosition(FGTime *t, Star* ourSun);
};

View File

@@ -40,6 +40,7 @@
#include "moon.hxx"
/*************************************************************************
* Moon::Moon(FGTime *t)
* Public constructor for class Moon. Initializes the orbital elements and
@@ -56,6 +57,7 @@ Moon::Moon(FGTime *t) :
0.054900, 0.000000,
115.3654, 13.0649929509, t)
{
#if 0
int width, height;
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
@@ -125,16 +127,29 @@ Moon::Moon(FGTime *t) :
GL_RGBA, GL_UNSIGNED_BYTE,
moon_halotexbuf);
moonObject = gluNewQuadric();
#endif
}
Moon::Moon() :
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)
{
}
Moon::~Moon()
{
//delete moonObject;
delete moon_texbuf;
delete moon_halotexbuf;
//delete moonObject;
// delete moon_texbuf;
// delete moon_halotexbuf;
}
#if 0
static int texWidth = 256; /* 64x64 is plenty */
void Moon::setHalo()
@@ -182,6 +197,7 @@ void Moon::setHalo()
// GL_UNSIGNED_BYTE, textureBuf);
//free(textureBuf);
}
#endif
/*****************************************************************************
@@ -190,7 +206,7 @@ void Moon::setHalo()
* the position of the moon as seen from the current position on the surface
* of the moon.
****************************************************************************/
void Moon::updatePosition(FGTime *t, Star *ourSun)
void Moon::updatePosition(FGTime *t, double lat, Star *ourSun)
{
double
eccAnom, ecl, actTime,
@@ -255,7 +271,7 @@ void Moon::updatePosition(FGTime *t, Star *ourSun)
r += (-0.58 * cos(M - 2*D)
-0.46 * cos(2*D)
);
FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
// 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);
@@ -282,11 +298,11 @@ void Moon::updatePosition(FGTime *t, Star *ourSun)
// 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() );
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 * f->get_Latitude());
rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * lat);
// FG_LOG( FG_GENERAL, FG_INFO, "rho = " << rho );
if (geoRa < 0)
@@ -308,6 +324,7 @@ void Moon::updatePosition(FGTime *t, Star *ourSun)
}
#if 0
/************************************************************************
* void Moon::newImage()
*
@@ -396,3 +413,4 @@ void Moon::newImage()
{
}
}
#endif

View File

@@ -24,6 +24,7 @@
#ifndef _MOON_HXX_
#define _MOON_HXX_
#include <simgear/constants.h>
#include <Aircraft/aircraft.hxx>
@@ -35,22 +36,27 @@
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;
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();
// void setHalo();
public:
Moon ( FGTime *t);
~Moon();
void updatePosition(FGTime *t, Star *ourSun);
void newImage();
Moon( FGTime *t);
Moon();
~Moon();
void updatePosition(FGTime *t, double lat, Star *ourSun);
// void newImage();
};

View File

@@ -45,6 +45,15 @@ Neptune::Neptune(FGTime *t) :
260.2471, 0.00599514700, t)
{
}
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)
*

View File

@@ -32,6 +32,7 @@ class Neptune : public CelestialBody
{
public:
Neptune ( FGTime *t);
Neptune ();
void updatePosition(FGTime *t, Star *ourSun);
};

View File

@@ -30,7 +30,8 @@
class Pluto : public CelestialBody
{
public:
Pluto ( FGTime t);
Pluto ( FGTime *t);
Pluto ();
};
#endif // _PLUTO_HXX_

View File

@@ -45,6 +45,15 @@ Saturn::Saturn(FGTime *t) :
316.9670, 0.03344422820, t)
{
}
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)

View File

@@ -32,6 +32,7 @@ class Saturn : public CelestialBody
{
public:
Saturn ( FGTime *t);
Saturn ();
void updatePosition(FGTime *t, Star *ourSun);
};

View File

@@ -1,377 +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 <simgear/xgl/xgl.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_random.h>
#include <Aircraft/aircraft.hxx>
#include <FDM/flight.hxx>
#include <Main/views.hxx>
#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 GLubyte inner_color[12][4];
static GLubyte middle_color[12][4];
static GLubyte 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] = (GLubyte)((l->sky_color[j] - diff * 0.3) * 255);
middle_color[i][j] = (GLubyte)((l->sky_color[j] - diff * 0.9
+ middle_amt[j]) * 255);
outer_color[i][j] = (GLubyte)((l->fog_color[j] + outer_amt[j])
* 255);
if ( inner_color[i][j] > 255 ) { inner_color[i][j] = 255; }
if ( inner_color[i][j] < 25 ) { inner_color[i][j] = 25; }
if ( middle_color[i][j] > 255 ) { middle_color[i][j] = 255; }
if ( middle_color[i][j] < 25 ) { middle_color[i][j] = 25; }
if ( outer_color[i][j] > 255 ) { outer_color[i][j] = 255; }
if ( outer_color[i][j] < 25 ) { outer_color[i][j] = 25; }
}
inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
(GLubyte)(l->sky_color[3] * 255);
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] = (GLubyte)((l->sky_color[j] - diff * 0.3) * 255);
middle_color[i][j] = (GLubyte)((l->sky_color[j] - diff * 0.9
+ middle_amt[j]) * 255);
outer_color[i][j] = (GLubyte)((l->fog_color[j] + outer_amt[j])
* 255);
if ( inner_color[i][j] > 255 ) { inner_color[i][j] = 255; }
if ( inner_color[i][j] < 25 ) { inner_color[i][j] = 25; }
if ( middle_color[i][j] > 255 ) { middle_color[i][j] = 255; }
if ( middle_color[i][j] < 25 ) { middle_color[i][j] = 25; }
if ( outer_color[i][j] > 255 ) { outer_color[i][j] = 255; }
if ( outer_color[i][j] < 35 ) { outer_color[i][j] = 35; }
}
inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
(GLubyte)(l->sky_color[3] * 255);
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;
GLubyte sky_color[4];
GLubyte inner_color[4];
GLubyte middle_color[4];
GLubyte 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] = (GLubyte)((l->sky_color[i] - diff * 0.3) * 255);
middle_color[i] = (GLubyte)((l->sky_color[i] - diff * 0.9) * 255);
outer_color[i] = (GLubyte)(l->adj_fog_color[i] * 255);
}
inner_color[3] = middle_color[3] = outer_color[3] =
(GLubyte)(l->adj_fog_color[3] * 255);
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 );
for ( i = 0; i < 4; i++ ) {
sky_color[i] = (GLubyte)(l->sky_color[i] * 255);
}
xglColor4fv(l->sky_color);
xglVertex3f(0.0, 0.0, CENTER_ELEV);
for ( i = 11; i >= 0; i-- ) {
xglColor4ubv( inner_color );
xglVertex3fv( inner_vertex[i] );
}
xglColor4ubv( inner_color );
xglVertex3fv( inner_vertex[11] );
xglEnd();
// Draw the middle ring
xglBegin( GL_TRIANGLE_STRIP );
for ( i = 0; i < 12; i++ ) {
xglColor4ubv( 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] );
xglColor4ubv( 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] );
}
xglColor4ubv( middle_color );
// xglColor4f(1.0, 0.0, 0.0, 1.0);
xglVertex3fv( middle_vertex[0] );
xglColor4ubv( 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++ ) {
xglColor4ubv( outer_color );
xglVertex3fv( outer_vertex[i] );
xglColor4ubv( middle_color );
xglVertex3fv( middle_vertex[i] );
}
xglColor4ubv( outer_color );
xglVertex3fv( outer_vertex[0] );
xglColor4ubv( middle_color );
xglVertex3fv( middle_vertex[0] );
xglEnd();
// Draw the bottom skirt
xglBegin( GL_TRIANGLE_STRIP );
xglColor4ubv( 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();
}

View File

@@ -1,217 +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 <simgear/xgl/xgl.h>
#include <simgear/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();
}

View File

@@ -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_

View File

@@ -22,6 +22,7 @@
* $Id$
**************************************************************************/
#ifdef __BORLANDC__
# define exception c_exception
#endif
@@ -35,6 +36,7 @@
#include "star.hxx"
/*************************************************************************
* Star::Star(FGTime *t)
* Public constructor for class Star
@@ -45,105 +47,34 @@
* 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)
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)
{
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;
*p = 0xff;
*(p+1) = 0xff;
*(p+2) = 0xff;
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+3) = (int)((double) 0xff * (t*t));
} else {
*(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(FGTime *t, Star *ourSun)
*
* calculates the current position of our sun.
*************************************************************************/
@@ -184,87 +115,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);
glBlendFunc ( GL_SRC_ALPHA, 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
}
}

View File

@@ -24,35 +24,31 @@
#ifndef _STAR_HXX_
#define _STAR_HXX_
#include <Time/fg_time.hxx>
#include "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 (FGTime *t);
Star ();
~Star();
void updatePosition(FGTime *t);
double getM();
double getw();
double getxs();
double getys();
double getDistance();
};
inline double Star::getM()

View File

@@ -1,8 +1,8 @@
// stars.cxx -- data structures and routines for managing and rendering stars.
// stars.cxx -- manage star data
//
// Written by Curtis Olson, started August 1997.
// Written by Curtis Olson, started March 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
@@ -19,250 +19,100 @@
// 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 <simgear/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 <simgear/xgl/xgl.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
#include <simgear/misc/fgstream.hxx>
#include <simgear/misc/stopwatch.hxx>
#include <Aircraft/aircraft.hxx>
#include <Main/options.hxx>
#include <Main/views.hxx>
#include <Time/fg_time.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
// Constructor
FGStars::FGStars() {
}
// Define four structures, each with varying amounts of stars
static GLint stars[FG_STAR_LEVELS];
FGStars::FGStars( FGPath path ) {
data_path = FGPath( path );
load();
}
// Initialize the Star Management Subsystem
int fgStarsInit( void ) {
// Destructor
FGStars::~FGStars() {
}
bool FGStars::load() {
// -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;
stars = new sgdVec3[FG_MAX_STARS];
FG_LOG( FG_ASTRO, FG_INFO, "Initializing 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() );
if ( FG_STAR_LEVELS < 4 ) {
FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
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);
}
// 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() );
double ra, dec, mag;
char c;
string name;
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();
nstars = 0;
// read in each line of the file
while ( ! in.eof() && starcount < FG_MAX_STARS )
{
while ( ! in.eof() && nstars < 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" );
getline( in, name, ',' );
// cout << " data = " << name << endl;
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) );
// read name and first comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
} // 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);
in >> ra;
xglCallList(stars[i]);
} else {
// printf("not RENDERING STARS (day)\n");
// 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;
}

View File

@@ -1,8 +1,8 @@
// stars.hxx -- data structures and routines for managing and rendering stars.
// stars.hxx -- manage star data
//
// Written by Curtis Olson, started August 1997.
// Written by Curtis Olson, started March 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
@@ -25,23 +25,37 @@
#define _STARS_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/sg.h>
#include <Time/fg_time.hxx>
#include <simgear/misc/fgpath.hxx>
#define FG_STAR_LEVELS 8 // how many star transitions
// Initialize the Star Management Subsystem
int fgStarsInit( void );
#define FG_MAX_STARS 850
// Draw the Stars
void fgStarsRender( void );
// [no longer used?] extern FGTime cur_time_params;
class FGStars {
int nstars;
sgdVec3 *stars;
FGPath data_path;
public:
// Constructor
FGStars();
FGStars( FGPath path );
// Destructor
~FGStars();
// load the stars database
bool load();
// stars
inline int getNumStars() const { return nstars; }
inline sgdVec3 *getStars() { return stars; }
};
#endif // _STARS_HXX

View File

@@ -45,6 +45,15 @@ Uranus::Uranus(FGTime *t) :
142.5905, 0.01172580600, t)
{
}
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)

View File

@@ -32,6 +32,7 @@ class Uranus : public CelestialBody
{
public:
Uranus ( FGTime *t);
Uranus ();
void updatePosition(FGTime *t, Star *ourSun);
};

View File

@@ -45,6 +45,15 @@ Venus::Venus(FGTime *t) :
48.00520, 1.60213022440, t)
{
}
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)

View File

@@ -32,6 +32,7 @@ class Venus : public CelestialBody
{
public:
Venus ( FGTime *t);
Venus ();
void updatePosition(FGTime *t, Star *ourSun);
};

23
simgear/fg_traits.hxx Normal file
View 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

86
simgear/fg_zlib.h Normal file
View File

@@ -0,0 +1,86 @@
/**************************************************************************
* 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 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 _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 */

View File

@@ -0,0 +1,15 @@
includedir = @includedir@/magvar
lib_LIBRARIES = libsgmagvar.a
include_HEADERS = magvar.hxx
libsgmagvar_a_SOURCES = magvar.cxx
noinst_PROGRAMS = testmagvar
testmagvar_SOURCES = testmagvar.cxx
testmagvar_LDADD = $(top_builddir)/simgear/magvar/libsgmagvar.a
INCLUDES += -I$(top_builddir)

464
simgear/magvar/magvar.cxx Normal file
View File

@@ -0,0 +1,464 @@
// magvar.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 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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "magvar.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;
}
/* Convert degrees to radians */
double deg_to_rad( double deg )
{
return deg*pi/180.;
}
/* Convert radians to degrees */
double rad_to_deg( double rad )
{
return rad*180./pi;
}
/*
* 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 SGMagVar( 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

56
simgear/magvar/magvar.hxx Normal file
View File

@@ -0,0 +1,56 @@
// magvar.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 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_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 );
/* Convert degrees to radians */
double deg_to_rad( double deg );
/* Convert radians to degrees */
double rad_to_deg( double rad );
/* 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 SGMagVar( double lat, double lon, double h, long dat, double* field );
#endif // SG_MAGVAR_HXX

View File

@@ -0,0 +1,56 @@
/* 2/14/00 fixed help message- dip angle (down positive), variation (E positive) */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "magvar.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 = SGMagVar( 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);
}

View File

@@ -1,168 +0,0 @@
/* #include "HEADERS.h" */
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that perform geometry-related operations
* on matrices.
* -------------------------------------------------------------------------*/
#include "mat3defs.h"
/* -------------------------- Static Routines ---------------------------- */
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
/*
* This takes a matrix used to transform points, and returns a corresponding
* matrix that can be used to transform direction vectors (between points).
*/
void
MAT3direction_matrix(register double (*result_mat)[4], register double (*mat)[4])
{
register int i;
MAT3copy(result_mat, mat);
for (i = 0; i < 4; i++) result_mat[i][3] = result_mat[3][i] = 0.0;
result_mat[3][3] = 1.0;
}
/*
* This takes a matrix used to transform points, and returns a corresponding
* matrix that can be used to transform vectors that must remain perpendicular
* to planes defined by the points. It is useful when you are transforming
* some object that has both points and normals in its definition, and you
* only have the transformation matrix for the points. This routine returns
* FALSE if the normal matrix is uncomputable. Otherwise, it returns TRUE.
*
* Spike sez: "This is the adjoint for the non-homogeneous part of the
* transformation."
*/
int
MAT3normal_matrix(register double (*result_mat)[4], register double (*mat)[4])
{
register int ret;
MAT3mat tmp_mat;
MAT3direction_matrix(result_mat, mat);
if ( (ret = MAT3invert(tmp_mat, tmp_mat)) ) {
MAT3transpose(result_mat, tmp_mat);
}
return(ret);
}
/*
* Sets the given matrix to be a scale matrix for the given vector of
* scale values.
*/
void
MAT3scale(double (*result_mat)[4], double *scale)
{
MAT3identity(result_mat);
result_mat[0][0] = scale[0];
result_mat[1][1] = scale[1];
result_mat[2][2] = scale[2];
}
/*
* Sets up a matrix for a rotation about an axis given by the line from
* (0,0,0) to axis, through an angle (in radians).
* Looking along the axis toward the origin, the rotation is counter-clockwise.
*/
#define SELECT .7071 /* selection constant (roughly .5*sqrt(2) */
void
MAT3rotate(double (*result_mat)[4], double *axis, double angle_in_radians)
{
MAT3vec naxis, /* Axis of rotation, normalized */
base2, /* 2nd unit basis vec, perp to axis */
base3; /* 3rd unit basis vec, perp to axis & base2 */
double dot;
MAT3mat base_mat, /* Change-of-basis matrix */
base_mat_trans; /* Inverse of c-o-b matrix */
register int i;
/* Step 1: extend { axis } to a basis for 3-space: { axis, base2, base3 }
* which is orthonormal (all three have unit length, and all three are
* mutually orthogonal). Also should be oriented, i.e. axis cross base2 =
* base3, rather than -base3.
*
* Method: Find a vector linearly independent from axis. For this we
* either use the y-axis, or, if that is too close to axis, the
* z-axis. 'Too close' means that the dot product is too near to 1.
*/
MAT3_COPY_VEC(naxis, axis);
MAT3_NORMALIZE_VEC(naxis, dot);
if (dot == 0.0) {
/* ERR_ERROR(MAT3_errid, ERR_SEVERE,
(ERR_S, "Zero-length axis vector given to MAT3rotate")); */
return;
}
MAT3perp_vec(base2, naxis, TRUE);
MAT3cross_product(base3, naxis, base2);
/* Set up the change-of-basis matrix, and its inverse */
MAT3identity(base_mat);
MAT3identity(base_mat_trans);
MAT3identity(result_mat);
for (i = 0; i < 3; i++){
base_mat_trans[i][0] = base_mat[0][i] = naxis[i];
base_mat_trans[i][1] = base_mat[1][i] = base2[i];
base_mat_trans[i][2] = base_mat[2][i] = base3[i];
}
/* If T(u) = uR, where R is base_mat, then T(x-axis) = naxis,
* T(y-axis) = base2, and T(z-axis) = base3. The inverse of base_mat is
* its transpose. OK?
*/
result_mat[1][1] = result_mat[2][2] = cos(angle_in_radians);
result_mat[2][1] = -(result_mat[1][2] = sin(angle_in_radians));
MAT3mult(result_mat, base_mat_trans, result_mat);
MAT3mult(result_mat, result_mat, base_mat);
}
/*
* Sets the given matrix to be a translation matrix for the given vector of
* translation values.
*/
void
MAT3translate(double (*result_mat)[4], double *trans)
{
MAT3identity(result_mat);
result_mat[3][0] = trans[0];
result_mat[3][1] = trans[1];
result_mat[3][2] = trans[2];
}
/*
* Sets the given matrix to be a shear matrix for the given x and y shear
* values.
*/
void
MAT3shear(double (*result_mat)[4], double xshear, double yshear)
{
MAT3identity(result_mat);
result_mat[2][0] = xshear;
result_mat[2][1] = yshear;
}

View File

@@ -1,311 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that operate solely on matrices.
* -------------------------------------------------------------------------*/
#include "mat3defs.h"
/* -------------------------- Static Routines ---------------------------- */
#define SMALL 1e-20 /* Small enough to be considered zero */
/*
* Shuffles rows in inverse of 3x3. See comment in MAT3_inv3_second_col().
*/
static void
MAT3_inv3_swap( register double inv[3][3], int row0, int row1, int row2)
{
register int i, tempi;
double temp;
#define SWAP_ROWS(a, b) \
for (i = 0; i < 3; i++) SWAP(inv[a][i], inv[b][i], temp); \
SWAP(a, b, tempi)
if (row0 != 0){
if (row1 == 0) {
SWAP_ROWS(row0, row1);
}
else {
SWAP_ROWS(row0, row2);
}
}
if (row1 != 1) {
SWAP_ROWS(row1, row2);
}
}
/*
* Does Gaussian elimination on second column.
*/
static int
MAT3_inv3_second_col (register double source[3][3], register double inv[3][3], int row0)
{
register int row1, row2, i1, i2, i;
double temp;
double a, b;
/* Find which row to use */
if (row0 == 0) i1 = 1, i2 = 2;
else if (row0 == 1) i1 = 0, i2 = 2;
else i1 = 0, i2 = 1;
/* Find which is larger in abs. val.:the entry in [i1][1] or [i2][1] */
/* and use that value for pivoting. */
a = source[i1][1]; if (a < 0) a = -a;
b = source[i2][1]; if (b < 0) b = -b;
if (a > b) row1 = i1;
else row1 = i2;
row2 = (row1 == i1 ? i2 : i1);
/* Scale row1 in source */
if ((source[row1][1] < SMALL) && (source[row1][1] > -SMALL)) return(FALSE);
temp = 1.0 / source[row1][1];
source[row1][1] = 1.0;
source[row1][2] *= temp; /* source[row1][0] is zero already */
/* Scale row1 in inv */
inv[row1][row1] = temp; /* it used to be a 1.0 */
inv[row1][row0] *= temp;
/* Clear column one, source, and make corresponding changes in inv */
for (i = 0; i < 3; i++) if (i != row1) { /* for i = all rows but row1 */
temp = -source[i][1];
source[i][1] = 0.0;
source[i][2] += temp * source[row1][2];
inv[i][row1] = temp * inv[row1][row1];
inv[i][row0] += temp * inv[row1][row0];
}
/* Scale row2 in source */
if ((source[row2][2] < SMALL) && (source[row2][2] > -SMALL)) return(FALSE);
temp = 1.0 / source[row2][2];
source[row2][2] = 1.0; /* source[row2][*] is zero already */
/* Scale row2 in inv */
inv[row2][row2] = temp; /* it used to be a 1.0 */
inv[row2][row0] *= temp;
inv[row2][row1] *= temp;
/* Clear column one, source, and make corresponding changes in inv */
for (i = 0; i < 3; i++) if (i != row2) { /* for i = all rows but row2 */
temp = -source[i][2];
source[i][2] = 0.0;
inv[i][row0] += temp * inv[row2][row0];
inv[i][row1] += temp * inv[row2][row1];
inv[i][row2] += temp * inv[row2][row2];
}
/*
* Now all is done except that the inverse needs to have its rows shuffled.
* row0 needs to be moved to inv[0][*], row1 to inv[1][*], etc.
*
* We *didn't* do the swapping before the elimination so that we could more
* easily keep track of what ops are needed to be done in the inverse.
*/
MAT3_inv3_swap(inv, row0, row1, row2);
return(TRUE);
}
/*
* Fast inversion routine for 3 x 3 matrices. - Written by jfh.
*
* This takes 30 multiplies/divides, as opposed to 39 for Cramer's Rule.
* The algorithm consists of performing fast gaussian elimination, by never
* doing any operations where the result is guaranteed to be zero, or where
* one operand is guaranteed to be zero. This is done at the cost of clarity,
* alas.
*
* Returns 1 if the inverse was successful, 0 if it failed.
*/
static int
MAT3_invert3 (register double source[3][3], register double inv[3][3])
{
register int i, row0;
double temp;
double a, b, c;
inv[0][0] = inv[1][1] = inv[2][2] = 1.0;
inv[0][1] = inv[0][2] = inv[1][0] = inv[1][2] = inv[2][0] = inv[2][1] = 0.0;
/* attempt to find the largest entry in first column to use as pivot */
a = source[0][0]; if (a < 0) a = -a;
b = source[1][0]; if (b < 0) b = -b;
c = source[2][0]; if (c < 0) c = -c;
if (a > b) {
if (a > c) row0 = 0;
else row0 = 2;
}
else {
if (b > c) row0 = 1;
else row0 = 2;
}
/* Scale row0 of source */
if ((source[row0][0] < SMALL) && (source[row0][0] > -SMALL)) return(FALSE);
temp = 1.0 / source[row0][0];
source[row0][0] = 1.0;
source[row0][1] *= temp;
source[row0][2] *= temp;
/* Scale row0 of inverse */
inv[row0][row0] = temp; /* other entries are zero -- no effort */
/* Clear column zero of source, and make corresponding changes in inverse */
for (i = 0; i < 3; i++) if (i != row0) { /* for i = all rows but row0 */
temp = -source[i][0];
source[i][0] = 0.0;
source[i][1] += temp * source[row0][1];
source[i][2] += temp * source[row0][2];
inv[i][row0] = temp * inv[row0][row0];
}
/*
* We've now done gaussian elimination so that the source and
* inverse look like this:
*
* 1 * * * 0 0
* 0 * * * 1 0
* 0 * * * 0 1
*
* We now proceed to do elimination on the second column.
*/
if (! MAT3_inv3_second_col(source, inv, row0)) return(FALSE);
return(TRUE);
}
/*
* Finds a new pivot for a non-simple 4x4. See comments in MAT3invert().
*/
static int
MAT3_inv4_pivot (register MAT3mat src, MAT3vec r, double *s, int *swap)
{
register int i, j;
double temp, max;
*swap = -1;
if (MAT3_IS_ZERO(src[3][3])) {
/* Look for a different pivot element: one with largest abs value */
max = 0.0;
for (i = 0; i < 4; i++) {
if (src[i][3] > max) max = src[*swap = i][3];
else if (src[i][3] < -max) max = -src[*swap = i][3];
}
/* No pivot element available ! */
if (*swap < 0) return(FALSE);
else for (j = 0; j < 4; j++) SWAP(src[*swap][j], src[3][j], temp);
}
MAT3_SET_VEC (r, -src[0][3], -src[1][3], -src[2][3]);
*s = 1.0 / src[3][3];
src[0][3] = src[1][3] = src[2][3] = 0.0;
src[3][3] = 1.0;
MAT3_SCALE_VEC(src[3], src[3], *s);
for (i = 0; i < 3; i++) {
src[0][i] += r[0] * src[3][i];
src[1][i] += r[1] * src[3][i];
src[2][i] += r[2] * src[3][i];
}
return(TRUE);
}
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
/*
* This returns the inverse of the given matrix. The result matrix
* may be the same as the one to invert.
*
* Fast inversion routine for 4 x 4 matrices, written by jfh.
*
* Returns 1 if the inverse was successful, 0 if it failed.
*
* This routine has been specially tweaked to notice the following:
* If the matrix has the form
* * * * 0
* * * * 0
* * * * 0
* * * * 1
*
* (as do many matrices in graphics), then we compute the inverse of
* the upper left 3x3 matrix and use this to find the general inverse.
*
* In the event that the right column is not 0-0-0-1, we do gaussian
* elimination to make it so, then use the 3x3 inverse, and then do
* our gaussian elimination.
*/
int
MAT3invert(double (*result_mat)[4], double (*mat)[4])
{
MAT3mat src, inv;
register int i, j, simple;
double m[3][3], inv3[3][3], s, temp;
MAT3vec r, t;
int swap;
MAT3copy(src, mat);
MAT3identity(inv);
/* If last column is not (0,0,0,1), use special code */
simple = (mat[0][3] == 0.0 && mat[1][3] == 0.0 &&
mat[2][3] == 0.0 && mat[3][3] == 1.0);
if (! simple && ! MAT3_inv4_pivot(src, r, &s, &swap)) return(FALSE);
MAT3_COPY_VEC(t, src[3]); /* Translation vector */
/* Copy upper-left 3x3 matrix */
for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) m[i][j] = src[i][j];
if (! MAT3_invert3(m, inv3)) return(FALSE);
for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) inv[i][j] = inv3[i][j];
for (i = 0; i < 3; i++) for (j = 0; j < 3; j++)
inv[3][i] -= t[j] * inv3[j][i];
if (! simple) {
/* We still have to undo our gaussian elimination from earlier on */
/* add r0 * first col to last col */
/* add r1 * 2nd col to last col */
/* add r2 * 3rd col to last col */
for (i = 0; i < 4; i++) {
inv[i][3] += r[0] * inv[i][0] + r[1] * inv[i][1] + r[2] * inv[i][2];
inv[i][3] *= s;
}
if (swap >= 0)
for (i = 0; i < 4; i++) SWAP(inv[i][swap], inv[i][3], temp);
}
MAT3copy(result_mat, inv);
return(TRUE);
}

View File

@@ -1,120 +0,0 @@
/* #include "HEADERS.h" */
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that operate solely on matrices.
* -------------------------------------------------------------------------*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef WIN32
# ifndef HAVE_STL_SGI_PORT
# ifdef __BORLANDC__
# include <mem.h>
# else
# include <memory.h> /* required for memset() and memcpy() */
# endif
# endif
#endif
#include <string.h>
#include "mat3defs.h"
MAT3mat identityMatrix = {
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 0.0, 1.0 }
};
/* #include "macros.h" */
/* -------------------------- Static Routines ---------------------------- */
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
#if !defined( USE_XTRA_MAT3_INLINES )
/*
* This multiplies two matrices, producing a third, which may the same as
* either of the first two.
*/
void
MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
{
register int i, j;
MAT3mat tmp_mat;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
mat1[i][1] * mat2[1][j] +
mat1[i][2] * mat2[2][j] +
mat1[i][3] * mat2[3][j]);
MAT3copy (result_mat, tmp_mat);
}
#endif // !defined( USE_XTRA_MAT3_INLINES )
/*
* This returns the transpose of a matrix. The result matrix may be
* the same as the one to transpose.
*/
void
MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
{
register int i, j;
MAT3mat tmp_mat;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
tmp_mat[i][j] = mat[j][i];
MAT3copy (result_mat, tmp_mat);
}
/*
* This prints the given matrix to the given file pointer.
*/
void
MAT3print(double (*mat)[4], FILE *fp)
{
MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
}
/*
* This prints the given matrix to the given file pointer.
* use the format string to pass to fprintf. head and tail
* are printed at the beginning and end of each line.
*/
void
MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
{
register int i, j;
/* This is to allow this to be called easily from a debugger */
if (fp == NULL) fp = stderr;
if (title == NULL) title = "MAT3 matrix:\n";
if (head == NULL) head = " ";
if (format == NULL) format = "%#8.4lf ";
if (tail == NULL) tail = "\n";
(void) fprintf(fp, title);
for (i = 0; i < 4; i++) {
(void) fprintf(fp, head);
for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
(void) fprintf(fp, tail);
}
}

View File

@@ -1,154 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that operate on matrices and vectors, or
* vectors and vectors.
* -------------------------------------------------------------------------*/
/* #include "sphigslocal.h" */
/* -------------------------- Static Routines ---------------------------- */
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
/*
* Multiplies a vector by a matrix, setting the result vector.
* It assumes all homogeneous coordinates are 1.
* The two vectors involved may be the same.
*/
#include "mat3.h"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#if !defined( USE_XTRA_MAT3_INLINES )
void
MAT3mult_vec(double *result_vec, register double *vec, register double (*mat)[4])
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + mat[3][2];
MAT3_COPY_VEC(result_vec, temp);
}
#endif // !defined( USE_XTRA_MAT3_INLINES )
/*
* Multiplies a vector of size 4 by a matrix, setting the result vector.
* The fourth element of the vector is the homogeneous coordinate, which
* may or may not be 1. If the "normalize" parameter is TRUE, then the
* result vector will be normalized so that the homogeneous coordinate is 1.
* The two vectors involved may be the same.
* This returns zero if the vector was to be normalized, but couldn't be.
*/
int
MAT3mult_hvec(double *result_vec, register double *vec, register double (*mat)[4], int normalize)
{
MAT3hvec tempvec;
double norm_fac;
register double *temp = tempvec;
register int ret = TRUE;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + vec[3] * mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + vec[3] * mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + vec[3] * mat[3][2];
temp[3] = vec[0] * mat[0][3] + vec[1] * mat[1][3] +
vec[2] * mat[2][3] + vec[3] * mat[3][3];
/* Normalize if asked for, possible, and necessary */
if (normalize) {
if (MAT3_IS_ZERO(temp[3])) {
#ifndef THINK_C
fprintf (stderr,
"Can't normalize vector: homogeneous coordinate is 0");
#endif
ret = FALSE;
}
else {
norm_fac = 1.0 / temp[3];
MAT3_SCALE_VEC(result_vec, temp, norm_fac);
result_vec[3] = 1.0;
}
}
else MAT3_COPY_HVEC(result_vec, temp);
return(ret);
}
#if !defined( USE_XTRA_MAT3_INLINES )
/*
* Sets the first vector to be the cross-product of the last two vectors.
*/
void
MAT3cross_product(double *result_vec, register double *vec1, register double *vec2)
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
temp[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
temp[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
MAT3_COPY_VEC(result_vec, temp);
}
#endif // !defined( USE_XTRA_MAT3_INLINES )
/*
* Finds a vector perpendicular to vec and stores it in result_vec.
* Method: take any vector (we use <0,1,0>) and subtract the
* portion of it pointing in the vec direction. This doesn't
* work if vec IS <0,1,0> or is very near it. So if this is
* the case, use <0,0,1> instead.
* If "is_unit" is TRUE, the given vector is assumed to be unit length.
*/
#define SELECT .7071 /* selection constant (roughly .5*sqrt(2) */
void
MAT3perp_vec(double *result_vec, double *vec, int is_unit)
{
MAT3vec norm;
double dot;
MAT3_SET_VEC(result_vec, 0.0, 1.0, 0.0);
MAT3_COPY_VEC(norm, vec);
if (! is_unit) MAT3_NORMALIZE_VEC(norm, dot);
/* See if vector is too close to <0,1,0>. If so, use <0,0,1> */
if ((dot = MAT3_DOT_PRODUCT(norm, result_vec)) > SELECT || dot < -SELECT) {
result_vec[1] = 0.0;
result_vec[2] = 1.0;
dot = MAT3_DOT_PRODUCT(norm, result_vec);
}
/* Subtract off non-perpendicular part */
result_vec[0] -= dot * norm[0];
result_vec[1] -= dot * norm[1];
result_vec[2] -= dot * norm[2];
/* Make result unit length */
MAT3_NORMALIZE_VEC(result_vec, dot);
}

View File

@@ -1,5 +1,11 @@
includedir = @includedir@/math
if HAVE_ZLIB
ZLIB_INCL =
else
ZLIB_INCL = -I$(top_builddir)/src/zlib
endif
lib_LIBRARIES = libsgmath.a
include_HEADERS = \
@@ -9,7 +15,6 @@ include_HEADERS = \
fg_types.hxx \
interpolater.hxx \
leastsqs.hxx \
mat3.h \
point3d.hxx \
polar3d.hxx \
vector.hxx
@@ -17,16 +22,11 @@ include_HEADERS = \
EXTRA_DIST = linintp2.h linintp2.inl sphrintp.h sphrintp.inl
libsgmath_a_SOURCES = \
MAT3geom.c \
MAT3inv.c \
MAT3mat.c \
MAT3vec.c \
fg_geodesy.cxx \
fg_random.c \
interpolater.cxx \
leastsqs.cxx \
mat3defs.h mat3err.h \
polar3d.cxx \
vector.cxx
INCLUDES += -I$(top_builddir)/src
INCLUDES += -I$(top_builddir) $(ZLIB_INCL)

View File

@@ -1,233 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* -------------------------------------------------------------------------
Public MAT3 include file
------------------------------------------------------------------------- */
#ifndef MAT3_HAS_BEEN_INCLUDED
#define MAT3_HAS_BEEN_INCLUDED
/* ----------------------------- Constants ------------------------------ */
/*
* Make sure the math library .h file is included, in case it wasn't.
*/
#ifndef HUGE
#include <math.h>
#endif
#include <stdio.h>
#include <string.h>
#include <simgear/math/fg_memory.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAT3_DET0 -1 /* Indicates singular mat */
#define MAT3_EPSILON 1e-12 /* Close enough to zero */
#ifdef M_PI
# define MAT3_PI M_PI
#else
# define MAT3_PI 3.14159265358979323846
#endif
#define USE_XTRA_MAT3_INLINES
#if defined(i386)
#define USE_X86_ASM
#endif
#if defined(USE_X86_ASM)
static __inline__ int FloatToInt(float f)
{
int r;
__asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
return r;
}
#elif defined(__MSC__) && defined(__WIN32__)
static __inline int FloatToInt(float f)
{
int r;
_asm {
fld f
fistp r
}
return r;
}
#else
#define FloatToInt(F) ((int) ((F) < 0.0f ? (F)-0.5f : (F)+0.5f))
#endif
/* ------------------------------ Types --------------------------------- */
typedef double MAT3mat[4][4]; /* 4x4 matrix */
typedef double MAT3vec[3]; /* Vector */
typedef double MAT3hvec[4]; /* Vector with homogeneous coord */
/* ------------------------------ Macros -------------------------------- */
extern MAT3mat identityMatrix;
/* Tests if a number is within EPSILON of zero */
#define MAT3_IS_ZERO(N) ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
/* Sets a vector to the three given values */
#define MAT3_SET_VEC(V,X,Y,Z) ((V)[0]=(X), (V)[1]=(Y), (V)[2]=(Z))
/* Tests a vector for all components close to zero */
#define MAT3_IS_ZERO_VEC(V) (MAT3_IS_ZERO((V)[0]) && \
MAT3_IS_ZERO((V)[1]) && \
MAT3_IS_ZERO((V)[2]))
/* Dot product of two vectors */
#define MAT3_DOT_PRODUCT(V1,V2) \
((V1)[0]*(V2)[0] + (V1)[1]*(V2)[1] + (V1)[2]*(V2)[2])
/* Copy one vector to other */
#define MAT3_COPY_VEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2])
/* Normalize vector to unit length, using TEMP as temporary variable.
* TEMP will be zero if vector has zero length */
#define MAT3_NORMALIZE_VEC(V,TEMP) \
if ((TEMP = sqrt(MAT3_DOT_PRODUCT(V,V))) > MAT3_EPSILON) { \
TEMP = 1.0 / TEMP; \
MAT3_SCALE_VEC(V,V,TEMP); \
} else TEMP = 0.0
/* Scale vector by given factor, storing result vector in RESULT_V */
#define MAT3_SCALE_VEC(RESULT_V,V,SCALE) \
MAT3_SET_VEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), (V)[2]*(SCALE))
/* Adds vectors V1 and V2, storing result in RESULT_V */
#define MAT3_ADD_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2])
/* Subtracts vector V2 from V1, storing result in RESULT_V */
#define MAT3_SUB_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2])
/* Multiplies vectors V1 and V2, storing result in RESULT_V */
#define MAT3_MULT_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2])
/* Sets RESULT_V to the linear combination of V1 and V2, scaled by
* SCALE1 and SCALE2, respectively */
#define MAT3_LINEAR_COMB(RESULT_V,SCALE1,V1,SCALE2,V2) \
MAT3_SET_VEC(RESULT_V, (SCALE1)*(V1)[0] + (SCALE2)*(V2)[0], \
(SCALE1)*(V1)[1] + (SCALE2)*(V2)[1], \
(SCALE1)*(V1)[2] + (SCALE2)*(V2)[2])
/* Several of the vector macros are useful for homogeneous-coord vectors */
#define MAT3_SET_HVEC(V,X,Y,Z,W) ((V)[0]=(X), (V)[1]=(Y), \
(V)[2]=(Z), (V)[3]=(W))
#define MAT3_COPY_HVEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2], \
(TO)[3] = (FROM)[3])
#define MAT3_SCALE_HVEC(RESULT_V,V,SCALE) \
MAT3_SET_HVEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), \
(V)[2]*(SCALE), (V)[3]*(SCALE))
#define MAT3_ADD_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2], (V1)[3]+(V2)[3])
#define MAT3_SUB_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2], (V1)[3]-(V2)[3])
#define MAT3_MULT_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2], (V1)[3]*(V2)[3])
/* ------------------------------ Entries ------------------------------- */
#define MAT3identity(mat) fgmemcpy( mat, identityMatrix, sizeof(MAT3mat) )
#define MAT3zero(mat) fgmemzero( mat, sizeof(MAT3mat) )
#define MAT3copy(to, from) fgmemcpy( to, from, sizeof(MAT3mat) )
#if defined( USE_XTRA_MAT3_INLINES )
# define MAT3mult_vec( result_vec, vec, mat) { \
MAT3vec tempvec; \
tempvec[0]=vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0]; \
tempvec[1]=vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1]; \
tempvec[2]=vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2]; \
result_vec[0] = tempvec[0]; \
result_vec[1] = tempvec[1]; \
result_vec[2] = tempvec[2]; \
}
# define MAT3cross_product(result_vec, vec1, vec2) { \
MAT3vec tempvec; \
tempvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; \
tempvec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]; \
tempvec[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0]; \
result_vec[0] = tempvec[0]; \
result_vec[1] = tempvec[1]; \
result_vec[2] = tempvec[2]; \
}
# define MAT3mult( result_mat, mat1, mat2) { \
register int i, j; \
MAT3mat tmp_mat; \
for (i = 0; i < 4; i++) \
for (j = 0; j < 4; j++) \
tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + \
mat1[i][1] * mat2[1][j] + \
mat1[i][2] * mat2[2][j] + \
mat1[i][3] * mat2[3][j]); \
fgmemcpy(result_mat, tmp_mat, sizeof(MAT3mat)); \
}
#else // !defined( USE_XTRA_MAT3_INLINES )
/* In MAT3mat.c */
void MAT3mult(MAT3mat result, MAT3mat, MAT3mat);
void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
#endif // defined( USE_XTRA_MAT3_INLINES )
/* In MAT3geom.c */
void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat);
int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat);
void MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians);
void MAT3translate (MAT3mat result_mat, MAT3vec trans);
void MAT3scale (MAT3mat result_mat, MAT3vec scale);
void MAT3shear(MAT3mat result_mat, double xshear, double yshear);
void MAT3transpose (MAT3mat result, MAT3mat);
int MAT3invert (MAT3mat result, MAT3mat);
void MAT3print (MAT3mat, FILE *fp);
void MAT3print_formatted (MAT3mat, FILE *fp,
char *title, char *head, char *format, char *tail);
int MAT3equal( void );
double MAT3trace( void );
int MAT3power( void );
int MAT3column_reduce( void );
int MAT3kernel_basis( void );
/* In MAT3vec.c */
int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
#ifdef __cplusplus
}
#endif
#endif /* MAT3_HAS_BEEN_INCLUDED */

View File

@@ -1,56 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
#ifndef _MAT3DEFS_H
#define _MAT3DEFS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
/* #include <Math/mat3err.h> */
#include "mat3.h"
/* ----------------------------- Constants ------------------------------ */
#define FALSE 0
#define TRUE 1
#define CNULL ((char *) NULL)
/* ------------------------------ Macros -------------------------------- */
#define ALLOCN(P,T,N,M) \
if ((P = (T *) malloc((unsigned) (N) * sizeof(T))) == NULL) \
ERR_ERROR(MAT3_errid, ERR_FATAL, (ERR_ALLOC1, M)); \
else
#define FREE(P) free((char *) (P))
#define ABS(A) ((A) > 0 ? (A) : -(A))
#define MIN(A,B) ((A) < (B) ? (A) : (B))
#define MAX(A,B) ((A) > (B) ? (A) : (B))
#define SWAP(A,B,T) (T = A, A = B, B = T)
/* Is N within EPS of zero ? */
#define IS_ZERO(N,EPS) ((N) < EPS && (N) > -EPS)
/* Macros for lu routines */
#define LU_PERMUTE(p,i,j) { int LU_T; LU_T = p[i]; p[i] = p[j]; p[j] = LU_T; }
/* ------------------------- Internal Entries ---------------------------- */
/* ------------------------- Global Variables ---------------------------- */
/* extern ERRid *MAT3_errid; */
#ifdef __cplusplus
}
#endif
#endif /* _MAT3DEFS_H */

View File

@@ -1,41 +0,0 @@
#ifndef _MAT3ERR_H
#define _MAT3ERR_H
#ifdef __cplusplus
extern "C" {
#endif
#include "sph_errtypes.h"
#ifdef THINK_C
/* We hide this from gnu's compiler, which doesn't understand it. */
void SPH__error (int errtype, ...);
#endif
#define ERR_ERROR(A,B,C) \
if (1) {char cstr[256]; sprintf C; SPH__error(ERR_MAT3_PACKAGE, cstr); } else
#define ERR_S cstr,"%s\n"
#define ERR_SI cstr,"%s: %d\n"
#define ERR_SS cstr,"%s: %s\n"
#define ERR_SEVERE 0
#define ERR_FATAL 0
#define ERR_ALLOC1 0
typedef int ERRid;
#define ERRregister_package(S) 100
#ifdef __cplusplus
}
#endif
#endif /* _MAT3ERR_H */

View File

@@ -28,102 +28,6 @@
#include "vector.hxx"
#include "mat3.h"
// Map a vector onto the plane specified by normal
void map_vec_onto_cur_surface_plane(MAT3vec normal, MAT3vec v0, MAT3vec vec,
MAT3vec result)
{
MAT3vec 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
MAT3_SCALE_VEC( u1,
normal,
( MAT3_DOT_PRODUCT(normal, vec) /
MAT3_DOT_PRODUCT(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
MAT3_ADD_VEC(tmp, v0, vec);
MAT3_SUB_VEC(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
MAT3_SUB_VEC(result, v, v0);
// printf(" result = %.2f, %.2f, %.2f\n",
// result[0], result[1], result[2]);
}
// Given a point p, and a line through p0 with direction vector d,
// find the shortest distance from the point to the line
double fgPointLine(MAT3vec p, MAT3vec p0, MAT3vec d) {
MAT3vec u, u1, v;
double ud, dd, tmp;
// u = p - p0
MAT3_SUB_VEC(u, p, p0);
// calculate the projection, u1, of u along d.
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
ud = MAT3_DOT_PRODUCT(u, d);
dd = MAT3_DOT_PRODUCT(d, d);
tmp = ud / dd;
MAT3_SCALE_VEC(u1, d, tmp);;
// v = u - u1 = vector from closest point on line, p1, to the
// original point, p.
MAT3_SUB_VEC(v, u, u1);
return sqrt(MAT3_DOT_PRODUCT(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 fgPointLineSquared(MAT3vec p, MAT3vec p0, MAT3vec d) {
MAT3vec u, u1, v;
double ud, dd, tmp;
// u = p - p0
MAT3_SUB_VEC(u, p, p0);
// calculate the projection, u1, of u along d.
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
ud = MAT3_DOT_PRODUCT(u, d);
dd = MAT3_DOT_PRODUCT(d, d);
tmp = ud / dd;
MAT3_SCALE_VEC(u1, d, tmp);;
// v = u - u1 = vector from closest point on line, p1, to the
// original point, p.
MAT3_SUB_VEC(v, u, u1);
return ( MAT3_DOT_PRODUCT(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

View File

@@ -37,15 +37,6 @@
#include <plib/sg.h>
#include <simgear/math/mat3.h>
// Map a vector onto the plane specified by normal
void map_vec_onto_cur_surface_plane( MAT3vec normal,
MAT3vec v0,
MAT3vec vec,
MAT3vec result );
inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
sgVec3 v0,
@@ -92,16 +83,6 @@ inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
}
// Given a point p, and a line through p0 with direction vector d,
// find the shortest distance from the point to the line
double fgPointLine(MAT3vec p, MAT3vec p0, MAT3vec 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 fgPointLineSquared(MAT3vec p, MAT3vec p0, MAT3vec 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 sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0,

View File

@@ -10,8 +10,8 @@
#include <iostream>
#include <string>
#include <vector>
#include <Math/point3d.hxx>
#include <Math/polar3d.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
class CMetarReport
{

View File

@@ -9,7 +9,7 @@
// options is too tightly integrated into FlightGear to use in a test program
#include <Main/options.hxx>
#endif
#include <Misc/fgpath.hxx>
#include <simgear/misc/fgpath.hxx>
std::vector< CMetarStation *> METAR_Stations;

View File

@@ -11,8 +11,8 @@
#include <iostream>
#include <string>
#include <vector>
#include <Math/point3d.hxx>
#include <Math/polar3d.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
//using namespace std;
class CMetarStation

View File

@@ -3,7 +3,7 @@ includedir = @includedir@/misc
if HAVE_ZLIB
ZLIB_INCL =
else
ZLIB_INCL = -I$(top_builddir)/zlib
ZLIB_INCL = -I$(top_builddir)/src/zlib
endif
lib_LIBRARIES = libsgmisc.a
@@ -23,4 +23,4 @@ libsgmisc_a_SOURCES = \
texcoord.cxx \
zfstream.cxx
INCLUDES += -I$(top_builddir)/src
INCLUDES += -I$(top_builddir) $(ZLIB_INCL)

View File

@@ -80,7 +80,9 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes,
Point3D tmin, tmax, p, t;
bool first = true;
for ( int i = 0; i < (int)fan.size(); ++i ) {
int i;
for ( i = 0; i < (int)fan.size(); ++i ) {
p = geod_nodes[ fan[i] ];
// cout << "point p = " << p << endl;
@@ -162,7 +164,7 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes,
Point3D adjusted_t;
point_list tex;
tex.clear();
for ( int i = 0; i < (int)fan.size(); ++i ) {
for ( i = 0; i < (int)fan.size(); ++i ) {
p = geod_nodes[ fan[i] ];
t = basic_tex_coord( p, degree_width, degree_height, scale );
// cout << "second t = " << t << endl;

View File

@@ -24,9 +24,17 @@
#ifndef _zfstream_hxx
#define _zfstream_hxx
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <simgear/compiler.h>
#include <zlib.h>
#ifdef HAVE_ZLIB
# include <zlib.h>
#else
# include <simgear/zlib/zlib.h>
#endif
#ifdef FG_HAVE_STD_INCLUDES

View File

@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h> // memcpy()
#include <GL/glut.h>
#include <simgear/xgl/xgl.h>

View File

@@ -9,4 +9,4 @@ libsgscreen_a_SOURCES = \
screen-dump.cxx \
win32-printer.h
INCLUDES += -I$(top_builddir)/src
INCLUDES += -I$(top_builddir)

View File

@@ -11,7 +11,7 @@ libsgserial_a_SOURCES = serial.cxx
testserial_SOURCES = testserial.cxx
testserial_LDADD = \
$(top_builddir)/src/serial/libsgserial.a \
$(top_builddir)/src/debug/libsgdebug.a
$(top_builddir)/simgear/serial/libsgserial.a \
$(top_builddir)/simgear/debug/libsgdebug.a
INCLUDES += -I$(top_builddir)/src
INCLUDES += -I$(top_builddir)

View File

@@ -4,7 +4,7 @@
#include "serial.hxx"
main () {
int main () {
FGSerialPort port;
string value;
bool result;
@@ -27,4 +27,6 @@ main () {
cout << "-> " << value << endl;
}
}
return 0;
}

11
simgear/sky/Makefile.am Normal file
View File

@@ -0,0 +1,11 @@
noinst_LIBRARIES = libSky.a
libSky_a_SOURCES = \
dome.cxx dome.hxx \
moon.cxx moon.hxx \
oursun.cxx oursun.hxx \
sky.cxx sky.hxx \
sphere.cxx sphere.hxx \
stars.cxx stars.hxx
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src

512
simgear/sky/dome.cxx Normal file
View File

@@ -0,0 +1,512 @@
// dome.cxx -- model sky with an upside down "bowl"
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
//
// Copyright (C) 1997-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
// 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 <simgear/xgl/xgl.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_random.h>
#include "dome.hxx"
#ifdef __MWERKS__
# pragma global_optimizer off
#endif
// in meters of course
#define CENTER_ELEV 25000.0
#define UPPER_RADIUS 50000.0
#define UPPER_ELEV 20000.0
#define MIDDLE_RADIUS 70000.0
#define MIDDLE_ELEV 8000.0
#define LOWER_RADIUS 80000.0
#define LOWER_ELEV 0.0
#define BOTTOM_RADIUS 50000.0
#define BOTTOM_ELEV -2000.0
// Set up dome rendering callbacks
static int sgSkyDomePreDraw( ssgEntity *e ) {
/* cout << endl << "Dome Pre Draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
return true;
}
static int sgSkyDomePostDraw( ssgEntity *e ) {
/* cout << endl << "Dome Post Draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
// Constructor
SGSkyDome::SGSkyDome( void ) {
}
// Destructor
SGSkyDome::~SGSkyDome( void ) {
}
// initialize the sky object and connect it into our scene graph
ssgBranch * SGSkyDome::build( ) {
sgVec4 color;
float theta;
int i;
// set up the state
dome_state = new ssgSimpleState();
dome_state->setShadeModel( GL_SMOOTH );
dome_state->disable( GL_LIGHTING );
dome_state->disable( GL_CULL_FACE );
dome_state->disable( GL_TEXTURE_2D );
dome_state->enable( GL_COLOR_MATERIAL );
dome_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
dome_state->disable( GL_BLEND );
dome_state->disable( GL_ALPHA_TEST );
// initialize arrays
center_disk_vl = new ssgVertexArray( 14 );
center_disk_cl = new ssgColourArray( 14 );
upper_ring_vl = new ssgVertexArray( 26 );
upper_ring_cl = new ssgColourArray( 26 );
middle_ring_vl = new ssgVertexArray( 26 );
middle_ring_cl = new ssgColourArray( 26 );
lower_ring_vl = new ssgVertexArray( 26 );
lower_ring_cl = new ssgColourArray( 26 );
// initially seed to all blue
sgSetVec4( color, 0.0, 0.0, 1.0, 1.0 );
// generate the raw vertex data
sgVec3 center_vertex;
sgVec3 upper_vertex[12];
sgVec3 middle_vertex[12];
sgVec3 lower_vertex[12];
sgVec3 bottom_vertex[12];
sgSetVec3( center_vertex, 0.0, 0.0, CENTER_ELEV );
for ( i = 0; i < 12; i++ ) {
theta = (i * 30.0) * DEG_TO_RAD;
sgSetVec3( upper_vertex[i],
cos(theta) * UPPER_RADIUS,
sin(theta) * UPPER_RADIUS,
UPPER_ELEV );
sgSetVec3( middle_vertex[i],
cos((double)theta) * MIDDLE_RADIUS,
sin((double)theta) * MIDDLE_RADIUS,
MIDDLE_ELEV );
sgSetVec3( lower_vertex[i],
cos((double)theta) * LOWER_RADIUS,
sin((double)theta) * LOWER_RADIUS,
LOWER_ELEV );
sgSetVec3( bottom_vertex[i],
cos((double)theta) * BOTTOM_RADIUS,
sin((double)theta) * BOTTOM_RADIUS,
BOTTOM_ELEV );
}
// generate the center disk vertex/color arrays
center_disk_vl->add( center_vertex );
center_disk_cl->add( color );
for ( i = 11; i >= 0; i-- ) {
center_disk_vl->add( upper_vertex[i] );
center_disk_cl->add( color );
}
center_disk_vl->add( upper_vertex[11] );
center_disk_cl->add( color );
// generate the upper ring
for ( i = 0; i < 12; i++ ) {
upper_ring_vl->add( middle_vertex[i] );
upper_ring_cl->add( color );
upper_ring_vl->add( upper_vertex[i] );
upper_ring_cl->add( color );
}
upper_ring_vl->add( middle_vertex[0] );
upper_ring_cl->add( color );
upper_ring_vl->add( upper_vertex[0] );
upper_ring_cl->add( color );
// generate middle ring
for ( i = 0; i < 12; i++ ) {
middle_ring_vl->add( lower_vertex[i] );
middle_ring_cl->add( color );
middle_ring_vl->add( middle_vertex[i] );
middle_ring_cl->add( color );
}
middle_ring_vl->add( lower_vertex[0] );
middle_ring_cl->add( color );
middle_ring_vl->add( middle_vertex[0] );
middle_ring_cl->add( color );
// generate lower ring
for ( i = 0; i < 12; i++ ) {
lower_ring_vl->add( bottom_vertex[i] );
lower_ring_cl->add( color );
lower_ring_vl->add( lower_vertex[i] );
lower_ring_cl->add( color );
}
lower_ring_vl->add( bottom_vertex[0] );
lower_ring_cl->add( color );
lower_ring_vl->add( lower_vertex[0] );
lower_ring_cl->add( color );
// force a repaint of the sky colors with ugly defaults
sgVec3 fog_color;
sgSetVec3( fog_color, 1.0, 1.0, 1.0 );
repaint( color, fog_color, 0.0 );
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
ssgVtxTable *center_disk, *upper_ring, *middle_ring, *lower_ring;
center_disk = new ssgVtxTable( GL_TRIANGLE_FAN,
center_disk_vl, NULL, NULL, center_disk_cl );
upper_ring = new ssgVtxTable( GL_TRIANGLE_STRIP,
upper_ring_vl, NULL, NULL, upper_ring_cl );
middle_ring = new ssgVtxTable( GL_TRIANGLE_STRIP,
middle_ring_vl, NULL, NULL, middle_ring_cl );
lower_ring = new ssgVtxTable( GL_TRIANGLE_STRIP,
lower_ring_vl, NULL, NULL, lower_ring_cl );
center_disk->setState( dome_state );
upper_ring->setState( dome_state );
middle_ring->setState( dome_state );
lower_ring->setState( dome_state );
dome_transform = new ssgTransform;
dome_transform->addKid( center_disk );
dome_transform->addKid( upper_ring );
dome_transform->addKid( middle_ring );
dome_transform->addKid( lower_ring );
// not entirely satisfying. We are depending here that the first
// thing we add to a parent is the first drawn
center_disk->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
center_disk->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
upper_ring->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
upper_ring->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
middle_ring->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
middle_ring->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
lower_ring->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
lower_ring->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
return dome_transform;
}
// repaint the sky colors based on current value of sun_angle, sky,
// and fog colors. This updates the color arrays for ssgVtxTable.
// sun angle in degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sun_angle )
{
double diff;
sgVec3 outer_param, outer_amt, outer_diff;
sgVec3 middle_param, middle_amt, middle_diff;
int i, j;
// Check for sunrise/sunset condition
if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
// 0.0 - 0.4
sgSetVec3( outer_param,
(10.0 - fabs(90.0 - sun_angle)) / 20.0,
(10.0 - fabs(90.0 - sun_angle)) / 40.0,
-(10.0 - fabs(90.0 - sun_angle)) / 30.0 );
sgSetVec3( middle_param,
(10.0 - fabs(90.0 - sun_angle)) / 40.0,
(10.0 - fabs(90.0 - sun_angle)) / 80.0,
0.0 );
sgScaleVec3( outer_diff, outer_param, 1.0 / 6.0 );
sgScaleVec3( middle_diff, middle_param, 1.0 / 6.0 );
} else {
sgSetVec3( outer_param, 0.0, 0.0, 0.0 );
sgSetVec3( middle_param, 0.0, 0.0, 0.0 );
sgSetVec3( outer_diff, 0.0, 0.0, 0.0 );
sgSetVec3( middle_diff, 0.0, 0.0, 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
sgCopyVec3( outer_amt, outer_param );
sgCopyVec3( middle_amt, middle_param );
//
// First, recalulate the basic colors
//
sgVec4 upper_color[12];
sgVec4 middle_color[12];
sgVec4 lower_color[12];
sgVec4 bottom_color[12];
for ( i = 0; i < 6; i++ ) {
for ( j = 0; j < 3; j++ ) {
diff = sky_color[j] - fog_color[j];
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
// l->sky_color[j], l->fog_color[j], diff);
upper_color[i][j] = sky_color[j] - diff * 0.3;
middle_color[i][j] = sky_color[j] - diff * 0.9 + middle_amt[j];
lower_color[i][j] = fog_color[j] + outer_amt[j];
if ( upper_color[i][j] > 1.0 ) { upper_color[i][j] = 1.0; }
if ( upper_color[i][j] < 0.1 ) { upper_color[i][j] = 0.1; }
if ( middle_color[i][j] > 1.0 ) { middle_color[i][j] = 1.0; }
if ( middle_color[i][j] < 0.1 ) { middle_color[i][j] = 0.1; }
if ( lower_color[i][j] > 1.0 ) { lower_color[i][j] = 1.0; }
if ( lower_color[i][j] < 0.1 ) { lower_color[i][j] = 0.1; }
}
upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = 1.0;
for ( j = 0; j < 3; j++ ) {
outer_amt[j] -= outer_diff[j];
middle_amt[j] -= middle_diff[j];
}
/*
printf("upper_color[%d] = %.2f %.2f %.2f %.2f\n", i, upper_color[i][0],
upper_color[i][1], upper_color[i][2], upper_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("lower_color[%d] = %.2f %.2f %.2f %.2f\n", i,
lower_color[i][0], lower_color[i][1], lower_color[i][2],
lower_color[i][3]);
*/
}
sgSetVec3( outer_amt, 0.0, 0.0, 0.0 );
sgSetVec3( middle_amt, 0.0, 0.0, 0.0 );
for ( i = 6; i < 12; i++ ) {
for ( j = 0; j < 3; j++ ) {
diff = sky_color[j] - fog_color[j];
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
// sky_color[j], fog_color[j], diff);
upper_color[i][j] = sky_color[j] - diff * 0.3;
middle_color[i][j] = sky_color[j] - diff * 0.9 + middle_amt[j];
lower_color[i][j] = fog_color[j] + outer_amt[j];
if ( upper_color[i][j] > 1.0 ) { upper_color[i][j] = 1.0; }
if ( upper_color[i][j] < 0.1 ) { upper_color[i][j] = 0.1; }
if ( middle_color[i][j] > 1.0 ) { middle_color[i][j] = 1.0; }
if ( middle_color[i][j] < 0.1 ) { middle_color[i][j] = 0.1; }
if ( lower_color[i][j] > 1.0 ) { lower_color[i][j] = 1.0; }
if ( lower_color[i][j] < 0.1 ) { lower_color[i][j] = 0.1; }
}
upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = 1.0;
for ( j = 0; j < 3; j++ ) {
outer_amt[j] += outer_diff[j];
middle_amt[j] += middle_diff[j];
}
/*
printf("upper_color[%d] = %.2f %.2f %.2f %.2f\n", i, upper_color[i][0],
upper_color[i][1], upper_color[i][2], upper_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("lower_color[%d] = %.2f %.2f %.2f %.2f\n", i,
lower_color[i][0], lower_color[i][1], lower_color[i][2],
lower_color[i][3]);
*/
}
for ( i = 0; i < 12; i++ ) {
sgCopyVec4( bottom_color[i], fog_color );
}
//
// Second, assign the basic colors to the object color arrays
//
float *slot;
int counter;
// update the center disk color arrays
counter = 0;
slot = center_disk_cl->get( counter++ );
// sgVec4 red;
// sgSetVec4( red, 1.0, 0.0, 0.0, 1.0 );
sgCopyVec4( slot, sky_color );
for ( i = 11; i >= 0; i-- ) {
slot = center_disk_cl->get( counter++ );
sgCopyVec4( slot, upper_color[i] );
}
slot = center_disk_cl->get( counter++ );
sgCopyVec4( slot, upper_color[11] );
// generate the upper ring
counter = 0;
for ( i = 0; i < 12; i++ ) {
slot = upper_ring_cl->get( counter++ );
sgCopyVec4( slot, middle_color[i] );
slot = upper_ring_cl->get( counter++ );
sgCopyVec4( slot, upper_color[i] );
}
slot = upper_ring_cl->get( counter++ );
sgCopyVec4( slot, middle_color[0] );
slot = upper_ring_cl->get( counter++ );
sgCopyVec4( slot, upper_color[0] );
// generate middle ring
counter = 0;
for ( i = 0; i < 12; i++ ) {
slot = middle_ring_cl->get( counter++ );
sgCopyVec4( slot, lower_color[i] );
slot = middle_ring_cl->get( counter++ );
sgCopyVec4( slot, middle_color[i] );
}
slot = middle_ring_cl->get( counter++ );
sgCopyVec4( slot, lower_color[0] );
slot = middle_ring_cl->get( counter++ );
sgCopyVec4( slot, middle_color[0] );
// generate lower ring
counter = 0;
for ( i = 0; i < 12; i++ ) {
slot = lower_ring_cl->get( counter++ );
sgCopyVec4( slot, bottom_color[i] );
slot = lower_ring_cl->get( counter++ );
sgCopyVec4( slot, lower_color[i] );
}
slot = lower_ring_cl->get( counter++ );
sgCopyVec4( slot, bottom_color[0] );
slot = lower_ring_cl->get( counter++ );
sgCopyVec4( slot, lower_color[0] );
return true;
}
// reposition the sky at the specified origin and orientation
// lon specifies a rotation about the Z axis
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (and orients the
// sunrise/set effects
bool SGSkyDome::reposition( sgVec3 p, double lon, double lat, double spin ) {
sgMat4 T, LON, LAT, SPIN;
sgVec3 axis;
// Translate to view position
// Point3D zero_elev = current_view.get_cur_zero_elev();
// xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
sgMakeTransMat4( T, p );
// 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 );
sgSetVec3( axis, 0.0, 0.0, 1.0 );
sgMakeRotMat4( LON, lon * RAD_TO_DEG, axis );
// xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
sgSetVec3( axis, 0.0, 1.0, 0.0 );
sgMakeRotMat4( LAT, 90.0 - lat * RAD_TO_DEG, axis );
// xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 );
sgSetVec3( axis, 0.0, 0.0, 1.0 );
sgMakeRotMat4( SPIN, spin * RAD_TO_DEG, axis );
sgMat4 TRANSFORM;
sgCopyMat4( TRANSFORM, T );
sgPreMultMat4( TRANSFORM, LON );
sgPreMultMat4( TRANSFORM, LAT );
sgPreMultMat4( TRANSFORM, SPIN );
sgCoord skypos;
sgSetCoord( &skypos, TRANSFORM );
dome_transform->setTransform( &skypos );
return true;
}

83
simgear/sky/dome.hxx Normal file
View File

@@ -0,0 +1,83 @@
// dome.hxx -- model sky with an upside down "bowl"
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
//
// Copyright (C) 1997-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
// 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 _SKYDOME_HXX
#define _SKYDOME_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/ssg.h> // plib include
class SGSkyDome {
ssgTransform *dome_transform;
ssgSimpleState *dome_state;
ssgVertexArray *center_disk_vl;
ssgColourArray *center_disk_cl;
ssgVertexArray *upper_ring_vl;
ssgColourArray *upper_ring_cl;
ssgVertexArray *middle_ring_vl;
ssgColourArray *middle_ring_cl;
ssgVertexArray *lower_ring_vl;
ssgColourArray *lower_ring_cl;
public:
// Constructor
SGSkyDome( void );
// Destructor
~SGSkyDome( void );
// initialize the sky object and connect it into our scene graph
// root
ssgBranch *build();
// repaint the sky colors based on current value of sun_angle,
// sky, and fog colors. This updates the color arrays for
// ssgVtxTable.
// sun angle in degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( sgVec3 sky_color, sgVec3 fog_color, double sun_angle );
// reposition the sky at the specified origin and orientation
// lon specifies a rotation about the Z axis
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (and orients the
// sunrise/set effects
bool reposition( sgVec3 p, double lon, double lat, double spin );
};
#endif // _SKYDOME_HXX

272
simgear/sky/moon.cxx Normal file
View File

@@ -0,0 +1,272 @@
// moon.hxx -- model earth's moon
//
// 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).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
// 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 <stdio.h>
#include <iostream>
#include <plib/ssg.h>
#include <simgear/constants.h>
#include "sphere.hxx"
#include "moon.hxx"
// Set up moon rendering call backs
static int sgMoonOrbPreDraw( ssgEntity *e ) {
/* cout << endl << "Moon orb pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE ) ;
// sgVec4 color;
// sgSetVec4( color, 0.0, 0.0, 0.0, 1.0 );
// glMaterialfv ( GL_FRONT_AND_BACK, GL_AMBIENT, color ) ;
return true;
}
static int sgMoonOrbPostDraw( ssgEntity *e ) {
/* cout << endl << "Moon orb post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgMoonHaloPreDraw( ssgEntity *e ) {
/* cout << endl << "Moon halo pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgMoonHaloPostDraw( ssgEntity *e ) {
/* cout << endl << "Moon halo post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
// Constructor
SGMoon::SGMoon( void ) {
}
// Destructor
SGMoon::~SGMoon( void ) {
}
// build the moon object
ssgBranch * SGMoon::build( FGPath path, double moon_size ) {
// set up the orb state
path.append( "moon.rgba" );
orb_state = new ssgSimpleState();
orb_state->setTexture( (char *)path.c_str() );
orb_state->setShadeModel( GL_SMOOTH );
orb_state->enable( GL_LIGHTING );
orb_state->enable( GL_CULL_FACE );
orb_state->enable( GL_TEXTURE_2D );
orb_state->enable( GL_COLOR_MATERIAL );
orb_state->setColourMaterial( GL_DIFFUSE );
orb_state->setMaterial( GL_AMBIENT, 0.0, 0.0, 0.0, 1.0 );
orb_state->setMaterial( GL_SPECULAR, 0.0, 0.0, 0.0, 1.0 );
orb_state->enable( GL_BLEND );
orb_state->enable( GL_ALPHA_TEST );
orb_state->setAlphaClamp( 0.01 );
cl = new ssgColourArray( 1 );
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
ssgBranch *orb = ssgMakeSphere( orb_state, cl, moon_size, 15, 15,
sgMoonOrbPreDraw, sgMoonOrbPostDraw );
// force a repaint of the moon colors with arbitrary defaults
repaint( 0.0 );
// build the halo
// moon_texbuf = new GLubyte[64*64*3];
// moon_texid = makeHalo( moon_texbuf, 64 );
// my_glWritePPMFile("moonhalo.ppm", moon_texbuf, 64, 64, RGB);
#if 0
// set up the halo state
halo_state = new ssgSimpleState();
halo_state->setTexture( "halo.rgb" );
// halo_state->setTexture( moon_texid );
halo_state->enable( GL_TEXTURE_2D );
halo_state->disable( GL_LIGHTING );
halo_state->setShadeModel( GL_SMOOTH );
halo_state->disable( GL_CULL_FACE );
halo_state->disable( GL_COLOR_MATERIAL );
halo_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
halo_state->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
halo_state -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ) ;
halo_state -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
// halo_state -> setShininess ( 0 ) ;
halo_state->enable( GL_ALPHA_TEST );
halo_state->setAlphaClamp(0.01);
halo_state->enable ( GL_BLEND ) ;
// Build ssg structure
double size = moon_size * 10.0;
sgVec3 v3;
halo_vl = new ssgVertexArray;
sgSetVec3( v3, -size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, -size, 0.0, size );
halo_vl->add( v3 );
sgSetVec3( v3, size, 0.0, size );
halo_vl->add( v3 );
sgVec2 v2;
halo_tl = new ssgTexCoordArray;
sgSetVec2( v2, 0.0f, 0.0f );
halo_tl->add( v2 );
sgSetVec2( v2, 1.0, 0.0 );
halo_tl->add( v2 );
sgSetVec2( v2, 0.0, 1.0 );
halo_tl->add( v2 );
sgSetVec2( v2, 1.0, 1.0 );
halo_tl->add( v2 );
ssgLeaf *halo =
new ssgVtxTable ( GL_TRIANGLE_STRIP, halo_vl, NULL, halo_tl, cl );
halo->setState( halo_state );
#endif
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
moon_transform = new ssgTransform;
// moon_transform->addKid( halo );
moon_transform->addKid( orb );
return moon_transform;
}
// repaint the moon colors based on current value of moon_angle in
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = moon rise/set
// 180 degrees = darkest midnight
bool SGMoon::repaint( double moon_angle ) {
if ( moon_angle * RAD_TO_DEG < 100 ) {
// else moon is well below horizon (so no point in repainting it)
// x_10 = moon_angle^10
double x_10 = moon_angle * moon_angle * moon_angle * moon_angle
* moon_angle * moon_angle * moon_angle * moon_angle * moon_angle
* moon_angle;
float 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; }
sgVec4 color;
sgSetVec4( color,
(ambient * 6.0) - 1.0, // minimum value = 0.8
(ambient * 11.0) - 3.0, // minimum value = 0.3
(ambient * 12.0) - 3.6, // minimum value = 0.0
0.5 );
if (color[0] > 1.0) color[0] = 1.0;
if (color[1] > 1.0) color[1] = 1.0;
if (color[2] > 1.0) color[2] = 1.0;
// cout << "color = " << color[0] << " " << color[1] << " "
// << color[2] << endl;
float *ptr;
ptr = cl->get( 0 );
sgCopyVec4( ptr, color );
}
return true;
}
// reposition the moon at the specified right ascension and
// declination, offset by our current position (p) so that it appears
// fixed at a great distance from the viewer. Also add in an optional
// rotation (i.e. for the current time of day.)
bool SGMoon::reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double moon_dist )
{
sgMat4 T1, T2, GST, RA, DEC;
sgVec3 axis;
sgVec3 v;
sgMakeTransMat4( T1, p );
sgSetVec3( axis, 0.0, 0.0, -1.0 );
sgMakeRotMat4( GST, angle, axis );
// xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
sgSetVec3( axis, 0.0, 0.0, 1.0 );
sgMakeRotMat4( RA, (rightAscension * RAD_TO_DEG) - 90.0, axis );
// xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
sgSetVec3( axis, 1.0, 0.0, 0.0 );
sgMakeRotMat4( DEC, declination * RAD_TO_DEG, axis );
// xglTranslatef(0,60000,0);
sgSetVec3( v, 0.0, 60000.0, 0.0 );
sgMakeTransMat4( T2, v );
sgMat4 TRANSFORM;
sgCopyMat4( TRANSFORM, T1 );
sgPreMultMat4( TRANSFORM, GST );
sgPreMultMat4( TRANSFORM, RA );
sgPreMultMat4( TRANSFORM, DEC );
sgPreMultMat4( TRANSFORM, T2 );
sgCoord skypos;
sgSetCoord( &skypos, TRANSFORM );
moon_transform->setTransform( &skypos );
return true;
}

76
simgear/sky/moon.hxx Normal file
View File

@@ -0,0 +1,76 @@
// moon.hxx -- model earth's moon
//
// 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).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
//
// 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_MOON_HXX_
#define _SG_MOON_HXX_
#include <plib/ssg.h>
#include <simgear/misc/fgpath.hxx>
class SGMoon {
ssgTransform *moon_transform;
ssgSimpleState *orb_state;
ssgSimpleState *halo_state;
ssgColourArray *cl;
ssgVertexArray *halo_vl;
ssgTexCoordArray *halo_tl;
public:
// Constructor
SGMoon( void );
// Destructor
~SGMoon( void );
// build the moon object
ssgBranch *build( FGPath path, double moon_size );
// repaint the moon colors based on current value of moon_anglein
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = moon rise/set
// 180 degrees = darkest midnight
bool repaint( double moon_angle );
// reposition the moon at the specified right ascension and
// declination, offset by our current position (p) so that it
// appears fixed at a great distance from the viewer. Also add in
// an optional rotation (i.e. for the current time of day.)
bool reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double moon_dist );
};
#endif // _SG_MOON_HXX_

364
simgear/sky/oursun.cxx Normal file
View File

@@ -0,0 +1,364 @@
// oursun.hxx -- model earth's sun
//
// 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).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
// 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 <stdio.h>
#include <iostream>
#include <plib/ssg.h>
#include <simgear/constants.h>
#include "sphere.hxx"
#include "oursun.hxx"
// Set up sun rendering call backs
static int sgSunOrbPreDraw( ssgEntity *e ) {
/* cout << endl << "Sun orb pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
return true;
}
static int sgSunOrbPostDraw( ssgEntity *e ) {
/* cout << endl << "Sun orb post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
static int sgSunHaloPreDraw( ssgEntity *e ) {
/* cout << endl << "Sun halo pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgSunHaloPostDraw( ssgEntity *e ) {
/* cout << endl << "Sun halo post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
// Constructor
SGSun::SGSun( void ) {
}
// Destructor
SGSun::~SGSun( void ) {
}
#if 0
static GLuint makeHalo( GLubyte *sun_texbuf, int width ) {
int texSize;
GLuint texid;
GLubyte *p;
int i,j;
double radius;
// create a texture id
#ifdef GL_VERSION_1_1
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);
#elif GL_EXT_texture_object
glGenTexturesEXT(1, &texid);
glBindTextureEXT(GL_TEXTURE_2D, texid);
#else
# error port me
#endif
glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
// create the actual texture contents
texSize = width * width;
if ( !sun_texbuf ) {
cout << "ouch ..." << endl;
exit(-1); // Ugly!
}
p = sun_texbuf;
radius = (double)(width / 2);
GLubyte value;
double x, y, d;
for ( i = 0; i < width; i++ ) {
for ( j = 0; j < width; j++ ) {
x = fabs((double)(i - (width / 2)));
y = fabs((double)(j - (width / 2)));
d = sqrt((x * x) + (y * y));
if (d < radius) {
// t is 1.0 at center, 0.0 at edge
double t = 1.0 - (d / radius);
// inverse square looks nice
value = (int)((double) 0xff * (t*t));
} else {
value = 0x00;
}
*p = value;
*(p+1) = value;
*(p+2) = value;
// *(p+3) = value;
p += 3;
}
}
/* glTexImage2D( GL_TEXTURE_2D,
0,
GL_RGBA,
width, width,
0,
GL_RGBA, GL_UNSIGNED_BYTE,
sun_texbuf ); */
return texid;
}
#define RGB 3 // 3 bytes of color info per pixel
#define RGBA 4 // 4 bytes of color+alpha info
void my_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int win_height, int mode)
{
int i, j, k, q;
unsigned char *ibuffer;
FILE *fp;
int pixelSize = mode==GL_RGBA?4:3;
ibuffer = (unsigned char *) malloc(win_width*win_height*RGB);
fp = fopen(filename, "wb");
fprintf(fp, "P6\n# CREATOR: glReadPixel()\n%d %d\n%d\n",
win_width, win_height, UCHAR_MAX);
q = 0;
for (i = 0; i < win_height; i++) {
for (j = 0; j < win_width; j++) {
for (k = 0; k < RGB; k++) {
ibuffer[q++] = (unsigned char)
*(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k));
}
}
}
// *(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k));
fwrite(ibuffer, sizeof(unsigned char), RGB*win_width*win_height, fp);
fclose(fp);
free(ibuffer);
printf("wrote file (%d x %d pixels, %d bytes)\n",
win_width, win_height, RGB*win_width*win_height);
}
#endif
// initialize the sun object and connect it into our scene graph root
ssgBranch * SGSun::build( FGPath path, double sun_size ) {
// set up the orb state
orb_state = new ssgSimpleState();
orb_state->setShadeModel( GL_SMOOTH );
orb_state->disable( GL_LIGHTING );
orb_state->disable( GL_CULL_FACE );
orb_state->disable( GL_TEXTURE_2D );
orb_state->enable( GL_COLOR_MATERIAL );
orb_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
orb_state->disable( GL_BLEND );
orb_state->disable( GL_ALPHA_TEST );
cl = new ssgColourArray( 1 );
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
ssgBranch *orb = ssgMakeSphere( orb_state, cl, sun_size, 10, 10,
sgSunOrbPreDraw, sgSunOrbPostDraw );
// force a repaint of the sun colors with arbitrary defaults
repaint( 0.0 );
// build the halo
// sun_texbuf = new GLubyte[64*64*3];
// sun_texid = makeHalo( sun_texbuf, 64 );
// my_glWritePPMFile("sunhalo.ppm", sun_texbuf, 64, 64, RGB);
// set up the halo state
path.append( "halo.rgba" );
halo_state = new ssgSimpleState();
halo_state->setTexture( (char *)path.c_str() );
// halo_state->setTexture( sun_texid );
halo_state->enable( GL_TEXTURE_2D );
halo_state->disable( GL_LIGHTING );
halo_state->setShadeModel( GL_SMOOTH );
halo_state->disable( GL_CULL_FACE );
halo_state->enable( GL_COLOR_MATERIAL );
halo_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
halo_state->enable( GL_ALPHA_TEST );
halo_state->setAlphaClamp(0.01);
halo_state->enable ( GL_BLEND ) ;
// Build ssg structure
double size = sun_size * 10.0;
sgVec3 v3;
halo_vl = new ssgVertexArray;
sgSetVec3( v3, -size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, -size, 0.0, size );
halo_vl->add( v3 );
sgSetVec3( v3, size, 0.0, size );
halo_vl->add( v3 );
sgVec2 v2;
halo_tl = new ssgTexCoordArray;
sgSetVec2( v2, 0.0f, 0.0f );
halo_tl->add( v2 );
sgSetVec2( v2, 1.0, 0.0 );
halo_tl->add( v2 );
sgSetVec2( v2, 0.0, 1.0 );
halo_tl->add( v2 );
sgSetVec2( v2, 1.0, 1.0 );
halo_tl->add( v2 );
ssgLeaf *halo =
new ssgVtxTable ( GL_TRIANGLE_STRIP, halo_vl, NULL, halo_tl, cl );
halo->setState( halo_state );
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
sun_transform = new ssgTransform;
sun_transform->addKid( halo );
halo->setCallback( SSG_CALLBACK_PREDRAW, sgSunHaloPreDraw );
halo->setCallback( SSG_CALLBACK_POSTDRAW, sgSunHaloPostDraw );
sun_transform->addKid( orb );
return sun_transform;
}
// repaint the sun colors based on current value of sun_angle in
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGSun::repaint( double sun_angle ) {
if ( sun_angle * RAD_TO_DEG < 100 ) {
// else sun is well below horizon (so no point in repainting it)
// x_10 = sun_angle^10
double x_10 = sun_angle * sun_angle * sun_angle * sun_angle * sun_angle
* sun_angle * sun_angle * sun_angle * sun_angle * sun_angle;
float 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; }
sgVec4 color;
sgSetVec4( color,
(ambient * 6.0) - 1.0, // minimum value = 0.8
(ambient * 11.0) - 3.0, // minimum value = 0.3
(ambient * 12.0) - 3.6, // minimum value = 0.0
1.0 );
if (color[0] > 1.0) color[0] = 1.0;
if (color[1] > 1.0) color[1] = 1.0;
if (color[2] > 1.0) color[2] = 1.0;
// cout << "color = " << color[0] << " " << color[1] << " "
// << color[2] << endl;
float *ptr;
ptr = cl->get( 0 );
sgCopyVec4( ptr, color );
}
return true;
}
// reposition the sun at the specified right ascension and
// declination, offset by our current position (p) so that it appears
// fixed at a great distance from the viewer. Also add in an optional
// rotation (i.e. for the current time of day.)
bool SGSun::reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double sun_dist )
{
sgMat4 T1, T2, GST, RA, DEC;
sgVec3 axis;
sgVec3 v;
sgMakeTransMat4( T1, p );
sgSetVec3( axis, 0.0, 0.0, -1.0 );
sgMakeRotMat4( GST, angle, axis );
// xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
sgSetVec3( axis, 0.0, 0.0, 1.0 );
sgMakeRotMat4( RA, (rightAscension * RAD_TO_DEG) - 90.0, axis );
// xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
sgSetVec3( axis, 1.0, 0.0, 0.0 );
sgMakeRotMat4( DEC, declination * RAD_TO_DEG, axis );
// xglTranslatef(0,60000,0);
sgSetVec3( v, 0.0, 60000.0, 0.0 );
sgMakeTransMat4( T2, v );
sgMat4 TRANSFORM;
sgCopyMat4( TRANSFORM, T1 );
sgPreMultMat4( TRANSFORM, GST );
sgPreMultMat4( TRANSFORM, RA );
sgPreMultMat4( TRANSFORM, DEC );
sgPreMultMat4( TRANSFORM, T2 );
sgCoord skypos;
sgSetCoord( &skypos, TRANSFORM );
sun_transform->setTransform( &skypos );
return true;
}

79
simgear/sky/oursun.hxx Normal file
View File

@@ -0,0 +1,79 @@
// oursun.hxx -- model earth's sun
//
// 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).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
//
// 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_SUN_HXX_
#define _SG_SUN_HXX_
#include <plib/ssg.h>
#include <simgear/misc/fgpath.hxx>
class SGSun {
ssgTransform *sun_transform;
ssgSimpleState *orb_state;
ssgSimpleState *halo_state;
ssgColourArray *cl;
ssgVertexArray *halo_vl;
ssgTexCoordArray *halo_tl;
GLuint sun_texid;
GLubyte *sun_texbuf;
public:
// Constructor
SGSun( void );
// Destructor
~SGSun( void );
// return the sun object
ssgBranch *build( FGPath path, double sun_size );
// repaint the sun colors based on current value of sun_anglein
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( double sun_angle );
// reposition the sun at the specified right ascension and
// declination, offset by our current position (p) so that it
// appears fixed at a great distance from the viewer. Also add in
// an optional rotation (i.e. for the current time of day.)
bool reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double sun_dist );
};
#endif // _SG_SUN_HXX_

117
simgear/sky/sky.cxx Normal file
View File

@@ -0,0 +1,117 @@
// sky.cxx -- ssg based sky model
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
//
// Copyright (C) 1997-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
// 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 <plib/ssg.h> // plib include
#include "sky.hxx"
// Constructor
SGSky::SGSky( void ) {
}
// Destructor
SGSky::~SGSky( void ) {
}
// initialize the sky and connect the components to the scene graph at
// the provided branch
ssgBranch * SGSky::build( double sun_size, double moon_size,
int nplanets, sgdVec3 *planet_data,
double planet_dist,
int nstars, sgdVec3 *star_data, double star_dist )
{
sky_selector = new ssgSelector;
sky_transform = new ssgTransform;
dome = new SGSkyDome;
sky_transform -> addKid( dome->build() );
planets = new SGStars;
sky_transform -> addKid( planets->build(nplanets, planet_data,
planet_dist)
);
stars = new SGStars;
sky_transform -> addKid( stars->build(nstars, star_data, star_dist) );
moon = new SGMoon;
sky_transform -> addKid( moon->build(tex_path, moon_size) );
oursun = new SGSun;
sky_transform -> addKid( oursun->build(tex_path, sun_size) );
sky_selector->addKid( sky_transform );
sky_selector->clrTraversalMaskBits( SSGTRAV_HOT );
return sky_selector;
}
// repaint the sky components based on current value of sun_angle,
// sky, and fog colors.
//
// sun angle in degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGSky::repaint( sgVec4 sky_color, sgVec4 fog_color,
double sun_angle, double moon_angle,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data )
{
dome->repaint( sky_color, fog_color, sun_angle );
oursun->repaint( sun_angle );
moon->repaint( moon_angle );
planets->repaint( sun_angle, nplanets, planet_data );
stars->repaint( sun_angle, nstars, star_data );
return true;
}
// reposition the sky at the specified origin and orientation
//
// lon specifies a rotation about the Z axis
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used by
// the skydome and perhaps clouds.
bool SGSky::reposition( sgVec3 view_pos, sgVec3 zero_elev,
double lon, double lat, double spin,
double gst,
double sun_ra, double sun_dec, double sun_dist,
double moon_ra, double moon_dec, double moon_dist )
{
double angle = gst * 15; // degrees
dome->reposition( zero_elev, lon, lat, spin );
oursun->reposition( view_pos, angle, sun_ra, sun_dec, sun_dist );
moon->reposition( view_pos, angle, moon_ra, moon_dec, moon_dist );
planets->reposition( view_pos, angle );
stars->reposition( view_pos, angle );
return true;
}

113
simgear/sky/sky.hxx Normal file
View File

@@ -0,0 +1,113 @@
// sky.hxx -- ssg based sky model
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
//
// Copyright (C) 1997-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
// 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_SKY_HXX
#define _SG_SKY_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/ssg.h> // plib include
#include <simgear/misc/fgpath.hxx>
#include "dome.hxx"
#include "moon.hxx"
#include "oursun.hxx"
#include "stars.hxx"
class SGSky {
// components of the sky
SGSkyDome *dome;
SGSun *oursun;
SGMoon *moon;
SGStars *planets;
SGStars *stars;
ssgSelector *sky_selector;
ssgTransform *sky_transform;
FGPath tex_path;
public:
// Constructor
SGSky( void );
// Destructor
~SGSky( void );
// initialize the sky and connect the components to the scene
// graph at the provided branch
ssgBranch *build( double sun_size, double moon_size,
int nplanets, sgdVec3 *planet_data, double planet_dist,
int nstars, sgdVec3 *star_data, double star_dist );
// repaint the sky components based on current value of sun_angle,
// sky, and fog colors.
//
// sun angle in degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( sgVec4 sky_color, sgVec4 fog_color,
double sun_angle, double moon_angle,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data );
// reposition the sky at the specified origin and orientation
//
// lon specifies a rotation about the Z axis
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used
// by the skydome and perhaps clouds.
bool reposition( sgVec3 view_pos, sgVec3 zero_elev,
double lon, double lat, double spin,
double gst,
double sun_ra, double sun_dec, double sun_dist,
double moon_ra, double moon_dec, double moon_dist );
// specify the texture path (optional, defaults to current directory)
inline void texture_path( const string& path ) {
tex_path = FGPath( path );
}
// enable the sky in the scene graph (default)
inline void enable() { sky_selector->select( 1 ); }
// disable the sky in the scene graph. The leaf node is still
// there, how ever it won't be traversed on by ssgCullandRender()
inline void disable() { sky_selector->select( 0 ); }
};
#endif // _SG_SKY_HXX

132
simgear/sky/sphere.cxx Normal file
View File

@@ -0,0 +1,132 @@
// sphere.cxx -- build an ssg sphere object
//
// Pulled straight out of MesaGLU/quadratic.c
//
// Original gluSphere code is Copyright (C) 1999-2000 Brian Paul and
// licensed under the GPL
//
// 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 <plib/ssg.h>
// return a sphere object as an ssgBranch
ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl,
double radius, int slices, int stacks,
ssgCallback predraw, ssgCallback postdraw )
{
float rho, drho, theta, dtheta;
float x, y, z;
float s, t, ds, dt;
int i, j, imin, imax;
float nsign = 1.0;
ssgBranch *sphere = new ssgBranch;
sgVec2 vec2;
sgVec3 vec3;
// handle cl whether it is preinitialized or not
if ( cl == NULL ) {
// create a new array if needed
cl = new ssgColourArray( 1 );
}
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
if ( cl->getNum() > 1 ) {
cl->removeAll();
cl->add( color );
} else if ( cl->getNum() == 0 ) {
cl->add( color );
} else {
// accept value as given to us in
}
drho = M_PI / (float) stacks;
dtheta = 2.0 * M_PI / (float) slices;
/* texturing: s goes from 0.0/0.25/0.5/0.75/1.0 at +y/+x/-y/-x/+y
axis t goes from -1.0/+1.0 at z = -radius/+radius (linear along
longitudes) cannot use triangle fan on texturing (s coord. at
top/bottom tip varies) */
ds = 1.0 / slices;
dt = 1.0 / stacks;
t = 1.0; /* because loop now runs from 0 */
imin = 0;
imax = stacks;
/* build slices as quad strips */
for ( i = imin; i < imax; i++ ) {
ssgVertexArray *vl = new ssgVertexArray();
ssgNormalArray *nl = new ssgNormalArray();
ssgTexCoordArray *tl = new ssgTexCoordArray();
rho = i * drho;
s = 0.0;
for ( j = 0; j <= slices; j++ ) {
theta = (j == slices) ? 0.0 : j * dtheta;
x = -sin(theta) * sin(rho);
y = cos(theta) * sin(rho);
z = nsign * cos(rho);
// glNormal3f( x*nsign, y*nsign, z*nsign );
sgSetVec3( vec3, x*nsign, y*nsign, z*nsign );
sgNormalizeVec3( vec3 );
nl->add( vec3 );
// glTexCoord2f(s,t);
sgSetVec2( vec2, s, t );
tl->add( vec2 );
// glVertex3f( x*radius, y*radius, z*radius );
sgSetVec3( vec3, x*radius, y*radius, z*radius );
vl->add( vec3 );
x = -sin(theta) * sin(rho+drho);
y = cos(theta) * sin(rho+drho);
z = nsign * cos(rho+drho);
// glNormal3f( x*nsign, y*nsign, z*nsign );
sgSetVec3( vec3, x*nsign, y*nsign, z*nsign );
sgNormalizeVec3( vec3 );
nl->add( vec3 );
// glTexCoord2f(s,t-dt);
sgSetVec2( vec2, s, t-dt );
tl->add( vec2 );
s += ds;
// glVertex3f( x*radius, y*radius, z*radius );
sgSetVec3( vec3, x*radius, y*radius, z*radius );
vl->add( vec3 );
}
ssgLeaf *slice =
new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, cl );
slice->setState( state );
slice->setCallback( SSG_CALLBACK_PREDRAW, predraw );
slice->setCallback( SSG_CALLBACK_POSTDRAW, postdraw );
sphere->addKid( slice );
t -= dt;
}
return sphere;
}

View File

@@ -1,8 +1,9 @@
// sky.hxx -- model sky with an upside down "bowl"
// sphere.hxx -- build an ssg sphere object
//
// Written by Curtis Olson, started December 1997.
// Pulled straight out of MesaGLU/quadratic.c
//
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
// Original gluSphere code is Copyright (C) 1999-2000 Brian Paul and
// licensed under the GPL
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@@ -21,33 +22,13 @@
// $Id$
#ifndef _SKY_HXX
#define _SKY_HXX
#include <plib/ssg.h>
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/ssg.h> // plib include
class fgSky : ssgLeaf
{
};
// (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
// return a sphere object as an ssgBranch (and connect in the
// specified ssgSimpleState
ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl,
double radius, int slices, int stacks,
ssgCallback predraw, ssgCallback postdraw );

227
simgear/sky/stars.cxx Normal file
View File

@@ -0,0 +1,227 @@
// stars.cxx -- model the stars
//
// 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).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
// 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 <stdio.h>
#include <iostream>
#include <plib/ssg.h>
#include <simgear/constants.h>
#include "stars.hxx"
// Set up star rendering call backs
static int sgStarPreDraw( ssgEntity *e ) {
/* cout << endl << "Star pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgStarPostDraw( ssgEntity *e ) {
/* cout << endl << "Star post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
// Constructor
SGStars::SGStars( void ) {
}
// Destructor
SGStars::~SGStars( void ) {
}
// initialize the stars object and connect it into our scene graph root
ssgBranch * SGStars::build( int num, sgdVec3 *star_data, double star_dist ) {
sgVec4 color;
if ( star_data == NULL ) {
cout << "WARNING: null star data passed to SGStars::build()" << endl;
}
// set up the orb state
state = new ssgSimpleState();
state->disable( GL_LIGHTING );
state->disable( GL_CULL_FACE );
state->disable( GL_TEXTURE_2D );
state->enable( GL_COLOR_MATERIAL );
state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
state->enable( GL_BLEND );
state->disable( GL_ALPHA_TEST );
vl = new ssgVertexArray( num );
cl = new ssgColourArray( num );
// cl = new ssgColourArray( 1 );
// sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
// cl->add( color );
// Build ssg structure
sgVec3 p;
for ( int i = 0; i < num; ++i ) {
// position seeded to arbitrary values
sgSetVec3( p,
star_dist * cos( star_data[i][0] )
* cos( star_data[i][1] ),
star_dist * sin( star_data[i][0] )
* cos( star_data[i][1] ),
star_dist * sin( star_data[i][1] )
);
vl->add( p );
// color (magnitude)
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
}
ssgLeaf *stars_obj =
new ssgVtxTable ( GL_POINTS, vl, NULL, NULL, cl );
stars_obj->setState( state );
stars_obj->setCallback( SSG_CALLBACK_PREDRAW, sgStarPreDraw );
stars_obj->setCallback( SSG_CALLBACK_POSTDRAW, sgStarPostDraw );
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
stars_transform = new ssgTransform;
stars_transform->addKid( stars_obj );
cout << "stars = " << stars_transform << endl;
return stars_transform;
}
// repaint the sun colors based on current value of sun_angle in
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGStars::repaint( double sun_angle, int num, sgdVec3 *star_data ) {
// double min = 100;
// double max = -100;
double mag, nmag, alpha, factor, cutoff;
float *color;
// determine which star structure to draw
if ( sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) {
// deep night
factor = 1.0;
cutoff = 4.5;
} else if ( sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
factor = 1.0;
cutoff = 3.8;
} else if ( sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
factor = 0.95;
cutoff = 3.1;
} else if ( sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
factor = 0.9;
cutoff = 2.4;
} else if ( sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
factor = 0.85;
cutoff = 1.8;
} else if ( sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
factor = 0.8;
cutoff = 1.2;
} else if ( sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
factor = 0.75;
cutoff = 0.6;
} else {
// early dusk or late dawn
factor = 0.7;
cutoff = 0.0;
}
for ( int i = 0; i < num; ++i ) {
// if ( star_data[i][2] < min ) { min = star_data[i][2]; }
// if ( star_data[i][2] > max ) { max = star_data[i][2]; }
// magnitude ranges from -1 (bright) to 4 (dim). The range of
// star and planet magnitudes can actually go outside of this,
// but for our purpose, if it is brighter that -1, we'll color
// it full white/alpha anyway and 4 is a convenient cutoff
// point which keeps the number of stars drawn at about 500.
// color (magnitude)
mag = star_data[i][2];
if ( mag < cutoff ) {
nmag = ( 4.5 - mag ) / 5.5; // translate to 0 ... 1.0 scale
// alpha = nmag * 0.7 + 0.3; // translate to a 0.3 ... 1.0 scale
alpha = nmag * 0.85 + 0.15; // translate to a 0.15 ... 1.0 scale
alpha *= factor; // dim when the sun is brighter
} else {
alpha = 0.0;
}
if (alpha > 1.0) { alpha = 1.0; }
if (alpha < 0.0) { alpha = 0.0; }
color = cl->get( i );
sgSetVec4( color, 1.0, 1.0, 1.0, alpha );
// cout << "alpha[" << i << "] = " << alpha << endl;
}
// cout << "min = " << min << " max = " << max << " count = " << num
// << endl;
return true;
}
// reposition the stars for the specified time (GST rotation),
// offset by our current position (p) so that it appears fixed at a
// great distance from the viewer.
bool SGStars::reposition( sgVec3 p, double angle )
{
sgMat4 T1, GST;
sgVec3 axis;
sgMakeTransMat4( T1, p );
sgSetVec3( axis, 0.0, 0.0, -1.0 );
sgMakeRotMat4( GST, angle, axis );
sgMat4 TRANSFORM;
sgCopyMat4( TRANSFORM, T1 );
sgPreMultMat4( TRANSFORM, GST );
sgCoord skypos;
sgSetCoord( &skypos, TRANSFORM );
stars_transform->setTransform( &skypos );
return true;
}

69
simgear/sky/stars.hxx Normal file
View File

@@ -0,0 +1,69 @@
// stars.hxx -- model the stars
//
// 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).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
//
// 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_STARS_HXX_
#define _SG_STARS_HXX_
#include <plib/ssg.h>
class SGStars {
ssgTransform *stars_transform;
ssgSimpleState *state;
ssgColourArray *cl;
ssgVertexArray *vl;
public:
// Constructor
SGStars( void );
// Destructor
~SGStars( void );
// initialize the stars structure
ssgBranch *build( int num, sgdVec3 *star_data, double star_dist );
// repaint the planet magnitudes based on current value of
// sun_angle in degrees relative to verticle (so we can make them
// relatively dimmer during dawn and dusk
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( double sun_angle, int num, sgdVec3 *star_data );
// reposition the stars for the specified time (GST rotation),
// offset by our current position (p) so that it appears fixed at
// a great distance from the viewer.
bool reposition( sgVec3 p, double angle );
};
#endif // _SG_STARS_HXX_

31
simgear/version.h.in Normal file
View File

@@ -0,0 +1,31 @@
// version.h -- SimGear version
//
// Written by Curtis Olson, started February 2000.
//
// 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
// 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 _SIMGEAR_VERSION_H
#define _SIMGEAR_VERSION_H
#define SIMGEAR_VERSION @VERSION@
#endif // _SIMGEAR_VERSION_H