1
0
Fork 0

Goodbye old HUD - and the archeology it depended upon in cockpit.cxx

This commit is contained in:
James Turner 2010-10-29 01:18:06 +01:00
parent 6081f24b00
commit d1a4590721
20 changed files with 6 additions and 5261 deletions

View file

@ -1923,90 +1923,6 @@
<Filter
Name="Lib_Cockpit"
>
<File
RelativePath="..\..\..\src\Cockpit\cockpit.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\cockpit.hxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud.cxx"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud.hxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_card.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_dnst.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_gaug.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_inst.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_labl.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_ladr.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_rwy.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_scal.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Cockpit\hud_tbi.cxx"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\..\src\Cockpit\panel.cxx"
>

View file

@ -1,14 +1,8 @@
noinst_LIBRARIES = libCockpit.a
libCockpit_a_SOURCES = \
cockpit.cxx cockpit.hxx \
hud.cxx hud.hxx \
hud_card.cxx hud_dnst.cxx hud_gaug.cxx hud_inst.cxx \
hud_labl.cxx hud_ladr.cxx \
hud_rwy.cxx \
hud_scal.cxx hud_tbi.cxx \
panel.cxx panel.hxx \
panel_io.cxx panel_io.hxx
panel_io.cxx panel_io.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -1,465 +0,0 @@
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <simgear/compiler.h>
#include <simgear/sg_inlines.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props.hxx>
#include <simgear/timing/sg_time.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/viewmgr.hxx>
#include <Main/viewer.hxx>
#include <Scenery/scenery.hxx>
#include <GUI/gui.h>
#include "cockpit.hxx"
#include "hud.hxx"
// 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.
//
float get_latitude( void )
{
return fgGetDouble("/position/latitude-deg");
}
float get_lat_min( void )
{
double a, d;
a = fgGetDouble("/position/latitude-deg");
if (a < 0.0) {
a = -a;
}
d = (double) ( (int) a);
float lat_min = (a - d) * 60.0;
return lat_min;
}
float get_longitude( void )
{
return fgGetDouble("/position/longitude-deg");
}
char*
get_formated_gmt_time( void )
{
static char buf[32];
const struct tm *p = globals->get_time_params()->getGmt();
sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
p->tm_hour, p->tm_min, p->tm_sec);
return buf;
}
float get_long_min( void )
{
double a, d;
a = fgGetDouble("/position/longitude-deg");
if (a < 0.0) {
a = -a;
}
d = (double) ( (int) a);
float lon_min = (a - d) * 60.0;
return lon_min;
}
float get_throttleval( void )
{
// Hack limiting to one engine
return globals->get_controls()->get_throttle( 0 );
}
float get_aileronval( void )
{
return globals->get_controls()->get_aileron();
}
float get_elevatorval( void )
{
return globals->get_controls()->get_elevator();
}
float get_elev_trimval( void )
{
return globals->get_controls()->get_elevator_trim();
}
float get_rudderval( void )
{
return globals->get_controls()->get_rudder();
}
float get_speed( void )
{
static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
float speed = fgGetDouble("/velocities/airspeed-kt")
* speedup_node->getIntValue();
return speed;
}
float get_mach(void)
{
return fgGetDouble("/velocities/mach");
}
float get_aoa( void )
{
return fgGetDouble("/orientation/alpha-deg");
}
float get_roll( void )
{
return fgGetDouble("/orientation/roll-deg") * SG_DEGREES_TO_RADIANS;
}
float get_pitch( void )
{
return fgGetDouble("/orientation/pitch-deg") * SG_DEGREES_TO_RADIANS;
}
float get_heading( void )
{
return fgGetDouble("/orientation/heading-deg");
}
float get_altitude( void )
{
static const SGPropertyNode *startup_units_node
= fgGetNode("/sim/startup/units");
if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
return fgGetDouble("/position/altitude-ft");
} else {
return fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
}
}
float get_agl( void )
{
static const SGPropertyNode *startup_units_node
= fgGetNode("/sim/startup/units");
if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
return fgGetDouble("/position/altitude-agl-ft");
} else {
return fgGetDouble("/position/altitude-agl-ft") * SG_FEET_TO_METER;
}
}
float get_sideslip( void )
{
return fgGetDouble("/orientation/side-slip-rad");
}
float get_frame_rate( void )
{
return fgGetInt("/sim/frame-rate");
}
float get_fov( void )
{
return globals->get_current_view()->get_fov();
}
float get_vfc_ratio( void )
{
// float vfc = current_view.get_vfc_ratio();
// return (vfc);
return 0.0;
}
float get_vfc_tris_drawn ( void )
{
// float rendered = current_view.get_tris_rendered();
// return (rendered);
return 0.0;
}
float get_vfc_tris_culled ( void )
{
// float culled = current_view.get_tris_culled();
// return (culled);
return 0.0;
}
float get_climb_rate( void )
{
static const SGPropertyNode *startup_units_node
= fgGetNode("/sim/startup/units");
float climb_rate = fgGetDouble("/velocities/vertical-speed-fps", 0.0);
if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
climb_rate *= 60.0;
} else {
climb_rate *= SG_FEET_TO_METER * 60.0;
}
return climb_rate;
}
float get_view_direction( void )
{
double view_off = 360.0 - globals->get_current_view()->getHeadingOffset_deg();
double view = fgGetDouble("/orientation/heading-deg") + view_off;
SG_NORMALIZE_RANGE(view, 0.0, 360.0);
return view;
}
// Added by Markus Hof on 5. Jan 2004
float get_dme( void )
{
static const SGPropertyNode * dme_node =
fgGetNode("/instrumentation/dme/indicated-distance-nm");
return dme_node->getFloatValue();
}
float get_Ax ( void )
{
return fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
}
float get_anzg ( void )
{
return fgGetDouble("/accelerations/n-z-cg-fps_sec", 0.0);
}
#ifdef ENABLE_SP_FDM
float get_aux1 (void)
{
return fgGetDouble("/fdm-ada/ship-lat", 0.0);
}
float get_aux2 (void)
{
return fgGetDouble("/fdm-ada/ship-lon", 0.0);
}
float get_aux3 (void)
{
return fgGetDouble("/fdm-ada/ship-alt", 0.0);
}
float get_aux4 (void)
{
return fgGetDouble("/fdm-ada/skijump-dist", 0.0);
}
float get_aux5 (void)
{
return fgGetDouble("/fdm-ada/aux5", 0.0);
}
float get_aux6 (void)
{
return fgGetDouble("/fdm-ada/aux6", 0.0);
}
float get_aux7 (void)
{
return fgGetDouble("/fdm-ada/aux7", 0.0);
}
float get_aux8 (void)
{
return fgGetDouble("/fdm-ada/aux8", 0.0);}
float get_aux9 (void)
{
return fgGetDouble("/fdm-ada/aux9", 0.0);}
float get_aux10 (void)
{
return fgGetDouble("/fdm-ada/aux10", 0.0);
}
float get_aux11 (void)
{
return fgGetDouble("/fdm-ada/aux11", 0.0);
}
float get_aux12 (void)
{
return fgGetDouble("/fdm-ada/aux12", 0.0);
}
float get_aux13 (void)
{
return fgGetDouble("/fdm-ada/aux13", 0.0);
}
float get_aux14 (void)
{
return fgGetDouble("/fdm-ada/aux14", 0.0);
}
float get_aux15 (void)
{
return fgGetDouble("/fdm-ada/aux15", 0.0);
}
float get_aux16 (void)
{
return fgGetDouble("/fdm-ada/aux16", 0.0);
}
float get_aux17 (void)
{
return fgGetDouble("/fdm-ada/aux17", 0.0);
}
float get_aux18 (void)
{
return fgGetDouble("/fdm-ada/aux18", 0.0);
}
#endif
bool fgCockpitInit()
{
SG_LOG( SG_COCKPIT, SG_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();
return true;
}
void fgCockpitUpdate( osg::State* state ) {
static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
static const SGPropertyNode * hud_visibility_node
= fgGetNode("/sim/hud/visibility");
int iwidth = xsize_node->getIntValue();
int iheight = ysize_node->getIntValue();
// FIXME: inefficient
if ( hud_visibility_node->getBoolValue() ) {
// This will check the global hud linked list pointer.
// If there is anything to draw it will.
fgUpdateHUD( state );
}
glViewport( 0, 0, iwidth, iheight );
}
struct FuncTable {
const char *name;
FLTFNPTR func;
} fn_table[] = {
{ "agl", get_agl },
{ "aileronval", get_aileronval },
{ "altitude", get_altitude },
{ "anzg", get_anzg },
{ "aoa", get_aoa },
{ "ax", get_Ax },
{ "climb", get_climb_rate },
{ "elevatortrimval", get_elev_trimval },
{ "elevatorval", get_elevatorval },
{ "fov", get_fov },
{ "framerate", get_frame_rate },
{ "heading", get_heading },
{ "latitude", get_latitude },
{ "longitude", get_longitude },
{ "mach", get_mach },
{ "rudderval", get_rudderval },
{ "speed", get_speed },
{ "throttleval", get_throttleval },
{ "view_direction", get_view_direction },
{ "vfc_tris_culled", get_vfc_tris_culled },
{ "vfc_tris_drawn", get_vfc_tris_drawn },
#ifdef ENABLE_SP_FDM
{ "aux1", get_aux1 },
{ "aux2", get_aux2 },
{ "aux3", get_aux3 },
{ "aux4", get_aux4 },
{ "aux5", get_aux5 },
{ "aux6", get_aux6 },
{ "aux7", get_aux7 },
{ "aux8", get_aux8 },
{ "aux9", get_aux9 },
{ "aux10", get_aux10 },
{ "aux11", get_aux11 },
{ "aux12", get_aux12 },
{ "aux13", get_aux13 },
{ "aux14", get_aux14 },
{ "aux15", get_aux15 },
{ "aux16", get_aux16 },
{ "aux17", get_aux17 },
{ "aux18", get_aux18 },
#endif
{ 0, 0 },
};
FLTFNPTR get_func(const char *name)
{
for (int i = 0; fn_table[i].name; i++)
if (!strcmp(fn_table[i].name, name))
return fn_table[i].func;
return 0;
}

View file

@ -1,39 +0,0 @@
/**************************************************************************
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id$
**************************************************************************/
#ifndef _COCKPIT_HXX
#define _COCKPIT_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <osg/State>
bool fgCockpitInit();
void fgCockpitUpdate( osg::State* );
#endif /* _COCKPIT_HXX */

View file

@ -1,654 +0,0 @@
// hud.cxx -- hud defines and prototypes
//
// Written by Michele America, started September 1997.
//
// Copyright (C) 1997 Michele F. America - micheleamerica@geocities.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include <simgear/compiler.h>
#include <simgear/structure/exception.hxx>
#include <string>
#include <fstream>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <math.h>
#include <stdlib.h>
#include <stdio.h> // char related functions
#include <string.h> // strcmp()
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props_io.hxx>
#include <osg/Matrixf>
#include <GUI/new_gui.hxx> // FGFontCache
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#include <Airports/runways.hxx>
#include <Main/viewer.hxx>
#include "hud.hxx"
static HUD_Properties *HUDprop = 0;
static char units[5];
deque<SGSharedPtr<instr_item> > HUD_deque;
fgTextList HUD_TextList;
fgLineList HUD_LineList;
fgLineList HUD_StippleLineList;
fntRenderer *HUDtext = 0;
fntTexFont *HUD_Font = 0;
float HUD_TextSize = 0;
int HUD_style = 0;
float HUD_matrix[16];
int readHud( istream &input );
int readInstrument ( const SGPropertyNode * node);
static void drawHUD(osg::State*);
static void fgUpdateHUDVirtual(osg::State*);
class locRECT {
public:
RECT rect;
locRECT( UINT left, UINT top, UINT right, UINT bottom);
RECT get_rect(void) { return rect; }
};
locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
{
rect.left = left;
rect.top = top;
rect.right = right;
rect.bottom = bottom;
}
// #define DEBUG
int readInstrument(const SGPropertyNode * node)
{
static const SGPropertyNode *startup_units_node
= fgGetNode("/sim/startup/units");
instr_item *HIptr;
if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
strcpy(units, " ft");
} else {
strcpy(units, " m");
}
const SGPropertyNode * ladder_group = node->getNode("ladders");
if (ladder_group != 0) {
int nLadders = ladder_group->nChildren();
for (int j = 0; j < nLadders; j++) {
HIptr = static_cast<instr_item *>(new HudLadder(ladder_group->getChild(j)));
HUD_deque.insert(HUD_deque.begin(), HIptr);
}
}
const SGPropertyNode * card_group = node->getNode("cards");
if (card_group != 0) {
int nCards = card_group->nChildren();
for (int j = 0; j < nCards; j++) {
const char *type = card_group->getChild(j)->getStringValue("type", "gauge");
if (!strcmp(type, "gauge"))
HIptr = static_cast<instr_item *>(new gauge_instr(card_group->getChild(j)));
else if (!strcmp(type, "dial") || !strcmp(type, "tape"))
HIptr = static_cast<instr_item *>(new hud_card(card_group->getChild(j)));
else {
SG_LOG(SG_INPUT, SG_WARN, "HUD: unknown 'card' type: " << type);
continue;
}
HUD_deque.insert(HUD_deque.begin(), HIptr);
}
}
const SGPropertyNode * label_group = node->getNode("labels");
if (label_group != 0) {
int nLabels = label_group->nChildren();
for (int j = 0; j < nLabels; j++) {
HIptr = static_cast<instr_item *>(new instr_label(label_group->getChild(j)));
HUD_deque.insert(HUD_deque.begin(), HIptr);
}
}
const SGPropertyNode * tbi_group = node->getNode("tbis");
if (tbi_group != 0) {
int nTbis = tbi_group->nChildren();
for (int j = 0; j < nTbis; j++) {
HIptr = static_cast<instr_item *>(new fgTBI_instr(tbi_group->getChild(j)));
HUD_deque.insert(HUD_deque.begin(), HIptr);
}
}
const SGPropertyNode * rwy_group = node->getNode("runways");
if (rwy_group != 0) {
int nRwy = rwy_group->nChildren();
for (int j = 0; j < nRwy; j++) {
HIptr = static_cast<instr_item *>(new runway_instr(rwy_group->getChild(j)));
HUD_deque.insert(HUD_deque.begin(), HIptr);
}
}
return 0;
} //end readinstrument
int readHud( istream &input )
{
SGPropertyNode root;
try {
readProperties(input, &root);
} catch (const sg_exception &e) {
guiErrorMessage("Error reading HUD: ", e);
return 0;
}
SG_LOG(SG_INPUT, SG_DEBUG, "Read properties for " <<
root.getStringValue("name"));
if (!root.getNode("depreciated"))
SG_LOG(SG_INPUT, SG_ALERT, "WARNING: use of depreciated old HUD");
HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
SG_LOG(SG_INPUT, SG_DEBUG, "Reading Hud instruments");
const SGPropertyNode * instrument_group = root.getChild("instruments");
int nInstruments = instrument_group->nChildren();
for (int i = 0; i < nInstruments; i++) {
const SGPropertyNode * node = instrument_group->getChild(i);
SGPath path( globals->get_fg_root() );
path.append(node->getStringValue("path"));
SG_LOG(SG_INPUT, SG_DEBUG, "Reading Instrument "
<< node->getName()
<< " from "
<< path.str());
SGPropertyNode root2;
try {
readProperties(path.str(), &root2);
} catch (const sg_exception &e) {
guiErrorMessage("Error reading HUD instrument: ", e);
continue;
}
readInstrument(&root2);
}//for loop(i)
return 0;
}
// fgHUDInit
//
// Constructs a HUD object and then adds in instruments. At the present
// the instruments are hard coded into the routine. Ultimately these need
// to be defined by the aircraft's instrumentation records so that the
// display for a Piper Cub doesn't show the speed range of a North American
// mustange and the engine readouts of a B36!
//
int fgHUDInit()
{
HUD_style = 1;
SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
string hud_path =
fgGetString("/sim/hud/path", "Huds/Default/default.xml");
SGPath path(globals->get_fg_root());
path.append(hud_path);
ifstream input(path.c_str());
if (!input.good()) {
SG_LOG(SG_INPUT, SG_ALERT,
"Cannot read Hud configuration from " << path.str());
} else {
readHud(input);
input.close();
}
if ( HUDtext ) {
// this chunk of code is not necessarily thread safe if the
// compiler optimizer reorders these statements. Note that
// "delete ptr" does not set "ptr = NULL". We have to do that
// ourselves.
fntRenderer *tmp = HUDtext;
HUDtext = NULL;
delete tmp;
}
FGFontCache *fc = globals->get_fontcache();
const char* fileName = fgGetString("/sim/hud/font/name", "Helvetica.txf");
HUD_Font = fc->getTexFont(fileName);
if (!HUD_Font)
throw sg_io_exception("/sim/hud/font/name is not a texture font",
sg_location(fileName));
HUD_TextSize = fgGetFloat("/sim/hud/font/size", 10);
HUDtext = new fntRenderer();
HUDtext->setFont(HUD_Font);
HUDtext->setPointSize(HUD_TextSize);
HUD_TextList.setFont( HUDtext );
if (!HUDprop)
HUDprop = new HUD_Properties;
return 0; // For now. Later we may use this for an error code.
}
int fgHUDInit2()
{
HUD_style = 2;
SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
SGPath path(globals->get_fg_root());
path.append("Huds/Minimal/default.xml");
ifstream input(path.c_str());
if (!input.good()) {
SG_LOG(SG_INPUT, SG_ALERT,
"Cannot read Hud configuration from " << path.str());
} else {
readHud(input);
input.close();
}
if (!HUDprop)
HUDprop = new HUD_Properties;
return 0; // For now. Later we may use this for an error code.
}
//$$$ End - added, Neetha, 28 Nov 2k
// fgUpdateHUD
//
// Performs a once around the list of calls to instruments installed in
// the HUD object with requests for redraw. Kinda. It will when this is
// all C++.
//
void fgUpdateHUD( osg::State* state ) {
static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
if ( HUD_style == 1 && enable3d_node->getBoolValue() ) {
fgUpdateHUDVirtual(state);
return;
}
static const float normal_aspect = float(640) / float(480);
// note: aspect_ratio is Y/X
float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
if ( current_aspect > normal_aspect ) {
float aspect_adjust = current_aspect / normal_aspect;
float adjust = 320.0f*aspect_adjust - 320.0f;
fgUpdateHUD( state, -adjust, 0.0f, 640.0f+adjust, 480.0f );
} else {
float aspect_adjust = normal_aspect / current_aspect;
float adjust = 240.0f*aspect_adjust - 240.0f;
fgUpdateHUD( state, 0.0f, -adjust, 640.0f, 480.0f+adjust );
}
}
void fgUpdateHUDVirtual(osg::State* state)
{
using namespace osg;
FGViewer* view = globals->get_current_view();
// Standard fgfs projection, with essentially meaningless clip
// planes (we'll map the whole HUD plane to z=-1)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
Matrixf proj
= Matrixf::perspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
0.1, 10);
glLoadMatrix(proj.ptr());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Standard fgfs view direction computation
Vec3f lookat;
lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
if (fabs(lookat[1]) > 9999)
lookat[1] = 9999; // FPU sanity
Matrixf mv = Matrixf::lookAt(Vec3f(0.0, 0.0, 0.0), lookat,
Vec3f(0.0, 1.0, 0.0));
glLoadMatrix(mv.ptr());
// Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
// This is the default fgfs field of view, which the HUD files are
// written to assume.
float dx = 0.52056705; // tan(55/2)
float dy = dx * 0.75; // assumes 4:3 aspect ratio
float m[16];
m[0] = dx; m[4] = 0; m[ 8] = 0; m[12] = 0;
m[1] = 0; m[5] = dy; m[ 9] = 0; m[13] = 0;
m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0;
m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
glMultMatrixf(m);
// Convert the 640x480 "HUD standard" coordinate space to a square
// about the origin in the range [-1:1] at depth of -1
glScalef(1./320, 1./240, 1);
glTranslatef(-320, -240, -1);
// Do the deed
drawHUD(state);
// Clean up our mess
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void fgUpdateHUD( osg::State* state, GLfloat x_start, GLfloat y_start,
GLfloat x_end, GLfloat y_end )
{
using namespace osg;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
Matrixf proj = Matrixf::ortho2D(x_start, x_end, y_start, y_end);
glLoadMatrix(proj.ptr());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
drawHUD(state);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void drawHUD(osg::State* state)
{
if ( !HUD_deque.size() ) // Trust everyone, but ALWAYS cut the cards!
return;
HUD_TextList.erase();
HUD_LineList.erase();
// HUD_StippleLineList.erase();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
static const SGPropertyNode *heading_enabled
= fgGetNode("/autopilot/locks/heading", true);
static const SGPropertyNode *altitude_enabled
= fgGetNode("/autopilot/locks/altitude", true);
static char hud_hdg_text[256];
static char hud_gps_text0[256];
static char hud_gps_text1[256];
static char hud_gps_text2[256];
static char hud_alt_text[256];
glEnable(GL_BLEND);
if (HUDprop->isTransparent())
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
else
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (HUDprop->isAntialiased()) {
glEnable(GL_LINE_SMOOTH);
glAlphaFunc(GL_GREATER, HUDprop->alphaClamp());
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
//glLineWidth(1.5);
} else {
//glLineWidth(1.0);
}
HUDprop->setColor();
for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
//HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
int apY = 480 - 80;
if (strcmp( heading_enabled->getStringValue(), "dg-heading-hold") == 0 ) {
snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
fgGetDouble("/autopilot/settings/heading-bug-deg") );
HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
apY -= 15;
} else if ( strcmp(heading_enabled->getStringValue(), "true-heading-hold") == 0 ) {
snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
fgGetDouble("/autopilot/settings/true-heading-deg") );
HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
apY -= 15;
}
// GPS current waypoint information
SGPropertyNode_ptr gps = fgGetNode("/instrumentation/gps", true);
SGPropertyNode_ptr curWp = gps->getChild("wp")->getChild("wp",1);
if ((gps->getDoubleValue("raim") > 0.5) && curWp) {
// GPS is receiving a valid signal
snprintf(hud_gps_text0, 256, "WPT:%5s BRG:%03.0f %5.1fnm",
curWp->getStringValue("ID"),
curWp->getDoubleValue("bearing-mag-deg"),
curWp->getDoubleValue("distance-nm"));
HUD_TextList.add( fgText( 40, apY, hud_gps_text0 ) );
apY -= 15;
// curWp->getStringValue("TTW")
snprintf(hud_gps_text2, 256, "ETA %s", curWp->getStringValue("TTW"));
HUD_TextList.add( fgText( 40, apY, hud_gps_text2 ) );
apY -= 15;
double courseError = curWp->getDoubleValue("course-error-nm");
if (fabs(courseError) >= 0.01) {
// generate an arrow indicatinng if the pilot should turn left or right
char dir = (courseError < 0.0) ? '<' : '>';
snprintf(hud_gps_text1, 256, "GPS TRK:%03.0f XTRK:%c%4.2fnm",
gps->getDoubleValue("indicated-track-magnetic-deg"), dir, fabs(courseError));
} else { // on course, don't bother showing the XTRK error
snprintf(hud_gps_text1, 256, "GPS TRK:%03.0f",
gps->getDoubleValue("indicated-track-magnetic-deg"));
}
HUD_TextList.add( fgText( 40, apY, hud_gps_text1) );
apY -= 15;
} // of valid GPS output
////////////////////
if ( strcmp( altitude_enabled->getStringValue(), "altitude-hold" ) == 0 ) {
snprintf( hud_alt_text, 256, "alt = %.0f\n",
fgGetDouble("/autopilot/settings/target-altitude-ft") );
HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
apY -= 15;
} else if ( strcmp( altitude_enabled->getStringValue(), "agl-hold" ) == 0 ){
snprintf( hud_alt_text, 256, "agl = %.0f\n",
fgGetDouble("/autopilot/settings/target-agl-ft") );
HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
apY -= 15;
}
HUD_TextList.draw();
HUD_LineList.draw();
// glEnable(GL_LINE_STIPPLE);
// glLineStipple( 1, 0x00FF );
// HUD_StippleLineList.draw();
// glDisable(GL_LINE_STIPPLE);
if (HUDprop->isAntialiased()) {
glDisable(GL_ALPHA_TEST);
glDisable(GL_LINE_SMOOTH);
//glLineWidth(1.0);
}
if (HUDprop->isTransparent())
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
}
void fgTextList::draw()
{
if (!Font)
return;
vector<fgText>::iterator curString = List.begin();
vector<fgText>::iterator lastString = List.end();
glPushAttrib(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
if (HUDprop->isTransparent())
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
else
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (HUDprop->isAntialiased()) {
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, HUDprop->alphaClamp());
}
Font->begin();
for (; curString != lastString; curString++)
curString->Draw(Font);
Font->end();
glDisable(GL_TEXTURE_2D);
glPopAttrib();
}
// HUD property listener class
//
HUD_Properties::HUD_Properties() :
_current(fgGetNode("/sim/hud/current-color", true)),
_visibility(fgGetNode("/sim/hud/visibility", true)),
_antialiasing(fgGetNode("/sim/hud/color/antialiased", true)),
_transparency(fgGetNode("/sim/hud/color/transparent", true)),
_red(fgGetNode("/sim/hud/color/red", true)),
_green(fgGetNode("/sim/hud/color/green", true)),
_blue(fgGetNode("/sim/hud/color/blue", true)),
_alpha(fgGetNode("/sim/hud/color/alpha", true)),
_alpha_clamp(fgGetNode("/sim/hud/color/alpha-clamp", true)),
_brightness(fgGetNode("/sim/hud/color/brightness", true)),
_visible(false),
_antialiased(false),
_transparent(false),
_a(0.67),
_cl(0.01)
{
_visibility->addChangeListener(this);
_antialiasing->addChangeListener(this);
_transparency->addChangeListener(this);
_red->addChangeListener(this);
_green->addChangeListener(this);
_blue->addChangeListener(this);
_alpha->addChangeListener(this);
_alpha_clamp->addChangeListener(this);
_brightness->addChangeListener(this);
_current->addChangeListener(this, true);
}
void HUD_Properties::valueChanged(SGPropertyNode *node)
{
if (!strcmp(node->getName(), "current-color")) {
int i = node->getIntValue();
if (i < 0)
i = 0;
SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
if ((n = n->getChild("color", i, false))) {
if (n->hasValue("red"))
_red->setFloatValue(n->getFloatValue("red", 1.0));
if (n->hasValue("green"))
_green->setFloatValue(n->getFloatValue("green", 1.0));
if (n->hasValue("blue"))
_blue->setFloatValue(n->getFloatValue("blue", 1.0));
if (n->hasValue("alpha"))
_alpha->setFloatValue(n->getFloatValue("alpha", 0.67));
if (n->hasValue("alpha-clamp"))
_alpha_clamp->setFloatValue(n->getFloatValue("alpha-clamp", 0.01));
if (n->hasValue("brightness"))
_brightness->setFloatValue(n->getFloatValue("brightness", 0.75));
if (n->hasValue("antialiased"))
_antialiasing->setBoolValue(n->getBoolValue("antialiased", false));
if (n->hasValue("transparent"))
_transparency->setBoolValue(n->getBoolValue("transparent", false));
}
}
_visible = _visibility->getBoolValue();
_transparent = _transparency->getBoolValue();
_antialiased = _antialiasing->getBoolValue();
float brt = _brightness->getFloatValue();
_r = clamp(brt * _red->getFloatValue());
_g = clamp(brt * _green->getFloatValue());
_b = clamp(brt * _blue->getFloatValue());
_a = clamp(_alpha->getFloatValue());
_cl = clamp(_alpha_clamp->getFloatValue());
}
void HUD_Properties::setColor() const
{
if (_antialiased)
glColor4f(_r, _g, _b, _a);
else
glColor3f(_r, _g, _b);
}

View file

@ -1,730 +0,0 @@
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef _OLDHUD_HXX
#define _OLDHUD_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/compiler.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef __CYGWIN__
#include <ieeefp.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <algorithm> // for_each()
#include <vector> // STL vector
#include <deque> // STL double ended queue
#include <fstream>
namespace osg {
class State;
}
#include <simgear/math/SGMath.hxx>
#include <simgear/constants.h>
#include <Include/fg_typedefs.h>
#include <Aircraft/controls.hxx>
#include <FDM/flight.hxx>
#include <GUI/gui.h>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Main/viewmgr.hxx>
class FGRunway;
using std::deque;
using std::vector;
#define float_to_int(v) SGMiscf::roundToInt(v)
// some of Norman's crazy optimizations. :-)
#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 };
// Label constants
#define HUD_FONT_SMALL 1
#define HUD_FONT_LARGE 2
enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
#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
// in cockpit.cxx
extern float get_throttleval ( void );
extern float get_aileronval ( void );
extern float get_elevatorval ( void );
extern float get_elev_trimval( void );
extern float get_rudderval ( void );
extern float get_speed ( void );
extern float get_aoa ( void );
extern float get_nlf ( void );
extern float get_roll ( void );
extern float get_pitch ( void );
extern float get_heading ( void );
extern float get_view_direction( void );
extern float get_altitude ( void );
extern float get_agl ( void );
extern float get_sideslip ( void );
extern float get_frame_rate ( void );
extern float get_latitude ( void );
extern float get_lat_min ( void );
extern float get_longitude ( void );
extern float get_long_min ( void );
extern float get_fov ( void );
extern float get_vfc_ratio ( void );
extern float get_vfc_tris_drawn ( void );
extern float get_vfc_tris_culled ( void );
extern float get_climb_rate ( void );
extern float get_mach( void );
extern char *coord_format_lat(float);
extern char *coord_format_lon(float);
extern char *get_formated_gmt_time( void );
enum hudinstype{ HUDno_instr,
HUDscale,
HUDlabel,
HUDladder,
HUDcirc_ladder,
HUDhorizon,
HUDgauge,
HUDdual_inst,
HUDmoving_scale,
HUDtbi
};
typedef struct gltagRGBTRIPLE { // rgbt
GLfloat Blue;
GLfloat Green;
GLfloat Red;
} glRGBTRIPLE;
class fgLineSeg2D {
private:
GLfloat x0, y0, x1, y1;
public:
fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
: x0(a), y0(b), x1(c), y1(d) {}
fgLineSeg2D( const fgLineSeg2D & image )
: x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
fgLineSeg2D& operator= ( const fgLineSeg2D & image ) { // seems unused
x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
}
void draw() const
{
glVertex2f(x0, y0);
glVertex2f(x1, y1);
}
};
class DrawLineSeg2D {
public:
void operator() (const fgLineSeg2D& elem) const {
elem.draw();
}
};
#define USE_HUD_TextList
extern fntTexFont *HUD_Font;
extern float HUD_TextSize;
extern fntRenderer *HUDtext;
extern float HUD_matrix[16];
class fgText {
private:
float x, y;
string msg;
bool digit;
// seems unused
public:
fgText(float x, float y, const string& c, bool digits=false): x(x), y(y), msg( c), digit( digits) {};
fgText( const fgText & image )
: x(image.x), y(image.y), msg(image.msg), digit(image.digit) { }
fgText& operator = ( const fgText & image ) {
x = image.x; y = image.y; msg= image.msg; digit = image.digit;
return *this;
}
static int getStringWidth ( const char *str )
{
if ( HUDtext && str ) {
float r, l ;
HUD_Font->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
return float_to_int( r - l );
}
return 0 ;
}
int StringWidth ()
{
if ( HUDtext && msg != "") {
float r, l ;
HUD_Font->getBBox ( msg.c_str(), HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
return float_to_int( r - l );
}
return 0 ;
}
// this code is changed to display Numbers with big/small digits
// according to MIL Standards for example Altitude above 10000 ft
// is shown as 10ooo.
void Draw(fntRenderer *fnt) {
if (digit) {
int c=0;
int p=4;
if (msg[0]=='-') {
//if negative value then increase the c and p values
//for '-' sign. c++;
p++;
}
for (string::size_type i = 0; i < msg.size(); i++) {
if ((msg[i]>='0') && (msg[i]<='9'))
c++;
}
float orig_size = fnt->getPointSize();
if (c>p) {
fnt->setPointSize(HUD_TextSize * 0.8);
int p2=(c-3)*8; //advance to the last 3 digits
fnt->start2f(x+p2,y);
fnt->puts(msg.c_str() + c - 3); // display last 3 digits
fnt->setPointSize(HUD_TextSize * 1.2);
fnt->start2f(x,y);
fnt->puts(msg.substr(0,c-3).c_str());
} else {
fnt->setPointSize(HUD_TextSize * 1.2);
fnt->start2f( x, y );
fnt->puts(msg.c_str());
}
fnt->setPointSize(orig_size);
} else {
//if digits not true
fnt->start2f( x, y );
fnt->puts( msg.c_str()) ;
}
}
void Draw()
{
guiFnt.drawString( msg.c_str(), float_to_int(x), float_to_int(y) );
}
};
class fgLineList {
vector < fgLineSeg2D > List;
public:
fgLineList( void ) {}
void add( const fgLineSeg2D& seg ) { List.push_back(seg); }
void erase( void ) { List.clear();}
void draw( void ) {
glBegin(GL_LINES);
for_each( List.begin(), List.end(), DrawLineSeg2D());
glEnd();
}
};
class fgTextList {
fntRenderer *Font;
vector< fgText > List;
public:
fgTextList ( void ) { Font = 0; }
void setFont( fntRenderer *Renderer ) { Font = Renderer; }
void add( const fgText& String ) { List.push_back(String); }
void erase( void ) { List.clear(); }
void draw( void );
};
inline void Text( fgTextList &List, float x, float y, char *s)
{
List.add( fgText( x, y, s) );
}
inline void Text( fgTextList &List, const fgText &me)
{
List.add(me);
}
inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
{
List.add(fgLineSeg2D(x1,y1,x2,y2));
}
// Declare our externals
extern fgTextList HUD_TextList;
extern fgLineList HUD_LineList;
extern fgLineList HUD_StippleLineList;
class instr_item : public SGReferenced { // 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.
FLTFNPTR load_value_fn;
float 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; //
int digits;
public:
instr_item( int x,
int y,
UINT height,
UINT width,
FLTFNPTR data_source,
float data_scaling,
UINT options,
bool working = true,
int digit = 0);
virtual ~instr_item ();
void set_data_source ( FLTFNPTR fn ) { load_value_fn = fn; }
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; }
float get_value ( void ) { return load_value_fn(); }
float 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; }
int get_digits ( void ) { return digits; }
inline int get_x() const { return scrn_pos.left; }
inline int get_y() const { return scrn_pos.top; }
inline int get_width() const { return scrn_pos.right; }
inline int get_height() const { return scrn_pos.bottom; }
UINT huds_vert (UINT options) { return (options & HUDS_VERT); }
UINT huds_left (UINT options) { return (options & HUDS_LEFT); }
UINT huds_right (UINT options) { return (options & HUDS_RIGHT); }
UINT huds_both (UINT options) {
return ((options & HUDS_BOTH) == HUDS_BOTH);
}
UINT huds_noticks (UINT options) { return (options & HUDS_NOTICKS); }
UINT huds_notext (UINT options) { return (options & HUDS_NOTEXT); }
UINT huds_top (UINT options) { return (options & HUDS_TOP); }
UINT huds_bottom (UINT options) { return (options & HUDS_BOTTOM); }
virtual void display_enable( bool working ) { is_enabled = working;}
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
void drawOneLine( float x1, float y1, float x2, float y2)
{
HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
}
void drawOneStippleLine( float x1, float y1, float x2, float y2)
{
HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
}
void TextString( char *msg, float x, float y, bool digit )
{
HUD_TextList.add(fgText(x, y, msg,digit));
}
int getStringWidth ( char *str )
{
if ( HUDtext && str ) {
float r, l ;
HUD_Font->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
return float_to_int( r - l );
}
return 0 ;
}
};
typedef instr_item *HIptr;
class HUDdraw {
public:
void operator() (HIptr elem) const {
if ( elem->enabled())
elem->draw();
}
};
extern int HUD_style;
// 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;
fgLabelJust justify;
int fontSize;
int blink;
string format_buffer;
bool lat;
bool lon;
bool lbox;
SGPropertyNode_ptr lon_node;
SGPropertyNode_ptr lat_node;
public:
instr_label(const SGPropertyNode *);
virtual void draw(void);
};
//
// fgRunway_instr This class is responsible for rendering the active runway
// in the hud (if visible).
class runway_instr : public instr_item {
private:
void boundPoint(const sgdVec3& v, sgdVec3& m);
bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
bool drawLine(const sgdVec3& a1, const sgdVec3& a2,
const sgdVec3& p1, const sgdVec3& p2);
void drawArrow();
FGRunway* get_active_runway();
void get_rwy_points(sgdVec3 *points);
void setLineWidth(void);
sgdVec3 points3d[6], points2d[6];
double mm[16],pm[16], arrowScale, arrowRad, lnScale;
double scaleDist, default_pitch, default_heading;
GLint view[4];
FGRunway* runway;
FGViewer* cockpit_view;
unsigned short stippleOut, stippleCen;
bool drawIA, drawIAAlways;
RECT location;
POINT center;
public:
runway_instr(const SGPropertyNode *);
virtual void draw( void );
void setArrowRotationRadius(double radius);
// Scales the runway indication arrow
void setArrowScale(double scale);
// Draws arrow when runway is not visible in HUD if draw=true
void setDrawArrow(bool draw);
// Always draws arrow if draw=true;
void setDrawArrowAlways(bool draw);
// Sets the maximum line scale
void setLineScale(double scale);
// Sets the distance where to start scaling the lines
void setScaleDist(double dist_nm);
// Sets the stipple pattern of the outline of the runway
void setStippleOutline(unsigned short stipple);
// Sets the stipple patter of the center line of the runway
void setStippleCenterline(unsigned short stipple);
};
//
// 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:
float range_shown; // Width Units.
float Maximum_value; // ceiling.
float Minimum_value; // Representation floor.
float 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,
FLTFNPTR load_fn,
UINT options,
float show_range,
float max_value,
float min_value,
float disp_scaling,
UINT major_divs,
UINT minor_divs,
UINT rollover,
int dp_showing,
bool working = true);
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;}
float min_val ( void ) { return Minimum_value;}
float max_val ( void ) { return Maximum_value;}
UINT modulo ( void ) { return Modulo; }
float factor ( void ) { return scale_factor;}
float 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:
float val_span;
string type;
float half_width_units;
bool draw_tick_bottom;
bool draw_tick_top;
bool draw_tick_right;
bool draw_tick_left;
bool draw_cap_bottom;
bool draw_cap_top;
bool draw_cap_right;
bool draw_cap_left;
float marker_offset;
bool pointer;
string pointer_type;
string tick_type;
string tick_length;
float radius;
float maxValue;
float minValue;
int divisions;
int zoom;
UINT Maj_div;
UINT Min_div;
public:
hud_card(const SGPropertyNode *);
// virtual void display_enable( bool setting ); // FIXME
virtual void draw(void);
void circles(float, float, float);
void fixed(float, float, float, float, float, float);
void zoomed_scale(int, int);
};
class gauge_instr : public instr_scale {
public:
gauge_instr(const SGPropertyNode *);
virtual void draw( void ); // Required method in base class
};
//
// 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:
FLTFNPTR alt_data_source;
public:
dual_instr_item ( int x,
int y,
UINT width,
UINT height,
FLTFNPTR chn1_source,
FLTFNPTR chn2_source,
bool working,
UINT options );
float current_ch1( void ) { return (float)alt_data_source(); }
float current_ch2( void ) { return (float)get_value(); }
virtual void draw( void ) {}
};
class fgTBI_instr : public dual_instr_item {
private:
UINT BankLimit;
UINT SlewLimit;
UINT scr_hole;
bool tsi;
float rad;
public:
fgTBI_instr(const SGPropertyNode *);
UINT bank_limit(void) { return BankLimit; }
UINT slew_limit(void) { return SlewLimit; }
virtual void draw(void);
};
class HudLadder : public dual_instr_item {
private:
UINT width_units;
int div_units;
UINT minor_div;
UINT label_pos;
UINT scr_hole;
float vmax;
float vmin;
float factor;
string hudladder_type;
bool frl;
bool target_spot;
bool velocity_vector;
bool drift_marker;
bool alpha_bracket;
bool energy_marker;
bool climb_dive_marker;
bool glide_slope_marker;
float glide_slope;
bool energy_worm;
bool waypoint_marker;
int zenith;
int nadir;
int hat;
// The Ladder has it's own temporary display lists
fgTextList TextList;
fgLineList LineList;
fgLineList StippleLineList;
public:
HudLadder(const SGPropertyNode *);
virtual void draw(void);
void drawZenith(float, float, float);
void drawNadir(float, float, float);
void Text(float x, float y, char *s)
{
TextList.add(fgText(x, y, s));
}
void Line(float x1, float y1, float x2, float y2)
{
LineList.add(fgLineSeg2D(x1, y1, x2, y2));
}
void StippleLine(float x1, float y1, float x2, float y2)
{
StippleLineList.add(fgLineSeg2D(x1, y1, x2, y2));
}
};
extern int fgHUDInit();
extern int fgHUDInit2();
extern void fgUpdateHUD( osg::State* );
extern void fgUpdateHUD( osg::State*, GLfloat x_start, GLfloat y_start,
GLfloat x_end, GLfloat y_end );
class HUD_Properties : public SGPropertyChangeListener {
public:
HUD_Properties();
void valueChanged(SGPropertyNode *n);
void setColor() const;
bool isVisible() const { return _visible; }
bool isAntialiased() const { return _antialiased; }
bool isTransparent() const { return _transparent; }
float alphaClamp() const { return _cl; }
private:
float clamp(float f) { return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f; }
SGPropertyNode_ptr _current;
SGPropertyNode_ptr _visibility;
SGPropertyNode_ptr _antialiasing;
SGPropertyNode_ptr _transparency;
SGPropertyNode_ptr _red, _green, _blue, _alpha;
SGPropertyNode_ptr _alpha_clamp;
SGPropertyNode_ptr _brightness;
bool _visible;
bool _antialiased;
bool _transparent;
float _r, _g, _b, _a, _cl;
};
#endif // _OLDHUD_H

File diff suppressed because it is too large Load diff

View file

@ -1,19 +0,0 @@
#include "hud.hxx"
dual_instr_item::dual_instr_item(
int x,
int y,
UINT width,
UINT height,
FLTFNPTR chn1_source,
FLTFNPTR chn2_source,
bool working,
UINT options) :
instr_item(x, y, width, height,
chn1_source, 1, options, working),
alt_data_source(chn2_source)
{
}

View file

@ -1,293 +0,0 @@
#include "hud.hxx"
#ifdef USE_HUD_TextList
#define textString(x, y, text, digit) TextString(text, x , y ,digit)
#else
#define textString(x, y, text, digit) puDrawString(guiFnt, text, x, y)
#endif
FLTFNPTR get_func(const char *name); // FIXME
gauge_instr::gauge_instr(const SGPropertyNode *node) :
instr_scale(
node->getIntValue("x"),
node->getIntValue("y"),
node->getIntValue("width"),
node->getIntValue("height"),
0 /*load_fn*/,
node->getIntValue("options"),
node->getFloatValue("maxValue") - node->getFloatValue("minValue"), // Always shows span?
node->getFloatValue("maxValue"),
node->getFloatValue("minValue"),
node->getFloatValue("disp_scaling"),
node->getIntValue("major_divs"),
node->getIntValue("minor_divs"),
node->getIntValue("modulator"), // "rollover"
0, /* hud.cxx: static int dp_shoing = 0; */ // FIXME
node->getBoolValue("working", true))
{
SG_LOG(SG_INPUT, SG_BULK, "Done reading gauge instrument "
<< node->getStringValue("name", "[unnamed]"));
set_data_source(get_func(node->getStringValue("loadfn")));
}
// 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 gauge_instr::draw(void)
{
float marker_xs, marker_xe;
float marker_ys, marker_ye;
int text_x, text_y;
int width, height, bottom_4;
int lenstr;
int i;
char TextScale[80];
bool condition;
int disp_val = 0;
float vmin = min_val();
float vmax = max_val();
POINT mid_scr = get_centroid();
float cur_value = get_value();
RECT scrn_rect = get_location();
UINT options = get_options();
width = scrn_rect.left + scrn_rect.right;
height = scrn_rect.top + scrn_rect.bottom;
bottom_4 = scrn_rect.bottom / 4;
// Draw the basic markings for the scale...
if (huds_vert(options)) { // Vertical scale
// Bottom tick bar
drawOneLine(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
// Top tick bar
drawOneLine( scrn_rect.left, height, width, height);
marker_xs = scrn_rect.left;
marker_xe = width;
if (huds_left(options)) { // Read left, so line down right side
drawOneLine(width, scrn_rect.top, width, height);
marker_xs = marker_xe - scrn_rect.right / 3.0; // Adjust tick
}
if (huds_right(options)) { // Read right, so down left sides
drawOneLine(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
marker_xe = scrn_rect.left + scrn_rect.right / 3.0; // Adjust tick
}
// At this point marker x_start and x_end values are transposed.
// To keep this from confusing things they are now interchanged.
if (huds_both(options)) {
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 (!huds_noticks(options)) { // If not no ticks...:)
// Calculate x marker offsets
int last = (int)vmax + 1; // float_to_int(vmax)+1;
i = (int)vmin; //float_to_int(vmin);
for (; i < last; i++) {
// Calculate the location of this tick
marker_ys = scrn_rect.top + (i - vmin) * factor()/* +.5f*/;
// 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 % (int)div_min())) {
if (huds_left(options) && huds_right(options)) {
drawOneLine(scrn_rect.left, marker_ys, marker_xs - 3, marker_ys);
drawOneLine(marker_xe + 3, marker_ys, width, marker_ys);
} else if (huds_left(options)) {
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 % (int)div_max())) {
if (huds_left(options) && huds_right(options)) {
drawOneLine(scrn_rect.left, marker_ys, marker_xs, marker_ys);
drawOneLine(marker_xe, marker_ys, width, marker_ys);
} else {
drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
}
if (!huds_notext(options)) {
disp_val = i;
sprintf(TextScale, "%d",
float_to_int(disp_val * data_scaling()/*+.5*/));
lenstr = getStringWidth(TextScale);
if (huds_left(options) && huds_right(options)) {
text_x = mid_scr.x - lenstr/2 ;
} else if (huds_left(options)) {
text_x = float_to_int(marker_xs - lenstr);
} else {
text_x = float_to_int(marker_xe - lenstr);
}
// Now we know where to put the text.
text_y = float_to_int(marker_ys);
textString(text_x, text_y, TextScale, 0);
}
}
}
}
}
// 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 + float_to_int((cur_value - vmin) * factor() /*+.5f*/);
// text_x = marker_xs - scrn_rect.left;
if (huds_right(options)) {
glBegin(GL_LINE_STRIP);
glVertex2f(scrn_rect.left, text_y + 5);
glVertex2f(float_to_int(marker_xe), text_y);
glVertex2f(scrn_rect.left, text_y - 5);
glEnd();
}
if (huds_left(options)) {
glBegin(GL_LINE_STRIP);
glVertex2f(width, text_y + 5);
glVertex2f(float_to_int(marker_xs), text_y);
glVertex2f(width, text_y - 5);
glEnd();
}
// End if VERTICAL SCALE TYPE
} else { // Horizontal scale by default
// left tick bar
drawOneLine(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
// right tick bar
drawOneLine(width, scrn_rect.top, width, height );
marker_ys = scrn_rect.top; // Starting point for
marker_ye = height; // tick y location calcs
marker_xs = scrn_rect.left + (cur_value - vmin) * factor() /*+ .5f*/;
if (huds_top(options)) {
// Bottom box line
drawOneLine(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
marker_ye = scrn_rect.top + scrn_rect.bottom / 2.0; // Tick point adjust
// Bottom arrow
glBegin(GL_LINE_STRIP);
glVertex2f(marker_xs - bottom_4, scrn_rect.top);
glVertex2f(marker_xs, marker_ye);
glVertex2f(marker_xs + bottom_4, scrn_rect.top);
glEnd();
}
if (huds_bottom(options)) {
// Top box line
drawOneLine(scrn_rect.left, height, width, height);
// Tick point adjust
marker_ys = height - scrn_rect.bottom / 2.0;
// Top arrow
glBegin(GL_LINE_STRIP);
glVertex2f(marker_xs + bottom_4, height);
glVertex2f(marker_xs, marker_ys );
glVertex2f(marker_xs - bottom_4, height);
glEnd();
}
int last = (int)vmax + 1; //float_to_int(vmax)+1;
i = (int)vmin; //float_to_int(vmin);
for (; i <last ; i++) {
condition = true;
if (!modulo() && i < min_val())
condition = false;
if (condition) {
marker_xs = scrn_rect.left + (i - vmin) * factor()/* +.5f*/;
// marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
if (div_min()) {
if (!(i % (int)div_min())) {
// draw in ticks only if they aren't too close to the edge.
if (((marker_xs + 5) > scrn_rect.left)
|| ((marker_xs - 5) < (width))) {
if (huds_both(options)) {
drawOneLine(marker_xs, scrn_rect.top, marker_xs, marker_ys - 4);
drawOneLine(marker_xs, marker_ye + 4, marker_xs, height);
} else if (huds_top(options)) {
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())) {
if (modulo()) {
if (disp_val < 0) {
while (disp_val < 0)
disp_val += modulo();
}
disp_val = i % (int)modulo();
} else {
disp_val = i;
}
sprintf(TextScale, "%d",
float_to_int(disp_val * data_scaling()/* +.5*/));
lenstr = getStringWidth(TextScale);
// Draw major ticks and text only if far enough from the edge.
if (((marker_xs - 10) > scrn_rect.left)
&& ((marker_xs + 10) < width)) {
if (huds_both(options)) {
drawOneLine(marker_xs, scrn_rect.top, marker_xs, marker_ys);
drawOneLine(marker_xs, marker_ye, marker_xs, height);
if (!huds_notext(options))
textString(marker_xs - lenstr, marker_ys + 4, TextScale, 0);
} else {
drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
if (!huds_notext(options)) {
if (huds_top(options))
textString(marker_xs - lenstr, height - 10, TextScale, 0);
else
textString(marker_xs - lenstr, scrn_rect.top, TextScale, 0);
}
}
}
}
}
}
}
}
}

View file

@ -1,93 +0,0 @@
#include "hud.hxx"
UINT instr_item :: instances = 0; // Initial value of zero
int instr_item :: brightness = 5;/*HUD_BRT_MEDIUM*/
//glRGBTRIPLE instr_item :: color = {0.1, 0.7, 0.0};
glRGBTRIPLE instr_item :: color = {0.0, 1.0, 0.0};
// constructor ( No default provided )
instr_item::instr_item(
int x,
int y,
UINT width,
UINT height,
FLTFNPTR data_source,
float data_scaling,
UINT options,
bool working,
int digit) :
handle ( ++instances ),
load_value_fn ( data_source ),
disp_factor ( data_scaling ),
opts ( options ),
is_enabled ( working ),
broken ( FALSE ),
digits ( digit )
{
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);
}
instr_item::~instr_item ()
{
if (instances)
instances--;
}
// 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;
}

View file

@ -1,145 +0,0 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "hud.hxx"
#ifdef USE_HUD_TextList
#define textString(x, y, text, digit) TextString(text, x , y ,digit)
#else
#define textString(x, y, text, digit) puDrawString(guiFnt, text, x, y)
#endif
FLTFNPTR get_func(const char *name); // FIXME
instr_label::instr_label(const SGPropertyNode *node) :
instr_item(
node->getIntValue("x"),
node->getIntValue("y"),
node->getIntValue("width"),
node->getIntValue("height"),
NULL /* node->getStringValue("data_source") */, // FIXME
node->getFloatValue("scale_data"),
node->getIntValue("options"),
node->getBoolValue("working", true),
node->getIntValue("digits")),
pformat(node->getStringValue("label_format")),
fontSize(fgGetInt("/sim/startup/xsize") > 1000 ? HUD_FONT_LARGE : HUD_FONT_SMALL), // FIXME
blink(node->getIntValue("blinking")),
lat(node->getBoolValue("latitude", false)),
lon(node->getBoolValue("longitude", false)),
lbox(node->getBoolValue("label_box", false)),
lon_node(fgGetNode("/position/longitude-string", true)),
lat_node(fgGetNode("/position/latitude-string", true))
{
SG_LOG(SG_INPUT, SG_BULK, "Done reading instr_label instrument "
<< node->getStringValue("name", "[unnamed]"));
set_data_source(get_func(node->getStringValue("data_source")));
int just = node->getIntValue("justification");
if (just == 0)
justify = LEFT_JUST;
else if (just == 1)
justify = CENTER_JUST;
else if (just == 2)
justify = RIGHT_JUST;
string pre_str(node->getStringValue("pre_label_string"));
if (pre_str== "NULL")
pre_str.clear();
else if (pre_str == "blank")
pre_str = " ";
const char *units = strcmp(fgGetString("/sim/startup/units"), "feet") ? " m" : " ft"; // FIXME
string post_str(node->getStringValue("post_label_string"));
if (post_str== "NULL")
post_str.clear();
else if (post_str == "blank")
post_str = " ";
else if (post_str == "units")
post_str = units;
format_buffer = pre_str + pformat;
format_buffer += post_str;
}
void instr_label::draw(void)
{
char label_buffer[80];
int posincr;
int lenstr;
RECT scrn_rect = get_location();
memset( label_buffer, 0, sizeof( label_buffer));
if (data_available()) {
if (lat)
snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), lat_node->getStringValue());
else if (lon)
snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), lon_node->getStringValue());
else {
if (lbox) {// Box for label
float x = scrn_rect.left;
float y = scrn_rect.top;
float w = scrn_rect.right;
float h = HUD_TextSize;
glPushMatrix();
glLoadIdentity();
glBegin(GL_LINES);
glVertex2f(x - 2.0, y - 2.0);
glVertex2f(x + w + 2.0, y - 2.0);
glVertex2f(x + w + 2.0, y + h + 2.0);
glVertex2f(x - 2.0, y + h + 2.0);
glEnd();
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0xAAAA);
glBegin(GL_LINES);
glVertex2f(x + w + 2.0, y - 2.0);
glVertex2f(x + w + 2.0, y + h + 2.0);
glVertex2f(x - 2.0, y + h + 2.0);
glVertex2f(x - 2.0, y - 2.0);
glEnd();
glDisable(GL_LINE_STIPPLE);
glPopMatrix();
}
snprintf(label_buffer, sizeof(label_buffer)-1, format_buffer.c_str(), get_value() * data_scaling());
}
} else {
snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), 0);
}
lenstr = getStringWidth(label_buffer);
#ifdef DEBUGHUD
fgPrintf( SG_COCKPIT, SG_DEBUG, format_buffer);
fgPrintf( SG_COCKPIT, SG_DEBUG, "\n");
fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer);
fgPrintf( SG_COCKPIT, SG_DEBUG, "\n");
#endif
lenstr = strlen(label_buffer);
if (justify == RIGHT_JUST)
posincr = scrn_rect.right - lenstr;
else if (justify == CENTER_JUST)
posincr = get_span() - (lenstr / 2); // -lenstr*4;
else // justify == LEFT_JUST
posincr = 0;
if (fontSize == HUD_FONT_SMALL) {
textString(scrn_rect.left + posincr, scrn_rect.top,
label_buffer, get_digits());
} else if (fontSize == HUD_FONT_LARGE) {
textString(scrn_rect.left + posincr, scrn_rect.top,
label_buffer, get_digits());
}
}

View file

@ -1,785 +0,0 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <simgear/constants.h>
#include "hud.hxx"
#include "panel.hxx"
#include <Main/viewer.hxx>
// FIXME
extern float get_roll(void);
extern float get_pitch(void);
HudLadder::HudLadder(const SGPropertyNode *node) :
dual_instr_item(
node->getIntValue("x"),
node->getIntValue("y"),
node->getIntValue("width"),
node->getIntValue("height"),
get_roll,
get_pitch, // FIXME getter functions from cockpit.cxx
node->getBoolValue("working", true),
HUDS_RIGHT),
width_units(int(node->getFloatValue("span_units"))),
div_units(int(fabs(node->getFloatValue("division_units")))),
minor_div(0 /* hud.cxx: static float minor_division = 0 */),
label_pos(node->getIntValue("lbl_pos")),
scr_hole(node->getIntValue("screen_hole")),
factor(node->getFloatValue("compression_factor")),
hudladder_type(node->getStringValue("name")),
frl(node->getBoolValue("enable_frl", false)),
target_spot(node->getBoolValue("enable_target_spot", false)),
velocity_vector(node->getBoolValue("enable_velocity_vector", false)),
drift_marker(node->getBoolValue("enable_drift_marker", false)),
alpha_bracket(node->getBoolValue("enable_alpha_bracket", false)),
energy_marker(node->getBoolValue("enable_energy_marker", false)),
climb_dive_marker(node->getBoolValue("enable_climb_dive_marker", false)),
glide_slope_marker(node->getBoolValue("enable_glide_slope_marker",false)),
glide_slope(node->getFloatValue("glide_slope", -4.0)),
energy_worm(node->getBoolValue("enable_energy_marker", false)),
waypoint_marker(node->getBoolValue("enable_waypoint_marker", false)),
zenith(node->getIntValue("zenith")),
nadir(node->getIntValue("nadir")),
hat(node->getIntValue("hat"))
{
// The factor assumes a base of 55 degrees per 640 pixels.
// Invert to convert the "compression" factor to a
// pixels-per-degree number.
if (fgGetBool("/sim/hud/enable3d", true) && HUD_style == 1)
factor = 640.0 / 55.0;
SG_LOG(SG_INPUT, SG_BULK, "Done reading HudLadder instrument"
<< node->getStringValue("name", "[unnamed]"));
if (!width_units)
width_units = 45;
vmax = width_units / 2;
vmin = -vmax;
}
//
// Draws a climb ladder in the center of the HUD
//
void HudLadder::draw(void)
{
float x_ini, x_ini2;
float x_end, x_end2;
float y = 0;
int count;
float cosine, sine, xvvr, yvvr, Vxx = 0.0, Vyy = 0.0, Vzz = 0.0;
float up_vel, ground_vel, actslope = 0.0;
float Axx = 0.0, Ayy = 0.0, Azz = 0.0, total_vel = 0.0, pot_slope, t1;
float t2 = 0.0, psi = 0.0, alpha, pla;
float vel_x = 0.0, vel_y = 0.0, drift;
bool pitch_ladder = false;
bool climb_dive_ladder = false;
bool clip_plane = false;
GLdouble eqn_top[4] = {0.0, -1.0, 0.0, 0.0};
GLdouble eqn_left[4] = {-1.0, 0.0, 0.0, 100.0};
GLdouble eqn_right[4] = {1.0, 0.0, 0.0, 100.0};
POINT centroid = get_centroid();
RECT box = get_location();
float half_span = box.right / 2.0;
float roll_value = current_ch2();
alpha = get_aoa();
pla = get_throttleval();
#ifdef ENABLE_SP_FDM
int lgear, wown, wowm, ilcanclaw, ihook;
ilcanclaw = fgGetInt("/fdm-ada/iaux2", 0);
lgear = fgGetInt("/fdm-ada/iaux3", 0);
wown = fgGetInt("/fdm-ada/iaux4", 0);
wowm = fgGetInt("/fdm-ada/iaux5", 0);;
ihook = fgGetInt("/fdm-ada/iaux6", 0);
#endif
float pitch_value = current_ch1() * SGD_RADIANS_TO_DEGREES;
if (hudladder_type == "Climb/Dive Ladder") {
pitch_ladder = false;
climb_dive_ladder = true;
clip_plane = true;
} else { // hudladder_type == "Pitch Ladder"
pitch_ladder = true;
climb_dive_ladder = false;
clip_plane = false;
}
//**************************************************************
glPushMatrix();
// define (0, 0) as center of screen
glTranslatef(centroid.x, centroid.y, 0);
// OBJECT STATIC RETICLE
// TYPE FRL
// ATTRIB - ALWAYS
// Draw the FRL spot and line
if (frl) {
#define FRL_DIAMOND_SIZE 2.0
glBegin(GL_LINE_LOOP);
glVertex2f(-FRL_DIAMOND_SIZE, 0.0);
glVertex2f(0.0, FRL_DIAMOND_SIZE);
glVertex2f(FRL_DIAMOND_SIZE, 0.0);
glVertex2f(0.0, -FRL_DIAMOND_SIZE);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(0, FRL_DIAMOND_SIZE);
glVertex2f(0, 8.0);
glEnd();
#undef FRL_DIAMOND_SIZE
}
// TYPE WATERLINE_MARK (W shaped _ _ )
// \/\/
//****************************************************************
// TYPE TARGET_SPOT
// Draw the target spot.
if (target_spot) {
#define CENTER_DIAMOND_SIZE 6.0
glBegin(GL_LINE_LOOP);
glVertex2f(-CENTER_DIAMOND_SIZE, 0.0);
glVertex2f(0.0, CENTER_DIAMOND_SIZE);
glVertex2f(CENTER_DIAMOND_SIZE, 0.0);
glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
glEnd();
#undef CENTER_DIAMOND_SIZE
}
//****************************************************************
//velocity vector reticle - computations
if (velocity_vector) {
Vxx = fgGetDouble("/velocities/north-relground-fps", 0.0);
Vyy = fgGetDouble("/velocities/east-relground-fps", 0.0);
Vzz = fgGetDouble("/velocities/down-relground-fps", 0.0);
Axx = fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
Ayy = fgGetDouble("/accelerations/ned/east-accel-fps_sec", 0.0);
Azz = fgGetDouble("/accelerations/ned/down-accel-fps_sec", 0.0);
psi = get_heading();
if (psi > 180.0)
psi = psi - 360;
total_vel = sqrt(Vxx * Vxx + Vyy * Vyy + Vzz * Vzz);
ground_vel = sqrt(Vxx * Vxx + Vyy * Vyy);
up_vel = Vzz;
if (ground_vel < 2.0) {
if (fabs(up_vel) < 2.0)
actslope = 0.0;
else
actslope = (up_vel / fabs(up_vel)) * 90.0;
} else {
actslope = atan(up_vel / ground_vel) * SGD_RADIANS_TO_DEGREES;
}
xvvr = (((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi)
* (factor / globals->get_current_view()->get_aspect_ratio()));
drift = ((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi);
yvvr = ((actslope - pitch_value) * factor);
vel_y = ((actslope - pitch_value) * cos(roll_value) + drift * sin(roll_value)) * factor;
vel_x = (-(actslope - pitch_value) * sin(roll_value) + drift * cos(roll_value))
* (factor/globals->get_current_view()->get_aspect_ratio());
// printf("%f %f %f %f\n",vel_x, vel_y, drift, psi);
//****************************************************************
// OBJECT MOVING RETICLE
// TYPE - DRIFT MARKER
// ATTRIB - ALWAYS
// drift marker
if (drift_marker) {
glBegin(GL_LINE_STRIP);
glVertex2f((xvvr * 25 / 120) - 6, -4);
glVertex2f(xvvr * 25 / 120, 8);
glVertex2f((xvvr * 25 / 120) + 6, -4);
glEnd();
}
//****************************************************************
// Clipping coordinates for ladder to be input from xml file
// Clip hud ladder
if (clip_plane) {
glClipPlane(GL_CLIP_PLANE0, eqn_top);
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE1, eqn_left);
glEnable(GL_CLIP_PLANE1);
glClipPlane(GL_CLIP_PLANE2, eqn_right);
glEnable(GL_CLIP_PLANE2);
// glScissor(-100,-240, 200, 240);
// glEnable(GL_SCISSOR_TEST);
}
//****************************************************************
// OBJECT MOVING RETICLE
// TYPE VELOCITY VECTOR
// ATTRIB - ALWAYS
// velocity vector
glBegin(GL_LINE_LOOP); // Use polygon to approximate a circle
for (count = 0; count < 50; count++) {
cosine = 6 * cos(count * SGD_2PI / 50.0);
sine = 6 * sin(count * SGD_2PI / 50.0);
glVertex2f(cosine + vel_x, sine + vel_y);
}
glEnd();
//velocity vector reticle orientation lines
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 12, vel_y);
glVertex2f(vel_x - 6, vel_y);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x + 12, vel_y);
glVertex2f(vel_x + 6, vel_y);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x, vel_y + 12);
glVertex2f(vel_x, vel_y + 6);
glEnd();
#ifdef ENABLE_SP_FDM
// OBJECT MOVING RETICLE
// TYPE LINE
// ATTRIB - ON CONDITION
if (lgear == 1) {
// undercarriage status
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x + 8, vel_y);
glVertex2f(vel_x + 8, vel_y - 4);
glEnd();
// OBJECT MOVING RETICLE
// TYPE LINE
// ATTRIB - ON CONDITION
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 8, vel_y);
glVertex2f(vel_x - 8, vel_y - 4);
glEnd();
// OBJECT MOVING RETICLE
// TYPE LINE
// ATTRIB - ON CONDITION
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x, vel_y - 6);
glVertex2f(vel_x, vel_y - 10);
glEnd();
}
// OBJECT MOVING RETICLE
// TYPE V
// ATTRIB - ON CONDITION
if (ihook == 1) {
// arrestor hook status
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 4, vel_y - 8);
glVertex2f(vel_x, vel_y - 10);
glVertex2f(vel_x + 4, vel_y - 8);
glEnd();
}
#endif
} // if velocity_vector
//***************************************************************
// OBJECT MOVING RETICLE
// TYPE - SQUARE_BRACKET
// ATTRIB - ON CONDITION
// alpha bracket
#ifdef ENABLE_SP_FDM
if (alpha_bracket && ihook == 1) {
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 20 , vel_y - (16 - alpha) * factor);
glVertex2f(vel_x - 17, vel_y - (16 - alpha) * factor);
glVertex2f(vel_x - 17, vel_y - (14 - alpha) * factor);
glVertex2f(vel_x - 20, vel_y - (14 - alpha) * factor);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x + 20 , vel_y - (16 - alpha) * factor);
glVertex2f(vel_x + 17, vel_y - (16 - alpha) * factor);
glVertex2f(vel_x + 17, vel_y - (14 - alpha) * factor);
glVertex2f(vel_x + 20, vel_y - (14 - alpha) * factor);
glEnd();
}
#endif
//printf("xvr=%f, yvr=%f, Vx=%f, Vy=%f, Vz=%f\n",xvvr, yvvr, Vx, Vy, Vz);
//printf("Ax=%f, Ay=%f, Az=%f\n",Ax, Ay, Az);
//****************************************************************
// OBJECT MOVING RETICLE
// TYPE ENERGY_MARKERS
// ATTRIB - ALWAYS
//energy markers - compute potential slope
if (energy_marker) {
if (total_vel < 5.0) {
t1 = 0;
t2 = 0;
} else {
t1 = up_vel / total_vel;
t2 = asin((Vxx * Axx + Vyy * Ayy + Vzz * Azz) / (9.81 * total_vel));
}
pot_slope = ((t2 / 3) * SGD_RADIANS_TO_DEGREES) * factor + vel_y;
// if (pot_slope < (vel_y - 45)) pot_slope = vel_y - 45;
// if (pot_slope > (vel_y + 45)) pot_slope = vel_y + 45;
//energy markers
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 20, pot_slope - 5);
glVertex2f(vel_x - 15, pot_slope);
glVertex2f(vel_x - 20, pot_slope + 5);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x + 20, pot_slope - 5);
glVertex2f(vel_x + 15, pot_slope);
glVertex2f(vel_x + 20, pot_slope + 5);
glEnd();
if (pla > (105.0 / 131.0)) {
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 24, pot_slope - 5);
glVertex2f(vel_x - 19, pot_slope);
glVertex2f(vel_x - 24, pot_slope + 5);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(vel_x + 24, pot_slope - 5);
glVertex2f(vel_x + 19, pot_slope);
glVertex2f(vel_x + 24, pot_slope + 5);
glEnd();
}
}
//**********************************************************
// ramp reticle
// OBJECT STATIC RETICLE
// TYPE LINE
// ATTRIB - ON CONDITION
#ifdef ENABLE_SP_FDM
if (energy_worm && ilcanclaw == 1) {
glBegin(GL_LINE_STRIP);
glVertex2f(-15, -134);
glVertex2f(15, -134);
glEnd();
// OBJECT MOVING RETICLE
// TYPE BOX
// ATTRIB - ON CONDITION
glBegin(GL_LINE_STRIP);
glVertex2f(-6, -134);
glVertex2f(-6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
glVertex2f(+6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
glVertex2f(6, -134);
glEnd();
// OBJECT MOVING RETICLE
// TYPE DIAMOND
// ATTRIB - ON CONDITION
glBegin(GL_LINE_LOOP);
glVertex2f(-6, actslope * 4.0 - 134);
glVertex2f(0, actslope * 4.0 -134 + 3);
glVertex2f(6, actslope * 4.0 - 134);
glVertex2f(0, actslope * 4.0 -134 -3);
glEnd();
}
#endif
//*************************************************************
// OBJECT MOVING RETICLE
// TYPE DIAMOND
// ATTRIB - ALWAYS
// Draw the locked velocity vector.
if (climb_dive_marker) {
glBegin(GL_LINE_LOOP);
glVertex2f(-3.0, 0.0 + vel_y);
glVertex2f(0.0, 6.0 + vel_y);
glVertex2f(3.0, 0.0 + vel_y);
glVertex2f(0.0, -6.0 + vel_y);
glEnd();
}
//****************************************************************
if (climb_dive_ladder) { // CONFORMAL_HUD
vmin = pitch_value - (float)width_units;
vmax = pitch_value + (float)width_units;
glTranslatef(vel_x, vel_y, 0);
} else { // pitch_ladder - Default Hud
vmin = pitch_value - (float)width_units * 0.5f;
vmax = pitch_value + (float)width_units * 0.5f;
}
glRotatef(roll_value * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
// FRL marker not rotated - this line shifted below
if (div_units) {
char TextLadder[8];
float label_length;
float label_height;
float left;
float right;
float bot;
float top;
float text_offset = 4.0f;
float zero_offset = 0.0;
if (climb_dive_ladder)
zero_offset = 50.0f; // horizon line is wider by this much (hard coded ??)
else
zero_offset = 10.0f;
fntFont *font = HUDtext->getFont(); // FIXME
float pointsize = HUDtext->getPointSize();
float italic = HUDtext->getSlant();
TextList.setFont(HUDtext);
TextList.erase();
LineList.erase();
StippleLineList.erase();
int last = float_to_int(vmax) + 1;
int i = float_to_int(vmin);
if (!scr_hole) {
x_end = half_span;
for (; i<last; i++) {
y = (((float)(i - pitch_value) * factor) + .5f);
if (!(i % div_units)) { // At integral multiple of div
sprintf(TextLadder, "%d", i);
font->getBBox(TextLadder, pointsize, italic,
&left, &right, &bot, &top);
label_length = right - left;
label_length += text_offset;
label_height = (top - bot) / 2.0f;
x_ini = -half_span;
if (i >= 0) {
// Make zero point wider on left
if (i == 0)
x_ini -= zero_offset;
// Zero or above draw solid lines
Line(x_ini, y, x_end, y);
if (i == 90 && zenith == 1)
drawZenith(x_ini, x_end, y);
} else {
// Below zero draw dashed lines.
StippleLine(x_ini, y, x_end, y);
if (i == -90 && nadir ==1)
drawNadir(x_ini, x_end, y);
}
// Calculate the position of the left text and write it.
Text(x_ini-label_length, y-label_height, TextLadder);
Text(x_end+text_offset, y-label_height, TextLadder);
}
}
} else { // if (scr_hole)
// Draw ladder with space in the middle of the lines
float hole = (float)((scr_hole) / 2.0f);
x_end = -half_span + hole;
x_ini2 = half_span - hole;
for (; i < last; i++) {
if (hudladder_type == "Pitch Ladder")
y = (((float)(i - pitch_value) * factor) + .5);
else if (hudladder_type == "Climb/Dive Ladder")
y = (((float)(i - actslope) * factor) + .5);
if (!(i % div_units)) { // At integral multiple of div
sprintf(TextLadder, "%d", i);
font->getBBox(TextLadder, pointsize, italic,
&left, &right, &bot, &top);
label_length = right - left;
label_length += text_offset;
label_height = (top - bot) / 2.0f;
// printf("l %f r %f b %f t %f\n",left, right, bot, top);
// Start by calculating the points and drawing the
// left side lines.
x_ini = -half_span;
x_end2 = half_span;
if (i >= 0) {
// Make zero point wider on left
if (i == 0) {
x_ini -= zero_offset;
x_end2 += zero_offset;
}
//draw climb bar vertical lines
if (climb_dive_ladder) {
// Zero or above draw solid lines
Line(x_end, y - 5.0, x_end, y);
Line(x_ini2, y - 5.0, x_ini2, y);
}
// draw pitch / climb bar
Line(x_ini, y, x_end, y);
Line(x_ini2, y, x_end2, y);
if (i == 90 && zenith == 1)
drawZenith(x_ini2, x_end, y);
} else { // i < 0
// draw dive bar vertical lines
if (climb_dive_ladder) {
Line(x_end, y + 5.0, x_end, y);
Line(x_ini2, y + 5.0, x_ini2, y);
}
// draw pitch / dive bars
StippleLine(x_ini, y, x_end, y);
StippleLine(x_ini2, y, x_end2, y);
if (i == -90 && nadir == 1)
drawNadir(x_ini2, x_end, y);
}
// Now calculate the location of the left side label using
Text(x_ini-label_length, y - label_height, TextLadder);
Text(x_end2+text_offset, y - label_height, TextLadder);
}
}
// OBJECT LADDER MARK
// TYPE LINE
// ATTRIB - ON CONDITION
// draw appraoch glide slope marker
#ifdef ENABLE_SP_FDM
if (glide_slope_marker && ihook) {
Line(-half_span + 15, (glide_slope-actslope) * factor,
-half_span + hole, (glide_slope - actslope) * factor);
Line(half_span - 15, (glide_slope-actslope) * factor,
half_span - hole, (glide_slope - actslope) * factor);
}
#endif
}
TextList.draw();
glLineWidth(0.2);
LineList.draw();
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0x00FF);
StippleLineList.draw();
glDisable(GL_LINE_STIPPLE);
}
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
// glDisable(GL_SCISSOR_TEST);
glPopMatrix();
//*************************************************************
//*************************************************************
#ifdef ENABLE_SP_FDM
if (waypoint_marker) {
//waypoint marker computation
float fromwp_lat, towp_lat, fromwp_lon, towp_lon, dist, delx, dely, hyp, theta, brg;
fromwp_lon = get_longitude() * SGD_DEGREES_TO_RADIANS;
fromwp_lat = get_latitude() * SGD_DEGREES_TO_RADIANS;
towp_lon = fgGetDouble("/fdm-ada/ship-lon", 0.0) * SGD_DEGREES_TO_RADIANS;
towp_lat = fgGetDouble("/fdm-ada/ship-lat", 0.0) * SGD_DEGREES_TO_RADIANS;
dist = acos(sin(fromwp_lat) * sin(towp_lat) + cos(fromwp_lat)
* cos(towp_lat) * cos(fabs(fromwp_lon - towp_lon)));
delx= towp_lat - fromwp_lat;
dely = towp_lon - fromwp_lon;
hyp = sqrt(pow(delx, 2) + pow(dely, 2));
if (hyp != 0)
theta = asin(dely / hyp);
else
theta = 0.0;
brg = theta * SGD_RADIANS_TO_DEGREES;
if (brg > 360.0)
brg = 0.0;
if (delx < 0)
brg = 180 - brg;
// {Brg = asin(cos(towp_lat)*sin(fabs(fromwp_lon-towp_lon))/ sin(dist));
// Brg = Brg * SGD_RADIANS_TO_DEGREES; }
dist *= SGD_RADIANS_TO_DEGREES * 60.0 * 1852.0; //rad->deg->nm->m
// end waypoint marker computation
//*********************************************************
// OBJECT MOVING RETICLE
// TYPE ARROW
// waypoint marker
if (fabs(brg-psi) > 10.0) {
glPushMatrix();
glTranslatef(centroid.x, centroid.y, 0);
glTranslatef(vel_x, vel_y, 0);
glRotatef(brg - psi, 0.0, 0.0, -1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(-2.5, 20.0);
glVertex2f(-2.5, 30.0);
glVertex2f(-5.0, 30.0);
glVertex2f(0.0, 35.0);
glVertex2f(5.0, 30.0);
glVertex2f(2.5, 30.0);
glVertex2f(2.5, 20.0);
glEnd();
glPopMatrix();
}
// waypoint marker on heading scale
if (fabs(brg-psi) < 12.0) {
if (hat == 0) {
glBegin(GL_LINE_LOOP);
glVertex2f(((brg - psi) * 60 / 25) + 320, 240.0);
glVertex2f(((brg - psi) * 60 / 25) + 326, 240.0 - 4);
glVertex2f(((brg - psi) * 60 / 25) + 323, 240.0 - 4);
glVertex2f(((brg - psi) * 60 / 25) + 323, 240.0 - 8);
glVertex2f(((brg - psi) * 60 / 25) + 317, 240.0 - 8);
glVertex2f(((brg - psi) * 60 / 25) + 317, 240.0 - 4);
glVertex2f(((brg - psi) * 60 / 25) + 314, 240.0 - 4);
glEnd();
} else { //if hat=0
float x = (brg - psi) * 60 / 25 + 320, y = 240.0, r = 5.0;
float x1, y1;
glEnable(GL_POINT_SMOOTH);
glBegin(GL_POINTS);
for (int count = 0; count <= 200; count++) {
float temp = count * 3.142 * 3 / (200.0 * 2.0);
float temp1 = temp - (45.0 * SGD_DEGREES_TO_RADIANS);
x1 = x + r * cos(temp1);
y1 = y + r * sin(temp1);
glVertex2f(x1, y1);
}
glEnd();
glDisable(GL_POINT_SMOOTH);
} //hat=0
} //brg<12
} // if waypoint_marker
#endif
}//draw
/******************************************************************/
// draws the zenith symbol for highest possible climb angle (i.e. 90 degree climb angle)
//
void HudLadder::drawZenith(float xfirst, float xlast, float yvalue)
{
float xcentre = (xfirst + xlast) / 2.0;
float ycentre = yvalue;
Line(xcentre - 9.0, ycentre, xcentre - 3.0, ycentre + 1.3);
Line(xcentre - 9.0, ycentre, xcentre - 3.0, ycentre - 1.3);
Line(xcentre + 9.0, ycentre, xcentre + 3.0, ycentre + 1.3);
Line(xcentre + 9.0, ycentre, xcentre + 3.0, ycentre - 1.3);
Line(xcentre, ycentre + 9.0, xcentre - 1.3, ycentre + 3.0);
Line(xcentre, ycentre + 9.0, xcentre + 1.3, ycentre + 3.0);
Line(xcentre - 3.9, ycentre + 3.9, xcentre - 3.0, ycentre + 1.3);
Line(xcentre - 3.9, ycentre + 3.9, xcentre - 1.3, ycentre + 3.0);
Line(xcentre + 3.9, ycentre + 3.9, xcentre + 1.3, ycentre+3.0);
Line(xcentre + 3.9, ycentre + 3.9, xcentre + 3.0, ycentre+1.3);
Line(xcentre - 3.9, ycentre - 3.9, xcentre - 3.0, ycentre-1.3);
Line(xcentre - 3.9, ycentre - 3.9, xcentre - 1.3, ycentre-2.6);
Line(xcentre + 3.9, ycentre - 3.9, xcentre + 3.0, ycentre-1.3);
Line(xcentre + 3.9, ycentre - 3.9, xcentre + 1.3, ycentre-2.6);
Line(xcentre - 1.3, ycentre - 2.6, xcentre, ycentre - 27.0);
Line(xcentre + 1.3, ycentre - 2.6, xcentre, ycentre - 27.0);
}
// draws the nadir symbol for lowest possible dive angle (i.e. 90 degree dive angle)
//
void HudLadder::drawNadir(float xfirst, float xlast, float yvalue)
{
float xcentre = (xfirst + xlast) / 2.0;
float ycentre = yvalue;
float r = 7.5;
float x1, y1, x2, y2;
// to draw a circle
float xcent1, xcent2, ycent1, ycent2;
xcent1 = xcentre + r;
ycent1 = ycentre;
for (int count = 1; count <= 400; count++) {
float temp = count * 2 * 3.142 / 400.0;
xcent2 = xcentre + r * cos(temp);
ycent2 = ycentre + r * sin(temp);
Line(xcent1, ycent1, xcent2, ycent2);
xcent1 = xcent2;
ycent1 = ycent2;
}
xcent2 = xcentre + r;
ycent2 = ycentre;
drawOneLine(xcent1, ycent1, xcent2, ycent2); //to connect last point to first point
//end circle
//to draw a line above the circle
Line(xcentre, ycentre + 7.5, xcentre, ycentre + 22.5);
//line in the middle of circle
Line(xcentre - 7.5, ycentre, xcentre + 7.5, ycentre);
float theta = asin (2.5 / 7.5);
float theta1 = asin(5.0 / 7.5);
x1 = xcentre + r * cos(theta);
y1 = ycentre + 2.5;
x2 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta);
y2 = ycentre + 2.5;
Line(x1, y1, x2, y2);
x1 = xcentre + r * cos(theta1);
y1 = ycentre + 5.0;
x2 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1);
y2 = ycentre + 5.0;
Line(x1, y1, x2, y2);
x1 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta);
y1 = ycentre - 2.5;
x2 = xcentre + r * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta);
y2 = ycentre - 2.5;
Line(x1, y1, x2, y2);
x1 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1);
y1 = ycentre - 5.0;
x2 = xcentre + r * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1);
y2 = ycentre - 5.0;
Line(x1, y1, x2, y2);
}

View file

@ -1,437 +0,0 @@
// hud_rwy.cxx -- An instrument that renders a virtual runway on the HUD
//
// Written by Aaron Wilson & Phillip Merritt, Nov 2004.
//
// Copyright (C) 2004 Aaron Wilson, Aaron.I.Wilson@nasa.gov
// Copyright (C) 2004 Phillip Merritt, Phillip.M.Merritt@nasa.gov
//
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <simgear/compiler.h>
#include "hud.hxx"
#include <math.h>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#include <Environment/environment.hxx>
#include <Environment/environment_mgr.hxx>
#include <ATCDCL/ATCutils.hxx>
#include <Main/viewer.hxx>
#include <simgear/math/project.hxx>
// int x, int y, int width, int height, float scale_data, bool working)
runway_instr::runway_instr(const SGPropertyNode *node) :
instr_item(
node->getIntValue("x"),
node->getIntValue("y"),
node->getIntValue("width"),
node->getIntValue("height"),
NULL,
node->getDoubleValue("scale"),
0,
node->getBoolValue("working", true)),
arrowScale(node->getDoubleValue("arrow_scale", 1.0)),
arrowRad(node->getDoubleValue("arrow_radius")),
lnScale(node->getDoubleValue("line_scale", 1.0)),
scaleDist(node->getDoubleValue("scale_dist_nm")),
default_pitch(fgGetDouble("/sim/view[0]/config/pitch-pitch-deg", 0.0)),
default_heading(fgGetDouble("/sim/view[0]/config/pitch-heading-deg", 0.0)),
cockpit_view(globals->get_viewmgr()->get_view(0)),
stippleOut(node->getIntValue("outer_stipple", 0xFFFF)),
stippleCen(node->getIntValue("center_stipple", 0xFFFF)),
drawIA(arrowScale > 0 ? true : false),
drawIAAlways(arrowScale > 0 ? node->getBoolValue("arrow_always") : false)
{
SG_LOG(SG_INPUT, SG_BULK, "Done reading runway instrument "
<< node->getStringValue("name", "[unnamed]"));
view[0] = 0;
view[1] = 0;
view[2] = 640;
view[3] = 480;
center.x = view[2] >> 1;
center.y = view[3] >> 1;
location.left = center.x - (get_width() >> 1) + get_x();
location.right = center.x + (get_width() >>1) + get_x();
location.bottom = center.y - (get_height() >>1) + get_y();
location.top = center.y + (get_height() >> 1) + get_y();
}
void runway_instr::draw()
{
if (!is_broken() && (runway = get_active_runway())) {
glPushAttrib(GL_LINE_STIPPLE | GL_LINE_STIPPLE_PATTERN | GL_LINE_WIDTH);
float modelView[4][4], projMat[4][4];
bool anyLines;
//Get the current view
FGViewer* curr_view = globals->get_viewmgr()->get_current_view();
int curr_view_id = globals->get_viewmgr()->get_current();
double gpo = curr_view->getGoalPitchOffset_deg();
double gho = curr_view->getGoalHeadingOffset_deg();
double po = curr_view->getPitchOffset_deg();
double ho = curr_view->getHeadingOffset_deg();
double yaw = -(cockpit_view->getHeadingOffset_deg() - default_heading) * SG_DEGREES_TO_RADIANS;
double pitch = (cockpit_view->getPitchOffset_deg() - default_pitch) * SG_DEGREES_TO_RADIANS;
//double roll = fgGetDouble("/sim/view[0]/config/roll-offset-deg",0.0) //TODO: adjust for default roll offset
double sPitch = sin(pitch), cPitch = cos(pitch),
sYaw = sin(yaw), cYaw = cos(yaw);
//Set the camera to the cockpit view to get the view of the runway from the cockpit
// OSGFIXME
// ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW());
get_rwy_points(points3d);
//Get the current project matrix
// OSGFIXME
// ssgGetProjectionMatrix(projMat);
// const sgVec4 *viewMat = globals->get_current_view()->get_VIEW();
//Get the current model view matrix (cockpit view)
// OSGFIXME
// ssgGetModelviewMatrix(modelView);
//Create a rotation matrix to correct for any offsets (other than default offsets) to the model view matrix
sgMat4 xy; //rotation about the Rxy, negate the sin's on Ry
xy[0][0] = cYaw; xy[1][0] = 0.0f; xy[2][0] = -sYaw; xy[3][0] = 0.0f;
xy[0][1] = sPitch*-sYaw; xy[1][1] = cPitch; xy[2][1] = -sPitch*cYaw; xy[3][1] = 0.0f;
xy[0][2] = cPitch*sYaw; xy[1][2] = sPitch; xy[2][2] = cPitch*cYaw; xy[3][2] = 0.0f;
xy[0][3] = 0.0f; xy[1][3] = 0.0f; xy[2][3] = 0.0f; xy[3][3] = 1.0f;
//Re-center the model view
sgPostMultMat4(modelView,xy);
//copy float matrices to double
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
int idx = (i * 4) + j;
mm[idx] = (double)modelView[i][j];
pm[idx] = (double)projMat[i][j];
}
}
//Calculate the 2D points via gluProject
int result = GL_TRUE;
for (int i = 0; i < 6; i++) {
result = simgear::project(points3d[i][0], points3d[i][1], points3d[i][2],
mm, pm, view,
&points2d[i][0], &points2d[i][1], &points2d[i][2]);
}
//set the line width based on our distance from the runway
setLineWidth();
//Draw the runway lines on the HUD
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, stippleOut);
anyLines =
drawLine(points3d[0], points3d[1], points2d[0], points2d[1]) | //draw top
drawLine(points3d[2], points3d[1], points2d[2], points2d[1]) | //draw right
drawLine(points3d[2], points3d[3], points2d[2], points2d[3]) | //draw bottom
drawLine(points3d[3], points3d[0], points2d[3], points2d[0]); //draw left
glLineStipple(1, stippleCen);
anyLines |= drawLine(points3d[5], points3d[4], points2d[5], points2d[4]); //draw center
//Check to see if arrow needs drawn
if ((!anyLines && drawIA) || drawIAAlways) {
drawArrow(); //draw indication arrow
}
//Set the camera back to the current view
// OSGFIXME
// ssgSetCamera((sgVec4 *)curr_view);
glPopAttrib();
}//if not broken
}
FGRunway* runway_instr::get_active_runway()
{
const FGAirport* apt = fgFindAirportID(fgGetString("/sim/presets/airport-id"));
if (!apt) return NULL;
return apt->getActiveRunwayForUsage();
}
void runway_instr::get_rwy_points(sgdVec3 *points3d)
{
double alt = runway->geod().getElevationM();
double length = runway->lengthM() * 0.5;
double width = runway->widthM() * 0.5;
double frontLat = 0.0, frontLon = 0.0, backLat = 0.0, backLon = 0.0, az = 0.0, tempLat = 0.0, tempLon = 0.0;
double runwayLon = runway->geod().getLongitudeDeg(),
runwayLat = runway->geod().getLatitudeDeg();
double heading = runway->headingDeg();
geo_direct_wgs_84(alt, runwayLat, runwayLon, heading, length, &backLat, &backLon, &az);
sgGeodToCart(backLat * SG_DEGREES_TO_RADIANS, backLon * SG_DEGREES_TO_RADIANS, alt, points3d[4]);
geo_direct_wgs_84(alt, runwayLat, runwayLon, heading + 180, length, &frontLat, &frontLon, &az);
sgGeodToCart(frontLat * SG_DEGREES_TO_RADIANS, frontLon * SG_DEGREES_TO_RADIANS, alt, points3d[5]);
geo_direct_wgs_84(alt, backLat, backLon, heading + 90, width, &tempLat, &tempLon, &az);
sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[0]);
geo_direct_wgs_84(alt, backLat, backLon, heading - 90, width, &tempLat, &tempLon, &az);
sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[1]);
geo_direct_wgs_84(alt, frontLat, frontLon, heading - 90, width, &tempLat, &tempLon, &az);
sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[2]);
geo_direct_wgs_84(alt, frontLat, frontLon, heading + 90, width, &tempLat, &tempLon, &az);
sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[3]);
}
bool runway_instr::drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& point1, const sgdVec3& point2)
{
sgdVec3 p1, p2;
sgdCopyVec3(p1, point1);
sgdCopyVec3(p2, point2);
bool p1Inside = (p1[0] >= location.left && p1[0] <= location.right
&& p1[1] >= location.bottom && p1[1] <= location.top);
bool p1Insight = (p1[2] >= 0.0 && p1[2] < 1.0);
bool p1Valid = p1Insight && p1Inside;
bool p2Inside = (p2[0] >= location.left && p2[0] <= location.right
&& p2[1] >= location.bottom && p2[1] <= location.top);
bool p2Insight = (p2[2] >= 0.0 && p2[2] < 1.0);
bool p2Valid = p2Insight && p2Inside;
if (p1Valid && p2Valid) { //Both project points are valid, draw the line
glBegin(GL_LINES);
glVertex2d(p1[0],p1[1]);
glVertex2d(p2[0],p2[1]);
glEnd();
} else if (p1Valid) { //p1 is valid and p2 is not, calculate a new valid point
sgdVec3 vec = {a2[0] - a1[0], a2[1] - a1[1], a2[2] - a1[2]};
//create the unit vector
sgdScaleVec3(vec, 1.0 / sgdLengthVec3(vec));
sgdVec3 newPt;
sgdCopyVec3(newPt, a1);
sgdAddVec3(newPt, vec);
if (simgear::project(newPt[0], newPt[1], newPt[2], mm, pm, view,
&p2[0], &p2[1], &p2[2])
&& (p2[2] > 0 && p2[2] < 1.0)) {
boundPoint(p1, p2);
glBegin(GL_LINES);
glVertex2d(p1[0], p1[1]);
glVertex2d(p2[0], p2[1]);
glEnd();
}
} else if (p2Valid) { //p2 is valid and p1 is not, calculate a new valid point
sgdVec3 vec = {a1[0] - a2[0], a1[1] - a2[1], a1[2] - a2[2]};
//create the unit vector
sgdScaleVec3(vec, 1.0 / sgdLengthVec3(vec));
sgdVec3 newPt;
sgdCopyVec3(newPt, a2);
sgdAddVec3(newPt, vec);
if (simgear::project(newPt[0], newPt[1], newPt[2], mm, pm, view,
&p1[0], &p1[1], &p1[2])
&& (p1[2] > 0 && p1[2] < 1.0)) {
boundPoint(p2, p1);
glBegin(GL_LINES);
glVertex2d(p2[0], p2[1]);
glVertex2d(p1[0], p1[1]);
glEnd();
}
} else if (p1Insight && p2Insight) { //both points are insight, but not inside
bool v = boundOutsidePoints(p1, p2);
if (v) {
glBegin(GL_LINES);
glVertex2d(p1[0], p1[1]);
glVertex2d(p2[0], p2[1]);
glEnd();
}
return v;
}
//else both points are not insight, don't draw anything
return (p1Valid && p2Valid);
}
void runway_instr::boundPoint(const sgdVec3& v, sgdVec3& m)
{
double y = v[1];
if (m[1] < v[1])
y = location.bottom;
else if (m[1] > v[1])
y = location.top;
if (m[0] == v[0]) {
m[1] = y;
return; //prevent divide by zero
}
double slope = (m[1] - v[1]) / (m[0] - v[0]);
m[0] = (y - v[1]) / slope + v[0];
m[1] = y;
if (m[0] < location.left) {
m[0] = location.left;
m[1] = slope * (location.left - v[0]) + v[1];
} else if (m[0] > location.right) {
m[0] = location.right;
m[1] = slope * (location.right - v[0]) + v[1];
}
}
bool runway_instr::boundOutsidePoints(sgdVec3& v, sgdVec3& m)
{
bool pointsInvalid = (v[1] > location.top && m[1] > location.top) ||
(v[1] < location.bottom && m[1] < location.bottom) ||
(v[0] > location.right && m[0] > location.right) ||
(v[0] < location.left && m[0] < location.left);
if (pointsInvalid)
return false;
if (m[0] == v[0]) {//x's are equal, vertical line
if (m[1] > v[1]) {
m[1] = location.top;
v[1] = location.bottom;
} else {
v[1] = location.top;
m[1] = location.bottom;
}
return true;
}
if (m[1] == v[1]) { //y's are equal, horizontal line
if (m[0] > v[0]) {
m[0] = location.right;
v[0] = location.left;
} else {
v[0] = location.right;
m[0] = location.left;
}
return true;
}
double slope = (m[1] - v[1]) / (m[0] - v[0]);
double b = v[1] - (slope * v[0]);
double y1 = slope * location.left + b;
double y2 = slope * location.right + b;
double x1 = (location.bottom - b) / slope;
double x2 = (location.top - b) / slope;
int counter = 0;
if (y1 >= location.bottom && y1 <= location.top) {
v[0] = location.left;
v[1] = y1;
counter++;
}
if (y2 >= location.bottom && y2 <= location.top) {
if (counter > 0) {
m[0] = location.right;
m[1] = y2;
} else {
v[0] = location.right;
v[1] = y2;
}
counter++;
}
if (x1 >= location.left && x1 <= location.right) {
if (counter > 0) {
m[0] = x1;
m[1] = location.bottom;
} else {
v[0] = x1;
v[1] = location.bottom;
}
counter++;
}
if (x2 >= location.left && x2 <= location.right) {
m[0] = x1;
m[1] = location.bottom;
counter++;
}
return (counter == 2);
}
void runway_instr::drawArrow()
{
SGGeod acPos(SGGeod::fromDeg(
fgGetDouble("/position/longitude-deg"),
fgGetDouble("/position/latitude-deg")));
float theta = SGGeodesy::courseDeg(acPos, runway->geod());
theta -= fgGetDouble("/orientation/heading-deg");
theta = -theta;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslated((location.right + location.left) / 2.0,(location.top + location.bottom) / 2.0, 0.0);
glRotated(theta, 0.0, 0.0, 1.0);
glTranslated(0.0, arrowRad, 0.0);
glScaled(arrowScale, arrowScale, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d(-5.0, 12.5);
glVertex2d(0.0, 25.0);
glVertex2d(5.0, 12.5);
glEnd();
glBegin(GL_QUADS);
glVertex2d(-2.5, 0.0);
glVertex2d(-2.5, 12.5);
glVertex2d(2.5, 12.5);
glVertex2d(2.5, 0.0);
glEnd();
glPopMatrix();
}
void runway_instr::setLineWidth()
{
//Calculate the distance from the runway, A
SGGeod acPos(SGGeod::fromDeg(
fgGetDouble("/position/longitude-deg"),
fgGetDouble("/position/latitude-deg")));
double distance = SGGeodesy::distanceNm(acPos, runway->geod());
//Get altitude above runway, B
double alt_nm = get_agl();
static const SGPropertyNode *startup_units_node = fgGetNode("/sim/startup/units");
if (!strcmp(startup_units_node->getStringValue(), "feet"))
alt_nm *= SG_FEET_TO_METER*SG_METER_TO_NM;
else
alt_nm *= SG_METER_TO_NM;
//Calculate distance away from runway, C = v(A≤+B≤)
distance = sqrt(alt_nm * alt_nm + distance*distance);
if (distance < scaleDist)
glLineWidth(1.0 + ((lnScale - 1) * ((scaleDist - distance) / scaleDist)));
else
glLineWidth(1.0);
}
void runway_instr::setArrowRotationRadius(double radius) { arrowRad = radius; }
void runway_instr::setArrowScale(double scale) { arrowScale = scale; }
void runway_instr::setDrawArrow(bool draw) {drawIA = draw;}
void runway_instr::setDrawArrowAlways(bool draw) {drawIAAlways = draw;}
void runway_instr::setLineScale(double scale) {lnScale = scale;}
void runway_instr::setScaleDist(double dist_m) {scaleDist = dist_m;}
void runway_instr::setStippleOutline(unsigned short stipple) {stippleOut = stipple;}
void runway_instr::setStippleCenterline(unsigned short stipple){stippleCen = stipple;}

View file

@ -1,53 +0,0 @@
#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 gauge_instr classes.
//============================================================================
instr_scale::instr_scale(
int x,
int y,
UINT width,
UINT height,
FLTFNPTR load_fn,
UINT options,
float show_range,
float maxValue,
float minValue,
float 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 = (float)get_span() / range_shown;
if (show_range < 0)
range_shown = -range_shown;
temp = float_to_int(Maximum_value - Minimum_value) / 100;
if (range_shown < temp)
range_shown = temp;
}

View file

@ -1,241 +0,0 @@
//
// Turn Bank Indicator
//
#include <math.h>
#include "hud.hxx"
// FIXME
extern float get_roll(void);
extern float get_sideslip(void);
// x, y, width, height, get_roll, get_sideslip, maxBankAngle, maxSlipAngle, gap_width, working, tsi, rad
// int x, int y, UINT width, UINT height, FLTFNPTR chn1_source, FLTFNPTR chn2_source, float maxBankAngle,
// float maxSlipAngle, UINT gap_width, bool working, bool tsivalue, float radius) :
fgTBI_instr::fgTBI_instr(const SGPropertyNode *node) :
dual_instr_item(
node->getIntValue("x"),
node->getIntValue("y"),
node->getIntValue("width"),
node->getIntValue("height"),
get_roll, // FIXME
get_sideslip,
node->getBoolValue("working", true),
HUDS_TOP),
BankLimit(int(node->getFloatValue("maxBankAngle"))),
SlewLimit(int(node->getFloatValue("maxSlipAngle"))),
scr_hole(node->getIntValue("gap_width")),
tsi(node->getBoolValue("tsi")),
rad(node->getFloatValue("rad"))
{
SG_LOG(SG_INPUT, SG_BULK, "Done reading TBI instrument"
<< node->getStringValue("name", "[unnamed]"));
}
void fgTBI_instr::draw(void)
{
float bank_angle, sideslip_angle;
float ss_const; // sideslip angle pixels per rad
float cen_x, cen_y, bank, fspan, tee, hole;
int span = get_span();
float zero = 0.0;
RECT My_box = get_location();
POINT centroid = get_centroid();
int tee_height = My_box.bottom;
bank_angle = current_ch2(); // Roll limit +/- 30 degrees
if (bank_angle < -SGD_PI_2 / 3)
bank_angle = -SGD_PI_2 / 3;
else if (bank_angle > SGD_PI_2 / 3)
bank_angle = SGD_PI_2 / 3;
sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
if (sideslip_angle < -SGD_PI / 9)
sideslip_angle = -SGD_PI / 9;
else if ( sideslip_angle > SGD_PI / 9 )
sideslip_angle = SGD_PI / 9;
cen_x = centroid.x;
cen_y = centroid.y;
bank = bank_angle * SGD_RADIANS_TO_DEGREES;
tee = -tee_height;
fspan = span;
hole = scr_hole;
ss_const = 2 * sideslip_angle * fspan / (SGD_2PI / 9); // width represents 40 degrees
// printf("side_slip: %f fspan: %f\n", sideslip_angle, fspan);
// printf("ss_const: %f hole: %f\n", ss_const, hole);
glPushMatrix();
glTranslatef(cen_x, cen_y, zero);
glRotatef(-bank, zero, zero, 1.0);
if (!tsi) {
glBegin(GL_LINES);
if (!scr_hole) {
glVertex2f(-fspan, zero);
glVertex2f(fspan, zero);
} else {
glVertex2f(-fspan, zero);
glVertex2f(-hole, zero);
glVertex2f(hole, zero);
glVertex2f(fspan, zero);
}
// draw teemarks
glVertex2f(hole, zero);
glVertex2f(hole, tee);
glVertex2f(-hole, zero);
glVertex2f(-hole, tee);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2f(ss_const, -hole);
glVertex2f(ss_const + hole, zero);
glVertex2f(ss_const, hole);
glVertex2f(ss_const - hole, zero);
glEnd();
} else { //if tsi enabled
drawOneLine(cen_x-1.0, My_box.top, cen_x + 1.0, My_box.top);
drawOneLine(cen_x-1.0, My_box.top, cen_x - 1.0, My_box.top + 10.0);
drawOneLine(cen_x+1.0, My_box.top, cen_x + 1.0, My_box.top + 10.0);
drawOneLine(cen_x-1.0, My_box.top + 10.0, cen_x + 1.0, My_box.top + 10.0);
float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
float xc, yc, r = rad, r1 = rad - 10.0, r2 = rad - 5.0;
xc = My_box.left + My_box.right / 2.0 ;
yc = My_box.top + r;
// first n last lines
x1 = xc + r * cos(255.0 * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin(255.0 * SGD_DEGREES_TO_RADIANS);
x2 = xc + r1 * cos(255.0 * SGD_DEGREES_TO_RADIANS);
y2 = yc + r1 * sin(255.0 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1,y1,x2,y2);
x1 = xc + r * cos(285.0 * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin(285.0 * SGD_DEGREES_TO_RADIANS);
x2 = xc + r1 * cos(285.0 * SGD_DEGREES_TO_RADIANS);
y2 = yc + r1 * sin(285.0 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1, y1, x2, y2);
// second n fifth lines
x1 = xc + r * cos(260.0 * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin(260.0 * SGD_DEGREES_TO_RADIANS);
x2 = xc + r2 * cos(260.0 * SGD_DEGREES_TO_RADIANS);
y2 = yc + r2 * sin(260.0 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1, y1, x2, y2);
x1 = xc + r * cos(280.0 * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin(280.0 * SGD_DEGREES_TO_RADIANS);
x2 = xc + r2 * cos(280.0 * SGD_DEGREES_TO_RADIANS);
y2 = yc + r2 * sin(280.0 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1, y1, x2, y2);
// third n fourth lines
x1 = xc + r * cos(265.0 * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin(265.0 * SGD_DEGREES_TO_RADIANS);
x2 = xc + r2 * cos(265.0 * SGD_DEGREES_TO_RADIANS);
y2 = yc + r2 * sin(265.0 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1, y1, x2, y2);
x1 = xc + r * cos(275.0 * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin(275.0 * SGD_DEGREES_TO_RADIANS);
x2 = xc + r2 * cos(275.0 * SGD_DEGREES_TO_RADIANS);
y2 = yc + r2 * sin(275.0 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1,y1,x2,y2);
// draw marker
float valbank, valsideslip, sideslip;
r = rad + 5.0; // add gap
// upper polygon
bank_angle = current_ch2();
bank = bank_angle * SGD_RADIANS_TO_DEGREES; // Roll limit +/- 30 degrees
if (bank > BankLimit)
bank = BankLimit;
if (bank < -1.0*BankLimit)
bank = -1.0*BankLimit;
valbank = bank * 15.0 / BankLimit; // total span of TSI is 30 degrees
sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
sideslip = sideslip_angle * SGD_RADIANS_TO_DEGREES;
if (sideslip > SlewLimit)
sideslip = SlewLimit;
if (sideslip < -1.0 * SlewLimit)
sideslip = -1.0 * SlewLimit;
valsideslip = sideslip * 15.0 / SlewLimit;
// values 270, 225 and 315 are angles in degrees...
x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
drawOneLine(x1, y1, x2, y2);
drawOneLine(x2, y2, x3, y3);
drawOneLine(x3, y3, x1, y1);
// lower polygon
x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
x4 = x1 + 10.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
y4 = y1 + 10.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
x5 = x1 + 10.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
y5 = y1 + 10.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
x2 = x2 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
y2 = y2 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
x3 = x3 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
y3 = y3 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
x4 = x4 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
y4 = y4 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
x5 = x5 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
y5 = y5 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
drawOneLine(x2, y2, x3, y3);
drawOneLine(x3, y3, x5, y5);
drawOneLine(x5, y5, x4, y4);
drawOneLine(x4, y4, x2, y2);
}
glPopMatrix();
}

View file

@ -56,7 +56,6 @@ using std::setfill;
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Cockpit/panel.hxx>
#include <Cockpit/hud.hxx>
#include "instrument_mgr.hxx"
#include "od_gauge.hxx"
@ -331,7 +330,7 @@ wxRadarBg::update (double delta_time_sec)
}
_radar_ref_rng = _radar_ref_rng_node->getDoubleValue();
_view_heading = get_heading() * SG_DEGREES_TO_RADIANS;
_view_heading = fgGetDouble("/orientation/heading-deg") * SG_DEGREES_TO_RADIANS;
_centerTrans.makeTranslate(0.0f, 0.0f, 0.0f);
_scale = 200.0 / _range_nm;
@ -500,7 +499,7 @@ wxRadarBg::update_weather()
if (iradarEcho->lightning || lwc < LWClevel[level])
continue;
float radius = sgSqrt(iradarEcho->dist) * SG_METER_TO_NM * _scale;
float radius = sqrt(iradarEcho->dist) * SG_METER_TO_NM * _scale;
float size = iradarEcho->radius * 2.0 * SG_METER_TO_NM * _scale;
if (radius - size > 180)
@ -617,7 +616,7 @@ wxRadarBg::update_aircraft()
// double bearing = test_brg * SG_DEGREES_TO_RADIANS;
// float angle = calcRelBearing(bearing, _view_heading);
double bumpinessFactor = (*ground_echoes_iterator)->bumpiness;
float heading = get_heading();
float heading = fgGetDouble("/orientation/heading-deg");
if ( _display_mode == BSCAN ){
test_rng = (*ground_echoes_iterator)->elevation * 6;
test_brg = (*ground_echoes_iterator)->bearing;

View file

@ -25,7 +25,6 @@
#include <Cockpit/panel.hxx>
#include <Cockpit/panel_io.hxx>
#include <Cockpit/hud.hxx>
#include <Environment/environment.hxx>
#include <FDM/flight.hxx>
#include <GUI/gui.h>
@ -454,24 +453,11 @@ do_preferences_load (const SGPropertyNode * arg)
return true;
}
static void
fix_hud_visibility()
{
if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
if ( globals->get_viewmgr()->get_current() == 1 ) {
globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
}
}
}
static void
do_view_next( bool )
{
globals->get_current_view()->setHeadingOffset_deg(0.0);
globals->get_viewmgr()->next_view();
fix_hud_visibility();
}
static void
@ -479,7 +465,6 @@ do_view_prev( bool )
{
globals->get_current_view()->setHeadingOffset_deg(0.0);
globals->get_viewmgr()->prev_view();
fix_hud_visibility();
}
/**
@ -490,7 +475,6 @@ do_view_cycle (const SGPropertyNode * arg)
{
globals->get_current_view()->setHeadingOffset_deg(0.0);
globals->get_viewmgr()->next_view();
fix_hud_visibility();
return true;
}
@ -1307,21 +1291,6 @@ do_increase_visibility (const SGPropertyNode * arg)
return true;
}
static bool
do_hud_init(const SGPropertyNode *)
{
fgHUDInit(); // minimal HUD
return true;
}
static bool
do_hud_init2(const SGPropertyNode *)
{
fgHUDInit2(); // normal HUD
return true;
}
/**
* An fgcommand to allow loading of xml files via nasal,
* the xml file's structure will be made available within
@ -1521,8 +1490,6 @@ static struct {
{ "replay", do_replay },
{ "decrease-visibility", do_decrease_visibility },
{ "increase-visibility", do_increase_visibility },
{ "hud-init", do_hud_init },
{ "hud-init2", do_hud_init2 },
{ "loadxml", do_load_xml_to_proptree},
{ "savexml", do_save_xml_from_proptree },
{ "press-cockpit-button", do_press_cockpit_button },

View file

@ -85,7 +85,6 @@
#include <Autopilot/route_mgr.hxx>
#include <Autopilot/autopilotgroup.hxx>
#include <Cockpit/cockpit.hxx>
#include <Cockpit/panel.hxx>
#include <Cockpit/panel_io.hxx>
@ -1401,15 +1400,6 @@ bool fgInitSubsystems() {
// AI Traffic manager
globals->add_subsystem("Traffic Manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
if( fgCockpitInit()) {
// Cockpit initialized ok.
} else {
SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
exit(-1);
}
////////////////////////////////////////////////////////////////////
// Add a new 2D panel.
////////////////////////////////////////////////////////////////////

View file

@ -52,8 +52,7 @@
#include <Time/light.hxx>
#include <Aircraft/replay.hxx>
#include <Cockpit/cockpit.hxx>
#include <Cockpit/hud.hxx>
#include <Aircraft/controls.hxx>
#include <Model/panelnode.hxx>
#include <Model/acmodel.hxx>
#include <Scenery/scenery.hxx>

View file

@ -80,8 +80,6 @@
#include <Time/light.hxx>
#include <Time/light.hxx>
#include <Cockpit/panel.hxx>
#include <Cockpit/cockpit.hxx>
#include <Cockpit/hud.hxx>
#include <Model/panelnode.hxx>
#include <Model/modelmgr.hxx>
#include <Model/acmodel.hxx>
@ -98,6 +96,7 @@
#include "CameraGroup.hxx"
#include "FGEventHandler.hxx"
#include <Main/viewer.hxx>
#include <Main/viewmgr.hxx>
using namespace osg;
using namespace simgear;
@ -206,8 +205,6 @@ public:
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushClientAttrib(~0u);
fgCockpitUpdate(&state);
HUD *hud = static_cast<HUD*>(globals->get_subsystem("hud"));
hud->draw(state);