1
0
Fork 0

get rid of struct Point and get_centroid(). Instruments may access *their*

properties directly. This is properly encapsulated already.
This commit is contained in:
mfranz 2006-07-22 10:09:36 +00:00
parent 5c101b8021
commit 64502bdb80
8 changed files with 50 additions and 66 deletions

View file

@ -200,10 +200,6 @@ public:
void init(); void init();
void update(double); void update(double);
typedef struct {
float x, y;
} Point;
// called from Main/renderer.cxx to draw 2D and 3D HUD // called from Main/renderer.cxx to draw 2D and 3D HUD
void draw(); void draw();
@ -380,7 +376,6 @@ public:
protected: protected:
inline float get_span() const { return _scr_span; } inline float get_span() const { return _scr_span; }
inline Point get_centroid() const { return _mid_span; }
inline int get_digits() const { return _digits; } inline int get_digits() const { return _digits; }
inline bool option_vert() const { return (_options & VERT) == VERT; } inline bool option_vert() const { return (_options & VERT) == VERT; }
@ -403,12 +398,12 @@ protected:
string _name; string _name;
int _options; int _options;
float _x, _y, _w, _h; float _x, _y, _w, _h;
float _center_x, _center_y;
private: private:
SGCondition *_condition; SGCondition *_condition;
float _disp_factor; // Multiply by to get numbers shown on scale. float _disp_factor; // Multiply by to get numbers shown on scale.
float _scr_span; // Working values for draw; float _scr_span; // Working values for draw;
Point _mid_span;
int _digits; int _digits;
}; };
@ -633,7 +628,6 @@ private:
bool _draw_arrow; // draw arrow when runway is not visible in HUD bool _draw_arrow; // draw arrow when runway is not visible in HUD
bool _draw_arrow_always; // always draws arrow bool _draw_arrow_always; // always draws arrow
float _left, _right, _top, _bottom; float _left, _right, _top, _bottom;
Point _center;
}; };

View file

@ -51,7 +51,6 @@ void HUD::Gauge::draw(void)
int disp_val = 0; int disp_val = 0;
float vmin = _input.min(); float vmin = _input.min();
float vmax = _input.max(); float vmax = _input.max();
Point mid_scr = get_centroid();
float cur_value = _input.getFloatValue(); float cur_value = _input.getFloatValue();
width = _x + _w; // FIXME huh? width = _x + _w; // FIXME huh?
@ -137,7 +136,7 @@ void HUD::Gauge::draw(void)
lenstr = text_width(buf); lenstr = text_width(buf);
if (option_left() && option_right()) { if (option_left() && option_right()) {
text_x = mid_scr.x - lenstr/2 ; text_x = _center_x - lenstr/2 ;
} else if (option_left()) { } else if (option_left()) {
text_x = marker_xs - lenstr; text_x = marker_xs - lenstr;

View file

@ -84,8 +84,8 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
_scr_span = _w; _scr_span = _w;
} }
_mid_span.x = _x + _w / 2.0; _center_x = _x + _w / 2.0;
_mid_span.y = _y + _h / 2.0; _center_y = _y + _h / 2.0;
} }

View file

@ -96,8 +96,6 @@ void HUD::Ladder::draw(void)
GLdouble eqn_left[4] = {-1.0, 0.0, 0.0, 100.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}; GLdouble eqn_right[4] = {1.0, 0.0, 0.0, 100.0};
Point centroid = get_centroid();
float half_span = _w / 2.0; float half_span = _w / 2.0;
float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS; // FIXME rad/deg conversion float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS; // FIXME rad/deg conversion
alpha = get__aoa(); alpha = get__aoa();
@ -127,7 +125,7 @@ void HUD::Ladder::draw(void)
//************************************************************** //**************************************************************
glPushMatrix(); glPushMatrix();
// define (0, 0) as center of screen // define (0, 0) as center of screen
glTranslatef(centroid.x, centroid.y, 0); glTranslatef(_center_x, _center_y, 0);
// OBJECT STATIC RETICLE // OBJECT STATIC RETICLE
// TYPE FRL (FUSELAGE REFERENCE LINE) // TYPE FRL (FUSELAGE REFERENCE LINE)
@ -307,14 +305,14 @@ void HUD::Ladder::draw(void)
#ifdef ENABLE_SP_FDM #ifdef ENABLE_SP_FDM
if (_alpha_bracket && ihook == 1) { if (_alpha_bracket && ihook == 1) {
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex2f(vel_x - 20 , vel_y - (16 - alpha) * _compression); glVertex2f(vel_x - 20, vel_y - (16 - alpha) * _compression);
glVertex2f(vel_x - 17, vel_y - (16 - alpha) * _compression); glVertex2f(vel_x - 17, vel_y - (16 - alpha) * _compression);
glVertex2f(vel_x - 17, vel_y - (14 - alpha) * _compression); glVertex2f(vel_x - 17, vel_y - (14 - alpha) * _compression);
glVertex2f(vel_x - 20, vel_y - (14 - alpha) * _compression); glVertex2f(vel_x - 20, vel_y - (14 - alpha) * _compression);
glEnd(); glEnd();
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex2f(vel_x + 20 , vel_y - (16 - alpha) * _compression); glVertex2f(vel_x + 20, vel_y - (16 - alpha) * _compression);
glVertex2f(vel_x + 17, vel_y - (16 - alpha) * _compression); glVertex2f(vel_x + 17, vel_y - (16 - alpha) * _compression);
glVertex2f(vel_x + 17, vel_y - (14 - alpha) * _compression); glVertex2f(vel_x + 17, vel_y - (14 - alpha) * _compression);
glVertex2f(vel_x + 20, vel_y - (14 - alpha) * _compression); glVertex2f(vel_x + 20, vel_y - (14 - alpha) * _compression);
@ -635,7 +633,7 @@ void HUD::Ladder::draw(void)
// waypoint marker // waypoint marker
if (fabs(brg-psi) > 10.0) { if (fabs(brg-psi) > 10.0) {
glPushMatrix(); glPushMatrix();
glTranslatef(centroid.x, centroid.y, 0); glTranslatef(_center_x, _center_y, 0);
glTranslatef(vel_x, vel_y, 0); glTranslatef(vel_x, vel_y, 0);
glRotatef(brg - psi, 0.0, 0.0, -1.0); glRotatef(brg - psi, 0.0, 0.0, -1.0);
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);

View file

@ -46,9 +46,8 @@ void HUD::AimingReticle::draw(void)
bool active = _active_condition ? _active_condition->test() : true; bool active = _active_condition ? _active_condition->test() : true;
float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle
Point centroid = get_centroid(); float x = _center_x;
float x = centroid.x; float y = _center_y;
float y = centroid.y;
if (active) { // stadiametric (4.2.4.4) if (active) { // stadiametric (4.2.4.4)
draw_bullet(x, y, _bullet_size); draw_bullet(x, y, _bullet_size);

View file

@ -60,13 +60,13 @@ HUD::Runway::Runway(HUD *hud, const SGPropertyNode *node, float x, float y) :
_view[2] = 640; _view[2] = 640;
_view[3] = 480; _view[3] = 480;
_center.x = _view[2] / 2; _center_x = _view[2] / 2;
_center.y = _view[3] / 2; _center_y = _view[3] / 2;
_left = _center.x - (_w / 2) + _x; _left = _center_x - (_w / 2) + _x;
_right = _center.x + (_w / 2) + _x; _right = _center_x + (_w / 2) + _x;
_bottom = _center.y - (_h / 2) + _y; _bottom = _center_y - (_h / 2) + _y;
_top = _center.y + (_h / 2) + _y; _top = _center_y + (_h / 2) + _y;
} }

View file

@ -66,7 +66,6 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
int oddtype; int oddtype;
// int k; //odd or even values for ticks // FIXME odd scale // int k; //odd or even values for ticks // FIXME odd scale
Point mid_scr = get_centroid();
float cur_value = _input.getFloatValue(); float cur_value = _input.getFloatValue();
if (int(floor(_input.max() + 0.5)) & 1) if (int(floor(_input.max() + 0.5)) & 1)
@ -86,15 +85,15 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
} else { // FIXED } else { // FIXED
vmin = cur_value - _half_width_units; // width units == needle travel vmin = cur_value - _half_width_units; // width units == needle travel
vmax = cur_value + _half_width_units; // or picture unit span. vmax = cur_value + _half_width_units; // or picture unit span.
text_x = mid_scr.x; text_x = _center_x;
text_y = mid_scr.y; text_y = _center_y;
} }
} else { } else {
vmin = cur_value - _half_width_units; // width units == needle travel vmin = cur_value - _half_width_units; // width units == needle travel
vmax = cur_value + _half_width_units; // or picture unit span. vmax = cur_value + _half_width_units; // or picture unit span.
text_x = mid_scr.x; text_x = _center_x;
text_y = mid_scr.y; text_y = _center_y;
} }
@ -142,8 +141,8 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
marker_xs = marker_xe - _w / 3.0; marker_xs = marker_xe - _w / 3.0;
// draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y + _w / 6); // draw_line(marker_xs, _center_y, marker_xe, _center_y + _w / 6);
// draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y - _w / 6); // draw_line(marker_xs, _center_y, marker_xe, _center_y - _w / 6);
// draw pointer // draw pointer
if (_pointer) { if (_pointer) {
@ -156,7 +155,7 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
if (_input.min() >= 0.0) if (_input.min() >= 0.0)
ycentre = _y; ycentre = _y;
else if (_input.max() + _input.min() == 0.0) else if (_input.max() + _input.min() == 0.0)
ycentre = mid_scr.y; ycentre = _center_y;
else if (oddtype) else if (oddtype)
ycentre = _y + (1.0 - _input.min()) * _h ycentre = _y + (1.0 - _input.min()) * _h
/ (_input.max() - _input.min()); / (_input.max() - _input.min());
@ -198,8 +197,8 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
marker_xe = _x + _w / 3.0; marker_xe = _x + _w / 3.0;
// Indicator carrot // Indicator carrot
// draw_line(_x, mid_scr.y + _w / 6, marker_xe, mid_scr.y); // draw_line(_x, _center_y + _w / 6, marker_xe, _center_y);
// draw_line(_x, mid_scr.y - _w / 6, marker_xe, mid_scr.y); // draw_line(_x, _center_y - _w / 6, marker_xe, _center_y);
// draw pointer // draw pointer
if (_pointer) { if (_pointer) {
@ -213,7 +212,7 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
if (_input.min() >= 0.0) if (_input.min() >= 0.0)
ycentre = _y; ycentre = _y;
else if (_input.max() + _input.min() == 0.0) else if (_input.max() + _input.min() == 0.0)
ycentre = mid_scr.y; ycentre = _center_y;
else if (oddtype) else if (oddtype)
ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min()); ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
else else
@ -408,15 +407,15 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
// Tick point adjust // Tick point adjust
marker_ye = _y + _h / 2; marker_ye = _y + _h / 2;
// Bottom arrow // Bottom arrow
// draw_line(mid_scr.x, marker_ye, mid_scr.x - _h / 4, _y); // draw_line(_center_x, marker_ye, _center_x - _h / 4, _y);
// draw_line(mid_scr.x, marker_ye, mid_scr.x + _h / 4, _y); // draw_line(_center_x, marker_ye, _center_x + _h / 4, _y);
// draw pointer // draw pointer
if (_pointer) { if (_pointer) {
if (_pointer_type == MOVING) { if (_pointer_type == MOVING) {
if (!_zoom) { if (!_zoom) {
//Code for Moving Type Pointer //Code for Moving Type Pointer
float xcentre = mid_scr.x; float xcentre = _center_x;
float range = _w; float range = _w;
float xpoint = xcentre + (cur_value * range / _val_span); float xpoint = xcentre + (cur_value * range / _val_span);
float ypoint = _y - _marker_offset; float ypoint = _y - _marker_offset;
@ -441,8 +440,8 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
// Tick point adjust // Tick point adjust
marker_ys = top - _h / 2; marker_ys = top - _h / 2;
// Top arrow // Top arrow
// draw_line(mid_scr.x + _h / 4, _y + _h, mid_scr.x, marker_ys); // draw_line(_center_x + _h / 4, _y + _h, _center_x, marker_ys);
// draw_line(mid_scr.x - _h / 4, _y + _h, mid_scr.x , marker_ys); // draw_line(_center_x - _h / 4, _y + _h, _center_x , marker_ys);
// draw pointer // draw pointer
if (_pointer) { if (_pointer) {
@ -450,7 +449,7 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale)
if (!_zoom) { if (!_zoom) {
//Code for Moving Type Pointer //Code for Moving Type Pointer
float xcentre = mid_scr.x ; float xcentre = _center_x;
float range = _w; float range = _w;
float hgt = _y + _h; float hgt = _y + _h;
float xpoint = xcentre + (cur_value * range / _val_span); float xpoint = xcentre + (cur_value * range / _val_span);
@ -582,7 +581,6 @@ void HUD::Tape::fixed(float x1, float y1, float x2, float y2, float x3, float y3
void HUD::Tape::zoomed_scale(int first, int last) void HUD::Tape::zoomed_scale(int first, int last)
{ {
Point mid_scr = get_centroid();
const int BUFSIZE = 80; const int BUFSIZE = 80;
char buf[BUFSIZE]; char buf[BUFSIZE];
int data[80]; int data[80];
@ -594,7 +592,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
while (first <= last) { while (first <= last) {
if ((first % (int)_major_divs) == 0) { if ((first % (int)_major_divs) == 0) {
data[a] = first; data[a] = first;
a++ ; a++;
} }
first++; first++;
} }
@ -610,9 +608,9 @@ void HUD::Tape::zoomed_scale(int first, int last)
float xstart, yfirst, ycentre, ysecond; float xstart, yfirst, ycentre, ysecond;
float hgt = bottom * 20.0 / 100.0; // 60% of height should be zoomed float hgt = bottom * 20.0 / 100.0; // 60% of height should be zoomed
yfirst = mid_scr.y - hgt; yfirst = _center_y - hgt;
ycentre = mid_scr.y; ycentre = _center_y;
ysecond = mid_scr.y + hgt; ysecond = _center_y + hgt;
float range = hgt * 2; float range = hgt * 2;
int i; int i;
@ -628,7 +626,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
static float ycent, ypoint, xpoint; // FIXME really static? static float ycent, ypoint, xpoint; // FIXME really static?
static float wth; static float wth;
ycent = mid_scr.y; ycent = _center_y;
wth = _x + _w; wth = _x + _w;
if (cur_value <= data[centre + 1]) if (cur_value <= data[centre + 1])
@ -676,7 +674,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
draw_bullet(xstart - 2.5, ycentre, 3.0); draw_bullet(xstart - 2.5, ycentre, 3.0);
} }
yfirst = mid_scr.y - hgt; yfirst = _center_y - hgt;
for (i = 0; i <= incr; i++) { for (i = 0; i <= incr; i++) {
draw_line(xstart, yfirst, xstart - 5.0, yfirst); draw_line(xstart, yfirst, xstart - 5.0, yfirst);
@ -727,7 +725,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
draw_bullet(xstart + 2.5, ycentre, 3.0); draw_bullet(xstart + 2.5, ycentre, 3.0);
} }
yfirst = mid_scr.y - hgt; yfirst = _center_y - hgt;
for (i = 0; i <= incr; i++) { for (i = 0; i <= incr; i++) {
draw_line(xstart, yfirst, xstart + 5.0, yfirst); draw_line(xstart, yfirst, xstart + 5.0, yfirst);
@ -773,9 +771,9 @@ void HUD::Tape::zoomed_scale(int first, int last)
float ystart, xfirst, xcentre, xsecond; float ystart, xfirst, xcentre, xsecond;
float hgt = bottom * 20.0 / 100.0; // 60% of height should be zoomed float hgt = bottom * 20.0 / 100.0; // 60% of height should be zoomed
xfirst = mid_scr.x - hgt; xfirst = _center_x - hgt;
xcentre = mid_scr.x; xcentre = _center_x;
xsecond = mid_scr.x + hgt; xsecond = _center_x + hgt;
float range = hgt * 2; float range = hgt * 2;
int i; int i;
@ -791,7 +789,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
//begin //begin
static float xcent, xpoint, ypoint; // FIXME really static? static float xcent, xpoint, ypoint; // FIXME really static?
xcent = mid_scr.x; xcent = _center_x;
if (cur_value <= data[centre + 1]) if (cur_value <= data[centre + 1])
if (cur_value > data[centre]) { if (cur_value > data[centre]) {
@ -839,7 +837,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
draw_bullet(xcentre, ystart - 2.5, 3.0); draw_bullet(xcentre, ystart - 2.5, 3.0);
} }
xfirst = mid_scr.x - hgt; xfirst = _center_x - hgt;
for (i = 0; i <= incr; i++) { for (i = 0; i <= incr; i++) {
draw_line(xfirst, ystart, xfirst, ystart - 5.0); draw_line(xfirst, ystart, xfirst, ystart - 5.0);
@ -891,7 +889,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
draw_bullet(xcentre, ystart + 2.5, 3.0); draw_bullet(xcentre, ystart + 2.5, 3.0);
} }
xfirst = mid_scr.x - hgt; xfirst = _center_x - hgt;
for (i = 0; i <= incr; i++) { for (i = 0; i <= incr; i++) {
draw_line(xfirst, ystart, xfirst, ystart + 5.0); draw_line(xfirst, ystart, xfirst, ystart + 5.0);

View file

@ -48,17 +48,13 @@ void HUD::TurnBankIndicator::draw(void)
float sideslip = _sideslip.getFloatValue(); float sideslip = _sideslip.getFloatValue();
float span = get_span(); float span = get_span();
Point centroid = get_centroid();
float cen_x = centroid.x;
float cen_y = centroid.y;
float tee_height = _h; float tee_height = _h;
float tee = -tee_height; float tee = -tee_height;
float ss_const = 2 * sideslip * span / 40.0; // sideslip angle pixels per deg (width represents 40 deg) float ss_const = 2 * sideslip * span / 40.0; // sideslip angle pixels per deg (width represents 40 deg)
glPushMatrix(); glPushMatrix();
glTranslatef(cen_x, cen_y, 0.0); glTranslatef(_center_x, _center_y, 0.0);
glRotatef(-bank, 0.0, 0.0, 1.0); glRotatef(-bank, 0.0, 0.0, 1.0);
if (!_bank_scale) { if (!_bank_scale) {
@ -91,10 +87,10 @@ void HUD::TurnBankIndicator::draw(void)
} else { // draw MIL-STD 1878B/4.2.2.4 bank scale } else { // draw MIL-STD 1878B/4.2.2.4 bank scale
draw_line(cen_x - 1.0, _y, cen_x + 1.0, _y); draw_line(_center_x - 1.0, _y, _center_x + 1.0, _y);
draw_line(cen_x - 1.0, _y, cen_x - 1.0, _y + 10.0); draw_line(_center_x - 1.0, _y, _center_x - 1.0, _y + 10.0);
draw_line(cen_x + 1.0, _y, cen_x + 1.0, _y + 10.0); draw_line(_center_x + 1.0, _y, _center_x + 1.0, _y + 10.0);
draw_line(cen_x - 1.0, _y + 10.0, cen_x + 1.0, _y + 10.0); draw_line(_center_x - 1.0, _y + 10.0, _center_x + 1.0, _y + 10.0);
float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5; float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
float xc, yc; float xc, yc;