Compare commits

...

18 Commits

Author SHA1 Message Date
curt
2c920ae1df Added is_open() so we can check if the open() succeeded. 1999-03-27 14:04:25 +00:00
curt
bbde3b36bf Elimitated some const warnings from the compiler. 1999-03-27 05:34:05 +00:00
curt
88a016c516 Minor optimization tweaks. 1999-03-25 19:02:28 +00:00
curt
22d4058564 Jettisoned old bucketutils.[ch] for newbucket.[ch]xx 1999-03-25 19:01:47 +00:00
curt
79e6c529ea MSVC++ portability tweaks contributed by Bernie Bright.
Added using std::ostream declaration.
  Added forward declarations to work around a MSVC bug.
1999-03-15 17:58:41 +00:00
curt
7b22b8cd92 Moved to math subdirectory. 1999-03-13 17:34:44 +00:00
curt
bc2ae82e81 Added some informational methods. 1999-03-12 22:51:18 +00:00
curt
764f4037b0 Tweak for native SGI compilers. 1999-03-08 22:00:12 +00:00
curt
a60454a786 Tweaks for compiling with native SGI compilers. 1999-03-02 01:01:42 +00:00
curt
d136ad3e57 Added initial support for native SGI compilers. 1999-02-26 22:07:53 +00:00
curt
739588f9c3 Renamed bucketutils.c -> bucketutils.cxx 1999-02-17 20:52:02 +00:00
curt
505de4703b Added a routine to calculate the offset in bucket units between two buckets. 1999-02-11 01:09:33 +00:00
curt
236a1f2a2d Added a FG_CLIPPER debug type for the polygon clipper lib. 1999-02-09 00:08:48 +00:00
curt
91efc5ad87 Added a new "newbucket.[ch]xx" FGBucket class to replace the old
fgBUCKET struct and C routines.  This FGBucket class adjusts the tile
width towards the poles to ensure the tiles are at least 8 miles wide.
1999-02-08 23:52:13 +00:00
curt
123c816048 MSVC++ portability changes by Bernie Bright:
Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
Simulator/Cockpit/hud.cxx: Added Standard headers
Simulator/Cockpit/panel.cxx: Redefinition of default parameter
Simulator/Flight/flight.cxx: Replaced cout with FG_LOG.  Deleted <stdio.h>
Simulator/Main/fg_init.cxx:
Simulator/Main/GLUTmain.cxx:
Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
Simulator/Objects/material.hxx:
Simulator/Time/timestamp.hxx: VC++ friend kludge
Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
Simulator/Main/views.hxx: Added a constant
1999-02-02 20:13:23 +00:00
curt
fab6d05157 Optimizations from Norman Vine. 1999-02-01 21:08:28 +00:00
curt
3240464c7c Portability tweaks by Bernie Bright. 1999-01-27 04:46:14 +00:00
curt
a2ffd27b7c Moved DEM/ to the Tools/ subdir. 1999-01-27 04:45:56 +00:00
26 changed files with 1166 additions and 634 deletions

View File

@@ -1,5 +1,11 @@
noinst_LIBRARIES = libBucket.a
libBucket_a_SOURCES = bucketutils.c bucketutils.h bucketutils.hxx
libBucket_a_SOURCES = newbucket.cxx newbucket.hxx
bin_PROGRAMS = testbucket
testbucket_SOURCES = testbucket.cxx
testbucket_LDADD = $(top_builddir)/Lib/Bucket/libBucket.a
INCLUDES += -I$(top_builddir)

View File

@@ -1,326 +0,0 @@
// bucketutils.c -- support routines to handle fgBUCKET operations
//
// Written by Curtis Olson, started January 1998.
//
// 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$
// (Log is kept at end of this file)
#include <math.h>
#include <stdio.h>
#include <Include/fg_constants.h>
#include "bucketutils.h"
/* Generate the unique scenery tile index containing the specified
lon/lat parameters.
The index is constructed as follows:
9 bits - to represent 360 degrees of longitude (-180 to 179)
8 bits - to represent 180 degrees of latitude (-90 to 89)
Each 1 degree by 1 degree tile is further broken down into an 8x8
grid. So we also need:
3 bits - to represent x (0 to 7)
3 bits - to represent y (0 to 7) */
long int fgBucketGenIndex( const fgBUCKET *p) {
long index = 0;
index = ((p->lon + 180) << 14) + ((p->lat + 90) << 6) + (p->y << 3) + p->x;
// printf(" generated index = %ld\n", index);
return(index);
}
// Parse a unique scenery tile index and find the lon, lat, x, and y
void fgBucketParseIndex(long int index, fgBUCKET *p) {
p->lon = index >> 14;
index -= p->lon << 14;
p->lon -= 180;
p->lat = index >> 6;
index -= p->lat << 6;
p->lat -= 90;
p->y = index >> 3;
index -= p->y << 3;
p->x = index;
}
// Build a path name from an tile index
void fgBucketGenBasePath( const fgBUCKET *p, char *path) {
long int index;
int top_lon, top_lat, main_lon, main_lat;
char hem, pole;
index = fgBucketGenIndex(p);
path[0] = '\0';
top_lon = p->lon / 10;
main_lon = p->lon;
if ( (p->lon < 0) && (top_lon * 10 != p->lon) ) {
top_lon -= 1;
}
top_lon *= 10;
if ( top_lon >= 0 ) {
hem = 'e';
} else {
hem = 'w';
top_lon *= -1;
}
if ( main_lon < 0 ) {
main_lon *= -1;
}
top_lat = p->lat / 10;
main_lat = p->lat;
if ( (p->lat < 0) && (top_lat * 10 != p->lat) ) {
top_lat -= 1;
}
top_lat *= 10;
if ( top_lat >= 0 ) {
pole = 'n';
} else {
pole = 's';
top_lat *= -1;
}
if ( main_lat < 0 ) {
main_lat *= -1;
}
sprintf(path, "%c%03d%c%03d/%c%03d%c%03d",
hem, top_lon, pole, top_lat,
hem, main_lon, pole, main_lat);
}
// offset an bucket struct by the specified amounts in the X & Y direction
void fgBucketOffset(fgBUCKET *in, fgBUCKET *out, int x, int y) {
int diff, temp;
int dist_lat;
out->lon = in->lon;
out->lat = in->lat;
out->x = in->x;
out->y = in->y;
// do X direction
diff = out->x + x;
// printf(" reducing x (%d)\n", diff);
if ( diff >= 0 ) {
temp = diff / 8;
} else if ( diff < -7 ) {
temp = (diff + 1) / 8 - 1;
} else {
temp = diff / 8 - 1;
}
out->x = ((diff % 8) + 8) % 8;
out->lon = ( (out->lon + 180 + 360 + temp) % 360 ) - 180;
// do Y direction
diff = out->y + y;
// printf(" reducing x (%d)\n", diff);
if ( diff >= 0 ) {
temp = diff / 8;
} else if ( diff < -7 ) {
temp = (diff + 1) / 8 - 1;
} else {
temp = diff / 8 - 1;
}
out->y = ((diff % 8) + 8) % 8;
out->lat = out->lat + temp;
if ( out->lat >= 90 ) {
dist_lat = out->lat - 90;
// printf(" +lat = %d +y = %d\n", dist_lat, out->y);
out->lat = 90 - (dist_lat + 1);
out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
out->y = 7 - out->y;
}
if ( out->lat < -90 ) {
dist_lat = -90 - out->lat;
// printf(" +lat = %d +y = %d\n", dist_lat, out->y);
out->lat = -90 + (dist_lat - 1);
out->lon = ( (out->lon + 180 + 180) % 360 ) - 180;
out->y = 7 - out->y;
}
}
// Given a lat/lon in degrees, find the "bucket" or tile that it falls
// within
void fgBucketFind(double lon, double lat, fgBUCKET *p) {
double diff;
diff = lon - (double)(int)lon;
// printf("diff = %.2f\n", diff);
if ( (lon >= 0) || (fabs(diff) < FG_EPSILON) ) {
p->lon = (int)lon;
} else {
p->lon = (int)lon - 1;
}
// printf(" p->lon = %d\n", p->lon);
diff = lat - (double)(int)lat;
// printf("diff = %.2f\n", diff);
if ( (lat >= 0) || (fabs(diff) < FG_EPSILON) ) {
p->lat = (int)lat;
} else {
p->lat = (int)lat - 1;
}
// printf(" p->lat = %d\n", p->lat);
p->x = (int)((lon - p->lon) * 8);
p->y = (int)((lat - p->lat) * 8);
// printf( "Bucket = lon,lat = %d,%d x,y index = %d,%d\n",
// p->lon, p->lat, p->x, p->y);
}
// Given a lat/lon, fill in the local tile index array
void fgBucketGenIdxArray(fgBUCKET *p1, fgBUCKET *tiles, int width, int height) {
fgBUCKET *p2;
int dw, dh, i, j;
dh = height / 2;
dw = width / 2;
for ( j = 0; j < height; j++ ) {
for ( i = 0; i < width; i++ ) {
fgBucketOffset(p1, &tiles[(j*width)+i], i - dw, j - dh);
p2 = &tiles[(j*width)+i];
/* printf( " bucket = %d %d %d %d index = %ld\n",
p2->lon, p2->lat, p2->x, p2->y,
fgBucketGenIndex(&tiles[(j*width)+i])); */
}
}
}
/* sample main for testing
int main() {
fgBUCKET p1;
long int tile[49];
char path[256];
double lon, lat;
int i, j;
p1.lon = 180;
p1.lat = 90;
p1.x = 7;
p1.y = 7;
printf("Max index = %ld\n", gen_index(&p1));
lon = -50.0;
lat = -50.0;
find_bucket(lon, lat, &p1);
gen_idx_array(&p1, tile, 7, 7);
for ( j = 0; j < 7; j++ ) {
for ( i = 0; i < 7; i++ ) {
gen_path(tile[(j*7)+i], path);
printf(" path = %s\n", path);
}
}
lon = 50.0;
lat = 50.0;
find_bucket(lon, lat, &p1);
gen_idx_array(&p1, tile, 7, 7);
for ( j = 0; j < 7; j++ ) {
for ( i = 0; i < 7; i++ ) {
gen_path(tile[(j*7)+i], path);
printf(" path = %s\n", path);
}
}
return(1);
} */
// $Log$
// Revision 1.5 1998/12/09 18:48:08 curt
// Use C++ style comments.
//
// Revision 1.4 1998/12/07 21:08:01 curt
// Added a const in a couple places to get rid of annoying compiler warnings.
//
// Revision 1.3 1998/07/04 00:46:47 curt
// typedef'd struct fgBUCKET.
//
// Revision 1.2 1998/04/25 22:06:22 curt
// Edited cvs log messages in source files ... bad bad bad!
//
// Revision 1.1 1998/04/08 23:28:58 curt
// Adopted Gnu automake/autoconf system.
//
// Revision 1.6 1998/02/09 15:07:51 curt
// Minor tweaks.
//
// Revision 1.5 1998/01/29 00:51:38 curt
// First pass at tile cache, dynamic tile loading and tile unloading now works.
//
// Revision 1.4 1998/01/27 03:26:41 curt
// Playing with new fgPrintf command.
//
// Revision 1.3 1998/01/27 00:48:01 curt
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
// system and commandline/config file processing code.
//
// Revision 1.2 1998/01/24 00:03:28 curt
// Initial revision.
//
// Revision 1.1 1998/01/23 20:06:51 curt
// tileutils.* renamed to bucketutils.*
//
// Revision 1.6 1998/01/19 19:27:18 curt
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
// This should simplify things tremendously.
//
// Revision 1.5 1998/01/14 02:19:04 curt
// Makde offset_bucket visible to outside.
//
// Revision 1.4 1998/01/13 00:23:12 curt
// Initial changes to support loading and management of scenery tiles. Note,
// there's still a fair amount of work left to be done.
//
// Revision 1.3 1998/01/10 00:01:47 curt
// Misc api changes and tweaks.
//
// Revision 1.2 1998/01/08 02:22:28 curt
// Continue working on basic features.
//
// Revision 1.1 1998/01/07 23:50:52 curt
// "area" renamed to "tile"
//
// Revision 1.1 1998/01/07 23:23:40 curt
// Initial revision.
//

View File

@@ -1,130 +0,0 @@
// bucketutils.h -- support routines to handle fgBUCKET operations
//
// Written by Curtis Olson, started January 1998.
//
// 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$
// (Log is kept at end of this file)
#ifndef _BUCKETUTILS_H
#define _BUCKETUTILS_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int lon; // longitude (-180 to 179)
int lat; // latitude (-90 to 89)
int x; // x (0 to 7)
int y; // y (0 to 7)
} fgBUCKET;
/* Generate the unique scenery tile index containing the specified
lon/lat parameters.
The index is constructed as follows:
9 bits - to represent 360 degrees of longitude (-180 to 179)
8 bits - to represent 180 degrees of latitude (-90 to 89)
Each 1 degree by 1 degree tile is further broken down into an 8x8
grid. So we also need:
3 bits - to represent x (0 to 7)
3 bits - to represent y (0 to 7) */
long int fgBucketGenIndex( const fgBUCKET *p);
// Parse a unique scenery tile index and find the lon, lat, x, and y
void fgBucketParseIndex(long int index, fgBUCKET *p);
// Build a path name from an tile index
void fgBucketGenBasePath( const fgBUCKET *p, char *path);
// offset an bucket struct by the specified amounts in the X & Y direction
void fgBucketOffset(fgBUCKET *in, fgBUCKET *out, int x, int y);
// Given a lat/lon in degrees, find the "bucket" or tile that it falls
// within
void fgBucketFind(double lon, double lat, fgBUCKET *p);
// Given a lat/lon, fill in the local tile index array
void fgBucketGenIdxArray(fgBUCKET *p1, fgBUCKET *tiles, int width, int height);
#ifdef __cplusplus
}
#endif
#endif // _BUCKETUTILS_H
// $Log$
// Revision 1.4 1998/12/09 18:48:09 curt
// Use C++ style comments.
//
// Revision 1.3 1998/12/07 21:08:03 curt
// Added a const in a couple places to get rid of annoying compiler warnings.
//
// Revision 1.2 1998/07/04 00:46:48 curt
// typedef'd struct fgBUCKET.
//
// Revision 1.1 1998/04/08 23:28:59 curt
// Adopted Gnu automake/autoconf system.
//
// Revision 1.2 1998/01/24 00:03:28 curt
// Initial revision.
//
// Revision 1.1 1998/01/23 20:06:52 curt
// tileutils.* renamed to bucketutils.*
//
// Revision 1.6 1998/01/22 02:59:42 curt
// Changed #ifdef FILE_H to #ifdef _FILE_H
//
// Revision 1.5 1998/01/14 02:19:05 curt
// Makde offset_bucket visible to outside.
//
// Revision 1.4 1998/01/13 00:23:12 curt
// Initial changes to support loading and management of scenery tiles. Note,
// there's still a fair amount of work left to be done.
//
// Revision 1.3 1998/01/10 00:01:48 curt
// Misc api changes and tweaks.
//
// Revision 1.2 1998/01/08 02:22:28 curt
// Continue working on basic features.
//
// Revision 1.1 1998/01/07 23:50:52 curt
// "area" renamed to "tile"
//
// Revision 1.1 1998/01/07 23:23:40 curt
// Initial revision.
//

View File

@@ -1,81 +0,0 @@
/**************************************************************************
* bucketutils.hxx -- support routines to handle fgBUCKET operations
*
* Written by Bernie Bright, started January 1998.
*
* Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
*
* 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$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef _BUCKETUTILS_HXX
#define _BUCKETUTILS_HXX
#include <string>
FG_USING_NAMESPACE(std);
#include "bucketutils.h"
#include <Include/compiler.h>
FG_USING_STD(string);
inline bool
operator== ( const fgBUCKET& b1, const fgBUCKET& b2 )
{
return ( b1.lon == b2.lon &&
b1.lat == b2.lat &&
b1.x == b2.x &&
b1.y == b2.y );
}
inline string
fgBucketGenIndex( const fgBUCKET& p )
{
char index_str[256];
sprintf( index_str, "%ld", fgBucketGenIndex( &p ) );
return string( index_str );
}
inline string
fgBucketGenBasePath( const fgBUCKET& p )
{
char base_path[256];
fgBucketGenBasePath( &p, base_path );
return string( base_path );
}
inline ostream&
operator<< ( ostream& out, const fgBUCKET& b )
{
return out << b.lon << "," << b.lat << " " << b.x << "," << b.y;
}
#endif /* _BUCKETUTILS_HXX */
// $Log$
// Revision 1.2 1999/01/19 20:56:53 curt
// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
//
// Revision 1.1 1998/11/09 23:42:12 curt
// Initial revision.
//

163
Bucket/newbucket.cxx Normal file
View File

@@ -0,0 +1,163 @@
/**************************************************************************
* newbucket.hxx -- new bucket routines for better world modeling
*
* Written by Curtis L. Olson, started February 1999.
*
* Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
*
* This 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$
* (Log is kept at end of this file)
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "newbucket.hxx"
// Build the path name for this bucket
string FGBucket::gen_base_path() const {
// long int index;
int top_lon, top_lat, main_lon, main_lat;
char hem, pole;
char path[256];
// index = gen_index();
path[0] = '\0';
top_lon = lon / 10;
main_lon = lon;
if ( (lon < 0) && (top_lon * 10 != lon) ) {
top_lon -= 1;
}
top_lon *= 10;
if ( top_lon >= 0 ) {
hem = 'e';
} else {
hem = 'w';
top_lon *= -1;
}
if ( main_lon < 0 ) {
main_lon *= -1;
}
top_lat = lat / 10;
main_lat = lat;
if ( (lat < 0) && (top_lat * 10 != lat) ) {
top_lat -= 1;
}
top_lat *= 10;
if ( top_lat >= 0 ) {
pole = 'n';
} else {
pole = 's';
top_lat *= -1;
}
if ( main_lat < 0 ) {
main_lat *= -1;
}
sprintf(path, "%c%03d%c%02d/%c%03d%c%02d",
hem, top_lon, pole, top_lat,
hem, main_lon, pole, main_lat);
return path;
}
// find the bucket which is offset by the specified tile units in the
// X & Y direction. We need the current lon and lat to resolve
// ambiguities when going from a wider tile to a narrower one above or
// below. This assumes that we are feeding in
FGBucket fgBucketOffset( double dlon, double dlat, int dx, int dy ) {
FGBucket result( dlon, dlat );
double clat = result.get_center_lat() + dy * FG_BUCKET_SPAN;
// walk dy units in the lat direction
result.set_bucket( dlon, clat );
// find the lon span for the new latitude
double span = bucket_span( clat );
// walk dx units in the lon direction
result.set_bucket( dlon + dx * span, clat );
return result;
}
// calculate the offset between two buckets
void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ) {
// Latitude difference
double c1_lat = b1.get_center_lat();
double c2_lat = b2.get_center_lat();
double diff_lat = c2_lat - c1_lat;
#ifdef HAVE_RINT
*dy = (int)rint( diff_lat / FG_BUCKET_SPAN );
#else
if ( diff_lat > 0 ) {
*dy = (int)( diff_lat / FG_BUCKET_SPAN + 0.5 );
} else {
*dy = (int)( diff_lat / FG_BUCKET_SPAN - 0.5 );
}
#endif
// longitude difference
double c1_lon = b1.get_center_lon();
double c2_lon = b2.get_center_lon();
double diff_lon = c2_lon - c1_lon;
double span;
if ( bucket_span(c1_lat) <= bucket_span(c2_lat) ) {
span = bucket_span(c1_lat);
} else {
span = bucket_span(c2_lat);
}
#ifdef HAVE_RINT
*dx = (int)rint( diff_lon / span );
#else
if ( diff_lon > 0 ) {
*dx = (int)( diff_lon / span + 0.5 );
} else {
*dx = (int)( diff_lon / span - 0.5 );
}
#endif
}
// $Log$
// Revision 1.4 1999/03/27 05:34:05 curt
// Elimitated some const warnings from the compiler.
//
// Revision 1.3 1999/02/26 22:07:54 curt
// Added initial support for native SGI compilers.
//
// Revision 1.2 1999/02/11 01:09:33 curt
// Added a routine to calculate the offset in bucket units between two buckets.
//
// Revision 1.1 1999/02/08 23:52:16 curt
// Added a new "newbucket.[ch]xx" FGBucket class to replace the old
// fgBUCKET struct and C routines. This FGBucket class adjusts the tile
// width towards the poles to ensure the tiles are at least 8 miles wide.
//

360
Bucket/newbucket.hxx Normal file
View File

@@ -0,0 +1,360 @@
/**************************************************************************
* newbucket.hxx -- new bucket routines for better world modeling
*
* Written by Curtis L. Olson, started February 1999.
*
* Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
*
* This 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$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef _NEWBUCKET_HXX
#define _NEWBUCKET_HXX
#include <Include/compiler.h>
#include STL_STRING
#ifdef FG_HAVE_STD_INCLUDES
# include <cstdio> // sprintf()
# include <iostream>
#else
# include <stdio.h> // sprintf()
# include <iostream.h>
#endif
FG_USING_STD(string);
FG_USING_STD(ostream);
#include <Include/fg_constants.h>
#define FG_BUCKET_SPAN 0.125 // 1/8 of a degree
#define FG_HALF_BUCKET_SPAN 0.0625 // 1/2 of 1/8 of a degree = 1/16 = 0.0625
class FGBucket;
ostream& operator<< ( ostream&, const FGBucket& );
bool operator== ( const FGBucket&, const FGBucket& );
class FGBucket {
private:
double cx, cy; // centerpoint (lon, lat) in degrees of bucket
int lon; // longitude index (-180 to 179)
int lat; // latitude index (-90 to 89)
int x; // x subdivision (0 to 7)
int y; // y subdivision (0 to 7)
public:
// default constructor
FGBucket();
// create a bucket which would contain the specified lon/lat
FGBucket(const double lon, const double lat);
// create a bucket based on "long int" index
FGBucket(const long int bindex);
// create an impossible bucket if false
FGBucket(const bool is_good);
~FGBucket();
// Set the bucket params for the specified lat and lon
void set_bucket( double dlon, double dlat );
// Generate the unique scenery tile index for this bucket
long int gen_index();
string gen_index_str() const;
// Build the path name for this bucket
string gen_base_path() const;
// return the center lon of a tile
double get_center_lon() const;
// return width of the tile
double get_width() const;
// return the center lat of a tile
double get_center_lat() const;
// return height of the tile
double get_height() const;
// Informational methods
inline int get_lon() const { return lon; }
inline int get_lat() const { return lat; }
inline int get_x() const { return x; }
inline int get_y() const { return y; }
// friends
friend ostream& operator<< ( ostream&, const FGBucket& );
friend bool operator== ( const FGBucket&, const FGBucket& );
};
// return the horizontal tile span factor based on latitude
inline double bucket_span( double l ) {
if ( l >= 89.0 ) {
return 0.0;
} else if ( l >= 88.0 ) {
return 8.0;
} else if ( l >= 86.0 ) {
return 4.0;
} else if ( l >= 83.0 ) {
return 2.0;
} else if ( l >= 76.0 ) {
return 1.0;
} else if ( l >= 62.0 ) {
return 0.5;
} else if ( l >= 22.0 ) {
return 0.25;
} else if ( l >= -22.0 ) {
return 0.125;
} else if ( l >= -62.0 ) {
return 0.25;
} else if ( l >= -76.0 ) {
return 0.5;
} else if ( l >= -83.0 ) {
return 1.0;
} else if ( l >= -86.0 ) {
return 2.0;
} else if ( l >= -88.0 ) {
return 4.0;
} else if ( l >= -89.0 ) {
return 8.0;
} else {
return 0.0;
}
}
// Set the bucket params for the specified lat and lon
inline void FGBucket::set_bucket( double dlon, double dlat ) {
//
// latitude first
//
double span = bucket_span( dlat );
double diff = dlon - (double)(int)dlon;
// cout << "diff = " << diff << " span = " << span << endl;
if ( (dlon >= 0) || (fabs(diff) < FG_EPSILON) ) {
lon = (int)dlon;
} else {
lon = (int)dlon - 1;
}
// find subdivision or super lon if needed
if ( span < FG_EPSILON ) {
// polar cap
lon = 0;
x = 0;
} else if ( span <= 1.0 ) {
x = (int)((dlon - lon) / span);
} else {
if ( (dlon >= 0) || (fabs(diff) < FG_EPSILON) ) {
lon = (int)( (int)(lon / span) * span);
} else {
// cout << " lon = " << lon
// << " tmp = " << (int)((lon-1) / span) << endl;
lon = (int)( (int)((lon + 1) / span) * span - span);
if ( lon < -180 ) {
lon = -180;
}
}
x = 0;
}
//
// then latitude
//
diff = dlat - (double)(int)dlat;
if ( (dlat >= 0) || (fabs(diff) < FG_EPSILON) ) {
lat = (int)dlat;
} else {
lat = (int)dlat - 1;
}
y = (int)((dlat - lat) * 8);
}
// default constructor
inline FGBucket::FGBucket() {}
// constructor for specified location
inline FGBucket::FGBucket(const double dlon, const double dlat) {
set_bucket(dlon, dlat);
}
// create an impossible bucket if false
inline FGBucket::FGBucket(const bool is_good) {
set_bucket(0.0, 0.0);
if ( !is_good ) {
lon = -1000;
}
}
// Parse a unique scenery tile index and find the lon, lat, x, and y
inline FGBucket::FGBucket(const long int bindex) {
long int index = bindex;
lon = index >> 14;
index -= lon << 14;
lon -= 180;
lat = index >> 6;
index -= lat << 6;
lat -= 90;
y = index >> 3;
index -= y << 3;
x = index;
}
// default destructor
inline FGBucket::~FGBucket() {}
// Generate the unique scenery tile index for this bucket
//
// The index is constructed as follows:
//
// 9 bits - to represent 360 degrees of longitude (-180 to 179)
// 8 bits - to represent 180 degrees of latitude (-90 to 89)
//
// Each 1 degree by 1 degree tile is further broken down into an 8x8
// grid. So we also need:
//
// 3 bits - to represent x (0 to 7)
// 3 bits - to represent y (0 to 7)
inline long int FGBucket::gen_index() {
return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x;
}
inline string FGBucket::gen_index_str() const {
char tmp[20];
sprintf(tmp, "%ld",
(((long)lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x);
return (string)tmp;
}
// return the center lon of a tile
inline double FGBucket::get_center_lon() const {
double span = bucket_span( lat + y / 8.0 + FG_HALF_BUCKET_SPAN );
if ( span >= 1.0 ) {
return lon + span / 2.0;
} else {
return lon + x * span + span / 2.0;
}
}
// return width of the tile
inline double FGBucket::get_width() const {
return bucket_span( get_center_lat() );
}
// return the center lat of a tile
inline double FGBucket::get_center_lat() const {
return lat + y / 8.0 + FG_HALF_BUCKET_SPAN;
}
// return height of the tile
inline double FGBucket::get_height() const {
return FG_BUCKET_SPAN;
}
// offset a bucket struct by the specified tile units in the X & Y
// direction
FGBucket fgBucketOffset( double dlon, double dlat, int x, int y );
// calculate the offset between two buckets
void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy );
/*
// Given a lat/lon, fill in the local tile index array
void fgBucketGenIdxArray(fgBUCKET *p1, fgBUCKET *tiles, int width, int height);
*/
inline ostream&
operator<< ( ostream& out, const FGBucket& b )
{
return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y;
}
inline bool
operator== ( const FGBucket& b1, const FGBucket& b2 )
{
return ( b1.lon == b2.lon &&
b1.lat == b2.lat &&
b1.x == b2.x &&
b1.y == b2.y );
}
#endif // _NEWBUCKET_HXX
// $Log$
// Revision 1.8 1999/03/27 05:34:06 curt
// Elimitated some const warnings from the compiler.
//
// Revision 1.7 1999/03/25 19:01:51 curt
// Jettisoned old bucketutils.[ch] for newbucket.[ch]xx
//
// Revision 1.6 1999/03/15 17:58:41 curt
// MSVC++ portability tweaks contributed by Bernie Bright.
// Added using std::ostream declaration.
// Added forward declarations to work around a MSVC bug.
//
// Revision 1.5 1999/03/12 22:51:18 curt
// Added some informational methods.
//
// Revision 1.4 1999/03/02 01:01:43 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.3 1999/02/26 22:07:55 curt
// Added initial support for native SGI compilers.
//
// Revision 1.2 1999/02/11 01:09:34 curt
// Added a routine to calculate the offset in bucket units between two buckets.
//
// Revision 1.1 1999/02/08 23:52:16 curt
// Added a new "newbucket.[ch]xx" FGBucket class to replace the old
// fgBUCKET struct and C routines. This FGBucket class adjusts the tile
// width towards the poles to ensure the tiles are at least 8 miles wide.
//

32
Bucket/testbucket.cxx Normal file
View File

@@ -0,0 +1,32 @@
// test new bucket routines
#include "newbucket.cxx"
main() {
double lat = 21.9625;
double lon = -110.0 + 0.0625;
/*
while ( lon < 180 ) {
FGBucket b1( lon, lat );
long int index = b1.gen_index();
FGBucket b2( index );
cout << lon << "," << lat << " ";
cout << b2 << " " << b2.get_center_lon() << ","
<< b2.get_center_lat() << endl;
lon += 0.125;
}
*/
FGBucket b1;
for ( int j = 2; j >= -2; j-- ) {
for ( int i = -2; i < 3; i++ ) {
b1 = fgBucketOffset(lon, lat, i, j);
cout << "(" << i << "," << j << ")" << b1 << "\t";
}
cout << endl;
}
}

View File

@@ -17,7 +17,8 @@ typedef enum {
FG_AIRCRAFT = 0x00000400,
FG_AUTOPILOT = 0x00000800,
FG_SERIAL = 0x00001000,
FG_UNDEFD = 0x00002000, // For range checking
FG_CLIPPER = 0x00002000,
FG_UNDEFD = 0x00004000, // For range checking
FG_ALL = 0xFFFFFFFF
} fgDebugClass;

View File

@@ -29,12 +29,11 @@
#endif
#include "Include/compiler.h"
#include <Include/compiler.h>
#ifdef FG_HAVE_STD_INCLUDES
# include <streambuf>
# include <iostream>
//# include <ostream>
#else
# include <iostream.h>
# include "Include/fg_traits.hxx"
@@ -42,10 +41,12 @@
#include "debug_types.h"
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
FG_USING_STD(streambuf);
FG_USING_STD(ostream);
FG_USING_STD(cerr);
FG_USING_STD(endl);
#endif
//
// TODO:
@@ -211,6 +212,9 @@ fglog()
#endif // _LOGSTREAM_H
// $Log$
// Revision 1.4 1999/03/02 01:01:47 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.3 1999/01/19 20:53:35 curt
// Portability updates by Bernie Bright.
//

View File

@@ -14,7 +14,6 @@ SUBDIRS = \
$(AUDIO_DIRS) \
Bucket \
Debug \
DEM \
Math \
Misc \
PUI \

View File

@@ -8,6 +8,7 @@ libMath_a_SOURCES = \
fg_geodesy.cxx fg_geodesy.hxx \
fg_random.c fg_random.h \
interpolater.cxx interpolater.hxx \
leastsqs.cxx leastsqs.hxx \
mat3.h mat3defs.h mat3err.h \
point3d.hxx \
polar3d.cxx polar3d.hxx \

View File

@@ -8,14 +8,22 @@
// $Id$
// (Log is kept at end of this file)
#include <math.h>
#include <errno.h>
#include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDES
# include <cmath>
# include <cerrno>
#else
# include <math.h>
# include <errno.h>
#endif
#include <Include/fg_constants.h>
#include <Math/fg_geodesy.hxx>
#include <Math/point3d.hxx>
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
FG_USING_STD(cout);
#endif
// ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator
#define ONE_SECOND 4.848136811E-6
@@ -156,6 +164,12 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
$Header$
$Log$
Revision 1.6 1999/03/02 01:01:49 curt
Tweaks for compiling with native SGI compilers.
Revision 1.5 1999/01/27 04:46:14 curt
Portability tweaks by Bernie Bright.
Revision 1.4 1998/11/20 01:00:36 curt
Patch in fgGeoc2Geod() to avoid a floating explosion.
point3d.hxx include math.h for FreeBSD
@@ -242,6 +256,12 @@ Initial Flight Gear revision.
// $Log$
// Revision 1.6 1999/03/02 01:01:49 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.5 1999/01/27 04:46:14 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.4 1998/11/20 01:00:36 curt
// Patch in fgGeoc2Geod() to avoid a floating explosion.
// point3d.hxx include math.h for FreeBSD

View File

@@ -56,8 +56,6 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
// a cartesian point
inline Point3D fgGeodToCart(const Point3D& geod) {
Point3D cp;
Point3D pp;
double gc_lon, gc_lat, sl_radius;
// printf("A geodetic point is (%.2f, %.2f, %.2f)\n",
@@ -69,12 +67,8 @@ inline Point3D fgGeodToCart(const Point3D& geod) {
// printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon,
// gc_lat, sl_radius+geod[2]);
pp = Point3D(gc_lon, gc_lat, sl_radius + geod.radius());
cp = fgPolarToCart3d(pp);
// printf("A cart point is (%.8f, %.8f, %.8f)\n", cp.x, cp.y, cp.z);
return(cp);
Point3D pp = Point3D( gc_lon, gc_lat, sl_radius + geod.radius());
return fgPolarToCart3d(pp);
}
@@ -120,6 +114,9 @@ inline Point3D fgGeodToCart(const Point3D& geod) {
$Header$
$Log$
Revision 1.4 1999/01/27 04:46:15 curt
Portability tweaks by Bernie Bright.
Revision 1.3 1998/10/18 01:17:11 curt
Point3D tweaks.
@@ -196,6 +193,9 @@ Initial Flight Gear revision.
// $Log$
// Revision 1.4 1999/01/27 04:46:15 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.3 1998/10/18 01:17:11 curt
// Point3D tweaks.
//

View File

@@ -24,7 +24,9 @@
// (Log is kept at end of this file)
#include <string>
#include <Include/compiler.h>
#include STL_STRING
#include <Debug/logstream.hxx>
#include <Include/fg_zlib.h>
@@ -36,8 +38,6 @@
// Constructor -- loads the interpolation table from the specified
// file
fgINTERPTABLE::fgINTERPTABLE( const string& file ) {
string fgfile, line;
FG_LOG( FG_MATH, FG_INFO, "Initializing Interpolator for " << file );
fg_gzifstream in( file );
@@ -103,6 +103,12 @@ fgINTERPTABLE::~fgINTERPTABLE( void ) {
// $Log$
// Revision 1.7 1999/02/26 22:08:03 curt
// Added initial support for native SGI compilers.
//
// Revision 1.6 1999/01/27 04:46:16 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.5 1998/11/06 21:17:27 curt
// Converted to new logstream debugging facility. This allows release
// builds with no messages at all (and no performance impact) by using

View File

@@ -32,9 +32,10 @@
# error This library requires C++
#endif
#include "Include/compiler.h"
#include <string>
#include STL_STRING
FG_USING_STD(string);
#define MAX_TABLE_SIZE 32
@@ -61,6 +62,15 @@ public:
// $Log$
// Revision 1.6 1999/03/02 01:01:50 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.5 1999/02/26 22:08:05 curt
// Added initial support for native SGI compilers.
//
// Revision 1.4 1999/01/27 04:46:17 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.3 1998/11/06 21:17:28 curt
// Converted to new logstream debugging facility. This allows release
// builds with no messages at all (and no performance impact) by using

152
Math/leastsqs.cxx Normal file
View File

@@ -0,0 +1,152 @@
// leastsqs.c -- Implements a simple linear least squares best fit routine
//
// Written by Curtis Olson, started September 1997.
//
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
//
// This 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$
// (Log is kept at end of this file)
//
#include <stdio.h>
#include "leastsqs.hxx"
/*
Least squares fit:
y = b0 + b1x
n*sum(xi*yi) - (sum(xi)*sum(yi))
b1 = --------------------------------
n*sum(xi^2) - (sum(xi))^2
b0 = sum(yi)/n - b1*(sum(xi)/n)
*/
double sum_xi, sum_yi, sum_xi_2, sum_xi_yi;
int sum_n;
void least_squares(double *x, double *y, int n, double *m, double *b) {
int i;
sum_xi = sum_yi = sum_xi_2 = sum_xi_yi = 0.0;
sum_n = n;
for ( i = 0; i < n; i++ ) {
sum_xi += x[i];
sum_yi += y[i];
sum_xi_2 += x[i] * x[i];
sum_xi_yi += x[i] * y[i];
}
/* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n",
sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */
*m = ( (double)sum_n * sum_xi_yi - sum_xi * sum_yi ) /
( (double)sum_n * sum_xi_2 - sum_xi * sum_xi );
*b = (sum_yi / (double)sum_n) - (*m) * (sum_xi / (double)sum_n);
/* printf("slope = %.2f intercept = %.2f\n", *m, *b); */
}
/* incrimentally update existing values with a new data point */
void least_squares_update(double x, double y, double *m, double *b) {
++sum_n;
sum_xi += x;
sum_yi += y;
sum_xi_2 += x * x;
sum_xi_yi += x * y;
/* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n",
sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */
*m = ( (double)sum_n * sum_xi_yi - sum_xi * sum_yi ) /
( (double)sum_n * sum_xi_2 - sum_xi * sum_xi );
*b = (sum_yi / (double)sum_n) - (*m) * (sum_xi / (double)sum_n);
/* printf("slope = %.2f intercept = %.2f\n", *m, *b); */
}
/*
return the least squares error:
(y[i] - y_hat[i])^2
-------------------
n
*/
double least_squares_error(double *x, double *y, int n, double m, double b) {
int i;
double error, sum;
sum = 0.0;
for ( i = 0; i < n; i++ ) {
error = y[i] - (m * x[i] + b);
sum += error * error;
// printf("%.2f %.2f\n", error, sum);
}
return ( sum / (double)n );
}
/*
return the maximum least squares error:
(y[i] - y_hat[i])^2
*/
double least_squares_max_error(double *x, double *y, int n, double m, double b){
int i;
double error, max_error;
max_error = 0.0;
for ( i = 0; i < n; i++ ) {
error = y[i] - (m * x[i] + b);
error = error * error;
if ( error > max_error ) {
max_error = error;
}
}
return ( max_error );
}
// $Log$
// Revision 1.1 1999/03/13 17:34:45 curt
// Moved to math subdirectory.
//
// Revision 1.2 1998/04/21 17:03:41 curt
// Prepairing for C++ integration.
//
// Revision 1.1 1998/04/08 22:57:24 curt
// Adopted Gnu automake/autoconf system.
//
// Revision 1.1 1998/03/19 02:54:47 curt
// Reorganized into a class lib called fgDEM.
//
// Revision 1.1 1997/10/13 17:02:35 curt
// Initial revision.
//

90
Math/leastsqs.hxx Normal file
View File

@@ -0,0 +1,90 @@
// leastsqs.h -- Implements a simple linear least squares best fit routine
//
// Written by Curtis Olson, started September 1997.
//
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
//
// This 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$
// (Log is kept at end of this file)
///
#ifndef _LEASTSQS_H
#define _LEASTSQS_H
#ifndef __cplusplus
# error This library requires C++
#endif
/*
Least squares fit:
y = b0 + b1x
n*sum(xi*yi) - (sum(xi)*sum(yi))
b1 = --------------------------------
n*sum(xi^2) - (sum(xi))^2
b0 = sum(yi)/n - b1*(sum(xi)/n)
*/
void least_squares(double *x, double *y, int n, double *m, double *b);
/* incrimentally update existing values with a new data point */
void least_squares_update(double x, double y, double *m, double *b);
/*
return the least squares error:
(y[i] - y_hat[i])^2
-------------------
n
*/
double least_squares_error(double *x, double *y, int n, double m, double b);
/*
return the maximum least squares error:
(y[i] - y_hat[i])^2
*/
double least_squares_max_error(double *x, double *y, int n, double m, double b);
#endif // _LEASTSQS_H
// $Log$
// Revision 1.1 1999/03/13 17:34:45 curt
// Moved to math subdirectory.
//
// Revision 1.2 1998/04/21 17:03:42 curt
// Prepairing for C++ integration.
//
// Revision 1.1 1998/04/08 22:57:25 curt
// Adopted Gnu automake/autoconf system.
//
// Revision 1.1 1998/03/19 02:54:48 curt
// Reorganized into a class lib called fgDEM.
//
// Revision 1.1 1997/10/13 17:02:35 curt
// Initial revision.
//

View File

@@ -30,13 +30,25 @@
# error This library requires C++
#endif
#include "Include/compiler.h"
#include <iostream>
#include <assert.h>
#if defined( __BORLANDC__ )
# define exception c_exception
#elif defined( __FreeBSD__ )
# include <math.h>
#ifdef FG_MATH_EXCEPTION_CLASH
# define exception c_exception
#endif
#ifdef FG_HAVE_STD_INCLUDES
# include <iostream>
# include <cassert>
# include <cmath>
#else
# include <iostream.h>
# include <assert.h>
# include <math.h>
#endif
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
FG_USING_STD(ostream);
FG_USING_STD(istream);
#endif
// -rp- assert.h is buggy under MWCWP3, as multiple #include undef assert !
@@ -48,6 +60,13 @@ const double fgPoint3_Epsilon = 0.0000001;
enum {PX, PY, PZ}; // axes
// Kludge for msvc++ 6.0 - requires forward decls of friend functions.
class Point3D;
istream& operator>> ( istream&, Point3D& );
ostream& operator<< ( ostream&, const Point3D& );
Point3D operator- (const Point3D& p); // -p1
bool operator== (const Point3D& a, const Point3D& b); // p1 == p2?
///////////////////////////
//
@@ -103,7 +122,8 @@ public:
friend ostream& operator<< ( ostream&, const Point3D& );
// Special functions
double distance3D(const Point3D& a) const; // distance between
double distance3D(const Point3D& a) const; // distance between
double distance3Dsquared(const Point3D& a) const; // distance between ^ 2
};
@@ -299,10 +319,33 @@ Point3D::distance3D(const Point3D& a ) const
return sqrt(x*x + y*y + z*z);
}
inline double
Point3D::distance3Dsquared(const Point3D& a ) const
{
double x, y, z;
x = n[PX] - a.n[PX];
y = n[PY] - a.n[PY];
z = n[PZ] - a.n[PZ];
return(x*x + y*y + z*z);
}
#endif // _POINT3D_HXX
// $Log$
// Revision 1.10 1999/03/02 01:01:52 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.9 1999/02/01 21:08:28 curt
// Optimizations from Norman Vine.
//
// Revision 1.8 1999/01/27 04:46:18 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.7 1999/01/19 20:56:58 curt
// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
//

View File

@@ -30,40 +30,6 @@
#include "polar3d.hxx"
// Convert a polar coordinate to a cartesian coordinate. Lon and Lat
// must be specified in radians. The FG convention is for distances
// to be specified in meters
Point3D fgPolarToCart3d(const Point3D& p) {
Point3D pnew;
double tmp;
tmp = cos( p.lat() ) * p.radius();
pnew = Point3D ( cos( p.lon() ) * tmp,
sin( p.lon() ) * tmp,
sin( p.lat() ) * p.radius() );
return pnew;
}
// Convert a cartesian coordinate to polar coordinates (lon/lat
// specified in radians. Distances are specified in meters.
Point3D fgCartToPolar3d(const Point3D& cp) {
Point3D pp;
pp = Point3D( atan2( cp.y(), cp.x() ),
FG_PI_2 -
atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ),
sqrt(cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z()) );
// printf("lon = %.2f lat = %.2f radius = %.2f\n",
// pp.lon, pp.lat, pp.radius);
return pp;
}
// Find the Altitude above the Ellipsoid (WGS84) given the Earth
// Centered Cartesian coordinate vector Distances are specified in
// meters.
@@ -95,6 +61,9 @@ double fgGeodAltFromCart(const Point3D& cp)
// $Log$
// Revision 1.6 1999/01/27 04:46:19 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.5 1998/10/18 01:17:13 curt
// Point3D tweaks.
//

View File

@@ -35,27 +35,41 @@
#include <Math/point3d.hxx>
// Convert a polar coordinate to a cartesian coordinate. Lon and Lat
// must be specified in radians. The FG convention is for distances
// to be specified in meters
Point3D fgPolarToCart3d(const Point3D& p);
// Convert a cartesian coordinate to polar coordinates (lon/lat
// specified in radians. Distances are specified in meters.
Point3D fgCartToPolar3d(const Point3D& cp);
// Find the Altitude above the Ellipsoid (WGS84) given the Earth
// Centered Cartesian coordinate vector Distances are specified in
// meters.
double fgGeodAltFromCart(const Point3D& cp);
// Convert a polar coordinate to a cartesian coordinate. Lon and Lat
// must be specified in radians. The FG convention is for distances
// to be specified in meters
inline Point3D fgPolarToCart3d(const Point3D& p) {
double tmp = cos( p.lat() ) * p.radius();
return Point3D( cos( p.lon() ) * tmp,
sin( p.lon() ) * tmp,
sin( p.lat() ) * p.radius() );
}
// Convert a cartesian coordinate to polar coordinates (lon/lat
// specified in radians. Distances are specified in meters.
inline Point3D fgCartToPolar3d(const Point3D& cp) {
return Point3D( atan2( cp.y(), cp.x() ),
FG_PI_2 -
atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ),
sqrt(cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z()) );
}
#endif // _POLAR_HXX
// $Log$
// Revision 1.5 1999/01/27 04:46:20 curt
// Portability tweaks by Bernie Bright.
//
// Revision 1.4 1998/10/16 19:30:07 curt
// C++-ified the comments.
//

View File

@@ -82,7 +82,7 @@ void map_vec_onto_cur_surface_plane(MAT3vec normal, MAT3vec v0, MAT3vec vec,
// 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, dist;
double ud, dd, tmp;
// u = p - p0
MAT3_SUB_VEC(u, p, p0);
@@ -99,9 +99,7 @@ double fgPointLine(MAT3vec p, MAT3vec p0, MAT3vec d) {
// original point, p.
MAT3_SUB_VEC(v, u, u1);
dist = sqrt(MAT3_DOT_PRODUCT(v, v));
return( dist );
return sqrt(MAT3_DOT_PRODUCT(v, v));
}
@@ -131,6 +129,9 @@ double fgPointLineSquared(MAT3vec p, MAT3vec p0, MAT3vec d) {
// $Log$
// Revision 1.6 1999/03/25 19:02:28 curt
// Minor optimization tweaks.
//
// Revision 1.5 1998/10/16 23:36:38 curt
// c++-ifying.
//

View File

@@ -32,21 +32,27 @@
# include "Include/config.h"
#endif
#include <string>
#include <Include/compiler.h>
#include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDES
#if defined( FG_HAVE_STD_INCLUDES )
# include <istream>
#elif defined ( FG_HAVE_NATIVE_SGI_COMPILERS )
# include <CC/stream.h>
#else
# include <istream.h>
#endif
FG_USING_STD(string);
FG_USING_STD(istream);
#include STL_STRING
#include "zfstream.hxx"
FG_USING_STD(string);
#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
FG_USING_STD(istream);
#endif
//-----------------------------------------------------------------------------
//
// Envelope class for gzifstream.
@@ -72,6 +78,8 @@ public:
void close() { gzbuf.close(); }
bool is_open() { return gzbuf.is_open(); }
private:
// Not defined!
fg_gzifstream( const fg_gzifstream& );
@@ -92,6 +100,15 @@ istream& skipcomment( istream& in );
#endif /* _FGSTREAM_HXX */
// $Log$
// Revision 1.9 1999/03/27 14:04:25 curt
// Added is_open() so we can check if the open() succeeded.
//
// Revision 1.8 1999/03/02 01:01:55 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.7 1999/02/26 22:08:08 curt
// Added initial support for native SGI compilers.
//
// Revision 1.6 1999/01/19 20:41:46 curt
// Portability updates contributed by Bernie Bright.
//

View File

@@ -24,8 +24,8 @@
#ifndef STRUTILS_H
#define STRUTILS_H
#include <string>
#include "Include/compiler.h"
#include <Include/compiler.h>
#include STL_STRING
#ifdef FG_HAVE_STD_INCLUDES
# include <cstdlib>
@@ -64,6 +64,12 @@ atoi( const string& str )
#endif // STRUTILS_H
// $Log$
// Revision 1.6 1999/03/02 01:01:56 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.5 1999/02/26 22:08:09 curt
// Added initial support for native SGI compilers.
//
// Revision 1.4 1999/01/19 20:41:47 curt
// Portability updates contributed by Bernie Bright.
//

View File

@@ -66,6 +66,8 @@ FG_USING_STD(streamoff);
#if defined(__GNUC__) && __GNUC_MINOR__ < 8
# define ios_binary ios::bin
#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS )
# define ios_binary 0
#else
# define ios_binary ios::binary
#endif
@@ -152,6 +154,12 @@ struct gzifstream_base
#endif // _zfstream_hxx
// $Log$
// Revision 1.9 1999/03/08 22:00:12 curt
// Tweak for native SGI compilers.
//
// Revision 1.8 1999/02/26 22:08:10 curt
// Added initial support for native SGI compilers.
//
// Revision 1.7 1999/01/19 20:41:49 curt
// Portability updates contributed by Bernie Bright.
//

View File

@@ -22,20 +22,36 @@
// (Log is kept at end of this file)
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDE
# include <cerrno>
#else
# include <errno.h>
#endif
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
// maybe include something???
#else
# include <termios.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <unistd.h>
#endif
#include <Debug/logstream.hxx>
#include "serial.hxx"
fgSERIAL::fgSERIAL() {
dev_open = false;
fgSERIAL::fgSERIAL()
: dev_open(false)
{
// empty
}
fgSERIAL::fgSERIAL(const string& device, int baud) {
@@ -50,11 +66,44 @@ fgSERIAL::~fgSERIAL() {
// closing the port here screws us up because if we would even so
// much as make a copy of an fgSERIAL object and then delete it,
// the file descriptor gets closed. Doh!!!
// close(fd);
}
bool fgSERIAL::open_port(const string& device) {
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
fd = CreateFile( device.c_str(),
GENERIC_READ | GENERIC_WRITE,
0, // dwShareMode
NULL, // lpSecurityAttributes
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL );
if ( fd == INVALID_HANDLE_VALUE )
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
FG_LOG( FG_SERIAL, FG_ALERT, "Error opening serial device \""
<< device << "\" " << (const char*) lpMsgBuf );
LocalFree( lpMsgBuf );
return false;
}
dev_open = true;
return true;
#else
struct termios config;
fd = open(device.c_str(), O_RDWR | O_NONBLOCK);
@@ -97,16 +146,29 @@ bool fgSERIAL::open_port(const string& device) {
}
return true;
#endif
}
bool fgSERIAL::close_port() {
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
CloseHandle( fd );
#else
close(fd);
#endif
return true;
}
bool fgSERIAL::set_baud(int baud) {
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
return true;
#else
struct termios config;
speed_t speed = B9600;
@@ -158,9 +220,20 @@ bool fgSERIAL::set_baud(int baud) {
}
return true;
#endif
}
string fgSERIAL::read_port() {
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
string result = "";
return result;
#else
const int max_count = 1024;
char buffer[max_count+1];
int count;
@@ -183,9 +256,48 @@ string fgSERIAL::read_port() {
return result;
}
#endif
}
int fgSERIAL::write_port(const string& value) {
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
LPCVOID lpBuffer = value.c_str();
DWORD nNumberOfBytesToWrite = value.length();
DWORD lpNumberOfBytesWritten;
OVERLAPPED lpOverlapped;
if ( WriteFile( fd,
lpBuffer,
nNumberOfBytesToWrite,
&lpNumberOfBytesWritten,
&lpOverlapped ) == 0 )
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
FG_LOG( FG_SERIAL, FG_ALERT, "Serial I/O write error: "
<< (const char*) lpMsgBuf );
LocalFree( lpMsgBuf );
return int(lpNumberOfBytesWritten);
}
return int(lpNumberOfBytesWritten);
#else
static bool error = false;
int count;
@@ -217,10 +329,29 @@ int fgSERIAL::write_port(const string& value) {
}
return count;
#endif
}
// $Log$
// Revision 1.9 1999/02/02 20:13:23 curt
// MSVC++ portability changes by Bernie Bright:
//
// Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
// Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
// Simulator/Cockpit/hud.cxx: Added Standard headers
// Simulator/Cockpit/panel.cxx: Redefinition of default parameter
// Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
// Simulator/Main/fg_init.cxx:
// Simulator/Main/GLUTmain.cxx:
// Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
// Simulator/Objects/material.hxx:
// Simulator/Time/timestamp.hxx: VC++ friend kludge
// Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
// Simulator/Main/views.hxx: Added a constant
//
// Revision 1.8 1999/01/20 13:42:21 curt
// Tweaked FDM interface.
// Testing check sum support for NMEA serial output.

View File

@@ -30,8 +30,17 @@
# error This library requires C++
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string>
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
# include <windows.h>
#endif
#include <Include/compiler.h>
#include STL_STRING
FG_USING_STD(string);
// if someone know how to do this all with C++ streams let me know
// #include <stdio.h>
@@ -39,10 +48,15 @@
class fgSERIAL
{
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
typedef HANDLE fd_type;
#else
typedef int fd_type;
#endif
private:
int fd;
fd_type fd;
bool dev_open;
public:
@@ -66,6 +80,28 @@ public:
// $Log$
// Revision 1.5 1999/03/02 01:01:58 curt
// Tweaks for compiling with native SGI compilers.
//
// Revision 1.4 1999/02/26 22:08:13 curt
// Added initial support for native SGI compilers.
//
// Revision 1.3 1999/02/02 20:13:24 curt
// MSVC++ portability changes by Bernie Bright:
//
// Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
// Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
// Simulator/Cockpit/hud.cxx: Added Standard headers
// Simulator/Cockpit/panel.cxx: Redefinition of default parameter
// Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
// Simulator/Main/fg_init.cxx:
// Simulator/Main/GLUTmain.cxx:
// Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
// Simulator/Objects/material.hxx:
// Simulator/Time/timestamp.hxx: VC++ friend kludge
// Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
// Simulator/Main/views.hxx: Added a constant
//
// Revision 1.2 1998/11/30 17:15:30 curt
// Having the class destructor close the fd was a bad idea ... especially if you
// ever make a copy of the instance and then subsequently destroy either.