Merge FG_Simulator as subdirectory
This commit is contained in:
commit
66a0be21da
211 changed files with 43256 additions and 0 deletions
5
Simulator/Aircraft/Makefile.am
Normal file
5
Simulator/Aircraft/Makefile.am
Normal file
|
@ -0,0 +1,5 @@
|
|||
noinst_LIBRARIES = libAircraft.a
|
||||
|
||||
libAircraft_a_SOURCES = aircraft.cxx aircraft.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
158
Simulator/Aircraft/aircraft.cxx
Normal file
158
Simulator/Aircraft/aircraft.cxx
Normal file
|
@ -0,0 +1,158 @@
|
|||
// aircraft.cxx -- various aircraft routines
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 "aircraft.hxx"
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
|
||||
// This is a record containing all the info for the aircraft currently
|
||||
// being operated
|
||||
fgAIRCRAFT current_aircraft;
|
||||
|
||||
|
||||
// Initialize an Aircraft structure
|
||||
void fgAircraftInit( void ) {
|
||||
FG_LOG( FG_AIRCRAFT, FG_INFO, "Initializing Aircraft structure" );
|
||||
|
||||
current_aircraft.fdm_state = &cur_fdm_state;
|
||||
current_aircraft.controls = &controls;
|
||||
}
|
||||
|
||||
|
||||
// Display various parameters to stdout
|
||||
void fgAircraftOutputCurrent(fgAIRCRAFT *a) {
|
||||
FGInterface *f;
|
||||
|
||||
f = a->fdm_state;
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_DEBUG,
|
||||
"Pos = ("
|
||||
<< (f->get_Longitude() * 3600.0 * RAD_TO_DEG) << ","
|
||||
<< (f->get_Latitude() * 3600.0 * RAD_TO_DEG) << ","
|
||||
<< f->get_Altitude()
|
||||
<< ") (Phi,Theta,Psi)=("
|
||||
<< f->get_Phi() << ","
|
||||
<< f->get_Theta() << ","
|
||||
<< f->get_Psi() << ")" );
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_DEBUG,
|
||||
"Kts = " << f->get_V_equiv_kts()
|
||||
<< " Elev = " << controls.get_elevator()
|
||||
<< " Aileron = " << controls.get_aileron()
|
||||
<< " Rudder = " << controls.get_rudder()
|
||||
<< " Power = " << controls.get_throttle( 0 ) );
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.7 1999/02/05 21:28:09 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.6 1998/12/05 15:53:59 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.5 1998/12/03 01:14:58 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
//
|
||||
// Revision 1.4 1998/11/06 21:17:31 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUG flag.
|
||||
//
|
||||
// Revision 1.3 1998/10/25 14:08:37 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.2 1998/10/17 01:33:52 curt
|
||||
// C++ ifying ...
|
||||
//
|
||||
// Revision 1.1 1998/10/16 23:26:47 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.19 1998/04/25 22:06:24 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.18 1998/04/18 04:13:56 curt
|
||||
// Moved fg_debug.c to it's own library.
|
||||
//
|
||||
// Revision 1.17 1998/02/12 21:59:31 curt
|
||||
// Incorporated code changes contributed by Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.16 1998/02/07 15:29:31 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.15 1998/01/27 00:47:46 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.14 1998/01/19 19:26:56 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.13 1997/12/15 23:54:30 curt
|
||||
// Add xgl wrappers for debugging.
|
||||
// Generate terrain normals on the fly.
|
||||
//
|
||||
// Revision 1.12 1997/12/10 22:37:37 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.11 1997/09/13 02:00:05 curt
|
||||
// Mostly working on stars and generating sidereal time for accurate star
|
||||
// placement.
|
||||
//
|
||||
// Revision 1.10 1997/08/27 03:29:56 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.9 1997/07/19 22:39:08 curt
|
||||
// Moved PI to ../constants.h
|
||||
//
|
||||
// Revision 1.8 1997/06/25 15:39:45 curt
|
||||
// Minor changes to compile with rsxnt/win32.
|
||||
//
|
||||
// Revision 1.7 1997/06/02 03:01:39 curt
|
||||
// Working on views (side, front, back, transitions, etc.)
|
||||
//
|
||||
// Revision 1.6 1997/05/31 19:16:26 curt
|
||||
// Elevator trim added.
|
||||
//
|
||||
// Revision 1.5 1997/05/30 19:30:14 curt
|
||||
// The LaRCsim flight model is starting to look like it is working.
|
||||
//
|
||||
// Revision 1.4 1997/05/30 03:54:11 curt
|
||||
// Made a bit more progress towards integrating the LaRCsim flight model.
|
||||
//
|
||||
// Revision 1.3 1997/05/29 22:39:56 curt
|
||||
// Working on incorporating the LaRCsim flight model.
|
||||
//
|
||||
// Revision 1.2 1997/05/23 15:40:29 curt
|
||||
// Added GNU copyright headers.
|
||||
//
|
||||
// Revision 1.1 1997/05/16 15:58:24 curt
|
||||
// Initial revision.
|
||||
//
|
||||
|
122
Simulator/Aircraft/aircraft.hxx
Normal file
122
Simulator/Aircraft/aircraft.hxx
Normal file
|
@ -0,0 +1,122 @@
|
|||
//*************************************************************************
|
||||
// aircraft.hxx -- define shared aircraft parameters
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 _AIRCRAFT_HXX
|
||||
#define _AIRCRAFT_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Controls/controls.hxx>
|
||||
|
||||
|
||||
// Define a structure containing all the parameters for an aircraft
|
||||
typedef struct{
|
||||
FGInterface *fdm_state;
|
||||
FGControls *controls;
|
||||
} fgAIRCRAFT ;
|
||||
|
||||
|
||||
// current_aircraft contains all the parameters of the aircraft
|
||||
// currently being operated.
|
||||
extern fgAIRCRAFT current_aircraft;
|
||||
|
||||
|
||||
// Initialize an Aircraft structure
|
||||
void fgAircraftInit( void );
|
||||
|
||||
|
||||
// Display various parameters to stdout
|
||||
void fgAircraftOutputCurrent(fgAIRCRAFT *a);
|
||||
|
||||
|
||||
#endif // _AIRCRAFT_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.6 1999/02/05 21:28:10 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.5 1999/02/01 21:33:24 curt
|
||||
// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
|
||||
// Jon accepted my offer to do this and thought it was a good idea.
|
||||
//
|
||||
// Revision 1.4 1998/12/05 16:13:10 curt
|
||||
// Renamed class fgCONTROLS to class FGControls.
|
||||
//
|
||||
// Revision 1.3 1998/12/05 15:54:01 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.2 1998/10/17 01:33:54 curt
|
||||
// C++ ifying ...
|
||||
//
|
||||
// Revision 1.1 1998/10/16 23:26:49 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.12 1998/04/22 13:26:15 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.11 1998/04/21 17:02:27 curt
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.10 1998/02/07 15:29:32 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.9 1998/01/22 02:59:23 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.8 1998/01/19 19:26:57 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.7 1997/12/10 22:37:38 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.6 1997/09/13 02:00:06 curt
|
||||
// Mostly working on stars and generating sidereal time for accurate star
|
||||
// placement.
|
||||
//
|
||||
// Revision 1.5 1997/08/27 03:29:58 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.4 1997/07/23 21:52:17 curt
|
||||
// Put comments around the text after an #endif for increased portability.
|
||||
//
|
||||
// Revision 1.3 1997/06/21 17:12:42 curt
|
||||
// Capitalized subdirectory names.
|
||||
//
|
||||
// Revision 1.2 1997/05/23 15:40:30 curt
|
||||
// Added GNU copyright headers.
|
||||
//
|
||||
// Revision 1.1 1997/05/16 15:58:25 curt
|
||||
// Initial revision.
|
||||
//
|
7
Simulator/Airports/Makefile.am
Normal file
7
Simulator/Airports/Makefile.am
Normal file
|
@ -0,0 +1,7 @@
|
|||
noinst_LIBRARIES = libAirports.a
|
||||
|
||||
libAirports_a_SOURCES = \
|
||||
genapt.cxx genapt.hxx \
|
||||
simple.cxx simple.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
345
Simulator/Airports/genapt.cxx
Normal file
345
Simulator/Airports/genapt.cxx
Normal file
|
@ -0,0 +1,345 @@
|
|||
//
|
||||
// genapt.cxx -- generate airport scenery from the given definition file
|
||||
//
|
||||
// Written by Curtis Olson, started September 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#include <Include/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
#include <vector>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#ifdef FG_HAVE_NATIVE_SGI_COMPILERS
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <Debug/logstream.hxx>
|
||||
// #include <Include/fg_types.h>
|
||||
#include <Math/fg_geodesy.hxx>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/point3d.hxx>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Misc/fgstream.hxx>
|
||||
#include <Objects/material.hxx>
|
||||
|
||||
// #include <gpc/gpc.h>
|
||||
|
||||
#include "genapt.hxx"
|
||||
|
||||
FG_USING_STD(string);
|
||||
FG_USING_STD(vector);
|
||||
|
||||
|
||||
typedef vector < Point3D > container;
|
||||
typedef container::iterator iterator;
|
||||
typedef container::const_iterator const_iterator;
|
||||
|
||||
|
||||
#define FG_APT_BASE_TEX_CONSTANT 2000.0
|
||||
|
||||
// Calculate texture coordinates for a given point.
|
||||
static Point3D calc_tex_coords(double *node, const Point3D& ref) {
|
||||
Point3D cp;
|
||||
Point3D pp;
|
||||
|
||||
cp = Point3D( node[0] + ref.x(), node[1] + ref.y(), node[2] + ref.z() );
|
||||
|
||||
pp = fgCartToPolar3d(cp);
|
||||
|
||||
pp.setx( fmod(FG_APT_BASE_TEX_CONSTANT * pp.x(), 10.0) );
|
||||
pp.sety( fmod(FG_APT_BASE_TEX_CONSTANT * pp.y(), 10.0) );
|
||||
|
||||
if ( pp.x() < 0.0 ) {
|
||||
pp.setx( pp.x() + 10.0 );
|
||||
}
|
||||
|
||||
if ( pp.y() < 0.0 ) {
|
||||
pp.sety( pp.y() + 10.0 );
|
||||
}
|
||||
|
||||
return(pp);
|
||||
}
|
||||
|
||||
|
||||
// generate the actual base area for the airport
|
||||
static void
|
||||
gen_base( const Point3D& average, const container& perimeter, fgTILE *t)
|
||||
{
|
||||
GLint display_list;
|
||||
Point3D cart, cart_trans, tex;
|
||||
MAT3vec normal;
|
||||
double dist, max_dist, temp;
|
||||
int center_num, i;
|
||||
|
||||
fgFRAGMENT fragment;
|
||||
|
||||
max_dist = 0.0;
|
||||
|
||||
FG_LOG( FG_TERRAIN, FG_INFO,
|
||||
"generating airport base for size = " << perimeter.size() );
|
||||
|
||||
fragment.init();
|
||||
fragment.tile_ptr = t;
|
||||
|
||||
// find airport base material in the properties list
|
||||
if ( ! material_mgr.find( APT_BASE_MATERIAL, fragment.material_ptr )) {
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT,
|
||||
"Ack! unknown material name = " << APT_BASE_MATERIAL
|
||||
<< " in fgAptGenerat()" );
|
||||
}
|
||||
|
||||
FG_LOG( FG_TERRAIN, FG_INFO,
|
||||
" tile center = "
|
||||
<< t->center.x() << " " << t->center.y() << " " << t->center.z() );
|
||||
FG_LOG( FG_TERRAIN, FG_INFO,
|
||||
" airport center = "
|
||||
<< average.x() << " " << average.y() << " " << average.z() );
|
||||
fragment.center = average;
|
||||
|
||||
normal[0] = average.x();
|
||||
normal[1] = average.y();
|
||||
normal[2] = average.z();
|
||||
MAT3_NORMALIZE_VEC(normal, temp);
|
||||
|
||||
display_list = xglGenLists(1);
|
||||
xglNewList(display_list, GL_COMPILE);
|
||||
xglBegin(GL_TRIANGLE_FAN);
|
||||
|
||||
// first point center of fan
|
||||
cart_trans = average - t->center;
|
||||
t->nodes[t->ncount][0] = cart_trans.x();
|
||||
t->nodes[t->ncount][1] = cart_trans.y();
|
||||
t->nodes[t->ncount][2] = cart_trans.z();
|
||||
center_num = t->ncount;
|
||||
t->ncount++;
|
||||
|
||||
tex = calc_tex_coords( t->nodes[t->ncount-1], t->center );
|
||||
xglTexCoord2f(tex.x(), tex.y());
|
||||
xglNormal3dv(normal);
|
||||
xglVertex3dv(t->nodes[t->ncount-1]);
|
||||
|
||||
// first point on perimeter
|
||||
const_iterator current = perimeter.begin();
|
||||
cart = fgGeodToCart( *current );
|
||||
cart_trans = cart - t->center;
|
||||
t->nodes[t->ncount][0] = cart_trans.x();
|
||||
t->nodes[t->ncount][1] = cart_trans.y();
|
||||
t->nodes[t->ncount][2] = cart_trans.z();
|
||||
t->ncount++;
|
||||
|
||||
i = 1;
|
||||
tex = calc_tex_coords( t->nodes[i], t->center );
|
||||
dist = cart.distance3Dsquared(average);
|
||||
if ( dist > max_dist ) {
|
||||
max_dist = dist;
|
||||
}
|
||||
xglTexCoord2f(tex.x(), tex.y());
|
||||
xglVertex3dv(t->nodes[i]);
|
||||
++current;
|
||||
++i;
|
||||
|
||||
const_iterator last = perimeter.end();
|
||||
for ( ; current != last; ++current ) {
|
||||
cart = fgGeodToCart( *current );
|
||||
cart_trans = cart - t->center;
|
||||
t->nodes[t->ncount][0] = cart_trans.x();
|
||||
t->nodes[t->ncount][1] = cart_trans.y();
|
||||
t->nodes[t->ncount][2] = cart_trans.z();
|
||||
t->ncount++;
|
||||
fragment.add_face(center_num, i - 1, i);
|
||||
|
||||
tex = calc_tex_coords( t->nodes[i], t->center );
|
||||
dist = cart.distance3Dsquared(average);
|
||||
if ( dist > max_dist ) {
|
||||
max_dist = dist;
|
||||
}
|
||||
xglTexCoord2f(tex.x(), tex.y());
|
||||
xglVertex3dv(t->nodes[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
// last point (first point in perimeter list)
|
||||
current = perimeter.begin();
|
||||
cart = fgGeodToCart( *current );
|
||||
cart_trans = cart - t->center;
|
||||
fragment.add_face(center_num, i - 1, 1);
|
||||
|
||||
tex = calc_tex_coords( t->nodes[1], t->center );
|
||||
xglTexCoord2f(tex.x(), tex.y());
|
||||
xglVertex3dv(t->nodes[1]);
|
||||
|
||||
xglEnd();
|
||||
xglEndList();
|
||||
|
||||
fragment.bounding_radius = sqrt(max_dist);
|
||||
fragment.display_list = display_list;
|
||||
|
||||
t->fragment_list.push_back(fragment);
|
||||
}
|
||||
|
||||
|
||||
// Load a .apt file and register the GL fragments with the
|
||||
// corresponding tile
|
||||
int
|
||||
fgAptGenerate(const string& path, fgTILE *tile)
|
||||
{
|
||||
string token;
|
||||
string apt_id, apt_name;
|
||||
char c;
|
||||
int i = 1;
|
||||
|
||||
// face list (this indexes into the master tile vertex list)
|
||||
container perimeter;
|
||||
Point3D p, average;
|
||||
double avex = 0.0, avey = 0.0, avez = 0.0;
|
||||
int size;
|
||||
|
||||
// gpc_vertex p_2d, list_2d[MAX_PERIMETER];
|
||||
// gpc_vertex_list perimeter_2d;
|
||||
|
||||
fg_gzifstream in( path );
|
||||
if ( !in ) {
|
||||
// exit immediately assuming an airport file for this tile
|
||||
// doesn't exist.
|
||||
return 0;
|
||||
}
|
||||
|
||||
apt_id = "";
|
||||
|
||||
// read in each line of the file
|
||||
in >> skipcomment;
|
||||
while ( ! in.eof() )
|
||||
{
|
||||
in >> token;
|
||||
|
||||
if ( token == "a" ) {
|
||||
// airport info record (start of airport)
|
||||
|
||||
if ( apt_id.length() > 0 ) {
|
||||
// we have just finished reading and airport record.
|
||||
// process the info
|
||||
gen_base(average, perimeter, tile);
|
||||
}
|
||||
|
||||
FG_LOG( FG_TERRAIN, FG_INFO, "Reading airport record" );
|
||||
in >> apt_id;
|
||||
apt_name = "";
|
||||
i = 1;
|
||||
avex = avey = avez = 0.0;
|
||||
perimeter.erase( perimeter.begin(), perimeter.end() );
|
||||
// skip to end of line.
|
||||
while ( in.get(c) && c != '\n' ) {
|
||||
apt_name += c;
|
||||
}
|
||||
FG_LOG( FG_TERRAIN, FG_INFO,
|
||||
"\tID = " << apt_id << " Name = " << apt_name );
|
||||
} else if ( token == "p" ) {
|
||||
// airport area bounding polygon coordinate. These
|
||||
// specify a convex hull that should already have been cut
|
||||
// out of the base terrain. The points are given in
|
||||
// counter clockwise order and are specified in lon/lat
|
||||
// degrees.
|
||||
in >> p;
|
||||
avex += tile->nodes[i][0];
|
||||
avey += tile->nodes[i][1];
|
||||
avez += tile->nodes[i][2];
|
||||
perimeter.push_back(p);
|
||||
++i;
|
||||
} else if ( token == "r" ) {
|
||||
// runway record
|
||||
// skip for now
|
||||
while ( in.get(c) && c != '\n' );
|
||||
}
|
||||
|
||||
in >> skipcomment;
|
||||
}
|
||||
|
||||
if ( apt_id.length() > 0 ) {
|
||||
// we have just finished reading and airport record.
|
||||
// process the info
|
||||
size = perimeter.size();
|
||||
average = Point3D( avex / (double)size + tile->center.x(),
|
||||
avey / (double)size + tile->center.y(),
|
||||
avez / (double)size + tile->center.z() );
|
||||
|
||||
gen_base(average, perimeter, tile);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.14 1999/03/02 01:02:31 curt
|
||||
// Tweaks for building with native SGI compilers.
|
||||
//
|
||||
// Revision 1.13 1999/02/26 22:08:34 curt
|
||||
// Added initial support for native SGI compilers.
|
||||
//
|
||||
// Revision 1.12 1999/02/01 21:08:33 curt
|
||||
// Optimizations from Norman Vine.
|
||||
//
|
||||
// Revision 1.11 1998/11/23 21:48:09 curt
|
||||
// Borland portability tweaks.
|
||||
//
|
||||
// Revision 1.10 1998/11/07 19:07:06 curt
|
||||
// Enable release builds using the --without-logging option to the configure
|
||||
// script. Also a couple log message cleanups, plus some C to C++ comment
|
||||
// conversion.
|
||||
//
|
||||
// Revision 1.9 1998/11/06 21:17:32 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUG flag.
|
||||
//
|
||||
// Revision 1.8 1998/11/06 14:46:59 curt
|
||||
// Changes to track Bernie's updates to fgstream.
|
||||
//
|
||||
// Revision 1.7 1998/10/20 18:26:06 curt
|
||||
// Updates to point3d.hxx
|
||||
//
|
||||
// Revision 1.6 1998/10/18 01:17:16 curt
|
||||
// Point3D tweaks.
|
||||
//
|
||||
// Revision 1.5 1998/10/16 23:27:14 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.4 1998/10/16 00:51:46 curt
|
||||
// Converted to Point3D class.
|
||||
//
|
||||
// Revision 1.3 1998/09/21 20:55:00 curt
|
||||
// Used the cartesian form of the airport area coordinates to determine the
|
||||
// center.
|
||||
//
|
||||
// Revision 1.2 1998/09/14 12:44:30 curt
|
||||
// Don't recalculate perimeter points since it is not likely that they will match
|
||||
// exactly with the previously calculated points, which will leave an ugly gap
|
||||
// around the airport area.
|
||||
//
|
||||
// Revision 1.1 1998/09/14 02:14:01 curt
|
||||
// Initial revision of genapt.[ch]xx for generating airport scenery.
|
||||
//
|
77
Simulator/Airports/genapt.hxx
Normal file
77
Simulator/Airports/genapt.hxx
Normal file
|
@ -0,0 +1,77 @@
|
|||
//
|
||||
// getapt.hxx -- generate airport scenery from the given definition file
|
||||
//
|
||||
// Written by Curtis Olson, started September 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#ifndef _GENAPT_HXX
|
||||
#define _GENAPT_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <Include/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
#include <set>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
|
||||
#include <Scenery/tile.hxx>
|
||||
|
||||
FG_USING_STD(string);
|
||||
FG_USING_STD(set);
|
||||
|
||||
|
||||
// maximum size of airport perimeter structure, even for complex
|
||||
// airports such as KORD this number is typically not very big.
|
||||
#define MAX_PERIMETER 20
|
||||
|
||||
// name of the material to use for the airport base
|
||||
#define APT_BASE_MATERIAL "grass"
|
||||
|
||||
|
||||
// Load a .apt file and register the GL fragments with the
|
||||
// corresponding tile
|
||||
int
|
||||
fgAptGenerate(const string& path, fgTILE *tile);
|
||||
|
||||
|
||||
#endif /* _AIRPORTS_HXX */
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.3 1999/03/02 01:02:32 curt
|
||||
// Tweaks for building with native SGI compilers.
|
||||
//
|
||||
// Revision 1.2 1998/11/23 21:48:10 curt
|
||||
// Borland portability tweaks.
|
||||
//
|
||||
// Revision 1.1 1998/09/14 02:14:01 curt
|
||||
// Initial revision of genapt.[ch]xx for generating airport scenery.
|
||||
//
|
||||
//
|
236
Simulator/Airports/simple.cxx
Normal file
236
Simulator/Airports/simple.cxx
Normal file
|
@ -0,0 +1,236 @@
|
|||
//
|
||||
// simple.cxx -- a really simplistic class to manage airport ID,
|
||||
// lat, lon of the center of one of it's runways, and
|
||||
// elevation in feet.
|
||||
//
|
||||
// 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#include <Include/compiler.h>
|
||||
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Misc/fgstream.hxx>
|
||||
#include <Main/options.hxx>
|
||||
|
||||
#include STL_STRING
|
||||
#include STL_FUNCTIONAL
|
||||
#include STL_ALGORITHM
|
||||
|
||||
#include "simple.hxx"
|
||||
|
||||
|
||||
fgAIRPORTS::fgAIRPORTS() {
|
||||
}
|
||||
|
||||
|
||||
// load the data
|
||||
int fgAIRPORTS::load( const string& file ) {
|
||||
fgAIRPORT a;
|
||||
|
||||
// build the path name to the airport file
|
||||
string path = current_options.get_fg_root() + "/Airports/" + file;
|
||||
|
||||
airports.erase( airports.begin(), airports.end() );
|
||||
|
||||
fg_gzifstream in( path );
|
||||
if ( !in ) {
|
||||
FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
// We can use the STL copy algorithm because the input
|
||||
// file doesn't contain and comments or blank lines.
|
||||
copy( istream_iterator<fgAIRPORT,ptrdiff_t>(in.stream()),
|
||||
istream_iterator<fgAIRPORT,ptrdiff_t>(),
|
||||
inserter( airports, airports.begin() ) );
|
||||
*/
|
||||
|
||||
// read in each line of the file
|
||||
in >> skipcomment;
|
||||
while ( ! in.eof() )
|
||||
{
|
||||
in >> a;
|
||||
airports.insert(a);
|
||||
in >> skipcomment;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// search for the specified id
|
||||
bool
|
||||
fgAIRPORTS::search( const string& id, fgAIRPORT* a ) const
|
||||
{
|
||||
const_iterator it = airports.find( fgAIRPORT(id) );
|
||||
if ( it != airports.end() )
|
||||
{
|
||||
*a = *it;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fgAIRPORT
|
||||
fgAIRPORTS::search( const string& id ) const
|
||||
{
|
||||
fgAIRPORT a;
|
||||
this->search( id, &a );
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
fgAIRPORTS::~fgAIRPORTS( void ) {
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.10 1999/02/26 22:08:35 curt
|
||||
// Added initial support for native SGI compilers.
|
||||
//
|
||||
// Revision 1.9 1998/11/06 21:17:34 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUG flag.
|
||||
//
|
||||
// Revision 1.8 1998/11/06 14:47:01 curt
|
||||
// Changes to track Bernie's updates to fgstream.
|
||||
//
|
||||
// Revision 1.7 1998/09/08 21:38:41 curt
|
||||
// Changes by Bernie Bright.
|
||||
//
|
||||
// Revision 1.6 1998/09/03 21:25:02 curt
|
||||
// tweaked in data file comment handling.
|
||||
//
|
||||
// Revision 1.5 1998/09/02 14:35:38 curt
|
||||
// Rewrote simple airport loader so it can deal with comments and blank lines.
|
||||
//
|
||||
// Revision 1.4 1998/09/01 19:02:53 curt
|
||||
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
||||
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
||||
// I've put these in a new directory, Lib/Misc. Feel free to rename it
|
||||
// to something more appropriate. However you'll have to change the
|
||||
// include directives in all the other files. Additionally you'll have
|
||||
// add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
|
||||
//
|
||||
// The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
|
||||
// test so I've included the required changes in config.tgz.
|
||||
//
|
||||
// There are a fair few changes to Simulator/Objects as I've moved
|
||||
// things around. Loading tiles is quicker but thats not where the delay
|
||||
// is. Tile loading takes a few tenths of a second per file on a P200
|
||||
// but it seems to be the post-processing that leads to a noticeable
|
||||
// blip in framerate. I suppose its time to start profiling to see where
|
||||
// the delays are.
|
||||
//
|
||||
// I've included a brief description of each archives contents.
|
||||
//
|
||||
// Lib/Misc/
|
||||
// zfstream.cxx
|
||||
// zfstream.hxx
|
||||
// C++ stream interface into zlib.
|
||||
// Taken from zlib-1.1.3/contrib/iostream/.
|
||||
// Minor mods for STL compatibility.
|
||||
// There's no copyright associated with these so I assume they're
|
||||
// covered by zlib's.
|
||||
//
|
||||
// fgstream.cxx
|
||||
// fgstream.hxx
|
||||
// FlightGear input stream using gz_ifstream. Tries to open the
|
||||
// given filename. If that fails then filename is examined and a
|
||||
// ".gz" suffix is removed or appended and that file is opened.
|
||||
//
|
||||
// stopwatch.hxx
|
||||
// A simple timer for benchmarking. Not used in production code.
|
||||
// Taken from the Blitz++ project. Covered by GPL.
|
||||
//
|
||||
// strutils.cxx
|
||||
// strutils.hxx
|
||||
// Some simple string manipulation routines.
|
||||
//
|
||||
// Simulator/Airports/
|
||||
// Load airports database using fgstream.
|
||||
// Changed fgAIRPORTS to use set<> instead of map<>.
|
||||
// Added bool fgAIRPORTS::search() as a neater way doing the lookup.
|
||||
// Returns true if found.
|
||||
//
|
||||
// Simulator/Astro/
|
||||
// Modified fgStarsInit() to load stars database using fgstream.
|
||||
//
|
||||
// Simulator/Objects/
|
||||
// Modified fgObjLoad() to use fgstream.
|
||||
// Modified fgMATERIAL_MGR::load_lib() to use fgstream.
|
||||
// Many changes to fgMATERIAL.
|
||||
// Some changes to fgFRAGMENT but I forget what!
|
||||
//
|
||||
// Revision 1.3 1998/08/27 17:01:55 curt
|
||||
// Contributions from Bernie Bright <bbright@c031.aone.net.au>
|
||||
// - use strings for fg_root and airport_id and added methods to return
|
||||
// them as strings,
|
||||
// - inlined all access methods,
|
||||
// - made the parsing functions private methods,
|
||||
// - deleted some unused functions.
|
||||
// - propogated some of these changes out a bit further.
|
||||
//
|
||||
// Revision 1.2 1998/08/25 20:53:24 curt
|
||||
// Shuffled $FG_ROOT file layout.
|
||||
//
|
||||
// Revision 1.1 1998/08/25 17:19:13 curt
|
||||
// Moved from ../Main/
|
||||
//
|
||||
// Revision 1.8 1998/07/13 21:01:37 curt
|
||||
// Wrote access functions for current fgOPTIONS.
|
||||
//
|
||||
// Revision 1.7 1998/06/03 22:01:07 curt
|
||||
// Tweaking sound library usage.
|
||||
//
|
||||
// Revision 1.6 1998/06/03 00:47:13 curt
|
||||
// Updated to compile in audio support if OSS available.
|
||||
// Updated for new version of Steve's audio library.
|
||||
// STL includes don't use .h
|
||||
// Small view optimizations.
|
||||
//
|
||||
// Revision 1.5 1998/05/29 20:37:22 curt
|
||||
// Tweaked material properties & lighting a bit in GLUTmain.cxx.
|
||||
// Read airport list into a "map" STL for dynamic list sizing and fast tree
|
||||
// based lookups.
|
||||
//
|
||||
// Revision 1.4 1998/05/13 18:26:25 curt
|
||||
// Root path info moved to fgOPTIONS.
|
||||
//
|
||||
// Revision 1.3 1998/05/06 03:16:24 curt
|
||||
// Added an averaged global frame rate counter.
|
||||
// Added an option to control tile radius.
|
||||
//
|
||||
// Revision 1.2 1998/04/28 21:42:50 curt
|
||||
// Wrapped zlib calls up so we can conditionally comment out zlib support.
|
||||
//
|
||||
// Revision 1.1 1998/04/25 15:11:11 curt
|
||||
// Added an command line option to set starting position based on airport ID.
|
||||
//
|
||||
//
|
238
Simulator/Airports/simple.hxx
Normal file
238
Simulator/Airports/simple.hxx
Normal file
|
@ -0,0 +1,238 @@
|
|||
//
|
||||
// simple.hxx -- a really simplistic class to manage airport ID,
|
||||
// lat, lon of the center of one of it's runways, and
|
||||
// elevation in feet.
|
||||
//
|
||||
// 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#ifndef _AIRPORTS_HXX
|
||||
#define _AIRPORTS_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <Include/compiler.h>
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <istream>
|
||||
#else
|
||||
# include <istream.h>
|
||||
#endif
|
||||
|
||||
#include STL_STRING
|
||||
#include <set>
|
||||
|
||||
FG_USING_STD(string);
|
||||
FG_USING_STD(set);
|
||||
FG_USING_STD(istream);
|
||||
|
||||
|
||||
class fgAIRPORT {
|
||||
public:
|
||||
fgAIRPORT( const string& name = "",
|
||||
double lon = 0.0,
|
||||
double lat = 0.0,
|
||||
double ele = 0.0 )
|
||||
: id(name), longitude(lon), latitude(lat), elevation(ele) {}
|
||||
|
||||
bool operator < ( const fgAIRPORT& a ) const {
|
||||
return id < a.id;
|
||||
}
|
||||
|
||||
public:
|
||||
string id;
|
||||
double longitude;
|
||||
double latitude;
|
||||
double elevation;
|
||||
};
|
||||
|
||||
inline istream&
|
||||
operator >> ( istream& in, fgAIRPORT& a )
|
||||
{
|
||||
return in >> a.id >> a.longitude >> a.latitude >> a.elevation;
|
||||
}
|
||||
|
||||
class fgAIRPORTS {
|
||||
public:
|
||||
#ifdef FG_NO_DEFAULT_TEMPLATE_ARGS
|
||||
typedef set< fgAIRPORT, less< fgAIRPORT > > container;
|
||||
#else
|
||||
typedef set< fgAIRPORT > container;
|
||||
#endif
|
||||
typedef container::iterator iterator;
|
||||
typedef container::const_iterator const_iterator;
|
||||
|
||||
private:
|
||||
container airports;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
fgAIRPORTS();
|
||||
|
||||
// Destructor
|
||||
~fgAIRPORTS();
|
||||
|
||||
// load the data
|
||||
int load( const string& file );
|
||||
|
||||
// search for the specified id.
|
||||
// Returns true if successful, otherwise returns false.
|
||||
// On success, airport data is returned thru "airport" pointer.
|
||||
// "airport" is not changed if "id" is not found.
|
||||
bool search( const string& id, fgAIRPORT* airport ) const;
|
||||
fgAIRPORT search( const string& id ) const;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _AIRPORTS_HXX */
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.8 1999/03/15 17:58:57 curt
|
||||
// MSVC++ portability tweaks contributed by Bernie Bright.
|
||||
// Added using std::istream declaration.
|
||||
//
|
||||
// Revision 1.7 1999/03/02 01:02:33 curt
|
||||
// Tweaks for building with native SGI compilers.
|
||||
//
|
||||
// Revision 1.6 1999/02/26 22:08:36 curt
|
||||
// Added initial support for native SGI compilers.
|
||||
//
|
||||
// Revision 1.5 1998/11/02 18:25:34 curt
|
||||
// Check for __CYGWIN__ (b20) as well as __CYGWIN32__ (pre b20 compilers)
|
||||
// Other misc. tweaks.
|
||||
//
|
||||
// Revision 1.4 1998/09/08 21:38:43 curt
|
||||
// Changes by Bernie Bright.
|
||||
//
|
||||
// Revision 1.3 1998/09/01 19:02:54 curt
|
||||
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
||||
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
||||
// I've put these in a new directory, Lib/Misc. Feel free to rename it
|
||||
// to something more appropriate. However you'll have to change the
|
||||
// include directives in all the other files. Additionally you'll have
|
||||
// add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
|
||||
//
|
||||
// The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
|
||||
// test so I've included the required changes in config.tgz.
|
||||
//
|
||||
// There are a fair few changes to Simulator/Objects as I've moved
|
||||
// things around. Loading tiles is quicker but thats not where the delay
|
||||
// is. Tile loading takes a few tenths of a second per file on a P200
|
||||
// but it seems to be the post-processing that leads to a noticeable
|
||||
// blip in framerate. I suppose its time to start profiling to see where
|
||||
// the delays are.
|
||||
//
|
||||
// I've included a brief description of each archives contents.
|
||||
//
|
||||
// Lib/Misc/
|
||||
// zfstream.cxx
|
||||
// zfstream.hxx
|
||||
// C++ stream interface into zlib.
|
||||
// Taken from zlib-1.1.3/contrib/iostream/.
|
||||
// Minor mods for STL compatibility.
|
||||
// There's no copyright associated with these so I assume they're
|
||||
// covered by zlib's.
|
||||
//
|
||||
// fgstream.cxx
|
||||
// fgstream.hxx
|
||||
// FlightGear input stream using gz_ifstream. Tries to open the
|
||||
// given filename. If that fails then filename is examined and a
|
||||
// ".gz" suffix is removed or appended and that file is opened.
|
||||
//
|
||||
// stopwatch.hxx
|
||||
// A simple timer for benchmarking. Not used in production code.
|
||||
// Taken from the Blitz++ project. Covered by GPL.
|
||||
//
|
||||
// strutils.cxx
|
||||
// strutils.hxx
|
||||
// Some simple string manipulation routines.
|
||||
//
|
||||
// Simulator/Airports/
|
||||
// Load airports database using fgstream.
|
||||
// Changed fgAIRPORTS to use set<> instead of map<>.
|
||||
// Added bool fgAIRPORTS::search() as a neater way doing the lookup.
|
||||
// Returns true if found.
|
||||
//
|
||||
// Simulator/Astro/
|
||||
// Modified fgStarsInit() to load stars database using fgstream.
|
||||
//
|
||||
// Simulator/Objects/
|
||||
// Modified fgObjLoad() to use fgstream.
|
||||
// Modified fgMATERIAL_MGR::load_lib() to use fgstream.
|
||||
// Many changes to fgMATERIAL.
|
||||
// Some changes to fgFRAGMENT but I forget what!
|
||||
//
|
||||
// Revision 1.2 1998/08/27 17:01:56 curt
|
||||
// Contributions from Bernie Bright <bbright@c031.aone.net.au>
|
||||
// - use strings for fg_root and airport_id and added methods to return
|
||||
// them as strings,
|
||||
// - inlined all access methods,
|
||||
// - made the parsing functions private methods,
|
||||
// - deleted some unused functions.
|
||||
// - propogated some of these changes out a bit further.
|
||||
//
|
||||
// Revision 1.1 1998/08/25 17:19:14 curt
|
||||
// Moved from ../Main/
|
||||
//
|
||||
// Revision 1.7 1998/07/24 21:39:09 curt
|
||||
// Debugging output tweaks.
|
||||
// Cast glGetString to (char *) to avoid compiler errors.
|
||||
// Optimizations to fgGluLookAt() by Norman Vine.
|
||||
//
|
||||
// Revision 1.6 1998/07/06 21:34:19 curt
|
||||
// Added an enable/disable splash screen option.
|
||||
// Added an enable/disable intro music option.
|
||||
// Added an enable/disable instrument panel option.
|
||||
// Added an enable/disable mouse pointer option.
|
||||
// Added using namespace std for compilers that support this.
|
||||
//
|
||||
// Revision 1.5 1998/06/17 21:35:11 curt
|
||||
// Refined conditional audio support compilation.
|
||||
// Moved texture parameter setup calls to ../Scenery/materials.cxx
|
||||
// #include <string.h> before various STL includes.
|
||||
// Make HUD default state be enabled.
|
||||
//
|
||||
// Revision 1.4 1998/06/03 00:47:14 curt
|
||||
// Updated to compile in audio support if OSS available.
|
||||
// Updated for new version of Steve's audio library.
|
||||
// STL includes don't use .h
|
||||
// Small view optimizations.
|
||||
//
|
||||
// Revision 1.3 1998/06/01 17:54:42 curt
|
||||
// Added Linux audio support.
|
||||
// avoid glClear( COLOR_BUFFER_BIT ) when not using it to set the sky color.
|
||||
// map stl tweaks.
|
||||
//
|
||||
// Revision 1.2 1998/05/29 20:37:22 curt
|
||||
// Tweaked material properties & lighting a bit in GLUTmain.cxx.
|
||||
// Read airport list into a "map" STL for dynamic list sizing and fast tree
|
||||
// based lookups.
|
||||
//
|
||||
// Revision 1.1 1998/04/25 15:11:11 curt
|
||||
// Added an command line option to set starting position based on airport ID.
|
||||
//
|
||||
//
|
19
Simulator/Astro/Makefile.am
Normal file
19
Simulator/Astro/Makefile.am
Normal file
|
@ -0,0 +1,19 @@
|
|||
noinst_LIBRARIES = libAstro.a
|
||||
|
||||
libAstro_a_SOURCES = \
|
||||
celestialBody.cxx celestialBody.hxx \
|
||||
jupiter.cxx jupiter.hxx \
|
||||
mars.cxx mars.hxx \
|
||||
mercury.cxx mercury.hxx \
|
||||
moon.cxx moon.hxx \
|
||||
neptune.cxx neptune.hxx \
|
||||
pluto.hxx \
|
||||
saturn.cxx saturn.hxx \
|
||||
sky.cxx sky.hxx \
|
||||
solarsystem.cxx solarsystem.hxx \
|
||||
star.cxx star.hxx \
|
||||
stars.cxx stars.hxx \
|
||||
uranus.cxx uranus.hxx \
|
||||
venus.cxx venus.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
177
Simulator/Astro/celestialBody.cxx
Normal file
177
Simulator/Astro/celestialBody.cxx
Normal file
|
@ -0,0 +1,177 @@
|
|||
/**************************************************************************
|
||||
* celestialBody.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
#include <Debug/logstream.hxx>
|
||||
|
||||
#ifdef FG_MATH_EXCEPTION_CLASH
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
/**************************************************************************
|
||||
* void CelestialBody::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* Basically, this member function provides a general interface for
|
||||
* calculating the right ascension and declinaion. This function is
|
||||
* used for calculating the planetary positions. For the planets, an
|
||||
* overloaded member function is provided to additionally calculate the
|
||||
* planet's magnitude.
|
||||
* The sun and moon have their own overloaded updatePosition member, as their
|
||||
* position is calculated an a slightly different manner.
|
||||
*
|
||||
* arguments:
|
||||
* fgTIME t: provides the current time.
|
||||
* Star *ourSun: the sun's position is needed to convert heliocentric
|
||||
* coordinates into geocentric coordinates.
|
||||
*
|
||||
* return value: none
|
||||
*
|
||||
*************************************************************************/
|
||||
void CelestialBody::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
double eccAnom, v, ecl, actTime,
|
||||
xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
|
||||
|
||||
updateOrbElements(t);
|
||||
actTime = fgCalcActTime(t);
|
||||
|
||||
// calcualate the angle bewteen ecliptic and equatorial coordinate system
|
||||
ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 *actTime);
|
||||
|
||||
eccAnom = fgCalcEccAnom(M, e); //calculate the eccentric anomaly
|
||||
xv = a * (cos(eccAnom) - e);
|
||||
yv = a * (sqrt (1.0 - e*e) * sin(eccAnom));
|
||||
v = atan2(yv, xv); // the planet's true anomaly
|
||||
r = sqrt (xv*xv + yv*yv); // the planet's distance
|
||||
|
||||
// calculate the planet's position in 3D space
|
||||
xh = r * (cos(N) * cos(v+w) - sin(N) * sin(v+w) * cos(i));
|
||||
yh = r * (sin(N) * cos(v+w) + cos(N) * sin(v+w) * cos(i));
|
||||
zh = r * (sin(v+w) * sin(i));
|
||||
|
||||
// calculate the ecliptic longitude and latitude
|
||||
xg = xh + ourSun->getxs();
|
||||
yg = yh + ourSun->getys();
|
||||
zg = zh;
|
||||
|
||||
lonEcl = atan2(yh, xh);
|
||||
latEcl = atan2(zh, sqrt(xh*xh+yh*yh));
|
||||
|
||||
xe = xg;
|
||||
ye = yg * cos(ecl) - zg * sin(ecl);
|
||||
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)" );
|
||||
|
||||
//calculate some variables specific to calculating the magnitude
|
||||
//of the planet
|
||||
R = sqrt (xg*xg + yg*yg + zg*zg);
|
||||
s = ourSun->getDistance();
|
||||
|
||||
// It is possible from these calculations for the argument to acos
|
||||
// to exceed the valid range for acos(). So we do a little extra
|
||||
// checking.
|
||||
|
||||
double tmp = (r*r + R*R - s*s) / (2*r*R);
|
||||
if ( tmp > 1.0) {
|
||||
tmp = 1.0;
|
||||
} else if ( tmp < -1.0) {
|
||||
tmp = -1.0;
|
||||
}
|
||||
|
||||
FV = RAD_TO_DEG * acos( tmp );
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* double CelestialBody::fgCalcEccAnom(double M, double e)
|
||||
* this private member calculates the eccentric anomaly of a celestial body,
|
||||
* given its mean anomaly and eccentricity.
|
||||
*
|
||||
* -Mean anomaly: the approximate angle between the perihelion and the current
|
||||
* position. this angle increases uniformly with time.
|
||||
*
|
||||
* True anomaly: the actual angle between perihelion and current position.
|
||||
*
|
||||
* Eccentric anomaly: this is an auxilary angle, used in calculating the true
|
||||
* anomaly from the mean anomaly.
|
||||
*
|
||||
* -eccentricity. Indicates the amount in which the orbit deviates from a
|
||||
* circle (0 = circle, 0-1, is ellipse, 1 = parabola, > 1 = hyperbola).
|
||||
*
|
||||
* This function is also known as solveKeplersEquation()
|
||||
*
|
||||
* arguments:
|
||||
* M: the mean anomaly
|
||||
* e: the eccentricity
|
||||
*
|
||||
* return value:
|
||||
* the eccentric anomaly
|
||||
*
|
||||
****************************************************************************/
|
||||
double CelestialBody::fgCalcEccAnom(double M, double e)
|
||||
{
|
||||
double
|
||||
eccAnom, E0, E1, diff;
|
||||
|
||||
eccAnom = M + e * sin(M) * (1.0 + e * cos (M));
|
||||
// iterate to achieve a greater precision for larger eccentricities
|
||||
if (e > 0.05)
|
||||
{
|
||||
E0 = eccAnom;
|
||||
do
|
||||
{
|
||||
E1 = E0 - (E0 - e * sin(E0) - M) / (1 - e *cos(E0));
|
||||
diff = fabs(E0 - E1);
|
||||
E0 = E1;
|
||||
}
|
||||
while (diff > (DEG_TO_RAD * 0.001));
|
||||
return E0;
|
||||
}
|
||||
return eccAnom;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
196
Simulator/Astro/celestialBody.hxx
Normal file
196
Simulator/Astro/celestialBody.hxx
Normal file
|
@ -0,0 +1,196 @@
|
|||
/**************************************************************************
|
||||
* celestialBody.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef _CELESTIALBODY_H_
|
||||
#define _CELESTIALBODY_H_
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
|
||||
class Star;
|
||||
|
||||
class CelestialBody
|
||||
{
|
||||
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 */
|
||||
double iSec; /* inclination to the ecliptic second part */
|
||||
double wFirst; /* first part of argument of perihelion */
|
||||
double wSec; /* second part of argument of perihelion */
|
||||
double aFirst; /* semimayor axis first part*/
|
||||
double aSec; /* semimayor axis second part */
|
||||
double eFirst; /* eccentricity first part */
|
||||
double eSec; /* eccentricity second part */
|
||||
double MFirst; /* Mean anomaly first part */
|
||||
double MSec; /* Mean anomaly second part */
|
||||
|
||||
double N, i, w, a, e, M; /* the resulting orbital elements, obtained from the former */
|
||||
|
||||
double rightAscension, declination;
|
||||
double r, R, s, FV;
|
||||
double magnitude;
|
||||
double lonEcl, latEcl;
|
||||
|
||||
double fgCalcEccAnom(double M, double e);
|
||||
double fgCalcActTime(fgTIME *t);
|
||||
void updateOrbElements(fgTIME *t);
|
||||
|
||||
public:
|
||||
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, fgTIME *t);
|
||||
void getPos(double *ra, double *dec);
|
||||
void getPos(double *ra, double *dec, double *magnitude);
|
||||
double getLon();
|
||||
double getLat();
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* inline CelestialBody::CelestialBody
|
||||
* public constructor for a generic celestialBody object.
|
||||
* initializes the 6 primary orbital elements. The elements are:
|
||||
* N: longitude of the ascending node
|
||||
* i: inclination to the ecliptic
|
||||
* w: argument of perihelion
|
||||
* a: semi-major axis, or mean distance from the sun
|
||||
* e: eccenticity
|
||||
* M: mean anomaly
|
||||
* Each orbital element consists of a constant part and a variable part that
|
||||
* gradually changes over time.
|
||||
*
|
||||
* Argumetns:
|
||||
* the 13 arguments to the constructor constitute the first, constant
|
||||
* ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital
|
||||
* elements. The 13th argument is the current time. Note that the inclination
|
||||
* is written with a capital (If, Is), because 'if' is a reserved word in the
|
||||
* C/C++ programming language.
|
||||
***************************************************************************/
|
||||
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, fgTIME *t)
|
||||
{
|
||||
NFirst = Nf; NSec = Ns;
|
||||
iFirst = If; iSec = Is;
|
||||
wFirst = wf; wSec = ws;
|
||||
aFirst = af; aSec = as;
|
||||
eFirst = ef; eSec = es;
|
||||
MFirst = Mf; MSec = Ms;
|
||||
updateOrbElements(t);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* inline void CelestialBody::updateOrbElements(fgTIME *t)
|
||||
* given the current time, this private member calculates the actual
|
||||
* orbital elements
|
||||
*
|
||||
* Arguments: fgTIME *t: the current time:
|
||||
*
|
||||
* return value: none
|
||||
***************************************************************************/
|
||||
inline void CelestialBody::updateOrbElements(fgTIME *t)
|
||||
{
|
||||
double actTime = fgCalcActTime(t);
|
||||
M = DEG_TO_RAD * (MFirst + (MSec * actTime));
|
||||
w = DEG_TO_RAD * (wFirst + (wSec * actTime));
|
||||
N = DEG_TO_RAD * (NFirst + (NSec * actTime));
|
||||
i = DEG_TO_RAD * (iFirst + (iSec * actTime));
|
||||
e = eFirst + (eSec * actTime);
|
||||
a = aFirst + (aSec * actTime);
|
||||
}
|
||||
/*****************************************************************************
|
||||
* inline double CelestialBody::fgCalcActTime(fgTIME *t)
|
||||
* this private member function returns the offset in days from the epoch for
|
||||
* wich the orbital elements are calculated (Jan, 1st, 2000).
|
||||
*
|
||||
* Argument: the current time
|
||||
*
|
||||
* return value: the (fractional) number of days until Jan 1, 2000.
|
||||
****************************************************************************/
|
||||
inline double CelestialBody::fgCalcActTime(fgTIME *t)
|
||||
{
|
||||
return (t->mjd - 36523.5);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* inline void CelestialBody::getPos(double* ra, double* dec)
|
||||
* gives public access to Right Ascension and declination
|
||||
*
|
||||
****************************************************************************/
|
||||
inline void CelestialBody::getPos(double* ra, double* dec)
|
||||
{
|
||||
*ra = rightAscension;
|
||||
*dec = declination;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
|
||||
* gives public acces to the current Right ascension, declination, and
|
||||
* magnitude
|
||||
****************************************************************************/
|
||||
inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
|
||||
{
|
||||
*ra = rightAscension;
|
||||
*dec = declination;
|
||||
*magn = magnitude;
|
||||
}
|
||||
|
||||
inline double CelestialBody::getLon()
|
||||
{
|
||||
return lonEcl;
|
||||
}
|
||||
|
||||
inline double CelestialBody::getLat()
|
||||
{
|
||||
return latEcl;
|
||||
}
|
||||
|
||||
#endif // _CELESTIALBODY_H_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
66
Simulator/Astro/jupiter.cxx
Normal file
66
Simulator/Astro/jupiter.cxx
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**************************************************************************
|
||||
* jupiter.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "jupiter.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Jupiter::Jupiter(fgTIME *t)
|
||||
* Public constructor for class Jupiter
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Jupiter are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Jupiter::Jupiter(fgTIME *t) :
|
||||
CelestialBody(100.4542, 2.7685400E-5,
|
||||
1.3030, -1.557E-7,
|
||||
273.8777, 1.6450500E-5,
|
||||
5.2025600, 0.000000,
|
||||
0.048498, 4.469E-9,
|
||||
19.89500, 0.08308530010, t)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Jupiter::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Jupiter, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Jupiter specific equation
|
||||
*************************************************************************/
|
||||
void Jupiter::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
39
Simulator/Astro/jupiter.hxx
Normal file
39
Simulator/Astro/jupiter.hxx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
* jupiter.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _JUPITER_HXX_
|
||||
#define _JUPITER_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Jupiter : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Jupiter (fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _JUPITER_HXX_
|
60
Simulator/Astro/mars.cxx
Normal file
60
Simulator/Astro/mars.cxx
Normal file
|
@ -0,0 +1,60 @@
|
|||
/**************************************************************************
|
||||
* mars.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "mars.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Mars::Mars(fgTIME *t)
|
||||
* Public constructor for class Mars
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Mars are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Mars::Mars(fgTIME *t) :
|
||||
CelestialBody(49.55740, 2.1108100E-5,
|
||||
1.8497, -1.78E-8,
|
||||
286.5016, 2.9296100E-5,
|
||||
1.5236880, 0.000000,
|
||||
0.093405, 2.516E-9,
|
||||
18.60210, 0.52402077660, t)
|
||||
{
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Mars::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Mars, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Mars specific equation
|
||||
*************************************************************************/
|
||||
void Mars::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
|
||||
}
|
39
Simulator/Astro/mars.hxx
Normal file
39
Simulator/Astro/mars.hxx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
* mars.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _MARS_HXX_
|
||||
#define _MARS_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Mars : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Mars ( fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _MARS_HXX_
|
62
Simulator/Astro/mercury.cxx
Normal file
62
Simulator/Astro/mercury.cxx
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**************************************************************************
|
||||
* mercury.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "mercury.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Mercury::Mercury(fgTIME *t)
|
||||
* Public constructor for class Mercury
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Mercury are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Mercury::Mercury(fgTIME *t) :
|
||||
CelestialBody (48.33130, 3.2458700E-5,
|
||||
7.0047, 5.00E-8,
|
||||
29.12410, 1.0144400E-5,
|
||||
0.3870980, 0.000000,
|
||||
0.205635, 5.59E-10,
|
||||
168.6562, 4.09233443680, t)
|
||||
{
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Mercury::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Mercury, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Mercury specific equation
|
||||
*************************************************************************/
|
||||
void Mercury::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
|
||||
}
|
||||
|
||||
|
39
Simulator/Astro/mercury.hxx
Normal file
39
Simulator/Astro/mercury.hxx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
* mercury.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _MERCURY_HXX_
|
||||
#define _MERCURY_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Mercury : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Mercury ( fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star* ourSun);
|
||||
};
|
||||
|
||||
#endif // _MERURY_HXX_
|
394
Simulator/Astro/moon.cxx
Normal file
394
Simulator/Astro/moon.cxx
Normal file
|
@ -0,0 +1,394 @@
|
|||
/**************************************************************************
|
||||
* moon.cxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#include <FDM/flight.hxx>
|
||||
|
||||
#include <string.h>
|
||||
#include "moon.hxx"
|
||||
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Objects/texload.h>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Moon::Moon(fgTIME *t)
|
||||
* Public constructor for class Moon. Initializes the orbital elements and
|
||||
* sets up the moon texture.
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Moon are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Moon::Moon(fgTIME *t) :
|
||||
CelestialBody(125.1228, -0.0529538083,
|
||||
5.1454, 0.00000,
|
||||
318.0634, 0.1643573223,
|
||||
60.266600, 0.000000,
|
||||
0.054900, 0.000000,
|
||||
115.3654, 13.0649929509, t)
|
||||
{
|
||||
string tpath, fg_tpath;
|
||||
int width, height;
|
||||
|
||||
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
|
||||
#ifdef GL_VERSION_1_1
|
||||
xglGenTextures(1, &moon_texid);
|
||||
xglBindTexture(GL_TEXTURE_2D, moon_texid);
|
||||
#elif GL_EXT_texture_object
|
||||
xglGenTexturesEXT(1, &moon_texid);
|
||||
xglBindTextureEXT(GL_TEXTURE_2D, moon_texid);
|
||||
#else
|
||||
# error port me
|
||||
#endif
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// load in the texture data
|
||||
tpath = current_options.get_fg_root() + "/Textures/" + "moon.rgb";
|
||||
|
||||
if ( (moon_texbuf = read_rgb_texture(tpath.c_str(), &width, &height))
|
||||
== NULL )
|
||||
{
|
||||
// Try compressed
|
||||
fg_tpath = tpath + ".gz";
|
||||
if ( (moon_texbuf = read_rgb_texture(fg_tpath.c_str(), &width, &height))
|
||||
== NULL )
|
||||
{
|
||||
FG_LOG( FG_GENERAL, FG_ALERT,
|
||||
"Error in loading moon texture " << tpath );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
glTexImage2D( GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGB,
|
||||
256, 256,
|
||||
0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE,
|
||||
moon_texbuf);
|
||||
|
||||
// setup the halo texture
|
||||
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
|
||||
#ifdef GL_VERSION_1_1
|
||||
xglGenTextures(1, &moon_halotexid);
|
||||
xglBindTexture(GL_TEXTURE_2D, moon_halotexid);
|
||||
#elif GL_EXT_texture_object
|
||||
xglGenTexturesEXT(1, &moon_halotexid);
|
||||
xglBindTextureEXT(GL_TEXTURE_2D, moon_halotexid);
|
||||
#else
|
||||
# error port me
|
||||
#endif
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
setHalo();
|
||||
glTexImage2D( GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
256, 256,
|
||||
0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
moon_halotexbuf);
|
||||
moonObject = gluNewQuadric();
|
||||
}
|
||||
|
||||
Moon::~Moon()
|
||||
{
|
||||
//delete moonObject;
|
||||
delete moon_texbuf;
|
||||
delete moon_halotexbuf;
|
||||
}
|
||||
|
||||
|
||||
static int texWidth = 256; /* 64x64 is plenty */
|
||||
|
||||
void Moon::setHalo()
|
||||
{
|
||||
int texSize;
|
||||
//void *textureBuf;
|
||||
GLubyte *p;
|
||||
int i,j;
|
||||
double radius;
|
||||
|
||||
texSize = texWidth*texWidth;
|
||||
|
||||
moon_halotexbuf = new GLubyte[texSize*4];
|
||||
if (!moon_halotexbuf)
|
||||
return; // Ugly!
|
||||
|
||||
p = moon_halotexbuf;
|
||||
|
||||
radius = (double)(texWidth / 2);
|
||||
|
||||
for (i=0; i < texWidth; i++) {
|
||||
for (j=0; j < texWidth; j++) {
|
||||
double x, y, d;
|
||||
|
||||
x = fabs((double)(i - (texWidth / 2)));
|
||||
y = fabs((double)(j - (texWidth / 2)));
|
||||
|
||||
d = sqrt((x * x) + (y * y));
|
||||
if (d < radius)
|
||||
{
|
||||
double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
|
||||
// inverse square looks nice
|
||||
*p = (int)((double)0xff * (t * t));
|
||||
*(p+1) = (int)((double) 0xff * (t*t));
|
||||
*(p+2) = (int)((double) 0xff * (t*t));
|
||||
*(p+3) = 0x11;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p = 0x00;
|
||||
*(p+1) = 0x00;
|
||||
*(p+2) = 0x00;
|
||||
*(p+3) = 0x11;
|
||||
}
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
|
||||
// GL_LUMINANCE,
|
||||
// GL_UNSIGNED_BYTE, textureBuf);
|
||||
//free(textureBuf);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* void Moon::updatePosition(fgTIME *t, Star *ourSun)
|
||||
* this member function calculates the actual topocentric position (i.e.)
|
||||
* the position of the moon as seen from the current position on the surface
|
||||
* of the moon.
|
||||
****************************************************************************/
|
||||
void Moon::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
double
|
||||
eccAnom, ecl, actTime,
|
||||
xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
|
||||
Ls, Lm, D, F, mpar, gclat, rho, HA, g,
|
||||
geoRa, geoDec;
|
||||
|
||||
fgAIRCRAFT *air;
|
||||
FGInterface *f;
|
||||
|
||||
air = ¤t_aircraft;
|
||||
f = air->fdm_state;
|
||||
|
||||
updateOrbElements(t);
|
||||
actTime = fgCalcActTime(t);
|
||||
|
||||
// calculate the angle between ecliptic and equatorial coordinate system
|
||||
// in Radians
|
||||
ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 3.563E-7) * actTime);
|
||||
eccAnom = fgCalcEccAnom(M, e); // Calculate the eccentric anomaly
|
||||
xv = a * (cos(eccAnom) - e);
|
||||
yv = a * (sqrt(1.0 - e*e) * sin(eccAnom));
|
||||
v = atan2(yv, xv); // the moon's true anomaly
|
||||
r = sqrt (xv*xv + yv*yv); // and its distance
|
||||
|
||||
// estimate the geocentric rectangular coordinates here
|
||||
xh = r * (cos(N) * cos (v+w) - sin (N) * sin(v+w) * cos(i));
|
||||
yh = r * (sin(N) * cos (v+w) + cos (N) * sin(v+w) * cos(i));
|
||||
zh = r * (sin(v+w) * sin(i));
|
||||
|
||||
// calculate the ecliptic latitude and longitude here
|
||||
lonEcl = atan2 (yh, xh);
|
||||
latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
|
||||
|
||||
/* Calculate a number of perturbatioin, i.e. disturbances caused by the
|
||||
* gravitational infuence of the sun and the other major planets.
|
||||
* The largest of these even have a name */
|
||||
Ls = ourSun->getM() + ourSun->getw();
|
||||
Lm = M + w + N;
|
||||
D = Lm - Ls;
|
||||
F = Lm - N;
|
||||
|
||||
lonEcl += DEG_TO_RAD * (-1.274 * sin (M - 2*D)
|
||||
+0.658 * sin (2*D)
|
||||
-0.186 * sin(ourSun->getM())
|
||||
-0.059 * sin(2*M - 2*D)
|
||||
-0.057 * sin(M - 2*D + ourSun->getM())
|
||||
+0.053 * sin(M + 2*D)
|
||||
+0.046 * sin(2*D - ourSun->getM())
|
||||
+0.041 * sin(M - ourSun->getM())
|
||||
-0.035 * sin(D)
|
||||
-0.031 * sin(M + ourSun->getM())
|
||||
-0.015 * sin(2*F - 2*D)
|
||||
+0.011 * sin(M - 4*D)
|
||||
);
|
||||
latEcl += DEG_TO_RAD * (-0.173 * sin(F-2*D)
|
||||
-0.055 * sin(M - F - 2*D)
|
||||
-0.046 * sin(M + F - 2*D)
|
||||
+0.033 * sin(F + 2*D)
|
||||
+0.017 * sin(2*M + F)
|
||||
);
|
||||
r += (-0.58 * cos(M - 2*D)
|
||||
-0.46 * cos(2*D)
|
||||
);
|
||||
FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
|
||||
xg = r * cos(lonEcl) * cos(latEcl);
|
||||
yg = r * sin(lonEcl) * cos(latEcl);
|
||||
zg = r * sin(latEcl);
|
||||
|
||||
xe = xg;
|
||||
ye = yg * cos(ecl) -zg * sin(ecl);
|
||||
ze = yg * sin(ecl) +zg * cos(ecl);
|
||||
|
||||
geoRa = atan2(ye, xe);
|
||||
geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
|
||||
|
||||
// Given the moon's geocentric ra and dec, calculate its
|
||||
// topocentric ra and dec. i.e. the position as seen from the
|
||||
// surface of the earth, instead of the center of the earth
|
||||
|
||||
// First calculate the moon's parrallax, that is, the apparent size of the
|
||||
// (equatorial) radius of the earth, as seen from the moon
|
||||
mpar = asin ( 1 / r);
|
||||
gclat = f->get_Latitude() - 0.003358 *
|
||||
sin (2 * DEG_TO_RAD * f->get_Latitude() );
|
||||
rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * f->get_Latitude());
|
||||
if (geoRa < 0)
|
||||
geoRa += (2*FG_PI);
|
||||
|
||||
HA = t->lst - (3.8197186 * geoRa);
|
||||
g = atan (tan(gclat) / cos ((HA / 3.8197186)));
|
||||
rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
|
||||
declination = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* void Moon::newImage()
|
||||
*
|
||||
* This function regenerates a new visual image of the moon, which is added to
|
||||
* solarSystem display list.
|
||||
*
|
||||
* Arguments: Right Ascension and declination
|
||||
*
|
||||
* return value: none
|
||||
**************************************************************************/
|
||||
void Moon::newImage()
|
||||
{
|
||||
fgLIGHT *l = &cur_light_params;
|
||||
float moon_angle = l->moon_angle;
|
||||
|
||||
/*double x_2, x_4, x_8, x_10;
|
||||
GLfloat ambient;
|
||||
GLfloat amb[4];*/
|
||||
int moonSize = 750;
|
||||
|
||||
GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
|
||||
GLfloat black[4] = {0.0, 0.0,0.0,1.0};
|
||||
GLfloat white[4] = {1.0, 1.0,1.0,1.0};
|
||||
|
||||
if( moon_angle*RAD_TO_DEG < 100 )
|
||||
{
|
||||
/*
|
||||
x_2 = moon_angle * moon_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);
|
||||
xglColor3f(1.0, 1.0, 1.0); */
|
||||
xglPushMatrix();
|
||||
{
|
||||
//xglRotatef(-90, 0.0, 0.0, 1.0);
|
||||
xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
|
||||
xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
|
||||
|
||||
FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"Ra = (" << (RAD_TO_DEG *rightAscension)
|
||||
<< "), Dec= (" << (RAD_TO_DEG *declination) << ")" );
|
||||
xglTranslatef(0.0, 58600.0, 0.0);
|
||||
|
||||
glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
|
||||
glEnable(GL_BLEND); // BLEND ENABLED
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBindTexture(GL_TEXTURE_2D, moon_halotexid);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
|
||||
glEnd();
|
||||
|
||||
xglEnable(GL_LIGHTING); // LIGHTING ENABLED
|
||||
xglEnable( GL_LIGHT0 );
|
||||
// set lighting parameters
|
||||
xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
|
||||
xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
|
||||
xglEnable( GL_CULL_FACE );
|
||||
xglMaterialfv(GL_FRONT, GL_AMBIENT, black);
|
||||
xglMaterialfv(GL_FRONT, GL_DIFFUSE, moonColor);
|
||||
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
|
||||
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBindTexture(GL_TEXTURE_2D, moon_texid);
|
||||
//glDisable(GL_LIGHTING); // LIGHTING DISABLED
|
||||
|
||||
gluQuadricTexture(moonObject, GL_TRUE );
|
||||
gluSphere(moonObject, moonSize, 12, 12 );
|
||||
glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
|
||||
glDisable(GL_BLEND); // BLEND DISABLED
|
||||
}
|
||||
xglPopMatrix();
|
||||
glDisable(GL_LIGHTING); // LIGHTING DISABLED
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
57
Simulator/Astro/moon.hxx
Normal file
57
Simulator/Astro/moon.hxx
Normal file
|
@ -0,0 +1,57 @@
|
|||
/**************************************************************************
|
||||
* moon.hxx
|
||||
* Written by Durk Talsma. Originally started October 1997, for distribution
|
||||
* with the FlightGear project. Version 2 was written in August and
|
||||
* September 1998. This code is based upon algorithms and data kindly
|
||||
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _MOON_HXX_
|
||||
#define _MOON_HXX_
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Main/views.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Moon : public CelestialBody
|
||||
{
|
||||
private:
|
||||
void TexInit(); // This should move to the constructor eventually.
|
||||
|
||||
GLUquadricObj *moonObject;
|
||||
GLuint Sphere;
|
||||
GLuint moon_texid;
|
||||
GLuint moon_halotexid;
|
||||
GLubyte *moon_texbuf;
|
||||
GLubyte *moon_halotexbuf;
|
||||
|
||||
void setHalo();
|
||||
public:
|
||||
Moon ( fgTIME *t);
|
||||
~Moon();
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
void newImage();
|
||||
};
|
||||
|
||||
|
||||
#endif // _MOON_HXX_
|
60
Simulator/Astro/neptune.cxx
Normal file
60
Simulator/Astro/neptune.cxx
Normal file
|
@ -0,0 +1,60 @@
|
|||
/**************************************************************************
|
||||
* neptune.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "neptune.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Neptune::Neptune(fgTIME *t)
|
||||
* Public constructor for class Neptune
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Neptune are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Neptune::Neptune(fgTIME *t) :
|
||||
CelestialBody(131.7806, 3.0173000E-5,
|
||||
1.7700, -2.550E-7,
|
||||
272.8461, -6.027000E-6,
|
||||
30.058260, 3.313E-8,
|
||||
0.008606, 2.150E-9,
|
||||
260.2471, 0.00599514700, t)
|
||||
{
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Neptune::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Neptune, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Neptune specific equation
|
||||
*************************************************************************/
|
||||
void Neptune::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
|
||||
}
|
39
Simulator/Astro/neptune.hxx
Normal file
39
Simulator/Astro/neptune.hxx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
* neptune.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _NEPTUNE_HXX_
|
||||
#define _NEPTUNE_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Neptune : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Neptune ( fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _NEPTUNE_HXX_
|
37
Simulator/Astro/pluto.hxx
Normal file
37
Simulator/Astro/pluto.hxx
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**************************************************************************
|
||||
* pluto.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _PLUTO_HXX_
|
||||
#define _PLUTO_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
|
||||
class Pluto : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Pluto ( fgTIME t);
|
||||
};
|
||||
|
||||
#endif // _PLUTO_HXX_
|
70
Simulator/Astro/saturn.cxx
Normal file
70
Simulator/Astro/saturn.cxx
Normal file
|
@ -0,0 +1,70 @@
|
|||
/**************************************************************************
|
||||
* saturn.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "saturn.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Saturn::Saturn(fgTIME *t)
|
||||
* Public constructor for class Saturn
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Saturn are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Saturn::Saturn(fgTIME *t) :
|
||||
CelestialBody(113.6634, 2.3898000E-5,
|
||||
2.4886, -1.081E-7,
|
||||
339.3939, 2.9766100E-5,
|
||||
9.5547500, 0.000000,
|
||||
0.055546, -9.499E-9,
|
||||
316.9670, 0.03344422820, t)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Saturn::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Saturn, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Saturn specific equation
|
||||
*************************************************************************/
|
||||
void Saturn::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
|
||||
double actTime = fgCalcActTime(t);
|
||||
double ir = 0.4897394;
|
||||
double Nr = 2.9585076 + 6.6672E-7*actTime;
|
||||
double B = asin (sin(declination) * cos(ir) -
|
||||
cos(declination) * sin(ir) *
|
||||
sin(rightAscension - Nr));
|
||||
double ring_magn = -2.6 * sin(fabs(B)) + 1.2 * pow(sin(B), 2);
|
||||
magnitude = -9.0 + 5*log10(r*R) + 0.044 * FV + ring_magn;
|
||||
}
|
||||
|
46
Simulator/Astro/saturn.hxx
Normal file
46
Simulator/Astro/saturn.hxx
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**************************************************************************
|
||||
* saturn.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _SATURN_HXX_
|
||||
#define _SATURN_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Saturn : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Saturn ( fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _SATURN_HXX_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
516
Simulator/Astro/sky.cxx
Normal file
516
Simulator/Astro/sky.cxx
Normal file
|
@ -0,0 +1,516 @@
|
|||
// 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Main/views.hxx>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Time/event.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#include "sky.hxx"
|
||||
|
||||
|
||||
// in meters of course
|
||||
#define CENTER_ELEV 25000.0
|
||||
|
||||
#define INNER_RADIUS 50000.0
|
||||
#define INNER_ELEV 20000.0
|
||||
|
||||
#define MIDDLE_RADIUS 70000.0
|
||||
#define MIDDLE_ELEV 8000.0
|
||||
|
||||
#define OUTER_RADIUS 80000.0
|
||||
#define OUTER_ELEV 0.0
|
||||
|
||||
#define BOTTOM_RADIUS 50000.0
|
||||
#define BOTTOM_ELEV -2000.0
|
||||
|
||||
|
||||
static float inner_vertex[12][3];
|
||||
static float middle_vertex[12][3];
|
||||
static float outer_vertex[12][3];
|
||||
static float bottom_vertex[12][3];
|
||||
|
||||
static float inner_color[12][4];
|
||||
static float middle_color[12][4];
|
||||
static float outer_color[12][4];
|
||||
|
||||
|
||||
// Calculate the sky structure vertices
|
||||
void fgSkyVerticesInit( void ) {
|
||||
float theta;
|
||||
int i;
|
||||
|
||||
FG_LOG(FG_ASTRO, FG_INFO, " Generating the sky dome vertices.");
|
||||
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
theta = (i * 30.0) * DEG_TO_RAD;
|
||||
|
||||
inner_vertex[i][0] = cos(theta) * INNER_RADIUS;
|
||||
inner_vertex[i][1] = sin(theta) * INNER_RADIUS;
|
||||
inner_vertex[i][2] = INNER_ELEV;
|
||||
|
||||
// printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS,
|
||||
// sin(theta) * INNER_RADIUS);
|
||||
|
||||
middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
|
||||
middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
|
||||
middle_vertex[i][2] = MIDDLE_ELEV;
|
||||
|
||||
outer_vertex[i][0] = cos((double)theta) * OUTER_RADIUS;
|
||||
outer_vertex[i][1] = sin((double)theta) * OUTER_RADIUS;
|
||||
outer_vertex[i][2] = OUTER_ELEV;
|
||||
|
||||
bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
|
||||
bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
|
||||
bottom_vertex[i][2] = BOTTOM_ELEV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// (Re)calculate the sky colors at each vertex
|
||||
void fgSkyColorsInit( void ) {
|
||||
fgLIGHT *l;
|
||||
double sun_angle, diff;
|
||||
double outer_param[3], outer_amt[3], outer_diff[3];
|
||||
double middle_param[3], middle_amt[3], middle_diff[3];
|
||||
int i, j;
|
||||
|
||||
l = &cur_light_params;
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO,
|
||||
" Generating the sky colors for each vertex." );
|
||||
|
||||
// setup for the possibility of sunset effects
|
||||
sun_angle = l->sun_angle * RAD_TO_DEG;
|
||||
// fgPrintf( FG_ASTRO, FG_INFO,
|
||||
// " Sun angle in degrees = %.2f\n", sun_angle);
|
||||
|
||||
if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
|
||||
// 0.0 - 0.4
|
||||
outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
|
||||
outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
|
||||
outer_param[2] = -(10.0 - fabs(90.0 - sun_angle)) / 30.0;
|
||||
// outer_param[2] = 0.0;
|
||||
|
||||
middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
|
||||
middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 80.0;
|
||||
middle_param[2] = 0.0;
|
||||
|
||||
outer_diff[0] = outer_param[0] / 6.0;
|
||||
outer_diff[1] = outer_param[1] / 6.0;
|
||||
outer_diff[2] = outer_param[2] / 6.0;
|
||||
|
||||
middle_diff[0] = middle_param[0] / 6.0;
|
||||
middle_diff[1] = middle_param[1] / 6.0;
|
||||
middle_diff[2] = middle_param[2] / 6.0;
|
||||
} else {
|
||||
outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
|
||||
middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
|
||||
|
||||
outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
|
||||
middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
|
||||
}
|
||||
// printf(" outer_red_param = %.2f outer_red_diff = %.2f\n",
|
||||
// outer_red_param, outer_red_diff);
|
||||
|
||||
// calculate transition colors between sky and fog
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] = outer_param[j];
|
||||
middle_amt[j] = middle_param[j];
|
||||
}
|
||||
|
||||
for ( i = 0; i < 6; i++ ) {
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
diff = l->sky_color[j] - l->fog_color[j];
|
||||
|
||||
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
|
||||
// l->sky_color[j], l->fog_color[j], diff);
|
||||
|
||||
inner_color[i][j] = l->sky_color[j] - diff * 0.3;
|
||||
middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
|
||||
outer_color[i][j] = l->fog_color[j] + outer_amt[j];
|
||||
|
||||
if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
|
||||
if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
|
||||
if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
|
||||
if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
|
||||
if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
|
||||
if ( outer_color[i][j] < 0.10 ) { outer_color[i][j] = 0.10; }
|
||||
}
|
||||
inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
|
||||
l->sky_color[3];
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] -= outer_diff[j];
|
||||
middle_amt[j] -= middle_diff[j];
|
||||
}
|
||||
|
||||
/*
|
||||
printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
|
||||
inner_color[i][1], inner_color[i][2], inner_color[i][3]);
|
||||
printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
middle_color[i][0], middle_color[i][1], middle_color[i][2],
|
||||
middle_color[i][3]);
|
||||
printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
outer_color[i][0], outer_color[i][1], outer_color[i][2],
|
||||
outer_color[i][3]);
|
||||
*/
|
||||
}
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] = 0.0;
|
||||
middle_amt[j] = 0.0;
|
||||
}
|
||||
|
||||
for ( i = 6; i < 12; i++ ) {
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
diff = l->sky_color[j] - l->fog_color[j];
|
||||
|
||||
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
|
||||
// l->sky_color[j], l->fog_color[j], diff);
|
||||
|
||||
inner_color[i][j] = l->sky_color[j] - diff * 0.3;
|
||||
middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
|
||||
outer_color[i][j] = l->fog_color[j] + outer_amt[j];
|
||||
|
||||
if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
|
||||
if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
|
||||
if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
|
||||
if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
|
||||
if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
|
||||
if ( outer_color[i][j] < 0.15 ) { outer_color[i][j] = 0.15; }
|
||||
}
|
||||
inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
|
||||
l->sky_color[3];
|
||||
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
outer_amt[j] += outer_diff[j];
|
||||
middle_amt[j] += middle_diff[j];
|
||||
}
|
||||
|
||||
/*
|
||||
printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
|
||||
inner_color[i][1], inner_color[i][2], inner_color[i][3]);
|
||||
printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
middle_color[i][0], middle_color[i][1], middle_color[i][2],
|
||||
middle_color[i][3]);
|
||||
printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
outer_color[i][0], outer_color[i][1], outer_color[i][2],
|
||||
outer_color[i][3]);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialize the sky structure and colors
|
||||
void fgSkyInit( void ) {
|
||||
FG_LOG( FG_ASTRO, FG_INFO, "Initializing the sky" );
|
||||
|
||||
fgSkyVerticesInit();
|
||||
|
||||
// regester fgSkyColorsInit() as an event to be run periodically
|
||||
global_events.Register( "fgSkyColorsInit()", fgSkyColorsInit,
|
||||
fgEVENT::FG_EVENT_READY, 30000);
|
||||
}
|
||||
|
||||
|
||||
// Draw the Sky
|
||||
void fgSkyRender( void ) {
|
||||
FGInterface *f;
|
||||
fgLIGHT *l;
|
||||
float inner_color[4];
|
||||
float middle_color[4];
|
||||
float outer_color[4];
|
||||
double diff;
|
||||
int i;
|
||||
|
||||
f = current_aircraft.fdm_state;
|
||||
l = &cur_light_params;
|
||||
|
||||
// printf("Rendering the sky.\n");
|
||||
|
||||
// calculate the proper colors
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
diff = l->sky_color[i] - l->adj_fog_color[i];
|
||||
|
||||
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
|
||||
// l->sky_color[j], l->adj_fog_color[j], diff);
|
||||
|
||||
inner_color[i] = l->sky_color[i] - diff * 0.3;
|
||||
middle_color[i] = l->sky_color[i] - diff * 0.9;
|
||||
outer_color[i] = l->adj_fog_color[i];
|
||||
}
|
||||
inner_color[3] = middle_color[3] = outer_color[3] = l->adj_fog_color[3];
|
||||
|
||||
xglPushMatrix();
|
||||
|
||||
// Translate to view position
|
||||
Point3D zero_elev = current_view.get_cur_zero_elev();
|
||||
xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
|
||||
// printf(" Translated to %.2f %.2f %.2f\n",
|
||||
// zero_elev.x, zero_elev.y, zero_elev.z );
|
||||
|
||||
// Rotate to proper orientation
|
||||
// printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
|
||||
// FG_Latitude * RAD_TO_DEG);
|
||||
xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 );
|
||||
xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
|
||||
xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 );
|
||||
|
||||
// Draw inner/center section of sky*/
|
||||
xglBegin( GL_TRIANGLE_FAN );
|
||||
xglColor4fv(l->sky_color);
|
||||
xglVertex3f(0.0, 0.0, CENTER_ELEV);
|
||||
for ( i = 11; i >= 0; i-- ) {
|
||||
xglColor4fv( inner_color );
|
||||
xglVertex3fv( inner_vertex[i] );
|
||||
}
|
||||
xglColor4fv( inner_color );
|
||||
xglVertex3fv( inner_vertex[11] );
|
||||
xglEnd();
|
||||
|
||||
// Draw the middle ring
|
||||
xglBegin( GL_TRIANGLE_STRIP );
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
xglColor4fv( middle_color );
|
||||
// printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
// middle_color[i][0], middle_color[i][1], middle_color[i][2],
|
||||
// middle_color[i][3]);
|
||||
// xglColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
xglVertex3fv( middle_vertex[i] );
|
||||
xglColor4fv( inner_color );
|
||||
// printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i,
|
||||
// inner_color[i][0], inner_color[i][1], inner_color[i][2],
|
||||
// inner_color[i][3]);
|
||||
// xglColor4f(0.0, 0.0, 1.0, 1.0);
|
||||
xglVertex3fv( inner_vertex[i] );
|
||||
}
|
||||
xglColor4fv( middle_color );
|
||||
// xglColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
xglVertex3fv( middle_vertex[0] );
|
||||
xglColor4fv( inner_color );
|
||||
// xglColor4f(0.0, 0.0, 1.0, 1.0);
|
||||
xglVertex3fv( inner_vertex[0] );
|
||||
xglEnd();
|
||||
|
||||
// Draw the outer ring
|
||||
xglBegin( GL_TRIANGLE_STRIP );
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
xglColor4fv( outer_color );
|
||||
xglVertex3fv( outer_vertex[i] );
|
||||
xglColor4fv( middle_color );
|
||||
xglVertex3fv( middle_vertex[i] );
|
||||
}
|
||||
xglColor4fv( outer_color );
|
||||
xglVertex3fv( outer_vertex[0] );
|
||||
xglColor4fv( middle_color );
|
||||
xglVertex3fv( middle_vertex[0] );
|
||||
xglEnd();
|
||||
|
||||
// Draw the bottom skirt
|
||||
xglBegin( GL_TRIANGLE_STRIP );
|
||||
xglColor4fv( outer_color );
|
||||
for ( i = 0; i < 12; i++ ) {
|
||||
xglVertex3fv( bottom_vertex[i] );
|
||||
xglVertex3fv( outer_vertex[i] );
|
||||
}
|
||||
xglVertex3fv( bottom_vertex[0] );
|
||||
xglVertex3fv( outer_vertex[0] );
|
||||
xglEnd();
|
||||
|
||||
xglPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.21 1999/02/05 21:28:50 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.20 1999/02/02 20:13:29 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.19 1999/02/01 21:33:26 curt
|
||||
// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
|
||||
// Jon accepted my offer to do this and thought it was a good idea.
|
||||
//
|
||||
// Revision 1.18 1999/02/01 21:09:00 curt
|
||||
// Bug fix in vertex order of inner disk (fan) of the sky dome.
|
||||
//
|
||||
// Revision 1.17 1998/12/09 18:50:12 curt
|
||||
// Converted "class fgVIEW" to "class FGView" and updated to make data
|
||||
// members private and make required accessor functions.
|
||||
//
|
||||
// Revision 1.16 1998/12/05 15:54:03 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.15 1998/12/03 01:15:36 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
// Tweaks for Sun portability.
|
||||
//
|
||||
// Revision 1.14 1998/11/06 21:17:39 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUG flag.
|
||||
//
|
||||
// Revision 1.13 1998/10/20 18:28:30 curt
|
||||
// Tweaked sunset/sunrise colors.
|
||||
//
|
||||
// Revision 1.12 1998/10/16 23:27:18 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.11 1998/10/16 00:52:19 curt
|
||||
// Converted to Point3D class.
|
||||
//
|
||||
// Revision 1.10 1998/08/29 13:07:16 curt
|
||||
// Rewrite of event manager thanks to Bernie Bright.
|
||||
//
|
||||
// Revision 1.9 1998/08/22 01:18:59 curt
|
||||
// Minor tweaks to avoid using unitialized memory.
|
||||
//
|
||||
// Revision 1.8 1998/08/12 21:40:44 curt
|
||||
// Sky now tracks adjusted fog color so it blends well with terrain.
|
||||
//
|
||||
// Revision 1.7 1998/07/22 21:39:21 curt
|
||||
// Lower skirt tracks adjusted fog color, not fog color.
|
||||
//
|
||||
// Revision 1.6 1998/05/23 14:07:14 curt
|
||||
// Use new C++ events class.
|
||||
//
|
||||
// Revision 1.5 1998/04/28 01:19:02 curt
|
||||
// Type-ified fgTIME and fgVIEW
|
||||
//
|
||||
// Revision 1.4 1998/04/26 05:10:01 curt
|
||||
// "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
|
||||
//
|
||||
// Revision 1.3 1998/04/25 22:06:25 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.2 1998/04/24 00:45:03 curt
|
||||
// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
// Fixed a bug when generating sky colors.
|
||||
//
|
||||
// Revision 1.1 1998/04/22 13:21:32 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.9 1998/04/03 21:52:50 curt
|
||||
// Converting to Gnu autoconf system.
|
||||
//
|
||||
// Revision 1.8 1998/03/09 22:47:25 curt
|
||||
// Incorporated Durk's updates.
|
||||
//
|
||||
// Revision 1.7 1998/02/19 13:05:49 curt
|
||||
// Incorporated some HUD tweaks from Michelle America.
|
||||
// Tweaked the sky's sunset/rise colors.
|
||||
// Other misc. tweaks.
|
||||
//
|
||||
// Revision 1.6 1998/02/07 15:29:32 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.5 1998/01/27 00:47:48 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.4 1998/01/26 15:54:28 curt
|
||||
// Added a "skirt" to try to help hide gaps between scenery and sky. This will
|
||||
// have to be revisited in the future.
|
||||
//
|
||||
// Revision 1.3 1998/01/19 19:26:59 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.2 1998/01/19 18:40:17 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.1 1998/01/07 03:16:19 curt
|
||||
// Moved from .../Src/Scenery/ to .../Src/Astro/
|
||||
//
|
||||
// Revision 1.11 1997/12/30 22:22:38 curt
|
||||
// Further integration of event manager.
|
||||
//
|
||||
// Revision 1.10 1997/12/30 20:47:53 curt
|
||||
// Integrated new event manager with subsystem initializations.
|
||||
//
|
||||
// Revision 1.9 1997/12/30 13:06:57 curt
|
||||
// A couple lighting tweaks ...
|
||||
//
|
||||
// Revision 1.8 1997/12/23 04:58:38 curt
|
||||
// Tweaked the sky coloring a bit to build in structures to allow finer rgb
|
||||
// control.
|
||||
//
|
||||
// Revision 1.7 1997/12/22 23:45:48 curt
|
||||
// First stab at sunset/sunrise sky glow effects.
|
||||
//
|
||||
// Revision 1.6 1997/12/22 04:14:34 curt
|
||||
// Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
|
||||
//
|
||||
// Revision 1.5 1997/12/19 23:34:59 curt
|
||||
// Lot's of tweaking with sky rendering and lighting.
|
||||
//
|
||||
// Revision 1.4 1997/12/19 16:45:02 curt
|
||||
// Working on scene rendering order and options.
|
||||
//
|
||||
// Revision 1.3 1997/12/18 23:32:36 curt
|
||||
// First stab at sky dome actually starting to look reasonable. :-)
|
||||
//
|
||||
// Revision 1.2 1997/12/18 04:07:03 curt
|
||||
// Worked on properly translating and positioning the sky dome.
|
||||
//
|
||||
// Revision 1.1 1997/12/17 23:14:30 curt
|
||||
// Initial revision.
|
||||
// Begin work on rendering the sky. (Rather than just using a clear screen.)
|
||||
//
|
||||
|
73
Simulator/Astro/sky.hxx
Normal file
73
Simulator/Astro/sky.hxx
Normal file
|
@ -0,0 +1,73 @@
|
|||
// sky.hxx -- 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#ifndef _SKY_HXX
|
||||
#define _SKY_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
// (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
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.2 1998/10/16 23:27:19 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.1 1998/04/22 13:21:33 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.4 1998/04/21 17:02:32 curt
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.3 1998/01/22 02:59:28 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.2 1998/01/19 18:40:17 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.1 1998/01/07 03:16:19 curt
|
||||
// Moved from .../Src/Scenery/ to .../Src/Astro/
|
||||
//
|
||||
// Revision 1.2 1997/12/22 23:45:49 curt
|
||||
// First stab at sunset/sunrise sky glow effects.
|
||||
//
|
||||
// Revision 1.1 1997/12/17 23:14:31 curt
|
||||
// Initial revision.
|
||||
// Begin work on rendering the sky. (Rather than just using a clear screen.)
|
||||
//
|
219
Simulator/Astro/solarsystem.cxx
Normal file
219
Simulator/Astro/solarsystem.cxx
Normal file
|
@ -0,0 +1,219 @@
|
|||
/**************************************************************************
|
||||
* 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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Time/sunpos.hxx>
|
||||
#include <Time/moonpos.hxx>
|
||||
#include "solarsystem.hxx"
|
||||
|
||||
/***************************************************************************
|
||||
* default constructor for class SolarSystem:
|
||||
* or course there can only be one way to create an entire solar system -:) )
|
||||
* the fgTIME argument is needed to properly initialize the the current orbital
|
||||
* elements
|
||||
*************************************************************************/
|
||||
SolarSystem::SolarSystem(fgTIME *t)
|
||||
{
|
||||
if (theSolarSystem)
|
||||
{
|
||||
FG_LOG( FG_GENERAL, FG_ALERT, "Error: only one solarsystem allowed" );
|
||||
exit(-1);
|
||||
}
|
||||
theSolarSystem = this;
|
||||
ourSun = new Star(t);
|
||||
earthsMoon = new Moon(t);
|
||||
mercury = new Mercury(t);
|
||||
venus = new Venus(t);
|
||||
mars = new Mars(t);
|
||||
jupiter = new Jupiter(t);
|
||||
saturn = new Saturn(t);
|
||||
uranus = new Uranus(t);
|
||||
neptune = new Neptune(t);
|
||||
|
||||
displayList = 0;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
* the destructor for class SolarSystem;
|
||||
**************************************************************************/
|
||||
SolarSystem::~SolarSystem()
|
||||
{
|
||||
delete ourSun;
|
||||
delete earthsMoon;
|
||||
delete mercury;
|
||||
delete venus;
|
||||
delete mars;
|
||||
delete jupiter;
|
||||
delete saturn;
|
||||
delete uranus;
|
||||
delete neptune;
|
||||
}
|
||||
/****************************************************************************
|
||||
* void SolarSystem::rebuild()
|
||||
*
|
||||
* this member function updates the positions for the sun, moon, and planets,
|
||||
* and then rebuilds the display list.
|
||||
*
|
||||
* arguments: none
|
||||
* return value: none
|
||||
***************************************************************************/
|
||||
void SolarSystem::rebuild()
|
||||
{
|
||||
//fgLIGHT *l = &cur_light_params;
|
||||
fgTIME *t = &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);
|
||||
|
||||
// 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...
|
||||
|
||||
earthsMoon->newImage();
|
||||
// Step 2b: Add the sun
|
||||
//xglPushMatrix();
|
||||
//{
|
||||
ourSun->newImage();
|
||||
//}
|
||||
//xglPopMatrix();
|
||||
// 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();
|
||||
}
|
92
Simulator/Astro/solarsystem.hxx
Normal file
92
Simulator/Astro/solarsystem.hxx
Normal file
|
@ -0,0 +1,92 @@
|
|||
/**************************************************************************
|
||||
* 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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#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_
|
272
Simulator/Astro/star.cxx
Normal file
272
Simulator/Astro/star.cxx
Normal file
|
@ -0,0 +1,272 @@
|
|||
/**************************************************************************
|
||||
* star.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <Time/sunpos.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Time/light.hxx>
|
||||
#include "star.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Star::Star(fgTIME *t)
|
||||
* Public constructor for class Star
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements our sun are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
* note that the word sun is avoided, in order to prevent some compilation
|
||||
* problems on sun systems
|
||||
************************************************************************/
|
||||
Star::Star(fgTIME *t) :
|
||||
CelestialBody (0.000000, 0.0000000000,
|
||||
0.0000, 0.00000,
|
||||
282.9404, 4.7093500E-5,
|
||||
1.0000000, 0.000000,
|
||||
0.016709, -1.151E-9,
|
||||
356.0470, 0.98560025850, t)
|
||||
{
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
{
|
||||
//delete SunObject;
|
||||
delete [] sun_texbuf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int texWidth = 256; /* 64x64 is plenty */
|
||||
|
||||
void Star::setTexture()
|
||||
{
|
||||
int texSize;
|
||||
//void *textureBuf;
|
||||
GLubyte *p;
|
||||
int i,j;
|
||||
double radius;
|
||||
|
||||
texSize = texWidth*texWidth;
|
||||
|
||||
sun_texbuf = new GLubyte[texSize*4];
|
||||
if (!sun_texbuf)
|
||||
return; // Ugly!
|
||||
|
||||
p = sun_texbuf;
|
||||
|
||||
radius = (double)(texWidth / 2);
|
||||
|
||||
for (i=0; i < texWidth; i++) {
|
||||
for (j=0; j < texWidth; j++) {
|
||||
double x, y, d;
|
||||
|
||||
x = fabs((double)(i - (texWidth / 2)));
|
||||
y = fabs((double)(j - (texWidth / 2)));
|
||||
|
||||
d = sqrt((x * x) + (y * y));
|
||||
if (d < radius)
|
||||
{
|
||||
double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
|
||||
// inverse square looks nice
|
||||
*p = (int)((double)0xff * (t * t));
|
||||
*(p+1) = (int)((double) 0xff * (t*t));
|
||||
*(p+2) = (int)((double) 0xff * (t*t));
|
||||
*(p+3) = (int)((double) 0xff * (t*t));
|
||||
}
|
||||
else
|
||||
{
|
||||
*p = 0x00;
|
||||
*(p+1) = 0x00;
|
||||
*(p+2) = 0x00;
|
||||
*(p+3) = 0x00;
|
||||
}
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
|
||||
// GL_LUMINANCE,
|
||||
// GL_UNSIGNED_BYTE, textureBuf);
|
||||
//free(textureBuf);
|
||||
}
|
||||
/*************************************************************************
|
||||
* void Jupiter::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of our sun.
|
||||
*************************************************************************/
|
||||
void Star::updatePosition(fgTIME *t)
|
||||
{
|
||||
double
|
||||
actTime, eccAnom,
|
||||
xv, yv, v, r,
|
||||
xe, ye, ze, ecl;
|
||||
|
||||
updateOrbElements(t);
|
||||
|
||||
actTime = fgCalcActTime(t);
|
||||
ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle in Radians
|
||||
eccAnom = fgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
|
||||
|
||||
xv = cos(eccAnom) - e;
|
||||
yv = sqrt (1.0 - e*e) * sin(eccAnom);
|
||||
v = atan2 (yv, xv); // the sun's true anomaly
|
||||
distance = r = sqrt (xv*xv + yv*yv); // and its distance
|
||||
|
||||
lonEcl = v + w; // the sun's true longitude
|
||||
latEcl = 0;
|
||||
|
||||
// convert the sun's true longitude to ecliptic rectangular
|
||||
// geocentric coordinates (xs, ys)
|
||||
xs = r * cos (lonEcl);
|
||||
ys = r * sin (lonEcl);
|
||||
|
||||
// convert ecliptic coordinates to equatorial rectangular
|
||||
// geocentric coordinates
|
||||
|
||||
xe = xs;
|
||||
ye = ys * cos (ecl);
|
||||
ze = ys * sin (ecl);
|
||||
|
||||
// And finally, calculate right ascension and declination
|
||||
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 = 750;
|
||||
|
||||
// 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);
|
||||
|
||||
glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
|
||||
glEnable(GL_BLEND); // BLEND ENABLED
|
||||
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
//glEnable(GL_BLEND);
|
||||
//glDisable(GL_LIGHTING);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBindTexture(GL_TEXTURE_2D, sun_texid);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
|
||||
glEnd();
|
||||
}
|
||||
glPopMatrix();
|
||||
xglDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
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,58600,0);
|
||||
gluSphere( SunObject, sun_size, 10, 10 );
|
||||
}
|
||||
glPopMatrix();
|
||||
glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
|
||||
glDisable(GL_BLEND); // BLEND DISABLED
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
99
Simulator/Astro/star.hxx
Normal file
99
Simulator/Astro/star.hxx
Normal file
|
@ -0,0 +1,99 @@
|
|||
/**************************************************************************
|
||||
* star.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#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();
|
||||
public:
|
||||
Star (fgTIME *t);
|
||||
~Star();
|
||||
void updatePosition(fgTIME *t);
|
||||
double getM();
|
||||
double getw();
|
||||
//double getLon();
|
||||
double getxs();
|
||||
double getys();
|
||||
double getDistance();
|
||||
void newImage();
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline double Star::getM()
|
||||
{
|
||||
return M;
|
||||
}
|
||||
|
||||
inline double Star::getw()
|
||||
{
|
||||
return w;
|
||||
}
|
||||
|
||||
inline double Star::getxs()
|
||||
{
|
||||
return xs;
|
||||
}
|
||||
|
||||
inline double Star::getys()
|
||||
{
|
||||
return ys;
|
||||
}
|
||||
|
||||
inline double Star::getDistance()
|
||||
{
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
||||
#endif // _STAR_HXX_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
545
Simulator/Astro/stars.cxx
Normal file
545
Simulator/Astro/stars.cxx
Normal file
|
@ -0,0 +1,545 @@
|
|||
// stars.cxx -- data structures and routines for managing and rendering stars.
|
||||
//
|
||||
// Written by Curtis Olson, started August 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
// (Log is kept at end of this file)
|
||||
//*************************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "Include/compiler.h"
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <cmath>
|
||||
# include <cstdio>
|
||||
# include <cstring>
|
||||
# include <ctime>
|
||||
#else
|
||||
# include <math.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Misc/fgstream.hxx>
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/views.hxx>
|
||||
#include <Misc/stopwatch.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "Misc/stopwatch.hxx"
|
||||
|
||||
#include "stars.hxx"
|
||||
|
||||
FG_USING_STD(getline);
|
||||
|
||||
#define EpochStart (631065600)
|
||||
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
||||
#define FG_MAX_STARS 3500
|
||||
|
||||
// Define four structures, each with varying amounts of stars
|
||||
static GLint stars[FG_STAR_LEVELS];
|
||||
|
||||
|
||||
// Initialize the Star Management Subsystem
|
||||
int fgStarsInit( void ) {
|
||||
Point3D starlist[FG_MAX_STARS];
|
||||
// struct CelestialCoord pltPos;
|
||||
double right_ascension, declination, magnitude;
|
||||
double min_magnitude[FG_STAR_LEVELS];
|
||||
// double ra_save, decl_save;
|
||||
// double ra_save1, decl_save1;
|
||||
int i, j, starcount, count;
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO, "Initializing stars" );
|
||||
|
||||
if ( FG_STAR_LEVELS < 4 ) {
|
||||
FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// build the full path name to the stars data base file
|
||||
string path = current_options.get_fg_root() + "/Astro/stars" + ".gz";
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << path );
|
||||
|
||||
fg_gzifstream in( path );
|
||||
if ( ! in ) {
|
||||
FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: " << path );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
starcount = 0;
|
||||
|
||||
StopWatch timer;
|
||||
timer.start();
|
||||
|
||||
// read in each line of the file
|
||||
while ( ! in.eof() && starcount < FG_MAX_STARS )
|
||||
{
|
||||
in >> skipcomment;
|
||||
string name;
|
||||
getline( in, name, ',' );
|
||||
in >> starlist[starcount];
|
||||
++starcount;
|
||||
}
|
||||
|
||||
timer.stop();
|
||||
FG_LOG( FG_ASTRO, FG_INFO,
|
||||
"Loaded " << starcount << " stars in "
|
||||
<< timer.elapsedSeconds() << " seconds" );
|
||||
|
||||
min_magnitude[0] = 4.2;
|
||||
min_magnitude[1] = 3.6;
|
||||
min_magnitude[2] = 3.0;
|
||||
min_magnitude[3] = 2.4;
|
||||
min_magnitude[4] = 1.8;
|
||||
min_magnitude[5] = 1.2;
|
||||
min_magnitude[6] = 0.6;
|
||||
min_magnitude[7] = 0.0;
|
||||
|
||||
// build the various star display lists
|
||||
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
||||
|
||||
stars[i] = xglGenLists(1);
|
||||
xglNewList( stars[i], GL_COMPILE );
|
||||
xglBegin( GL_POINTS );
|
||||
|
||||
count = 0;
|
||||
|
||||
for ( j = 0; j < starcount; j++ ) {
|
||||
magnitude = starlist[j].z();
|
||||
// printf("magnitude = %.2f\n", magnitude);
|
||||
|
||||
if ( magnitude < min_magnitude[i] ) {
|
||||
right_ascension = starlist[j].x();
|
||||
declination = starlist[j].y();
|
||||
|
||||
count++;
|
||||
|
||||
// scale magnitudes to (0.0 - 1.0)
|
||||
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
||||
|
||||
// scale magnitudes again so they look ok
|
||||
if ( magnitude > 1.0 ) { magnitude = 1.0; }
|
||||
if ( magnitude < 0.0 ) { magnitude = 0.0; }
|
||||
// magnitude =
|
||||
// magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.042);
|
||||
|
||||
magnitude = magnitude * 0.9 +
|
||||
(((FG_STAR_LEVELS - 1) - i) * 0.014);
|
||||
// printf(" Found star: %d %s, %.3f %.3f %.3f\n", count,
|
||||
// name, right_ascension, declination, magnitude);
|
||||
|
||||
xglColor3f( magnitude, magnitude, magnitude );
|
||||
//xglColor3f(0,0,0);*/
|
||||
xglVertex3f( 50000.0*cos(right_ascension)*cos(declination),
|
||||
50000.0*sin(right_ascension)*cos(declination),
|
||||
50000.0*sin(declination) );
|
||||
}
|
||||
} // while
|
||||
|
||||
xglEnd();
|
||||
|
||||
/*
|
||||
xglBegin(GL_LINE_LOOP);
|
||||
xglColor3f(1.0, 0.0, 0.0);
|
||||
xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(decl_save-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
|
||||
50000.0 * sin(decl_save-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(decl_save+0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
|
||||
50000.0 * sin(decl_save+0.2) );
|
||||
xglEnd();
|
||||
*/
|
||||
|
||||
/*
|
||||
xglBegin(GL_LINE_LOOP);
|
||||
xglColor3f(0.0, 1.0, 0.0);
|
||||
xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(decl_save1-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
|
||||
50000.0 * sin(decl_save1-0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(decl_save1+0.2) );
|
||||
xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
|
||||
50000.0 * sin(decl_save1+0.2) );
|
||||
xglEnd();
|
||||
*/
|
||||
|
||||
xglEndList();
|
||||
|
||||
FG_LOG( FG_ASTRO, FG_INFO,
|
||||
" Loading " << count << " stars brighter than "
|
||||
<< min_magnitude[i] );
|
||||
}
|
||||
|
||||
return 1; // OK, we got here because initialization worked.
|
||||
}
|
||||
|
||||
|
||||
// Draw the Stars
|
||||
void fgStarsRender( void ) {
|
||||
FGInterface *f;
|
||||
fgLIGHT *l;
|
||||
fgTIME *t;
|
||||
int i;
|
||||
|
||||
f = current_aircraft.fdm_state;
|
||||
l = &cur_light_params;
|
||||
t = &cur_time_params;
|
||||
|
||||
// FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise
|
||||
|
||||
// t->sun_angle = 3.0; // to force stars to be drawn (for testing)
|
||||
|
||||
// render the stars
|
||||
if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
||||
// determine which star structure to draw
|
||||
if ( l->sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) {
|
||||
i = 0;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
|
||||
i = 1;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
|
||||
i = 2;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
|
||||
i = 3;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
|
||||
i = 4;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
|
||||
i = 5;
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
|
||||
i = 6;
|
||||
} else {
|
||||
i = 7;
|
||||
}
|
||||
|
||||
// printf("RENDERING STARS = %d (night)\n", i);
|
||||
|
||||
xglCallList(stars[i]);
|
||||
} else {
|
||||
// printf("not RENDERING STARS (day)\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.27 1999/02/05 21:28:52 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.26 1999/02/02 20:13:30 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.25 1998/12/09 18:50:15 curt
|
||||
// Converted "class fgVIEW" to "class FGView" and updated to make data
|
||||
// members private and make required accessor functions.
|
||||
//
|
||||
// Revision 1.24 1998/12/05 15:54:04 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.23 1998/11/23 21:48:28 curt
|
||||
// Borland portability tweaks.
|
||||
//
|
||||
// Revision 1.22 1998/11/07 19:07:07 curt
|
||||
// Enable release builds using the --without-logging option to the configure
|
||||
// script. Also a couple log message cleanups, plus some C to C++ comment
|
||||
// conversion.
|
||||
//
|
||||
// Revision 1.21 1998/11/06 21:17:42 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUG flag.
|
||||
//
|
||||
// Revision 1.20 1998/11/06 14:47:02 curt
|
||||
// Changes to track Bernie's updates to fgstream.
|
||||
//
|
||||
// Revision 1.19 1998/10/16 23:27:21 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.18 1998/10/16 00:52:20 curt
|
||||
// Converted to Point3D class.
|
||||
//
|
||||
// Revision 1.17 1998/09/24 15:36:19 curt
|
||||
// Converted to c++ style comments.
|
||||
//
|
||||
// Revision 1.16 1998/09/24 15:25:24 curt
|
||||
// Miscellaneous tweaks.
|
||||
//
|
||||
//
|
||||
// Revision 1.15 1998/09/17 18:25:12 curt
|
||||
// Fixed output message.
|
||||
//
|
||||
// Revision 1.14 1998/09/15 04:26:22 curt
|
||||
// New textured moon and rewritten/restructured Astro code contributed by Durk
|
||||
// Talsma.
|
||||
//
|
||||
// Revision 1.13 1998/09/01 19:03:04 curt
|
||||
// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
|
||||
// - The new classes in libmisc.tgz define a stream interface into zlib.
|
||||
// I've put these in a new directory, Lib/Misc. Feel free to rename it
|
||||
// to something more appropriate. However you'll have to change the
|
||||
// include directives in all the other files. Additionally you'll have
|
||||
// add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
|
||||
//
|
||||
// The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
|
||||
// test so I've included the required changes in config.tgz.
|
||||
//
|
||||
// There are a fair few changes to Simulator/Objects as I've moved
|
||||
// things around. Loading tiles is quicker but thats not where the delay
|
||||
// is. Tile loading takes a few tenths of a second per file on a P200
|
||||
// but it seems to be the post-processing that leads to a noticeable
|
||||
// blip in framerate. I suppose its time to start profiling to see where
|
||||
// the delays are.
|
||||
//
|
||||
// I've included a brief description of each archives contents.
|
||||
//
|
||||
// Lib/Misc/
|
||||
// zfstream.cxx
|
||||
// zfstream.hxx
|
||||
// C++ stream interface into zlib.
|
||||
// Taken from zlib-1.1.3/contrib/iostream/.
|
||||
// Minor mods for STL compatibility.
|
||||
// There's no copyright associated with these so I assume they're
|
||||
// covered by zlib's.
|
||||
//
|
||||
// fgstream.cxx
|
||||
// fgstream.hxx
|
||||
// FlightGear input stream using gz_ifstream. Tries to open the
|
||||
// given filename. If that fails then filename is examined and a
|
||||
// ".gz" suffix is removed or appended and that file is opened.
|
||||
//
|
||||
// stopwatch.hxx
|
||||
// A simple timer for benchmarking. Not used in production code.
|
||||
// Taken from the Blitz++ project. Covered by GPL.
|
||||
//
|
||||
// strutils.cxx
|
||||
// strutils.hxx
|
||||
// Some simple string manipulation routines.
|
||||
//
|
||||
// Simulator/Airports/
|
||||
// Load airports database using fgstream.
|
||||
// Changed fgAIRPORTS to use set<> instead of map<>.
|
||||
// Added bool fgAIRPORTS::search() as a neater way doing the lookup.
|
||||
// Returns true if found.
|
||||
//
|
||||
// Simulator/Astro/
|
||||
// Modified fgStarsInit() to load stars database using fgstream.
|
||||
//
|
||||
// Simulator/Objects/
|
||||
// Modified fgObjLoad() to use fgstream.
|
||||
// Modified fgMATERIAL_MGR::load_lib() to use fgstream.
|
||||
// Many changes to fgMATERIAL.
|
||||
// Some changes to fgFRAGMENT but I forget what!
|
||||
//
|
||||
// Revision 1.12 1998/08/27 17:02:01 curt
|
||||
// Contributions from Bernie Bright <bbright@c031.aone.net.au>
|
||||
// - use strings for fg_root and airport_id and added methods to return
|
||||
// them as strings,
|
||||
// - inlined all access methods,
|
||||
// - made the parsing functions private methods,
|
||||
// - deleted some unused functions.
|
||||
// - propogated some of these changes out a bit further.
|
||||
//
|
||||
// Revision 1.11 1998/08/25 20:53:29 curt
|
||||
// Shuffled $FG_ROOT file layout.
|
||||
//
|
||||
// Revision 1.10 1998/08/10 20:33:09 curt
|
||||
// Rewrote star loading and rendering to:
|
||||
// 1. significantly improve load speed
|
||||
// 2. transition from no stars to stars through eight stages.
|
||||
//
|
||||
// Revision 1.9 1998/08/06 12:45:20 curt
|
||||
// Modified to bring in stars in 8 increments based on magnitude, not number
|
||||
// of stars.
|
||||
//
|
||||
// Revision 1.8 1998/07/13 21:00:10 curt
|
||||
// Wrote access functions for current fgOPTIONS.
|
||||
//
|
||||
// Revision 1.7 1998/05/29 20:35:42 curt
|
||||
// Added zlib support for reading in compressed data files.
|
||||
//
|
||||
// Revision 1.6 1998/05/13 18:25:35 curt
|
||||
// Root path info moved to fgOPTIONS.
|
||||
//
|
||||
// Revision 1.5 1998/04/28 01:19:03 curt
|
||||
// Type-ified fgTIME and fgVIEW
|
||||
//
|
||||
// Revision 1.4 1998/04/26 05:10:02 curt
|
||||
// "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
|
||||
//
|
||||
// Revision 1.3 1998/04/25 22:06:26 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.2 1998/04/24 00:45:03 curt
|
||||
// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
// Fixed a bug when generating sky colors.
|
||||
//
|
||||
// Revision 1.1 1998/04/22 13:21:34 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.11 1998/04/18 04:13:58 curt
|
||||
// Moved fg_debug.c to it's own library.
|
||||
//
|
||||
// Revision 1.10 1998/04/03 21:52:51 curt
|
||||
// Converting to Gnu autoconf system.
|
||||
//
|
||||
// Revision 1.9 1998/03/14 00:27:12 curt
|
||||
// Updated fgGENERAL to a "type" of struct.
|
||||
//
|
||||
// Revision 1.8 1998/02/12 21:59:38 curt
|
||||
// Incorporated code changes contributed by Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.7 1998/02/09 15:07:48 curt
|
||||
// Minor tweaks.
|
||||
//
|
||||
// Revision 1.6 1998/02/02 20:53:23 curt
|
||||
// To version 0.29
|
||||
//
|
||||
// Revision 1.5 1998/01/27 18:35:53 curt
|
||||
// Minor tweaks.
|
||||
//
|
||||
// Revision 1.4 1998/01/27 00:47:49 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.3 1998/01/19 19:26:59 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.2 1998/01/19 18:40:18 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.1 1998/01/07 03:16:20 curt
|
||||
// Moved from .../Src/Scenery/ to .../Src/Astro/
|
||||
//
|
||||
// Revision 1.24 1997/12/30 22:22:39 curt
|
||||
// Further integration of event manager.
|
||||
//
|
||||
// Revision 1.23 1997/12/30 20:47:53 curt
|
||||
// Integrated new event manager with subsystem initializations.
|
||||
//
|
||||
// Revision 1.22 1997/12/30 16:36:53 curt
|
||||
// Merged in Durk's changes ...
|
||||
//
|
||||
// Revision 1.21 1997/12/19 23:35:00 curt
|
||||
// Lot's of tweaking with sky rendering and lighting.
|
||||
//
|
||||
// Revision 1.20 1997/12/15 23:55:03 curt
|
||||
// Add xgl wrappers for debugging.
|
||||
// Generate terrain normals on the fly.
|
||||
//
|
||||
// Revision 1.19 1997/12/12 19:53:00 curt
|
||||
// Working on lightling and material properties.
|
||||
//
|
||||
// Revision 1.18 1997/12/10 22:37:52 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.17 1997/12/09 04:25:33 curt
|
||||
// Working on adding a global lighting params structure.
|
||||
//
|
||||
// Revision 1.16 1997/11/25 19:25:38 curt
|
||||
// Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
//
|
||||
// Revision 1.15 1997/10/30 12:38:45 curt
|
||||
// Working on new scenery subsystem.
|
||||
//
|
||||
// Revision 1.14 1997/10/28 21:00:22 curt
|
||||
// Changing to new terrain format.
|
||||
//
|
||||
// Revision 1.13 1997/10/25 03:18:28 curt
|
||||
// Incorporated sun, moon, and planet position and rendering code contributed
|
||||
// by Durk Talsma.
|
||||
//
|
||||
// Revision 1.12 1997/09/23 00:29:43 curt
|
||||
// Tweaks to get things to compile with gcc-win32.
|
||||
//
|
||||
// Revision 1.11 1997/09/22 14:44:21 curt
|
||||
// Continuing to try to align stars correctly.
|
||||
//
|
||||
// Revision 1.10 1997/09/20 03:34:32 curt
|
||||
// Still trying to get those durned stars aligned properly.
|
||||
//
|
||||
// Revision 1.9 1997/09/18 16:20:09 curt
|
||||
// At dusk/dawn add/remove stars in stages.
|
||||
//
|
||||
// Revision 1.8 1997/09/16 22:14:52 curt
|
||||
// Tweaked time of day lighting equations. Don't draw stars during the day.
|
||||
//
|
||||
// Revision 1.7 1997/09/16 15:50:31 curt
|
||||
// Working on star alignment and time issues.
|
||||
//
|
||||
// Revision 1.6 1997/09/05 14:17:31 curt
|
||||
// More tweaking with stars.
|
||||
//
|
||||
// Revision 1.5 1997/09/05 01:35:59 curt
|
||||
// Working on getting stars right.
|
||||
//
|
||||
// Revision 1.4 1997/09/04 02:17:38 curt
|
||||
// Shufflin' stuff.
|
||||
//
|
||||
// Revision 1.3 1997/08/29 17:55:28 curt
|
||||
// Worked on properly aligning the stars.
|
||||
//
|
||||
// Revision 1.2 1997/08/27 21:32:30 curt
|
||||
// Restructured view calculation code. Added stars.
|
||||
//
|
||||
// Revision 1.1 1997/08/27 03:34:48 curt
|
||||
// Initial revision.
|
||||
|
||||
|
114
Simulator/Astro/stars.hxx
Normal file
114
Simulator/Astro/stars.hxx
Normal file
|
@ -0,0 +1,114 @@
|
|||
// stars.hxx -- data structures and routines for managing and rendering stars.
|
||||
//
|
||||
// Written by Curtis Olson, started August 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#ifndef _STARS_HXX
|
||||
#define _STARS_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#define FG_STAR_LEVELS 8 // how many star transitions
|
||||
|
||||
// Initialize the Star Management Subsystem
|
||||
int fgStarsInit( void );
|
||||
|
||||
// Draw the Stars
|
||||
void fgStarsRender( void );
|
||||
|
||||
// [no longer used?] extern struct OrbElements pltOrbElements[9];
|
||||
extern fgTIME cur_time_params;
|
||||
|
||||
|
||||
#endif // _STARS_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.8 1999/01/19 20:57:00 curt
|
||||
// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
|
||||
//
|
||||
// Revision 1.7 1998/09/24 15:36:20 curt
|
||||
// Converted to c++ style comments.
|
||||
//
|
||||
// Revision 1.6 1998/09/24 15:25:26 curt
|
||||
// Miscellaneous tweaks.
|
||||
//
|
||||
//
|
||||
// Revision 1.5 1998/09/17 18:25:13 curt
|
||||
// Fixed output message.
|
||||
//
|
||||
// Revision 1.4 1998/09/15 04:26:23 curt
|
||||
// New textured moon and rewritten/restructured Astro code contributed by Durk
|
||||
// Talsma.
|
||||
//
|
||||
// Revision 1.3 1998/08/06 12:45:20 curt
|
||||
// Modified to bring in stars in 8 increments based on magnitude, not number
|
||||
// of stars.
|
||||
//
|
||||
// Revision 1.2 1998/04/28 01:19:03 curt
|
||||
// Type-ified fgTIME and fgVIEW
|
||||
//
|
||||
// Revision 1.1 1998/04/22 13:21:35 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.5 1998/04/21 17:02:33 curt
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.4 1998/02/12 21:59:39 curt
|
||||
// Incorporated code changes contributed by Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.3 1998/01/22 02:59:28 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.2 1998/01/19 18:40:18 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.1 1998/01/07 03:16:20 curt
|
||||
// Moved from .../Src/Scenery/ to .../Src/Astro/
|
||||
//
|
||||
// Revision 1.6 1997/10/25 03:18:29 curt
|
||||
// Incorporated sun, moon, and planet position and rendering code contributed
|
||||
// by Durk Talsma.
|
||||
//
|
||||
// Revision 1.5 1997/09/18 16:20:09 curt
|
||||
// At dusk/dawn add/remove stars in stages.
|
||||
//
|
||||
// Revision 1.4 1997/09/05 01:36:00 curt
|
||||
// Working on getting stars right.
|
||||
//
|
||||
// Revision 1.3 1997/08/29 17:55:28 curt
|
||||
// Worked on properly aligning the stars.
|
||||
//
|
||||
// Revision 1.2 1997/08/27 21:32:30 curt
|
||||
// Restructured view calculation code. Added stars.
|
||||
//
|
||||
// Revision 1.1 1997/08/27 03:34:50 curt
|
||||
// Initial revision.
|
||||
//
|
||||
|
61
Simulator/Astro/uranus.cxx
Normal file
61
Simulator/Astro/uranus.cxx
Normal file
|
@ -0,0 +1,61 @@
|
|||
/**************************************************************************
|
||||
* uranus.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "uranus.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Uranus::Uranus(fgTIME *t)
|
||||
* Public constructor for class Uranus
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Uranus are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Uranus::Uranus(fgTIME *t) :
|
||||
CelestialBody(74.00050, 1.3978000E-5,
|
||||
0.7733, 1.900E-8,
|
||||
96.66120, 3.0565000E-5,
|
||||
19.181710, -1.55E-8,
|
||||
0.047318, 7.450E-9,
|
||||
142.5905, 0.01172580600, t)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Uranus::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Uranus, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Uranus specific equation
|
||||
*************************************************************************/
|
||||
void Uranus::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
|
||||
}
|
39
Simulator/Astro/uranus.hxx
Normal file
39
Simulator/Astro/uranus.hxx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
* uranus.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _URANUS_HXX_
|
||||
#define _URANUS_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Uranus : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Uranus ( fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _URANUS_HXX_
|
61
Simulator/Astro/venus.cxx
Normal file
61
Simulator/Astro/venus.cxx
Normal file
|
@ -0,0 +1,61 @@
|
|||
/**************************************************************************
|
||||
* venus.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# define exception c_exception
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "venus.hxx"
|
||||
|
||||
/*************************************************************************
|
||||
* Venus::Venus(fgTIME *t)
|
||||
* Public constructor for class Venus
|
||||
* Argument: The current time.
|
||||
* the hard coded orbital elements for Venus are passed to
|
||||
* CelestialBody::CelestialBody();
|
||||
************************************************************************/
|
||||
Venus::Venus(fgTIME *t) :
|
||||
CelestialBody(76.67990, 2.4659000E-5,
|
||||
3.3946, 2.75E-8,
|
||||
54.89100, 1.3837400E-5,
|
||||
0.7233300, 0.000000,
|
||||
0.006773, -1.302E-9,
|
||||
48.00520, 1.60213022440, t)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* void Venus::updatePosition(fgTIME *t, Star *ourSun)
|
||||
*
|
||||
* calculates the current position of Venus, by calling the base class,
|
||||
* CelestialBody::updatePosition(); The current magnitude is calculated using
|
||||
* a Venus specific equation
|
||||
*************************************************************************/
|
||||
void Venus::updatePosition(fgTIME *t, Star *ourSun)
|
||||
{
|
||||
CelestialBody::updatePosition(t, ourSun);
|
||||
magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
|
||||
}
|
39
Simulator/Astro/venus.hxx
Normal file
39
Simulator/Astro/venus.hxx
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
* venus.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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
#ifndef _VENUS_HXX_
|
||||
#define _VENUS_HXX_
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include "celestialBody.hxx"
|
||||
#include "star.hxx"
|
||||
|
||||
class Venus : public CelestialBody
|
||||
{
|
||||
public:
|
||||
Venus ( fgTIME *t);
|
||||
void updatePosition(fgTIME *t, Star *ourSun);
|
||||
};
|
||||
|
||||
#endif // _VENUS_HXX_
|
5
Simulator/Autopilot/Makefile.am
Normal file
5
Simulator/Autopilot/Makefile.am
Normal file
|
@ -0,0 +1,5 @@
|
|||
noinst_LIBRARIES = libAutopilot.a
|
||||
|
||||
libAutopilot_a_SOURCES = autopilot.cxx autopilot.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
590
Simulator/Autopilot/autopilot.cxx
Normal file
590
Simulator/Autopilot/autopilot.cxx
Normal file
|
@ -0,0 +1,590 @@
|
|||
// autopilot.cxx -- autopilot subsystem
|
||||
//
|
||||
// Written by Jeff Goeke-Smith, started April 1998.
|
||||
//
|
||||
// Copyright (C) 1998 Jeff Goeke-Smith, jgoeke@voyager.net
|
||||
//
|
||||
// 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 <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Scenery/scenery.hxx>
|
||||
|
||||
#include "autopilot.hxx"
|
||||
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Main/options.hxx>
|
||||
|
||||
|
||||
// The below routines were copied right from hud.c ( I hate reinventing
|
||||
// the wheel more than necessary)
|
||||
|
||||
// The following routines obtain information concerntin the aircraft's
|
||||
// current state and return it to calling instrument display routines.
|
||||
// They should eventually be member functions of the aircraft.
|
||||
//
|
||||
|
||||
|
||||
static double get_speed( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_V_equiv_kts() );
|
||||
}
|
||||
|
||||
static double get_aoa( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Gamma_vert_rad() * RAD_TO_DEG );
|
||||
}
|
||||
|
||||
static double fgAPget_roll( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG );
|
||||
}
|
||||
|
||||
static double get_pitch( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Theta() );
|
||||
}
|
||||
|
||||
double fgAPget_heading( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG );
|
||||
}
|
||||
|
||||
static double fgAPget_altitude( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
|
||||
}
|
||||
|
||||
static double fgAPget_climb( void )
|
||||
{
|
||||
// return in meters per minute
|
||||
return( current_aircraft.fdm_state->get_Climb_Rate() * FEET_TO_METER * 60 );
|
||||
}
|
||||
|
||||
static double get_sideslip( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Beta() );
|
||||
}
|
||||
|
||||
static double fgAPget_agl( void )
|
||||
{
|
||||
double agl;
|
||||
|
||||
agl = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
|
||||
- scenery.cur_elev;
|
||||
|
||||
return( agl );
|
||||
}
|
||||
|
||||
// End of copied section. ( thanks for the wheel :-)
|
||||
|
||||
// Local Prototype section
|
||||
|
||||
double LinearExtrapolate( double x,double x1, double y1, double x2, double y2);
|
||||
double NormalizeDegrees( double Input);
|
||||
|
||||
// End Local ProtoTypes
|
||||
|
||||
fgAPDataPtr APDataGlobal; // global variable holding the AP info
|
||||
// I want this gone. Data should be in aircraft structure
|
||||
|
||||
|
||||
bool fgAPHeadingEnabled( void )
|
||||
{
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
|
||||
// heading hold enabled?
|
||||
return APData->heading_hold;
|
||||
}
|
||||
|
||||
bool fgAPAltitudeEnabled( void )
|
||||
{
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
|
||||
// altitude hold or terrain follow enabled?
|
||||
return APData->altitude_hold || APData->terrain_follow ;
|
||||
}
|
||||
|
||||
bool fgAPAutoThrottleEnabled( void )
|
||||
{
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
|
||||
// autothrottle enabled?
|
||||
return APData->auto_throttle;
|
||||
}
|
||||
|
||||
void fgAPAltitudeAdjust( double inc )
|
||||
{
|
||||
// Remove at a later date
|
||||
fgAPDataPtr APData;
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
double target_alt, target_agl;
|
||||
|
||||
if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
|
||||
target_alt = APData->TargetAltitude * METER_TO_FEET;
|
||||
target_agl = APData->TargetAGL * METER_TO_FEET;
|
||||
} else {
|
||||
target_alt = APData->TargetAltitude;
|
||||
target_agl = APData->TargetAGL;
|
||||
}
|
||||
|
||||
target_alt = (int)(target_alt / inc) * inc + inc;
|
||||
target_agl = (int)(target_agl / inc) * inc + inc;
|
||||
|
||||
if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
|
||||
target_alt *= FEET_TO_METER;
|
||||
target_agl *= FEET_TO_METER;
|
||||
}
|
||||
|
||||
APData->TargetAltitude = target_alt;
|
||||
APData->TargetAGL = target_agl;
|
||||
}
|
||||
|
||||
void fgAPHeadingAdjust( double inc )
|
||||
{
|
||||
fgAPDataPtr APData;
|
||||
APData = APDataGlobal;
|
||||
|
||||
double target = (int)(APData->TargetHeading / inc) * inc + inc;
|
||||
|
||||
APData->TargetHeading = NormalizeDegrees(target);
|
||||
}
|
||||
|
||||
void fgAPAutoThrottleAdjust( double inc )
|
||||
{
|
||||
fgAPDataPtr APData;
|
||||
APData = APDataGlobal;
|
||||
|
||||
double target = (int)(APData->TargetSpeed / inc) * inc + inc;
|
||||
|
||||
APData->TargetSpeed = target;
|
||||
}
|
||||
|
||||
void fgAPInit( fgAIRCRAFT *current_aircraft )
|
||||
{
|
||||
fgAPDataPtr APData ;
|
||||
|
||||
FG_LOG( FG_AUTOPILOT, FG_INFO, "Init AutoPilot Subsystem" );
|
||||
|
||||
APData = (fgAPDataPtr)calloc(sizeof(fgAPData),1);
|
||||
|
||||
if (APData == NULL) {
|
||||
// I couldn't get the mem. Dying
|
||||
FG_LOG( FG_AUTOPILOT, FG_ALERT, "No ram for Autopilot. Dying.");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
APData->heading_hold = false ; // turn the heading hold off
|
||||
APData->altitude_hold = false ; // turn the altitude hold off
|
||||
|
||||
APData->TargetHeading = 0.0; // default direction, due north
|
||||
APData->TargetAltitude = 3000; // default altitude in meters
|
||||
APData->alt_error_accum = 0.0;
|
||||
|
||||
// These eventually need to be read from current_aircaft somehow.
|
||||
|
||||
#if 0
|
||||
// Original values
|
||||
// the maximum roll, in Deg
|
||||
APData->MaxRoll = 7;
|
||||
// the deg from heading to start rolling out at, in Deg
|
||||
APData->RollOut = 30;
|
||||
// how far can I move the aleron from center.
|
||||
APData->MaxAileron= .1;
|
||||
// Smoothing distance for alerion control
|
||||
APData->RollOutSmooth = 10;
|
||||
#endif
|
||||
|
||||
// the maximum roll, in Deg
|
||||
APData->MaxRoll = 20;
|
||||
|
||||
// the deg from heading to start rolling out at, in Deg
|
||||
APData->RollOut = 20;
|
||||
|
||||
// how far can I move the aleron from center.
|
||||
APData->MaxAileron= .2;
|
||||
|
||||
// Smoothing distance for alerion control
|
||||
APData->RollOutSmooth = 10;
|
||||
|
||||
//Remove at a later date
|
||||
APDataGlobal = APData;
|
||||
|
||||
};
|
||||
|
||||
int fgAPRun( void )
|
||||
{
|
||||
// Remove the following lines when the calling funcitons start
|
||||
// passing in the data pointer
|
||||
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
// heading hold enabled?
|
||||
if ( APData->heading_hold == true ) {
|
||||
double RelHeading;
|
||||
double TargetRoll;
|
||||
double RelRoll;
|
||||
double AileronSet;
|
||||
|
||||
RelHeading =
|
||||
NormalizeDegrees( APData->TargetHeading - fgAPget_heading());
|
||||
// figure out how far off we are from desired heading
|
||||
|
||||
// Now it is time to deterime how far we should be rolled.
|
||||
FG_LOG( FG_AUTOPILOT, FG_DEBUG, "RelHeading: " << RelHeading );
|
||||
|
||||
|
||||
// Check if we are further from heading than the roll out point
|
||||
if ( fabs(RelHeading) > APData->RollOut ) {
|
||||
// set Target Roll to Max in desired direction
|
||||
if (RelHeading < 0 ) {
|
||||
TargetRoll = 0-APData->MaxRoll;
|
||||
} else {
|
||||
TargetRoll = APData->MaxRoll;
|
||||
}
|
||||
} else {
|
||||
// We have to calculate the Target roll
|
||||
|
||||
// This calculation engine thinks that the Target roll
|
||||
// should be a line from (RollOut,MaxRoll) to (-RollOut,
|
||||
// -MaxRoll) I hope this works well. If I get ambitious
|
||||
// some day this might become a fancier curve or
|
||||
// something.
|
||||
|
||||
TargetRoll = LinearExtrapolate( RelHeading, -APData->RollOut,
|
||||
-APData->MaxRoll, APData->RollOut,
|
||||
APData->MaxRoll );
|
||||
}
|
||||
|
||||
// Target Roll has now been Found.
|
||||
|
||||
// Compare Target roll to Current Roll, Generate Rel Roll
|
||||
|
||||
FG_LOG( FG_COCKPIT, FG_BULK, "TargetRoll: " << TargetRoll );
|
||||
|
||||
RelRoll = NormalizeDegrees(TargetRoll - fgAPget_roll());
|
||||
|
||||
// Check if we are further from heading than the roll out smooth point
|
||||
if ( fabs(RelRoll) > APData->RollOutSmooth ) {
|
||||
// set Target Roll to Max in desired direction
|
||||
if (RelRoll < 0 ) {
|
||||
AileronSet = 0-APData->MaxAileron;
|
||||
} else {
|
||||
AileronSet = APData->MaxAileron;
|
||||
}
|
||||
} else {
|
||||
AileronSet = LinearExtrapolate( RelRoll, -APData->RollOutSmooth,
|
||||
-APData->MaxAileron,
|
||||
APData->RollOutSmooth,
|
||||
APData->MaxAileron );
|
||||
}
|
||||
|
||||
controls.set_aileron( AileronSet );
|
||||
controls.set_rudder( 0.0 );
|
||||
}
|
||||
|
||||
// altitude hold or terrain follow enabled?
|
||||
if ( APData->altitude_hold || APData->terrain_follow ) {
|
||||
double speed, max_climb, error;
|
||||
double prop_error, int_error;
|
||||
double prop_adj, int_adj, total_adj;
|
||||
|
||||
if ( APData->altitude_hold ) {
|
||||
// normal altitude hold
|
||||
APData->TargetClimbRate =
|
||||
(APData->TargetAltitude - fgAPget_altitude()) * 8.0;
|
||||
} else if ( APData->terrain_follow ) {
|
||||
// brain dead ground hugging with no look ahead
|
||||
APData->TargetClimbRate =
|
||||
( APData->TargetAGL - fgAPget_agl() ) * 16.0;
|
||||
} else {
|
||||
// just try to zero out rate of climb ...
|
||||
APData->TargetClimbRate = 0.0;
|
||||
}
|
||||
|
||||
speed = get_speed();
|
||||
|
||||
if ( speed < 90.0 ) {
|
||||
max_climb = 0.0;
|
||||
} else if ( speed < 100.0 ) {
|
||||
max_climb = (speed - 90.0) * 20;
|
||||
} else {
|
||||
max_climb = ( speed - 100.0 ) * 4.0 + 200.0;
|
||||
}
|
||||
|
||||
if ( APData->TargetClimbRate > max_climb ) {
|
||||
APData->TargetClimbRate = max_climb;
|
||||
}
|
||||
|
||||
if ( APData->TargetClimbRate < -400.0 ) {
|
||||
APData->TargetClimbRate = -400.0;
|
||||
}
|
||||
|
||||
error = fgAPget_climb() - APData->TargetClimbRate;
|
||||
|
||||
// accumulate the error under the curve ... this really should
|
||||
// be *= delta t
|
||||
APData->alt_error_accum += error;
|
||||
|
||||
// calculate integral error, and adjustment amount
|
||||
int_error = APData->alt_error_accum;
|
||||
// printf("error = %.2f int_error = %.2f\n", error, int_error);
|
||||
int_adj = int_error / 8000.0;
|
||||
|
||||
// caclulate proportional error
|
||||
prop_error = error;
|
||||
prop_adj = prop_error / 2000.0;
|
||||
|
||||
total_adj = 0.9 * prop_adj + 0.1 * int_adj;
|
||||
if ( total_adj > 0.6 ) { total_adj = 0.6; }
|
||||
if ( total_adj < -0.2 ) { total_adj = -0.2; }
|
||||
|
||||
controls.set_elevator( total_adj );
|
||||
}
|
||||
|
||||
// auto throttle enabled?
|
||||
if ( APData->auto_throttle ) {
|
||||
double error;
|
||||
double prop_error, int_error;
|
||||
double prop_adj, int_adj, total_adj;
|
||||
|
||||
error = APData->TargetSpeed - get_speed();
|
||||
|
||||
// accumulate the error under the curve ... this really should
|
||||
// be *= delta t
|
||||
APData->speed_error_accum += error;
|
||||
if ( APData->speed_error_accum > 2000.0 ) {
|
||||
APData->speed_error_accum = 2000.0;
|
||||
}
|
||||
if ( APData->speed_error_accum < -2000.0 ) {
|
||||
APData->speed_error_accum = -2000.0;
|
||||
}
|
||||
|
||||
// calculate integral error, and adjustment amount
|
||||
int_error = APData->speed_error_accum;
|
||||
|
||||
// printf("error = %.2f int_error = %.2f\n", error, int_error);
|
||||
int_adj = int_error / 200.0;
|
||||
|
||||
// caclulate proportional error
|
||||
prop_error = error;
|
||||
prop_adj = 0.5 + prop_error / 50.0;
|
||||
|
||||
total_adj = 0.9 * prop_adj + 0.1 * int_adj;
|
||||
if ( total_adj > 1.0 ) { total_adj = 1.0; }
|
||||
if ( total_adj < 0.0 ) { total_adj = 0.0; }
|
||||
|
||||
controls.set_throttle( FGControls::ALL_ENGINES, total_adj );
|
||||
}
|
||||
|
||||
/*
|
||||
if (APData->Mode == 2) // Glide slope hold
|
||||
{
|
||||
double RelSlope;
|
||||
double RelElevator;
|
||||
|
||||
// First, calculate Relative slope and normalize it
|
||||
RelSlope = NormalizeDegrees( APData->TargetSlope - get_pitch());
|
||||
|
||||
// Now calculate the elevator offset from current angle
|
||||
if ( abs(RelSlope) > APData->SlopeSmooth )
|
||||
{
|
||||
if ( RelSlope < 0 ) // set RelElevator to max in the correct direction
|
||||
RelElevator = -APData->MaxElevator;
|
||||
else
|
||||
RelElevator = APData->MaxElevator;
|
||||
}
|
||||
|
||||
else
|
||||
RelElevator = LinearExtrapolate(RelSlope,-APData->SlopeSmooth,-APData->MaxElevator,APData->SlopeSmooth,APData->MaxElevator);
|
||||
|
||||
// set the elevator
|
||||
fgElevMove(RelElevator);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// Ok, we are done
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void fgAPSetMode( int mode)
|
||||
{
|
||||
//Remove the following line when the calling funcitons start passing in the data pointer
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
fgPrintf( FG_COCKPIT, FG_INFO, "APSetMode : %d\n", mode );
|
||||
|
||||
APData->Mode = mode; // set the new mode
|
||||
}
|
||||
*/
|
||||
|
||||
void fgAPToggleHeading( void )
|
||||
{
|
||||
// Remove at a later date
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
if ( APData->heading_hold ) {
|
||||
// turn off heading hold
|
||||
APData->heading_hold = false;
|
||||
} else {
|
||||
// turn on heading hold, lock at current heading
|
||||
APData->heading_hold = true;
|
||||
APData->TargetHeading = fgAPget_heading();
|
||||
}
|
||||
|
||||
FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetHeading: ("
|
||||
<< APData->heading_hold << ") " << APData->TargetHeading );
|
||||
}
|
||||
|
||||
|
||||
void fgAPToggleAltitude( void )
|
||||
{
|
||||
// Remove at a later date
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
if ( APData->altitude_hold ) {
|
||||
// turn off altitude hold
|
||||
APData->altitude_hold = false;
|
||||
} else {
|
||||
// turn on altitude hold, lock at current altitude
|
||||
APData->altitude_hold = true;
|
||||
APData->terrain_follow = false;
|
||||
APData->TargetAltitude = fgAPget_altitude();
|
||||
APData->alt_error_accum = 0.0;
|
||||
// alt_error_queue.erase( alt_error_queue.begin(),
|
||||
// alt_error_queue.end() );
|
||||
}
|
||||
|
||||
FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetAltitude: ("
|
||||
<< APData->altitude_hold << ") " << APData->TargetAltitude );
|
||||
}
|
||||
|
||||
|
||||
void fgAPToggleAutoThrottle ( void )
|
||||
{
|
||||
// Remove at a later date
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
if ( APData->auto_throttle ) {
|
||||
// turn off altitude hold
|
||||
APData->auto_throttle = false;
|
||||
} else {
|
||||
// turn on terrain follow, lock at current agl
|
||||
APData->auto_throttle = true;
|
||||
APData->TargetSpeed = get_speed();
|
||||
APData->speed_error_accum = 0.0;
|
||||
}
|
||||
|
||||
FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetAutoThrottle: ("
|
||||
<< APData->auto_throttle << ") " << APData->TargetSpeed );
|
||||
}
|
||||
|
||||
void fgAPToggleTerrainFollow( void )
|
||||
{
|
||||
// Remove at a later date
|
||||
fgAPDataPtr APData;
|
||||
|
||||
APData = APDataGlobal;
|
||||
// end section
|
||||
|
||||
if ( APData->terrain_follow ) {
|
||||
// turn off altitude hold
|
||||
APData->terrain_follow = false;
|
||||
} else {
|
||||
// turn on terrain follow, lock at current agl
|
||||
APData->terrain_follow = true;
|
||||
APData->altitude_hold = false;
|
||||
APData->TargetAGL = fgAPget_agl();
|
||||
APData->alt_error_accum = 0.0;
|
||||
}
|
||||
|
||||
FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetTerrainFollow: ("
|
||||
<< APData->terrain_follow << ") " << APData->TargetAGL );
|
||||
}
|
||||
|
||||
double LinearExtrapolate( double x,double x1,double y1,double x2,double y2)
|
||||
{
|
||||
// This procedure extrapolates the y value for the x posistion on a line defined by x1,y1; x2,y2
|
||||
//assert(x1 != x2); // Divide by zero error. Cold abort for now
|
||||
|
||||
double m, b, y; // the constants to find in y=mx+b
|
||||
|
||||
m=(y2-y1)/(x2-x1); // calculate the m
|
||||
|
||||
b= y1- m * x1; // calculate the b
|
||||
|
||||
y = m * x + b; // the final calculation
|
||||
|
||||
return (y);
|
||||
|
||||
};
|
||||
|
||||
double NormalizeDegrees(double Input)
|
||||
{
|
||||
// normalize the input to the range (-180,180]
|
||||
// Input should not be greater than -360 to 360. Current rules send the output to an undefined state.
|
||||
if (Input > 180)
|
||||
Input -= 360;
|
||||
if (Input <= -180)
|
||||
Input += 360;
|
||||
|
||||
return (Input);
|
||||
};
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.15 1999/02/12 23:22:35 curt
|
||||
// Allow auto-throttle adjustment while active.
|
||||
//
|
||||
// Revision 1.14 1999/02/12 22:17:14 curt
|
||||
// Changes contributed by Norman Vine to allow adjustment of the autopilot
|
||||
// while it is activated.
|
||||
//
|
92
Simulator/Autopilot/autopilot.hxx
Normal file
92
Simulator/Autopilot/autopilot.hxx
Normal file
|
@ -0,0 +1,92 @@
|
|||
// autopilot.hxx -- autopilot defines and prototypes (very alpha)
|
||||
//
|
||||
// Written by Jeff Goeke-Smith, started April 1998.
|
||||
//
|
||||
// Copyright (C) 1998 Jeff Goeke-Smith - jgoeke@voyager.net
|
||||
//
|
||||
// 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 _AUTOPILOT_HXX
|
||||
#define _AUTOPILOT_HXX
|
||||
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Controls/controls.hxx>
|
||||
|
||||
|
||||
// Structures
|
||||
typedef struct {
|
||||
bool heading_hold; // the current state of the heading hold
|
||||
bool altitude_hold; // the current state of the altitude hold
|
||||
bool terrain_follow; // the current state of the terrain follower
|
||||
bool auto_throttle; // the current state of the auto throttle
|
||||
|
||||
double TargetHeading; // the heading the AP should steer to.
|
||||
double TargetAltitude; // altitude to hold
|
||||
double TargetAGL; // the terrain separation
|
||||
double TargetClimbRate; // climb rate to shoot for
|
||||
double TargetSpeed; // speed to shoot for
|
||||
double alt_error_accum; // altitude error accumulator
|
||||
double speed_error_accum; // speed error accumulator
|
||||
|
||||
double TargetSlope; // the glide slope hold value
|
||||
|
||||
double MaxRoll ; // the max the plane can roll for the turn
|
||||
double RollOut; // when the plane should roll out
|
||||
// measured from Heading
|
||||
double MaxAileron; // how far to move the aleroin from center
|
||||
double RollOutSmooth; // deg to use for smoothing Aileron Control
|
||||
double MaxElevator; // the maximum elevator allowed
|
||||
double SlopeSmooth; // smoothing angle for elevator
|
||||
|
||||
} fgAPData, *fgAPDataPtr ;
|
||||
|
||||
|
||||
// Defines
|
||||
#define AP_CURRENT_HEADING -1
|
||||
|
||||
|
||||
// prototypes
|
||||
void fgAPInit( fgAIRCRAFT *current_aircraft );
|
||||
int fgAPRun( void );
|
||||
void fgAPToggleHeading( void );
|
||||
void fgAPToggleAltitude( void );
|
||||
void fgAPToggleTerrainFollow( void );
|
||||
void fgAPToggleAutoThrottle( void );
|
||||
|
||||
bool fgAPAltitudeEnabled( void );
|
||||
bool fgAPHeadingEnabled( void );
|
||||
bool fgAPAutoThrottleEnabled( void );
|
||||
void fgAPAltitudeAdjust( double inc );
|
||||
void fgAPHeadingAdjust( double inc );
|
||||
void fgAPAutoThrottleAdjust( double inc );
|
||||
|
||||
|
||||
#endif // _AUTOPILOT_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.9 1999/02/12 23:22:36 curt
|
||||
// Allow auto-throttle adjustment while active.
|
||||
//
|
||||
// Revision 1.8 1999/02/12 22:17:15 curt
|
||||
// Changes contributed by Norman Vine to allow adjustment of the autopilot
|
||||
// while it is activated.
|
||||
//
|
13
Simulator/CVSROOT/checkoutlist
Normal file
13
Simulator/CVSROOT/checkoutlist
Normal file
|
@ -0,0 +1,13 @@
|
|||
# The "checkoutlist" file is used to support additional version controlled
|
||||
# administrative files in $CVSROOT/CVSROOT, such as template files.
|
||||
#
|
||||
# The first entry on a line is a filename which will be checked out from
|
||||
# the corresponding RCS file in the $CVSROOT/CVSROOT directory.
|
||||
# The remainder of the line is an error message to use if the file cannot
|
||||
# be checked out.
|
||||
#
|
||||
# File format:
|
||||
#
|
||||
# [<whitespace>]<filename><whitespace><error message><end-of-line>
|
||||
#
|
||||
# comment lines begin with '#'
|
15
Simulator/CVSROOT/commitinfo
Normal file
15
Simulator/CVSROOT/commitinfo
Normal file
|
@ -0,0 +1,15 @@
|
|||
# The "commitinfo" file is used to control pre-commit checks.
|
||||
# The filter on the right is invoked with the repository and a list
|
||||
# of files to check. A non-zero exit of the filter program will
|
||||
# cause the commit to be aborted.
|
||||
#
|
||||
# The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being committed to, relative
|
||||
# to the $CVSROOT. For the first match that is found, then the remainder
|
||||
# of the line is the name of the filter to run.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
22
Simulator/CVSROOT/cvswrappers
Normal file
22
Simulator/CVSROOT/cvswrappers
Normal file
|
@ -0,0 +1,22 @@
|
|||
# This file describes wrappers and other binary files to CVS.
|
||||
#
|
||||
# Wrappers are the concept where directories of files are to be
|
||||
# treated as a single file. The intended use is to wrap up a wrapper
|
||||
# into a single tar such that the tar archive can be treated as a
|
||||
# single binary file in CVS.
|
||||
#
|
||||
# To solve the problem effectively, it was also necessary to be able to
|
||||
# prevent rcsmerge from merging these files.
|
||||
#
|
||||
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
|
||||
#
|
||||
# wildcard [option value][option value]...
|
||||
#
|
||||
# where option is one of
|
||||
# -f from cvs filter value: path to filter
|
||||
# -t to cvs filter value: path to filter
|
||||
# -m update methodology value: MERGE or COPY
|
||||
#
|
||||
# and value is a single-quote delimited value.
|
||||
#
|
||||
# For example:
|
21
Simulator/CVSROOT/editinfo
Normal file
21
Simulator/CVSROOT/editinfo
Normal file
|
@ -0,0 +1,21 @@
|
|||
# The "editinfo" file is used to allow verification of logging
|
||||
# information. It works best when a template (as specified in the
|
||||
# rcsinfo file) is provided for the logging procedure. Given a
|
||||
# template with locations for, a bug-id number, a list of people who
|
||||
# reviewed the code before it can be checked in, and an external
|
||||
# process to catalog the differences that were code reviewed, the
|
||||
# following test can be applied to the code:
|
||||
#
|
||||
# Making sure that the entered bug-id number is correct.
|
||||
# Validating that the code that was reviewed is indeed the code being
|
||||
# checked in (using the bug-id number or a seperate review
|
||||
# number to identify this particular code set.).
|
||||
#
|
||||
# If any of the above test failed, then the commit would be aborted.
|
||||
#
|
||||
# Actions such as mailing a copy of the report to each reviewer are
|
||||
# better handled by an entry in the loginfo file.
|
||||
#
|
||||
# One thing that should be noted is the the ALL keyword is not
|
||||
# supported. There can be only one entry that matches a given
|
||||
# repository.
|
19
Simulator/CVSROOT/loginfo
Normal file
19
Simulator/CVSROOT/loginfo
Normal file
|
@ -0,0 +1,19 @@
|
|||
# The "loginfo" file is used to control where "cvs commit" log information is
|
||||
# sent. The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being made to, relative to the
|
||||
# $CVSROOT. For the first match that is found, the remainder of the line is a
|
||||
# filter program that should expect log information on its standard input
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in the
|
||||
# first field of this file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
||||
#
|
||||
# The filter program may use one and only one "%s" modifier (ala printf). If
|
||||
# such a "%s" is specified in the filter program, a brief title is included
|
||||
# (as one argument, enclosed in single quotes) showing the relative directory
|
||||
# name and listing the modified file names.
|
||||
#
|
||||
# For example:
|
||||
#DEFAULT (echo ""; who am i; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
|
26
Simulator/CVSROOT/modules
Normal file
26
Simulator/CVSROOT/modules
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Three different line formats are valid:
|
||||
# key -a aliases...
|
||||
# key [options] directory
|
||||
# key [options] directory files...
|
||||
#
|
||||
# Where "options" are composed of:
|
||||
# -i prog Run "prog" on "cvs commit" from top-level of module.
|
||||
# -o prog Run "prog" on "cvs checkout" of module.
|
||||
# -e prog Run "prog" on "cvs export" of module.
|
||||
# -t prog Run "prog" on "cvs rtag" of module.
|
||||
# -u prog Run "prog" on "cvs update" of module.
|
||||
# -d dir Place module in directory "dir" instead of module name.
|
||||
# -l Top-level directory only -- do not recurse.
|
||||
#
|
||||
# NOTE: If you change any of the "Run" options above, you'll have to
|
||||
# release and re-checkout any working directories of these modules.
|
||||
#
|
||||
# And "directory" is a path to a directory relative to $CVSROOT.
|
||||
#
|
||||
# The "-a" option specifies an alias. An alias is interpreted as if
|
||||
# everything on the right of the "-a" had been typed on the command line.
|
||||
#
|
||||
# You can encode a module within a module by using the special '&'
|
||||
# character to interpose another module into the current module. This
|
||||
# can be useful for creating a module that consists of many directories
|
||||
# spread out over the entire source repository.
|
12
Simulator/CVSROOT/notify
Normal file
12
Simulator/CVSROOT/notify
Normal file
|
@ -0,0 +1,12 @@
|
|||
# The "notify" file controls where notifications from watches set by
|
||||
# "cvs watch add" or "cvs edit" are sent. The first entry on a line is
|
||||
# a regular expression which is tested against the directory that the
|
||||
# change is being made to, relative to the $CVSROOT. If it matches,
|
||||
# then the remainder of the line is a filter program that should contain
|
||||
# one occurrence of %s for the user to notify, and information on its
|
||||
# standard input.
|
||||
#
|
||||
# "ALL" or "DEFAULT" can be used in place of the regular expression.
|
||||
#
|
||||
# For example:
|
||||
#ALL mail %s -s "CVS notification"
|
13
Simulator/CVSROOT/rcsinfo
Normal file
13
Simulator/CVSROOT/rcsinfo
Normal file
|
@ -0,0 +1,13 @@
|
|||
# The "rcsinfo" file is used to control templates with which the editor
|
||||
# is invoked on commit and import.
|
||||
#
|
||||
# The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being made to, relative to the
|
||||
# $CVSROOT. For the first match that is found, then the remainder of the
|
||||
# line is the name of the file that contains the template.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
20
Simulator/CVSROOT/taginfo
Normal file
20
Simulator/CVSROOT/taginfo
Normal file
|
@ -0,0 +1,20 @@
|
|||
# The "taginfo" file is used to control pre-tag checks.
|
||||
# The filter on the right is invoked with the following arguments:
|
||||
#
|
||||
# $1 -- tagname
|
||||
# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
|
||||
# $3 -- repository
|
||||
# $4-> file revision [file revision ...]
|
||||
#
|
||||
# A non-zero exit of the filter program will cause the tag to be aborted.
|
||||
#
|
||||
# The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being committed to, relative
|
||||
# to the $CVSROOT. For the first match that is found, then the remainder
|
||||
# of the line is the name of the filter to run.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
10
Simulator/Cockpit/Makefile.am
Normal file
10
Simulator/Cockpit/Makefile.am
Normal file
|
@ -0,0 +1,10 @@
|
|||
noinst_LIBRARIES = libCockpit.a
|
||||
|
||||
libCockpit_a_SOURCES = \
|
||||
cockpit.cxx cockpit.hxx \
|
||||
hud.cxx hud.hxx \
|
||||
hud_card.cxx hud_dnst.cxx hud_guag.cxx hud_inst.cxx \
|
||||
hud_labl.cxx hud_ladr.cxx hud_scal.cxx hud_tbi.cxx \
|
||||
panel.cxx panel.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
414
Simulator/Cockpit/cockpit.cxx
Normal file
414
Simulator/Cockpit/cockpit.cxx
Normal file
|
@ -0,0 +1,414 @@
|
|||
//*************************************************************************
|
||||
// cockpit.cxx -- routines to draw a cockpit (initial draft)
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
|
||||
//
|
||||
// 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
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Include/general.hxx>
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/views.hxx>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
#include "cockpit.hxx"
|
||||
#include "panel.hxx"
|
||||
|
||||
|
||||
// This is a structure that contains all data related to
|
||||
// cockpit/panel/hud system
|
||||
|
||||
static pCockpit ac_cockpit;
|
||||
|
||||
// The following routines obtain information concerntin the aircraft's
|
||||
// current state and return it to calling instrument display routines.
|
||||
// They should eventually be member functions of the aircraft.
|
||||
//
|
||||
|
||||
double get_latitude( void )
|
||||
{
|
||||
return((double)((int)( current_aircraft.fdm_state->get_Latitude()
|
||||
* RAD_TO_DEG)) );
|
||||
}
|
||||
|
||||
double get_lat_min( void )
|
||||
{
|
||||
double a, d;
|
||||
|
||||
a = current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
|
||||
if (a < 0.0) {
|
||||
a = -a;
|
||||
}
|
||||
d = (double) ( (int) a);
|
||||
return( (a - d) * 60.0);
|
||||
}
|
||||
|
||||
double get_longitude( void )
|
||||
{
|
||||
return( (double)((int) (current_aircraft.fdm_state->get_Longitude()
|
||||
* RAD_TO_DEG)) );
|
||||
}
|
||||
|
||||
double get_long_min( void )
|
||||
{
|
||||
double a, d;
|
||||
|
||||
a = current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
|
||||
if (a < 0.0) {
|
||||
a = -a;
|
||||
}
|
||||
d = (double) ( (int) a);
|
||||
return( (a - d) * 60.0);
|
||||
}
|
||||
|
||||
double get_throttleval( void )
|
||||
{
|
||||
return controls.get_throttle( 0 ); // Hack limiting to one engine
|
||||
}
|
||||
|
||||
double get_aileronval( void )
|
||||
{
|
||||
return controls.get_aileron();
|
||||
}
|
||||
|
||||
double get_elevatorval( void )
|
||||
{
|
||||
return controls.get_elevator();
|
||||
}
|
||||
|
||||
double get_elev_trimval( void )
|
||||
{
|
||||
return controls.get_elevator_trim();
|
||||
}
|
||||
|
||||
double get_rudderval( void )
|
||||
{
|
||||
return controls.get_rudder();
|
||||
}
|
||||
|
||||
double get_speed( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_V_equiv_kts() );
|
||||
}
|
||||
|
||||
double get_aoa( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Alpha() * RAD_TO_DEG );
|
||||
}
|
||||
|
||||
double get_roll( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Phi() );
|
||||
}
|
||||
|
||||
double get_pitch( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Theta() );
|
||||
}
|
||||
|
||||
double get_heading( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG );
|
||||
}
|
||||
|
||||
double get_altitude( void )
|
||||
{
|
||||
if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
|
||||
return current_aircraft.fdm_state->get_Altitude();
|
||||
} else {
|
||||
return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
|
||||
}
|
||||
}
|
||||
|
||||
double get_agl( void )
|
||||
{
|
||||
if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
|
||||
return current_aircraft.fdm_state->get_Altitude()
|
||||
- scenery.cur_elev * METER_TO_FEET;
|
||||
} else {
|
||||
return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
|
||||
- scenery.cur_elev;
|
||||
}
|
||||
}
|
||||
|
||||
double get_sideslip( void )
|
||||
{
|
||||
return( current_aircraft.fdm_state->get_Beta() );
|
||||
}
|
||||
|
||||
double get_frame_rate( void )
|
||||
{
|
||||
return (double) general.get_frame_rate();
|
||||
}
|
||||
|
||||
double get_fov( void )
|
||||
{
|
||||
return (current_options.get_fov());
|
||||
}
|
||||
|
||||
double get_vfc_ratio( void )
|
||||
{
|
||||
return current_view.get_vfc_ratio();
|
||||
}
|
||||
|
||||
double get_vfc_tris_drawn ( void )
|
||||
{
|
||||
return current_view.get_tris_rendered();
|
||||
}
|
||||
|
||||
double get_climb_rate( void )
|
||||
{
|
||||
if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
|
||||
return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
|
||||
} else {
|
||||
return current_aircraft.fdm_state->get_Climb_Rate()
|
||||
* FEET_TO_METER * 60.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
|
||||
{
|
||||
FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
|
||||
|
||||
// cockpit->code = 1; /* It will be aircraft dependent */
|
||||
// cockpit->status = 0;
|
||||
|
||||
// If aircraft has HUD specified we will get the specs from its def
|
||||
// file. For now we will depend upon hard coding in hud?
|
||||
|
||||
// We must insure that the existing instrument link is purged.
|
||||
// This is done by deleting the links in the list.
|
||||
|
||||
// HI_Head is now a null pointer so we can generate a new list from the
|
||||
// current aircraft.
|
||||
|
||||
fgHUDInit( cur_aircraft );
|
||||
ac_cockpit = new fg_Cockpit();
|
||||
|
||||
if ( current_options.get_panel_status() ) {
|
||||
new FGPanel;
|
||||
}
|
||||
|
||||
FG_LOG( FG_COCKPIT, FG_INFO,
|
||||
" Code " << ac_cockpit->code() << " Status "
|
||||
<< ac_cockpit->status() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void fgCockpitUpdate( void ) {
|
||||
FG_LOG( FG_COCKPIT, FG_DEBUG,
|
||||
"Cockpit: code " << ac_cockpit->code() << " status "
|
||||
<< ac_cockpit->status() );
|
||||
|
||||
if ( current_options.get_hud_status() ) {
|
||||
// This will check the global hud linked list pointer.
|
||||
// If these is anything to draw it will.
|
||||
fgUpdateHUD();
|
||||
}
|
||||
|
||||
if ( current_options.get_panel_status() &&
|
||||
(fabs( current_view.get_view_offset() ) < 0.2) )
|
||||
{
|
||||
xglViewport( 0, 0,
|
||||
current_view.get_winWidth(),
|
||||
current_view.get_winHeight() );
|
||||
FGPanel::OurPanel->Update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.31 1999/03/08 21:56:08 curt
|
||||
// Added panel changes sent in by Friedemann.
|
||||
//
|
||||
// Revision 1.30 1999/02/05 21:28:57 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.29 1999/01/08 19:27:34 curt
|
||||
// Fixed AOA reading on HUD.
|
||||
// Continued work on time jitter compensation.
|
||||
//
|
||||
// Revision 1.28 1999/01/07 20:24:17 curt
|
||||
// Update fgGENERAL to FGGeneral.
|
||||
//
|
||||
// Revision 1.27 1998/12/18 23:35:09 curt
|
||||
// Converted to a simpler frame rate counting method.
|
||||
//
|
||||
// Revision 1.26 1998/12/09 18:50:19 curt
|
||||
// Converted "class fgVIEW" to "class FGView" and updated to make data
|
||||
// members private and make required accessor functions.
|
||||
//
|
||||
// Revision 1.25 1998/12/05 15:54:07 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.24 1998/12/03 01:16:00 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
//
|
||||
// Revision 1.23 1998/11/09 23:38:50 curt
|
||||
// Panel updates from Friedemann.
|
||||
//
|
||||
// Revision 1.22 1998/11/06 21:17:45 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUG flag.
|
||||
//
|
||||
// Revision 1.21 1998/11/02 23:04:02 curt
|
||||
// HUD units now display in feet by default with meters being a command line
|
||||
// option.
|
||||
//
|
||||
// Revision 1.20 1998/10/25 14:08:40 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.19 1998/10/17 01:33:56 curt
|
||||
// C++ ifying ...
|
||||
//
|
||||
// Revision 1.18 1998/10/16 23:27:23 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.17 1998/09/29 14:56:30 curt
|
||||
// c++-ified comments.
|
||||
//
|
||||
// Revision 1.16 1998/09/29 02:01:06 curt
|
||||
// Added a "rate of climb" indicator.
|
||||
//
|
||||
// Revision 1.15 1998/08/28 18:14:39 curt
|
||||
// Added new cockpit code from Friedemann Reinhard
|
||||
// <mpt218@faupt212.physik.uni-erlangen.de>
|
||||
//
|
||||
// Revision 1.14 1998/08/24 20:05:15 curt
|
||||
// Added a second minimalistic HUD.
|
||||
// Added code to display the number of triangles rendered.
|
||||
//
|
||||
// Revision 1.13 1998/08/22 01:19:27 curt
|
||||
// Omit panel code because it's texture loading overruns array bounds.
|
||||
//
|
||||
// Revision 1.12 1998/07/13 21:28:00 curt
|
||||
// Converted the aoa scale to a radio altimeter.
|
||||
//
|
||||
// Revision 1.11 1998/07/13 21:00:45 curt
|
||||
// Integrated Charlies latest HUD updates.
|
||||
// Wrote access functions for current fgOPTIONS.
|
||||
//
|
||||
// Revision 1.10 1998/07/08 14:41:08 curt
|
||||
// Renamed polar3d.h to polar3d.hxx
|
||||
//
|
||||
// Revision 1.9 1998/06/27 16:47:53 curt
|
||||
// Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
|
||||
// first pass at an isntrument panel.
|
||||
//
|
||||
// Revision 1.8 1998/05/17 16:58:12 curt
|
||||
// Added a View Frustum Culling ratio display to the hud.
|
||||
//
|
||||
// Revision 1.7 1998/05/16 13:04:13 curt
|
||||
// New updates from Charlie Hotchkiss.
|
||||
//
|
||||
// Revision 1.6 1998/05/13 18:27:53 curt
|
||||
// Added an fov to hud display.
|
||||
//
|
||||
// Revision 1.5 1998/05/11 18:13:10 curt
|
||||
// Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
|
||||
//
|
||||
// Revision 1.4 1998/05/03 00:46:45 curt
|
||||
// polar.h -> polar3d.h
|
||||
//
|
||||
// Revision 1.3 1998/04/30 12:36:02 curt
|
||||
// C++-ifying a couple source files.
|
||||
//
|
||||
// Revision 1.2 1998/04/25 22:06:26 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.1 1998/04/24 00:45:54 curt
|
||||
// C++-ifing the code a bit.
|
||||
//
|
||||
// Revision 1.13 1998/04/18 04:14:01 curt
|
||||
// Moved fg_debug.c to it's own library.
|
||||
//
|
||||
// Revision 1.12 1998/04/14 02:23:09 curt
|
||||
// Code reorganizations. Added a Lib/ directory for more general libraries.
|
||||
//
|
||||
// Revision 1.11 1998/03/14 00:32:13 curt
|
||||
// Changed a printf() to a fgPrintf().
|
||||
//
|
||||
// Revision 1.10 1998/02/07 15:29:33 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.9 1998/02/03 23:20:14 curt
|
||||
// Lots of little tweaks to fix various consistency problems discovered by
|
||||
// Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
|
||||
// passed arguments along to the real printf(). Also incorporated HUD changes
|
||||
// by Michele America.
|
||||
//
|
||||
// Revision 1.8 1998/01/31 00:43:03 curt
|
||||
// Added MetroWorks patches from Carmen Volpe.
|
||||
//
|
||||
// Revision 1.7 1998/01/27 00:47:51 curt
|
||||
// Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.6 1998/01/19 19:27:01 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.5 1998/01/19 18:40:19 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.4 1997/12/30 20:47:34 curt
|
||||
// Integrated new event manager with subsystem initializations.
|
||||
//
|
||||
// Revision 1.3 1997/12/15 23:54:33 curt
|
||||
// Add xgl wrappers for debugging.
|
||||
// Generate terrain normals on the fly.
|
||||
//
|
||||
// Revision 1.2 1997/12/10 22:37:38 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.1 1997/08/29 18:03:20 curt
|
||||
// Initial revision.
|
||||
//
|
||||
|
105
Simulator/Cockpit/cockpit.hxx
Normal file
105
Simulator/Cockpit/cockpit.hxx
Normal file
|
@ -0,0 +1,105 @@
|
|||
/**************************************************************************
|
||||
* cockpit.hxx -- cockpit defines and prototypes (initial draft)
|
||||
*
|
||||
* Written by Michele America, started September 1997.
|
||||
*
|
||||
* Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
|
||||
*
|
||||
* 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 _COCKPIT_HXX
|
||||
#define _COCKPIT_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
#include "panel.hxx"
|
||||
|
||||
// Class fg_Cockpit This class is a holder for the heads up display
|
||||
// and is initialized with a
|
||||
class fg_Cockpit {
|
||||
private:
|
||||
int Code;
|
||||
int Status;
|
||||
|
||||
public:
|
||||
fg_Cockpit () : Code(1), Status(0) {};
|
||||
int code ( void ) { return Code; }
|
||||
int status( void ) { return Status; }
|
||||
};
|
||||
|
||||
|
||||
typedef fg_Cockpit * pCockpit;
|
||||
|
||||
bool fgCockpitInit( fgAIRCRAFT *cur_aircraft );
|
||||
void fgCockpitUpdate( void );
|
||||
|
||||
|
||||
#endif /* _COCKPIT_HXX */
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.4 1998/07/13 21:00:46 curt
|
||||
/* Integrated Charlies latest HUD updates.
|
||||
/* Wrote access functions for current fgOPTIONS.
|
||||
/*
|
||||
* Revision 1.3 1998/06/27 16:47:54 curt
|
||||
* Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
|
||||
* first pass at an isntrument panel.
|
||||
*
|
||||
* Revision 1.2 1998/05/11 18:13:10 curt
|
||||
* Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
|
||||
*
|
||||
* Revision 1.1 1998/04/24 00:45:55 curt
|
||||
* C++-ifing the code a bit.
|
||||
*
|
||||
* Revision 1.8 1998/04/22 13:26:19 curt
|
||||
* C++ - ifing the code a bit.
|
||||
*
|
||||
* Revision 1.7 1998/04/21 17:02:34 curt
|
||||
* Prepairing for C++ integration.
|
||||
*
|
||||
* Revision 1.6 1998/02/07 15:29:33 curt
|
||||
* Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.5 1998/01/22 02:59:29 curt
|
||||
* Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
*
|
||||
* Revision 1.4 1998/01/19 19:27:01 curt
|
||||
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
* This should simplify things tremendously.
|
||||
*
|
||||
* Revision 1.3 1998/01/19 18:40:19 curt
|
||||
* Tons of little changes to clean up the code and to remove fatal errors
|
||||
* when building with the c++ compiler.
|
||||
*
|
||||
* Revision 1.2 1997/12/10 22:37:39 curt
|
||||
* Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
* i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
*
|
||||
* Revision 1.1 1997/08/29 18:03:21 curt
|
||||
* Initial revision.
|
||||
*
|
||||
*/
|
1008
Simulator/Cockpit/hud.cxx
Normal file
1008
Simulator/Cockpit/hud.cxx
Normal file
File diff suppressed because it is too large
Load diff
639
Simulator/Cockpit/hud.hxx
Normal file
639
Simulator/Cockpit/hud.hxx
Normal file
|
@ -0,0 +1,639 @@
|
|||
// hud.hxx -- hud defines and prototypes (initial draft)
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
|
||||
//
|
||||
// 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 _HUD_HXX
|
||||
#define _HUD_HXX
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_VALUES_H
|
||||
# include <values.h> // for MAXINT
|
||||
#endif
|
||||
|
||||
#include <deque> // STL double ended queue
|
||||
|
||||
#include <fg_typedefs.h>
|
||||
#include <fg_constants.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Controls/controls.hxx>
|
||||
|
||||
FG_USING_STD(deque);
|
||||
|
||||
#ifndef WIN32
|
||||
typedef struct {
|
||||
int x, y;
|
||||
} POINT;
|
||||
|
||||
typedef struct {
|
||||
int top, bottom, left, right;
|
||||
} RECT;
|
||||
#endif
|
||||
|
||||
// View mode definitions
|
||||
|
||||
enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
|
||||
|
||||
// DAY, NIGHT and brightness levels need to be visible where dialogs and
|
||||
// controls can be used to set intensity and appropriate color. This will
|
||||
// be moved.
|
||||
// Hud general constants
|
||||
#define DAY 1
|
||||
#define NIGHT 2
|
||||
#define BRT_BLACK 3
|
||||
#define BRT_DARK 4
|
||||
#define BRT_MEDIUM 5
|
||||
#define BRT_LIGHT 6
|
||||
#define SIZE_SMALL 7
|
||||
#define SIZE_LARGE 8
|
||||
|
||||
// Label constants
|
||||
#define SMALL 1
|
||||
#define LARGE 2
|
||||
|
||||
#define BLINK 3
|
||||
#define NOBLINK 4
|
||||
|
||||
enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
|
||||
|
||||
// Ladder constants
|
||||
#define NONE 1
|
||||
#define UPPER_LEFT 2
|
||||
#define UPPER_CENTER 3
|
||||
#define UPPER_RIGHT 4
|
||||
#define CENTER_RIGHT 5
|
||||
#define LOWER_RIGHT 6
|
||||
#define LOWER_CENTER 7
|
||||
#define LOWER_LEFT 8
|
||||
#define CENTER_LEFT 9
|
||||
#define SOLID_LINES 10
|
||||
#define DASHED_LINES 11
|
||||
#define DASHED_NEG_LINES 12
|
||||
|
||||
|
||||
#define HORIZON_FIXED 1
|
||||
#define HORIZON_MOVING 2
|
||||
#define LABEL_COUNTER 1
|
||||
#define LABEL_WARNING 2
|
||||
|
||||
#define HUDS_AUTOTICKS 0x0001
|
||||
#define HUDS_VERT 0x0002
|
||||
#define HUDS_HORZ 0x0000
|
||||
#define HUDS_TOP 0x0004
|
||||
#define HUDS_BOTTOM 0x0008
|
||||
#define HUDS_LEFT HUDS_TOP
|
||||
#define HUDS_RIGHT HUDS_BOTTOM
|
||||
#define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
|
||||
#define HUDS_NOTICKS 0x0010
|
||||
#define HUDS_ARITHTIC 0x0020
|
||||
#define HUDS_DECITICS 0x0040
|
||||
#define HUDS_NOTEXT 0x0080
|
||||
|
||||
// Ladder orientaion
|
||||
// #define HUD_VERTICAL 1
|
||||
// #define HUD_HORIZONTAL 2
|
||||
// #define HUD_FREEFLOAT 3
|
||||
|
||||
// Ladder orientation modes
|
||||
// #define HUD_LEFT 1
|
||||
// #define HUD_RIGHT 2
|
||||
// #define HUD_TOP 1
|
||||
// #define HUD_BOTTOM 2
|
||||
// #define HUD_V_LEFT 1
|
||||
// #define HUD_V_RIGHT 2
|
||||
// #define HUD_H_TOP 1
|
||||
// #define HUD_H_BOTTOM 2
|
||||
|
||||
|
||||
// Ladder sub-types
|
||||
// #define HUD_LIM 1
|
||||
// #define HUD_NOLIM 2
|
||||
// #define HUD_CIRC 3
|
||||
|
||||
// #define HUD_INSTR_LADDER 1
|
||||
// #define HUD_INSTR_CLADDER 2
|
||||
// #define HUD_INSTR_HORIZON 3
|
||||
// #define HUD_INSTR_LABEL 4
|
||||
|
||||
extern double get_throttleval ( void );
|
||||
extern double get_aileronval ( void );
|
||||
extern double get_elevatorval ( void );
|
||||
extern double get_elev_trimval( void );
|
||||
extern double get_rudderval ( void );
|
||||
extern double get_speed ( void );
|
||||
extern double get_aoa ( void );
|
||||
extern double get_roll ( void );
|
||||
extern double get_pitch ( void );
|
||||
extern double get_heading ( void );
|
||||
extern double get_altitude ( void );
|
||||
extern double get_agl ( void );
|
||||
extern double get_sideslip ( void );
|
||||
extern double get_frame_rate ( void );
|
||||
extern double get_latitude ( void );
|
||||
extern double get_lat_min ( void );
|
||||
extern double get_longitude ( void );
|
||||
extern double get_long_min ( void );
|
||||
extern double get_fov ( void );
|
||||
extern double get_vfc_ratio ( void );
|
||||
extern double get_vfc_tris_drawn ( void );
|
||||
extern double get_climb_rate ( void );
|
||||
|
||||
enum hudinstype{ HUDno_instr,
|
||||
HUDscale,
|
||||
HUDlabel,
|
||||
HUDladder,
|
||||
HUDcirc_ladder,
|
||||
HUDhorizon,
|
||||
HUDguage,
|
||||
HUDdual_inst,
|
||||
HUDmoving_scale,
|
||||
HUDtbi
|
||||
};
|
||||
|
||||
typedef struct gltagRGBTRIPLE { // rgbt
|
||||
GLfloat Blue;
|
||||
GLfloat Green;
|
||||
GLfloat Red;
|
||||
} glRGBTRIPLE;
|
||||
|
||||
class instr_item { // An Abstract Base Class (ABC)
|
||||
private:
|
||||
static UINT instances; // More than 64K instruments? Nah!
|
||||
static int brightness;
|
||||
static glRGBTRIPLE color;
|
||||
|
||||
UINT handle;
|
||||
RECT scrn_pos; // Framing - affects scale dimensions
|
||||
// and orientation. Vert vs Horz, etc.
|
||||
DBLFNPTR load_value_fn;
|
||||
double disp_factor; // Multiply by to get numbers shown on scale.
|
||||
UINT opts;
|
||||
bool is_enabled;
|
||||
bool broken;
|
||||
UINT scr_span; // Working values for draw;
|
||||
POINT mid_span; //
|
||||
|
||||
public:
|
||||
instr_item( int x,
|
||||
int y,
|
||||
UINT height,
|
||||
UINT width,
|
||||
DBLFNPTR data_source,
|
||||
double data_scaling,
|
||||
UINT options,
|
||||
bool working = true);
|
||||
|
||||
instr_item( const instr_item & image );
|
||||
|
||||
instr_item & operator = ( const instr_item & rhs );
|
||||
virtual ~instr_item ();
|
||||
|
||||
int get_brightness ( void ) { return brightness;}
|
||||
RECT get_location ( void ) { return scrn_pos; }
|
||||
bool is_broken ( void ) { return broken; }
|
||||
bool enabled ( void ) { return is_enabled;}
|
||||
bool data_available ( void ) { return !!load_value_fn; }
|
||||
double get_value ( void ) { return load_value_fn(); }
|
||||
double data_scaling ( void ) { return disp_factor; }
|
||||
UINT get_span ( void ) { return scr_span; }
|
||||
POINT get_centroid ( void ) { return mid_span; }
|
||||
UINT get_options ( void ) { return opts; }
|
||||
|
||||
virtual void display_enable( bool working ) { is_enabled = !! working;}
|
||||
|
||||
|
||||
virtual void update( void );
|
||||
virtual void break_display ( bool bad );
|
||||
virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
|
||||
void SetPosition ( int x, int y, UINT width, UINT height );
|
||||
UINT get_Handle( void );
|
||||
virtual void draw( void ) = 0; // Required method in derived classes
|
||||
};
|
||||
|
||||
typedef deque< instr_item * > HudContainerType;
|
||||
typedef HudContainerType::iterator HudIterator;
|
||||
|
||||
typedef instr_item *HIptr;
|
||||
extern HudContainerType HUD_deque;
|
||||
|
||||
// instr_item This class has no other purpose than to maintain
|
||||
// a linked list of instrument and derived class
|
||||
// object pointers.
|
||||
|
||||
|
||||
class instr_label : public instr_item {
|
||||
private:
|
||||
const char *pformat;
|
||||
const char *pre_str;
|
||||
const char *post_str;
|
||||
fgLabelJust justify;
|
||||
int fontSize;
|
||||
int blink;
|
||||
|
||||
public:
|
||||
instr_label( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR data_source,
|
||||
const char *label_format,
|
||||
const char *pre_label_string = 0,
|
||||
const char *post_label_string = 0,
|
||||
double scale_data = 1.0,
|
||||
UINT options = HUDS_TOP,
|
||||
fgLabelJust justification = CENTER_JUST,
|
||||
int font_size = SMALL,
|
||||
int blinking = NOBLINK,
|
||||
bool working = true);
|
||||
|
||||
~instr_label();
|
||||
|
||||
instr_label( const instr_label & image);
|
||||
instr_label & operator = (const instr_label & rhs );
|
||||
virtual void draw( void ); // Required method in base class
|
||||
};
|
||||
|
||||
typedef instr_label * pInstlabel;
|
||||
|
||||
//
|
||||
// instr_scale This class is an abstract base class for both moving
|
||||
// scale and moving needle (fixed scale) indicators. It
|
||||
// does not draw itself, but is not instanciable.
|
||||
//
|
||||
|
||||
class instr_scale : public instr_item {
|
||||
private:
|
||||
double range_shown; // Width Units.
|
||||
double Maximum_value; // ceiling.
|
||||
double Minimum_value; // Representation floor.
|
||||
double scale_factor; // factor => screen units/range values.
|
||||
UINT Maj_div; // major division marker units
|
||||
UINT Min_div; // minor division marker units
|
||||
UINT Modulo; // Roll over point
|
||||
int signif_digits; // digits to show to the right.
|
||||
|
||||
public:
|
||||
instr_scale( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR load_fn,
|
||||
UINT options,
|
||||
double show_range,
|
||||
double max_value = 100.0,
|
||||
double min_value = 0.0,
|
||||
double disp_scaling = 1.0,
|
||||
UINT major_divs = 10,
|
||||
UINT minor_divs = 5,
|
||||
UINT rollover = 0,
|
||||
int dp_showing = 2,
|
||||
bool working = true);
|
||||
|
||||
virtual ~instr_scale();
|
||||
instr_scale( const instr_scale & image);
|
||||
instr_scale & operator = (const instr_scale & rhs);
|
||||
|
||||
virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
|
||||
UINT div_min ( void ) { return Min_div;}
|
||||
UINT div_max ( void ) { return Maj_div;}
|
||||
double min_val ( void ) { return Minimum_value;}
|
||||
double max_val ( void ) { return Maximum_value;}
|
||||
UINT modulo ( void ) { return Modulo; }
|
||||
double factor ( void ) { return scale_factor;}
|
||||
double range_to_show( void ) { return range_shown;}
|
||||
};
|
||||
|
||||
// hud_card_ This class displays the indicated quantity on
|
||||
// a scale that moves past the pointer. It may be
|
||||
// horizontal or vertical, read above(left) or below(right) of the base
|
||||
// line.
|
||||
|
||||
class hud_card : public instr_scale {
|
||||
private:
|
||||
double val_span;
|
||||
double half_width_units;
|
||||
|
||||
public:
|
||||
hud_card( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR load_fn,
|
||||
UINT options,
|
||||
double maxValue = 100.0,
|
||||
double minValue = 0.0,
|
||||
double disp_scaling = 1.0,
|
||||
UINT major_divs = 10,
|
||||
UINT minor_divs = 5,
|
||||
UINT modulator = 100,
|
||||
int dp_showing = 2,
|
||||
double value_span = 100.0,
|
||||
bool working = true);
|
||||
|
||||
~hud_card();
|
||||
hud_card( const hud_card & image);
|
||||
hud_card & operator = (const hud_card & rhs );
|
||||
// virtual void display_enable( bool setting );
|
||||
virtual void draw( void ); // Required method in base class
|
||||
};
|
||||
|
||||
typedef hud_card * pCardScale;
|
||||
|
||||
class guage_instr : public instr_scale {
|
||||
private:
|
||||
|
||||
public:
|
||||
guage_instr( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR load_fn,
|
||||
UINT options,
|
||||
double disp_scaling = 1.0,
|
||||
double maxValue = 100,
|
||||
double minValue = 0,
|
||||
UINT major_divs = 50,
|
||||
UINT minor_divs = 0,
|
||||
int dp_showing = 2,
|
||||
UINT modulus = 0,
|
||||
bool working = true);
|
||||
|
||||
~guage_instr();
|
||||
guage_instr( const guage_instr & image);
|
||||
guage_instr & operator = (const guage_instr & rhs );
|
||||
virtual void draw( void ); // Required method in base class
|
||||
};
|
||||
|
||||
typedef guage_instr * pGuageInst;
|
||||
//
|
||||
// dual_instr_item This class was created to form the base class
|
||||
// for both panel and HUD Turn Bank Indicators.
|
||||
|
||||
class dual_instr_item : public instr_item {
|
||||
private:
|
||||
DBLFNPTR alt_data_source;
|
||||
|
||||
public:
|
||||
dual_instr_item ( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR chn1_source,
|
||||
DBLFNPTR chn2_source,
|
||||
bool working = true,
|
||||
UINT options = HUDS_TOP);
|
||||
|
||||
virtual ~dual_instr_item() {};
|
||||
dual_instr_item( const dual_instr_item & image);
|
||||
dual_instr_item & operator = (const dual_instr_item & rhs );
|
||||
|
||||
double current_ch1( void ) { return alt_data_source();}
|
||||
double current_ch2( void ) { return get_value();}
|
||||
virtual void draw ( void ) { }
|
||||
};
|
||||
|
||||
class fgTBI_instr : public dual_instr_item {
|
||||
private:
|
||||
UINT BankLimit;
|
||||
UINT SlewLimit;
|
||||
UINT scr_hole;
|
||||
|
||||
public:
|
||||
fgTBI_instr( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR chn1_source = get_roll,
|
||||
DBLFNPTR chn2_source = get_sideslip,
|
||||
double maxBankAngle = 45.0,
|
||||
double maxSlipAngle = 5.0,
|
||||
UINT gap_width = 5.0,
|
||||
bool working = true);
|
||||
|
||||
fgTBI_instr( const fgTBI_instr & image);
|
||||
fgTBI_instr & operator = (const fgTBI_instr & rhs );
|
||||
|
||||
~fgTBI_instr();
|
||||
|
||||
UINT bank_limit( void ) { return BankLimit;}
|
||||
UINT slew_limit( void ) { return SlewLimit;}
|
||||
|
||||
virtual void draw( void ); // Required method in base class
|
||||
};
|
||||
|
||||
typedef fgTBI_instr * pTBI;
|
||||
|
||||
class HudLadder : public dual_instr_item {
|
||||
private:
|
||||
UINT width_units;
|
||||
int div_units;
|
||||
UINT minor_div;
|
||||
UINT label_pos;
|
||||
UINT scr_hole;
|
||||
double vmax;
|
||||
double vmin;
|
||||
double factor;
|
||||
|
||||
public:
|
||||
HudLadder( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR ptch_source = get_roll,
|
||||
DBLFNPTR roll_source = get_pitch,
|
||||
double span_units = 45.0,
|
||||
double division_units = 10.0,
|
||||
double minor_division = 0.0,
|
||||
UINT screen_hole = 70,
|
||||
UINT lbl_pos = 0,
|
||||
bool working = true );
|
||||
|
||||
~HudLadder();
|
||||
|
||||
HudLadder( const HudLadder & image );
|
||||
HudLadder & operator = ( const HudLadder & rhs );
|
||||
virtual void draw( void );
|
||||
};
|
||||
|
||||
|
||||
//using namespace std;
|
||||
//deque <instr_item> * Hdeque_ptr;
|
||||
|
||||
extern void HUD_brightkey( bool incr_bright );
|
||||
extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
|
||||
extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
|
||||
extern void fgUpdateHUD( void );
|
||||
|
||||
extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
|
||||
extern void drawOneLine ( RECT &rect);
|
||||
extern void textString ( int x,
|
||||
int y,
|
||||
char *msg,
|
||||
void *font = GLUT_BITMAP_8_BY_13);
|
||||
extern void strokeString( int x,
|
||||
int y,
|
||||
char *msg,
|
||||
void *font = GLUT_STROKE_ROMAN,
|
||||
float theta = 0);
|
||||
/*
|
||||
bool AddHUDInstrument( instr_item *pBlackBox );
|
||||
void DrawHUD ( void );
|
||||
bool DamageInstrument( INSTR_HANDLE unit );
|
||||
bool RepairInstrument( INSTR_HANDLE unit );
|
||||
|
||||
|
||||
void fgUpdateHUD ( Hptr hud );
|
||||
void fgUpdateHUD2( Hptr hud ); // Future use?
|
||||
void fgHUDSetTimeMode( Hptr hud, int time_of_day );
|
||||
*/
|
||||
|
||||
#endif // _HUD_H
|
||||
|
||||
// $Log$
|
||||
// Revision 1.19 1999/03/02 01:02:38 curt
|
||||
// Tweaks for building with native SGI compilers.
|
||||
//
|
||||
// Revision 1.18 1999/02/26 22:08:45 curt
|
||||
// Added initial support for native SGI compilers.
|
||||
//
|
||||
// Revision 1.17 1999/02/01 21:33:28 curt
|
||||
// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
|
||||
// Jon accepted my offer to do this and thought it was a good idea.
|
||||
//
|
||||
// Revision 1.16 1998/10/17 01:33:59 curt
|
||||
// C++ ifying ...
|
||||
//
|
||||
// Revision 1.15 1998/10/16 23:27:27 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.14 1998/09/29 14:56:33 curt
|
||||
// c++-ified comments.
|
||||
//
|
||||
// Revision 1.13 1998/09/29 02:01:09 curt
|
||||
// Added a "rate of climb" indicator.
|
||||
//
|
||||
// Revision 1.12 1998/08/24 20:05:17 curt
|
||||
// Added a second minimalistic HUD.
|
||||
// Added code to display the number of triangles rendered.
|
||||
//
|
||||
// Revision 1.11 1998/07/24 21:36:55 curt
|
||||
// Ran dos2unix to get rid of extraneous ^M's. Tweaked parameter in
|
||||
// ImageGetRawData() to match usage.
|
||||
//
|
||||
// Revision 1.10 1998/07/13 21:28:02 curt
|
||||
// Converted the aoa scale to a radio altimeter.
|
||||
//
|
||||
// Revision 1.9 1998/07/13 21:00:48 curt
|
||||
// Integrated Charlies latest HUD updates.
|
||||
// Wrote access functions for current fgOPTIONS.
|
||||
//
|
||||
// Revision 1.8 1998/07/03 13:16:29 curt
|
||||
// Added Charlie Hotchkiss's HUD updates and improvementes.
|
||||
//
|
||||
// Revision 1.6 1998/06/03 00:43:28 curt
|
||||
// No .h when including stl stuff.
|
||||
//
|
||||
// Revision 1.5 1998/05/17 16:58:13 curt
|
||||
// Added a View Frustum Culling ratio display to the hud.
|
||||
//
|
||||
// Revision 1.4 1998/05/16 13:04:15 curt
|
||||
// New updates from Charlie Hotchkiss.
|
||||
//
|
||||
// Revision 1.3 1998/05/13 18:27:55 curt
|
||||
// Added an fov to hud display.
|
||||
//
|
||||
// Revision 1.2 1998/05/11 18:13:12 curt
|
||||
// Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
|
||||
//
|
||||
// Revision 1.15 1998/02/23 19:07:57 curt
|
||||
// Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
// calculation code between sun display, and other FG sections that use this
|
||||
// for things like lighting.
|
||||
//
|
||||
// Revision 1.14 1998/02/21 14:53:14 curt
|
||||
// Added Charlie's HUD changes.
|
||||
//
|
||||
// Revision 1.13 1998/02/20 00:16:22 curt
|
||||
// Thursday's tweaks.
|
||||
//
|
||||
// Revision 1.12 1998/02/19 13:05:52 curt
|
||||
// Incorporated some HUD tweaks from Michelle America.
|
||||
// Tweaked the sky's sunset/rise colors.
|
||||
// Other misc. tweaks.
|
||||
//
|
||||
// Revision 1.11 1998/02/16 13:38:42 curt
|
||||
// Integrated changes from Charlie Hotchkiss.
|
||||
//
|
||||
// Revision 1.11 1998/02/16 13:38:42 curt
|
||||
// Integrated changes from Charlie Hotchkiss.
|
||||
//
|
||||
// Revision 1.10 1998/02/12 21:59:42 curt
|
||||
// Incorporated code changes contributed by Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.8 1998/02/07 15:29:35 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.7 1998/02/03 23:20:15 curt
|
||||
// Lots of little tweaks to fix various consistency problems discovered by
|
||||
// Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
|
||||
// passed arguments along to the real printf(). Also incorporated HUD changes
|
||||
// by Michele America.
|
||||
//
|
||||
// Revision 1.6 1998/01/22 02:59:30 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.5 1998/01/19 19:27:01 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.4 1998/01/19 18:40:21 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.3 1997/12/30 16:36:41 curt
|
||||
// Merged in Durk's changes ...
|
||||
//
|
||||
// Revision 1.2 1997/12/10 22:37:40 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.1 1997/08/29 18:03:22 curt
|
||||
// Initial revision.
|
||||
//
|
386
Simulator/Cockpit/hud_card.cxx
Normal file
386
Simulator/Cockpit/hud_card.cxx
Normal file
|
@ -0,0 +1,386 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
//========== Top of hud_card class member definitions =============
|
||||
|
||||
hud_card ::
|
||||
hud_card( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR data_source,
|
||||
UINT options,
|
||||
double max_value,
|
||||
double min_value,
|
||||
double disp_scaling,
|
||||
UINT major_divs,
|
||||
UINT minor_divs,
|
||||
UINT modulus,
|
||||
int dp_showing,
|
||||
double value_span,
|
||||
bool working) :
|
||||
instr_scale( x,y,width,height,
|
||||
data_source, options,
|
||||
value_span,
|
||||
max_value, min_value, disp_scaling,
|
||||
major_divs, minor_divs, modulus,
|
||||
working),
|
||||
val_span ( value_span)
|
||||
{
|
||||
half_width_units = range_to_show() / 2.0;
|
||||
}
|
||||
|
||||
hud_card ::
|
||||
~hud_card() { }
|
||||
|
||||
hud_card ::
|
||||
hud_card( const hud_card & image):
|
||||
instr_scale( (const instr_scale & ) image),
|
||||
val_span( image.val_span),
|
||||
half_width_units (image.half_width_units)
|
||||
{
|
||||
}
|
||||
|
||||
hud_card & hud_card ::
|
||||
operator = (const hud_card & rhs )
|
||||
{
|
||||
if( !( this == &rhs)){
|
||||
instr_scale::operator = (rhs);
|
||||
val_span = rhs.val_span;
|
||||
half_width_units = rhs.half_width_units;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void hud_card ::
|
||||
draw( void ) // (HUD_scale * pscale )
|
||||
{
|
||||
double vmin, vmax;
|
||||
int marker_xs;
|
||||
int marker_xe;
|
||||
int marker_ys;
|
||||
int marker_ye;
|
||||
/* register */ int i;
|
||||
char TextScale[80];
|
||||
bool condition;
|
||||
int disp_val = 0;
|
||||
POINT mid_scr = get_centroid();
|
||||
double cur_value = get_value();
|
||||
RECT scrn_rect = get_location();
|
||||
UINT options = get_options();
|
||||
|
||||
vmin = cur_value - half_width_units; // width units == needle travel
|
||||
vmax = cur_value + half_width_units; // or picture unit span.
|
||||
// Draw the basic markings for the scale...
|
||||
|
||||
if( options & HUDS_VERT ) { // Vertical scale
|
||||
drawOneLine( scrn_rect.left, // Bottom tick bar
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top);
|
||||
|
||||
drawOneLine( scrn_rect.left, // Top tick bar
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom );
|
||||
|
||||
marker_xs = scrn_rect.left;
|
||||
marker_xe = scrn_rect.left + scrn_rect.right;
|
||||
|
||||
// We do not use else in the following so that combining the two
|
||||
// options produces a "caged" display with double carrots. The
|
||||
// same is done for horizontal card indicators.
|
||||
|
||||
if( options & HUDS_LEFT ) { // Calculate x marker offset
|
||||
drawOneLine( scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom); // Cap right side
|
||||
|
||||
marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
|
||||
// Indicator carrot
|
||||
drawOneLine( marker_xs, mid_scr.y,
|
||||
marker_xe, mid_scr.y + scrn_rect.right / 6);
|
||||
drawOneLine( marker_xs, mid_scr.y,
|
||||
marker_xe, mid_scr.y - scrn_rect.right / 6);
|
||||
|
||||
}
|
||||
if( options & HUDS_RIGHT ) { // We'll default this for now.
|
||||
drawOneLine( scrn_rect.left,
|
||||
scrn_rect.top,
|
||||
scrn_rect.left,
|
||||
scrn_rect.top + scrn_rect.bottom); // Cap left side
|
||||
|
||||
marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
|
||||
// Indicator carrot
|
||||
drawOneLine( scrn_rect.left, mid_scr.y + scrn_rect.right / 6,
|
||||
marker_xe, mid_scr.y );
|
||||
drawOneLine( scrn_rect.left, mid_scr.y - scrn_rect.right / 6,
|
||||
marker_xe, mid_scr.y);
|
||||
}
|
||||
|
||||
// At this point marker x_start and x_end values are transposed.
|
||||
// To keep this from confusing things they are now interchanged.
|
||||
if(( options & HUDS_BOTH) == HUDS_BOTH) {
|
||||
marker_ye = marker_xs;
|
||||
marker_xs = marker_xe;
|
||||
marker_xe = marker_ye;
|
||||
}
|
||||
|
||||
// Work through from bottom to top of scale. Calculating where to put
|
||||
// minor and major ticks.
|
||||
|
||||
for( i = (int)vmin; i <= (int)vmax; i++ ) {
|
||||
condition = true;
|
||||
if( !modulo()) {
|
||||
if( i < min_val()) {
|
||||
condition = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( condition ) { // Show a tick if necessary
|
||||
// Calculate the location of this tick
|
||||
marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
|
||||
|
||||
// Block calculation artifact from drawing ticks below min coordinate.
|
||||
// Calculation here accounts for text height.
|
||||
|
||||
if(( marker_ys < (scrn_rect.top + 4)) |
|
||||
( marker_ys > (scrn_rect.top + scrn_rect.bottom - 4))) {
|
||||
// Magic numbers!!!
|
||||
continue;
|
||||
}
|
||||
if( div_min()) {
|
||||
if( (i%div_min()) == 0) {
|
||||
if((( marker_ys - 5) > scrn_rect.top ) &&
|
||||
(( marker_ys + 5) < (scrn_rect.top + scrn_rect.bottom))){
|
||||
if( (options & HUDS_BOTH) == HUDS_BOTH ) {
|
||||
drawOneLine( scrn_rect.left, marker_ys,
|
||||
marker_xs, marker_ys );
|
||||
drawOneLine( marker_xe, marker_ys,
|
||||
scrn_rect.left + scrn_rect.right, marker_ys );
|
||||
}
|
||||
else {
|
||||
if( options & HUDS_LEFT ) {
|
||||
drawOneLine( marker_xs + 4, marker_ys,
|
||||
marker_xe, marker_ys );
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys,
|
||||
marker_xe - 4, marker_ys );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( div_max()) {
|
||||
if( !(i%(int)div_max())){
|
||||
if(modulo()) {
|
||||
if( disp_val < 0) {
|
||||
disp_val += modulo();
|
||||
}
|
||||
else {
|
||||
disp_val = i % modulo();
|
||||
}
|
||||
}
|
||||
else {
|
||||
disp_val = i;
|
||||
}
|
||||
sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
|
||||
if(( (marker_ys - 8 ) > scrn_rect.top ) &&
|
||||
( (marker_ys + 8) < (scrn_rect.top + scrn_rect.bottom))){
|
||||
if( (options & HUDS_BOTH) == HUDS_BOTH) {
|
||||
drawOneLine( scrn_rect.left, marker_ys,
|
||||
marker_xs, marker_ys);
|
||||
drawOneLine( marker_xs, marker_ys,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
marker_ys);
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
textString ( marker_xs + 2, marker_ys,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
if( options & HUDS_LEFT ) {
|
||||
textString( marker_xs - 8 * strlen(TextScale) - 2,
|
||||
marker_ys - 4,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
else {
|
||||
textString( marker_xe + 3 * strlen(TextScale),
|
||||
marker_ys - 4,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
}
|
||||
} // Else read oriented right
|
||||
} // End if modulo division by major interval is zero
|
||||
} // End if major interval divisor non-zero
|
||||
} // End if condition
|
||||
} // End for range of i from vmin to vmax
|
||||
} // End if VERTICAL SCALE TYPE
|
||||
else { // Horizontal scale by default
|
||||
drawOneLine( scrn_rect.left, // left tick bar
|
||||
scrn_rect.top,
|
||||
scrn_rect.left,
|
||||
scrn_rect.top + scrn_rect.bottom);
|
||||
|
||||
drawOneLine( scrn_rect.left + scrn_rect.right, // right tick bar
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom );
|
||||
|
||||
marker_ys = scrn_rect.top; // Starting point for
|
||||
marker_ye = scrn_rect.top + scrn_rect.bottom; // tick y location calcs
|
||||
|
||||
if( options & HUDS_TOP ) {
|
||||
drawOneLine( scrn_rect.left,
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top); // Bottom box line
|
||||
|
||||
marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
|
||||
// Bottom arrow
|
||||
drawOneLine( mid_scr.x, marker_ye,
|
||||
mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
|
||||
drawOneLine( mid_scr.x, marker_ye,
|
||||
mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
|
||||
}
|
||||
if( options & HUDS_BOTTOM) {
|
||||
drawOneLine( scrn_rect.left,
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom); // Top box line
|
||||
// Tick point adjust
|
||||
marker_ys = scrn_rect.top +
|
||||
scrn_rect.bottom - scrn_rect.bottom / 2;
|
||||
// Top arrow
|
||||
drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
mid_scr.x ,
|
||||
marker_ys );
|
||||
drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
mid_scr.x ,
|
||||
marker_ys );
|
||||
}
|
||||
|
||||
// if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
|
||||
// marker_xe = marker_ys;
|
||||
// marker_ys = marker_ye;
|
||||
// marker_ye = marker_xe;
|
||||
// }
|
||||
|
||||
// printf("vmin = %d vmax = %d\n", (int)vmin, (int)vmax);
|
||||
for( i = (int)vmin; i <= (int)vmax; i++ ) {
|
||||
// printf("<*> i = %d\n", i);
|
||||
condition = true;
|
||||
if( !modulo()) {
|
||||
if( i < min_val()) {
|
||||
condition = false;
|
||||
}
|
||||
}
|
||||
// printf("<**> i = %d\n", i);
|
||||
if( condition ) {
|
||||
marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
|
||||
if( div_min()){
|
||||
if( (i%(int)div_min()) == 0 ) {
|
||||
// draw in ticks only if they aren't too close to the edge.
|
||||
if((( marker_xs - 5) > scrn_rect.left ) &&
|
||||
(( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
|
||||
|
||||
if( (options & HUDS_BOTH) == HUDS_BOTH ) {
|
||||
drawOneLine( marker_xs, scrn_rect.top,
|
||||
marker_xs, marker_ys - 4);
|
||||
drawOneLine( marker_xs, marker_ye + 4,
|
||||
marker_xs, scrn_rect.top + scrn_rect.bottom);
|
||||
}
|
||||
else {
|
||||
if( options & HUDS_TOP) {
|
||||
drawOneLine( marker_xs, marker_ys,
|
||||
marker_xs, marker_ye - 4);
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys + 4,
|
||||
marker_xs, marker_ye);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// printf("<***> i = %d\n", i);
|
||||
if( div_max()) {
|
||||
// printf("i = %d\n", i);
|
||||
if( (i%(int)div_max())==0 ) {
|
||||
if(modulo()) {
|
||||
if( disp_val < 0) {
|
||||
disp_val += modulo();
|
||||
}
|
||||
else {
|
||||
disp_val = i % modulo();
|
||||
}
|
||||
}
|
||||
else {
|
||||
disp_val = i;
|
||||
}
|
||||
// printf("disp_val = %d\n", disp_val);
|
||||
// printf("%d\n", (int)(disp_val * (double)data_scaling() + 0.5));
|
||||
sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
|
||||
// Draw major ticks and text only if far enough from the edge.
|
||||
if(( (marker_xs - 10)> scrn_rect.left ) &&
|
||||
( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
|
||||
if( (options & HUDS_BOTH) == HUDS_BOTH) {
|
||||
drawOneLine( marker_xs, scrn_rect.top,
|
||||
marker_xs, marker_ys);
|
||||
drawOneLine( marker_xs, marker_ye,
|
||||
marker_xs, scrn_rect.top + scrn_rect.bottom);
|
||||
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
textString ( marker_xs - 4 * strlen(TextScale),
|
||||
marker_ys + 4,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys,
|
||||
marker_xs, marker_ye );
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
if( options & HUDS_TOP ) {
|
||||
textString ( marker_xs - 4 * strlen(TextScale),
|
||||
scrn_rect.top + scrn_rect.bottom - 10,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
else {
|
||||
textString( marker_xs - 4 * strlen(TextScale),
|
||||
scrn_rect.top,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// printf("<****> i = %d\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
Simulator/Cockpit/hud_dnst.cxx
Normal file
56
Simulator/Cockpit/hud_dnst.cxx
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
|
||||
//============ Top of dual_instr_item class member definitions ============
|
||||
|
||||
dual_instr_item ::
|
||||
dual_instr_item ( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR chn1_source,
|
||||
DBLFNPTR chn2_source,
|
||||
bool working,
|
||||
UINT options ):
|
||||
instr_item( x, y, width, height,
|
||||
chn1_source, options, working),
|
||||
alt_data_source( chn2_source )
|
||||
{
|
||||
}
|
||||
|
||||
dual_instr_item ::
|
||||
dual_instr_item( const dual_instr_item & image) :
|
||||
instr_item ((instr_item &) image ),
|
||||
alt_data_source( image.alt_data_source)
|
||||
{
|
||||
}
|
||||
|
||||
dual_instr_item & dual_instr_item ::
|
||||
operator = (const dual_instr_item & rhs )
|
||||
{
|
||||
if( !(this == &rhs)) {
|
||||
instr_item::operator = (rhs);
|
||||
alt_data_source = rhs.alt_data_source;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// End of hud_dnst.cxx
|
||||
|
356
Simulator/Cockpit/hud_guag.cxx
Normal file
356
Simulator/Cockpit/hud_guag.cxx
Normal file
|
@ -0,0 +1,356 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
//============== Top of guage_instr class member definitions ==============
|
||||
|
||||
guage_instr ::
|
||||
guage_instr( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR load_fn,
|
||||
UINT options,
|
||||
double disp_scale,
|
||||
double maxValue,
|
||||
double minValue,
|
||||
UINT major_divs,
|
||||
UINT minor_divs,
|
||||
int dp_showing,
|
||||
UINT modulus,
|
||||
bool working) :
|
||||
instr_scale( x, y, width, height,
|
||||
load_fn, options,
|
||||
(maxValue - minValue), // Always shows span?
|
||||
maxValue, minValue,
|
||||
disp_scale,
|
||||
major_divs, minor_divs,
|
||||
modulus, dp_showing,
|
||||
working)
|
||||
{
|
||||
}
|
||||
|
||||
guage_instr ::
|
||||
~guage_instr()
|
||||
{
|
||||
}
|
||||
|
||||
guage_instr ::
|
||||
guage_instr( const guage_instr & image):
|
||||
instr_scale( (instr_scale &) image)
|
||||
{
|
||||
}
|
||||
|
||||
guage_instr & guage_instr ::
|
||||
operator = (const guage_instr & rhs )
|
||||
{
|
||||
if( !(this == &rhs)) {
|
||||
instr_scale::operator = (rhs);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// As implemented, draw only correctly draws a horizontal or vertical
|
||||
// scale. It should contain a variation that permits clock type displays.
|
||||
// Now is supports "tickless" displays such as control surface indicators.
|
||||
// This routine should be worked over before using. Current value would be
|
||||
// fetched and not used if not commented out. Clearly that is intollerable.
|
||||
|
||||
void guage_instr :: draw (void)
|
||||
{
|
||||
int marker_xs, marker_xe;
|
||||
int marker_ys, marker_ye;
|
||||
int text_x, text_y;
|
||||
int i;
|
||||
char TextScale[80];
|
||||
bool condition;
|
||||
int disp_val;
|
||||
double vmin = min_val();
|
||||
double vmax = max_val();
|
||||
POINT mid_scr = get_centroid();
|
||||
double cur_value = get_value();
|
||||
RECT scrn_rect = get_location();
|
||||
UINT options = get_options();
|
||||
|
||||
// Draw the basic markings for the scale...
|
||||
|
||||
if( options & HUDS_VERT ) { // Vertical scale
|
||||
drawOneLine( scrn_rect.left, // Bottom tick bar
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top);
|
||||
|
||||
drawOneLine( scrn_rect.left, // Top tick bar
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom );
|
||||
|
||||
marker_xs = scrn_rect.left;
|
||||
marker_xe = scrn_rect.left + scrn_rect.right;
|
||||
|
||||
if( options & HUDS_LEFT ) { // Read left, so line down right side
|
||||
drawOneLine( scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom);
|
||||
|
||||
marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
|
||||
}
|
||||
if( options & HUDS_RIGHT ) { // Read right, so down left sides
|
||||
drawOneLine( scrn_rect.left,
|
||||
scrn_rect.top,
|
||||
scrn_rect.left,
|
||||
scrn_rect.top + scrn_rect.bottom);
|
||||
marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
|
||||
}
|
||||
|
||||
// At this point marker x_start and x_end values are transposed.
|
||||
// To keep this from confusing things they are now interchanged.
|
||||
if(( options & HUDS_BOTH) == HUDS_BOTH) {
|
||||
marker_ye = marker_xs;
|
||||
marker_xs = marker_xe;
|
||||
marker_xe = marker_ye;
|
||||
}
|
||||
|
||||
// Work through from bottom to top of scale. Calculating where to put
|
||||
// minor and major ticks.
|
||||
|
||||
if( !(options & HUDS_NOTICKS )) { // If not no ticks...:)
|
||||
// Calculate x marker offsets
|
||||
for( i = (int)vmin; i <= (int)vmax; i++ ) {
|
||||
|
||||
// Calculate the location of this tick
|
||||
marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
|
||||
|
||||
// We compute marker_ys even though we don't know if we will use
|
||||
// either major or minor divisions. Simpler.
|
||||
|
||||
if( div_min()) { // Minor tick marks
|
||||
if( (i%div_min()) == 0) {
|
||||
if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
|
||||
drawOneLine( scrn_rect.left, marker_ys,
|
||||
marker_xs - 3, marker_ys );
|
||||
drawOneLine( marker_xe + 3, marker_ys,
|
||||
scrn_rect.left + scrn_rect.right, marker_ys );
|
||||
}
|
||||
else {
|
||||
if( options & HUDS_LEFT) {
|
||||
drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now we work on the major divisions. Since these are also labeled
|
||||
// and no labels are drawn otherwise, we label inside this if
|
||||
// statement.
|
||||
|
||||
if( div_max()) { // Major tick mark
|
||||
if( (i%div_max()) == 0 ) {
|
||||
if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
|
||||
|
||||
drawOneLine( scrn_rect.left, marker_ys,
|
||||
marker_xs, marker_ys );
|
||||
drawOneLine( marker_xe, marker_ys,
|
||||
scrn_rect.left + scrn_rect.right, marker_ys );
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
|
||||
}
|
||||
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
disp_val = i;
|
||||
sprintf( TextScale, "%d",disp_val * (int)(data_scaling() +.5));
|
||||
|
||||
if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
|
||||
text_x = mid_scr.x - 2 - ((3 * strlen( TextScale ))>>1);
|
||||
}
|
||||
else {
|
||||
if( options & HUDS_LEFT ) {
|
||||
text_x = marker_xs - 2 - 3 * strlen( TextScale);
|
||||
}
|
||||
else {
|
||||
text_x = marker_xe + 10 - strlen( TextScale );
|
||||
}
|
||||
}
|
||||
// Now we know where to put the text.
|
||||
text_y = marker_ys;
|
||||
textString( text_x, text_y, TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
} //
|
||||
} //
|
||||
} //
|
||||
// Now that the scale is drawn, we draw in the pointer(s). Since labels
|
||||
// have been drawn, text_x and text_y may be recycled. This is used
|
||||
// with the marker start stops to produce a pointer for each side reading
|
||||
|
||||
text_y = scrn_rect.top + (int)((cur_value - vmin) * factor() + .5);
|
||||
// text_x = marker_xs - scrn_rect.left;
|
||||
|
||||
if( options & HUDS_RIGHT ) {
|
||||
drawOneLine(scrn_rect.left, text_y + 5,
|
||||
marker_xe, text_y);
|
||||
drawOneLine(scrn_rect.left, text_y - 5,
|
||||
marker_xe, text_y);
|
||||
}
|
||||
if( options & HUDS_LEFT ) {
|
||||
drawOneLine(scrn_rect.left + scrn_rect.right, text_y + 5,
|
||||
marker_xs, text_y);
|
||||
drawOneLine(scrn_rect.left + scrn_rect.right, text_y - 5,
|
||||
marker_xs, text_y);
|
||||
}
|
||||
} // End if VERTICAL SCALE TYPE
|
||||
else { // Horizontal scale by default
|
||||
drawOneLine( scrn_rect.left, // left tick bar
|
||||
scrn_rect.top,
|
||||
scrn_rect.left,
|
||||
scrn_rect.top + scrn_rect.bottom);
|
||||
|
||||
drawOneLine( scrn_rect.left + scrn_rect.right, // right tick bar
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom );
|
||||
|
||||
marker_ys = scrn_rect.top; // Starting point for
|
||||
marker_ye = scrn_rect.top + scrn_rect.bottom; // tick y location calcs
|
||||
marker_xs = scrn_rect.left + (int)((cur_value - vmin) * factor() + .5);
|
||||
|
||||
if( options & HUDS_TOP ) {
|
||||
drawOneLine( scrn_rect.left,
|
||||
scrn_rect.top,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top); // Bottom box line
|
||||
|
||||
marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
|
||||
// Bottom arrow
|
||||
drawOneLine( marker_xs, marker_ye,
|
||||
marker_xs - scrn_rect.bottom / 4, scrn_rect.top);
|
||||
drawOneLine( marker_xs, marker_ye,
|
||||
marker_xs + scrn_rect.bottom / 4, scrn_rect.top);
|
||||
}
|
||||
if( options & HUDS_BOTTOM) {
|
||||
drawOneLine( scrn_rect.left,
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
scrn_rect.left + scrn_rect.right,
|
||||
scrn_rect.top + scrn_rect.bottom); // Top box line
|
||||
// Tick point adjust
|
||||
marker_ys = scrn_rect.top +
|
||||
scrn_rect.bottom - scrn_rect.bottom / 2;
|
||||
// Top arrow
|
||||
drawOneLine( marker_xs + scrn_rect.bottom / 4,
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
marker_xs,
|
||||
marker_ys );
|
||||
drawOneLine( marker_xs - scrn_rect.bottom / 4,
|
||||
scrn_rect.top + scrn_rect.bottom,
|
||||
marker_xs ,
|
||||
marker_ys );
|
||||
}
|
||||
|
||||
for( i = (int)vmin; i <= (int)vmax; i++ ) {
|
||||
condition = true;
|
||||
if( !modulo()) {
|
||||
if( i < min_val()) {
|
||||
condition = false;
|
||||
}
|
||||
}
|
||||
if( condition ) {
|
||||
marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
|
||||
if( div_min()){
|
||||
if( (i%(int)div_min()) == 0 ) {
|
||||
// draw in ticks only if they aren't too close to the edge.
|
||||
if((( marker_xs + 5) > scrn_rect.left ) ||
|
||||
(( marker_xs - 5 )< (scrn_rect.left + scrn_rect.right))){
|
||||
|
||||
if( (options & HUDS_BOTH) == HUDS_BOTH ) {
|
||||
drawOneLine( marker_xs, scrn_rect.top,
|
||||
marker_xs, marker_ys - 4);
|
||||
drawOneLine( marker_xs, marker_ye + 4,
|
||||
marker_xs, scrn_rect.top + scrn_rect.bottom);
|
||||
}
|
||||
else {
|
||||
if( options & HUDS_TOP) {
|
||||
drawOneLine( marker_xs, marker_ys,
|
||||
marker_xs, marker_ye - 4);
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys + 4,
|
||||
marker_xs, marker_ye);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( div_max()) {
|
||||
if( (i%(int)div_max())==0 ) {
|
||||
if(modulo()) {
|
||||
if( disp_val < 0) {
|
||||
disp_val += modulo();
|
||||
}
|
||||
else {
|
||||
disp_val = i % modulo();
|
||||
}
|
||||
}
|
||||
else {
|
||||
disp_val = i;
|
||||
}
|
||||
sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
|
||||
// Draw major ticks and text only if far enough from the edge.
|
||||
if(( (marker_xs - 10)> scrn_rect.left ) &&
|
||||
( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
|
||||
if( (options & HUDS_BOTH) == HUDS_BOTH) {
|
||||
drawOneLine( marker_xs, scrn_rect.top,
|
||||
marker_xs, marker_ys);
|
||||
drawOneLine( marker_xs, marker_ye,
|
||||
marker_xs, scrn_rect.top + scrn_rect.bottom);
|
||||
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
textString ( marker_xs - 4 * strlen(TextScale),
|
||||
marker_ys + 4,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawOneLine( marker_xs, marker_ys,
|
||||
marker_xs, marker_ye );
|
||||
if( !(options & HUDS_NOTEXT)) {
|
||||
if( options & HUDS_TOP ) {
|
||||
textString ( marker_xs - 4 * strlen(TextScale),
|
||||
scrn_rect.top + scrn_rect.bottom - 10,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
else {
|
||||
textString( marker_xs - 4 * strlen(TextScale),
|
||||
scrn_rect.top,
|
||||
TextScale, GLUT_BITMAP_8_BY_13 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
144
Simulator/Cockpit/hud_inst.cxx
Normal file
144
Simulator/Cockpit/hud_inst.cxx
Normal file
|
@ -0,0 +1,144 @@
|
|||
// Abstract Base Class instr_item
|
||||
//
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
|
||||
UINT instr_item :: instances = 0; // Initial value of zero
|
||||
int instr_item :: brightness = BRT_MEDIUM;
|
||||
glRGBTRIPLE instr_item :: color = {0.1, 0.7, 0.0};
|
||||
|
||||
// constructor ( No default provided )
|
||||
instr_item ::
|
||||
instr_item( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR data_source,
|
||||
double data_scaling,
|
||||
UINT options,
|
||||
bool working) :
|
||||
handle ( ++instances ),
|
||||
load_value_fn ( data_source ),
|
||||
disp_factor ( data_scaling ),
|
||||
opts ( options ),
|
||||
is_enabled ( working ),
|
||||
broken ( FALSE )
|
||||
{
|
||||
scrn_pos.left = x;
|
||||
scrn_pos.top = y;
|
||||
scrn_pos.right = width;
|
||||
scrn_pos.bottom = height;
|
||||
|
||||
// Set up convenience values for centroid of the box and
|
||||
// the span values according to orientation
|
||||
|
||||
if( opts & HUDS_VERT) { // Vertical style
|
||||
// Insure that the midpoint marker will fall exactly at the
|
||||
// middle of the bar.
|
||||
if( !(scrn_pos.bottom % 2)) {
|
||||
scrn_pos.bottom++;
|
||||
}
|
||||
scr_span = scrn_pos.bottom;
|
||||
}
|
||||
else {
|
||||
// Insure that the midpoint marker will fall exactly at the
|
||||
// middle of the bar.
|
||||
if( !(scrn_pos.right % 2)) {
|
||||
scrn_pos.right++;
|
||||
}
|
||||
scr_span = scrn_pos.right;
|
||||
}
|
||||
// Here we work out the centroid for the corrected box.
|
||||
mid_span.x = scrn_pos.left + (scrn_pos.right >> 1);
|
||||
mid_span.y = scrn_pos.top + (scrn_pos.bottom >> 1);
|
||||
}
|
||||
|
||||
|
||||
// copy constructor
|
||||
instr_item ::
|
||||
instr_item ( const instr_item & image ):
|
||||
handle ( ++instances ),
|
||||
scrn_pos ( image.scrn_pos ),
|
||||
load_value_fn( image.load_value_fn),
|
||||
disp_factor ( image.disp_factor ),
|
||||
opts ( image.opts ),
|
||||
is_enabled ( image.is_enabled ),
|
||||
broken ( image.broken ),
|
||||
scr_span ( image.scr_span ),
|
||||
mid_span ( image.mid_span )
|
||||
{
|
||||
}
|
||||
|
||||
// assignment operator
|
||||
|
||||
instr_item & instr_item :: operator = ( const instr_item & rhs )
|
||||
{
|
||||
if( !(this == &rhs )) { // Not an identity assignment
|
||||
scrn_pos = rhs.scrn_pos;
|
||||
load_value_fn = rhs.load_value_fn;
|
||||
disp_factor = rhs.disp_factor;
|
||||
opts = rhs.opts;
|
||||
is_enabled = rhs.is_enabled;
|
||||
broken = rhs.broken;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
instr_item :: ~instr_item ()
|
||||
{
|
||||
if( instances ) {
|
||||
instances--;
|
||||
}
|
||||
}
|
||||
|
||||
void instr_item ::
|
||||
update( void )
|
||||
{
|
||||
}
|
||||
|
||||
// break_display This is emplaced to provide hooks for making
|
||||
// instruments unreliable. The default behavior is
|
||||
// to simply not display, but more sophisticated behavior is available
|
||||
// by over riding the function which is virtual in this class.
|
||||
|
||||
void instr_item ::
|
||||
break_display ( bool bad )
|
||||
{
|
||||
broken = !!bad;
|
||||
is_enabled = FALSE;
|
||||
}
|
||||
|
||||
void instr_item ::
|
||||
SetBrightness ( int level )
|
||||
{
|
||||
brightness = level; // This is all we will do for now. Later the
|
||||
// brightness levels will be sensitive both to
|
||||
// the control knob and the outside light levels
|
||||
// to emulated night vision effects.
|
||||
}
|
||||
|
||||
UINT instr_item :: get_Handle( void )
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
|
144
Simulator/Cockpit/hud_labl.cxx
Normal file
144
Simulator/Cockpit/hud_labl.cxx
Normal file
|
@ -0,0 +1,144 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
|
||||
//======================= Top of instr_label class =========================
|
||||
instr_label ::
|
||||
instr_label( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR data_source,
|
||||
const char *label_format,
|
||||
const char *pre_label_string,
|
||||
const char *post_label_string,
|
||||
double scale_data,
|
||||
UINT options,
|
||||
fgLabelJust justification,
|
||||
int font_size,
|
||||
int blinking,
|
||||
bool working ):
|
||||
instr_item( x, y, width, height,
|
||||
data_source, scale_data,options, working ),
|
||||
pformat ( label_format ),
|
||||
pre_str ( pre_label_string ),
|
||||
post_str ( post_label_string ),
|
||||
justify ( justification ),
|
||||
fontSize ( font_size ),
|
||||
blink ( blinking )
|
||||
{
|
||||
}
|
||||
|
||||
// I put this in to make it easy to construct a class member using the current
|
||||
// C code.
|
||||
|
||||
|
||||
instr_label :: ~instr_label()
|
||||
{
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
instr_label :: instr_label( const instr_label & image) :
|
||||
instr_item((const instr_item &)image),
|
||||
pformat ( image.pformat ),
|
||||
pre_str ( image.pre_str ),
|
||||
post_str ( image.post_str ),
|
||||
blink ( image.blink )
|
||||
{
|
||||
}
|
||||
|
||||
instr_label & instr_label ::operator = (const instr_label & rhs )
|
||||
{
|
||||
if( !(this == &rhs)) {
|
||||
instr_item::operator = (rhs);
|
||||
pformat = rhs.pformat;
|
||||
fontSize = rhs.fontSize;
|
||||
blink = rhs.blink;
|
||||
justify = rhs.justify;
|
||||
pre_str = rhs.pre_str;
|
||||
post_str = rhs.post_str;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// draw Draws a label anywhere in the HUD
|
||||
//
|
||||
//
|
||||
void instr_label ::
|
||||
draw( void ) // Required method in base class
|
||||
{
|
||||
char format_buffer[80];
|
||||
char label_buffer[80];
|
||||
int posincr;
|
||||
int lenstr;
|
||||
RECT scrn_rect = get_location();
|
||||
|
||||
if( pre_str != NULL) {
|
||||
if( post_str != NULL ) {
|
||||
sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
|
||||
}
|
||||
else {
|
||||
sprintf( format_buffer, "%s%s", pre_str, pformat );
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( post_str != NULL ) {
|
||||
sprintf( format_buffer, "%s%s", pformat, post_str );
|
||||
}
|
||||
} // else do nothing if both pre and post strings are nulls. Interesting.
|
||||
|
||||
if( data_available() ) {
|
||||
sprintf( label_buffer, format_buffer, get_value() );
|
||||
}
|
||||
else {
|
||||
sprintf( label_buffer, format_buffer );
|
||||
}
|
||||
|
||||
#ifdef DEBUGHUD
|
||||
fgPrintf( FG_COCKPIT, FG_DEBUG, format_buffer );
|
||||
fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
|
||||
fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
|
||||
fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
|
||||
#endif
|
||||
lenstr = strlen( label_buffer );
|
||||
|
||||
posincr = 0; // default to RIGHT_JUST ... center located calc: -lenstr*8;
|
||||
|
||||
if( justify == CENTER_JUST ) {
|
||||
posincr = - (lenstr << 2); // -lenstr*4;
|
||||
}
|
||||
else {
|
||||
if( justify == LEFT_JUST ) {
|
||||
posincr = - (lenstr << 8); // 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( fontSize == SMALL ) {
|
||||
textString( scrn_rect.left + posincr, scrn_rect.top,
|
||||
label_buffer, GLUT_BITMAP_8_BY_13);
|
||||
}
|
||||
else {
|
||||
if( fontSize == LARGE ) {
|
||||
textString( scrn_rect.left + posincr, scrn_rect.top,
|
||||
label_buffer, GLUT_BITMAP_9_BY_15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
299
Simulator/Cockpit/hud_ladr.cxx
Normal file
299
Simulator/Cockpit/hud_ladr.cxx
Normal file
|
@ -0,0 +1,299 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
//====================== Top of HudLadder Class =======================
|
||||
HudLadder ::
|
||||
HudLadder( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR ptch_source,
|
||||
DBLFNPTR roll_source,
|
||||
double span_units,
|
||||
double major_div,
|
||||
double minor_div,
|
||||
UINT screen_hole,
|
||||
UINT lbl_pos,
|
||||
bool working) :
|
||||
dual_instr_item( x, y, width, height,
|
||||
ptch_source,
|
||||
roll_source,
|
||||
working,
|
||||
HUDS_RIGHT),
|
||||
width_units ( span_units ),
|
||||
div_units ( major_div < 0? -major_div: major_div ),
|
||||
minor_div ( minor_div ),
|
||||
label_pos ( lbl_pos ),
|
||||
scr_hole ( screen_hole ),
|
||||
vmax ( span_units/2 ),
|
||||
vmin ( -vmax )
|
||||
{
|
||||
if( !width_units ) {
|
||||
width_units = 45;
|
||||
}
|
||||
factor = (double)get_span() / (double) width_units;
|
||||
}
|
||||
|
||||
HudLadder ::
|
||||
~HudLadder()
|
||||
{
|
||||
}
|
||||
|
||||
HudLadder ::
|
||||
HudLadder( const HudLadder & image ) :
|
||||
dual_instr_item( (dual_instr_item &) image),
|
||||
width_units ( image.width_units ),
|
||||
div_units ( image.div_units ),
|
||||
label_pos ( image.label_pos ),
|
||||
scr_hole ( image.scr_hole ),
|
||||
vmax ( image.vmax ),
|
||||
vmin ( image.vmin ),
|
||||
factor ( image.factor )
|
||||
{
|
||||
}
|
||||
HudLadder & HudLadder ::
|
||||
operator = ( const HudLadder & rhs )
|
||||
{
|
||||
if( !(this == &rhs)) {
|
||||
(dual_instr_item &)(*this) = (dual_instr_item &)rhs;
|
||||
width_units = rhs.width_units;
|
||||
div_units = rhs.div_units;
|
||||
label_pos = rhs.label_pos;
|
||||
scr_hole = rhs.scr_hole;
|
||||
vmax = rhs.vmax;
|
||||
vmin = rhs.vmin;
|
||||
factor = rhs.factor;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// Draws a climb ladder in the center of the HUD
|
||||
//
|
||||
|
||||
void HudLadder :: draw( void )
|
||||
{
|
||||
double roll_value;
|
||||
double pitch_value;
|
||||
int marker_y;
|
||||
int x_ini;
|
||||
int x_end;
|
||||
int y_ini;
|
||||
int y_end;
|
||||
int new_x_ini;
|
||||
int new_x_end;
|
||||
int new_y_ini;
|
||||
int new_y_end;
|
||||
int i;
|
||||
POINT centroid = get_centroid();
|
||||
RECT box = get_location();
|
||||
int scr_min = box.top;
|
||||
int half_span = box.right >> 1;
|
||||
char TextLadder[80];
|
||||
int condition;
|
||||
int label_length;
|
||||
roll_value = current_ch2();
|
||||
GLfloat sinRoll = sin( roll_value );
|
||||
GLfloat cosRoll = cos( roll_value );
|
||||
|
||||
pitch_value = current_ch1() * RAD_TO_DEG;
|
||||
vmin = pitch_value - (double)width_units/2.0;
|
||||
vmax = pitch_value + (double)width_units/2.0;
|
||||
|
||||
// Box the target.
|
||||
drawOneLine( centroid.x - 5, centroid.y, centroid.x, centroid.y + 5);
|
||||
drawOneLine( centroid.x, centroid.y + 5, centroid.x + 5, centroid.y);
|
||||
drawOneLine( centroid.x + 5, centroid.y, centroid.x, centroid.y - 5);
|
||||
drawOneLine( centroid.x, centroid.y - 5, centroid.x - 5, centroid.y);
|
||||
|
||||
for( i=(int)vmin; i<=(int)vmax; i++ ) { // Through integer pitch values...
|
||||
condition = 1;
|
||||
if( condition ) {
|
||||
marker_y = centroid.y + (int)(((double)(i - pitch_value) * factor) + .5);
|
||||
if( div_units ) {
|
||||
if( !(i % div_units )) { // At integral multiple of div
|
||||
sprintf( TextLadder, "%d", i );
|
||||
label_length = strlen( TextLadder );
|
||||
if( scr_hole == 0 ) {
|
||||
if( i ) {
|
||||
x_ini = centroid.x - half_span;
|
||||
}
|
||||
else { // Make zero point wider on left
|
||||
x_ini = centroid.x - half_span - 10;
|
||||
}
|
||||
y_ini = marker_y;
|
||||
x_end = centroid.x + half_span;
|
||||
y_end = marker_y;
|
||||
new_x_ini = centroid.x + (int)(
|
||||
(x_ini - centroid.x) * cosRoll -
|
||||
(y_ini - centroid.y) * sinRoll);
|
||||
new_y_ini = centroid.y + (int)( \
|
||||
(x_ini - centroid.x) * sinRoll + \
|
||||
(y_ini - centroid.y) * cosRoll);
|
||||
new_x_end = centroid.x + (int)( \
|
||||
(x_end - centroid.x) * cosRoll - \
|
||||
(y_end - centroid.y) * sinRoll);
|
||||
new_y_end = centroid.y + (int)( \
|
||||
(x_end - centroid.x) * sinRoll + \
|
||||
(y_end - centroid.y) * cosRoll);
|
||||
|
||||
if( i >= 0 ) { // Above zero draw solid lines
|
||||
drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
|
||||
}
|
||||
else { // Below zero draw dashed lines.
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple( 1, 0x00FF );
|
||||
drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
// Calculate the position of the left text and write it.
|
||||
new_x_ini = centroid.x + (int)(
|
||||
(x_ini - 8 * label_length- 4 - centroid.x) * cosRoll -
|
||||
(y_ini - 4 ) * sinRoll);
|
||||
new_y_ini = centroid.y + (int)(
|
||||
(x_ini - 8 * label_length- 4 - centroid.x) * sinRoll +
|
||||
(y_ini - 4 - centroid.y) * cosRoll);
|
||||
strokeString( new_x_ini , new_y_ini ,
|
||||
TextLadder, GLUT_STROKE_ROMAN,
|
||||
roll_value );
|
||||
|
||||
// Calculate the position of the right text and write it.
|
||||
new_x_end = centroid.x + (int)( \
|
||||
(x_end + 24 - 8 * label_length - centroid.x) * cosRoll - \
|
||||
(y_end - 4 - centroid.y) * sinRoll);
|
||||
new_y_end = centroid.y + (int)( \
|
||||
(x_end + 24 - 8 * label_length - centroid.x) * sinRoll + \
|
||||
(y_end - 4 - centroid.y) * cosRoll);
|
||||
strokeString( new_x_end, new_y_end,
|
||||
TextLadder, GLUT_STROKE_ROMAN,
|
||||
roll_value );
|
||||
}
|
||||
else { // Draw ladder with space in the middle of the lines
|
||||
// Start by calculating the points and drawing the
|
||||
// left side lines.
|
||||
if( i != 0 ) {
|
||||
x_ini = centroid.x - half_span;
|
||||
}
|
||||
else {
|
||||
x_ini = centroid.x - half_span - 10;
|
||||
}
|
||||
y_ini = marker_y;
|
||||
x_end = centroid.x - half_span + scr_hole/2;
|
||||
y_end = marker_y;
|
||||
|
||||
new_x_end = centroid.x+ (int)( \
|
||||
(x_end - centroid.x) * cosRoll -\
|
||||
(y_end - centroid.y) * sinRoll);
|
||||
new_y_end = centroid.y+ (int)( \
|
||||
(x_end - centroid.x) * sinRoll +\
|
||||
(y_end - centroid.y) * cosRoll);
|
||||
new_x_ini = centroid.x + (int)( \
|
||||
(x_ini - centroid.x) * cosRoll -\
|
||||
(y_ini - centroid.y) * sinRoll);
|
||||
new_y_ini = centroid.y + (int)( \
|
||||
(x_ini - centroid.x) * sinRoll +\
|
||||
(y_ini - centroid.y) * cosRoll);
|
||||
|
||||
if( i >= 0 )
|
||||
{
|
||||
drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
|
||||
}
|
||||
else {
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple( 1, 0x00FF );
|
||||
drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
// Now calculate the location of the left side label using
|
||||
// the previously calculated start of the left side line.
|
||||
|
||||
x_ini = x_ini - (label_length + 32 + centroid.x);
|
||||
if( i < 0) {
|
||||
x_ini -= 8;
|
||||
}
|
||||
else {
|
||||
if( i == 0 ) {
|
||||
x_ini += 20;
|
||||
}
|
||||
}
|
||||
y_ini = y_ini - ( 4 + centroid.y);
|
||||
|
||||
new_x_ini = centroid.x + (int)(x_ini * cosRoll - y_ini * sinRoll);
|
||||
new_y_ini = centroid.y + (int)(x_ini * sinRoll + y_ini * cosRoll);
|
||||
strokeString( new_x_ini , new_y_ini ,
|
||||
TextLadder, GLUT_STROKE_MONO_ROMAN,
|
||||
roll_value );
|
||||
|
||||
// Now calculate and draw the right side line location
|
||||
x_ini = centroid.x + half_span - scr_hole/2;
|
||||
y_ini = marker_y;
|
||||
if( i != 0 ) {
|
||||
x_end = centroid.x + half_span;
|
||||
}
|
||||
else {
|
||||
x_end = centroid.x + half_span + 10;
|
||||
}
|
||||
y_end = marker_y;
|
||||
|
||||
new_x_ini = centroid.x + (int)( \
|
||||
(x_ini-centroid.x)*cosRoll -\
|
||||
(y_ini-centroid.y)*sinRoll);
|
||||
new_y_ini = centroid.y + (int)( \
|
||||
(x_ini-centroid.x)*sinRoll +\
|
||||
(y_ini-centroid.y)*cosRoll);
|
||||
new_x_end = centroid.x + (int)( \
|
||||
(x_end-centroid.x)*cosRoll -\
|
||||
(y_end-centroid.y)*sinRoll);
|
||||
new_y_end = centroid.y + (int)( \
|
||||
(x_end-centroid.x)*sinRoll +\
|
||||
(y_end-centroid.y)*cosRoll);
|
||||
|
||||
if( i >= 0 )
|
||||
{
|
||||
drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
|
||||
}
|
||||
else
|
||||
{
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple( 1, 0x00FF );
|
||||
drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
|
||||
// Calculate the location and draw the right side label
|
||||
// using the end of the line as previously calculated.
|
||||
x_end -= centroid.x + label_length - 24;
|
||||
if( i < 0 ) {
|
||||
x_end -= 8;
|
||||
}
|
||||
y_end = marker_y - ( 4 + centroid.y);
|
||||
new_x_end = centroid.x + (int)( (GLfloat)x_end * cosRoll -
|
||||
(GLfloat)y_end * sinRoll);
|
||||
new_y_end = centroid.y + (int)( (GLfloat)x_end * sinRoll +
|
||||
(GLfloat)y_end * cosRoll);
|
||||
strokeString( new_x_end, new_y_end,
|
||||
TextLadder, GLUT_STROKE_MONO_ROMAN,
|
||||
roll_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
101
Simulator/Cockpit/hud_scal.cxx
Normal file
101
Simulator/Cockpit/hud_scal.cxx
Normal file
|
@ -0,0 +1,101 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
//============== Top of instr_scale class memeber definitions ===============
|
||||
//
|
||||
// Notes:
|
||||
// 1. instr_scales divide the specified location into half and then
|
||||
// the half opposite the read direction in half again. A bar is
|
||||
// then drawn along the second divider. Scale ticks are drawn
|
||||
// between the middle and quarter section lines (minor division
|
||||
// markers) or just over the middle line.
|
||||
//
|
||||
// 2. This class was not intended to be instanciated. See moving_scale
|
||||
// and guage_instr classes.
|
||||
//============================================================================
|
||||
instr_scale ::
|
||||
instr_scale ( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR load_fn,
|
||||
UINT options,
|
||||
double show_range,
|
||||
double maxValue,
|
||||
double minValue,
|
||||
double disp_scale,
|
||||
UINT major_divs,
|
||||
UINT minor_divs,
|
||||
UINT rollover,
|
||||
int dp_showing,
|
||||
bool working ) :
|
||||
instr_item( x, y, width, height,
|
||||
load_fn, disp_scale, options, working),
|
||||
range_shown ( show_range ),
|
||||
Maximum_value( maxValue ),
|
||||
Minimum_value( minValue ),
|
||||
Maj_div ( major_divs ),
|
||||
Min_div ( minor_divs ),
|
||||
Modulo ( rollover ),
|
||||
signif_digits( dp_showing )
|
||||
{
|
||||
int temp;
|
||||
|
||||
scale_factor = (double)get_span() / range_shown;
|
||||
if( show_range < 0 ) {
|
||||
range_shown = -range_shown;
|
||||
}
|
||||
temp = (Maximum_value - Minimum_value) / 100;
|
||||
if( range_shown < temp ) {
|
||||
range_shown = temp;
|
||||
}
|
||||
}
|
||||
|
||||
instr_scale ::
|
||||
instr_scale( const instr_scale & image ) :
|
||||
instr_item( (const instr_item &) image),
|
||||
range_shown ( image.range_shown ),
|
||||
Maximum_value( image.Maximum_value ),
|
||||
Minimum_value( image.Minimum_value ),
|
||||
scale_factor ( image.scale_factor ),
|
||||
Maj_div ( image.Maj_div ),
|
||||
Min_div ( image.Min_div ),
|
||||
Modulo ( image.Modulo ),
|
||||
signif_digits( image.signif_digits )
|
||||
{
|
||||
}
|
||||
|
||||
instr_scale & instr_scale :: operator = (const instr_scale & rhs )
|
||||
{
|
||||
if( !(this == &rhs)) {
|
||||
instr_item::operator = (rhs);
|
||||
range_shown = rhs.range_shown;
|
||||
scale_factor = rhs.scale_factor;
|
||||
Maximum_value = rhs.Maximum_value;
|
||||
Minimum_value = rhs.Minimum_value;
|
||||
Maj_div = rhs.Maj_div;
|
||||
Min_div = rhs.Min_div;
|
||||
Modulo = rhs.Modulo;
|
||||
signif_digits = rhs.signif_digits;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
instr_scale :: ~ instr_scale () {}
|
||||
|
190
Simulator/Cockpit/hud_tbi.cxx
Normal file
190
Simulator/Cockpit/hud_tbi.cxx
Normal file
|
@ -0,0 +1,190 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/polar3d.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_timer.hxx>
|
||||
|
||||
|
||||
#include "hud.hxx"
|
||||
//============ Top of fgTBI_instr class member definitions ==============
|
||||
|
||||
fgTBI_instr ::
|
||||
fgTBI_instr( int x,
|
||||
int y,
|
||||
UINT width,
|
||||
UINT height,
|
||||
DBLFNPTR chn1_source,
|
||||
DBLFNPTR chn2_source,
|
||||
double maxBankAngle,
|
||||
double maxSlipAngle,
|
||||
UINT gap_width,
|
||||
bool working ) :
|
||||
dual_instr_item( x, y, width, height,
|
||||
chn1_source,
|
||||
chn2_source,
|
||||
working,
|
||||
HUDS_TOP),
|
||||
BankLimit (maxBankAngle),
|
||||
SlewLimit (maxSlipAngle),
|
||||
scr_hole (gap_width )
|
||||
{
|
||||
}
|
||||
|
||||
fgTBI_instr :: ~fgTBI_instr() {}
|
||||
|
||||
fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
|
||||
dual_instr_item( (const dual_instr_item &) image),
|
||||
BankLimit( image.BankLimit),
|
||||
SlewLimit( image.SlewLimit),
|
||||
scr_hole ( image.scr_hole )
|
||||
{
|
||||
}
|
||||
|
||||
fgTBI_instr & fgTBI_instr ::
|
||||
operator = (const fgTBI_instr & rhs )
|
||||
{
|
||||
if( !(this == &rhs)) {
|
||||
dual_instr_item::operator = (rhs);
|
||||
BankLimit = rhs.BankLimit;
|
||||
SlewLimit = rhs.SlewLimit;
|
||||
scr_hole = rhs.scr_hole;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// Draws a Turn Bank Indicator on the screen
|
||||
//
|
||||
|
||||
void fgTBI_instr :: draw( void )
|
||||
{
|
||||
int x_inc1, y_inc1;
|
||||
int x_inc2, y_inc2;
|
||||
int x_t_inc1, y_t_inc1;
|
||||
|
||||
int d_bottom_x, d_bottom_y;
|
||||
int d_right_x, d_right_y;
|
||||
int d_top_x, d_top_y;
|
||||
int d_left_x, d_left_y;
|
||||
|
||||
int inc_b_x, inc_b_y;
|
||||
int inc_r_x, inc_r_y;
|
||||
int inc_t_x, inc_t_y;
|
||||
int inc_l_x, inc_l_y;
|
||||
RECT My_box = get_location();
|
||||
POINT centroid = get_centroid();
|
||||
int tee_height = My_box.bottom;
|
||||
|
||||
// struct fgFLIGHT *f = ¤t_aircraft.flight;
|
||||
double sin_bank, cos_bank;
|
||||
double bank_angle, sideslip_angle;
|
||||
double ss_const; // sideslip angle pixels per rad
|
||||
|
||||
bank_angle = current_ch2(); // Roll limit +/- 30 degrees
|
||||
if( bank_angle < -FG_PI_2/3 ) {
|
||||
bank_angle = -FG_PI_2/3;
|
||||
}
|
||||
else
|
||||
if( bank_angle > FG_PI_2/3 ) {
|
||||
bank_angle = FG_PI_2/3;
|
||||
}
|
||||
sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
|
||||
if( sideslip_angle < -FG_PI/9 ) {
|
||||
sideslip_angle = -FG_PI/9;
|
||||
}
|
||||
else
|
||||
if( sideslip_angle > FG_PI/9 ) {
|
||||
sideslip_angle = FG_PI/9;
|
||||
}
|
||||
|
||||
// sin_bank = sin( FG_2PI-FG_Phi );
|
||||
// cos_bank = cos( FG_2PI-FG_Phi );
|
||||
sin_bank = sin(FG_2PI-bank_angle);
|
||||
cos_bank = cos(FG_2PI-bank_angle);
|
||||
|
||||
x_inc1 = (int)(get_span() * cos_bank);
|
||||
y_inc1 = (int)(get_span() * sin_bank);
|
||||
x_inc2 = (int)(scr_hole * cos_bank);
|
||||
y_inc2 = (int)(scr_hole * sin_bank);
|
||||
|
||||
x_t_inc1 = (int)(tee_height * sin_bank);
|
||||
y_t_inc1 = (int)(tee_height * cos_bank);
|
||||
|
||||
d_bottom_x = 0;
|
||||
d_bottom_y = (int)(-scr_hole);
|
||||
d_right_x = (int)(scr_hole);
|
||||
d_right_y = 0;
|
||||
d_top_x = 0;
|
||||
d_top_y = (int)(scr_hole);
|
||||
d_left_x = (int)(-scr_hole);
|
||||
d_left_y = 0;
|
||||
|
||||
ss_const = (get_span()*2)/(FG_2PI/9); // width represents 40 degrees
|
||||
|
||||
d_bottom_x += (int)(sideslip_angle*ss_const);
|
||||
d_right_x += (int)(sideslip_angle*ss_const);
|
||||
d_left_x += (int)(sideslip_angle*ss_const);
|
||||
d_top_x += (int)(sideslip_angle*ss_const);
|
||||
|
||||
inc_b_x = (int)(d_bottom_x*cos_bank-d_bottom_y*sin_bank);
|
||||
inc_b_y = (int)(d_bottom_x*sin_bank+d_bottom_y*cos_bank);
|
||||
inc_r_x = (int)(d_right_x*cos_bank-d_right_y*sin_bank);
|
||||
inc_r_y = (int)(d_right_x*sin_bank+d_right_y*cos_bank);
|
||||
inc_t_x = (int)(d_top_x*cos_bank-d_top_y*sin_bank);
|
||||
inc_t_y = (int)(d_top_x*sin_bank+d_top_y*cos_bank);
|
||||
inc_l_x = (int)(d_left_x*cos_bank-d_left_y*sin_bank);
|
||||
inc_l_y = (int)(d_left_x*sin_bank+d_left_y*cos_bank);
|
||||
|
||||
if( scr_hole == 0 )
|
||||
{
|
||||
drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
|
||||
centroid.x + x_inc1, centroid.y + y_inc1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
|
||||
centroid.x - x_inc2, centroid.y - y_inc2 );
|
||||
drawOneLine( centroid.x + x_inc2, centroid.y + y_inc2, \
|
||||
centroid.x + x_inc1, centroid.y + y_inc1 );
|
||||
}
|
||||
|
||||
// draw teemarks
|
||||
drawOneLine( centroid.x + x_inc2, \
|
||||
centroid.y + y_inc2, \
|
||||
centroid.x + x_inc2 + x_t_inc1, \
|
||||
centroid.y + y_inc2 - y_t_inc1 );
|
||||
drawOneLine( centroid.x - x_inc2, \
|
||||
centroid.y - y_inc2, \
|
||||
centroid.x - x_inc2 + x_t_inc1, \
|
||||
centroid.y - y_inc2 - y_t_inc1 );
|
||||
|
||||
// draw sideslip diamond (it is not yet positioned correctly )
|
||||
drawOneLine( centroid.x + inc_b_x, \
|
||||
centroid.y + inc_b_y, \
|
||||
centroid.x + inc_r_x, \
|
||||
centroid.y + inc_r_y );
|
||||
drawOneLine( centroid.x + inc_r_x, \
|
||||
centroid.y + inc_r_y, \
|
||||
centroid.x + inc_t_x, \
|
||||
centroid.y + inc_t_y );
|
||||
drawOneLine( centroid.x + inc_t_x, \
|
||||
centroid.y + inc_t_y, \
|
||||
centroid.x + inc_l_x, \
|
||||
centroid.y + inc_l_y );
|
||||
drawOneLine( centroid.x + inc_l_x, \
|
||||
centroid.y + inc_l_y, \
|
||||
centroid.x + inc_b_x, \
|
||||
centroid.y + inc_b_y );
|
||||
|
||||
}
|
1097
Simulator/Cockpit/panel.cxx
Normal file
1097
Simulator/Cockpit/panel.cxx
Normal file
File diff suppressed because it is too large
Load diff
280
Simulator/Cockpit/panel.hxx
Normal file
280
Simulator/Cockpit/panel.hxx
Normal file
|
@ -0,0 +1,280 @@
|
|||
// panel.hxx -- instrument panel defines and prototypes
|
||||
//
|
||||
// Written by Friedemann Reinhard, started June 1998.
|
||||
//
|
||||
// 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)
|
||||
|
||||
#define LETTER_OFFSET 0.03515625
|
||||
|
||||
#ifndef _PANEL_HXX
|
||||
#define _PANEL_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
class FGInstrument;
|
||||
|
||||
class FGPanel{
|
||||
|
||||
private:
|
||||
int height, width;
|
||||
GLuint FontList;
|
||||
|
||||
GLubyte *background;
|
||||
|
||||
// FGInstrument **instr_list;
|
||||
FGInstrument *test_instr[7];
|
||||
|
||||
void GetData(void);
|
||||
|
||||
public:
|
||||
static FGPanel *OurPanel;
|
||||
|
||||
FGPanel(void);
|
||||
|
||||
float get_height(void){
|
||||
return height;
|
||||
}
|
||||
|
||||
void ReInit( int x, int y, int finx, int finy);
|
||||
void Update(void);
|
||||
|
||||
void DrawLetter(void){
|
||||
glBegin(GL_POLYGON);
|
||||
glTexCoord2f(0.0, 0.0);
|
||||
glVertex2f(0.0, 0.0);
|
||||
glTexCoord2f(LETTER_OFFSET + 0.004, 0.0);
|
||||
glVertex2f(7.0, 0.0);
|
||||
glTexCoord2f(LETTER_OFFSET + 0.004, 0.0390625);
|
||||
glVertex2f(7.0, 9.0);
|
||||
glTexCoord2f(0.0, 0.0390625);
|
||||
glVertex2f(0.0, 9.0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawTestLetter(float X, float Y);
|
||||
void InitLists(void);
|
||||
void TexString(char *s, float XPos, float YPos, float size);
|
||||
|
||||
};
|
||||
|
||||
class FGInstrument{
|
||||
friend class FGPanel;
|
||||
|
||||
protected:
|
||||
float XPos, YPos;
|
||||
|
||||
public:
|
||||
FGInstrument(void){
|
||||
}
|
||||
|
||||
virtual ~FGInstrument(void){}
|
||||
|
||||
virtual void Init(void) = 0;
|
||||
virtual void Render(void) = 0;
|
||||
};
|
||||
|
||||
class FGHorizon : public FGInstrument {
|
||||
private:
|
||||
float texXPos;
|
||||
float texYPos;
|
||||
float radius;
|
||||
float bottom; // tell the program the offset between midpoint and bottom
|
||||
float top; // guess what ;-)
|
||||
float vertices[180][2];
|
||||
float normals[180][3];
|
||||
float texCoord[180][2];
|
||||
|
||||
public:
|
||||
FGHorizon(void){
|
||||
XPos = 0.0; YPos = 0.0;
|
||||
Init();
|
||||
}
|
||||
|
||||
FGHorizon(float inXPos, float inYPos){
|
||||
XPos = inXPos; YPos = inYPos;
|
||||
Init();
|
||||
}
|
||||
|
||||
virtual void Init(void);
|
||||
virtual void Render(void);
|
||||
|
||||
};
|
||||
|
||||
class FGTurnCoordinator : public FGInstrument {
|
||||
private:
|
||||
float PlaneTexXPos;
|
||||
float PlaneTexYPos;
|
||||
float alpha;
|
||||
float PlaneAlpha;
|
||||
float alphahist[2];
|
||||
float rollhist[2];
|
||||
float BallXPos;
|
||||
float BallYPos;
|
||||
float BallTexXPos;
|
||||
float BallTexYPos;
|
||||
float BallRadius;
|
||||
GLfloat vertices[72];
|
||||
|
||||
public:
|
||||
FGTurnCoordinator(void){
|
||||
XPos = 0.0; YPos = 0.0;
|
||||
Init();
|
||||
}
|
||||
|
||||
FGTurnCoordinator(float inXPos, float inYPos){
|
||||
XPos = inXPos; YPos = inYPos;
|
||||
Init();
|
||||
}
|
||||
|
||||
virtual void Init (void);
|
||||
virtual void Render(void);
|
||||
|
||||
};
|
||||
|
||||
class FGRpmGauge : public FGInstrument {
|
||||
private:
|
||||
GLuint list;
|
||||
|
||||
public:
|
||||
FGRpmGauge(void){
|
||||
XPos = 0.0; YPos = 0.0;
|
||||
Init();
|
||||
}
|
||||
|
||||
FGRpmGauge(float inXPos, float inYPos){
|
||||
XPos = inXPos; YPos = inYPos;
|
||||
Init();
|
||||
}
|
||||
|
||||
virtual void Init(void);
|
||||
virtual void Render(void);
|
||||
};
|
||||
|
||||
// temporary class until I get the software-only routines for the
|
||||
// instruments run
|
||||
|
||||
class FGTexInstrument : public FGInstrument {
|
||||
|
||||
private:
|
||||
float radius;
|
||||
float length;
|
||||
float width;
|
||||
float angle;
|
||||
float tape[2];
|
||||
float value1;
|
||||
float value2;
|
||||
float alpha1;
|
||||
float alpha2;
|
||||
float teXpos;
|
||||
float texYpos;
|
||||
int variable;
|
||||
GLfloat vertices[20];
|
||||
|
||||
public:
|
||||
FGTexInstrument(void){
|
||||
XPos = 0.0; YPos = 0.0;
|
||||
Init();
|
||||
}
|
||||
|
||||
FGTexInstrument(float inXPos, float inYPos, float inradius, float inlength, float inwidth, float inangle, float invalue1, float invalue2, float inalpha1, float inalpha2, float intexXPos, float intexYPos, int invariable){
|
||||
|
||||
XPos = inXPos; YPos = inYPos;
|
||||
radius = inradius; angle = inangle;
|
||||
length = inlength; width = inwidth;
|
||||
value1 = invalue1; value2 = invalue2;
|
||||
alpha1 = inalpha1; alpha2 = inalpha2;
|
||||
teXpos = intexXPos; texYpos = intexYPos;
|
||||
variable = invariable;
|
||||
Init();
|
||||
}
|
||||
|
||||
void CreatePointer(void);
|
||||
void UpdatePointer(void);
|
||||
|
||||
void Init(void);
|
||||
void Render(void);
|
||||
};
|
||||
|
||||
typedef struct{
|
||||
float XPos;
|
||||
float YPos;
|
||||
float radius;
|
||||
float length;
|
||||
float width;
|
||||
float angle;
|
||||
float tape[2];
|
||||
float value1;
|
||||
float value2;
|
||||
float alpha1;
|
||||
float alpha2;
|
||||
float teXpos;
|
||||
float texYpos;
|
||||
int variable;
|
||||
GLfloat vertices[20];
|
||||
}Pointer;
|
||||
|
||||
void fgEraseArea(GLfloat *array, int NumVerti, GLfloat texXPos, GLfloat texYPos, GLfloat XPos, GLfloat YPos, int Texid, float ScaleFactor);
|
||||
void DrawScale(float XPos, float YPos, float InnerRadius, float OuterRadius, float alpha1, float alpha2, int steps, float LineWidth, float red, float green, float blue, bool filled);
|
||||
void DrawBeechcraftLogo(float XPos, float YPos, float Width, float Height);
|
||||
|
||||
void PrintMatrix( void);
|
||||
|
||||
#endif // _PANEL_HXX
|
||||
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.9 1999/03/09 20:58:18 curt
|
||||
// Tweaks for compiling under native Irix compilers.
|
||||
//
|
||||
// Revision 1.8 1999/03/08 21:56:10 curt
|
||||
// Added panel changes sent in by Friedemann.
|
||||
//
|
||||
// Revision 1.5 1999/01/07 19:25:55 curt
|
||||
// Updates from Friedemann Reinhard.
|
||||
//
|
||||
// Revision 1.4 1998/11/11 00:19:29 curt
|
||||
// Updated comment delimeter to C++ style.
|
||||
//
|
||||
// Revision 1.3 1998/11/09 23:38:54 curt
|
||||
// Panel updates from Friedemann.
|
||||
//
|
||||
// Revision 1.2 1998/08/28 18:14:41 curt
|
||||
// Added new cockpit code from Friedemann Reinhard
|
||||
// <mpt218@faupt212.physik.uni-erlangen.de>
|
||||
//
|
||||
// Revision 1.1 1998/06/27 16:47:55 curt
|
||||
// Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
|
||||
// first pass at an isntrument panel.
|
||||
|
||||
|
5
Simulator/Controls/Makefile.am
Normal file
5
Simulator/Controls/Makefile.am
Normal file
|
@ -0,0 +1,5 @@
|
|||
noinst_LIBRARIES = libControls.a
|
||||
|
||||
libControls_a_SOURCES = controls.cxx controls.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Simulator
|
91
Simulator/Controls/controls.cxx
Normal file
91
Simulator/Controls/controls.cxx
Normal file
|
@ -0,0 +1,91 @@
|
|||
// controls.cxx -- defines a standard interface to all flight sim controls
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 "controls.hxx"
|
||||
|
||||
|
||||
FGControls controls;
|
||||
|
||||
|
||||
// Constructor
|
||||
FGControls::FGControls() :
|
||||
aileron( 0.0 ),
|
||||
elevator( 0.0 ),
|
||||
elevator_trim( 1.969572E-03 ),
|
||||
rudder( 0.0 )
|
||||
{
|
||||
for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
|
||||
throttle[engine] = 0.0;
|
||||
}
|
||||
|
||||
for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
|
||||
brake[wheel] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
FGControls::~FGControls() {
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.3 1998/12/05 16:13:12 curt
|
||||
// Renamed class fgCONTROLS to class FGControls.
|
||||
//
|
||||
// Revision 1.2 1998/10/25 14:08:41 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.1 1998/10/18 01:51:05 curt
|
||||
// c++-ifying ...
|
||||
//
|
||||
// Revision 1.8 1998/09/29 02:01:31 curt
|
||||
// Added a brake.
|
||||
//
|
||||
// Revision 1.7 1998/02/07 15:29:36 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.6 1998/01/19 19:27:02 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.5 1998/01/19 18:40:22 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.4 1997/12/10 22:37:41 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.3 1997/08/27 03:30:01 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.2 1997/06/21 17:12:48 curt
|
||||
// Capitalized subdirectory names.
|
||||
//
|
||||
// Revision 1.1 1997/05/31 19:24:04 curt
|
||||
// Initial revision.
|
||||
//
|
||||
|
252
Simulator/Controls/controls.hxx
Normal file
252
Simulator/Controls/controls.hxx
Normal file
|
@ -0,0 +1,252 @@
|
|||
// controls.hxx -- defines a standard interface to all flight sim controls
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 _CONTROLS_HXX
|
||||
#define _CONTROLS_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
// Define a structure containing the control parameters
|
||||
|
||||
class FGControls {
|
||||
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
ALL_ENGINES = -1,
|
||||
MAX_ENGINES = 10
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ALL_WHEELS = -1,
|
||||
MAX_WHEELS = 3
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
double aileron;
|
||||
double elevator;
|
||||
double elevator_trim;
|
||||
double rudder;
|
||||
double throttle[MAX_ENGINES];
|
||||
double brake[MAX_WHEELS];
|
||||
|
||||
public:
|
||||
|
||||
FGControls();
|
||||
~FGControls();
|
||||
|
||||
// Query functions
|
||||
inline double get_aileron() const { return aileron; }
|
||||
inline double get_elevator() const { return elevator; }
|
||||
inline double get_elevator_trim() const { return elevator_trim; }
|
||||
inline double get_rudder() const { return rudder; }
|
||||
inline double get_throttle(int engine) const { return throttle[engine]; }
|
||||
inline double get_brake(int wheel) const { return brake[wheel]; }
|
||||
|
||||
// Update functions
|
||||
inline void set_aileron( double pos ) {
|
||||
aileron = pos;
|
||||
if ( aileron < -1.0 ) aileron = -1.0;
|
||||
if ( aileron > 1.0 ) aileron = 1.0;
|
||||
}
|
||||
inline void move_aileron( double amt ) {
|
||||
aileron += amt;
|
||||
if ( aileron < -1.0 ) aileron = -1.0;
|
||||
if ( aileron > 1.0 ) aileron = 1.0;
|
||||
}
|
||||
inline void set_elevator( double pos ) {
|
||||
elevator = pos;
|
||||
if ( elevator < -1.0 ) elevator = -1.0;
|
||||
if ( elevator > 1.0 ) elevator = 1.0;
|
||||
}
|
||||
inline void move_elevator( double amt ) {
|
||||
elevator += amt;
|
||||
if ( elevator < -1.0 ) elevator = -1.0;
|
||||
if ( elevator > 1.0 ) elevator = 1.0;
|
||||
}
|
||||
inline void set_elevator_trim( double pos ) {
|
||||
elevator_trim = pos;
|
||||
if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
|
||||
if ( elevator_trim > 1.0 ) elevator_trim = 1.0;
|
||||
}
|
||||
inline void move_elevator_trim( double amt ) {
|
||||
elevator_trim += amt;
|
||||
if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
|
||||
if ( elevator_trim > 1.0 ) elevator_trim = 1.0;
|
||||
}
|
||||
inline void set_rudder( double pos ) {
|
||||
rudder = pos;
|
||||
if ( rudder < -1.0 ) rudder = -1.0;
|
||||
if ( rudder > 1.0 ) rudder = 1.0;
|
||||
}
|
||||
inline void move_rudder( double amt ) {
|
||||
rudder += amt;
|
||||
if ( rudder < -1.0 ) rudder = -1.0;
|
||||
if ( rudder > 1.0 ) rudder = 1.0;
|
||||
}
|
||||
inline void set_throttle( int engine, double pos ) {
|
||||
if ( engine == ALL_ENGINES ) {
|
||||
for ( int i = 0; i < MAX_ENGINES; i++ ) {
|
||||
throttle[i] = pos;
|
||||
if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
|
||||
if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
|
||||
throttle[engine] = pos;
|
||||
if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
|
||||
if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void move_throttle( int engine, double amt ) {
|
||||
if ( engine == ALL_ENGINES ) {
|
||||
for ( int i = 0; i < MAX_ENGINES; i++ ) {
|
||||
throttle[i] += amt;
|
||||
if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
|
||||
if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
|
||||
throttle[engine] += amt;
|
||||
if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
|
||||
if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void set_brake( int wheel, double pos ) {
|
||||
if ( wheel == ALL_WHEELS ) {
|
||||
for ( int i = 0; i < MAX_WHEELS; i++ ) {
|
||||
brake[i] = pos;
|
||||
if ( brake[i] < 0.0 ) brake[i] = 0.0;
|
||||
if ( brake[i] > 1.0 ) brake[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
|
||||
brake[wheel] = pos;
|
||||
if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
|
||||
if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void move_brake( int wheel, double amt ) {
|
||||
if ( wheel == ALL_WHEELS ) {
|
||||
for ( int i = 0; i < MAX_WHEELS; i++ ) {
|
||||
brake[i] += amt;
|
||||
if ( brake[i] < 0.0 ) brake[i] = 0.0;
|
||||
if ( brake[i] > 1.0 ) brake[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
|
||||
brake[wheel] += amt;
|
||||
if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
|
||||
if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
extern FGControls controls;
|
||||
|
||||
|
||||
#endif // _CONTROLS_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.4 1999/01/27 04:48:13 curt
|
||||
// C++ style refinements by Bernie Bright.
|
||||
//
|
||||
// Revision 1.3 1998/12/05 16:13:13 curt
|
||||
// Renamed class fgCONTROLS to class FGControls.
|
||||
//
|
||||
// Revision 1.2 1998/10/25 14:08:42 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.1 1998/10/18 01:51:07 curt
|
||||
// c++-ifying ...
|
||||
//
|
||||
// Revision 1.17 1998/09/29 14:57:00 curt
|
||||
// c++-ified some comments.
|
||||
//
|
||||
// Revision 1.16 1998/09/29 02:01:32 curt
|
||||
// Added a brake.
|
||||
//
|
||||
// Revision 1.15 1998/04/25 22:06:27 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.14 1998/04/22 13:26:19 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.13 1998/04/21 17:02:35 curt
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.12 1998/02/09 22:56:48 curt
|
||||
// Removed "depend" files from cvs control. Other minor make tweaks.
|
||||
//
|
||||
// Revision 1.11 1998/02/07 15:29:36 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.10 1998/01/27 00:47:52 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.9 1998/01/22 02:59:31 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.8 1998/01/19 18:40:22 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.7 1997/12/15 23:54:36 curt
|
||||
// Add xgl wrappers for debugging.
|
||||
// Generate terrain normals on the fly.
|
||||
//
|
||||
// Revision 1.6 1997/12/10 22:37:41 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.5 1997/08/27 03:30:02 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.4 1997/07/23 21:52:18 curt
|
||||
// Put comments around the text after an #endif for increased portability.
|
||||
//
|
||||
// Revision 1.3 1997/05/31 19:16:27 curt
|
||||
// Elevator trim added.
|
||||
//
|
||||
// Revision 1.2 1997/05/23 15:40:33 curt
|
||||
// Added GNU copyright headers.
|
||||
//
|
||||
// Revision 1.1 1997/05/16 15:59:48 curt
|
||||
// Initial revision.
|
||||
//
|
5
Simulator/External/Makefile.am
vendored
Normal file
5
Simulator/External/Makefile.am
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
noinst_LIBRARIES = libExternal.a
|
||||
|
||||
libExternal_a_SOURCES = external.cxx external.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Simulator
|
61
Simulator/External/external.cxx
vendored
Normal file
61
Simulator/External/external.cxx
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
// external.cxx -- externally driven flight model
|
||||
//
|
||||
// Written by Curtis Olson, started January 1998.
|
||||
//
|
||||
// Copyright (C) 1998 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)
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "external.hxx"
|
||||
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
|
||||
|
||||
// reset flight params to a specific position
|
||||
void fgExternalInit( FGInterface &f ) {
|
||||
}
|
||||
|
||||
|
||||
// update position based on inputs, positions, velocities, etc.
|
||||
void fgExternalUpdate( FGInterface& f, int multiloop ) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.5 1999/02/05 21:29:03 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.4 1999/02/01 21:33:32 curt
|
||||
// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
|
||||
// Jon accepted my offer to do this and thought it was a good idea.
|
||||
//
|
||||
// Revision 1.3 1999/01/19 17:52:11 curt
|
||||
// Working on being able to extrapolate a new position and orientation
|
||||
// based on a position, orientation, and time offset.
|
||||
//
|
||||
// Revision 1.2 1998/12/05 15:54:13 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.1 1998/12/04 01:28:49 curt
|
||||
// Initial revision.
|
||||
//
|
104
Simulator/External/external.hxx
vendored
Normal file
104
Simulator/External/external.hxx
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
// external.hxx -- the "external" flight model (driven from other
|
||||
// external input)
|
||||
//
|
||||
// Written by Curtis Olson, started December 1998.
|
||||
//
|
||||
// Copyright (C) 1998 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 _EXTERNAL_HXX
|
||||
#define _EXTERNAL_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <Time/fg_time.hxx>
|
||||
#include <Time/timestamp.hxx>
|
||||
|
||||
|
||||
/*
|
||||
class fgFDM_EXTERNAL {
|
||||
|
||||
public:
|
||||
|
||||
// Time Stamp
|
||||
|
||||
// The time at which these values are correct (for extrapolating
|
||||
// later frames between position updates)
|
||||
FGTimeStamp t;
|
||||
|
||||
// Positions
|
||||
|
||||
// placement in geodetic coordinates
|
||||
double Latitude;
|
||||
double Longitude;
|
||||
double Altitude;
|
||||
|
||||
// orientation in euler angles relative to local frame (or ground
|
||||
// position)
|
||||
double Phi; // roll
|
||||
double Theta; // pitch
|
||||
double Psi; // heading
|
||||
|
||||
// Velocities
|
||||
|
||||
// velocities in geodetic coordinates
|
||||
double Latitude_dot; // rad/sec
|
||||
double Longitude_dot; // rad/sec
|
||||
double Altitude_dot; // feet/sec
|
||||
|
||||
// rotational rates
|
||||
double Phi_dot;
|
||||
double Theta_dot;
|
||||
double Psi_dot;
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
// reset flight params to a specific position
|
||||
void fgExternalInit( FGInterface& f );
|
||||
|
||||
|
||||
#endif // _EXTERNAL_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.6 1999/02/05 21:29:04 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.5 1999/01/19 17:52:12 curt
|
||||
// Working on being able to extrapolate a new position and orientation
|
||||
// based on a position, orientation, and time offset.
|
||||
//
|
||||
// Revision 1.4 1999/01/09 13:37:37 curt
|
||||
// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms.
|
||||
//
|
||||
// Revision 1.3 1998/12/05 15:54:14 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.2 1998/12/05 14:18:47 curt
|
||||
// added an fgTIMESTAMP to define when this record is valid.
|
||||
//
|
||||
// Revision 1.1 1998/12/04 01:28:49 curt
|
||||
// Initial revision.
|
||||
//
|
273
Simulator/FDM/JSBsim.cxx
Normal file
273
Simulator/FDM/JSBsim.cxx
Normal file
|
@ -0,0 +1,273 @@
|
|||
// JSBsim.cxx -- interface to the JSBsim flight model
|
||||
//
|
||||
// Written by Curtis 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)
|
||||
|
||||
|
||||
#include <Include/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Controls/controls.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Main/options.hxx>
|
||||
#include <Math/fg_geodesy.hxx>
|
||||
|
||||
#include <FDM/JSBsim/FGFDMExec.h>
|
||||
#include <FDM/JSBsim/FGAircraft.h>
|
||||
#include <FDM/JSBsim/FGFCS.h>
|
||||
#include <FDM/JSBsim/FGPosition.h>
|
||||
#include <FDM/JSBsim/FGRotation.h>
|
||||
#include <FDM/JSBsim/FGState.h>
|
||||
#include <FDM/JSBsim/FGTranslation.h>
|
||||
|
||||
#include "JSBsim.hxx"
|
||||
|
||||
|
||||
// The default aircraft
|
||||
FGFDMExec FDMExec;
|
||||
|
||||
|
||||
// Initialize the JSBsim flight model, dt is the time increment for
|
||||
// each subsequent iteration through the EOM
|
||||
int fgJSBsimInit(double dt) {
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing JSBsim" );
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, " created FDMExec" );
|
||||
|
||||
string aircraft_path = current_options.get_fg_root() + "/Aircraft";
|
||||
string engine_path = current_options.get_fg_root() + "/Engine";
|
||||
|
||||
FDMExec.GetAircraft()->LoadAircraft(aircraft_path, engine_path, "X15");
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft" );
|
||||
|
||||
FDMExec.GetState()->Reset(aircraft_path, "Reset00");
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, " loaded initial conditions" );
|
||||
|
||||
FDMExec.GetState()->Setdt(dt);
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, " set dt" );
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing JSBsim" );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Run an iteration of the EOM (equations of motion)
|
||||
int fgJSBsimUpdate(FGInterface& f, int multiloop) {
|
||||
double save_alt = 0.0;
|
||||
|
||||
// lets try to avoid really screwing up the JSBsim model
|
||||
if ( f.get_Altitude() < -9000 ) {
|
||||
save_alt = f.get_Altitude();
|
||||
f.set_Altitude( 0.0 );
|
||||
}
|
||||
|
||||
// copy control positions into the JSBsim structure
|
||||
FDMExec.GetFCS()->SetDa( controls.get_aileron() );
|
||||
FDMExec.GetFCS()->SetDe( controls.get_elevator()
|
||||
+ controls.get_elevator_trim() );
|
||||
FDMExec.GetFCS()->SetDr( controls.get_rudder() );
|
||||
FDMExec.GetFCS()->SetDf( 0.0 );
|
||||
FDMExec.GetFCS()->SetDs( 0.0 );
|
||||
FDMExec.GetFCS()->SetThrottle( FGControls::ALL_ENGINES,
|
||||
controls.get_throttle( 0 ) );
|
||||
// FCS->SetBrake( controls.get_brake( 0 ) );
|
||||
|
||||
// Inform JSBsim of the local terrain altitude
|
||||
// Runway_altitude = f.get_Runway_altitude();
|
||||
|
||||
// old -- FGInterface_2_JSBsim() not needed except for Init()
|
||||
// translate FG to JSBsim structure
|
||||
// FGInterface_2_JSBsim(f);
|
||||
// printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
|
||||
// printf("Altitude = %.2f\n", Altitude * 0.3048);
|
||||
// printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
|
||||
|
||||
/* FDMExec.GetState()->Setsim_time(State->Getsim_time()
|
||||
+ State->Getdt() * multiloop); */
|
||||
|
||||
for ( int i = 0; i < multiloop; i++ ) {
|
||||
FDMExec.Run();
|
||||
}
|
||||
|
||||
// printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
|
||||
// printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
|
||||
|
||||
// translate JSBsim back to FG structure so that the
|
||||
// autopilot (and the rest of the sim can use the updated
|
||||
// values
|
||||
|
||||
fgJSBsim_2_FGInterface(f);
|
||||
|
||||
// but lets restore our original bogus altitude when we are done
|
||||
if ( save_alt < -9000.0 ) {
|
||||
f.set_Altitude( save_alt );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Convert from the FGInterface struct to the JSBsim generic_ struct
|
||||
int FGInterface_2_JSBsim (FGInterface& f) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Convert from the JSBsim generic_ struct to the FGInterface struct
|
||||
int fgJSBsim_2_FGInterface (FGInterface& f) {
|
||||
|
||||
// Velocities
|
||||
f.set_Velocities_Local( FDMExec.GetPosition()->GetVn(),
|
||||
FDMExec.GetPosition()->GetVe(),
|
||||
FDMExec.GetPosition()->GetVd() );
|
||||
// f.set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground,
|
||||
// V_down_rel_ground );
|
||||
// f.set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass,
|
||||
// V_down_airmass );
|
||||
// f.set_Velocities_Local_Rel_Airmass( V_north_rel_airmass,
|
||||
// V_east_rel_airmass, V_down_rel_airmass );
|
||||
// f.set_Velocities_Gust( U_gust, V_gust, W_gust );
|
||||
// f.set_Velocities_Wind_Body( U_body, V_body, W_body );
|
||||
|
||||
// f.set_V_rel_wind( V_rel_wind );
|
||||
// f.set_V_true_kts( V_true_kts );
|
||||
// f.set_V_rel_ground( V_rel_ground );
|
||||
// f.set_V_inertial( V_inertial );
|
||||
// f.set_V_ground_speed( V_ground_speed );
|
||||
// f.set_V_equiv( V_equiv );
|
||||
|
||||
/* ***FIXME*** */ f.set_V_equiv_kts( FDMExec.GetState()->GetVt() );
|
||||
// f.set_V_calibrated( V_calibrated );
|
||||
// f.set_V_calibrated_kts( V_calibrated_kts );
|
||||
|
||||
f.set_Omega_Body( FDMExec.GetRotation()->GetP(),
|
||||
FDMExec.GetRotation()->GetQ(),
|
||||
FDMExec.GetRotation()->GetR() );
|
||||
// f.set_Omega_Local( P_local, Q_local, R_local );
|
||||
// f.set_Omega_Total( P_total, Q_total, R_total );
|
||||
|
||||
// f.set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot );
|
||||
// ***FIXME*** f.set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot );
|
||||
|
||||
// Positions
|
||||
double lat_geoc = FDMExec.GetState()->Getlatitude();
|
||||
double lon = FDMExec.GetState()->Getlongitude();
|
||||
double alt = FDMExec.GetState()->Geth();
|
||||
double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
|
||||
fgGeocToGeod( lat_geoc, EQUATORIAL_RADIUS_M + alt * FEET_TO_METER,
|
||||
&lat_geod, &tmp_alt, &sl_radius1 );
|
||||
fgGeodToGeoc( lat_geod, alt * FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << lon << " lat_geod = " << lat_geod
|
||||
<< " lat_geoc = " << lat_geoc
|
||||
<< " alt = " << alt << " tmp_alt = " << tmp_alt * METER_TO_FEET
|
||||
<< " sl_radius1 = " << sl_radius1 * METER_TO_FEET
|
||||
<< " sl_radius2 = " << sl_radius2 * METER_TO_FEET
|
||||
<< " Equator = " << EQUATORIAL_RADIUS_FT );
|
||||
|
||||
f.set_Geocentric_Position( lat_geoc, lon,
|
||||
sl_radius2 * METER_TO_FEET + alt );
|
||||
f.set_Geodetic_Position( lat_geod, lon, alt );
|
||||
f.set_Euler_Angles( FDMExec.GetRotation()->Getphi(),
|
||||
FDMExec.GetRotation()->Gettht(),
|
||||
FDMExec.GetRotation()->Getpsi() );
|
||||
|
||||
// Miscellaneous quantities
|
||||
// f.set_T_Local_to_Body(T_local_to_body_m);
|
||||
// f.set_Gravity( Gravity );
|
||||
// f.set_Centrifugal_relief( Centrifugal_relief );
|
||||
|
||||
f.set_Alpha( FDMExec.GetTranslation()->Getalpha() );
|
||||
f.set_Beta( FDMExec.GetTranslation()->Getbeta() );
|
||||
// f.set_Alpha_dot( Alpha_dot );
|
||||
// f.set_Beta_dot( Beta_dot );
|
||||
|
||||
// f.set_Cos_alpha( Cos_alpha );
|
||||
// f.set_Sin_alpha( Sin_alpha );
|
||||
// f.set_Cos_beta( Cos_beta );
|
||||
// f.set_Sin_beta( Sin_beta );
|
||||
|
||||
// f.set_Cos_phi( Cos_phi );
|
||||
// f.set_Sin_phi( Sin_phi );
|
||||
// f.set_Cos_theta( Cos_theta );
|
||||
// f.set_Sin_theta( Sin_theta );
|
||||
// f.set_Cos_psi( Cos_psi );
|
||||
// f.set_Sin_psi( Sin_psi );
|
||||
|
||||
// ***ATTENDTOME*** f.set_Gamma_vert_rad( Gamma_vert_rad );
|
||||
// f.set_Gamma_horiz_rad( Gamma_horiz_rad );
|
||||
|
||||
// f.set_Sigma( Sigma );
|
||||
// f.set_Density( Density );
|
||||
// f.set_V_sound( V_sound );
|
||||
// f.set_Mach_number( Mach_number );
|
||||
|
||||
// f.set_Static_pressure( Static_pressure );
|
||||
// f.set_Total_pressure( Total_pressure );
|
||||
// f.set_Impact_pressure( Impact_pressure );
|
||||
// f.set_Dynamic_pressure( Dynamic_pressure );
|
||||
|
||||
// f.set_Static_temperature( Static_temperature );
|
||||
// f.set_Total_temperature( Total_temperature );
|
||||
|
||||
/* **FIXME*** */ f.set_Sea_level_radius( sl_radius2 * METER_TO_FEET );
|
||||
/* **FIXME*** */ f.set_Earth_position_angle( 0.0 );
|
||||
|
||||
/* ***FIXME*** */ f.set_Runway_altitude( 0.0 );
|
||||
// f.set_Runway_latitude( Runway_latitude );
|
||||
// f.set_Runway_longitude( Runway_longitude );
|
||||
// f.set_Runway_heading( Runway_heading );
|
||||
// f.set_Radius_to_rwy( Radius_to_rwy );
|
||||
|
||||
// f.set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy);
|
||||
// f.set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy );
|
||||
// f.set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy,
|
||||
// D_pilot_above_rwy );
|
||||
// f.set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy );
|
||||
|
||||
f.set_sin_lat_geocentric( lat_geoc );
|
||||
f.set_cos_lat_geocentric( lat_geoc );
|
||||
f.set_sin_cos_longitude( lon );
|
||||
f.set_sin_cos_latitude( lat_geod );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.4 1999/04/03 04:20:01 curt
|
||||
// Optimizations (tm) by Norman Vine.
|
||||
//
|
||||
// Revision 1.3 1999/02/26 22:09:10 curt
|
||||
// Added initial support for native SGI compilers.
|
||||
// Integrated Jon's next version of JSBsim.
|
||||
//
|
||||
// Revision 1.2 1999/02/11 21:09:40 curt
|
||||
// Interface with Jon's submitted JSBsim changes.
|
||||
//
|
||||
// Revision 1.1 1999/02/05 21:29:38 curt
|
||||
// Incorporating Jon S. Berndt's flight model code.
|
||||
//
|
56
Simulator/FDM/JSBsim.hxx
Normal file
56
Simulator/FDM/JSBsim.hxx
Normal file
|
@ -0,0 +1,56 @@
|
|||
// JSBsim.hxx -- interface to the "JSBsim" flight model
|
||||
//
|
||||
// Written by Curtis 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 _JSBSIM_HXX
|
||||
#define _JSBSIM_HXX
|
||||
|
||||
#include <FDM/JSBsim/FGFDMExec.h>
|
||||
#undef MAX_ENGINES
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
|
||||
|
||||
// reset flight params to a specific position
|
||||
int fgJSBsimInit(double dt);
|
||||
|
||||
// update position based on inputs, positions, velocities, etc.
|
||||
int fgJSBsimUpdate(FGInterface& f, int multiloop);
|
||||
|
||||
// Convert from the FGInterface struct to the JSBsim generic_ struct
|
||||
int FGInterface_2_JSBsim (FGInterface& f);
|
||||
|
||||
// Convert from the JSBsim generic_ struct to the FGInterface struct
|
||||
int fgJSBsim_2_FGInterface (FGInterface& f);
|
||||
|
||||
|
||||
#endif // _JSBSIM_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.2 1999/02/11 21:09:41 curt
|
||||
// Interface with Jon's submitted JSBsim changes.
|
||||
//
|
||||
// Revision 1.1 1999/02/05 21:29:38 curt
|
||||
// Incorporating Jon S. Berndt's flight model code.
|
||||
//
|
455
Simulator/FDM/LaRCsim.cxx
Normal file
455
Simulator/FDM/LaRCsim.cxx
Normal file
|
@ -0,0 +1,455 @@
|
|||
// LaRCsim.cxx -- interface to the LaRCsim flight model
|
||||
//
|
||||
// Written by Curtis Olson, started October 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#include "LaRCsim.hxx"
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Controls/controls.hxx>
|
||||
#include <Debug/logstream.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <FDM/LaRCsim/ls_cockpit.h>
|
||||
#include <FDM/LaRCsim/ls_generic.h>
|
||||
#include <FDM/LaRCsim/ls_interface.h>
|
||||
|
||||
|
||||
// Initialize the LaRCsim flight model, dt is the time increment for
|
||||
// each subsequent iteration through the EOM
|
||||
int fgLaRCsimInit(double dt) {
|
||||
ls_toplevel_init(dt);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
// Run an iteration of the EOM (equations of motion)
|
||||
int fgLaRCsimUpdate(FGInterface& f, int multiloop) {
|
||||
double save_alt = 0.0;
|
||||
|
||||
// lets try to avoid really screwing up the LaRCsim model
|
||||
if ( f.get_Altitude() < -9000.0 ) {
|
||||
save_alt = f.get_Altitude();
|
||||
f.set_Altitude( 0.0 );
|
||||
}
|
||||
|
||||
// copy control positions into the LaRCsim structure
|
||||
Lat_control = controls.get_aileron();
|
||||
Long_control = controls.get_elevator();
|
||||
Long_trim = controls.get_elevator_trim();
|
||||
Rudder_pedal = controls.get_rudder();
|
||||
Throttle_pct = controls.get_throttle( 0 );
|
||||
Brake_pct = controls.get_brake( 0 );
|
||||
|
||||
// Inform LaRCsim of the local terrain altitude
|
||||
Runway_altitude = f.get_Runway_altitude();
|
||||
|
||||
// old -- FGInterface_2_LaRCsim() not needed except for Init()
|
||||
// translate FG to LaRCsim structure
|
||||
// FGInterface_2_LaRCsim(f);
|
||||
// printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
|
||||
// printf("Altitude = %.2f\n", Altitude * 0.3048);
|
||||
// printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
|
||||
|
||||
ls_update(multiloop);
|
||||
|
||||
// printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
|
||||
// printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
|
||||
|
||||
// translate LaRCsim back to FG structure so that the
|
||||
// autopilot (and the rest of the sim can use the updated
|
||||
// values
|
||||
fgLaRCsim_2_FGInterface(f);
|
||||
|
||||
// but lets restore our original bogus altitude when we are done
|
||||
if ( save_alt < -9000.0 ) {
|
||||
f.set_Altitude( save_alt );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Convert from the FGInterface struct to the LaRCsim generic_ struct
|
||||
int FGInterface_2_LaRCsim (FGInterface& f) {
|
||||
|
||||
Mass = f.get_Mass();
|
||||
I_xx = f.get_I_xx();
|
||||
I_yy = f.get_I_yy();
|
||||
I_zz = f.get_I_zz();
|
||||
I_xz = f.get_I_xz();
|
||||
// Dx_pilot = f.get_Dx_pilot();
|
||||
// Dy_pilot = f.get_Dy_pilot();
|
||||
// Dz_pilot = f.get_Dz_pilot();
|
||||
Dx_cg = f.get_Dx_cg();
|
||||
Dy_cg = f.get_Dy_cg();
|
||||
Dz_cg = f.get_Dz_cg();
|
||||
// F_X = f.get_F_X();
|
||||
// F_Y = f.get_F_Y();
|
||||
// F_Z = f.get_F_Z();
|
||||
// F_north = f.get_F_north();
|
||||
// F_east = f.get_F_east();
|
||||
// F_down = f.get_F_down();
|
||||
// F_X_aero = f.get_F_X_aero();
|
||||
// F_Y_aero = f.get_F_Y_aero();
|
||||
// F_Z_aero = f.get_F_Z_aero();
|
||||
// F_X_engine = f.get_F_X_engine();
|
||||
// F_Y_engine = f.get_F_Y_engine();
|
||||
// F_Z_engine = f.get_F_Z_engine();
|
||||
// F_X_gear = f.get_F_X_gear();
|
||||
// F_Y_gear = f.get_F_Y_gear();
|
||||
// F_Z_gear = f.get_F_Z_gear();
|
||||
// M_l_rp = f.get_M_l_rp();
|
||||
// M_m_rp = f.get_M_m_rp();
|
||||
// M_n_rp = f.get_M_n_rp();
|
||||
// M_l_cg = f.get_M_l_cg();
|
||||
// M_m_cg = f.get_M_m_cg();
|
||||
// M_n_cg = f.get_M_n_cg();
|
||||
// M_l_aero = f.get_M_l_aero();
|
||||
// M_m_aero = f.get_M_m_aero();
|
||||
// M_n_aero = f.get_M_n_aero();
|
||||
// M_l_engine = f.get_M_l_engine();
|
||||
// M_m_engine = f.get_M_m_engine();
|
||||
// M_n_engine = f.get_M_n_engine();
|
||||
// M_l_gear = f.get_M_l_gear();
|
||||
// M_m_gear = f.get_M_m_gear();
|
||||
// M_n_gear = f.get_M_n_gear();
|
||||
// V_dot_north = f.get_V_dot_north();
|
||||
// V_dot_east = f.get_V_dot_east();
|
||||
// V_dot_down = f.get_V_dot_down();
|
||||
// U_dot_body = f.get_U_dot_body();
|
||||
// V_dot_body = f.get_V_dot_body();
|
||||
// W_dot_body = f.get_W_dot_body();
|
||||
// A_X_cg = f.get_A_X_cg();
|
||||
// A_Y_cg = f.get_A_Y_cg();
|
||||
// A_Z_cg = f.get_A_Z_cg();
|
||||
// A_X_pilot = f.get_A_X_pilot();
|
||||
// A_Y_pilot = f.get_A_Y_pilot();
|
||||
// A_Z_pilot = f.get_A_Z_pilot();
|
||||
// N_X_cg = f.get_N_X_cg();
|
||||
// N_Y_cg = f.get_N_Y_cg();
|
||||
// N_Z_cg = f.get_N_Z_cg();
|
||||
// N_X_pilot = f.get_N_X_pilot();
|
||||
// N_Y_pilot = f.get_N_Y_pilot();
|
||||
// N_Z_pilot = f.get_N_Z_pilot();
|
||||
// P_dot_body = f.get_P_dot_body();
|
||||
// Q_dot_body = f.get_Q_dot_body();
|
||||
// R_dot_body = f.get_R_dot_body();
|
||||
V_north = f.get_V_north();
|
||||
V_east = f.get_V_east();
|
||||
V_down = f.get_V_down();
|
||||
// V_north_rel_ground = f.get_V_north_rel_ground();
|
||||
// V_east_rel_ground = f.get_V_east_rel_ground();
|
||||
// V_down_rel_ground = f.get_V_down_rel_ground();
|
||||
// V_north_airmass = f.get_V_north_airmass();
|
||||
// V_east_airmass = f.get_V_east_airmass();
|
||||
// V_down_airmass = f.get_V_down_airmass();
|
||||
// V_north_rel_airmass = f.get_V_north_rel_airmass();
|
||||
// V_east_rel_airmass = f.get_V_east_rel_airmass();
|
||||
// V_down_rel_airmass = f.get_V_down_rel_airmass();
|
||||
// U_gust = f.get_U_gust();
|
||||
// V_gust = f.get_V_gust();
|
||||
// W_gust = f.get_W_gust();
|
||||
// U_body = f.get_U_body();
|
||||
// V_body = f.get_V_body();
|
||||
// W_body = f.get_W_body();
|
||||
// V_rel_wind = f.get_V_rel_wind();
|
||||
// V_true_kts = f.get_V_true_kts();
|
||||
// V_rel_ground = f.get_V_rel_ground();
|
||||
// V_inertial = f.get_V_inertial();
|
||||
// V_ground_speed = f.get_V_ground_speed();
|
||||
// V_equiv = f.get_V_equiv();
|
||||
// V_equiv_kts = f.get_V_equiv_kts();
|
||||
// V_calibrated = f.get_V_calibrated();
|
||||
// V_calibrated_kts = f.get_V_calibrated_kts();
|
||||
P_body = f.get_P_body();
|
||||
Q_body = f.get_Q_body();
|
||||
R_body = f.get_R_body();
|
||||
// P_local = f.get_P_local();
|
||||
// Q_local = f.get_Q_local();
|
||||
// R_local = f.get_R_local();
|
||||
// P_total = f.get_P_total();
|
||||
// Q_total = f.get_Q_total();
|
||||
// R_total = f.get_R_total();
|
||||
// Phi_dot = f.get_Phi_dot();
|
||||
// Theta_dot = f.get_Theta_dot();
|
||||
// Psi_dot = f.get_Psi_dot();
|
||||
// Latitude_dot = f.get_Latitude_dot();
|
||||
// Longitude_dot = f.get_Longitude_dot();
|
||||
// Radius_dot = f.get_Radius_dot();
|
||||
Lat_geocentric = f.get_Lat_geocentric();
|
||||
Lon_geocentric = f.get_Lon_geocentric();
|
||||
Radius_to_vehicle = f.get_Radius_to_vehicle();
|
||||
Latitude = f.get_Latitude();
|
||||
Longitude = f.get_Longitude();
|
||||
Altitude = f.get_Altitude();
|
||||
Phi = f.get_Phi();
|
||||
Theta = f.get_Theta();
|
||||
Psi = f.get_Psi();
|
||||
// T_local_to_body_11 = f.get_T_local_to_body_11();
|
||||
// T_local_to_body_12 = f.get_T_local_to_body_12();
|
||||
// T_local_to_body_13 = f.get_T_local_to_body_13();
|
||||
// T_local_to_body_21 = f.get_T_local_to_body_21();
|
||||
// T_local_to_body_22 = f.get_T_local_to_body_22();
|
||||
// T_local_to_body_23 = f.get_T_local_to_body_23();
|
||||
// T_local_to_body_31 = f.get_T_local_to_body_31();
|
||||
// T_local_to_body_32 = f.get_T_local_to_body_32();
|
||||
// T_local_to_body_33 = f.get_T_local_to_body_33();
|
||||
// Gravity = f.get_Gravity();
|
||||
// Centrifugal_relief = f.get_Centrifugal_relief();
|
||||
// Alpha = f.get_Alpha();
|
||||
// Beta = f.get_Beta();
|
||||
// Alpha_dot = f.get_Alpha_dot();
|
||||
// Beta_dot = f.get_Beta_dot();
|
||||
// Cos_alpha = f.get_Cos_alpha();
|
||||
// Sin_alpha = f.get_Sin_alpha();
|
||||
// Cos_beta = f.get_Cos_beta();
|
||||
// Sin_beta = f.get_Sin_beta();
|
||||
// Cos_phi = f.get_Cos_phi();
|
||||
// Sin_phi = f.get_Sin_phi();
|
||||
// Cos_theta = f.get_Cos_theta();
|
||||
// Sin_theta = f.get_Sin_theta();
|
||||
// Cos_psi = f.get_Cos_psi();
|
||||
// Sin_psi = f.get_Sin_psi();
|
||||
// Gamma_vert_rad = f.get_Gamma_vert_rad();
|
||||
// Gamma_horiz_rad = f.get_Gamma_horiz_rad();
|
||||
// Sigma = f.get_Sigma();
|
||||
// Density = f.get_Density();
|
||||
// V_sound = f.get_V_sound();
|
||||
// Mach_number = f.get_Mach_number();
|
||||
// Static_pressure = f.get_Static_pressure();
|
||||
// Total_pressure = f.get_Total_pressure();
|
||||
// Impact_pressure = f.get_Impact_pressure();
|
||||
// Dynamic_pressure = f.get_Dynamic_pressure();
|
||||
// Static_temperature = f.get_Static_temperature();
|
||||
// Total_temperature = f.get_Total_temperature();
|
||||
Sea_level_radius = f.get_Sea_level_radius();
|
||||
Earth_position_angle = f.get_Earth_position_angle();
|
||||
Runway_altitude = f.get_Runway_altitude();
|
||||
// Runway_latitude = f.get_Runway_latitude();
|
||||
// Runway_longitude = f.get_Runway_longitude();
|
||||
// Runway_heading = f.get_Runway_heading();
|
||||
// Radius_to_rwy = f.get_Radius_to_rwy();
|
||||
// D_cg_north_of_rwy = f.get_D_cg_north_of_rwy();
|
||||
// D_cg_east_of_rwy = f.get_D_cg_east_of_rwy();
|
||||
// D_cg_above_rwy = f.get_D_cg_above_rwy();
|
||||
// X_cg_rwy = f.get_X_cg_rwy();
|
||||
// Y_cg_rwy = f.get_Y_cg_rwy();
|
||||
// H_cg_rwy = f.get_H_cg_rwy();
|
||||
// D_pilot_north_of_rwy = f.get_D_pilot_north_of_rwy();
|
||||
// D_pilot_east_of_rwy = f.get_D_pilot_east_of_rwy();
|
||||
// D_pilot_above_rwy = f.get_D_pilot_above_rwy();
|
||||
// X_pilot_rwy = f.get_X_pilot_rwy();
|
||||
// Y_pilot_rwy = f.get_Y_pilot_rwy();
|
||||
// H_pilot_rwy = f.get_H_pilot_rwy();
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
// Convert from the LaRCsim generic_ struct to the FGInterface struct
|
||||
int fgLaRCsim_2_FGInterface (FGInterface& f) {
|
||||
|
||||
// Mass properties and geometry values
|
||||
f.set_Inertias( Mass, I_xx, I_yy, I_zz, I_xz );
|
||||
// f.set_Pilot_Location( Dx_pilot, Dy_pilot, Dz_pilot );
|
||||
f.set_CG_Position( Dx_cg, Dy_cg, Dz_cg );
|
||||
|
||||
// Forces
|
||||
// f.set_Forces_Body_Total( F_X, F_Y, F_Z );
|
||||
// f.set_Forces_Local_Total( F_north, F_east, F_down );
|
||||
// f.set_Forces_Aero( F_X_aero, F_Y_aero, F_Z_aero );
|
||||
// f.set_Forces_Engine( F_X_engine, F_Y_engine, F_Z_engine );
|
||||
// f.set_Forces_Gear( F_X_gear, F_Y_gear, F_Z_gear );
|
||||
|
||||
// Moments
|
||||
// f.set_Moments_Total_RP( M_l_rp, M_m_rp, M_n_rp );
|
||||
// f.set_Moments_Total_CG( M_l_cg, M_m_cg, M_n_cg );
|
||||
// f.set_Moments_Aero( M_l_aero, M_m_aero, M_n_aero );
|
||||
// f.set_Moments_Engine( M_l_engine, M_m_engine, M_n_engine );
|
||||
// f.set_Moments_Gear( M_l_gear, M_m_gear, M_n_gear );
|
||||
|
||||
// Accelerations
|
||||
// f.set_Accels_Local( V_dot_north, V_dot_east, V_dot_down );
|
||||
// f.set_Accels_Body( U_dot_body, V_dot_body, W_dot_body );
|
||||
// f.set_Accels_CG_Body( A_X_cg, A_Y_cg, A_Z_cg );
|
||||
// f.set_Accels_Pilot_Body( A_X_pilot, A_Y_pilot, A_Z_pilot );
|
||||
// f.set_Accels_CG_Body_N( N_X_cg, N_Y_cg, N_Z_cg );
|
||||
// f.set_Accels_Pilot_Body_N( N_X_pilot, N_Y_pilot, N_Z_pilot );
|
||||
// f.set_Accels_Omega( P_dot_body, Q_dot_body, R_dot_body );
|
||||
|
||||
// Velocities
|
||||
f.set_Velocities_Local( V_north, V_east, V_down );
|
||||
// f.set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground,
|
||||
// V_down_rel_ground );
|
||||
// f.set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass,
|
||||
// V_down_airmass );
|
||||
// f.set_Velocities_Local_Rel_Airmass( V_north_rel_airmass,
|
||||
// V_east_rel_airmass, V_down_rel_airmass );
|
||||
// f.set_Velocities_Gust( U_gust, V_gust, W_gust );
|
||||
// f.set_Velocities_Wind_Body( U_body, V_body, W_body );
|
||||
|
||||
// f.set_V_rel_wind( V_rel_wind );
|
||||
// f.set_V_true_kts( V_true_kts );
|
||||
// f.set_V_rel_ground( V_rel_ground );
|
||||
// f.set_V_inertial( V_inertial );
|
||||
// f.set_V_ground_speed( V_ground_speed );
|
||||
// f.set_V_equiv( V_equiv );
|
||||
f.set_V_equiv_kts( V_equiv_kts );
|
||||
// f.set_V_calibrated( V_calibrated );
|
||||
// f.set_V_calibrated_kts( V_calibrated_kts );
|
||||
|
||||
f.set_Omega_Body( P_body, Q_body, R_body );
|
||||
// f.set_Omega_Local( P_local, Q_local, R_local );
|
||||
// f.set_Omega_Total( P_total, Q_total, R_total );
|
||||
|
||||
// f.set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot );
|
||||
f.set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot );
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << Longitude
|
||||
<< " lat_geoc = " << Lat_geocentric << " lat_geod = " << Latitude
|
||||
<< " alt = " << Altitude << " sl_radius = " << Sea_level_radius
|
||||
<< " radius_to_vehicle = " << Radius_to_vehicle );
|
||||
|
||||
// Positions
|
||||
f.set_Geocentric_Position( Lat_geocentric, Lon_geocentric,
|
||||
Radius_to_vehicle );
|
||||
f.set_Geodetic_Position( Latitude, Longitude, Altitude );
|
||||
f.set_Euler_Angles( Phi, Theta, Psi );
|
||||
|
||||
// Miscellaneous quantities
|
||||
f.set_T_Local_to_Body(T_local_to_body_m);
|
||||
// f.set_Gravity( Gravity );
|
||||
// f.set_Centrifugal_relief( Centrifugal_relief );
|
||||
|
||||
f.set_Alpha( Alpha );
|
||||
f.set_Beta( Beta );
|
||||
// f.set_Alpha_dot( Alpha_dot );
|
||||
// f.set_Beta_dot( Beta_dot );
|
||||
|
||||
// f.set_Cos_alpha( Cos_alpha );
|
||||
// f.set_Sin_alpha( Sin_alpha );
|
||||
// f.set_Cos_beta( Cos_beta );
|
||||
// f.set_Sin_beta( Sin_beta );
|
||||
|
||||
// f.set_Cos_phi( Cos_phi );
|
||||
// f.set_Sin_phi( Sin_phi );
|
||||
// f.set_Cos_theta( Cos_theta );
|
||||
// f.set_Sin_theta( Sin_theta );
|
||||
// f.set_Cos_psi( Cos_psi );
|
||||
// f.set_Sin_psi( Sin_psi );
|
||||
|
||||
f.set_Gamma_vert_rad( Gamma_vert_rad );
|
||||
// f.set_Gamma_horiz_rad( Gamma_horiz_rad );
|
||||
|
||||
// f.set_Sigma( Sigma );
|
||||
// f.set_Density( Density );
|
||||
// f.set_V_sound( V_sound );
|
||||
// f.set_Mach_number( Mach_number );
|
||||
|
||||
// f.set_Static_pressure( Static_pressure );
|
||||
// f.set_Total_pressure( Total_pressure );
|
||||
// f.set_Impact_pressure( Impact_pressure );
|
||||
// f.set_Dynamic_pressure( Dynamic_pressure );
|
||||
|
||||
// f.set_Static_temperature( Static_temperature );
|
||||
// f.set_Total_temperature( Total_temperature );
|
||||
|
||||
f.set_Sea_level_radius( Sea_level_radius );
|
||||
f.set_Earth_position_angle( Earth_position_angle );
|
||||
|
||||
f.set_Runway_altitude( Runway_altitude );
|
||||
// f.set_Runway_latitude( Runway_latitude );
|
||||
// f.set_Runway_longitude( Runway_longitude );
|
||||
// f.set_Runway_heading( Runway_heading );
|
||||
// f.set_Radius_to_rwy( Radius_to_rwy );
|
||||
|
||||
// f.set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy);
|
||||
// f.set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy );
|
||||
// f.set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy,
|
||||
// D_pilot_above_rwy );
|
||||
// f.set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy );
|
||||
|
||||
f.set_sin_lat_geocentric(Lat_geocentric);
|
||||
f.set_cos_lat_geocentric(Lat_geocentric);
|
||||
f.set_sin_cos_longitude(Longitude);
|
||||
f.set_sin_cos_latitude(Latitude);
|
||||
|
||||
// printf("sin_lat_geo %f cos_lat_geo %f\n", sin_Lat_geoc, cos_Lat_geoc);
|
||||
// printf("sin_lat %f cos_lat %f\n",
|
||||
// f.get_sin_latitude(), f.get_cos_latitude());
|
||||
// printf("sin_lon %f cos_lon %f\n",
|
||||
// f.get_sin_longitude(), f.get_cos_longitude());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.12 1999/04/03 04:20:02 curt
|
||||
// Optimizations (tm) by Norman Vine.
|
||||
//
|
||||
// Revision 1.11 1999/02/05 21:28:58 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.10 1999/02/01 21:33:30 curt
|
||||
// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
|
||||
// Jon accepted my offer to do this and thought it was a good idea.
|
||||
//
|
||||
// Revision 1.9 1999/01/08 19:27:36 curt
|
||||
// Fixed AOA reading on HUD.
|
||||
// Continued work on time jitter compensation.
|
||||
//
|
||||
// Revision 1.8 1998/12/18 23:37:06 curt
|
||||
// Collapsed out the FGState variables not currently needed. They are just
|
||||
// commented out and can be readded easily at any time. The point of this
|
||||
// exersize is to determine which variables were or were not currently being
|
||||
// used.
|
||||
//
|
||||
// Revision 1.7 1998/12/14 13:31:06 curt
|
||||
// LaRCsim maintains all it's variables internally. I had been copying all of
|
||||
// them back and forth to the FG struture everytime I updated the flight model.
|
||||
// However, I have realized that this is not necessary. I just need to copy
|
||||
// the control positions and environmental parameters into the LaRCsim structure
|
||||
// before updating the FDM, then copy every thing back out into the publick FGFS
|
||||
// structure afterwords. This seems to solve (or at least help) a westward
|
||||
// drift problem some poeple had been observing.
|
||||
//
|
||||
// Revision 1.6 1998/12/05 15:54:08 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.5 1998/12/03 04:25:02 curt
|
||||
// Working on fixing up new fgFLIGHT class.
|
||||
//
|
||||
// Revision 1.4 1998/12/03 01:16:37 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
//
|
||||
// Revision 1.3 1998/10/25 14:08:43 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.2 1998/10/17 01:34:11 curt
|
||||
// C++ ifying ...
|
||||
//
|
||||
// Revision 1.1 1998/10/17 00:43:58 curt
|
||||
// Initial revision.
|
||||
//
|
||||
//
|
65
Simulator/FDM/LaRCsim.hxx
Normal file
65
Simulator/FDM/LaRCsim.hxx
Normal file
|
@ -0,0 +1,65 @@
|
|||
//*************************************************************************
|
||||
// LaRCsim.hxx -- interface to the "LaRCsim" flight model
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 _LARCSIM_HXX
|
||||
#define _LARCSIM_HXX
|
||||
|
||||
|
||||
#include "flight.hxx"
|
||||
|
||||
|
||||
// reset flight params to a specific position
|
||||
int fgLaRCsimInit(double dt);
|
||||
|
||||
// update position based on inputs, positions, velocities, etc.
|
||||
int fgLaRCsimUpdate(FGInterface& f, int multiloop);
|
||||
|
||||
// Convert from the FGInterface struct to the LaRCsim generic_ struct
|
||||
int FGInterface_2_LaRCsim (FGInterface& f);
|
||||
|
||||
// Convert from the LaRCsim generic_ struct to the FGInterface struct
|
||||
int fgLaRCsim_2_FGInterface (FGInterface& f);
|
||||
|
||||
|
||||
#endif // _LARCSIM_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.5 1999/02/05 21:28:59 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.4 1998/12/05 15:54:09 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.3 1998/12/03 01:16:38 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
//
|
||||
// Revision 1.2 1998/10/17 01:34:13 curt
|
||||
// C++ ifying ...
|
||||
//
|
||||
// Revision 1.1 1998/10/17 00:43:58 curt
|
||||
// Initial revision.
|
||||
//
|
11
Simulator/FDM/Makefile.am
Normal file
11
Simulator/FDM/Makefile.am
Normal file
|
@ -0,0 +1,11 @@
|
|||
SUBDIRS = External JSBsim LaRCsim Slew
|
||||
|
||||
noinst_LIBRARIES = libFlight.a
|
||||
|
||||
libFlight_a_SOURCES = flight.cxx flight.hxx \
|
||||
JSBsim.cxx JSBsim.hxx \
|
||||
LaRCsim.cxx LaRCsim.hxx
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
||||
|
||||
DEFS += -DFGFS
|
326
Simulator/FDM/flight.cxx
Normal file
326
Simulator/FDM/flight.cxx
Normal file
|
@ -0,0 +1,326 @@
|
|||
// flight.c -- a general interface to the various flight models
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 <Debug/logstream.hxx>
|
||||
#include <FDM/External/external.hxx>
|
||||
#include <FDM/LaRCsim/ls_interface.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Math/fg_geodesy.hxx>
|
||||
#include <Time/timestamp.hxx>
|
||||
|
||||
#include "flight.hxx"
|
||||
#include "JSBsim.hxx"
|
||||
#include "LaRCsim.hxx"
|
||||
|
||||
|
||||
// base_fdm_state is the internal state that is updated in integer
|
||||
// multiples of "dt". This leads to "jitter" with respect to the real
|
||||
// world time, so we introduce cur_fdm_state which is extrapolated by
|
||||
// the difference between sim time and real world time
|
||||
|
||||
FGInterface cur_fdm_state;
|
||||
FGInterface base_fdm_state;
|
||||
|
||||
|
||||
// Extrapolate fdm based on time_offset (in usec)
|
||||
void FGInterface::extrapolate( int time_offset ) {
|
||||
double dt = time_offset / 1000000.0;
|
||||
cout << "extrapolating FDM by dt = " << dt << endl;
|
||||
|
||||
double lat = geodetic_position_v[0] + geocentric_rates_v[0] * dt;
|
||||
double lat_geoc = geocentric_position_v[0] + geocentric_rates_v[0] * dt;
|
||||
|
||||
double lon = geodetic_position_v[1] + geocentric_rates_v[1] * dt;
|
||||
double lon_geoc = geocentric_position_v[1] + geocentric_rates_v[1] * dt;
|
||||
|
||||
double alt = geodetic_position_v[2] + geocentric_rates_v[2] * dt;
|
||||
double radius = geocentric_position_v[2] + geocentric_rates_v[2] * dt;
|
||||
|
||||
geodetic_position_v[0] = lat;
|
||||
geocentric_position_v[0] = lat_geoc;
|
||||
|
||||
geodetic_position_v[1] = lon;
|
||||
geocentric_position_v[1] = lon_geoc;
|
||||
|
||||
geodetic_position_v[2] = alt;
|
||||
geocentric_position_v[2] = radius;
|
||||
}
|
||||
|
||||
|
||||
// Initialize the flight model parameters
|
||||
int fgFDMInit(int model, FGInterface& f, double dt) {
|
||||
double save_alt = 0.0;
|
||||
|
||||
FG_LOG( FG_FLIGHT ,FG_INFO, "Initializing flight model" );
|
||||
|
||||
base_fdm_state = f;
|
||||
|
||||
if ( model == FGInterface::FG_SLEW ) {
|
||||
// fgSlewInit(dt);
|
||||
} else if ( model == FGInterface::FG_JSBSIM ) {
|
||||
fgJSBsimInit(dt);
|
||||
fgJSBsim_2_FGInterface(base_fdm_state);
|
||||
} else if ( model == FGInterface::FG_LARCSIM ) {
|
||||
// lets try to avoid really screwing up the LaRCsim model
|
||||
if ( base_fdm_state.get_Altitude() < -9000.0 ) {
|
||||
save_alt = base_fdm_state.get_Altitude();
|
||||
base_fdm_state.set_Altitude( 0.0 );
|
||||
}
|
||||
|
||||
// translate FG to LaRCsim structure
|
||||
FGInterface_2_LaRCsim(base_fdm_state);
|
||||
|
||||
// initialize LaRCsim
|
||||
fgLaRCsimInit(dt);
|
||||
|
||||
FG_LOG( FG_FLIGHT, FG_INFO, "FG pos = " <<
|
||||
base_fdm_state.get_Latitude() );
|
||||
|
||||
// translate LaRCsim back to FG structure
|
||||
fgLaRCsim_2_FGInterface(base_fdm_state);
|
||||
|
||||
// but lets restore our original bogus altitude when we are done
|
||||
if ( save_alt < -9000.0 ) {
|
||||
base_fdm_state.set_Altitude( save_alt );
|
||||
}
|
||||
} else if ( model == FGInterface::FG_EXTERNAL ) {
|
||||
fgExternalInit(base_fdm_state);
|
||||
} else {
|
||||
FG_LOG( FG_FLIGHT, FG_WARN,
|
||||
"Unimplemented flight model == " << model );
|
||||
}
|
||||
|
||||
// set valid time for this record
|
||||
base_fdm_state.stamp_time();
|
||||
|
||||
f = base_fdm_state;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Run multiloop iterations of the flight model
|
||||
int fgFDMUpdate(int model, FGInterface& f, int multiloop, int time_offset) {
|
||||
double time_step, start_elev, end_elev;
|
||||
|
||||
// printf("Altitude = %.2f\n", FG_Altitude * 0.3048);
|
||||
|
||||
// set valid time for this record
|
||||
base_fdm_state.stamp_time();
|
||||
|
||||
time_step = (1.0 / DEFAULT_MODEL_HZ) * multiloop;
|
||||
start_elev = base_fdm_state.get_Altitude();
|
||||
|
||||
if ( model == FGInterface::FG_SLEW ) {
|
||||
// fgSlewUpdate(f, multiloop);
|
||||
} else if ( model == FGInterface::FG_JSBSIM ) {
|
||||
fgJSBsimUpdate(base_fdm_state, multiloop);
|
||||
f = base_fdm_state;
|
||||
} else if ( model == FGInterface::FG_LARCSIM ) {
|
||||
fgLaRCsimUpdate(base_fdm_state, multiloop);
|
||||
// extrapolate position based on actual time
|
||||
// f = extrapolate_fdm( base_fdm_state, time_offset );
|
||||
f = base_fdm_state;
|
||||
} else if ( model == FGInterface::FG_EXTERNAL ) {
|
||||
// fgExternalUpdate(f, multiloop);
|
||||
FGTimeStamp current;
|
||||
current.stamp();
|
||||
f = base_fdm_state;
|
||||
f.extrapolate( current - base_fdm_state.get_time_stamp() );
|
||||
} else {
|
||||
FG_LOG( FG_FLIGHT, FG_WARN,
|
||||
"Unimplemented flight model == " << model );
|
||||
}
|
||||
|
||||
end_elev = base_fdm_state.get_Altitude();
|
||||
|
||||
if ( time_step > 0.0 ) {
|
||||
// feet per second
|
||||
base_fdm_state.set_Climb_Rate( (end_elev - start_elev) / time_step );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Set the altitude (force)
|
||||
void fgFDMForceAltitude(int model, double alt_meters) {
|
||||
double sea_level_radius_meters;
|
||||
double lat_geoc;
|
||||
|
||||
// Set the FG variables first
|
||||
fgGeodToGeoc( base_fdm_state.get_Latitude(), alt_meters,
|
||||
&sea_level_radius_meters, &lat_geoc);
|
||||
|
||||
base_fdm_state.set_Altitude( alt_meters * METER_TO_FEET );
|
||||
base_fdm_state.set_Radius_to_vehicle( base_fdm_state.get_Altitude() +
|
||||
(sea_level_radius_meters *
|
||||
METER_TO_FEET) );
|
||||
|
||||
// additional work needed for some flight models
|
||||
if ( model == FGInterface::FG_LARCSIM ) {
|
||||
ls_ForceAltitude( base_fdm_state.get_Altitude() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the local ground elevation
|
||||
void fgFDMSetGroundElevation(int model, double ground_meters) {
|
||||
base_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET );
|
||||
cur_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET );
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.17 1999/04/03 04:20:03 curt
|
||||
// Optimizations (tm) by Norman Vine.
|
||||
//
|
||||
// Revision 1.16 1999/02/26 22:09:12 curt
|
||||
// Added initial support for native SGI compilers.
|
||||
// Integrated Jon's next version of JSBsim.
|
||||
//
|
||||
// Revision 1.15 1999/02/05 21:29:01 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.14 1999/02/01 21:33:31 curt
|
||||
// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
|
||||
// Jon accepted my offer to do this and thought it was a good idea.
|
||||
//
|
||||
// Revision 1.13 1999/01/27 04:48:39 curt
|
||||
// Set the runway height in cur_fdm_state as well as base_fdm_state.
|
||||
//
|
||||
// Revision 1.12 1999/01/20 13:42:22 curt
|
||||
// Tweaked FDM interface.
|
||||
// Testing check sum support for NMEA serial output.
|
||||
//
|
||||
// Revision 1.11 1999/01/19 17:52:06 curt
|
||||
// Working on being able to extrapolate a new position and orientation
|
||||
// based on a position, orientation, and time offset.
|
||||
//
|
||||
// Revision 1.10 1999/01/09 13:37:32 curt
|
||||
// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms.
|
||||
//
|
||||
// Revision 1.9 1999/01/08 19:27:37 curt
|
||||
// Fixed AOA reading on HUD.
|
||||
// Continued work on time jitter compensation.
|
||||
//
|
||||
// Revision 1.8 1999/01/08 03:23:51 curt
|
||||
// Beginning work on compensating for sim time vs. real world time "jitter".
|
||||
//
|
||||
// Revision 1.7 1998/12/18 23:37:07 curt
|
||||
// Collapsed out the FGState variables not currently needed. They are just
|
||||
// commented out and can be readded easily at any time. The point of this
|
||||
// exersize is to determine which variables were or were not currently being
|
||||
// used.
|
||||
//
|
||||
// Revision 1.6 1998/12/05 15:54:11 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.5 1998/12/04 01:29:39 curt
|
||||
// Stubbed in a new flight model called "External" which is expected to be driven
|
||||
// from some external source.
|
||||
//
|
||||
// Revision 1.4 1998/12/03 01:16:40 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
//
|
||||
// Revision 1.3 1998/11/06 21:18:03 curt
|
||||
// Converted to new logstream debugging facility. This allows release
|
||||
// builds with no messages at all (and no performance impact) by using
|
||||
// the -DFG_NDEBUGNDEBUG flag.
|
||||
//
|
||||
// Revision 1.2 1998/10/16 23:27:40 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.1 1998/10/16 20:16:41 curt
|
||||
// Renamed flight.[ch] to flight.[ch]xx
|
||||
//
|
||||
// Revision 1.19 1998/09/29 14:57:38 curt
|
||||
// c++-ified comments.
|
||||
//
|
||||
// Revision 1.18 1998/09/29 02:02:40 curt
|
||||
// Added a rate of climb calculation.
|
||||
//
|
||||
// Revision 1.17 1998/08/24 20:09:07 curt
|
||||
// .
|
||||
//
|
||||
// Revision 1.16 1998/08/22 14:49:55 curt
|
||||
// Attempting to iron out seg faults and crashes.
|
||||
// Did some shuffling to fix a initialization order problem between view
|
||||
// position, scenery elevation.
|
||||
//
|
||||
// Revision 1.15 1998/07/30 23:44:36 curt
|
||||
// Beginning to add support for multiple flight models.
|
||||
//
|
||||
// Revision 1.14 1998/07/12 03:08:27 curt
|
||||
// Added fgFlightModelSetAltitude() to force the altitude to something
|
||||
// other than the current altitude. LaRCsim doesn't let you do this by just
|
||||
// changing FG_Altitude.
|
||||
//
|
||||
// Revision 1.13 1998/04/25 22:06:28 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.12 1998/04/21 16:59:33 curt
|
||||
// Integrated autopilot.
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.11 1998/04/18 04:14:04 curt
|
||||
// Moved fg_debug.c to it's own library.
|
||||
//
|
||||
// Revision 1.10 1998/02/07 15:29:37 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.9 1998/01/27 00:47:53 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.8 1998/01/19 19:27:03 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.7 1998/01/19 18:40:23 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.6 1998/01/19 18:35:43 curt
|
||||
// Minor tweaks and fixes for cygwin32.
|
||||
//
|
||||
// Revision 1.5 1997/12/30 20:47:37 curt
|
||||
// Integrated new event manager with subsystem initializations.
|
||||
//
|
||||
// Revision 1.4 1997/12/10 22:37:42 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.3 1997/08/27 03:30:04 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.2 1997/05/29 22:39:57 curt
|
||||
// Working on incorporating the LaRCsim flight model.
|
||||
//
|
||||
// Revision 1.1 1997/05/29 02:35:04 curt
|
||||
// Initial revision.
|
||||
//
|
978
Simulator/FDM/flight.hxx
Normal file
978
Simulator/FDM/flight.hxx
Normal file
|
@ -0,0 +1,978 @@
|
|||
// flight.hxx -- define shared flight model parameters
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 _FLIGHT_HXX
|
||||
#define _FLIGHT_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
/* Required get_()
|
||||
|
||||
`FGInterface::get_Longitude ()'
|
||||
`FGInterface::get_Latitude ()'
|
||||
`FGInterface::get_Altitude ()'
|
||||
`FGInterface::get_Phi ()'
|
||||
`FGInterface::get_Theta ()'
|
||||
`FGInterface::get_Psi ()'
|
||||
`FGInterface::get_V_equiv_kts ()'
|
||||
|
||||
`FGInterface::get_Mass ()'
|
||||
`FGInterface::get_I_xx ()'
|
||||
`FGInterface::get_I_yy ()'
|
||||
`FGInterface::get_I_zz ()'
|
||||
`FGInterface::get_I_xz ()'
|
||||
|
||||
`FGInterface::get_V_north ()'
|
||||
`FGInterface::get_V_east ()'
|
||||
`FGInterface::get_V_down ()'
|
||||
|
||||
`FGInterface::get_P_Body ()'
|
||||
`FGInterface::get_Q_Body ()'
|
||||
`FGInterface::get_R_Body ()'
|
||||
|
||||
`FGInterface::get_Gamma_vert_rad ()'
|
||||
`FGInterface::get_Climb_Rate ()'
|
||||
`FGInterface::get_Alpha ()'
|
||||
`FGInterface::get_Beta ()'
|
||||
|
||||
`FGInterface::get_Runway_altitude ()'
|
||||
|
||||
`FGInterface::get_Lon_geocentric ()'
|
||||
`FGInterface::get_Lat_geocentric ()'
|
||||
`FGInterface::get_Sea_level_radius ()'
|
||||
`FGInterface::get_Earth_position_angle ()'
|
||||
|
||||
`FGInterface::get_Latitude_dot()'
|
||||
`FGInterface::get_Longitude_dot()'
|
||||
`FGInterface::get_Radius_dot()'
|
||||
|
||||
`FGInterface::get_Dx_cg ()'
|
||||
`FGInterface::get_Dy_cg ()'
|
||||
`FGInterface::get_Dz_cg ()'
|
||||
|
||||
`FGInterface::get_T_local_to_body_11 ()' ... `FGInterface::get_T_local_to_body_33 ()'
|
||||
|
||||
`FGInterface::get_Radius_to_vehicle ()'
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <Time/timestamp.hxx>
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
typedef double FG_VECTOR_3[3];
|
||||
|
||||
|
||||
// This is based heavily on LaRCsim/ls_generic.h
|
||||
class FGInterface {
|
||||
|
||||
public:
|
||||
|
||||
// Define the various supported flight models (many not yet implemented)
|
||||
enum {
|
||||
// Slew (in MS terminology)
|
||||
FG_SLEW = 0,
|
||||
|
||||
// The NASA LaRCsim (Navion) flight model
|
||||
FG_LARCSIM = 1,
|
||||
|
||||
// Jon S. Berndt's new FDM written from the ground up in C++
|
||||
FG_JSBSIM = 2,
|
||||
|
||||
// The following aren't implemented but are here to spark
|
||||
// thoughts and discussions, and maybe even action.
|
||||
FG_ACM = 3,
|
||||
FG_SUPER_SONIC = 4,
|
||||
FG_HELICOPTER = 5,
|
||||
FG_AUTOGYRO = 6,
|
||||
FG_BALLOON = 7,
|
||||
FG_PARACHUTE = 8,
|
||||
|
||||
// Driven externally via a serial port, net, file, etc.
|
||||
FG_EXTERNAL = 9
|
||||
};
|
||||
|
||||
/*================== Mass properties and geometry values ==================*/
|
||||
|
||||
// Inertias
|
||||
double mass, i_xx, i_yy, i_zz, i_xz;
|
||||
inline double get_Mass() const { return mass; }
|
||||
inline double get_I_xx() const { return i_xx; }
|
||||
inline double get_I_yy() const { return i_yy; }
|
||||
inline double get_I_zz() const { return i_zz; }
|
||||
inline double get_I_xz() const { return i_xz; }
|
||||
inline void set_Inertias( double m, double xx, double yy,
|
||||
double zz, double xz)
|
||||
{
|
||||
mass = m;
|
||||
i_xx = xx;
|
||||
i_yy = yy;
|
||||
i_zz = zz;
|
||||
i_xz = xz;
|
||||
}
|
||||
|
||||
// Pilot location rel to ref pt
|
||||
FG_VECTOR_3 d_pilot_rp_body_v;
|
||||
// inline double * get_D_pilot_rp_body_v() {
|
||||
// return d_pilot_rp_body_v;
|
||||
// }
|
||||
// inline double get_Dx_pilot() const { return d_pilot_rp_body_v[0]; }
|
||||
// inline double get_Dy_pilot() const { return d_pilot_rp_body_v[1]; }
|
||||
// inline double get_Dz_pilot() const { return d_pilot_rp_body_v[2]; }
|
||||
/* inline void set_Pilot_Location( double dx, double dy, double dz ) {
|
||||
d_pilot_rp_body_v[0] = dx;
|
||||
d_pilot_rp_body_v[1] = dy;
|
||||
d_pilot_rp_body_v[2] = dz;
|
||||
} */
|
||||
|
||||
// CG position w.r.t. ref. point
|
||||
FG_VECTOR_3 d_cg_rp_body_v;
|
||||
// inline double * get_D_cg_rp_body_v() { return d_cg_rp_body_v; }
|
||||
inline double get_Dx_cg() const { return d_cg_rp_body_v[0]; }
|
||||
inline double get_Dy_cg() const { return d_cg_rp_body_v[1]; }
|
||||
inline double get_Dz_cg() const { return d_cg_rp_body_v[2]; }
|
||||
inline void set_CG_Position( double dx, double dy, double dz ) {
|
||||
d_cg_rp_body_v[0] = dx;
|
||||
d_cg_rp_body_v[1] = dy;
|
||||
d_cg_rp_body_v[2] = dz;
|
||||
}
|
||||
|
||||
/*================================ Forces =================================*/
|
||||
|
||||
FG_VECTOR_3 f_body_total_v;
|
||||
// inline double * get_F_body_total_v() { return f_body_total_v; }
|
||||
// inline double get_F_X() const { return f_body_total_v[0]; }
|
||||
// inline double get_F_Y() const { return f_body_total_v[1]; }
|
||||
// inline double get_F_Z() const { return f_body_total_v[2]; }
|
||||
/* inline void set_Forces_Body_Total( double x, double y, double z ) {
|
||||
f_body_total_v[0] = x;
|
||||
f_body_total_v[1] = y;
|
||||
f_body_total_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 f_local_total_v;
|
||||
// inline double * get_F_local_total_v() { return f_local_total_v; }
|
||||
// inline double get_F_north() const { return f_local_total_v[0]; }
|
||||
// inline double get_F_east() const { return f_local_total_v[1]; }
|
||||
// inline double get_F_down() const { return f_local_total_v[2]; }
|
||||
/* inline void set_Forces_Local_Total( double x, double y, double z ) {
|
||||
f_local_total_v[0] = x;
|
||||
f_local_total_v[1] = y;
|
||||
f_local_total_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 f_aero_v;
|
||||
// inline double * get_F_aero_v() { return f_aero_v; }
|
||||
// inline double get_F_X_aero() const { return f_aero_v[0]; }
|
||||
// inline double get_F_Y_aero() const { return f_aero_v[1]; }
|
||||
// inline double get_F_Z_aero() const { return f_aero_v[2]; }
|
||||
/* inline void set_Forces_Aero( double x, double y, double z ) {
|
||||
f_aero_v[0] = x;
|
||||
f_aero_v[1] = y;
|
||||
f_aero_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 f_engine_v;
|
||||
// inline double * get_F_engine_v() { return f_engine_v; }
|
||||
// inline double get_F_X_engine() const { return f_engine_v[0]; }
|
||||
// inline double get_F_Y_engine() const { return f_engine_v[1]; }
|
||||
// inline double get_F_Z_engine() const { return f_engine_v[2]; }
|
||||
/* inline void set_Forces_Engine( double x, double y, double z ) {
|
||||
f_engine_v[0] = x;
|
||||
f_engine_v[1] = y;
|
||||
f_engine_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 f_gear_v;
|
||||
// inline double * get_F_gear_v() { return f_gear_v; }
|
||||
// inline double get_F_X_gear() const { return f_gear_v[0]; }
|
||||
// inline double get_F_Y_gear() const { return f_gear_v[1]; }
|
||||
// inline double get_F_Z_gear() const { return f_gear_v[2]; }
|
||||
/* inline void set_Forces_Gear( double x, double y, double z ) {
|
||||
f_gear_v[0] = x;
|
||||
f_gear_v[1] = y;
|
||||
f_gear_v[2] = z;
|
||||
} */
|
||||
|
||||
/*================================ Moments ================================*/
|
||||
|
||||
FG_VECTOR_3 m_total_rp_v;
|
||||
// inline double * get_M_total_rp_v() { return m_total_rp_v; }
|
||||
// inline double get_M_l_rp() const { return m_total_rp_v[0]; }
|
||||
// inline double get_M_m_rp() const { return m_total_rp_v[1]; }
|
||||
// inline double get_M_n_rp() const { return m_total_rp_v[2]; }
|
||||
/* inline void set_Moments_Total_RP( double l, double m, double n ) {
|
||||
m_total_rp_v[0] = l;
|
||||
m_total_rp_v[1] = m;
|
||||
m_total_rp_v[2] = n;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 m_total_cg_v;
|
||||
// inline double * get_M_total_cg_v() { return m_total_cg_v; }
|
||||
// inline double get_M_l_cg() const { return m_total_cg_v[0]; }
|
||||
// inline double get_M_m_cg() const { return m_total_cg_v[1]; }
|
||||
// inline double get_M_n_cg() const { return m_total_cg_v[2]; }
|
||||
/* inline void set_Moments_Total_CG( double l, double m, double n ) {
|
||||
m_total_cg_v[0] = l;
|
||||
m_total_cg_v[1] = m;
|
||||
m_total_cg_v[2] = n;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 m_aero_v;
|
||||
// inline double * get_M_aero_v() { return m_aero_v; }
|
||||
// inline double get_M_l_aero() const { return m_aero_v[0]; }
|
||||
// inline double get_M_m_aero() const { return m_aero_v[1]; }
|
||||
// inline double get_M_n_aero() const { return m_aero_v[2]; }
|
||||
/* inline void set_Moments_Aero( double l, double m, double n ) {
|
||||
m_aero_v[0] = l;
|
||||
m_aero_v[1] = m;
|
||||
m_aero_v[2] = n;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 m_engine_v;
|
||||
// inline double * get_M_engine_v() { return m_engine_v; }
|
||||
// inline double get_M_l_engine() const { return m_engine_v[0]; }
|
||||
// inline double get_M_m_engine() const { return m_engine_v[1]; }
|
||||
// inline double get_M_n_engine() const { return m_engine_v[2]; }
|
||||
/* inline void set_Moments_Engine( double l, double m, double n ) {
|
||||
m_engine_v[0] = l;
|
||||
m_engine_v[1] = m;
|
||||
m_engine_v[2] = n;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 m_gear_v;
|
||||
// inline double * get_M_gear_v() { return m_gear_v; }
|
||||
// inline double get_M_l_gear() const { return m_gear_v[0]; }
|
||||
// inline double get_M_m_gear() const { return m_gear_v[1]; }
|
||||
// inline double get_M_n_gear() const { return m_gear_v[2]; }
|
||||
/* inline void set_Moments_Gear( double l, double m, double n ) {
|
||||
m_gear_v[0] = l;
|
||||
m_gear_v[1] = m;
|
||||
m_gear_v[2] = n;
|
||||
} */
|
||||
|
||||
/*============================== Accelerations ============================*/
|
||||
|
||||
FG_VECTOR_3 v_dot_local_v;
|
||||
// inline double * get_V_dot_local_v() { return v_dot_local_v; }
|
||||
// inline double get_V_dot_north() const { return v_dot_local_v[0]; }
|
||||
// inline double get_V_dot_east() const { return v_dot_local_v[1]; }
|
||||
// inline double get_V_dot_down() const { return v_dot_local_v[2]; }
|
||||
/* inline void set_Accels_Local( double north, double east, double down ) {
|
||||
v_dot_local_v[0] = north;
|
||||
v_dot_local_v[1] = east;
|
||||
v_dot_local_v[2] = down;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 v_dot_body_v;
|
||||
// inline double * get_V_dot_body_v() { return v_dot_body_v; }
|
||||
// inline double get_U_dot_body() const { return v_dot_body_v[0]; }
|
||||
// inline double get_V_dot_body() const { return v_dot_body_v[1]; }
|
||||
// inline double get_W_dot_body() const { return v_dot_body_v[2]; }
|
||||
/* inline void set_Accels_Body( double u, double v, double w ) {
|
||||
v_dot_local_v[0] = u;
|
||||
v_dot_local_v[1] = v;
|
||||
v_dot_local_v[2] = w;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 a_cg_body_v;
|
||||
// inline double * get_A_cg_body_v() { return a_cg_body_v; }
|
||||
// inline double get_A_X_cg() const { return a_cg_body_v[0]; }
|
||||
// inline double get_A_Y_cg() const { return a_cg_body_v[1]; }
|
||||
// inline double get_A_Z_cg() const { return a_cg_body_v[2]; }
|
||||
/* inline void set_Accels_CG_Body( double x, double y, double z ) {
|
||||
a_cg_body_v[0] = x;
|
||||
a_cg_body_v[1] = y;
|
||||
a_cg_body_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 a_pilot_body_v;
|
||||
// inline double * get_A_pilot_body_v() { return a_pilot_body_v; }
|
||||
// inline double get_A_X_pilot() const { return a_pilot_body_v[0]; }
|
||||
// inline double get_A_Y_pilot() const { return a_pilot_body_v[1]; }
|
||||
// inline double get_A_Z_pilot() const { return a_pilot_body_v[2]; }
|
||||
/* inline void set_Accels_Pilot_Body( double x, double y, double z ) {
|
||||
a_pilot_body_v[0] = x;
|
||||
a_pilot_body_v[1] = y;
|
||||
a_pilot_body_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 n_cg_body_v;
|
||||
// inline double * get_N_cg_body_v() { return n_cg_body_v; }
|
||||
// inline double get_N_X_cg() const { return n_cg_body_v[0]; }
|
||||
// inline double get_N_Y_cg() const { return n_cg_body_v[1]; }
|
||||
// inline double get_N_Z_cg() const { return n_cg_body_v[2]; }
|
||||
/* inline void set_Accels_CG_Body_N( double x, double y, double z ) {
|
||||
n_cg_body_v[0] = x;
|
||||
n_cg_body_v[1] = y;
|
||||
n_cg_body_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 n_pilot_body_v;
|
||||
// inline double * get_N_pilot_body_v() { return n_pilot_body_v; }
|
||||
// inline double get_N_X_pilot() const { return n_pilot_body_v[0]; }
|
||||
// inline double get_N_Y_pilot() const { return n_pilot_body_v[1]; }
|
||||
// inline double get_N_Z_pilot() const { return n_pilot_body_v[2]; }
|
||||
/* inline void set_Accels_Pilot_Body_N( double x, double y, double z ) {
|
||||
n_pilot_body_v[0] = x;
|
||||
n_pilot_body_v[1] = y;
|
||||
n_pilot_body_v[2] = z;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 omega_dot_body_v;
|
||||
// inline double * get_Omega_dot_body_v() { return omega_dot_body_v; }
|
||||
// inline double get_P_dot_body() const { return omega_dot_body_v[0]; }
|
||||
// inline double get_Q_dot_body() const { return omega_dot_body_v[1]; }
|
||||
// inline double get_R_dot_body() const { return omega_dot_body_v[2]; }
|
||||
/* inline void set_Accels_Omega( double p, double q, double r ) {
|
||||
omega_dot_body_v[0] = p;
|
||||
omega_dot_body_v[1] = q;
|
||||
omega_dot_body_v[2] = r;
|
||||
} */
|
||||
|
||||
|
||||
/*============================== Velocities ===============================*/
|
||||
|
||||
FG_VECTOR_3 v_local_v;
|
||||
// inline double * get_V_local_v() { return v_local_v; }
|
||||
inline double get_V_north() const { return v_local_v[0]; }
|
||||
inline double get_V_east() const { return v_local_v[1]; }
|
||||
inline double get_V_down() const { return v_local_v[2]; }
|
||||
inline void set_Velocities_Local( double north, double east, double down ) {
|
||||
v_local_v[0] = north;
|
||||
v_local_v[1] = east;
|
||||
v_local_v[2] = down;
|
||||
}
|
||||
|
||||
FG_VECTOR_3 v_local_rel_ground_v; // V rel w.r.t. earth surface
|
||||
// inline double * get_V_local_rel_ground_v() { return v_local_rel_ground_v; }
|
||||
// inline double get_V_north_rel_ground() const {
|
||||
// return v_local_rel_ground_v[0];
|
||||
// }
|
||||
// inline double get_V_east_rel_ground() const {
|
||||
// return v_local_rel_ground_v[1];
|
||||
// }
|
||||
// inline double get_V_down_rel_ground() const {
|
||||
// return v_local_rel_ground_v[2];
|
||||
// }
|
||||
/* inline void set_Velocities_Ground(double north, double east, double down) {
|
||||
v_local_rel_ground_v[0] = north;
|
||||
v_local_rel_ground_v[1] = east;
|
||||
v_local_rel_ground_v[2] = down;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 v_local_airmass_v; // velocity of airmass (steady winds)
|
||||
// inline double * get_V_local_airmass_v() { return v_local_airmass_v; }
|
||||
// inline double get_V_north_airmass() const { return v_local_airmass_v[0]; }
|
||||
// inline double get_V_east_airmass() const { return v_local_airmass_v[1]; }
|
||||
// inline double get_V_down_airmass() const { return v_local_airmass_v[2]; }
|
||||
/* inline void set_Velocities_Local_Airmass( double north, double east,
|
||||
double down)
|
||||
{
|
||||
v_local_airmass_v[0] = north;
|
||||
v_local_airmass_v[1] = east;
|
||||
v_local_airmass_v[2] = down;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 v_local_rel_airmass_v; // velocity of veh. relative to
|
||||
// airmass
|
||||
// inline double * get_V_local_rel_airmass_v() {
|
||||
//return v_local_rel_airmass_v;
|
||||
//}
|
||||
// inline double get_V_north_rel_airmass() const {
|
||||
//return v_local_rel_airmass_v[0];
|
||||
//}
|
||||
// inline double get_V_east_rel_airmass() const {
|
||||
//return v_local_rel_airmass_v[1];
|
||||
//}
|
||||
// inline double get_V_down_rel_airmass() const {
|
||||
//return v_local_rel_airmass_v[2];
|
||||
//}
|
||||
/* inline void set_Velocities_Local_Rel_Airmass( double north, double east,
|
||||
double down)
|
||||
{
|
||||
v_local_rel_airmass_v[0] = north;
|
||||
v_local_rel_airmass_v[1] = east;
|
||||
v_local_rel_airmass_v[2] = down;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 v_local_gust_v; // linear turbulence components, L frame
|
||||
// inline double * get_V_local_gust_v() { return v_local_gust_v; }
|
||||
// inline double get_U_gust() const { return v_local_gust_v[0]; }
|
||||
// inline double get_V_gust() const { return v_local_gust_v[1]; }
|
||||
// inline double get_W_gust() const { return v_local_gust_v[2]; }
|
||||
/* inline void set_Velocities_Gust( double u, double v, double w)
|
||||
{
|
||||
v_local_gust_v[0] = u;
|
||||
v_local_gust_v[1] = v;
|
||||
v_local_gust_v[2] = w;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 v_wind_body_v; // Wind-relative velocities in body axis
|
||||
// inline double * get_V_wind_body_v() { return v_wind_body_v; }
|
||||
// inline double get_U_body() const { return v_wind_body_v[0]; }
|
||||
// inline double get_V_body() const { return v_wind_body_v[1]; }
|
||||
// inline double get_W_body() const { return v_wind_body_v[2]; }
|
||||
/* inline void set_Velocities_Wind_Body( double u, double v, double w)
|
||||
{
|
||||
v_wind_body_v[0] = u;
|
||||
v_wind_body_v[1] = v;
|
||||
v_wind_body_v[2] = w;
|
||||
} */
|
||||
|
||||
double v_rel_wind, v_true_kts, v_rel_ground, v_inertial;
|
||||
double v_ground_speed, v_equiv, v_equiv_kts;
|
||||
double v_calibrated, v_calibrated_kts;
|
||||
|
||||
// inline double get_V_rel_wind() const { return v_rel_wind; }
|
||||
// inline void set_V_rel_wind(double wind) { v_rel_wind = wind; }
|
||||
|
||||
// inline double get_V_true_kts() const { return v_true_kts; }
|
||||
// inline void set_V_true_kts(double kts) { v_true_kts = kts; }
|
||||
|
||||
// inline double get_V_rel_ground() const { return v_rel_ground; }
|
||||
// inline void set_V_rel_ground( double v ) { v_rel_ground = v; }
|
||||
|
||||
// inline double get_V_inertial() const { return v_inertial; }
|
||||
// inline void set_V_inertial(double v) { v_inertial = v; }
|
||||
|
||||
// inline double get_V_ground_speed() const { return v_ground_speed; }
|
||||
// inline void set_V_ground_speed( double v) { v_ground_speed = v; }
|
||||
|
||||
// inline double get_V_equiv() const { return v_equiv; }
|
||||
// inline void set_V_equiv( double v ) { v_equiv = v; }
|
||||
|
||||
inline double get_V_equiv_kts() const { return v_equiv_kts; }
|
||||
inline void set_V_equiv_kts( double kts ) { v_equiv_kts = kts; }
|
||||
|
||||
// inline double get_V_calibrated() const { return v_calibrated; }
|
||||
// inline void set_V_calibrated( double v ) { v_calibrated = v; }
|
||||
|
||||
// inline double get_V_calibrated_kts() const { return v_calibrated_kts; }
|
||||
// inline void set_V_calibrated_kts( double kts ) { v_calibrated_kts = kts; }
|
||||
|
||||
FG_VECTOR_3 omega_body_v; // Angular B rates
|
||||
// inline double * get_Omega_body_v() { return omega_body_v; }
|
||||
inline double get_P_body() const { return omega_body_v[0]; }
|
||||
inline double get_Q_body() const { return omega_body_v[1]; }
|
||||
inline double get_R_body() const { return omega_body_v[2]; }
|
||||
inline void set_Omega_Body( double p, double q, double r ) {
|
||||
omega_body_v[0] = p;
|
||||
omega_body_v[1] = q;
|
||||
omega_body_v[2] = r;
|
||||
}
|
||||
|
||||
FG_VECTOR_3 omega_local_v; // Angular L rates
|
||||
// inline double * get_Omega_local_v() { return omega_local_v; }
|
||||
// inline double get_P_local() const { return omega_local_v[0]; }
|
||||
// inline double get_Q_local() const { return omega_local_v[1]; }
|
||||
// inline double get_R_local() const { return omega_local_v[2]; }
|
||||
/* inline void set_Omega_Local( double p, double q, double r ) {
|
||||
omega_local_v[0] = p;
|
||||
omega_local_v[1] = q;
|
||||
omega_local_v[2] = r;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 omega_total_v; // Diff btw B & L
|
||||
// inline double * get_Omega_total_v() { return omega_total_v; }
|
||||
// inline double get_P_total() const { return omega_total_v[0]; }
|
||||
// inline double get_Q_total() const { return omega_total_v[1]; }
|
||||
// inline double get_R_total() const { return omega_total_v[2]; }
|
||||
/* inline void set_Omega_Total( double p, double q, double r ) {
|
||||
omega_total_v[0] = p;
|
||||
omega_total_v[1] = q;
|
||||
omega_total_v[2] = r;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 euler_rates_v;
|
||||
// inline double * get_Euler_rates_v() { return euler_rates_v; }
|
||||
// inline double get_Phi_dot() const { return euler_rates_v[0]; }
|
||||
// inline double get_Theta_dot() const { return euler_rates_v[1]; }
|
||||
// inline double get_Psi_dot() const { return euler_rates_v[2]; }
|
||||
/* inline void set_Euler_Rates( double phi, double theta, double psi ) {
|
||||
euler_rates_v[0] = phi;
|
||||
euler_rates_v[1] = theta;
|
||||
euler_rates_v[2] = psi;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 geocentric_rates_v; // Geocentric linear velocities
|
||||
// inline double * get_Geocentric_rates_v() { return geocentric_rates_v; }
|
||||
inline double get_Latitude_dot() const { return geocentric_rates_v[0]; }
|
||||
inline double get_Longitude_dot() const { return geocentric_rates_v[1]; }
|
||||
inline double get_Radius_dot() const { return geocentric_rates_v[2]; }
|
||||
inline void set_Geocentric_Rates( double lat, double lon, double rad ) {
|
||||
geocentric_rates_v[0] = lat;
|
||||
geocentric_rates_v[1] = lon;
|
||||
geocentric_rates_v[2] = rad;
|
||||
}
|
||||
|
||||
/*=============================== Positions ===============================*/
|
||||
|
||||
FG_VECTOR_3 geocentric_position_v;
|
||||
// inline double * get_Geocentric_position_v() {
|
||||
// return geocentric_position_v;
|
||||
// }
|
||||
inline double get_Lat_geocentric() const {
|
||||
return geocentric_position_v[0];
|
||||
}
|
||||
inline double get_Lon_geocentric() const {
|
||||
return geocentric_position_v[1];
|
||||
}
|
||||
inline double get_Radius_to_vehicle() const {
|
||||
return geocentric_position_v[2];
|
||||
}
|
||||
inline void set_Radius_to_vehicle(double radius) {
|
||||
geocentric_position_v[2] = radius;
|
||||
}
|
||||
|
||||
inline void set_Geocentric_Position( double lat, double lon, double rad ) {
|
||||
geocentric_position_v[0] = lat;
|
||||
geocentric_position_v[1] = lon;
|
||||
geocentric_position_v[2] = rad;
|
||||
}
|
||||
|
||||
FG_VECTOR_3 geodetic_position_v;
|
||||
// inline double * get_Geodetic_position_v() { return geodetic_position_v; }
|
||||
inline double get_Latitude() const { return geodetic_position_v[0]; }
|
||||
inline void set_Latitude(double lat) { geodetic_position_v[0] = lat; }
|
||||
inline double get_Longitude() const { return geodetic_position_v[1]; }
|
||||
inline void set_Longitude(double lon) { geodetic_position_v[1] = lon; }
|
||||
inline double get_Altitude() const { return geodetic_position_v[2]; }
|
||||
inline void set_Altitude(double altitude) {
|
||||
geodetic_position_v[2] = altitude;
|
||||
}
|
||||
inline void set_Geodetic_Position( double lat, double lon, double alt ) {
|
||||
geodetic_position_v[0] = lat;
|
||||
geodetic_position_v[1] = lon;
|
||||
geodetic_position_v[2] = alt;
|
||||
}
|
||||
|
||||
FG_VECTOR_3 euler_angles_v;
|
||||
// inline double * get_Euler_angles_v() { return euler_angles_v; }
|
||||
inline double get_Phi() const { return euler_angles_v[0]; }
|
||||
inline double get_Theta() const { return euler_angles_v[1]; }
|
||||
inline double get_Psi() const { return euler_angles_v[2]; }
|
||||
inline void set_Euler_Angles( double phi, double theta, double psi ) {
|
||||
euler_angles_v[0] = phi;
|
||||
euler_angles_v[1] = theta;
|
||||
euler_angles_v[2] = psi;
|
||||
}
|
||||
|
||||
|
||||
/*======================= Miscellaneous quantities ========================*/
|
||||
|
||||
double t_local_to_body_m[3][3]; // Transformation matrix L to B
|
||||
// inline double * get_T_local_to_body_m() { return t_local_to_body_m; }
|
||||
inline double get_T_local_to_body_11() const {
|
||||
return t_local_to_body_m[0][0];
|
||||
}
|
||||
inline double get_T_local_to_body_12() const {
|
||||
return t_local_to_body_m[0][1];
|
||||
}
|
||||
inline double get_T_local_to_body_13() const {
|
||||
return t_local_to_body_m[0][2];
|
||||
}
|
||||
inline double get_T_local_to_body_21() const {
|
||||
return t_local_to_body_m[1][0];
|
||||
}
|
||||
inline double get_T_local_to_body_22() const {
|
||||
return t_local_to_body_m[1][1];
|
||||
}
|
||||
inline double get_T_local_to_body_23() const {
|
||||
return t_local_to_body_m[1][2];
|
||||
}
|
||||
inline double get_T_local_to_body_31() const {
|
||||
return t_local_to_body_m[2][0];
|
||||
}
|
||||
inline double get_T_local_to_body_32() const {
|
||||
return t_local_to_body_m[2][1];
|
||||
}
|
||||
inline double get_T_local_to_body_33() const {
|
||||
return t_local_to_body_m[2][2];
|
||||
}
|
||||
inline void set_T_Local_to_Body( double m[3][3] ) {
|
||||
int i, j;
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
for ( j = 0; j < 3; j++ ) {
|
||||
t_local_to_body_m[i][j] = m[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double gravity; // Local acceleration due to G
|
||||
// inline double get_Gravity() const { return gravity; }
|
||||
// inline void set_Gravity(double g) { gravity = g; }
|
||||
|
||||
double centrifugal_relief; // load factor reduction due to speed
|
||||
// inline double get_Centrifugal_relief() const { return centrifugal_relief; }
|
||||
// inline void set_Centrifugal_relief(double cr) { centrifugal_relief = cr; }
|
||||
|
||||
double alpha, beta, alpha_dot, beta_dot; // in radians
|
||||
inline double get_Alpha() const { return alpha; }
|
||||
inline void set_Alpha( double a ) { alpha = a; }
|
||||
inline double get_Beta() const { return beta; }
|
||||
inline void set_Beta( double b ) { beta = b; }
|
||||
// inline double get_Alpha_dot() const { return alpha_dot; }
|
||||
// inline void set_Alpha_dot( double ad ) { alpha_dot = ad; }
|
||||
// inline double get_Beta_dot() const { return beta_dot; }
|
||||
// inline void set_Beta_dot( double bd ) { beta_dot = bd; }
|
||||
|
||||
double cos_alpha, sin_alpha, cos_beta, sin_beta;
|
||||
// inline double get_Cos_alpha() const { return cos_alpha; }
|
||||
// inline void set_Cos_alpha( double ca ) { cos_alpha = ca; }
|
||||
// inline double get_Sin_alpha() const { return sin_alpha; }
|
||||
// inline void set_Sin_alpha( double sa ) { sin_alpha = sa; }
|
||||
// inline double get_Cos_beta() const { return cos_beta; }
|
||||
// inline void set_Cos_beta( double cb ) { cos_beta = cb; }
|
||||
// inline double get_Sin_beta() const { return sin_beta; }
|
||||
// inline void set_Sin_beta( double sb ) { sin_beta = sb; }
|
||||
|
||||
double cos_phi, sin_phi, cos_theta, sin_theta, cos_psi, sin_psi;
|
||||
// inline double get_Cos_phi() const { return cos_phi; }
|
||||
// inline void set_Cos_phi( double cp ) { cos_phi = cp; }
|
||||
// inline double get_Sin_phi() const { return sin_phi; }
|
||||
// inline void set_Sin_phi( double sp ) { sin_phi = sp; }
|
||||
// inline double get_Cos_theta() const { return cos_theta; }
|
||||
// inline void set_Cos_theta( double ct ) { cos_theta = ct; }
|
||||
// inline double get_Sin_theta() const { return sin_theta; }
|
||||
// inline void set_Sin_theta( double st ) { sin_theta = st; }
|
||||
// inline double get_Cos_psi() const { return cos_psi; }
|
||||
// inline void set_Cos_psi( double cp ) { cos_psi = cp; }
|
||||
// inline double get_Sin_psi() const { return sin_psi; }
|
||||
// inline void set_Sin_psi( double sp ) { sin_psi = sp; }
|
||||
|
||||
double gamma_vert_rad, gamma_horiz_rad; // Flight path angles
|
||||
inline double get_Gamma_vert_rad() const { return gamma_vert_rad; }
|
||||
inline void set_Gamma_vert_rad( double gv ) { gamma_vert_rad = gv; }
|
||||
// inline double get_Gamma_horiz_rad() const { return gamma_horiz_rad; }
|
||||
// inline void set_Gamma_horiz_rad( double gh ) { gamma_horiz_rad = gh; }
|
||||
|
||||
double sigma, density, v_sound, mach_number;
|
||||
// inline double get_Sigma() const { return sigma; }
|
||||
// inline void set_Sigma( double s ) { sigma = s; }
|
||||
// inline double get_Density() const { return density; }
|
||||
// inline void set_Density( double d ) { density = d; }
|
||||
// inline double get_V_sound() const { return v_sound; }
|
||||
// inline void set_V_sound( double v ) { v_sound = v; }
|
||||
// inline double get_Mach_number() const { return mach_number; }
|
||||
// inline void set_Mach_number( double m ) { mach_number = m; }
|
||||
|
||||
double static_pressure, total_pressure, impact_pressure;
|
||||
double dynamic_pressure;
|
||||
// inline double get_Static_pressure() const { return static_pressure; }
|
||||
// inline void set_Static_pressure( double sp ) { static_pressure = sp; }
|
||||
// inline double get_Total_pressure() const { return total_pressure; }
|
||||
// inline void set_Total_pressure( double tp ) { total_pressure = tp; }
|
||||
// inline double get_Impact_pressure() const { return impact_pressure; }
|
||||
// inline void set_Impact_pressure( double ip ) { impact_pressure = ip; }
|
||||
// inline double get_Dynamic_pressure() const { return dynamic_pressure; }
|
||||
// inline void set_Dynamic_pressure( double dp ) { dynamic_pressure = dp; }
|
||||
|
||||
double static_temperature, total_temperature;
|
||||
// inline double get_Static_temperature() const { return static_temperature; }
|
||||
// inline void set_Static_temperature( double t ) { static_temperature = t; }
|
||||
// inline double get_Total_temperature() const { return total_temperature; }
|
||||
// inline void set_Total_temperature( double t ) { total_temperature = t; }
|
||||
|
||||
double sea_level_radius, earth_position_angle;
|
||||
inline double get_Sea_level_radius() const { return sea_level_radius; }
|
||||
inline void set_Sea_level_radius( double r ) { sea_level_radius = r; }
|
||||
inline double get_Earth_position_angle() const {
|
||||
return earth_position_angle;
|
||||
}
|
||||
inline void set_Earth_position_angle(double a) {
|
||||
earth_position_angle = a;
|
||||
}
|
||||
|
||||
double runway_altitude, runway_latitude, runway_longitude;
|
||||
double runway_heading;
|
||||
inline double get_Runway_altitude() const { return runway_altitude; }
|
||||
inline void set_Runway_altitude( double alt ) { runway_altitude = alt; }
|
||||
// inline double get_Runway_latitude() const { return runway_latitude; }
|
||||
// inline void set_Runway_latitude( double lat ) { runway_latitude = lat; }
|
||||
// inline double get_Runway_longitude() const { return runway_longitude; }
|
||||
// inline void set_Runway_longitude( double lon ) { runway_longitude = lon; }
|
||||
// inline double get_Runway_heading() const { return runway_heading; }
|
||||
// inline void set_Runway_heading( double h ) { runway_heading = h; }
|
||||
|
||||
double radius_to_rwy;
|
||||
// inline double get_Radius_to_rwy() const { return radius_to_rwy; }
|
||||
// inline void set_Radius_to_rwy( double r ) { radius_to_rwy = r; }
|
||||
|
||||
FG_VECTOR_3 d_cg_rwy_local_v; // CG rel. to rwy in local coords
|
||||
// inline double * get_D_cg_rwy_local_v() { return d_cg_rwy_local_v; }
|
||||
// inline double get_D_cg_north_of_rwy() const { return d_cg_rwy_local_v[0]; }
|
||||
// inline double get_D_cg_east_of_rwy() const { return d_cg_rwy_local_v[1]; }
|
||||
// inline double get_D_cg_above_rwy() const { return d_cg_rwy_local_v[2]; }
|
||||
/* inline void set_CG_Rwy_Local( double north, double east, double above )
|
||||
{
|
||||
d_cg_rwy_local_v[0] = north;
|
||||
d_cg_rwy_local_v[1] = east;
|
||||
d_cg_rwy_local_v[2] = above;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 d_cg_rwy_rwy_v; // CG relative to rwy, in rwy coordinates
|
||||
// inline double * get_D_cg_rwy_rwy_v() { return d_cg_rwy_rwy_v; }
|
||||
// inline double get_X_cg_rwy() const { return d_cg_rwy_rwy_v[0]; }
|
||||
// inline double get_Y_cg_rwy() const { return d_cg_rwy_rwy_v[1]; }
|
||||
// inline double get_H_cg_rwy() const { return d_cg_rwy_rwy_v[2]; }
|
||||
/* inline void set_CG_Rwy_Rwy( double x, double y, double h )
|
||||
{
|
||||
d_cg_rwy_rwy_v[0] = x;
|
||||
d_cg_rwy_rwy_v[1] = y;
|
||||
d_cg_rwy_rwy_v[2] = h;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 d_pilot_rwy_local_v; // pilot rel. to rwy in local coords
|
||||
// inline double * get_D_pilot_rwy_local_v() { return d_pilot_rwy_local_v; }
|
||||
// inline double get_D_pilot_north_of_rwy() const {
|
||||
//return d_pilot_rwy_local_v[0];
|
||||
// }
|
||||
// inline double get_D_pilot_east_of_rwy() const {
|
||||
// return d_pilot_rwy_local_v[1];
|
||||
// }
|
||||
// inline double get_D_pilot_above_rwy() const {
|
||||
//return d_pilot_rwy_local_v[2];
|
||||
// }
|
||||
/* inline void set_Pilot_Rwy_Local( double north, double east, double above )
|
||||
{
|
||||
d_pilot_rwy_local_v[0] = north;
|
||||
d_pilot_rwy_local_v[1] = east;
|
||||
d_pilot_rwy_local_v[2] = above;
|
||||
} */
|
||||
|
||||
FG_VECTOR_3 d_pilot_rwy_rwy_v; // pilot rel. to rwy, in rwy coords.
|
||||
// inline double * get_D_pilot_rwy_rwy_v() { return d_pilot_rwy_rwy_v; }
|
||||
// inline double get_X_pilot_rwy() const { return d_pilot_rwy_rwy_v[0]; }
|
||||
// inline double get_Y_pilot_rwy() const { return d_pilot_rwy_rwy_v[1]; }
|
||||
// inline double get_H_pilot_rwy() const { return d_pilot_rwy_rwy_v[2]; }
|
||||
/* inline void set_Pilot_Rwy_Rwy( double x, double y, double h )
|
||||
{
|
||||
d_pilot_rwy_rwy_v[0] = x;
|
||||
d_pilot_rwy_rwy_v[1] = y;
|
||||
d_pilot_rwy_rwy_v[2] = h;
|
||||
} */
|
||||
|
||||
double climb_rate; // in feet per second
|
||||
inline double get_Climb_Rate() const { return climb_rate; }
|
||||
inline void set_Climb_Rate(double rate) { climb_rate = rate; }
|
||||
|
||||
FGTimeStamp valid_stamp; // time this record is valid
|
||||
FGTimeStamp next_stamp; // time this record is valid
|
||||
inline FGTimeStamp get_time_stamp() const { return valid_stamp; }
|
||||
inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); }
|
||||
|
||||
// Extrapolate FDM based on time_offset (in usec)
|
||||
void extrapolate( int time_offset );
|
||||
|
||||
// sin/cos lat_geocentric
|
||||
double sin_lat_geocentric;
|
||||
double cos_lat_geocentric;
|
||||
inline void set_sin_lat_geocentric(double parm) {
|
||||
sin_lat_geocentric = sin(parm);
|
||||
}
|
||||
inline void set_cos_lat_geocentric(double parm) {
|
||||
cos_lat_geocentric = cos(parm);
|
||||
}
|
||||
inline double get_sin_lat_geocentric(void) const {
|
||||
return sin_lat_geocentric;
|
||||
}
|
||||
inline double get_cos_lat_geocentric(void) const {
|
||||
return cos_lat_geocentric;
|
||||
}
|
||||
|
||||
double sin_longitude;
|
||||
double cos_longitude;
|
||||
inline void set_sin_cos_longitude(double parm) {
|
||||
sin_longitude = sin(parm);
|
||||
cos_longitude = cos(parm);
|
||||
}
|
||||
inline double get_sin_longitude(void) const {
|
||||
return sin_longitude;
|
||||
}
|
||||
inline double get_cos_longitude(void) const {
|
||||
return cos_longitude;
|
||||
}
|
||||
|
||||
double sin_latitude;
|
||||
double cos_latitude;
|
||||
inline void set_sin_cos_latitude(double parm) {
|
||||
sin_latitude = sin(parm);
|
||||
cos_latitude = cos(parm);
|
||||
}
|
||||
inline double get_sin_latitude(void) const {
|
||||
return sin_latitude;
|
||||
}
|
||||
inline double get_cos_latitude(void) const {
|
||||
return cos_latitude;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
extern FGInterface cur_fdm_state;
|
||||
|
||||
|
||||
// General interface to the flight model routines
|
||||
|
||||
// Initialize the flight model parameters
|
||||
int fgFDMInit(int model, FGInterface& f, double dt);
|
||||
|
||||
// Run multiloop iterations of the flight model
|
||||
int fgFDMUpdate(int model, FGInterface& f, int multiloop, int jitter);
|
||||
|
||||
// Set the altitude (force)
|
||||
void fgFDMForceAltitude(int model, double alt_meters);
|
||||
|
||||
// Set the local ground elevation
|
||||
void fgFDMSetGroundElevation(int model, double alt_meters);
|
||||
|
||||
|
||||
#endif // _FLIGHT_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.14 1999/04/03 04:20:04 curt
|
||||
// Optimizations (tm) by Norman Vine.
|
||||
//
|
||||
// Revision 1.13 1999/02/05 21:29:02 curt
|
||||
// Modifications to incorporate Jon S. Berndts flight model code.
|
||||
//
|
||||
// Revision 1.12 1999/01/20 13:42:23 curt
|
||||
// Tweaked FDM interface.
|
||||
// Testing check sum support for NMEA serial output.
|
||||
//
|
||||
// Revision 1.11 1999/01/19 17:52:07 curt
|
||||
// Working on being able to extrapolate a new position and orientation
|
||||
// based on a position, orientation, and time offset.
|
||||
//
|
||||
// Revision 1.10 1999/01/09 13:37:33 curt
|
||||
// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms.
|
||||
//
|
||||
// Revision 1.9 1999/01/08 19:27:38 curt
|
||||
// Fixed AOA reading on HUD.
|
||||
// Continued work on time jitter compensation.
|
||||
//
|
||||
// Revision 1.8 1999/01/08 03:23:52 curt
|
||||
// Beginning work on compensating for sim time vs. real world time "jitter".
|
||||
//
|
||||
// Revision 1.7 1998/12/18 23:37:09 curt
|
||||
// Collapsed out the FGState variables not currently needed. They are just
|
||||
// commented out and can be readded easily at any time. The point of this
|
||||
// exersize is to determine which variables were or were not currently being
|
||||
// used.
|
||||
//
|
||||
// Revision 1.6 1998/12/05 15:54:12 curt
|
||||
// Renamed class fgFLIGHT to class FGState as per request by JSB.
|
||||
//
|
||||
// Revision 1.5 1998/12/04 01:29:40 curt
|
||||
// Stubbed in a new flight model called "External" which is expected to be driven
|
||||
// from some external source.
|
||||
//
|
||||
// Revision 1.4 1998/12/03 04:25:03 curt
|
||||
// Working on fixing up new fgFLIGHT class.
|
||||
//
|
||||
// Revision 1.3 1998/12/03 01:16:41 curt
|
||||
// Converted fgFLIGHT to a class.
|
||||
//
|
||||
// Revision 1.2 1998/10/16 23:27:41 curt
|
||||
// C++-ifying.
|
||||
//
|
||||
// Revision 1.1 1998/10/16 20:16:44 curt
|
||||
// Renamed flight.[ch] to flight.[ch]xx
|
||||
//
|
||||
// Revision 1.20 1998/09/29 14:57:39 curt
|
||||
// c++-ified comments.
|
||||
//
|
||||
// Revision 1.19 1998/09/29 02:02:41 curt
|
||||
// Added a rate of climb calculation.
|
||||
//
|
||||
// Revision 1.18 1998/07/30 23:44:36 curt
|
||||
// Beginning to add support for multiple flight models.
|
||||
//
|
||||
// Revision 1.17 1998/07/12 03:08:28 curt
|
||||
// Added fgFlightModelSetAltitude() to force the altitude to something
|
||||
// other than the current altitude. LaRCsim doesn't let you do this by just
|
||||
// changing FG_Altitude.
|
||||
//
|
||||
// Revision 1.16 1998/04/22 13:26:20 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.15 1998/04/21 16:59:33 curt
|
||||
// Integrated autopilot.
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.14 1998/02/07 15:29:37 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.13 1998/01/24 00:04:59 curt
|
||||
// misc. tweaks.
|
||||
//
|
||||
// Revision 1.12 1998/01/22 02:59:32 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.11 1998/01/19 19:27:03 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.10 1997/12/10 22:37:43 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.9 1997/09/04 02:17:33 curt
|
||||
// Shufflin' stuff.
|
||||
//
|
||||
// Revision 1.8 1997/08/27 03:30:06 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.7 1997/07/23 21:52:19 curt
|
||||
// Put comments around the text after an #endif for increased portability.
|
||||
//
|
||||
// Revision 1.6 1997/06/21 17:52:22 curt
|
||||
// Continue directory shuffling ... everything should be compilable/runnable
|
||||
// again.
|
||||
//
|
||||
// Revision 1.5 1997/06/21 17:12:49 curt
|
||||
// Capitalized subdirectory names.
|
||||
//
|
||||
// Revision 1.4 1997/05/29 22:39:57 curt
|
||||
// Working on incorporating the LaRCsim flight model.
|
||||
//
|
||||
// Revision 1.3 1997/05/29 02:32:25 curt
|
||||
// Starting to build generic flight model interface.
|
||||
//
|
||||
// Revision 1.2 1997/05/23 15:40:37 curt
|
||||
// Added GNU copyright headers.
|
||||
//
|
||||
// Revision 1.1 1997/05/16 16:04:45 curt
|
||||
// Initial revision.
|
||||
//
|
12
Simulator/GUI/Makefile.am
Normal file
12
Simulator/GUI/Makefile.am
Normal file
|
@ -0,0 +1,12 @@
|
|||
if ENABLE_XMESA_FX
|
||||
DEFS += -DXMESA -DFX
|
||||
endif
|
||||
|
||||
noinst_LIBRARIES = libGUI.a
|
||||
|
||||
libGUI_a_SOURCES = gui.cxx gui.h
|
||||
|
||||
INCLUDES += -I$(top_builddir) \
|
||||
-I$(top_builddir)/Lib \
|
||||
-I$(top_builddir)/Lib/plib/include \
|
||||
-I$(top_builddir)/Simulator
|
242
Simulator/GUI/gui.cxx
Normal file
242
Simulator/GUI/gui.cxx
Normal file
|
@ -0,0 +1,242 @@
|
|||
/**************************************************************************
|
||||
* gui.cxx
|
||||
*
|
||||
* Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
|
||||
* project.
|
||||
*
|
||||
* 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
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <Include/compiler.h>
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#if defined(FX) && defined(XMESA)
|
||||
# include <GL/xmesa.h>
|
||||
#endif
|
||||
|
||||
#include STL_STRING
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Include/general.hxx>
|
||||
#include <Main/options.hxx>
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
FG_USING_STD(string);
|
||||
|
||||
|
||||
puMenuBar *mainMenuBar;
|
||||
puButton *hideMenuButton;
|
||||
puDialogBox *dialogBox;
|
||||
puText *dialogBoxMessage;
|
||||
puOneShot *dialogBoxOkButton;
|
||||
puText *timerText;
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
Mouse stuff
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
void guiMotionFunc ( int x, int y )
|
||||
{
|
||||
puMouse ( x, y ) ;
|
||||
glutPostRedisplay () ;
|
||||
}
|
||||
|
||||
|
||||
void guiMouseFunc(int button, int updown, int x, int y)
|
||||
{
|
||||
puMouse (button, updown, x,y);
|
||||
glutPostRedisplay ();
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
the Gui callback functions
|
||||
____________________________________________________________________*/
|
||||
|
||||
void hideMenuCb (puObject *cb)
|
||||
{
|
||||
if (cb -> getValue () )
|
||||
{
|
||||
mainMenuBar -> reveal();
|
||||
printf("Showing Menu");
|
||||
hideMenuButton -> setLegend ("Hide Menu");
|
||||
}
|
||||
else
|
||||
{
|
||||
mainMenuBar -> hide ();
|
||||
printf("Hiding Menu");
|
||||
hideMenuButton -> setLegend ("Show Menu");
|
||||
}
|
||||
}
|
||||
|
||||
void goAwayCb (puObject *)
|
||||
{
|
||||
delete dialogBox;
|
||||
dialogBox = NULL;
|
||||
}
|
||||
|
||||
void mkDialog (char *txt)
|
||||
{
|
||||
dialogBox = new puDialogBox (150, 50);
|
||||
{
|
||||
new puFrame (0,0,400, 100);
|
||||
dialogBoxMessage = new puText (10, 70);
|
||||
dialogBoxMessage -> setLabel (txt);
|
||||
dialogBoxOkButton = new puOneShot (180, 10, 240, 50);
|
||||
dialogBoxOkButton -> setLegend ("OK");
|
||||
dialogBoxOkButton -> makeReturnDefault (TRUE );
|
||||
dialogBoxOkButton -> setCallback (goAwayCb);
|
||||
}
|
||||
dialogBox -> close();
|
||||
dialogBox -> reveal();
|
||||
}
|
||||
|
||||
void notCb (puObject *)
|
||||
{
|
||||
mkDialog ("This function isn't implemented yet");
|
||||
}
|
||||
|
||||
void helpCb (puObject *)
|
||||
{
|
||||
#if defined(FX) && !defined(WIN32)
|
||||
# if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
|
||||
if ( global_fullscreen ) {
|
||||
global_fullscreen = false;
|
||||
XMesaSetFXmode( XMESA_FX_WINDOW );
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32)
|
||||
string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
|
||||
string command;
|
||||
|
||||
if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
|
||||
command = "netscape -remote \"openURL(" + url + ")\" &";
|
||||
} else {
|
||||
command = "netscape " + url + " &";
|
||||
}
|
||||
|
||||
system( command.c_str() );
|
||||
string text = "Help started in netscape window.";
|
||||
#else
|
||||
string text = "Help not yet implimented for Win32.";
|
||||
#endif
|
||||
|
||||
mkDialog ( (char*)text.c_str() );
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
The menu stuff
|
||||
---------------------------------------------------------------------*/
|
||||
char *fileSubmenu [] = { "Exit", "Close", "---------", "Print", "---------", "Save", "New", NULL };
|
||||
char *editSubmenu [] = { "Edit text", NULL };
|
||||
char *viewSubmenu [] = { "Cockpit View > ", "View >","------------", "View options...", NULL };
|
||||
char *aircraftSubmenu [] = { "Autopilot ...", "Engine ...", "Navigation", "Communication", NULL};
|
||||
char *environmentSubmenu [] = { "Time & Date...", "Terrain ...", "Weather", NULL};
|
||||
char *optionsSubmenu [] = { "Preferences", "Realism & Reliablity...", NULL};
|
||||
char *helpSubmenu [] = { "About...", "Help", NULL };
|
||||
|
||||
puCallback fileSubmenuCb [] = { notCb, notCb, NULL, notCb, NULL, notCb, notCb, NULL};
|
||||
puCallback editSubmenuCb [] = { notCb, NULL };
|
||||
puCallback viewSubmenuCb [] = { notCb, notCb, NULL, notCb, NULL };
|
||||
puCallback aircraftSubmenuCb [] = { notCb, notCb, notCb,notCb, NULL };
|
||||
puCallback environmentSubmenuCb [] = { notCb, notCb, notCb, NULL };
|
||||
puCallback optionsSubmenuCb [] = { notCb, notCb, NULL};
|
||||
puCallback helpSubmenuCb [] = { notCb, helpCb, NULL };
|
||||
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
init the gui
|
||||
_____________________________________________________________________*/
|
||||
|
||||
|
||||
|
||||
void guiInit()
|
||||
{
|
||||
char *mesa_win_state;
|
||||
|
||||
// Initialize PUI
|
||||
puInit();
|
||||
|
||||
if ( current_options.get_mouse_pointer() == 0 ) {
|
||||
// no preference specified for mouse pointer, attempt to autodetect...
|
||||
// Determine if we need to render the cursor, or if the windowing
|
||||
// system will do it. First test if we are rendering with glide.
|
||||
if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
|
||||
// Test for the MESA_GLX_FX env variable
|
||||
if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
|
||||
// test if we are fullscreen mesa/glide
|
||||
if ( (mesa_win_state[0] == 'f') ||
|
||||
(mesa_win_state[0] == 'F') ) {
|
||||
puShowCursor ();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ( current_options.get_mouse_pointer() == 1 ) {
|
||||
// don't show pointer
|
||||
} else if ( current_options.get_mouse_pointer() == 2 ) {
|
||||
// force showing pointer
|
||||
puShowCursor();
|
||||
}
|
||||
|
||||
// puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED );
|
||||
puSetDefaultStyle ( PUSTYLE_DEFAULT );
|
||||
// puSetDefaultColourScheme (0.2, 0.4, 0.8, 0.5);
|
||||
puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.5);
|
||||
|
||||
/* OK the rest is largerly put in here to mimick Steve Baker's
|
||||
"complex" example It should change in future versions */
|
||||
|
||||
// timerText = new puText (300, 10);
|
||||
// timerText -> setColour (PUCOL_LABEL, 1.0, 1.0, 1.0);
|
||||
|
||||
/* Make a button to hide the menu bar */
|
||||
hideMenuButton = new puButton (10,10, 150, 50);
|
||||
hideMenuButton -> setValue (TRUE);
|
||||
hideMenuButton -> setLegend ("Hide Menu");
|
||||
hideMenuButton -> setCallback (hideMenuCb);
|
||||
hideMenuButton -> makeReturnDefault (TRUE);
|
||||
hideMenuButton -> hide();
|
||||
|
||||
// Make the menu bar
|
||||
mainMenuBar = new puMenuBar ();
|
||||
mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
|
||||
mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
|
||||
mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
|
||||
mainMenuBar -> add_submenu ("Aircraft", aircraftSubmenu, aircraftSubmenuCb);
|
||||
mainMenuBar -> add_submenu ("Environment", environmentSubmenu,
|
||||
environmentSubmenuCb);
|
||||
mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
|
||||
mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
|
||||
mainMenuBar-> close ();
|
||||
}
|
44
Simulator/GUI/gui.h
Normal file
44
Simulator/GUI/gui.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**************************************************************************
|
||||
* gui.h
|
||||
*
|
||||
* Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
|
||||
* project.
|
||||
*
|
||||
* 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 _GUI_H_
|
||||
#define _GUI_H_
|
||||
|
||||
#include <pu.h>
|
||||
|
||||
extern puMenuBar *mainMenuBar;
|
||||
extern puButton *hideMenuButton;
|
||||
extern puDialogBox *dialogBox;
|
||||
extern puText *dialogBoxMessage;
|
||||
extern puOneShot *dialogBoxOkButton;
|
||||
extern puText *timerText;
|
||||
|
||||
extern void guiMotionFunc ( int x, int y );
|
||||
extern void guiMouseFunc(int button, int updown, int x, int y);
|
||||
extern void guiInit();
|
||||
|
||||
extern void mkDialog (char *txt);
|
||||
|
||||
#endif // _GUI_H_
|
464
Simulator/JSBsim/FGAircraft.cpp
Normal file
464
Simulator/JSBsim/FGAircraft.cpp
Normal file
|
@ -0,0 +1,464 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGAircraft.cpp
|
||||
Author: Jon S. Berndt
|
||||
Date started: 12/12/98
|
||||
Purpose: Encapsulates an aircraft
|
||||
Called by: FGFDMExec
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
Models the aircraft reactions and forces. This class is instantiated by the
|
||||
FGFDMExec class and scheduled as an FDM entry. LoadAircraft() is supplied with a
|
||||
name of a valid, registered aircraft, and the data file is parsed.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
12/12/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
COMMENTS, REFERENCES, and NOTES
|
||||
********************************************************************************
|
||||
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||
School, January 1994
|
||||
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||
JSC 12960, July 1977
|
||||
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||
NASA-Ames", NASA CR-2497, January 1975
|
||||
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||
1982 ISBN 0-471-08936-2
|
||||
|
||||
The aerodynamic coefficients used in this model are:
|
||||
|
||||
Longitudinal
|
||||
CL0 - Reference lift at zero alpha
|
||||
CD0 - Reference drag at zero alpha
|
||||
CDM - Drag due to Mach
|
||||
CLa - Lift curve slope (w.r.t. alpha)
|
||||
CDa - Drag curve slope (w.r.t. alpha)
|
||||
CLq - Lift due to pitch rate
|
||||
CLM - Lift due to Mach
|
||||
CLadt - Lift due to alpha rate
|
||||
|
||||
Cmadt - Pitching Moment due to alpha rate
|
||||
Cm0 - Reference Pitching moment at zero alpha
|
||||
Cma - Pitching moment slope (w.r.t. alpha)
|
||||
Cmq - Pitch damping (pitch moment due to pitch rate)
|
||||
CmM - Pitch Moment due to Mach
|
||||
|
||||
Lateral
|
||||
Cyb - Side force due to sideslip
|
||||
Cyr - Side force due to yaw rate
|
||||
|
||||
Clb - Dihedral effect (roll moment due to sideslip)
|
||||
Clp - Roll damping (roll moment due to roll rate)
|
||||
Clr - Roll moment due to yaw rate
|
||||
Cnb - Weathercocking stability (yaw moment due to sideslip)
|
||||
Cnp - Rudder adverse yaw (yaw moment due to roll rate)
|
||||
Cnr - Yaw damping (yaw moment due to yaw rate)
|
||||
|
||||
Control
|
||||
CLDe - Lift due to elevator
|
||||
CDDe - Drag due to elevator
|
||||
CyDr - Side force due to rudder
|
||||
CyDa - Side force due to aileron
|
||||
|
||||
CmDe - Pitch moment due to elevator
|
||||
ClDa - Roll moment due to aileron
|
||||
ClDr - Roll moment due to rudder
|
||||
CnDr - Yaw moment due to rudder
|
||||
CnDa - Yaw moment due to aileron
|
||||
|
||||
This class expects to be run in a directory which contains the subdirectory
|
||||
structure shown below (where example aircraft X-15 is shown):
|
||||
|
||||
aircraft/
|
||||
X-15/
|
||||
X-15.dat reset00 reset01 reset02 ...
|
||||
CDRAG/
|
||||
a0 a M De
|
||||
CSIDE/
|
||||
b r Dr Da
|
||||
CLIFT/
|
||||
a0 a M adt De
|
||||
CROLL/
|
||||
b p r Da Dr
|
||||
CPITCH/
|
||||
a0 a adt q M De
|
||||
CYAW/
|
||||
b p r Dr Da
|
||||
F-16/
|
||||
F-16.dat reset00 reset01 ...
|
||||
CDRAG/
|
||||
a0 a M De
|
||||
...
|
||||
|
||||
The General Idea
|
||||
|
||||
The file structure is arranged so that various modeled aircraft are stored in
|
||||
their own subdirectory. Each aircraft subdirectory is named after the aircraft.
|
||||
There should be a file present in the specific aircraft subdirectory (e.g.
|
||||
aircraft/X-15) with the same name as the directory with a .dat appended. This
|
||||
file contains mass properties information, name of aircraft, etc. for the
|
||||
aircraft. In that same directory are reset files numbered starting from 0 (two
|
||||
digit numbers), e.g. reset03. Within each reset file are values for important
|
||||
state variables for specific flight conditions (altitude, airspeed, etc.). Also
|
||||
within this directory are the directories containing lookup tables for the
|
||||
stability derivatives for the aircraft.
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef FGFS
|
||||
# include <Include/compiler.h>
|
||||
# ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <cmath>
|
||||
# else
|
||||
# include <math.h>
|
||||
# endif
|
||||
#else
|
||||
# include <cmath>
|
||||
#endif
|
||||
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
|
||||
{
|
||||
int i;
|
||||
|
||||
Name = "FGAircraft";
|
||||
|
||||
for (i=0;i<6;i++) coeff_ctr[i] = 0;
|
||||
|
||||
Axis[LiftCoeff] = "CLIFT";
|
||||
Axis[DragCoeff] = "CDRAG";
|
||||
Axis[SideCoeff] = "CSIDE";
|
||||
Axis[RollCoeff] = "CROLL";
|
||||
Axis[PitchCoeff] = "CPITCH";
|
||||
Axis[YawCoeff] = "CYAW";
|
||||
}
|
||||
|
||||
|
||||
FGAircraft::~FGAircraft(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string fname)
|
||||
{
|
||||
string path;
|
||||
string fullpath;
|
||||
string filename;
|
||||
string aircraftDef;
|
||||
string tag;
|
||||
DIR* dir;
|
||||
DIR* coeffdir;
|
||||
struct dirent* dirEntry;
|
||||
struct dirent* coeffdirEntry;
|
||||
struct stat st;
|
||||
struct stat st2;
|
||||
ifstream coeffInFile;
|
||||
|
||||
aircraftDef = aircraft_path + "/" + fname + "/" + fname + ".dat";
|
||||
ifstream aircraftfile(aircraftDef.c_str());
|
||||
|
||||
if (aircraftfile) {
|
||||
aircraftfile >> AircraftName; // String with no embedded spaces
|
||||
aircraftfile >> WingArea; // square feet
|
||||
aircraftfile >> WingSpan; // feet
|
||||
aircraftfile >> cbar; // feet
|
||||
aircraftfile >> Ixx; // slug ft^2
|
||||
aircraftfile >> Iyy; // "
|
||||
aircraftfile >> Izz; // "
|
||||
aircraftfile >> Ixz; // "
|
||||
aircraftfile >> EmptyWeight; // pounds
|
||||
EmptyMass = EmptyWeight / GRAVITY;
|
||||
aircraftfile >> tag;
|
||||
|
||||
numTanks = numEngines = 0;
|
||||
numSelectedOxiTanks = numSelectedFuelTanks = 0;
|
||||
|
||||
while ( !(tag == "EOF") ) {
|
||||
if (tag == "CGLOC") {
|
||||
aircraftfile >> Xcg; // inches
|
||||
aircraftfile >> Ycg; // inches
|
||||
aircraftfile >> Zcg; // inches
|
||||
} else if (tag == "EYEPOINTLOC") {
|
||||
aircraftfile >> Xep; // inches
|
||||
aircraftfile >> Yep; // inches
|
||||
aircraftfile >> Zep; // inches
|
||||
} else if (tag == "TANK") {
|
||||
Tank[numTanks] = new FGTank(aircraftfile);
|
||||
switch(Tank[numTanks]->GetType()) {
|
||||
case FGTank::ttFUEL:
|
||||
numSelectedFuelTanks++;
|
||||
break;
|
||||
case FGTank::ttOXIDIZER:
|
||||
numSelectedOxiTanks++;
|
||||
break;
|
||||
}
|
||||
numTanks++;
|
||||
} else if (tag == "ENGINE") {
|
||||
aircraftfile >> tag;
|
||||
Engine[numEngines] = new FGEngine(FDMExec, engine_path, tag, numEngines);
|
||||
numEngines++;
|
||||
}
|
||||
aircraftfile >> tag;
|
||||
}
|
||||
aircraftfile.close();
|
||||
PutState();
|
||||
|
||||
// Read subdirectory for this aircraft for stability derivative lookup tables:
|
||||
//
|
||||
// Build up the path name to the aircraft file by appending the aircraft
|
||||
// name to the "aircraft/" initial path. Initialize the directory entry
|
||||
// structure dirEntry in preparation for reading through the directory.
|
||||
// Build up a path to each file in the directory sequentially and "stat" it
|
||||
// to see if the entry is a directory or a file. If the entry is a file, then
|
||||
// compare it to each string in the Axis[] array to see which axis the
|
||||
// directory represents: Lift, Drag, Side, Roll, Pitch, Yaw. When the match
|
||||
// is found, go into that directory and search for any coefficient files.
|
||||
// Build a new coefficient by passing the full pathname to the coefficient
|
||||
// file to the FGCoefficient constructor.
|
||||
//
|
||||
// Note: axis_ctr=0 for the Lift "axis", 1 for Drag, 2 for Side force, 3 for
|
||||
// Roll, 4 for Pitch, and 5 for Yaw. The term coeff_ctr merely keeps
|
||||
// track of the number of coefficients registered for each of the
|
||||
// previously mentioned axis.
|
||||
|
||||
path = aircraft_path + "/" + AircraftName + "/";
|
||||
if (dir = opendir(path.c_str())) {
|
||||
|
||||
while (dirEntry = readdir(dir)) {
|
||||
fullpath = path + dirEntry->d_name;
|
||||
stat(fullpath.c_str(),&st);
|
||||
if ((st.st_mode & S_IFMT) == S_IFDIR) {
|
||||
for (int axis_ctr=0; axis_ctr < 6; axis_ctr++) {
|
||||
if (dirEntry->d_name == Axis[axis_ctr]) {
|
||||
if (coeffdir = opendir(fullpath.c_str())) {
|
||||
while (coeffdirEntry = readdir(coeffdir)) {
|
||||
if (coeffdirEntry->d_name[0] != '.') {
|
||||
filename = path + Axis[axis_ctr] + "/" + coeffdirEntry->d_name;
|
||||
stat(filename.c_str(),&st2);
|
||||
if (st2.st_size > 6) {
|
||||
Coeff[axis_ctr][coeff_ctr[axis_ctr]] = new FGCoefficient(FDMExec, filename);
|
||||
coeff_ctr[axis_ctr]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cerr << "Could not open directory " << path << " for reading" << endl;
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
cerr << "Unable to open aircraft definition file " << fname << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool FGAircraft::Run(void)
|
||||
{
|
||||
if (!FGModel::Run()) { // if false then execute this Run()
|
||||
GetState();
|
||||
|
||||
for (int i = 0; i < 3; i++) Forces[i] = Moments[i] = 0.0;
|
||||
|
||||
MassChange();
|
||||
|
||||
FProp(); FAero(); FGear(); FMass();
|
||||
MProp(); MAero(); MGear(); MMass();
|
||||
|
||||
PutState();
|
||||
} else { // skip Run() execution this time
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::MassChange()
|
||||
{
|
||||
// UPDATE TANK CONTENTS
|
||||
//
|
||||
// For each engine, cycle through the tanks and draw an equal amount of
|
||||
// fuel (or oxidizer) from each active tank. The needed amount of fuel is
|
||||
// determined by the engine in the FGEngine class. If more fuel is needed
|
||||
// than is available in the tank, then that amount is considered a shortage,
|
||||
// and will be drawn from the next tank. If the engine cannot be fed what it
|
||||
// needs, it will be considered to be starved, and will shut down.
|
||||
|
||||
float Oshortage, Fshortage;
|
||||
|
||||
for (int e=0; e<numEngines; e++) {
|
||||
Fshortage = Oshortage = 0.0;
|
||||
for (int t=0; t<numTanks; t++) {
|
||||
switch(Engine[e]->GetType()) {
|
||||
case FGEngine::etRocket:
|
||||
|
||||
switch(Tank[t]->GetType()) {
|
||||
case FGTank::ttFUEL:
|
||||
if (Tank[t]->GetSelected()) {
|
||||
Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
|
||||
numSelectedFuelTanks)*(dt*rate) + Fshortage);
|
||||
}
|
||||
break;
|
||||
case FGTank::ttOXIDIZER:
|
||||
if (Tank[t]->GetSelected()) {
|
||||
Oshortage = Tank[t]->Reduce((Engine[e]->CalcOxidizerNeed()/
|
||||
numSelectedOxiTanks)*(dt*rate) + Oshortage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case FGEngine::etPiston:
|
||||
case FGEngine::etTurboJet:
|
||||
case FGEngine::etTurboProp:
|
||||
|
||||
if (Tank[t]->GetSelected()) {
|
||||
Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
|
||||
numSelectedFuelTanks)*(dt*rate) + Fshortage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((Fshortage <= 0.0) || (Oshortage <= 0.0)) Engine[e]->SetStarved();
|
||||
else Engine[e]->SetStarved(false);
|
||||
}
|
||||
|
||||
Weight = EmptyWeight;
|
||||
for (int t=0; t<numTanks; t++)
|
||||
Weight += Tank[t]->GetContents();
|
||||
|
||||
Mass = Weight / GRAVITY;
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::FAero(void)
|
||||
{
|
||||
float F[3];
|
||||
|
||||
F[0] = F[1] = F[2] = 0.0;
|
||||
|
||||
for (int axis_ctr = 0; axis_ctr < 3; axis_ctr++)
|
||||
for (int ctr=0; ctr < coeff_ctr[axis_ctr]; ctr++)
|
||||
F[axis_ctr] += Coeff[axis_ctr][ctr]->Value();
|
||||
|
||||
Forces[0] += F[LiftCoeff]*sin(alpha) - F[DragCoeff]*cos(alpha) - F[SideCoeff]*sin(beta);
|
||||
Forces[1] += F[SideCoeff]*cos(beta);
|
||||
Forces[2] += -F[LiftCoeff]*cos(alpha) - F[DragCoeff]*sin(alpha);
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::FGear(void)
|
||||
{
|
||||
if (GearUp) {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::FMass(void)
|
||||
{
|
||||
Forces[0] += -GRAVITY*sin(tht) * Mass;
|
||||
Forces[1] += GRAVITY*sin(phi)*cos(tht) * Mass;
|
||||
Forces[2] += GRAVITY*cos(phi)*cos(tht) * Mass;
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::FProp(void)
|
||||
{
|
||||
for (int i=0;i<numEngines;i++) {
|
||||
Forces[0] += Engine[i]->CalcThrust();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::MAero(void)
|
||||
{
|
||||
for (int axis_ctr = 0; axis_ctr < 3; axis_ctr++)
|
||||
for (int ctr = 0; ctr < coeff_ctr[axis_ctr+3]; ctr++)
|
||||
Moments[axis_ctr] += Coeff[axis_ctr+3][ctr]->Value();
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::MGear(void)
|
||||
{
|
||||
if (GearUp) {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::MMass(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::MProp(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::GetState(void)
|
||||
{
|
||||
dt = State->Getdt();
|
||||
|
||||
alpha = Translation->Getalpha();
|
||||
beta = Translation->Getbeta();
|
||||
phi = Rotation->Getphi();
|
||||
tht = Rotation->Gettht();
|
||||
psi = Rotation->Getpsi();
|
||||
}
|
||||
|
||||
|
||||
void FGAircraft::PutState(void)
|
||||
{
|
||||
}
|
||||
|
491
Simulator/JSBsim/FGAircraft.h
Normal file
491
Simulator/JSBsim/FGAircraft.h
Normal file
|
@ -0,0 +1,491 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGAircraft.h
|
||||
Author: Jon S. Berndt
|
||||
Date started: 12/12/98
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
12/12/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGAIRCRAFT_H
|
||||
#define FGAIRCRAFT_H
|
||||
|
||||
/*******************************************************************************
|
||||
COMMENTS, REFERENCES, and NOTES
|
||||
*******************************************************************************/
|
||||
/**
|
||||
The aerodynamic coefficients used in this model typically are:
|
||||
<PRE>
|
||||
<b>Longitudinal</b>
|
||||
CL0 - Reference lift at zero alpha
|
||||
CD0 - Reference drag at zero alpha
|
||||
CDM - Drag due to Mach
|
||||
CLa - Lift curve slope (w.r.t. alpha)
|
||||
CDa - Drag curve slope (w.r.t. alpha)
|
||||
CLq - Lift due to pitch rate
|
||||
CLM - Lift due to Mach
|
||||
CLadt - Lift due to alpha rate
|
||||
|
||||
Cmadt - Pitching Moment due to alpha rate
|
||||
Cm0 - Reference Pitching moment at zero alpha
|
||||
Cma - Pitching moment slope (w.r.t. alpha)
|
||||
Cmq - Pitch damping (pitch moment due to pitch rate)
|
||||
CmM - Pitch Moment due to Mach
|
||||
|
||||
<b>Lateral</b>
|
||||
Cyb - Side force due to sideslip
|
||||
Cyr - Side force due to yaw rate
|
||||
|
||||
Clb - Dihedral effect (roll moment due to sideslip)
|
||||
Clp - Roll damping (roll moment due to roll rate)
|
||||
Clr - Roll moment due to yaw rate
|
||||
Cnb - Weathercocking stability (yaw moment due to sideslip)
|
||||
Cnp - Rudder adverse yaw (yaw moment due to roll rate)
|
||||
Cnr - Yaw damping (yaw moment due to yaw rate)
|
||||
|
||||
<b>Control</b>
|
||||
CLDe - Lift due to elevator
|
||||
CDDe - Drag due to elevator
|
||||
CyDr - Side force due to rudder
|
||||
CyDa - Side force due to aileron
|
||||
|
||||
CmDe - Pitch moment due to elevator
|
||||
ClDa - Roll moment due to aileron
|
||||
ClDr - Roll moment due to rudder
|
||||
CnDr - Yaw moment due to rudder
|
||||
CnDa - Yaw moment due to aileron
|
||||
</PRE>
|
||||
This class expects to be run in a directory which contains the subdirectory
|
||||
structure shown below (where example aircraft X-15 is shown):
|
||||
|
||||
<PRE>
|
||||
aircraft/
|
||||
X-15/
|
||||
X-15.dat reset00 reset01 reset02 ...
|
||||
CDRAG/
|
||||
a0 a M De
|
||||
CSIDE/
|
||||
b r Dr Da
|
||||
CLIFT/
|
||||
a0 a M adt De
|
||||
CROLL/
|
||||
b p r Da Dr
|
||||
CPITCH/
|
||||
a0 a adt q M De
|
||||
CYAW/
|
||||
b p r Dr Da
|
||||
F-16/
|
||||
F-16.dat reset00 reset01 ...
|
||||
CDRAG/
|
||||
a0 a M De
|
||||
...
|
||||
</PRE>
|
||||
|
||||
The General Idea
|
||||
|
||||
The file structure is arranged so that various modeled aircraft are stored in
|
||||
their own subdirectory. Each aircraft subdirectory is named after the aircraft.
|
||||
There should be a file present in the specific aircraft subdirectory (e.g.
|
||||
aircraft/X-15) with the same name as the directory with a .dat appended. This
|
||||
file contains mass properties information, name of aircraft, etc. for the
|
||||
aircraft. In that same directory are reset files numbered starting from 0 (two
|
||||
digit numbers), e.g. reset03. Within each reset file are values for important
|
||||
state variables for specific flight conditions (altitude, airspeed, etc.). Also
|
||||
within this directory are the directories containing lookup tables for the
|
||||
stability derivatives for the aircraft.
|
||||
@author Jon S. Berndt
|
||||
@memo Encompasses all aircraft functionality and objects
|
||||
@see <ll>
|
||||
<li>[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||
School, January 1994</li>
|
||||
<li>[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||
JSC 12960, July 1977</li>
|
||||
<li>[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||
NASA-Ames", NASA CR-2497, January 1975</li>
|
||||
<li>[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||
Wiley & Sons, 1979 ISBN 0-471-03032-5</li>
|
||||
<li>[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||
1982 ISBN 0-471-08936-2</li>
|
||||
</ll>
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef FGFS
|
||||
# include <Include/compiler.h>
|
||||
# ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <fstream>
|
||||
# else
|
||||
# include <fstream.h>
|
||||
# endif
|
||||
#else
|
||||
# include <fstream>
|
||||
#endif
|
||||
|
||||
#include "FGModel.h"
|
||||
#include "FGCoefficient.h"
|
||||
#include "FGEngine.h"
|
||||
#include "FGTank.h"
|
||||
|
||||
/*******************************************************************************
|
||||
DEFINITIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
class FGAircraft : public FGModel
|
||||
{
|
||||
public:
|
||||
// ***************************************************************************
|
||||
/** @memo Constructor
|
||||
@param FGFDMExec* - a pointer to the "owning" FDM Executive
|
||||
*/
|
||||
FGAircraft(FGFDMExec*);
|
||||
|
||||
// ***************************************************************************
|
||||
/** Destructor */
|
||||
~FGAircraft(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** This must be called for each dt to execute the model algorithm */
|
||||
bool Run(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** This function must be called with the name of an aircraft which
|
||||
has an associated .dat file in the appropriate subdirectory. The paths
|
||||
to the appropriate subdirectories are given as the first two parameters.
|
||||
@memo Loads the given aircraft.
|
||||
@param string Path to the aircraft files
|
||||
@param string Path to the engine files
|
||||
@param string The name of the aircraft to be loaded, e.g. "X15".
|
||||
@return True - if successful
|
||||
*/
|
||||
bool LoadAircraft(string, string, string);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Gets the aircraft name as defined in the aircraft config file.
|
||||
@param
|
||||
@return string Aircraft name.
|
||||
*/
|
||||
inline string GetAircraftName(void) {return AircraftName;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Sets the GearUp flag
|
||||
@param boolean true or false
|
||||
@return
|
||||
*/
|
||||
inline void SetGearUp(bool tt) {GearUp = tt;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Returns the state of the GearUp flag
|
||||
@param
|
||||
@return boolean true or false
|
||||
*/
|
||||
inline bool GetGearUp(void) {return GearUp;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Returns the area of the wing
|
||||
@param
|
||||
@return float wing area S, in square feet
|
||||
*/
|
||||
inline float GetWingArea(void) {return WingArea;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Returns the wing span
|
||||
@param
|
||||
@return float wing span in feet
|
||||
*/
|
||||
inline float GetWingSpan(void) {return WingSpan;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Returns the average wing chord
|
||||
@param
|
||||
@return float wing chord in feet
|
||||
*/
|
||||
inline float Getcbar(void) {return cbar;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Returns an engine object
|
||||
@param int The engine number
|
||||
@return FGEengine* The pointer to the requested engine object.
|
||||
*/
|
||||
inline FGEngine* GetEngine(int tt) {return Engine[tt];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline FGTank* GetTank(int tt) {return Tank[tt];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetWeight(void) {return Weight;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetMass(void) {return Mass;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetL(void) {return Moments[0];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetM(void) {return Moments[1];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetN(void) {return Moments[2];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetFx(void) {return Forces[0];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetFy(void) {return Forces[1];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetFz(void) {return Forces[2];}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetIxx(void) {return Ixx;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetIyy(void) {return Iyy;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetIzz(void) {return Izz;}
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
inline float GetIxz(void) {return Ixz;}
|
||||
|
||||
private:
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void GetState(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void PutState(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void FAero(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void FGear(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void FMass(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void FProp(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void MAero(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void MGear(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void MMass(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void MProp(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
void MassChange(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
float Moments[3];
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
float Forces[3];
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
string AircraftName;
|
||||
|
||||
// ***************************************************************************
|
||||
///
|
||||
float Ixx, Iyy, Izz, Ixz, EmptyMass, Mass;
|
||||
///
|
||||
float Xcg, Ycg, Zcg;
|
||||
///
|
||||
float Xep, Yep, Zep;
|
||||
///
|
||||
float rho, qbar, Vt;
|
||||
///
|
||||
float alpha, beta;
|
||||
///
|
||||
float WingArea, WingSpan, cbar;
|
||||
///
|
||||
float phi, tht, psi;
|
||||
///
|
||||
float Weight, EmptyWeight;
|
||||
///
|
||||
float dt;
|
||||
|
||||
///
|
||||
int numTanks;
|
||||
///
|
||||
int numEngines;
|
||||
///
|
||||
int numSelectedOxiTanks;
|
||||
///
|
||||
int numSelectedFuelTanks;
|
||||
///
|
||||
FGTank* Tank[MAX_TANKS];
|
||||
///
|
||||
FGEngine *Engine[MAX_ENGINES];
|
||||
|
||||
///
|
||||
FGCoefficient *Coeff[6][10];
|
||||
///
|
||||
int coeff_ctr[6];
|
||||
|
||||
///
|
||||
bool GearUp;
|
||||
|
||||
///
|
||||
enum Param {LiftCoeff,
|
||||
DragCoeff,
|
||||
SideCoeff,
|
||||
RollCoeff,
|
||||
PitchCoeff,
|
||||
YawCoeff,
|
||||
numCoeffs};
|
||||
|
||||
///
|
||||
string Axis[6];
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
78
Simulator/JSBsim/FGAtmosphere.cpp
Normal file
78
Simulator/JSBsim/FGAtmosphere.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGAtmosphere.cpp
|
||||
Author: Jon Berndt
|
||||
Date started: 11/24/98
|
||||
Purpose: Models the atmosphere
|
||||
Called by: FGSimExec
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
Models the atmosphere. The equation used below was determined by a third order
|
||||
curve fit using Excel. The data is from the ICAO atmosphere model.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
11/24/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex)
|
||||
{
|
||||
Name = "FGAtmosphere";
|
||||
}
|
||||
|
||||
|
||||
FGAtmosphere::~FGAtmosphere()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FGAtmosphere::Run(void)
|
||||
{
|
||||
if (!FGModel::Run()) { // if false then execute this Run()
|
||||
rho = 0.002377 - 7.0E-08*State->Geth()
|
||||
+ 7.0E-13*State->Geth()*State->Geth()
|
||||
- 2.0E-18*State->Geth()*State->Geth()*State->Geth();
|
||||
|
||||
State->SetMach(State->GetVt()/State->Geta());
|
||||
} else { // skip Run() execution this time
|
||||
}
|
||||
return false;
|
||||
}
|
87
Simulator/JSBsim/FGAtmosphere.h
Normal file
87
Simulator/JSBsim/FGAtmosphere.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGAtmosphere.h
|
||||
Author: Jon Berndt
|
||||
Date started: 11/24/98
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
11/24/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGATMOSPHERE_H
|
||||
#define FGATMOSPHERE_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGModel.h"
|
||||
|
||||
/*******************************************************************************
|
||||
COMMENTS, REFERENCES, and NOTES
|
||||
*******************************************************************************/
|
||||
/**
|
||||
The equation used in this model was determined by a third order curve fit using
|
||||
Excel. The data is from the ICAO atmosphere model.
|
||||
@memo Models the atmosphere.
|
||||
@author Jon S. Berndt
|
||||
*/
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
class FGAtmosphere : public FGModel
|
||||
{
|
||||
public:
|
||||
// ***************************************************************************
|
||||
/** @memo Constructor
|
||||
@param FGFDMExec* - a pointer to the "owning" FDM Executive
|
||||
*/
|
||||
FGAtmosphere(FGFDMExec*);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Destructor
|
||||
*/
|
||||
~FGAtmosphere(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** This must be called for each dt to execute the model algorithm */
|
||||
bool Run(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Returns the air density
|
||||
@return float air density in slugs/cubic foot
|
||||
*/
|
||||
inline float Getrho(void) {return rho;}
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
float rho;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
75
Simulator/JSBsim/FGAuxiliary.cpp
Normal file
75
Simulator/JSBsim/FGAuxiliary.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGAuxiliary.cpp
|
||||
Author: Jon Berndt
|
||||
Date started: 01/26/99
|
||||
Purpose: Calculates additional parameters needed by the visual system, etc.
|
||||
Called by: FGSimExec
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
This class calculates various auxiliary parameters, mostly used by the visual
|
||||
system
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
01/26/99 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
|
||||
{
|
||||
Name = "FGAuxiliary";
|
||||
}
|
||||
|
||||
|
||||
FGAuxiliary::~FGAuxiliary()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FGAuxiliary::Run()
|
||||
{
|
||||
if (!FGModel::Run()) {
|
||||
} else {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
65
Simulator/JSBsim/FGAuxiliary.h
Normal file
65
Simulator/JSBsim/FGAuxiliary.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGAuxiliary.h
|
||||
Author: Jon Berndt
|
||||
Date started: 01/26/99
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
11/22/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGAUXILIARY_H
|
||||
#define FGAUXILIARY_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
#include "FGModel.h"
|
||||
|
||||
/*******************************************************************************
|
||||
DEFINES
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
class FGAuxiliary : public FGModel
|
||||
{
|
||||
public:
|
||||
FGAuxiliary(FGFDMExec*);
|
||||
~FGAuxiliary(void);
|
||||
|
||||
bool Run(void);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
457
Simulator/JSBsim/FGCoefficient.cpp
Normal file
457
Simulator/JSBsim/FGCoefficient.cpp
Normal file
|
@ -0,0 +1,457 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGCoefficient.cpp
|
||||
Author: Jon S. Berndt
|
||||
Date started: 12/28/98
|
||||
Purpose: Encapsulates the stability derivative class FGCoefficient;
|
||||
Called by: FGAircraft
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
This class models the stability derivative coefficient lookup tables or
|
||||
equations. Note that the coefficients need not be calculated each delta-t.
|
||||
|
||||
The coefficient files are located in the axis subdirectory for each aircraft.
|
||||
For instance, for the X-15, you would find subdirectories under the
|
||||
aircraft/X-15/ directory named CLIFT, CDRAG, CSIDE, CROLL, CPITCH, CYAW. Under
|
||||
each of these directories would be files named a, a0, q, and so on. The file
|
||||
named "a" under the CLIFT directory would contain data for the stability
|
||||
derivative modeling lift due to a change in alpha. See the FGAircraft.cpp file
|
||||
for additional information. The coefficient files have the following format:
|
||||
|
||||
<name of coefficient>
|
||||
<short description of coefficient with no embedded spaces>
|
||||
<method used in calculating the coefficient: TABLE | EQUATION | VECTOR | VALUE>
|
||||
<parameter identifier for table row (if required)>
|
||||
<parameter identifier for table column (if required)>
|
||||
<OR'ed list of parameter identifiers needed to turn this coefficient into a force>
|
||||
<number of rows in table (if required)>
|
||||
<number of columns in table (if required)>
|
||||
|
||||
<value of parameter indexing into the column of a table or vector - or value
|
||||
itself for a VALUE coefficient>
|
||||
<values of parameter indexing into row of a table if TABLE type> <Value of
|
||||
coefficient at this row and column>
|
||||
|
||||
<... repeat above for each column of data in table ...>
|
||||
|
||||
As an example for the X-15, for the lift due to mach:
|
||||
|
||||
CLa0
|
||||
Lift_at_zero_alpha
|
||||
Table 8 3
|
||||
16384
|
||||
32768
|
||||
16387
|
||||
|
||||
0.00
|
||||
0.0 0.0
|
||||
0.5 0.4
|
||||
0.9 0.9
|
||||
1.0 1.6
|
||||
1.1 1.3
|
||||
1.4 1.0
|
||||
2.0 0.5
|
||||
3.0 0.5
|
||||
|
||||
30000.00
|
||||
0.0 0.0
|
||||
0.5 0.5
|
||||
0.9 1.0
|
||||
1.0 1.7
|
||||
1.1 1.4
|
||||
1.4 1.1
|
||||
2.0 0.6
|
||||
3.0 0.6
|
||||
|
||||
70000.00
|
||||
0.0 0.0
|
||||
0.5 0.6
|
||||
0.9 1.1
|
||||
1.0 1.7
|
||||
1.1 1.5
|
||||
1.4 1.2
|
||||
2.0 0.7
|
||||
3.0 0.7
|
||||
|
||||
Note that the values in a row which index into the table must be the same value
|
||||
for each column of data, so the first column of numbers for each altitude are
|
||||
seen to be equal, and there are the same number of values for each altitude.
|
||||
|
||||
See the header file FGCoefficient.h for the values of the identifiers.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
12/28/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGCoefficient.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
FGCoefficient::FGCoefficient(FGFDMExec* fdex)
|
||||
{
|
||||
FDMExec = fdex;
|
||||
State = FDMExec->GetState();
|
||||
Atmosphere = FDMExec->GetAtmosphere();
|
||||
FCS = FDMExec->GetFCS();
|
||||
Aircraft = FDMExec->GetAircraft();
|
||||
Translation = FDMExec->GetTranslation();
|
||||
Rotation = FDMExec->GetRotation();
|
||||
Position = FDMExec->GetPosition();
|
||||
Auxiliary = FDMExec->GetAuxiliary();
|
||||
Output = FDMExec->GetOutput();
|
||||
|
||||
rows = columns = 0;
|
||||
}
|
||||
|
||||
|
||||
FGCoefficient::FGCoefficient(FGFDMExec* fdex, string fname)
|
||||
{
|
||||
int r, c;
|
||||
float ftrashcan;
|
||||
|
||||
FDMExec = fdex;
|
||||
State = FDMExec->GetState();
|
||||
Atmosphere = FDMExec->GetAtmosphere();
|
||||
FCS = FDMExec->GetFCS();
|
||||
Aircraft = FDMExec->GetAircraft();
|
||||
Translation = FDMExec->GetTranslation();
|
||||
Rotation = FDMExec->GetRotation();
|
||||
Position = FDMExec->GetPosition();
|
||||
Auxiliary = FDMExec->GetAuxiliary();
|
||||
Output = FDMExec->GetOutput();
|
||||
|
||||
ifstream coeffDefFile(fname.c_str());
|
||||
|
||||
if (coeffDefFile) {
|
||||
if (!coeffDefFile.fail()) {
|
||||
coeffDefFile >> name;
|
||||
coeffDefFile >> description;
|
||||
coeffDefFile >> method;
|
||||
|
||||
if (method == "EQUATION") type = EQUATION;
|
||||
else if (method == "TABLE") type = TABLE;
|
||||
else if (method == "VECTOR") type = VECTOR;
|
||||
else if (method == "VALUE") type = VALUE;
|
||||
else type = UNKNOWN;
|
||||
|
||||
if (type == VECTOR || type == TABLE) {
|
||||
coeffDefFile >> rows;
|
||||
if (type == TABLE) {
|
||||
coeffDefFile >> columns;
|
||||
}
|
||||
coeffDefFile >> LookupR;
|
||||
}
|
||||
|
||||
if (type == TABLE) {
|
||||
coeffDefFile >> LookupC;
|
||||
}
|
||||
|
||||
coeffDefFile >> multipliers;
|
||||
|
||||
mult_count = 0;
|
||||
if (multipliers & FG_QBAR) {
|
||||
mult_idx[mult_count] = FG_QBAR;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_WINGAREA) {
|
||||
mult_idx[mult_count] = FG_WINGAREA;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_WINGSPAN) {
|
||||
mult_idx[mult_count] = FG_WINGSPAN;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_CBAR) {
|
||||
mult_idx[mult_count] = FG_CBAR;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_ALPHA) {
|
||||
mult_idx[mult_count] = FG_ALPHA;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_ALPHADOT) {
|
||||
mult_idx[mult_count] = FG_ALPHADOT;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_BETA) {
|
||||
mult_idx[mult_count] = FG_BETA;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_BETADOT) {
|
||||
mult_idx[mult_count] = FG_BETADOT;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_PITCHRATE) {
|
||||
mult_idx[mult_count] = FG_PITCHRATE;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_ROLLRATE) {
|
||||
mult_idx[mult_count] = FG_ROLLRATE;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_YAWRATE) {
|
||||
mult_idx[mult_count] = FG_YAWRATE;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_ELEVATOR) {
|
||||
mult_idx[mult_count] = FG_ELEVATOR;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_AILERON) {
|
||||
mult_idx[mult_count] = FG_AILERON;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_RUDDER) {
|
||||
mult_idx[mult_count] = FG_RUDDER;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_MACH) {
|
||||
mult_idx[mult_count] = FG_MACH;
|
||||
mult_count++;
|
||||
}
|
||||
if (multipliers & FG_ALTITUDE) {
|
||||
mult_idx[mult_count] = FG_ALTITUDE;
|
||||
mult_count++;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case VALUE:
|
||||
coeffDefFile >> StaticValue;
|
||||
break;
|
||||
case VECTOR:
|
||||
Allocate(rows,2);
|
||||
|
||||
for (r=1;r<=rows;r++) {
|
||||
coeffDefFile >> Table3D[r][0];
|
||||
coeffDefFile >> Table3D[r][1];
|
||||
}
|
||||
break;
|
||||
case TABLE:
|
||||
Allocate(rows, columns);
|
||||
|
||||
for (c=1;c<=columns;c++) {
|
||||
coeffDefFile >> Table3D[0][c];
|
||||
for (r=1;r<=rows;r++) {
|
||||
if ( c==1 ) coeffDefFile >> Table3D[r][0];
|
||||
else coeffDefFile >> ftrashcan;
|
||||
coeffDefFile >> Table3D[r][c];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
cerr << "Empty file" << endl;
|
||||
}
|
||||
coeffDefFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FGCoefficient::FGCoefficient(FGFDMExec* fdex, int r, int c)
|
||||
{
|
||||
FDMExec = fdex;
|
||||
State = FDMExec->GetState();
|
||||
Atmosphere = FDMExec->GetAtmosphere();
|
||||
FCS = FDMExec->GetFCS();
|
||||
Aircraft = FDMExec->GetAircraft();
|
||||
Translation = FDMExec->GetTranslation();
|
||||
Rotation = FDMExec->GetRotation();
|
||||
Position = FDMExec->GetPosition();
|
||||
Auxiliary = FDMExec->GetAuxiliary();
|
||||
Output = FDMExec->GetOutput();
|
||||
|
||||
rows = r;
|
||||
columns = c;
|
||||
Allocate(r,c);
|
||||
}
|
||||
|
||||
|
||||
FGCoefficient::FGCoefficient(FGFDMExec* fdex, int n)
|
||||
{
|
||||
FDMExec = fdex;
|
||||
State = FDMExec->GetState();
|
||||
Atmosphere = FDMExec->GetAtmosphere();
|
||||
FCS = FDMExec->GetFCS();
|
||||
Aircraft = FDMExec->GetAircraft();
|
||||
Translation = FDMExec->GetTranslation();
|
||||
Rotation = FDMExec->GetRotation();
|
||||
Position = FDMExec->GetPosition();
|
||||
Auxiliary = FDMExec->GetAuxiliary();
|
||||
Output = FDMExec->GetOutput();
|
||||
|
||||
rows = n;
|
||||
columns = 0;
|
||||
Allocate(n);
|
||||
}
|
||||
|
||||
|
||||
FGCoefficient::~FGCoefficient(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FGCoefficient::Allocate(int r, int c)
|
||||
{
|
||||
rows = r;
|
||||
columns = c;
|
||||
Table3D = new float*[r+1];
|
||||
for (int i=0;i<=r;i++) Table3D[i] = new float[c+1];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FGCoefficient::Allocate(int n)
|
||||
{
|
||||
rows = n;
|
||||
columns = 0;
|
||||
Table2D = new float[n+1];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
float FGCoefficient::Value(float rVal, float cVal)
|
||||
{
|
||||
float rFactor, cFactor, col1temp, col2temp, Value;
|
||||
int r, c, midx;
|
||||
|
||||
if (rows < 2 || columns < 2) return 0.0;
|
||||
|
||||
for (r=1;r<=rows;r++) if (Table3D[r][0] >= rVal) break;
|
||||
for (c=1;c<=columns;c++) if (Table3D[0][c] >= cVal) break;
|
||||
|
||||
c = c < 2 ? 2 : (c > columns ? columns : c);
|
||||
r = r < 2 ? 2 : (r > rows ? rows : r);
|
||||
|
||||
rFactor = (rVal - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]);
|
||||
cFactor = (cVal - Table3D[0][c-1]) / (Table3D[0][c] - Table3D[0][c-1]);
|
||||
|
||||
col1temp = rFactor*(Table3D[r][c-1] - Table3D[r-1][c-1]) + Table3D[r-1][c-1];
|
||||
col2temp = rFactor*(Table3D[r][c] - Table3D[r-1][c]) + Table3D[r-1][c];
|
||||
|
||||
Value = col1temp + cFactor*(col2temp - col1temp);
|
||||
|
||||
for (midx=0;midx<mult_count;midx++) {
|
||||
Value *= GetCoeffVal(mult_idx[midx]);
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
|
||||
float FGCoefficient::Value(float Val)
|
||||
{
|
||||
float Factor, Value;
|
||||
int r, midx;
|
||||
|
||||
if (rows < 2) return 0.0;
|
||||
|
||||
for (r=1;r<=rows;r++) if (Table3D[r][0] >= Val) break;
|
||||
r = r < 2 ? 2 : (r > rows ? rows : r);
|
||||
|
||||
// make sure denominator below does not go to zero.
|
||||
if (Table3D[r][0] != Table3D[r-1][0]) {
|
||||
Factor = (Val - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]);
|
||||
} else {
|
||||
Factor = 1.0;
|
||||
}
|
||||
Value = Factor*(Table3D[r][1] - Table3D[r-1][1]) + Table3D[r-1][1];
|
||||
|
||||
for (midx=0;midx<mult_count;midx++) {
|
||||
Value *= GetCoeffVal(mult_idx[midx]);
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
|
||||
float FGCoefficient::Value()
|
||||
{
|
||||
switch(type) {
|
||||
case 0:
|
||||
return -1;
|
||||
case 1:
|
||||
return (StaticValue);
|
||||
case 2:
|
||||
return (Value(GetCoeffVal(LookupR)));
|
||||
case 3:
|
||||
return (Value(GetCoeffVal(LookupR),GetCoeffVal(LookupC)));
|
||||
case 4:
|
||||
return 0.0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float FGCoefficient::GetCoeffVal(int val_idx)
|
||||
{
|
||||
switch(val_idx) {
|
||||
case FG_QBAR:
|
||||
return State->Getqbar();
|
||||
case FG_WINGAREA:
|
||||
return Aircraft->GetWingArea();
|
||||
case FG_WINGSPAN:
|
||||
return Aircraft->GetWingSpan();
|
||||
case FG_CBAR:
|
||||
return Aircraft->Getcbar();
|
||||
case FG_ALPHA:
|
||||
return Translation->Getalpha();
|
||||
case FG_ALPHADOT:
|
||||
return State->Getadot();
|
||||
case FG_BETA:
|
||||
return Translation->Getbeta();
|
||||
case FG_BETADOT:
|
||||
return State->Getbdot();
|
||||
case FG_PITCHRATE:
|
||||
return Rotation->GetQ();
|
||||
case FG_ROLLRATE:
|
||||
return Rotation->GetP();
|
||||
case FG_YAWRATE:
|
||||
return Rotation->GetR();
|
||||
case FG_ELEVATOR:
|
||||
return FCS->GetDe();
|
||||
case FG_AILERON:
|
||||
return FCS->GetDa();
|
||||
case FG_RUDDER:
|
||||
return FCS->GetDr();
|
||||
case FG_MACH:
|
||||
return State->GetMach();
|
||||
case FG_ALTITUDE:
|
||||
return State->Geth();
|
||||
}
|
||||
return 0;
|
||||
}
|
300
Simulator/JSBsim/FGCoefficient.h
Normal file
300
Simulator/JSBsim/FGCoefficient.h
Normal file
|
@ -0,0 +1,300 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGCoefficient.h
|
||||
Author: Jon Berndt
|
||||
Date started: 12/28/98
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
12/28/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGCOEFFICIENT_H
|
||||
#define FGCOEFFICIENT_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
#ifdef FGFS
|
||||
# include <Include/compiler.h>
|
||||
# include STL_STRING
|
||||
# ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <fstream>
|
||||
# else
|
||||
# include <fstream.h>
|
||||
# endif
|
||||
FG_USING_STD(string);
|
||||
#else
|
||||
# include <string>
|
||||
# include <fstream>
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
DEFINES
|
||||
*******************************************************************************/
|
||||
#define FG_QBAR 1
|
||||
#define FG_WINGAREA 2
|
||||
#define FG_WINGSPAN 4
|
||||
#define FG_CBAR 8
|
||||
#define FG_ALPHA 16
|
||||
#define FG_ALPHADOT 32
|
||||
#define FG_BETA 64
|
||||
#define FG_BETADOT 128
|
||||
#define FG_PITCHRATE 256
|
||||
#define FG_ROLLRATE 512
|
||||
#define FG_YAWRATE 1024
|
||||
#define FG_ELEVATOR 2048
|
||||
#define FG_AILERON 4096
|
||||
#define FG_RUDDER 8192
|
||||
#define FG_MACH 16384
|
||||
#define FG_ALTITUDE 32768L
|
||||
|
||||
/*******************************************************************************
|
||||
FORWARD DECLARATIONS
|
||||
*******************************************************************************/
|
||||
class FGFDMExec;
|
||||
class FGState;
|
||||
class FGAtmosphere;
|
||||
class FGFCS;
|
||||
class FGAircraft;
|
||||
class FGTranslation;
|
||||
class FGRotation;
|
||||
class FGPosition;
|
||||
class FGAuxiliary;
|
||||
class FGOutput;
|
||||
|
||||
/*******************************************************************************
|
||||
COMMENTS, REFERENCES, and NOTES
|
||||
*******************************************************************************/
|
||||
/**
|
||||
This class models the stability derivative coefficient lookup tables or
|
||||
equations. Note that the coefficients need not be calculated each delta-t.
|
||||
|
||||
The coefficient files are located in the axis subdirectory for each aircraft.
|
||||
For instance, for the X-15, you would find subdirectories under the
|
||||
aircraft/X-15/ directory named CLIFT, CDRAG, CSIDE, CROLL, CPITCH, CYAW. Under
|
||||
each of these directories would be files named a, a0, q, and so on. The file
|
||||
named "a" under the CLIFT directory would contain data for the stability
|
||||
derivative modeling lift due to a change in alpha. See the FGAircraft.cpp file
|
||||
for additional information. The coefficient files have the following format:
|
||||
|
||||
<name of coefficient>
|
||||
<short description of coefficient with no embedded spaces>
|
||||
<method used in calculating the coefficient: TABLE | EQUATION | VECTOR | VALUE>
|
||||
<parameter identifier for table row (if required)>
|
||||
<parameter identifier for table column (if required)>
|
||||
<OR'ed list of parameter identifiers needed to turn this coefficient into a force>
|
||||
<number of rows in table (if required)>
|
||||
<number of columns in table (if required)>
|
||||
|
||||
<value of parameter indexing into the column of a table or vector - or value
|
||||
itself for a VALUE coefficient>
|
||||
<values of parameter indexing into row of a table if TABLE type> <Value of
|
||||
coefficient at this row and column>
|
||||
|
||||
<... repeat above for each column of data in table ...>
|
||||
|
||||
As an example for the X-15, for the lift due to mach:
|
||||
<PRE>
|
||||
|
||||
CLa0
|
||||
Lift_at_zero_alpha
|
||||
Table 8 3
|
||||
16384
|
||||
32768
|
||||
16387
|
||||
|
||||
0.00
|
||||
0.0 0.0
|
||||
0.5 0.4
|
||||
0.9 0.9
|
||||
1.0 1.6
|
||||
1.1 1.3
|
||||
1.4 1.0
|
||||
2.0 0.5
|
||||
3.0 0.5
|
||||
|
||||
30000.00
|
||||
0.0 0.0
|
||||
0.5 0.5
|
||||
0.9 1.0
|
||||
1.0 1.7
|
||||
1.1 1.4
|
||||
1.4 1.1
|
||||
2.0 0.6
|
||||
3.0 0.6
|
||||
|
||||
70000.00
|
||||
0.0 0.0
|
||||
0.5 0.6
|
||||
0.9 1.1
|
||||
1.0 1.7
|
||||
1.1 1.5
|
||||
1.4 1.2
|
||||
2.0 0.7
|
||||
3.0 0.7
|
||||
</PRE>
|
||||
|
||||
Note that the values in a row which index into the table must be the same value
|
||||
for each column of data, so the first column of numbers for each altitude are
|
||||
seen to be equal, and there are the same number of values for each altitude.
|
||||
|
||||
<PRE>
|
||||
FG_QBAR 1
|
||||
FG_WINGAREA 2
|
||||
FG_WINGSPAN 4
|
||||
FG_CBAR 8
|
||||
FG_ALPHA 16
|
||||
FG_ALPHADOT 32
|
||||
FG_BETA 64
|
||||
FG_BETADOT 128
|
||||
FG_PITCHRATE 256
|
||||
FG_ROLLRATE 512
|
||||
FG_YAWRATE 1024
|
||||
FG_ELEVATOR 2048
|
||||
FG_AILERON 4096
|
||||
FG_RUDDER 8192
|
||||
FG_MACH 16384
|
||||
FG_ALTITUDE 32768L
|
||||
</PRE>
|
||||
@author Jon S. Berndt
|
||||
@memo This class models the stability derivative coefficient lookup tables or equations.
|
||||
*/
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
class FGCoefficient
|
||||
{
|
||||
public:
|
||||
// ***************************************************************************
|
||||
/** @memo Constructor
|
||||
@param FGFDMExec* - pointer to owning simulation executive
|
||||
*/
|
||||
FGCoefficient(FGFDMExec*);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo Constructor for two independent variable table
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
FGCoefficient(FGFDMExec*, int, int);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
FGCoefficient(FGFDMExec*, int);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
FGCoefficient(FGFDMExec*, string);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
~FGCoefficient(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
bool Allocate(int);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
bool Allocate(int, int);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
float Value(float, float);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
float Value(float);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
float Value(void);
|
||||
|
||||
// ***************************************************************************
|
||||
/** @memo
|
||||
@param
|
||||
@return
|
||||
*/
|
||||
enum Type {UNKNOWN, VALUE, VECTOR, TABLE, EQUATION};
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
string filename;
|
||||
string description;
|
||||
string name;
|
||||
string method;
|
||||
float StaticValue;
|
||||
float *Table2D;
|
||||
float **Table3D;
|
||||
float LookupR, LookupC;
|
||||
long int mult_idx[10];
|
||||
int rows, columns;
|
||||
Type type;
|
||||
int multipliers;
|
||||
int mult_count;
|
||||
|
||||
float GetCoeffVal(int);
|
||||
|
||||
FGFDMExec* FDMExec;
|
||||
FGState* State;
|
||||
FGAtmosphere* Atmosphere;
|
||||
FGFCS* FCS;
|
||||
FGAircraft* Aircraft;
|
||||
FGTranslation* Translation;
|
||||
FGRotation* Rotation;
|
||||
FGPosition* Position;
|
||||
FGAuxiliary* Auxiliary;
|
||||
FGOutput* Output;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
97
Simulator/JSBsim/FGControls.cpp
Normal file
97
Simulator/JSBsim/FGControls.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
// controls.cxx -- defines a standard interface to all flight sim controls
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 "controls.hxx"
|
||||
|
||||
|
||||
FGControls controls;
|
||||
|
||||
|
||||
// Constructor
|
||||
FGControls::FGControls() :
|
||||
aileron( 0.0 ),
|
||||
elevator( 0.0 ),
|
||||
elevator_trim( 1.969572E-03 ),
|
||||
rudder( 0.0 )
|
||||
{
|
||||
for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
|
||||
throttle[engine] = 0.0;
|
||||
}
|
||||
|
||||
for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
|
||||
brake[wheel] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
FGControls::~FGControls() {
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.1 1999/02/13 01:12:03 curt
|
||||
// Initial Revision.
|
||||
//
|
||||
// Revision 1.1 1999/02/09 04:51:32 jon
|
||||
// Initial revision
|
||||
//
|
||||
// Revision 1.3 1998/12/05 16:13:12 curt
|
||||
// Renamed class fgCONTROLS to class FGControls.
|
||||
//
|
||||
// Revision 1.2 1998/10/25 14:08:41 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.1 1998/10/18 01:51:05 curt
|
||||
// c++-ifying ...
|
||||
//
|
||||
// Revision 1.8 1998/09/29 02:01:31 curt
|
||||
// Added a brake.
|
||||
//
|
||||
// Revision 1.7 1998/02/07 15:29:36 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.6 1998/01/19 19:27:02 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.5 1998/01/19 18:40:22 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.4 1997/12/10 22:37:41 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.3 1997/08/27 03:30:01 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.2 1997/06/21 17:12:48 curt
|
||||
// Capitalized subdirectory names.
|
||||
//
|
||||
// Revision 1.1 1997/05/31 19:24:04 curt
|
||||
// Initial revision.
|
||||
//
|
||||
|
246
Simulator/JSBsim/FGControls.h
Normal file
246
Simulator/JSBsim/FGControls.h
Normal file
|
@ -0,0 +1,246 @@
|
|||
// controls.hxx -- defines a standard interface to all flight sim controls
|
||||
//
|
||||
// Written by Curtis Olson, started May 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 _CONTROLS_HXX
|
||||
#define _CONTROLS_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
// Define a structure containing the control parameters
|
||||
|
||||
class FGControls {
|
||||
|
||||
public:
|
||||
|
||||
static const int ALL_ENGINES = -1;
|
||||
static const int MAX_ENGINES = 10;
|
||||
|
||||
static const int ALL_WHEELS = -1;
|
||||
static const int MAX_WHEELS = 3;
|
||||
|
||||
private:
|
||||
|
||||
double aileron;
|
||||
double elevator;
|
||||
double elevator_trim;
|
||||
double rudder;
|
||||
double throttle[MAX_ENGINES];
|
||||
double brake[MAX_WHEELS];
|
||||
|
||||
public:
|
||||
|
||||
FGControls();
|
||||
~FGControls();
|
||||
|
||||
// Query functions
|
||||
inline double get_aileron() const { return aileron; }
|
||||
inline double get_elevator() const { return elevator; }
|
||||
inline double get_elevator_trim() const { return elevator_trim; }
|
||||
inline double get_rudder() const { return rudder; }
|
||||
inline double get_throttle(int engine) const { return throttle[engine]; }
|
||||
inline double get_brake(int wheel) const { return brake[wheel]; }
|
||||
|
||||
// Update functions
|
||||
inline void set_aileron( double pos ) {
|
||||
aileron = pos;
|
||||
if ( aileron < -1.0 ) aileron = -1.0;
|
||||
if ( aileron > 1.0 ) aileron = 1.0;
|
||||
}
|
||||
inline void move_aileron( double amt ) {
|
||||
aileron += amt;
|
||||
if ( aileron < -1.0 ) aileron = -1.0;
|
||||
if ( aileron > 1.0 ) aileron = 1.0;
|
||||
}
|
||||
inline void set_elevator( double pos ) {
|
||||
elevator = pos;
|
||||
if ( elevator < -1.0 ) elevator = -1.0;
|
||||
if ( elevator > 1.0 ) elevator = 1.0;
|
||||
}
|
||||
inline void move_elevator( double amt ) {
|
||||
elevator += amt;
|
||||
if ( elevator < -1.0 ) elevator = -1.0;
|
||||
if ( elevator > 1.0 ) elevator = 1.0;
|
||||
}
|
||||
inline void set_elevator_trim( double pos ) {
|
||||
elevator_trim = pos;
|
||||
if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
|
||||
if ( elevator_trim > 1.0 ) elevator_trim = 1.0;
|
||||
}
|
||||
inline void move_elevator_trim( double amt ) {
|
||||
elevator_trim += amt;
|
||||
if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
|
||||
if ( elevator_trim > 1.0 ) elevator_trim = 1.0;
|
||||
}
|
||||
inline void set_rudder( double pos ) {
|
||||
rudder = pos;
|
||||
if ( rudder < -1.0 ) rudder = -1.0;
|
||||
if ( rudder > 1.0 ) rudder = 1.0;
|
||||
}
|
||||
inline void move_rudder( double amt ) {
|
||||
rudder += amt;
|
||||
if ( rudder < -1.0 ) rudder = -1.0;
|
||||
if ( rudder > 1.0 ) rudder = 1.0;
|
||||
}
|
||||
inline void set_throttle( int engine, double pos ) {
|
||||
if ( engine == ALL_ENGINES ) {
|
||||
for ( int i = 0; i < MAX_ENGINES; i++ ) {
|
||||
throttle[i] = pos;
|
||||
if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
|
||||
if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
|
||||
throttle[engine] = pos;
|
||||
if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
|
||||
if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void move_throttle( int engine, double amt ) {
|
||||
if ( engine == ALL_ENGINES ) {
|
||||
for ( int i = 0; i < MAX_ENGINES; i++ ) {
|
||||
throttle[i] += amt;
|
||||
if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
|
||||
if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
|
||||
throttle[engine] += amt;
|
||||
if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
|
||||
if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void set_brake( int wheel, double pos ) {
|
||||
if ( wheel == ALL_WHEELS ) {
|
||||
for ( int i = 0; i < MAX_WHEELS; i++ ) {
|
||||
brake[i] = pos;
|
||||
if ( brake[i] < 0.0 ) brake[i] = 0.0;
|
||||
if ( brake[i] > 1.0 ) brake[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
|
||||
brake[wheel] = pos;
|
||||
if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
|
||||
if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void move_brake( int wheel, double amt ) {
|
||||
if ( wheel == ALL_WHEELS ) {
|
||||
for ( int i = 0; i < MAX_WHEELS; i++ ) {
|
||||
brake[i] += amt;
|
||||
if ( brake[i] < 0.0 ) brake[i] = 0.0;
|
||||
if ( brake[i] > 1.0 ) brake[i] = 1.0;
|
||||
}
|
||||
} else {
|
||||
if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
|
||||
brake[wheel] += amt;
|
||||
if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
|
||||
if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
extern FGControls controls;
|
||||
|
||||
|
||||
#endif // _CONTROLS_HXX
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.1 1999/02/13 01:12:03 curt
|
||||
// Initial Revision.
|
||||
//
|
||||
// Revision 1.3 1998/12/05 16:13:13 curt
|
||||
// Renamed class fgCONTROLS to class FGControls.
|
||||
//
|
||||
// Revision 1.2 1998/10/25 14:08:42 curt
|
||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||
//
|
||||
// Revision 1.1 1998/10/18 01:51:07 curt
|
||||
// c++-ifying ...
|
||||
//
|
||||
// Revision 1.17 1998/09/29 14:57:00 curt
|
||||
// c++-ified some comments.
|
||||
//
|
||||
// Revision 1.16 1998/09/29 02:01:32 curt
|
||||
// Added a brake.
|
||||
//
|
||||
// Revision 1.15 1998/04/25 22:06:27 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.14 1998/04/22 13:26:19 curt
|
||||
// C++ - ifing the code a bit.
|
||||
//
|
||||
// Revision 1.13 1998/04/21 17:02:35 curt
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.12 1998/02/09 22:56:48 curt
|
||||
// Removed "depend" files from cvs control. Other minor make tweaks.
|
||||
//
|
||||
// Revision 1.11 1998/02/07 15:29:36 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.10 1998/01/27 00:47:52 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.9 1998/01/22 02:59:31 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.8 1998/01/19 18:40:22 curt
|
||||
// Tons of little changes to clean up the code and to remove fatal errors
|
||||
// when building with the c++ compiler.
|
||||
//
|
||||
// Revision 1.7 1997/12/15 23:54:36 curt
|
||||
// Add xgl wrappers for debugging.
|
||||
// Generate terrain normals on the fly.
|
||||
//
|
||||
// Revision 1.6 1997/12/10 22:37:41 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.5 1997/08/27 03:30:02 curt
|
||||
// Changed naming scheme of basic shared structures.
|
||||
//
|
||||
// Revision 1.4 1997/07/23 21:52:18 curt
|
||||
// Put comments around the text after an #endif for increased portability.
|
||||
//
|
||||
// Revision 1.3 1997/05/31 19:16:27 curt
|
||||
// Elevator trim added.
|
||||
//
|
||||
// Revision 1.2 1997/05/23 15:40:33 curt
|
||||
// Added GNU copyright headers.
|
||||
//
|
||||
// Revision 1.1 1997/05/16 15:59:48 curt
|
||||
// Initial revision.
|
||||
//
|
52
Simulator/JSBsim/FGDefs.h
Normal file
52
Simulator/JSBsim/FGDefs.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGDefs.h
|
||||
Author: Jon S. Berndt
|
||||
Date started: 02/01/99
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
02/01/99 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGDEFS_H
|
||||
#define FGDEFS_H
|
||||
|
||||
#define MAX_ENGINES 10
|
||||
#define MAX_TANKS 30
|
||||
#define GRAVITY 32.174
|
||||
#define EARTHRAD 20898908.00 // feet
|
||||
#define OMEGAEARTH 7.2685E-3 // rad/sec
|
||||
#define EARTHRADSQRD 437882827922500.0
|
||||
#define ONESECOND 4.848136811E-6
|
||||
#define ECCENT 0.996647186
|
||||
#define ECCENTSQRD 0.99330561
|
||||
#define INVECCENTSQRD 1.0067395
|
||||
#define INVECCENTSQRDM1 0.0067395
|
||||
#define EPS 0.081819221
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
177
Simulator/JSBsim/FGEngine.cpp
Normal file
177
Simulator/JSBsim/FGEngine.cpp
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGEngine.cpp
|
||||
Author: Jon Berndt
|
||||
Date started: 01/21/99
|
||||
Called by: FGAircraft
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
See header file.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
01/21/99 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef FGFS
|
||||
# include <Include/compiler.h>
|
||||
# ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <fstream>
|
||||
# else
|
||||
# include <fstream.h>
|
||||
# endif
|
||||
#else
|
||||
# include <fstream>
|
||||
#endif
|
||||
|
||||
#include "FGEngine.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, int num)
|
||||
{
|
||||
string fullpath;
|
||||
string tag;
|
||||
|
||||
FDMExec = fdex;
|
||||
|
||||
State = FDMExec->GetState();
|
||||
Atmosphere = FDMExec->GetAtmosphere();
|
||||
FCS = FDMExec->GetFCS();
|
||||
Aircraft = FDMExec->GetAircraft();
|
||||
Translation = FDMExec->GetTranslation();
|
||||
Rotation = FDMExec->GetRotation();
|
||||
Position = FDMExec->GetPosition();
|
||||
Auxiliary = FDMExec->GetAuxiliary();
|
||||
Output = FDMExec->GetOutput();
|
||||
|
||||
Name = engineName;
|
||||
fullpath = enginePath + "/" + engineName + ".dat";
|
||||
ifstream enginefile(fullpath.c_str());
|
||||
|
||||
if (enginefile) {
|
||||
enginefile >> tag;
|
||||
|
||||
if (tag == "ROCKET") Type = etRocket;
|
||||
else if (tag == "PISTON") Type = etPiston;
|
||||
else if (tag == "TURBOPROP") Type = etTurboProp;
|
||||
else if (tag == "TURBOJET") Type = etTurboJet;
|
||||
else Type = etUnknown;
|
||||
|
||||
enginefile >> X;
|
||||
enginefile >> Y;
|
||||
enginefile >> Z;
|
||||
enginefile >> SLThrustMax;
|
||||
enginefile >> VacThrustMax;
|
||||
enginefile >> MaxThrottle;
|
||||
enginefile >> MinThrottle;
|
||||
enginefile >> SLFuelFlowMax;
|
||||
if (Type == 1)
|
||||
enginefile >> SLOxiFlowMax;
|
||||
enginefile.close();
|
||||
} else {
|
||||
cerr << "Unable to open engine definition file " << engineName << endl;
|
||||
}
|
||||
|
||||
EngineNumber = num;
|
||||
Thrust = 0.0;
|
||||
Starved = Flameout = false;
|
||||
}
|
||||
|
||||
|
||||
FGEngine::~FGEngine(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
float FGEngine::CalcRocketThrust(void)
|
||||
{
|
||||
float lastThrust;
|
||||
|
||||
Throttle = FCS->GetThrottle(EngineNumber);
|
||||
lastThrust = Thrust; // last actual thrust
|
||||
|
||||
if (Throttle < MinThrottle || Starved) {
|
||||
PctPower = Thrust = 0.0; // desired thrust
|
||||
Flameout = true;
|
||||
} else {
|
||||
PctPower = Throttle / MaxThrottle;
|
||||
Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
|
||||
SLThrustMax); // desired thrust
|
||||
Flameout = false;
|
||||
}
|
||||
|
||||
Thrust += 0.8*(Thrust - lastThrust); // actual thrust
|
||||
|
||||
return Thrust;
|
||||
}
|
||||
|
||||
|
||||
float FGEngine::CalcPistonThrust(void)
|
||||
{
|
||||
return Thrust;
|
||||
}
|
||||
|
||||
|
||||
float FGEngine::CalcThrust(void)
|
||||
{
|
||||
switch(Type) {
|
||||
case etRocket:
|
||||
return CalcRocketThrust();
|
||||
// break;
|
||||
case etPiston:
|
||||
return CalcPistonThrust();
|
||||
// break;
|
||||
default:
|
||||
return 9999.0;
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
float FGEngine::CalcFuelNeed() {
|
||||
FuelNeed = SLFuelFlowMax*PctPower;
|
||||
return FuelNeed;
|
||||
}
|
||||
|
||||
|
||||
float FGEngine::CalcOxidizerNeed() {
|
||||
OxidizerNeed = SLOxiFlowMax*PctPower;
|
||||
return OxidizerNeed;
|
||||
}
|
||||
|
133
Simulator/JSBsim/FGEngine.h
Normal file
133
Simulator/JSBsim/FGEngine.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGEngine.h
|
||||
Author: Jon S. Berndt
|
||||
Date started: 01/21/99
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Based on Flightgear code, which is based on LaRCSim. This class simulates
|
||||
a generic engine.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
01/21/99 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGEngine_H
|
||||
#define FGEngine_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef FGFS
|
||||
# include <Include/compiler.h>
|
||||
# include STL_STRING
|
||||
FG_USING_STD(string);
|
||||
#else
|
||||
# include <string>
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
DEFINES
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
class FGFDMExec;
|
||||
class FGState;
|
||||
class FGAtmosphere;
|
||||
class FGFCS;
|
||||
class FGAircraft;
|
||||
class FGTranslation;
|
||||
class FGRotation;
|
||||
class FGPosition;
|
||||
class FGAuxiliary;
|
||||
class FGOutput;
|
||||
|
||||
class FGEngine
|
||||
{
|
||||
public:
|
||||
FGEngine(FGFDMExec*, string, string, int);
|
||||
~FGEngine(void);
|
||||
|
||||
enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet};
|
||||
|
||||
float GetThrottle(void) {return Throttle;}
|
||||
float GetThrust(void) {return Thrust;}
|
||||
bool GetStarved(void) {return Starved;}
|
||||
bool GetFlameout(void) {return Flameout;}
|
||||
int GetType(void) {return Type;}
|
||||
string GetName() {return Name;}
|
||||
|
||||
void SetStarved(bool tt) {Starved = tt;}
|
||||
void SetStarved(void) {Starved = true;}
|
||||
|
||||
float CalcThrust(void);
|
||||
float CalcFuelNeed(void);
|
||||
float CalcOxidizerNeed(void);
|
||||
|
||||
private:
|
||||
string Name;
|
||||
EngineType Type;
|
||||
float X, Y, Z;
|
||||
float SLThrustMax;
|
||||
float VacThrustMax;
|
||||
float SLFuelFlowMax;
|
||||
float SLOxiFlowMax;
|
||||
float MaxThrottle;
|
||||
float MinThrottle;
|
||||
|
||||
float Thrust;
|
||||
float Throttle;
|
||||
float FuelNeed, OxidizerNeed;
|
||||
bool Starved;
|
||||
bool Flameout;
|
||||
float PctPower;
|
||||
int EngineNumber;
|
||||
|
||||
FGFDMExec* FDMExec;
|
||||
FGState* State;
|
||||
FGAtmosphere* Atmosphere;
|
||||
FGFCS* FCS;
|
||||
FGAircraft* Aircraft;
|
||||
FGTranslation* Translation;
|
||||
FGRotation* Rotation;
|
||||
FGPosition* Position;
|
||||
FGAuxiliary* Auxiliary;
|
||||
FGOutput* Output;
|
||||
|
||||
protected:
|
||||
float CalcRocketThrust(void);
|
||||
float CalcPistonThrust(void);
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
74
Simulator/JSBsim/FGFCS.cpp
Normal file
74
Simulator/JSBsim/FGFCS.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGFCS.cpp
|
||||
Author: Jon Berndt
|
||||
Date started: 12/12/98
|
||||
Purpose: Model the flight controls
|
||||
Called by: FDMExec
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
This class models the flight controls for a specific airplane
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
12/12/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGFCS.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
|
||||
{
|
||||
Name = "FGFCS";
|
||||
}
|
||||
|
||||
|
||||
FGFCS::~FGFCS(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FGFCS::Run(void)
|
||||
{
|
||||
if (!FGModel::Run()) {
|
||||
|
||||
} else {
|
||||
}
|
||||
return false;
|
||||
}
|
78
Simulator/JSBsim/FGFCS.h
Normal file
78
Simulator/JSBsim/FGFCS.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGGFCS.h
|
||||
Author: Jon S. Berndt
|
||||
Date started: 12/12/98
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
12/12/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGFCS_H
|
||||
#define FGFCS_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGModel.h"
|
||||
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
class FGFCS : public FGModel
|
||||
{
|
||||
public:
|
||||
FGFCS(FGFDMExec*);
|
||||
~FGFCS(void);
|
||||
|
||||
bool Run(void);
|
||||
|
||||
inline float GetDa(void) {return Da;}
|
||||
inline float GetDe(void) {return De;}
|
||||
inline float GetDr(void) {return Dr;}
|
||||
inline float GetDf(void) {return Df;}
|
||||
inline float GetDs(void) {return Ds;}
|
||||
inline float GetThrottle(int ii) {return Throttle[ii];}
|
||||
|
||||
inline void SetDa(float tt) {Da = tt;}
|
||||
inline void SetDe(float tt) {De = tt;}
|
||||
inline void SetDr(float tt) {Dr = tt;}
|
||||
inline void SetDf(float tt) {Df = tt;}
|
||||
inline void SetDs(float tt) {Ds = tt;}
|
||||
inline void SetThrottle(int ii, float tt) {Throttle[ii] = tt;}
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
float Da, De, Dr, Df, Ds;
|
||||
float Throttle[MAX_ENGINES];
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
174
Simulator/JSBsim/FGFDMExec.cpp
Normal file
174
Simulator/JSBsim/FGFDMExec.cpp
Normal file
|
@ -0,0 +1,174 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGFDMExec.cpp
|
||||
Author: Jon S. Berndt
|
||||
Date started: 11/17/98
|
||||
Purpose: Schedules and runs the model routines.
|
||||
Called by: The GUI.
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
This class wraps up the simulation scheduling routines.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
11/17/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef FGFS
|
||||
# include <Include/compiler.h>
|
||||
# ifdef FG_HAVE_STD_INCLUDES
|
||||
# include <iostream>
|
||||
# include <ctime>
|
||||
# else
|
||||
# include <iostream.h>
|
||||
# include <time.h>
|
||||
# endif
|
||||
#else
|
||||
# include <iostream>
|
||||
# include <ctime>
|
||||
#endif
|
||||
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGState.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
// Constructor
|
||||
|
||||
FGFDMExec::FGFDMExec(void)
|
||||
{
|
||||
FirstModel = 0;
|
||||
Error = 0;
|
||||
State = 0;
|
||||
Atmosphere = 0;
|
||||
FCS = 0;
|
||||
Aircraft = 0;
|
||||
Translation = 0;
|
||||
Rotation = 0;
|
||||
Position = 0;
|
||||
Auxiliary = 0;
|
||||
Output = 0;
|
||||
|
||||
// Instantiate this FDM Executive's Models
|
||||
|
||||
Atmosphere = new FGAtmosphere(this);
|
||||
FCS = new FGFCS(this);
|
||||
Aircraft = new FGAircraft(this);
|
||||
Translation = new FGTranslation(this);
|
||||
Rotation = new FGRotation(this);
|
||||
Position = new FGPosition(this);
|
||||
Auxiliary = new FGAuxiliary(this);
|
||||
Output = new FGOutput(this);
|
||||
|
||||
State = new FGState(this);
|
||||
|
||||
// Initialize models so they can communicate with each other
|
||||
|
||||
if (!Atmosphere->InitModel()) {cerr << "Atmosphere model init failed"; Error+=1;}
|
||||
if (!FCS->InitModel()) {cerr << "FCS model init failed"; Error+=2;}
|
||||
if (!Aircraft->InitModel()) {cerr << "Aircraft model init failed"; Error+=4;}
|
||||
if (!Translation->InitModel()){cerr << "Translation model init failed"; Error+=8;}
|
||||
if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;}
|
||||
if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
|
||||
if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
|
||||
if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
|
||||
|
||||
Schedule(Atmosphere, 5);
|
||||
Schedule(FCS, 1);
|
||||
Schedule(Aircraft, 1);
|
||||
Schedule(Rotation, 1);
|
||||
Schedule(Translation, 1);
|
||||
Schedule(Position, 1);
|
||||
Schedule(Auxiliary, 1);
|
||||
Schedule(Output, 5);
|
||||
|
||||
terminate = false;
|
||||
frozen = false;
|
||||
}
|
||||
|
||||
|
||||
FGFDMExec::~FGFDMExec(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int FGFDMExec::Schedule(FGModel* model, int rate)
|
||||
{
|
||||
FGModel* model_iterator;
|
||||
|
||||
model_iterator = FirstModel;
|
||||
|
||||
if (model_iterator == 0L) { // this is the first model
|
||||
|
||||
FirstModel = model;
|
||||
FirstModel->NextModel = 0L;
|
||||
FirstModel->SetRate(rate);
|
||||
|
||||
} else { // subsequent model
|
||||
|
||||
while (model_iterator->NextModel != 0L) {
|
||||
model_iterator = model_iterator->NextModel;
|
||||
}
|
||||
model_iterator->NextModel = model;
|
||||
model_iterator->NextModel->SetRate(rate);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool FGFDMExec::Run(void)
|
||||
{
|
||||
FGModel* model_iterator;
|
||||
|
||||
if (frozen) return true;
|
||||
|
||||
model_iterator = FirstModel;
|
||||
if (model_iterator == 0L) return false;
|
||||
|
||||
while (!model_iterator->Run())
|
||||
{
|
||||
model_iterator = model_iterator->NextModel;
|
||||
if (model_iterator == 0L) break;
|
||||
}
|
||||
|
||||
State->IncrTime();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
100
Simulator/JSBsim/FGFDMExec.h
Normal file
100
Simulator/JSBsim/FGFDMExec.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGFDMExec.h
|
||||
Author: Jon Berndt
|
||||
Date started: 11/17/98
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
11/17/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGFDMEXEC_HEADER_H
|
||||
#define FGFDMEXEC_HEADER_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGModel.h"
|
||||
|
||||
/*******************************************************************************
|
||||
CLASS DECLARATION
|
||||
*******************************************************************************/
|
||||
|
||||
class FGState;
|
||||
class FGAtmosphere;
|
||||
class FGFCS;
|
||||
class FGAircraft;
|
||||
class FGTranslation;
|
||||
class FGRotation;
|
||||
class FGPosition;
|
||||
class FGAuxiliary;
|
||||
class FGOutput;
|
||||
|
||||
class FGFDMExec
|
||||
{
|
||||
public:
|
||||
FGFDMExec::FGFDMExec(void);
|
||||
FGFDMExec::~FGFDMExec(void);
|
||||
|
||||
FGModel* FirstModel;
|
||||
|
||||
bool Initialize(void);
|
||||
int Schedule(FGModel* model, int rate);
|
||||
bool Run(void);
|
||||
void Freeze(void) {frozen = true;}
|
||||
void Resume(void) {frozen = false;}
|
||||
|
||||
inline FGState* GetState(void) {return State;}
|
||||
inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
|
||||
inline FGFCS* GetFCS(void) {return FCS;}
|
||||
inline FGAircraft* GetAircraft(void) {return Aircraft;}
|
||||
inline FGTranslation* GetTranslation(void) {return Translation;}
|
||||
inline FGRotation* GetRotation(void) {return Rotation;}
|
||||
inline FGPosition* GetPosition(void) {return Position;}
|
||||
inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
|
||||
inline FGOutput* GetOutput(void) {return Output;}
|
||||
|
||||
private:
|
||||
bool frozen;
|
||||
bool terminate;
|
||||
int Error;
|
||||
|
||||
FGState* State;
|
||||
FGAtmosphere* Atmosphere;
|
||||
FGFCS* FCS;
|
||||
FGAircraft* Aircraft;
|
||||
FGTranslation* Translation;
|
||||
FGRotation* Rotation;
|
||||
FGPosition* Position;
|
||||
FGAuxiliary* Auxiliary;
|
||||
FGOutput* Output;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
41
Simulator/JSBsim/FGMain.cpp
Normal file
41
Simulator/JSBsim/FGMain.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "FGFDMExec.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
void main(int argc, char** argv)
|
||||
{
|
||||
FGFDMExec* FDMExec;
|
||||
|
||||
struct timespec short_wait = {0,100000000};
|
||||
struct timespec no_wait = {0,100000000};
|
||||
|
||||
if (argc != 3) {
|
||||
cout << endl
|
||||
<< " You must enter the name of a registered aircraft and reset point:"
|
||||
<< endl << endl << " FDM <aircraft name> <reset file>" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
FDMExec = new FGFDMExec();
|
||||
|
||||
FDMExec->GetAircraft()->LoadAircraft("aircraft", "engine", string(argv[1]));
|
||||
FDMExec->GetState()->Reset("aircraft", string(argv[2]));
|
||||
|
||||
while (FDMExec->GetState()->Getsim_time() <= 25.0)
|
||||
{
|
||||
FDMExec->Run();
|
||||
nanosleep(&short_wait,&no_wait);
|
||||
}
|
||||
|
||||
delete FDMExec;
|
||||
}
|
397
Simulator/JSBsim/FGMatrix.cpp
Normal file
397
Simulator/JSBsim/FGMatrix.cpp
Normal file
|
@ -0,0 +1,397 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGMatrix.cpp
|
||||
Author: Tony Peden [formatted here by JSB]
|
||||
Date started: ??
|
||||
Purpose: FGMatrix class
|
||||
Called by: Various
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ARGUMENTS
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
??/??/?? TP Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "FGMatrix.h"
|
||||
#include <iostream.h>
|
||||
#include <iomanip.h>
|
||||
#include <fstream.h>
|
||||
|
||||
/*******************************************************************************
|
||||
DEFINES
|
||||
*******************************************************************************/
|
||||
|
||||
#pragma warn -use
|
||||
|
||||
/*******************************************************************************
|
||||
CONSTANTS
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
TYPEDEFS
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
GLOBALS
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
double** alloc(int rows,int cols)
|
||||
{
|
||||
double **A;
|
||||
|
||||
A = new double *[rows+1];
|
||||
if (!A) return NULL;
|
||||
|
||||
for (int i=0;i<=rows;i++){
|
||||
A[i]=new double[cols+1];
|
||||
if (!A[i]) return NULL;
|
||||
}
|
||||
return A;
|
||||
}
|
||||
|
||||
|
||||
void dealloc(double **A, int rows, int cols)
|
||||
{
|
||||
for(int i=0;i<=rows;i++){
|
||||
delete[] A[i];
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
}
|
||||
|
||||
|
||||
FGMatrix::FGMatrix(unsigned rows, unsigned cols)
|
||||
{
|
||||
this->rows=rows;
|
||||
this->cols=cols;
|
||||
keep=false;
|
||||
data=alloc(rows,cols);
|
||||
}
|
||||
|
||||
|
||||
FGMatrix::FGMatrix(const FGMatrix& A)
|
||||
{
|
||||
data=NULL;
|
||||
*this=A;
|
||||
}
|
||||
|
||||
|
||||
FGMatrix::~FGMatrix(void)
|
||||
{
|
||||
if (keep == false) {
|
||||
dealloc(data,rows,cols);
|
||||
rows=cols=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FGMatrix& FGMatrix::operator=(const FGMatrix& A)
|
||||
{
|
||||
if (&A != this) {
|
||||
if (data != NULL) dealloc(data,rows,cols);
|
||||
|
||||
width = A.width;
|
||||
prec = A.prec;
|
||||
delim = A.delim;
|
||||
origin = A.origin;
|
||||
rows = A.rows;
|
||||
cols = A.cols;
|
||||
keep = false;
|
||||
|
||||
if (A.keep == true) {
|
||||
data = A.data;
|
||||
} else {
|
||||
data = alloc(rows,cols);
|
||||
for (int i=0; i<=rows; i++) {
|
||||
for (int j=0; j<=cols; j++) {
|
||||
data[i][j] = A.data[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
double& FGMatrix::operator()(unsigned row, unsigned col)
|
||||
{
|
||||
return data[row][col];
|
||||
}
|
||||
|
||||
|
||||
unsigned FGMatrix::Rows(void) const
|
||||
{
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
unsigned FGMatrix::Cols(void) const
|
||||
{
|
||||
return cols;
|
||||
}
|
||||
|
||||
|
||||
void FGMatrix::SetOParams(char delim,int width,int prec,int origin)
|
||||
{
|
||||
FGMatrix::delim=delim;
|
||||
FGMatrix::width=width;
|
||||
FGMatrix::prec=prec;
|
||||
FGMatrix::origin=origin;
|
||||
}
|
||||
|
||||
|
||||
void FGMatrix::InitMatrix(double value)
|
||||
{
|
||||
if (data) {
|
||||
for (int i=0;i<=rows;i++) {
|
||||
for (int j=0;j<=cols;j++) {
|
||||
operator()(i,j) = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGMatrix::InitMatrix(void)
|
||||
{
|
||||
this->InitMatrix(0);
|
||||
}
|
||||
|
||||
|
||||
FGMatrix operator-(FGMatrix& A, FGMatrix& B)
|
||||
{
|
||||
if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) {
|
||||
cout << endl << "FGMatrix::operator-" << endl << '\t';
|
||||
cout << "Subtraction not defined for matrices of different sizes";
|
||||
cout << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FGMatrix Diff(A.Rows(),A.Cols());
|
||||
Diff.keep=true;
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
Diff(i,j)=A(i,j)-B(i,j);
|
||||
}
|
||||
}
|
||||
return Diff;
|
||||
}
|
||||
|
||||
|
||||
void operator-=(FGMatrix &A,FGMatrix &B)
|
||||
{
|
||||
if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) {
|
||||
cout << endl << "FGMatrix::operator-" << endl << '\t';
|
||||
cout << "Subtraction not defined for matrices of different sizes";
|
||||
cout << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
A(i,j)-=B(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FGMatrix operator+(FGMatrix& A, FGMatrix& B)
|
||||
{
|
||||
if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) {
|
||||
cout << endl << "FGMatrix::operator+" << endl << '\t';
|
||||
cout << "Addition not defined for matrices of different sizes";
|
||||
cout << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FGMatrix Sum(A.Rows(),A.Cols());
|
||||
Sum.keep = true;
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
Sum(i,j)=A(i,j)+B(i,j);
|
||||
}
|
||||
}
|
||||
return Sum;
|
||||
}
|
||||
|
||||
|
||||
void operator+=(FGMatrix &A,FGMatrix &B)
|
||||
{
|
||||
if ((A.Rows() != B.Rows()) || (A.Cols() != B.Cols())) {
|
||||
cout << endl << "FGMatrix::operator+" << endl << '\t';
|
||||
cout << "Addition not defined for matrices of different sizes";
|
||||
cout << endl;
|
||||
exit(1);
|
||||
}
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
A(i,j)+=B(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FGMatrix operator*(double scalar,FGMatrix &A)
|
||||
{
|
||||
FGMatrix Product(A.Rows(),A.Cols());
|
||||
Product.keep = true;
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
Product(i,j) = scalar*A(i,j);
|
||||
}
|
||||
}
|
||||
return Product;
|
||||
}
|
||||
|
||||
|
||||
void operator*=(FGMatrix &A,double scalar)
|
||||
{
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
A(i,j)*=scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FGMatrix operator*(FGMatrix &Left, FGMatrix &Right)
|
||||
{
|
||||
if (Left.Cols() != Right.Rows()) {
|
||||
cout << endl << "FGMatrix::operator*" << endl << '\t';
|
||||
cout << "The number of rows in the right matrix must match the number";
|
||||
cout << endl << '\t' << "of columns in the left." << endl;
|
||||
cout << '\t' << "Multiplication not defined." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FGMatrix Product(Left.Rows(),Right.Cols());
|
||||
Product.keep = true;
|
||||
for (int i=1;i<=Left.Rows();i++) {
|
||||
for (int j=1;j<=Right.Cols();j++) {
|
||||
Product(i,j) = 0;
|
||||
for (int k=1;k<=Left.Cols();k++) {
|
||||
Product(i,j)+=Left(i,k)*Right(k,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Product;
|
||||
}
|
||||
|
||||
|
||||
void operator*=(FGMatrix &Left,FGMatrix &Right)
|
||||
{
|
||||
if (Left.Cols() != Right.Rows()) {
|
||||
cout << endl << "FGMatrix::operator*" << endl << '\t';
|
||||
cout << "The number of rows in the right matrix must match the number";
|
||||
cout << endl << '\t' << "of columns in the left." << endl;
|
||||
cout << '\t' << "Multiplication not defined." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
double **prod;
|
||||
|
||||
prod=alloc(Left.Rows(),Right.Cols());
|
||||
for (int i=1;i<=Left.Rows();i++) {
|
||||
for (int j=1;j<=Right.Cols();j++) {
|
||||
prod[i][j] = 0;
|
||||
for (int k=1;k<=Left.Cols();k++) {
|
||||
prod[i][j]+=Left(i,k)*Right(k,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
dealloc(Left.data,Left.Rows(),Left.Cols());
|
||||
Left.data=prod;
|
||||
Left.cols=Right.cols;
|
||||
}
|
||||
|
||||
|
||||
FGMatrix operator/(FGMatrix& A, double scalar)
|
||||
{
|
||||
FGMatrix Quot(A.Rows(),A.Cols());
|
||||
A.keep = true;
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
Quot(i,j)=A(i,j)/scalar;
|
||||
}
|
||||
}
|
||||
return Quot;
|
||||
}
|
||||
|
||||
|
||||
void operator/=(FGMatrix &A,double scalar)
|
||||
{
|
||||
for (int i=1;i<=A.Rows();i++) {
|
||||
for (int j=1;j<=A.Cols();j++) {
|
||||
A(i,j)/=scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGMatrix::T(void)
|
||||
{
|
||||
if (rows==cols)
|
||||
TransposeSquare();
|
||||
else
|
||||
TransposeNonSquare();
|
||||
}
|
||||
|
||||
|
||||
void FGMatrix::TransposeSquare(void)
|
||||
{
|
||||
for (int i=1;i<=rows;i++) {
|
||||
for (int j=i+1;j<=cols;j++) {
|
||||
double tmp=data[i][j];
|
||||
data[i][j]=data[j][i];
|
||||
data[j][i]=tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGMatrix::TransposeNonSquare(void)
|
||||
{
|
||||
double **tran;
|
||||
|
||||
tran=alloc(rows,cols);
|
||||
for (int i=1;i<=rows;i++) {
|
||||
for (int j=1;j<=cols;j++) {
|
||||
tran[j][i]=data[i][j];
|
||||
}
|
||||
}
|
||||
dealloc(data,rows,cols);
|
||||
|
||||
data=tran;
|
||||
unsigned m=rows;
|
||||
rows=cols;
|
||||
cols=m;
|
||||
}
|
||||
|
||||
|
||||
FGColumnVector::FGColumnVector(void):FGMatrix(3,1) { }
|
||||
FGColumnVector::FGColumnVector(int m):FGMatrix(m,1) { }
|
||||
FGColumnVector::FGColumnVector(FGColumnVector& b):FGMatrix(b) { }
|
||||
FGColumnVector::~FGColumnVector() { }
|
||||
double& FGColumnVector::operator()(int m)
|
||||
{
|
||||
return FGMatrix::operator()(m,1);
|
||||
}
|
||||
|
98
Simulator/JSBsim/FGMatrix.h
Normal file
98
Simulator/JSBsim/FGMatrix.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Header: FGMatrix.h
|
||||
Author: Tony Peden [formatted here by Jon Berndt]
|
||||
Date started: Unknown
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
??/??/?? TP Created
|
||||
|
||||
/*******************************************************************************
|
||||
SENTRY
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef FGMATRIX_H
|
||||
#define FGMATRIX_H
|
||||
|
||||
/*******************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
|
||||
/*******************************************************************************
|
||||
DEFINES
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
CONSTANTS
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
TYPEDEFS
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
GLOBALS
|
||||
*******************************************************************************/
|
||||
|
||||
class FGMatrix
|
||||
{
|
||||
private:
|
||||
double **data;
|
||||
unsigned rows,cols;
|
||||
bool keep;
|
||||
char delim;
|
||||
int width,prec,origin;
|
||||
void TransposeSquare(void);
|
||||
void TransposeNonSquare(void);
|
||||
|
||||
public:
|
||||
FGMatrix(unsigned rows, unsigned cols);
|
||||
FGMatrix(const FGMatrix& A);
|
||||
~FGMatrix(void);
|
||||
|
||||
FGMatrix& FGMatrix::operator=(const FGMatrix& A);
|
||||
double& FGMatrix::operator()(unsigned row, unsigned col);
|
||||
|
||||
unsigned FGMatrix::Rows(void) const;
|
||||
unsigned FGMatrix::Cols(void) const;
|
||||
|
||||
void FGMatrix::T(void);
|
||||
void InitMatrix(void);
|
||||
void InitMatrix(double value);
|
||||
|
||||
friend FGMatrix operator-(FGMatrix& A, FGMatrix& B);
|
||||
friend FGMatrix operator+(FGMatrix& A, FGMatrix& B);
|
||||
friend FGMatrix operator*(double scalar,FGMatrix& A);
|
||||
friend FGMatrix operator*(FGMatrix& Left, FGMatrix& Right);
|
||||
friend FGMatrix operator/(FGMatrix& A, double scalar);
|
||||
|
||||
friend void operator-=(FGMatrix &A,FGMatrix &B);
|
||||
friend void operator+=(FGMatrix &A,FGMatrix &B);
|
||||
friend void operator*=(FGMatrix &A,FGMatrix &B);
|
||||
friend void operator*=(FGMatrix &A,double scalar);
|
||||
friend void operator/=(FGMatrix &A,double scalar);
|
||||
|
||||
void SetOParams(char delim,int width,int prec, int origin=0);
|
||||
};
|
||||
|
||||
class FGColumnVector : public FGMatrix
|
||||
{
|
||||
public:
|
||||
FGColumnVector(void);
|
||||
FGColumnVector(int m);
|
||||
FGColumnVector(FGColumnVector& b);
|
||||
~FGColumnVector();
|
||||
|
||||
double& operator()(int m);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#endif
|
117
Simulator/JSBsim/FGModel.cpp
Normal file
117
Simulator/JSBsim/FGModel.cpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Module: FGModel.cpp
|
||||
Author: Jon Berndt
|
||||
Date started: 11/11/98
|
||||
Purpose: Base class for all models
|
||||
Called by: FGSimExec, et. al.
|
||||
|
||||
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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., 59 Temple
|
||||
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Further information about the GNU General Public License can also be found on
|
||||
the world wide web at http://www.gnu.org.
|
||||
|
||||
FUNCTIONAL DESCRIPTION
|
||||
--------------------------------------------------------------------------------
|
||||
This base class for the FGAero, FGRotational, etc. classes defines methods
|
||||
common to all models.
|
||||
|
||||
HISTORY
|
||||
--------------------------------------------------------------------------------
|
||||
11/11/98 JSB Created
|
||||
|
||||
********************************************************************************
|
||||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "FGModel.h"
|
||||
#include "FGState.h"
|
||||
#include "FGFDMExec.h"
|
||||
#include "FGAtmosphere.h"
|
||||
#include "FGFCS.h"
|
||||
#include "FGAircraft.h"
|
||||
#include "FGTranslation.h"
|
||||
#include "FGRotation.h"
|
||||
#include "FGPosition.h"
|
||||
#include "FGAuxiliary.h"
|
||||
#include "FGOutput.h"
|
||||
|
||||
/*******************************************************************************
|
||||
************************************ CODE **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
FGModel::FGModel(FGFDMExec* fdmex)
|
||||
{
|
||||
FDMExec = fdmex;
|
||||
NextModel = 0L;
|
||||
|
||||
State = 0;
|
||||
Atmosphere = 0;
|
||||
FCS = 0;
|
||||
Aircraft = 0;
|
||||
Translation = 0;
|
||||
Rotation = 0;
|
||||
Position = 0;
|
||||
Auxiliary = 0;
|
||||
Output = 0;
|
||||
|
||||
exe_ctr = 1;
|
||||
}
|
||||
|
||||
|
||||
FGModel::~FGModel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FGModel::InitModel(void)
|
||||
{
|
||||
State = FDMExec->GetState();
|
||||
Atmosphere = FDMExec->GetAtmosphere();
|
||||
FCS = FDMExec->GetFCS();
|
||||
Aircraft = FDMExec->GetAircraft();
|
||||
Translation = FDMExec->GetTranslation();
|
||||
Rotation = FDMExec->GetRotation();
|
||||
Position = FDMExec->GetPosition();
|
||||
Auxiliary = FDMExec->GetAuxiliary();
|
||||
Output = FDMExec->GetOutput();
|
||||
|
||||
if (!State ||
|
||||
!Atmosphere ||
|
||||
!FCS ||
|
||||
!Aircraft ||
|
||||
!Translation ||
|
||||
!Rotation ||
|
||||
!Position ||
|
||||
!Auxiliary ||
|
||||
!Output) return(false);
|
||||
else return(true);
|
||||
}
|
||||
|
||||
|
||||
bool FGModel::Run()
|
||||
{
|
||||
if (exe_ctr == 1) {
|
||||
if (exe_ctr++ >= rate) exe_ctr = 1;
|
||||
return false;
|
||||
} else {
|
||||
if (exe_ctr++ >= rate) exe_ctr = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue