- extract clipping code to HUD.cxx, allowing generic clipping
and separate ladder clipping - fix acceleration node names - draw 90/-90 bars if there's no zenith/nadir
This commit is contained in:
parent
f08e16cd55
commit
7ba3d5cb53
3 changed files with 111 additions and 35 deletions
|
@ -71,7 +71,8 @@ HUD::HUD() :
|
|||
_font_renderer(new fntRenderer()),
|
||||
_font(0),
|
||||
_font_size(0.0),
|
||||
_style(0)
|
||||
_style(0),
|
||||
_clip_box(0)
|
||||
{
|
||||
SG_LOG(SG_COCKPIT, SG_INFO, "Initializing HUD Instrument");
|
||||
|
||||
|
@ -109,10 +110,14 @@ HUD::~HUD()
|
|||
_scr_heightN->removeChangeListener(this);
|
||||
_unitsN->removeChangeListener(this);
|
||||
delete _font_renderer;
|
||||
delete _clip_box;
|
||||
|
||||
deque<Item *>::const_iterator it, end = _items.end();
|
||||
for (it = _items.begin(); it != end; ++it)
|
||||
delete *it;
|
||||
end = _ladders.end();
|
||||
for (it = _ladders.begin(); it != end; ++it)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,7 +149,7 @@ void HUD::draw(osg::State&)
|
|||
if (!isVisible())
|
||||
return;
|
||||
|
||||
if (!_items.size())
|
||||
if (!_items.size() && !_ladders.size())
|
||||
return;
|
||||
|
||||
if (is3D()) {
|
||||
|
@ -265,6 +270,8 @@ void HUD::common_draw()
|
|||
}
|
||||
|
||||
setColor();
|
||||
_clip_box->set();
|
||||
|
||||
deque<Item *>::const_iterator it, end = _items.end();
|
||||
for (it = _items.begin(); it != end; ++it)
|
||||
if ((*it)->isEnabled())
|
||||
|
@ -280,6 +287,12 @@ void HUD::common_draw()
|
|||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
|
||||
// ladders last, as they can have their own clip planes
|
||||
end = _ladders.end();
|
||||
for (it = _ladders.begin(); it != end; ++it)
|
||||
if ((*it)->isEnabled())
|
||||
(*it)->draw();
|
||||
|
||||
if (isAntialiased()) {
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
|
@ -305,6 +318,7 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
|
|||
if (!level) {
|
||||
SG_LOG(SG_INPUT, TREE, endl << "load " << file);
|
||||
_items.erase(_items.begin(), _items.end());
|
||||
_ladders.erase(_ladders.begin(), _ladders.end());
|
||||
} else if (level > MAXNEST) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "HUD: files nested more than " << MAXNEST << " levels");
|
||||
return 0x1;
|
||||
|
@ -329,6 +343,9 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
|
|||
return 0x8;
|
||||
}
|
||||
|
||||
delete _clip_box;
|
||||
_clip_box = new ClipBox(fgGetNode("/sim/hud/clip"), x, y);
|
||||
|
||||
for (int i = 0; i < root.nChildren(); i++) {
|
||||
SGPropertyNode *n = root.getChild(i);
|
||||
const char *d = n->getStringValue("name", 0);
|
||||
|
@ -372,6 +389,8 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
|
|||
item = static_cast<Item *>(new TurnBankIndicator(this, n, x, y));
|
||||
} else if (!strcmp(name, "ladder")) {
|
||||
item = static_cast<Item *>(new Ladder(this, n, x, y));
|
||||
_ladders.insert(_ladders.begin(), item);
|
||||
continue;
|
||||
} else if (!strcmp(name, "runway")) {
|
||||
item = static_cast<Item *>(new Runway(this, n, x, y));
|
||||
} else if (!strcmp(name, "aiming-reticle")) {
|
||||
|
@ -573,3 +592,47 @@ void TextList::draw()
|
|||
}
|
||||
|
||||
|
||||
ClipBox::ClipBox(const SGPropertyNode *n, float xoffset, float yoffset) :
|
||||
_active(false),
|
||||
_xoffs(xoffset),
|
||||
_yoffs(yoffset)
|
||||
{
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
// const_cast is necessary because ATM there's no matching getChild(const ...)
|
||||
// prototype and getNode(const ..., <bool>) is wrongly interpreted as
|
||||
// getNode(const ..., <int>)
|
||||
_top_node = (const_cast<SGPropertyNode *>(n))->getChild("top", 0, true);
|
||||
_bot_node = (const_cast<SGPropertyNode *>(n))->getChild("bottom", 0, true);
|
||||
_left_node = (const_cast<SGPropertyNode *>(n))->getChild("left", 0, true);
|
||||
_right_node = (const_cast<SGPropertyNode *>(n))->getChild("right", 0, true);
|
||||
|
||||
_left[0] = 1.0, _left[1] = _left[2] = 0.0;
|
||||
_right[0] = -1.0, _right[1] = _right[2] = 0.0;
|
||||
_top[0] = 0.0, _top[1] = -1.0, _top[2] = 0.0;
|
||||
_bot[0] = 0.0, _bot[1] = 1.0, _bot[2] = 0.0;
|
||||
_active = true;
|
||||
}
|
||||
|
||||
|
||||
void ClipBox::set()
|
||||
{
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
_left[3] = -_left_node->getDoubleValue() - _xoffs;
|
||||
_right[3] = _right_node->getDoubleValue() + _xoffs;
|
||||
_bot[3] = -_bot_node->getDoubleValue() - _yoffs;
|
||||
_top[3] = _top_node->getDoubleValue() + _yoffs;
|
||||
|
||||
glClipPlane(GL_CLIP_PLANE0, _top);
|
||||
glEnable(GL_CLIP_PLANE0);
|
||||
glClipPlane(GL_CLIP_PLANE1, _bot);
|
||||
glEnable(GL_CLIP_PLANE1);
|
||||
glClipPlane(GL_CLIP_PLANE2, _left);
|
||||
glEnable(GL_CLIP_PLANE2);
|
||||
glClipPlane(GL_CLIP_PLANE3, _right);
|
||||
glEnable(GL_CLIP_PLANE3);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,26 @@ using std::vector;
|
|||
class FGViewer;
|
||||
|
||||
|
||||
class ClipBox {
|
||||
public:
|
||||
ClipBox(const SGPropertyNode *, float xoffset = 0, float yoffset = 0);
|
||||
void set();
|
||||
|
||||
private:
|
||||
bool _active;
|
||||
float _xoffs, _yoffs;
|
||||
SGConstPropertyNode_ptr _top_node;
|
||||
SGConstPropertyNode_ptr _bot_node;
|
||||
SGConstPropertyNode_ptr _left_node;
|
||||
SGConstPropertyNode_ptr _right_node;
|
||||
GLdouble _top[4];
|
||||
GLdouble _bot[4];
|
||||
GLdouble _left[4];
|
||||
GLdouble _right[4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LineSegment {
|
||||
public:
|
||||
LineSegment(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
|
||||
|
@ -192,6 +212,7 @@ private:
|
|||
class AimingReticle;
|
||||
|
||||
deque<Item *> _items;
|
||||
deque<Item *> _ladders;
|
||||
|
||||
SGPropertyNode_ptr _current;
|
||||
SGPropertyNode_ptr _visibility;
|
||||
|
@ -219,6 +240,7 @@ private:
|
|||
float _font_size;
|
||||
int _style;
|
||||
|
||||
ClipBox *_clip_box;
|
||||
TextList _text_list;
|
||||
LineList _line_list;
|
||||
LineList _stipple_line_list;
|
||||
|
@ -486,6 +508,7 @@ private:
|
|||
class HUD::Ladder : public Item {
|
||||
public:
|
||||
Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
~Ladder();
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
|
@ -516,7 +539,6 @@ private:
|
|||
float _vmin;
|
||||
float _compression;
|
||||
bool _dynamic_origin;
|
||||
bool _clip_plane;
|
||||
bool _frl; // fuselage reference line
|
||||
bool _target_spot;
|
||||
bool _target_markers;
|
||||
|
@ -533,6 +555,7 @@ private:
|
|||
bool _nadir;
|
||||
bool _hat;
|
||||
|
||||
ClipBox *_clip_box;
|
||||
// The Ladder has its own temporary display lists
|
||||
TextList _locTextList;
|
||||
LineList _locLineList;
|
||||
|
@ -591,5 +614,4 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
#endif // _HUD_HXX
|
||||
|
|
|
@ -35,9 +35,9 @@ float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"
|
|||
float get__Vx() { return fgGetFloat("/velocities/uBody-fps"); }
|
||||
float get__Vy() { return fgGetFloat("/velocities/vBody-fps"); }
|
||||
float get__Vz() { return fgGetFloat("/velocities/wBody-fps"); }
|
||||
float get__Ax() { return fgGetFloat("/acclerations/pilot/x-accel-fps_sec"); }
|
||||
float get__Ay() { return fgGetFloat("/acclerations/pilot/y-accel-fps_sec"); }
|
||||
float get__Az() { return fgGetFloat("/acclerations/pilot/z-accel-fps_sec"); }
|
||||
float get__Ax() { return fgGetFloat("/accelerations/pilot/x-accel-fps_sec"); }
|
||||
float get__Ay() { return fgGetFloat("/accelerations/pilot/y-accel-fps_sec"); }
|
||||
float get__Az() { return fgGetFloat("/accelerations/pilot/z-accel-fps_sec"); }
|
||||
float get__alpha() { return fgGetFloat("/orientation/alpha-deg"); }
|
||||
float get__beta() { return fgGetFloat("/orientation/side-slip-deg"); }
|
||||
#undef ENABLE_SP_FDM
|
||||
|
@ -55,7 +55,6 @@ HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
|||
_tick_length(n->getFloatValue("tick-length")),
|
||||
_compression(n->getFloatValue("compression-factor")),
|
||||
_dynamic_origin(n->getBoolValue("enable-dynamic-origin")),
|
||||
_clip_plane(n->getBoolValue("enable-clip-plane")),
|
||||
_frl(n->getBoolValue("enable-fuselage-ref-line")),
|
||||
_target_spot(n->getBoolValue("enable-target-spot")),
|
||||
_target_markers(n->getBoolValue("enable-target-markers")),
|
||||
|
@ -70,7 +69,8 @@ HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
|||
_waypoint_marker(n->getBoolValue("enable-waypoint-marker")),
|
||||
_zenith(n->getBoolValue("enable-zenith")),
|
||||
_nadir(n->getBoolValue("enable-nadir")),
|
||||
_hat(n->getBoolValue("enable-hat"))
|
||||
_hat(n->getBoolValue("enable-hat")),
|
||||
_clip_box(new ClipBox(n->getNode("clip")))
|
||||
{
|
||||
const char *t = n->getStringValue("type");
|
||||
_type = strcmp(t, "climb-dive") ? PITCH : CLIMB_DIVE;
|
||||
|
@ -83,6 +83,11 @@ HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
|||
}
|
||||
|
||||
|
||||
HUD::Ladder::~Ladder()
|
||||
{
|
||||
delete _clip_box;
|
||||
}
|
||||
|
||||
void HUD::Ladder::draw(void)
|
||||
{
|
||||
if (!_pitch.isValid() || !_roll.isValid())
|
||||
|
@ -191,23 +196,6 @@ void HUD::Ladder::draw(void)
|
|||
glEnd();
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
// Clipping coordinates for ladder to be input from xml file
|
||||
// Clip hud ladder. FIXME, these should be configurable, but they
|
||||
// have always been hardcoded here.
|
||||
if (_clip_plane) {
|
||||
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};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
// OBJECT MOVING RETICLE
|
||||
// TYPE VELOCITY VECTOR
|
||||
|
@ -423,6 +411,8 @@ void HUD::Ladder::draw(void)
|
|||
|
||||
//****************************************************************
|
||||
|
||||
_clip_box->set();
|
||||
|
||||
if (_dynamic_origin) {
|
||||
// ladder moves with alpha/beta offset projected onto horizon
|
||||
// line (so that the horizon line always aligns with the
|
||||
|
@ -469,17 +459,10 @@ void HUD::Ladder::draw(void)
|
|||
else // _type == CLIMB_DIVE
|
||||
y = float(i - actslope) * _compression + .5;
|
||||
|
||||
// draw symbols
|
||||
if (i == 90 && _zenith)
|
||||
draw_zenith(0.0, y);
|
||||
|
||||
if (i == -90 && _nadir)
|
||||
draw_nadir(0.0, y);
|
||||
|
||||
// OBJECT LADDER MARK
|
||||
// TYPE LINE
|
||||
// ATTRIB - ON CONDITION
|
||||
// draw appraoch glide slope marker
|
||||
// draw approach glide slope marker
|
||||
#ifdef ENABLE_SP_FDM
|
||||
if (_glide_slope_marker && ihook) {
|
||||
draw_line(-half_span + 15, (_glide_slope - actslope) * _compression,
|
||||
|
@ -489,7 +472,15 @@ void HUD::Ladder::draw(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (i > 85 || i < -85)
|
||||
// draw symbols
|
||||
if (i == 90 && _zenith)
|
||||
draw_zenith(0.0, y);
|
||||
else if (i == -90 && _nadir)
|
||||
draw_nadir(0.0, y);
|
||||
|
||||
if (_zenith && i > 85 || i > 90)
|
||||
continue;
|
||||
if (_nadir && i < -85 || i < -90)
|
||||
continue;
|
||||
|
||||
lo.x = -half_span;
|
||||
|
|
Loading…
Reference in a new issue