From d1a9512c91b4560698f0539970175e35a1c7f40d Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 14 Jun 2006 16:57:38 +0000 Subject: [PATCH] remove readTBI() and let the fgTBI_instr class read its properties --- src/Cockpit/hud.cxx | 45 +------ src/Cockpit/hud.hxx | 30 +---- src/Cockpit/hud_tbi.cxx | 288 ++++++++++++++++++---------------------- 3 files changed, 139 insertions(+), 224 deletions(-) diff --git a/src/Cockpit/hud.cxx b/src/Cockpit/hud.cxx index a8b7f5dd6..23a0c3ade 100644 --- a/src/Cockpit/hud.cxx +++ b/src/Cockpit/hud.cxx @@ -83,7 +83,6 @@ int HUD_style = 0; float HUD_matrix[16]; - static string name; static int x; static int y; @@ -103,9 +102,6 @@ static int dp_showing = 0; static string label_format; static string prelabel; static string postlabel; -static float maxBankAngle; -static float maxSlipAngle; -static UINT gap_width; static bool tick_bottom; static bool tick_top; static bool tick_right; @@ -123,8 +119,6 @@ static string length_tick; static float radius; static int divisions; static int zoom; -static bool tsi; -static float rad; static FLTFNPTR load_fn; @@ -132,7 +126,6 @@ static FLTFNPTR load_fn; int readHud( istream &input ); int readInstrument ( const SGPropertyNode * node); static instr_item * readCard ( const SGPropertyNode * node); -static instr_item * readTBI( const SGPropertyNode * node); static void drawHUD(); static void fgUpdateHUDVirtual(); @@ -290,42 +283,6 @@ readCard(const SGPropertyNode * node) return p; }// end readCard -static instr_item * -readTBI(const SGPropertyNode * node) -{ - - instr_item *p; - - name = node->getStringValue("name"); - x = node->getIntValue("x"); - y = node->getIntValue("y"); - width = node->getIntValue("width"); - height = node->getIntValue("height"); - maxBankAngle = node->getFloatValue("maxBankAngle"); - maxSlipAngle = node->getFloatValue("maxSlipAngle"); - gap_width = node->getIntValue("gap_width"); - working = node->getBoolValue("working"); - tsi = node->getBoolValue("tsi"); - rad = node->getFloatValue("rad"); - - SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name); - - - p = (instr_item *) new fgTBI_instr( x, - y, - width, - height, - get_roll, - get_sideslip, - maxBankAngle, - maxSlipAngle, - gap_width, - working, - tsi, - rad); - - return p; -} //end readTBI static instr_item * readRunway(const SGPropertyNode * node) { @@ -396,7 +353,7 @@ int readInstrument(const SGPropertyNode * node) if (tbi_group != 0) { int nTbis = tbi_group->nChildren(); for (int j = 0; j < nTbis; j++) { - HIptr = readTBI(tbi_group->getChild(j)); + HIptr = static_cast(new fgTBI_instr(tbi_group->getChild(j))); HUD_deque.insert( HUD_deque.begin(), HIptr); } } diff --git a/src/Cockpit/hud.hxx b/src/Cockpit/hud.hxx index 8591bb9b2..fcf26b1d1 100644 --- a/src/Cockpit/hud.hxx +++ b/src/Cockpit/hud.hxx @@ -626,8 +626,7 @@ public: // // fgRunway_instr This class is responsible for rendering the active runway // in the hud (if visible). -class runway_instr : public instr_item -{ +class runway_instr : public instr_item { private: void boundPoint(const sgdVec3& v, sgdVec3& m); bool boundOutsidePoints(sgdVec3& v, sgdVec3& m); @@ -841,8 +840,8 @@ public: virtual void draw( void ) { } }; -class fgTBI_instr : public dual_instr_item -{ + +class fgTBI_instr : public dual_instr_item { private: UINT BankLimit; UINT SlewLimit; @@ -851,27 +850,12 @@ private: float rad; public: - fgTBI_instr( int x, - int y, - UINT width, - UINT height, - FLTFNPTR chn1_source, - FLTFNPTR chn2_source, - float maxBankAngle, - float maxSlipAngle, - UINT gap_width, - bool working, - bool tsi, - float rad); - - fgTBI_instr( const fgTBI_instr & image); - - ~fgTBI_instr(); + fgTBI_instr(const SGPropertyNode *); - UINT bank_limit( void ) { return BankLimit;} - UINT slew_limit( void ) { return SlewLimit;} + UINT bank_limit(void) { return BankLimit; } + UINT slew_limit(void) { return SlewLimit; } - virtual void draw( void ); // Required method in base class + virtual void draw(void); }; diff --git a/src/Cockpit/hud_tbi.cxx b/src/Cockpit/hud_tbi.cxx index 4dfdf8a97..a602bcdb1 100644 --- a/src/Cockpit/hud_tbi.cxx +++ b/src/Cockpit/hud_tbi.cxx @@ -1,54 +1,43 @@ +// +// Turn Bank Indicator +// +#include #include "hud.hxx" -#include - - -//============ Top of fgTBI_instr class member definitions ============== - -fgTBI_instr::fgTBI_instr( - 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) : - dual_instr_item( x, y, width, height, - chn1_source, - chn2_source, - working, - HUDS_TOP), - BankLimit ((int)(maxBankAngle)), - SlewLimit ((int)(maxSlipAngle)), - scr_hole (gap_width) -{ - tsi=tsivalue; - rad=radius; -} +// 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 -fgTBI_instr::~fgTBI_instr() {} +// 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 fgTBI_instr & image) : - dual_instr_item( (const dual_instr_item &) image), - BankLimit( image.BankLimit), - SlewLimit( image.SlewLimit), - scr_hole ( image.scr_hole ) +fgTBI_instr::fgTBI_instr(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"), + 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_INFO, "Done reading TBI instrument" + << node->getStringValue("name", "[NONE]")); } -// -// Draws a Turn Bank Indicator on the screen -// - -void fgTBI_instr :: draw( void ) +void fgTBI_instr::draw(void) { float bank_angle, sideslip_angle; float ss_const; // sideslip angle pixels per rad @@ -61,147 +50,132 @@ void fgTBI_instr :: draw( void ) POINT centroid = get_centroid(); int tee_height = My_box.bottom; - bank_angle = current_ch2(); // Roll limit +/- 30 degrees + 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; + 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; + 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; + 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 + 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 ); + if (!scr_hole) { + glVertex2f(-fspan, zero); + glVertex2f(fspan, zero); } else { - glVertex2f( -fspan, zero ); - glVertex2f( -hole, zero ); - glVertex2f( hole, zero ); - glVertex2f( fspan, zero ); + 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 ); + 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); + glVertex2f(ss_const, -hole); + glVertex2f(ss_const + hole, zero); + glVertex2f(ss_const, hole); + glVertex2f(ss_const - hole, zero); glEnd(); } else { //if tsi enabled - // float factor = My_box.right / 6.0; + 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); - 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; - 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 ; + 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); + // 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); -//second n fifth lines + x1 = xc + r * cos(285.0 * SGD_DEGREES_TO_RADIANS); + y1 = yc + r * sin(285.0 * SGD_DEGREES_TO_RADIANS); - 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); + 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); -//third n fourth lines + // 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 (265.0 * SGD_DEGREES_TO_RADIANS); - y1= yc + r * sin (265.0 * SGD_DEGREES_TO_RADIANS); + 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); - x2= xc + r2 * cos (265.0 * SGD_DEGREES_TO_RADIANS); - y2= yc + r2 * sin (265.0 * SGD_DEGREES_TO_RADIANS); + // third n fourth lines + x1 = xc + r * cos(265.0 * SGD_DEGREES_TO_RADIANS); + y1 = yc + r * 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(265.0 * SGD_DEGREES_TO_RADIANS); + y2 = yc + r2 * sin(265.0 * SGD_DEGREES_TO_RADIANS); + drawOneLine(x1, y1, x2, y2); - x2= xc + r2 * cos (275.0 * SGD_DEGREES_TO_RADIANS); - y2= yc + r2 * sin (275.0 * SGD_DEGREES_TO_RADIANS); + 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); - //to draw marker - - - + // draw marker float valbank, valsideslip, sideslip; - r = rad + 5.0; //5 is added to get a gap + r = rad + 5.0; // add gap + // upper polygon - bank_angle = current_ch2(); + bank_angle = current_ch2(); - bank= bank_angle * SGD_RADIANS_TO_DEGREES; // Roll limit +/- 30 degrees + bank = bank_angle * SGD_RADIANS_TO_DEGREES; // Roll limit +/- 30 degrees if (bank > BankLimit) bank = BankLimit; if (bank < -1.0*BankLimit) @@ -210,51 +184,51 @@ void fgTBI_instr :: draw( void ) 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; + sideslip = sideslip_angle * SGD_RADIANS_TO_DEGREES; if (sideslip > SlewLimit) sideslip = SlewLimit; - if (sideslip < -1.0*SlewLimit) - sideslip = -1.0*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); + // 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); + 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); + 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); + // 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); + 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); + 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); + 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); + 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); + 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); -- 2.39.5