first commit
This commit is contained in:
734
src/Instrumentation/HUD/HUD.cxx
Normal file
734
src/Instrumentation/HUD/HUD.cxx
Normal file
@@ -0,0 +1,734 @@
|
||||
// HUD.cxx -- Head Up Display
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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 <simgear/structure/exception.hxx>
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/io/iostreams/sgstream.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <osg/GLU>
|
||||
|
||||
#include "fnt.h"
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Viewer/viewmgr.hxx>
|
||||
#include <Viewer/view.hxx>
|
||||
#include <GUI/FGFontCache.hxx>
|
||||
#include <GUI/gui.h> // for guiErrorMessage
|
||||
|
||||
#include "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
using std::endl;
|
||||
using std::ifstream;
|
||||
using std::string;
|
||||
using std::deque;
|
||||
using std::vector;
|
||||
|
||||
static float clamp(float f)
|
||||
{
|
||||
return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f;
|
||||
}
|
||||
|
||||
HUD::Input::Input(const SGPropertyNode *n, float factor, float offset,
|
||||
float min, float max) :
|
||||
_valid(false),
|
||||
_property(0),
|
||||
_damped(SGLimitsf::max())
|
||||
{
|
||||
if (!n)
|
||||
return;
|
||||
_factor = n->getFloatValue("factor", factor);
|
||||
_offset = n->getFloatValue("offset", offset);
|
||||
_min = n->getFloatValue("min", min);
|
||||
_max = n->getFloatValue("max", max);
|
||||
_coeff = 1.0 - 1.0 / powf(10, fabs(n->getFloatValue("damp", 0.0)));
|
||||
SGPropertyNode *p = ((SGPropertyNode *)n)->getNode("property", false);
|
||||
if (p) {
|
||||
string path = p->getStringValue();
|
||||
if (!path.empty()) {
|
||||
_property = fgGetNode(path, true);
|
||||
_valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HUD::HUD() :
|
||||
_currentPath(fgGetNode("/sim/hud/current-path", true)),
|
||||
_currentColor(fgGetNode("/sim/hud/current-color", true)),
|
||||
_visibility(fgGetNode("/sim/hud/visibility[1]", true)),
|
||||
_3DenabledN(fgGetNode("/sim/hud/enable3d[1]", 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),
|
||||
_loaded(false),
|
||||
_antialiased(false),
|
||||
_transparent(false),
|
||||
_a(0.67), // FIXME better names
|
||||
_cl(0.01),
|
||||
//
|
||||
_scr_widthN(fgGetNode("/sim/startup/xsize", true)),
|
||||
_scr_heightN(fgGetNode("/sim/startup/ysize", true)),
|
||||
_unitsN(fgGetNode("/sim/startup/units", true)),
|
||||
_timer(0.0),
|
||||
//
|
||||
_font_renderer(new fntRenderer()),
|
||||
_font(0),
|
||||
_font_size(0.0),
|
||||
_style(0),
|
||||
_listener_active(false),
|
||||
_clip_box(0)
|
||||
{
|
||||
SG_LOG(SG_COCKPIT, SG_INFO, "Initializing HUD Instrument");
|
||||
|
||||
SGPropertyNode* hud = fgGetNode("/sim/hud");
|
||||
hud->addChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
HUD::~HUD()
|
||||
{
|
||||
SGPropertyNode* hud = fgGetNode("/sim/hud");
|
||||
hud->removeChangeListener(this);
|
||||
|
||||
deinit();
|
||||
}
|
||||
|
||||
|
||||
void HUD::init()
|
||||
{
|
||||
std::string fontName;
|
||||
if (!_font) {
|
||||
fontName = fgGetString("/sim/hud/font/name", "Helvetica.txf");
|
||||
_font = FGFontCache::instance()->getTexFont(fontName);
|
||||
}
|
||||
if (!_font)
|
||||
throw sg_io_exception("/sim/hud/font/name is not a texture font",
|
||||
sg_location(fontName));
|
||||
|
||||
_font_size = fgGetFloat("/sim/hud/font/size", 8);
|
||||
_font_renderer->setFont(_font);
|
||||
_font_renderer->setPointSize(_font_size);
|
||||
_text_list.setFont(_font_renderer);
|
||||
_loaded = false;
|
||||
|
||||
currentColorChanged();
|
||||
_currentPath->fireValueChanged();
|
||||
}
|
||||
|
||||
void HUD::deinit()
|
||||
{
|
||||
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;
|
||||
|
||||
_items.clear();
|
||||
_ladders.clear();
|
||||
|
||||
delete _clip_box;
|
||||
_clip_box = NULL;
|
||||
|
||||
_loaded = false;
|
||||
}
|
||||
|
||||
void HUD::reinit()
|
||||
{
|
||||
deinit();
|
||||
_currentPath->fireValueChanged();
|
||||
}
|
||||
|
||||
void HUD::update(double dt)
|
||||
{
|
||||
_timer += dt;
|
||||
}
|
||||
|
||||
|
||||
void HUD::draw(osg::State&)
|
||||
{
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
if (_items.empty() && _ladders.empty())
|
||||
return;
|
||||
|
||||
if (is3D()) {
|
||||
draw3D();
|
||||
return;
|
||||
}
|
||||
|
||||
const float normal_aspect = 640.0f / 480.0f;
|
||||
// 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;
|
||||
draw2D(-adjust, 0.0f, 640.0f + adjust, 480.0f);
|
||||
|
||||
} else {
|
||||
float aspect_adjust = normal_aspect / current_aspect;
|
||||
float adjust = 240.0f * aspect_adjust - 240.0f;
|
||||
draw2D(0.0f, -adjust, 640.0f, 480.0f + adjust);
|
||||
}
|
||||
|
||||
glViewport(0, 0, _scr_width, _scr_height);
|
||||
}
|
||||
|
||||
|
||||
void HUD::draw3D()
|
||||
{
|
||||
using namespace osg;
|
||||
flightgear::View* 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.0 / 320, 1.0 / 240, 1);
|
||||
glTranslatef(-320, -240, -1);
|
||||
|
||||
common_draw();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void HUD::draw2D(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();
|
||||
|
||||
common_draw();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void HUD::common_draw()
|
||||
{
|
||||
_text_list.erase();
|
||||
_line_list.erase();
|
||||
_stipple_line_list.erase();
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
if (isTransparent())
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
else
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
if (isAntialiased()) {
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glAlphaFunc(GL_GREATER, alphaClamp());
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
|
||||
//glLineWidth(1.5);
|
||||
} else {
|
||||
//glLineWidth(1.0);
|
||||
}
|
||||
|
||||
setColor();
|
||||
_clip_box->set();
|
||||
|
||||
deque<Item *>::const_iterator it, end = _items.end();
|
||||
for (it = _items.begin(); it != end; ++it)
|
||||
if ((*it)->isEnabled())
|
||||
(*it)->draw();
|
||||
|
||||
_text_list.draw();
|
||||
_line_list.draw();
|
||||
|
||||
if (! _stipple_line_list.empty()) {
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple(1, 0x00FF);
|
||||
_stipple_line_list.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();
|
||||
|
||||
_clip_box->unset();
|
||||
|
||||
if (isAntialiased()) {
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
//glLineWidth(1.0);
|
||||
}
|
||||
|
||||
if (isTransparent())
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
int HUD::load(const char *file, float x, float y, int level, const string& indent)
|
||||
{
|
||||
const sgDebugPriority TREE = SG_INFO;
|
||||
const int MAXNEST = 10;
|
||||
|
||||
SGPath path(globals->resolve_maybe_aircraft_path(file));
|
||||
if (path.isNull())
|
||||
{
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot find configuration file '" << file << "'.");
|
||||
return 0x2;
|
||||
}
|
||||
|
||||
if (!level) {
|
||||
SG_LOG(SG_INPUT, TREE, "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;
|
||||
} else if (!file || !file[0]) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid filename ");
|
||||
return 0x2;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
sg_ifstream input(path);
|
||||
if (!input.good()) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from '" << path << "'");
|
||||
return 0x4;
|
||||
}
|
||||
|
||||
SGPropertyNode root;
|
||||
try {
|
||||
readProperties(input, &root);
|
||||
} catch (const sg_exception &e) {
|
||||
input.close();
|
||||
guiErrorMessage("HUD: Error ", e);
|
||||
return 0x8;
|
||||
}
|
||||
|
||||
delete _clip_box;
|
||||
_clip_box = new ClipBox(fgGetNode("/sim/hud/clipping"), x, y);
|
||||
|
||||
for (int i = 0; i < root.nChildren(); i++) {
|
||||
SGPropertyNode *n = root.getChild(i);
|
||||
string d = n->getStringValue("name", "");
|
||||
string desc;
|
||||
if (!d.empty())
|
||||
desc = string(": \"") + d + '"';
|
||||
|
||||
const string name = n->getNameString();
|
||||
if (name == "name") {
|
||||
continue;
|
||||
|
||||
} else if (name == "enable3d") {
|
||||
// set in the tree so that valueChanged() picks it up
|
||||
_3DenabledN->setBoolValue(n->getBoolValue());
|
||||
continue;
|
||||
|
||||
} else if (name == "import") {
|
||||
string fn = n->getStringValue("path", "");
|
||||
float xoffs = n->getFloatValue("x-offset", 0.0f);
|
||||
float yoffs = n->getFloatValue("y-offset", 0.0f);
|
||||
|
||||
SG_LOG(SG_INPUT, TREE, indent << "|__import " << fn << desc);
|
||||
|
||||
string ind = indent + string(i + 1 < root.nChildren() ? "| " : " ");
|
||||
ret |= load(fn.c_str(), x + xoffs, y + yoffs, level + 1, ind);
|
||||
continue;
|
||||
}
|
||||
|
||||
SG_LOG(SG_INPUT, TREE, indent << "|__" << name << desc);
|
||||
|
||||
Item *item;
|
||||
if (name == "label") {
|
||||
item = static_cast<Item *>(new Label(this, n, x, y));
|
||||
} else if (name == "gauge") {
|
||||
item = static_cast<Item *>(new Gauge(this, n, x, y));
|
||||
} else if (name == "tape") {
|
||||
item = static_cast<Item *>(new Tape(this, n, x, y));
|
||||
} else if (name == "dial") {
|
||||
item = static_cast<Item *>(new Dial(this, n, x, y));
|
||||
} else if (name == "turn-bank-indicator") {
|
||||
item = static_cast<Item *>(new TurnBankIndicator(this, n, x, y));
|
||||
} else if (name == "ladder") {
|
||||
item = static_cast<Item *>(new Ladder(this, n, x, y));
|
||||
_ladders.insert(_ladders.begin(), item);
|
||||
continue;
|
||||
} else if (name == "runway") {
|
||||
item = static_cast<Item *>(new Runway(this, n, x, y));
|
||||
} else if (name == "aiming-reticle") {
|
||||
item = static_cast<Item *>(new AimingReticle(this, n, x, y));
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, TREE, indent << " \\...unsupported!");
|
||||
continue;
|
||||
}
|
||||
_items.insert(_items.begin(), item);
|
||||
}
|
||||
input.close();
|
||||
SG_LOG(SG_INPUT, TREE, indent);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void HUD::valueChanged(SGPropertyNode *node)
|
||||
{
|
||||
if (_listener_active)
|
||||
return;
|
||||
_listener_active = true;
|
||||
|
||||
bool loadNow = false;
|
||||
_visible = _visibility->getBoolValue();
|
||||
if (_visible && !_loaded) {
|
||||
loadNow = true;
|
||||
}
|
||||
|
||||
if (node->getNameString() == "current-path" && _visible) {
|
||||
loadNow = true;
|
||||
}
|
||||
|
||||
if (loadNow) {
|
||||
int pathIndex = _currentPath->getIntValue();
|
||||
SGPropertyNode* pathNode = fgGetNode("/sim/hud/path", pathIndex);
|
||||
std::string path("Huds/default.xml");
|
||||
if (pathNode && pathNode->hasValue()) {
|
||||
path = pathNode->getStringValue();
|
||||
SG_LOG(SG_INSTR, SG_INFO, "will load Hud from " << path);
|
||||
}
|
||||
|
||||
_loaded = true;
|
||||
load(path.c_str());
|
||||
}
|
||||
|
||||
if (node->getNameString() == "current-color") {
|
||||
currentColorChanged();
|
||||
}
|
||||
|
||||
_scr_width = _scr_widthN->getIntValue();
|
||||
_scr_height = _scr_heightN->getIntValue();
|
||||
|
||||
|
||||
_3Denabled = _3DenabledN->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());
|
||||
|
||||
_units = _unitsN->getStringValue() != "feet" ? METER : FEET;
|
||||
_listener_active = false;
|
||||
}
|
||||
|
||||
void HUD::currentColorChanged()
|
||||
{
|
||||
SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
|
||||
int index = _currentColor->getIntValue();
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
n = n->getChild("color", index, false);
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void HUD::setColor() const
|
||||
{
|
||||
if (_antialiased)
|
||||
glColor4f(_r, _g, _b, _a);
|
||||
else
|
||||
glColor3f(_r, _g, _b);
|
||||
}
|
||||
|
||||
|
||||
void HUD::textAlign(fntRenderer *rend, const char *s, int align,
|
||||
float *x, float *y, float *l, float *r, float *b, float *t)
|
||||
{
|
||||
fntFont *font = rend->getFont();
|
||||
float gap = font->getGap();
|
||||
float left, right, bot, top;
|
||||
font->getBBox(s, rend->getPointSize(), rend->getSlant(), &left, &right, &bot, &top);
|
||||
|
||||
if (align & HUD::HCENTER)
|
||||
*x -= left - gap + (right - left - gap) / 2.0;
|
||||
else if (align & HUD::RIGHT)
|
||||
*x -= right;
|
||||
else if (align & HUD::LEFT)
|
||||
*x -= left;
|
||||
|
||||
if (align & HUD::VCENTER)
|
||||
*y -= bot + (top - bot) / 2.0;
|
||||
else if (align & HUD::TOP)
|
||||
*y -= top;
|
||||
else if (align & HUD::BOTTOM)
|
||||
*y -= bot;
|
||||
|
||||
*l = *x + left;
|
||||
*r = *x + right;
|
||||
*b = *y + bot;
|
||||
*t = *y + top;
|
||||
}
|
||||
|
||||
|
||||
// HUDText -- text container for TextList vector
|
||||
HUDText::HUDText(fntRenderer *fnt, float x, float y, const char *s, int align, int d) :
|
||||
_fnt(fnt),
|
||||
_x(x),
|
||||
_y(y),
|
||||
_digits(d)
|
||||
{
|
||||
strncpy(_msg, s, BUFSIZE - 1);
|
||||
_msg[BUFSIZE - 1] = '\0';
|
||||
|
||||
if (!align || !s[0])
|
||||
return;
|
||||
|
||||
float ign;
|
||||
HUD::textAlign(fnt, s, align, &_x, &_y, &ign, &ign, &ign, &ign);
|
||||
}
|
||||
|
||||
|
||||
void HUDText::draw()
|
||||
{
|
||||
if (!_digits) { // show all digits in same size
|
||||
_fnt->start2f(_x, _y);
|
||||
_fnt->puts(_msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME
|
||||
// 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.
|
||||
|
||||
int c = 0, i = 0;
|
||||
char *t = _msg;
|
||||
int p = 4;
|
||||
|
||||
if (t[0] == '-') {
|
||||
//if negative value then increase the c and p values
|
||||
//for '-' sign.
|
||||
c++; // was moved to the comment. Unintentionally? TODO
|
||||
p++;
|
||||
}
|
||||
char *tmp = _msg;
|
||||
while (tmp[i] != '\0') {
|
||||
if ((tmp[i] >= '0') && (tmp[i] <= '9'))
|
||||
c++;
|
||||
i++;
|
||||
}
|
||||
|
||||
float orig_size = _fnt->getPointSize();
|
||||
if (c > p) {
|
||||
_fnt->setPointSize(orig_size * 0.8);
|
||||
int p1 = c - 3;
|
||||
char *tmp1 = _msg + p1;
|
||||
int p2 = p1 * 8;
|
||||
|
||||
_fnt->start2f(_x + p2, _y);
|
||||
_fnt->puts(tmp1);
|
||||
|
||||
_fnt->setPointSize(orig_size * 1.2);
|
||||
char tmp2[BUFSIZE];
|
||||
strncpy(tmp2, _msg, p1);
|
||||
tmp2[p1] = '\0';
|
||||
|
||||
_fnt->start2f(_x, _y);
|
||||
_fnt->puts(tmp2);
|
||||
} else {
|
||||
_fnt->setPointSize(orig_size * 1.2);
|
||||
_fnt->start2f(_x, _y);
|
||||
_fnt->puts(tmp);
|
||||
}
|
||||
_fnt->setPointSize(orig_size);
|
||||
}
|
||||
|
||||
|
||||
// Register the subsystem.
|
||||
SGSubsystemMgr::Registrant<HUD> registrantHUD;
|
||||
|
||||
|
||||
void TextList::align(const char *s, int align, float *x, float *y,
|
||||
float *l, float *r, float *b, float *t) const
|
||||
{
|
||||
HUD::textAlign(_font, s, align, x, y, l, r, b, t);
|
||||
}
|
||||
|
||||
|
||||
void TextList::draw()
|
||||
{
|
||||
assert(_font);
|
||||
|
||||
// FIXME
|
||||
glPushAttrib(GL_COLOR_BUFFER_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
_font->begin();
|
||||
vector<HUDText>::iterator it, end = _list.end();
|
||||
for (it = _list.begin(); it != end; ++it)
|
||||
it->draw();
|
||||
_font->end();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void ClipBox::unset()
|
||||
{
|
||||
if (_active) {
|
||||
glDisable(GL_CLIP_PLANE0);
|
||||
glDisable(GL_CLIP_PLANE1);
|
||||
glDisable(GL_CLIP_PLANE2);
|
||||
glDisable(GL_CLIP_PLANE3);
|
||||
}
|
||||
}
|
||||
232
src/Instrumentation/HUD/HUD.hxx
Normal file
232
src/Instrumentation/HUD/HUD.hxx
Normal file
@@ -0,0 +1,232 @@
|
||||
// HUD.hxx -- Head Up Display
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifndef _HUD_HXX
|
||||
#define _HUD_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#include <osg/State>
|
||||
|
||||
#include <simgear/math/SGLimits.hxx>
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
|
||||
class FGFontCache;
|
||||
class fntRenderer;
|
||||
class fntTexFont;
|
||||
class FGViewer;
|
||||
class ClipBox;
|
||||
|
||||
class LineSegment
|
||||
{
|
||||
public:
|
||||
LineSegment(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
|
||||
: _x0(x0), _y0(y0), _x1(x1), _y1(y1) {}
|
||||
|
||||
void draw() const {
|
||||
glVertex2f(_x0, _y0);
|
||||
glVertex2f(_x1, _y1);
|
||||
}
|
||||
|
||||
private:
|
||||
GLfloat _x0, _y0, _x1, _y1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LineList
|
||||
{
|
||||
public:
|
||||
void add(const LineSegment& seg) { _list.push_back(seg); }
|
||||
void erase() { _list.erase(_list.begin(), _list.end()); }
|
||||
inline unsigned int size() const { return _list.size(); }
|
||||
inline bool empty() const { return _list.empty(); }
|
||||
void draw() {
|
||||
glBegin(GL_LINES);
|
||||
std::vector<LineSegment>::const_iterator it, end = _list.end();
|
||||
for (it = _list.begin(); it != end; ++it)
|
||||
it->draw();
|
||||
glEnd();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<LineSegment> _list;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUDText
|
||||
{
|
||||
public:
|
||||
HUDText(fntRenderer *f, float x, float y, const char *s, int align = 0, int digits = 0);
|
||||
void draw();
|
||||
|
||||
private:
|
||||
fntRenderer *_fnt;
|
||||
float _x, _y;
|
||||
int _digits;
|
||||
static const int BUFSIZE = 64;
|
||||
char _msg[BUFSIZE];
|
||||
};
|
||||
|
||||
|
||||
|
||||
class TextList
|
||||
{
|
||||
public:
|
||||
TextList() { _font = 0; }
|
||||
|
||||
void setFont(fntRenderer *Renderer) { _font = Renderer; }
|
||||
void add(float x, float y, const char *s, int align = 0, int digit = 0) {
|
||||
_list.push_back(HUDText(_font, x, y, s, align, digit));
|
||||
}
|
||||
void erase() { _list.erase(_list.begin(), _list.end()); }
|
||||
void align(const char *s, int align, float *x, float *y,
|
||||
float *l, float *r, float *b, float *t) const;
|
||||
void draw();
|
||||
|
||||
private:
|
||||
fntRenderer *_font;
|
||||
std::vector<HUDText> _list;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUD : public SGSubsystem,
|
||||
public SGPropertyChangeListener
|
||||
{
|
||||
public:
|
||||
HUD();
|
||||
~HUD();
|
||||
|
||||
// Subsystem API.
|
||||
void init() override;
|
||||
void reinit() override;
|
||||
void update(double) override;
|
||||
|
||||
// Subsystem identification.
|
||||
static const char* staticSubsystemClassId() { return "hud"; }
|
||||
|
||||
// called from Main/renderer.cxx to draw 2D and 3D HUD
|
||||
void draw(osg::State&);
|
||||
|
||||
// listener callback to read various HUD related properties
|
||||
void valueChanged(SGPropertyNode *);
|
||||
// set current glColor
|
||||
void setColor() const;
|
||||
inline bool isVisible() const { return _visible; }
|
||||
inline bool isAntialiased() const { return _antialiased; }
|
||||
inline bool isTransparent() const { return _transparent; }
|
||||
inline bool is3D() const { return _3Denabled; }
|
||||
inline float alphaClamp() const { return _cl; }
|
||||
inline double timer() const { return _timer; }
|
||||
static void textAlign(fntRenderer *rend, const char *s, int align, float *x, float *y,
|
||||
float *l, float *r, float *b, float *t);
|
||||
|
||||
enum Units { FEET, METER };
|
||||
Units getUnits() const { return _units; }
|
||||
|
||||
enum {
|
||||
HORIZONTAL = 0x0000, // keep that at zero?
|
||||
VERTICAL = 0x0001,
|
||||
TOP = 0x0002,
|
||||
BOTTOM = 0x0004,
|
||||
LEFT = 0x0008,
|
||||
RIGHT = 0x0010,
|
||||
NOTICKS = 0x0020,
|
||||
NOTEXT = 0x0040,
|
||||
BOTH = (LEFT|RIGHT),
|
||||
|
||||
// for alignment (with LEFT, RIGHT, TOP, BOTTOM)
|
||||
HCENTER = 0x0080,
|
||||
VCENTER = 0x0100,
|
||||
CENTER = (HCENTER|VCENTER),
|
||||
};
|
||||
|
||||
protected:
|
||||
void common_draw();
|
||||
int load(const char *, float x = 320.0f, float y = 240.0f,
|
||||
int level = 0, const std::string& indent = "");
|
||||
|
||||
private:
|
||||
void deinit();
|
||||
|
||||
void draw3D();
|
||||
void draw2D(GLfloat, GLfloat, GLfloat, GLfloat);
|
||||
|
||||
void currentColorChanged();
|
||||
|
||||
class Input;
|
||||
class Item;
|
||||
class Label;
|
||||
class Scale;
|
||||
class Gauge;
|
||||
class Tape;
|
||||
class Dial;
|
||||
class TurnBankIndicator;
|
||||
class Ladder;
|
||||
class Runway;
|
||||
class AimingReticle;
|
||||
|
||||
std::deque<Item *> _items;
|
||||
std::deque<Item *> _ladders;
|
||||
|
||||
SGPropertyNode_ptr _currentPath;
|
||||
SGPropertyNode_ptr _currentColor;
|
||||
SGPropertyNode_ptr _visibility;
|
||||
SGPropertyNode_ptr _3DenabledN;
|
||||
SGPropertyNode_ptr _antialiasing;
|
||||
SGPropertyNode_ptr _transparency;
|
||||
SGPropertyNode_ptr _red, _green, _blue, _alpha;
|
||||
SGPropertyNode_ptr _alpha_clamp;
|
||||
SGPropertyNode_ptr _brightness;
|
||||
bool _visible;
|
||||
bool _loaded;
|
||||
bool _3Denabled;
|
||||
bool _antialiased;
|
||||
bool _transparent;
|
||||
float _r, _g, _b, _a, _cl;
|
||||
|
||||
SGPropertyNode_ptr _scr_widthN, _scr_heightN;
|
||||
int _scr_width, _scr_height;
|
||||
SGPropertyNode_ptr _unitsN;
|
||||
Units _units;
|
||||
double _timer;
|
||||
|
||||
fntRenderer *_font_renderer;
|
||||
FGFontCache *_font_cache;
|
||||
fntTexFont *_font;
|
||||
float _font_size;
|
||||
int _style;
|
||||
bool _listener_active;
|
||||
|
||||
ClipBox *_clip_box;
|
||||
TextList _text_list;
|
||||
LineList _line_list;
|
||||
LineList _stipple_line_list;
|
||||
};
|
||||
|
||||
#endif // _HUD_HXX
|
||||
87
src/Instrumentation/HUD/HUD_dial.cxx
Normal file
87
src/Instrumentation/HUD/HUD_dial.cxx
Normal file
@@ -0,0 +1,87 @@
|
||||
// HUD_dial.cxx -- HUD Dial Instrument
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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 "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
HUD::Dial::Dial(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Scale(hud, n, x, y),
|
||||
_radius(n->getFloatValue("radius")),
|
||||
_divisions(n->getIntValue("divisions"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HUD::Dial::draw(void)
|
||||
{
|
||||
if (!_input.isValid())
|
||||
return;
|
||||
|
||||
const int BUFSIZE = 80;
|
||||
char buf[BUFSIZE];
|
||||
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glPointSize(3.0);
|
||||
|
||||
float incr = 360.0 / _divisions;
|
||||
for (float i = 0.0; i < 360.0; i += incr) {
|
||||
float i1 = i * SGD_DEGREES_TO_RADIANS;
|
||||
float x1 = _x + _radius * cos(i1);
|
||||
float y1 = _y + _radius * sin(i1);
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2f(x1, y1);
|
||||
glEnd();
|
||||
}
|
||||
glPointSize(1.0);
|
||||
glDisable(GL_POINT_SMOOTH);
|
||||
|
||||
|
||||
float offset = 90.0 * SGD_DEGREES_TO_RADIANS;
|
||||
const float R = 10.0; //size of carrot
|
||||
float theta = _input.getFloatValue();
|
||||
|
||||
float theta1 = -theta * SGD_DEGREES_TO_RADIANS + offset;
|
||||
float x1 = _x + _radius * cos(theta1);
|
||||
float y1 = _y + _radius * sin(theta1);
|
||||
float x2 = x1 - R * cos(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
|
||||
float y2 = y1 - R * sin(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
|
||||
float x3 = x1 - R * cos(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
|
||||
float y3 = y1 - R * sin(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
|
||||
|
||||
// draw carrot
|
||||
draw_line(x1, y1, x2, y2);
|
||||
draw_line(x1, y1, x3, y3);
|
||||
snprintf(buf, BUFSIZE, "%3.1f\n", theta);
|
||||
|
||||
// draw value
|
||||
int l = abs((int)theta);
|
||||
if (l) {
|
||||
if (l < 10)
|
||||
draw_text(_x, _y, buf, 0);
|
||||
else if (l < 100)
|
||||
draw_text(_x - 1.0, _y, buf, 0);
|
||||
else if (l < 360)
|
||||
draw_text(_x - 2.0, _y, buf, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
264
src/Instrumentation/HUD/HUD_gauge.cxx
Normal file
264
src/Instrumentation/HUD/HUD_gauge.cxx
Normal file
@@ -0,0 +1,264 @@
|
||||
// HUD_gauge.cxx -- HUD Gauge Instrument
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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 "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
HUD::Gauge::Gauge(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Scale(hud, n, x, y)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// 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 HUD::Gauge::draw(void)
|
||||
{
|
||||
if (!_input.isValid())
|
||||
return;
|
||||
|
||||
float marker_xs, marker_xe;
|
||||
float marker_ys, marker_ye;
|
||||
float text_y;
|
||||
int i;
|
||||
const int BUFSIZE = 80;
|
||||
char buf[BUFSIZE];
|
||||
bool condition;
|
||||
int disp_val = 0;
|
||||
float vmin = _input.min();
|
||||
float vmax = _input.max();
|
||||
float cur_value = _input.getFloatValue();
|
||||
|
||||
float right = _x + _w;
|
||||
float top = _y + _h;
|
||||
float bottom_4 = _h / 4.0; // FIXME
|
||||
float right_4 = _w / 4.0;
|
||||
|
||||
// Draw the basic markings for the scale...
|
||||
if (option_vert()) { // Vertical scale
|
||||
// Bottom tick bar
|
||||
draw_line(_x, _y, right, _y);
|
||||
|
||||
// Top tick bar
|
||||
draw_line(_x, top, right, top);
|
||||
|
||||
marker_xs = _x;
|
||||
marker_xe = right;
|
||||
|
||||
if (option_left()) { // Read left, so line down right side
|
||||
draw_line(right, _y, right, top);
|
||||
marker_xs = marker_xe - _w / 2.0; // Adjust tick
|
||||
}
|
||||
|
||||
if (option_right()) { // Read right, so down left sides
|
||||
draw_line(_x, _y, _x, top);
|
||||
marker_xe = _x + _w / 2.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 (option_both()) {
|
||||
marker_ye = marker_xs;
|
||||
marker_xs = marker_xe;
|
||||
marker_xe = marker_ye;
|
||||
}
|
||||
|
||||
// Work through from bottom to top of scale. Calculating where to put
|
||||
// minor and major ticks.
|
||||
|
||||
if (!option_noticks()) { // If not no ticks...:)
|
||||
// Calculate x marker offsets
|
||||
int last = (int)vmax + 1;
|
||||
i = (int)vmin;
|
||||
|
||||
for (; i < last; i++) {
|
||||
// Calculate the location of this tick
|
||||
marker_ys = _y + (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 (_minor_divs) { // Minor tick marks
|
||||
if (!(i % (int)_minor_divs)) {
|
||||
if (option_left() && option_right()) {
|
||||
draw_line(_x, marker_ys, marker_xs - 4, marker_ys);
|
||||
draw_line(marker_xe + 4, marker_ys, right, marker_ys);
|
||||
|
||||
} else if (option_left()) {
|
||||
draw_line(marker_xs + 4, marker_ys, marker_xe, marker_ys);
|
||||
} else {
|
||||
draw_line(marker_xs, marker_ys, marker_xe - 4, 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 (_major_divs) { // Major tick mark
|
||||
if (!(i % (int)_major_divs)) {
|
||||
if (option_left() && option_right()) {
|
||||
draw_line(_x, marker_ys, marker_xs, marker_ys);
|
||||
draw_line(marker_xe, marker_ys, right, marker_ys);
|
||||
} else {
|
||||
draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
|
||||
}
|
||||
|
||||
if (!option_notext()) {
|
||||
disp_val = i;
|
||||
snprintf(buf, BUFSIZE, "%d",
|
||||
int(disp_val * _input.factor()/*+.5*/)); /// was data_scaling(), which makes no sense
|
||||
|
||||
if (option_left() && option_right())
|
||||
draw_text(_center_x, marker_ys, buf, CENTER);
|
||||
else if (option_left())
|
||||
draw_text(marker_xs, marker_ys, buf, RIGHT|VCENTER);
|
||||
else
|
||||
draw_text(marker_xe, marker_ys, buf, LEFT|VCENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that the scale is drawn, we draw in the pointer(s).
|
||||
text_y = _y + ((cur_value - vmin) * factor() /*+.5f*/);
|
||||
|
||||
if (option_right()) {
|
||||
_hud->_line_list.add(LineSegment(_x, text_y + right_4, marker_xe, text_y));
|
||||
_hud->_line_list.add(LineSegment(marker_xe, text_y, _x, text_y - right_4));
|
||||
}
|
||||
if (option_left()) {
|
||||
_hud->_line_list.add(LineSegment(right, text_y + right_4, marker_xs, text_y));
|
||||
_hud->_line_list.add(LineSegment(marker_xs, text_y, right, text_y - right_4));
|
||||
}
|
||||
// End if VERTICAL SCALE TYPE
|
||||
|
||||
} else { // Horizontal scale by default
|
||||
// left tick bar
|
||||
draw_line(_x, _y, _x, top);
|
||||
|
||||
// right tick bar
|
||||
draw_line(right, _y, right, top );
|
||||
|
||||
marker_ys = _y; // Starting point for
|
||||
marker_ye = top; // tick y location calcs
|
||||
marker_xs = _x + (cur_value - vmin) * factor() /*+ .5f*/;
|
||||
|
||||
if (option_top()) {
|
||||
// Bottom box line
|
||||
draw_line(_x, _y, right, _y);
|
||||
|
||||
marker_ye = _y + _h / 2.0; // Tick point adjust
|
||||
// Bottom arrow
|
||||
_hud->_line_list.add(LineSegment(marker_xs - bottom_4, _y, marker_xs, marker_ye));
|
||||
_hud->_line_list.add(LineSegment(marker_xs, marker_ye, marker_xs + bottom_4, _y));
|
||||
}
|
||||
|
||||
if (option_bottom()) {
|
||||
// Top box line
|
||||
draw_line(_x, top, right, top);
|
||||
// Tick point adjust
|
||||
marker_ys = top - _h / 2.0;
|
||||
|
||||
// Top arrow
|
||||
_hud->_line_list.add(LineSegment(marker_xs + bottom_4, top, marker_xs, marker_ys));
|
||||
_hud->_line_list.add(LineSegment(marker_xs, marker_ys, marker_xs - bottom_4, top));
|
||||
}
|
||||
|
||||
|
||||
int last = (int)vmax + 1;
|
||||
i = (int)vmin;
|
||||
for (; i <last ; i++) {
|
||||
condition = true;
|
||||
if (!_modulo && i < _input.min())
|
||||
condition = false;
|
||||
|
||||
if (condition) {
|
||||
marker_xs = _x + (i - vmin) * factor()/* +.5f*/;
|
||||
// marker_xs = _x + (int)((i - vmin) * factor() + .5f);
|
||||
if (_minor_divs) {
|
||||
if (!(i % (int)_minor_divs)) {
|
||||
// draw in ticks only if they aren't too close to the edge.
|
||||
if (((marker_xs + 5) > _x)
|
||||
|| ((marker_xs - 5) < right)) {
|
||||
|
||||
if (option_both()) {
|
||||
draw_line(marker_xs, _y, marker_xs, marker_ys - 4);
|
||||
draw_line(marker_xs, marker_ye + 4, marker_xs, top);
|
||||
|
||||
} else if (option_top()) {
|
||||
draw_line(marker_xs, marker_ys, marker_xs, marker_ye - 4);
|
||||
} else {
|
||||
draw_line(marker_xs, marker_ys + 4, marker_xs, marker_ye);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_major_divs) {
|
||||
if (!(i % (int)_major_divs)) {
|
||||
if (_modulo) {
|
||||
if (disp_val < 0) {
|
||||
while (disp_val < 0)
|
||||
disp_val += _modulo;
|
||||
}
|
||||
disp_val = i % (int)_modulo;
|
||||
} else {
|
||||
disp_val = i;
|
||||
}
|
||||
snprintf(buf, BUFSIZE, "%d",
|
||||
int(disp_val * _input.factor()/* +.5*/)); // was data_scaling(), which makes no sense
|
||||
|
||||
// Draw major ticks and text only if far enough from the edge.
|
||||
if (((marker_xs - 10) > _x)
|
||||
&& ((marker_xs + 10) < right)) {
|
||||
if (option_both()) {
|
||||
draw_line(marker_xs, _y, marker_xs, marker_ys);
|
||||
draw_line(marker_xs, marker_ye, marker_xs, top);
|
||||
|
||||
if (!option_notext())
|
||||
draw_text(marker_xs, marker_ys, buf, CENTER);
|
||||
|
||||
} else {
|
||||
draw_line(marker_xs, marker_ys, marker_xs, marker_ye);
|
||||
|
||||
if (!option_notext()) {
|
||||
if (option_top())
|
||||
draw_text(marker_xs, top, buf, TOP|HCENTER);
|
||||
else
|
||||
draw_text(marker_xs, _y, buf, BOTTOM|HCENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
213
src/Instrumentation/HUD/HUD_instrument.cxx
Normal file
213
src/Instrumentation/HUD/HUD_instrument.cxx
Normal file
@@ -0,0 +1,213 @@
|
||||
// HUD_instrument.cxx -- HUD Common Instrument Base
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/math/SGLimits.hxx>
|
||||
#include <simgear/props/condition.hxx>
|
||||
|
||||
#include "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
|
||||
using std::vector;
|
||||
|
||||
HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
_hud(hud),
|
||||
_name(n->getStringValue("name", "[unnamed]")),
|
||||
_options(0),
|
||||
_condition(0),
|
||||
_digits(n->getIntValue("digits"))
|
||||
{
|
||||
const SGPropertyNode *node = n->getNode("condition");
|
||||
if (node)
|
||||
_condition = sgReadCondition(globals->get_props(), node);
|
||||
|
||||
_x = n->getFloatValue("x") + x;
|
||||
_y = n->getFloatValue("y") + y;
|
||||
_w = n->getFloatValue("width");
|
||||
_h = n->getFloatValue("height");
|
||||
|
||||
vector<SGPropertyNode_ptr> opt = n->getChildren("option");
|
||||
for (unsigned int i = 0; i < opt.size(); i++) {
|
||||
string o = opt[i]->getStringValue();
|
||||
if (o == "vertical")
|
||||
_options |= VERTICAL;
|
||||
else if (o == "horizontal")
|
||||
_options |= HORIZONTAL;
|
||||
else if (o == "top")
|
||||
_options |= TOP;
|
||||
else if (o == "left")
|
||||
_options |= LEFT;
|
||||
else if (o == "bottom")
|
||||
_options |= BOTTOM;
|
||||
else if (o == "right")
|
||||
_options |= RIGHT;
|
||||
else if (o == "both")
|
||||
_options |= (LEFT|RIGHT);
|
||||
else if (o == "noticks")
|
||||
_options |= NOTICKS;
|
||||
else if (o == "notext")
|
||||
_options |= NOTEXT;
|
||||
else
|
||||
SG_LOG(SG_INPUT, SG_WARN, "HUD: unsupported option: " << o);
|
||||
}
|
||||
|
||||
// Set up convenience values for centroid of the box and
|
||||
// the span values according to orientation
|
||||
|
||||
if (_options & VERTICAL) {
|
||||
_scr_span = _h;
|
||||
} else {
|
||||
_scr_span = _w;
|
||||
}
|
||||
|
||||
_center_x = _x + _w / 2.0;
|
||||
_center_y = _y + _h / 2.0;
|
||||
}
|
||||
|
||||
|
||||
bool HUD::Item::isEnabled()
|
||||
{
|
||||
return _condition ? _condition->test() : true;
|
||||
}
|
||||
|
||||
|
||||
void HUD::Item::draw_line(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
_hud->_line_list.add(LineSegment(x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
|
||||
void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
_hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
|
||||
void HUD::Item::draw_text(float x, float y, const char *msg, int align, int digit)
|
||||
{
|
||||
_hud->_text_list.add(x, y, msg, align, digit);
|
||||
}
|
||||
|
||||
|
||||
void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
|
||||
{
|
||||
float step = SG_PI / r;
|
||||
double prevX = r;
|
||||
double prevY = 0.0;
|
||||
for (float alpha = step; alpha < SG_PI * 2.0; alpha += step) {
|
||||
float x = r * cos(alpha);
|
||||
float y = r * sin(alpha);
|
||||
_hud->_line_list.add(LineSegment(prevX + xoffs, prevY + yoffs,
|
||||
x + xoffs, y + yoffs));
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
}
|
||||
}
|
||||
|
||||
void HUD::Item::draw_arc(float xoffs, float yoffs, float t0, float t1, float r) const
|
||||
{
|
||||
float step = SG_PI / r;
|
||||
t0 = t0 * SG_DEGREES_TO_RADIANS;
|
||||
t1 = t1 * SG_DEGREES_TO_RADIANS;
|
||||
|
||||
double prevX = r * cos(t0);
|
||||
double prevY = r * sin(t0);
|
||||
for (float alpha = t0 + step; alpha < t1; alpha += step) {
|
||||
float x = r * cos(alpha);
|
||||
float y = r * sin(alpha);
|
||||
_hud->_line_list.add(LineSegment(prevX + xoffs, prevY + yoffs,
|
||||
x + xoffs, y + yoffs));
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
}
|
||||
}
|
||||
|
||||
void HUD::Item::draw_bullet(float x, float y, float size)
|
||||
{
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glPointSize(size);
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2f(x, y);
|
||||
glEnd();
|
||||
|
||||
glPointSize(1.0);
|
||||
glDisable(GL_POINT_SMOOTH);
|
||||
}
|
||||
|
||||
|
||||
// make sure the format matches '[ -+#]?\d*(\.\d*)?(l?[df]|s)'
|
||||
//
|
||||
HUD::Item::Format HUD::Item::check_format(const char *f) const
|
||||
{
|
||||
bool l = false;
|
||||
Format fmt = STRING;
|
||||
|
||||
for (; *f; f++) {
|
||||
if (*f == '%') {
|
||||
if (f[1] == '%')
|
||||
f++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*f++ != '%')
|
||||
return NONE;
|
||||
if (*f == ' ' || *f == '+' || *f == '-' || *f == '#')
|
||||
f++;
|
||||
while (*f && isdigit(*f))
|
||||
f++;
|
||||
if (*f == '.') {
|
||||
f++;
|
||||
while (*f && isdigit(*f))
|
||||
f++;
|
||||
}
|
||||
if (*f == 'l')
|
||||
l = true, f++;
|
||||
|
||||
if (*f == 'd')
|
||||
fmt = l ? LONG : INT;
|
||||
else if (*f == 'f')
|
||||
fmt = l ? DOUBLE : FLOAT;
|
||||
else if (*f == 's') {
|
||||
if (l)
|
||||
return INVALID;
|
||||
fmt = STRING;
|
||||
} else
|
||||
return INVALID;
|
||||
|
||||
for (++f; *f; f++) {
|
||||
if (*f == '%') {
|
||||
if (f[1] == '%')
|
||||
f++;
|
||||
else
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
|
||||
185
src/Instrumentation/HUD/HUD_label.cxx
Normal file
185
src/Instrumentation/HUD/HUD_label.cxx
Normal file
@@ -0,0 +1,185 @@
|
||||
// HUD_label.cxx -- HUD Label
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
|
||||
HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Item(hud, n, x, y),
|
||||
_input(n->getNode("input", false)),
|
||||
_box(n->getBoolValue("box", false)),
|
||||
_pointer_width(n->getFloatValue("pointer-width", 7.0)),
|
||||
_pointer_length(n->getFloatValue("pointer-length", 5.0)),
|
||||
_blink_condition(0),
|
||||
_blink_interval(n->getFloatValue("blinking/interval", -1.0f)),
|
||||
_blink_target(0.0),
|
||||
_blink_state(true)
|
||||
{
|
||||
const SGPropertyNode *node = n->getNode("blinking/condition");
|
||||
if (node)
|
||||
_blink_condition = sgReadCondition(globals->get_props(), node);
|
||||
|
||||
string halign = n->getStringValue("halign", "center");
|
||||
if (halign == "left")
|
||||
_halign = LEFT;
|
||||
else if (halign == "right")
|
||||
_halign = RIGHT;
|
||||
else
|
||||
_halign = HCENTER;
|
||||
|
||||
_halign |= VCENTER;
|
||||
|
||||
string pre = n->getStringValue("prefix", "");
|
||||
string post = n->getStringValue("postfix", "");
|
||||
string fmt = n->getStringValue("format", "");
|
||||
|
||||
if (!pre.empty())
|
||||
_format = pre;
|
||||
|
||||
if (!fmt.empty())
|
||||
_format += fmt;
|
||||
else
|
||||
_format += "%s";
|
||||
|
||||
if (!post.empty())
|
||||
_format += post;
|
||||
|
||||
_mode = check_format(_format.c_str());
|
||||
if (_mode == INVALID) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid format '" << _format.c_str()
|
||||
<< "' in <label> '" << _name << '\'');
|
||||
_format = "INVALID";
|
||||
_mode = NONE;
|
||||
}
|
||||
|
||||
blink();
|
||||
}
|
||||
|
||||
|
||||
void HUD::Label::draw(void)
|
||||
{
|
||||
if (!((_mode == NONE || _input.isValid()) && blink()))
|
||||
return;
|
||||
|
||||
if (_box) {
|
||||
float l, r, p;
|
||||
float pw = _pointer_width / 2.0;
|
||||
|
||||
l = _center_x - pw;
|
||||
r = _center_x + pw;
|
||||
bool draw_parallel = fabs(_pointer_width - _w) > 2.0; // draw lines left and right of arrow?
|
||||
|
||||
if (option_bottom()) {
|
||||
if (draw_parallel) {
|
||||
draw_line(_x, _y, l, _y);
|
||||
draw_line(r, _y, _x + _w, _y);
|
||||
}
|
||||
p = _y - _pointer_length;
|
||||
draw_line(l, _y, _center_x, p);
|
||||
draw_line(_center_x, p, r, _y);
|
||||
} else
|
||||
draw_line(_x, _y, _x + _w, _y);
|
||||
|
||||
if (option_top()) {
|
||||
if (draw_parallel) {
|
||||
draw_line(_x, _y + _h, l, _y + _h);
|
||||
draw_line(r, _y + _h, _x + _w, _y + _h);
|
||||
}
|
||||
p = _y + _h + _pointer_length;
|
||||
draw_line(l, _y + _h, _center_x, p);
|
||||
draw_line(_center_x, p, r, _y + _h);
|
||||
} else
|
||||
draw_line(_x + _w, _y + _h, _x, _y + _h);
|
||||
|
||||
l = _center_y - pw;
|
||||
r = _center_y + pw;
|
||||
draw_parallel = fabs(_pointer_width - _h) > 2.0;
|
||||
|
||||
if (option_left()) {
|
||||
if (draw_parallel) {
|
||||
draw_line(_x, _y, _x, l);
|
||||
draw_line(_x, r, _x, _y + _h);
|
||||
}
|
||||
p = _x - _pointer_length;
|
||||
draw_line(_x, l, p, _center_y);
|
||||
draw_line(p, _center_y, _x, r);
|
||||
} else
|
||||
draw_line(_x, _y + _h, _x, _y);
|
||||
|
||||
if (option_right()) {
|
||||
if (draw_parallel) {
|
||||
draw_line(_x + _w, _y, _x + _w, l);
|
||||
draw_line(_x + _w, r, _x + _w, _y + _h);
|
||||
}
|
||||
p = _x + _w + _pointer_length;
|
||||
draw_line(_x + _w, l, p, _center_y);
|
||||
draw_line(p, _center_y, _x + _w, r);
|
||||
} else
|
||||
draw_line(_x + _w, _y, _x + _w, _y + _h);
|
||||
}
|
||||
|
||||
const int BUFSIZE = 256;
|
||||
char buf[BUFSIZE+1];
|
||||
buf[ BUFSIZE] = '\0'; // Be sure to terminate properly
|
||||
if (_mode == NONE)
|
||||
snprintf(buf, BUFSIZE, _format.c_str(), 0);
|
||||
else if (_mode == STRING)
|
||||
snprintf(buf, BUFSIZE, _format.c_str(), _input.getStringValue().c_str());
|
||||
else if (_mode == INT)
|
||||
snprintf(buf, BUFSIZE, _format.c_str(), int(_input.getFloatValue()));
|
||||
else if (_mode == LONG)
|
||||
snprintf(buf, BUFSIZE, _format.c_str(), long(_input.getFloatValue()));
|
||||
else if (_mode == FLOAT)
|
||||
snprintf(buf, BUFSIZE, _format.c_str(), float(_input.getFloatValue()));
|
||||
else if (_mode == DOUBLE) // not really supported yet
|
||||
snprintf(buf, BUFSIZE, _format.c_str(), double(_input.getFloatValue()));
|
||||
|
||||
if (_halign & HCENTER)
|
||||
draw_text(_center_x, _center_y, buf, _halign, get_digits());
|
||||
else if (_halign & LEFT)
|
||||
draw_text(_x, _center_y, buf, _halign, get_digits());
|
||||
else // if (_halign & RIGHT)
|
||||
draw_text(_x + _w, _center_y, buf, _halign, get_digits());
|
||||
}
|
||||
|
||||
|
||||
bool HUD::Label::blink()
|
||||
{
|
||||
if (_blink_interval < 0.0f)
|
||||
return true;
|
||||
|
||||
if (_blink_condition && !_blink_condition->test())
|
||||
return true;
|
||||
|
||||
if (_hud->timer() < _blink_target)
|
||||
return _blink_state;
|
||||
|
||||
_blink_target = _hud->timer() + _blink_interval;
|
||||
return _blink_state = !_blink_state;
|
||||
}
|
||||
|
||||
|
||||
764
src/Instrumentation/HUD/HUD_ladder.cxx
Normal file
764
src/Instrumentation/HUD/HUD_ladder.cxx
Normal file
@@ -0,0 +1,764 @@
|
||||
// HUD_ladder.cxx -- HUD Ladder Instrument
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
#include <simgear/math/SGGeometry.hxx>
|
||||
#include <Viewer/view.hxx>
|
||||
|
||||
#include "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
using std::string;
|
||||
|
||||
// FIXME
|
||||
static float get__heading() { return fgGetFloat("/orientation/heading-deg") * M_PI / 180.0; }
|
||||
static float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"); }
|
||||
static float get__Vx() { return fgGetFloat("/velocities/uBody-fps"); }
|
||||
static float get__Vy() { return fgGetFloat("/velocities/vBody-fps"); }
|
||||
static float get__Vz() { return fgGetFloat("/velocities/wBody-fps"); }
|
||||
static float get__Ax() { return fgGetFloat("/accelerations/pilot/x-accel-fps_sec"); }
|
||||
static float get__Ay() { return fgGetFloat("/accelerations/pilot/y-accel-fps_sec"); }
|
||||
static float get__Az() { return fgGetFloat("/accelerations/pilot/z-accel-fps_sec"); }
|
||||
static float get__alpha() { return fgGetFloat("/orientation/alpha-deg"); }
|
||||
static float get__beta() { return fgGetFloat("/orientation/side-slip-deg"); }
|
||||
#undef ENABLE_SP_FDM
|
||||
|
||||
|
||||
HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Item(hud, n, x, y),
|
||||
_pitch(n->getNode("pitch-input", false)),
|
||||
_roll(n->getNode("roll-input", false)),
|
||||
_width_units(int(n->getFloatValue("display-span"))),
|
||||
_div_units(int(fabs(n->getFloatValue("divisions")))),
|
||||
_scr_hole(fabs(n->getFloatValue("screen-hole")) * 0.5f),
|
||||
_zero_bar_overlength(n->getFloatValue("zero-bar-overlength", 10)),
|
||||
_dive_bar_angle(n->getBoolValue("enable-dive-bar-angle")),
|
||||
_tick_length(n->getFloatValue("tick-length")),
|
||||
_compression(n->getFloatValue("compression-factor")),
|
||||
_dynamic_origin(n->getBoolValue("enable-dynamic-origin")),
|
||||
_frl(n->getBoolValue("enable-fuselage-ref-line")),
|
||||
_target_spot(n->getBoolValue("enable-target-spot")),
|
||||
_target_markers(n->getBoolValue("enable-target-markers")),
|
||||
_velocity_vector(n->getBoolValue("enable-velocity-vector")),
|
||||
_ground_velocity_vector(n->getBoolValue("enable-ground-velocity-vector")),
|
||||
_drift_marker(n->getBoolValue("enable-drift-marker")),
|
||||
_alpha_bracket(n->getBoolValue("enable-alpha-bracket")),
|
||||
_energy_marker(n->getBoolValue("enable-energy-marker")),
|
||||
_climb_dive_marker(n->getBoolValue("enable-climb-dive-marker")),
|
||||
_glide_slope_marker(n->getBoolValue("enable-glide-slope-marker")),
|
||||
_glide_slope(n->getFloatValue("glide-slope", -4.0)),
|
||||
_energy_worm(n->getBoolValue("enable-energy-marker")),
|
||||
_waypoint_marker(n->getBoolValue("enable-waypoint-marker")),
|
||||
_zenith(n->getBoolValue("enable-zenith")),
|
||||
_nadir(n->getBoolValue("enable-nadir")),
|
||||
_hat(n->getBoolValue("enable-hat")),
|
||||
_clip_box(new ClipBox(n->getNode("clipping")))
|
||||
{
|
||||
string t = n->getStringValue("type");
|
||||
_type = t != "climb-dive" ? PITCH : CLIMB_DIVE;
|
||||
|
||||
if (!_width_units)
|
||||
_width_units = 45;
|
||||
|
||||
_vmax = _width_units / 2;
|
||||
_vmin = -_vmax;
|
||||
}
|
||||
|
||||
|
||||
HUD::Ladder::~Ladder()
|
||||
{
|
||||
delete _clip_box;
|
||||
}
|
||||
|
||||
void HUD::Ladder::draw(void)
|
||||
{
|
||||
if (!_pitch.isValid() || !_roll.isValid())
|
||||
return;
|
||||
|
||||
float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS;
|
||||
float pitch_value = _pitch.getFloatValue();
|
||||
|
||||
//**************************************************************
|
||||
glPushMatrix();
|
||||
glTranslatef(_center_x, _center_y, 0);
|
||||
|
||||
// OBJECT STATIC RETICLE
|
||||
// TYPE FRL (FUSELAGE REFERENCE LINE)
|
||||
// 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 _ _ ) // TODO (-> HUD_misc.cxx)
|
||||
// \/\/
|
||||
|
||||
//****************************************************************
|
||||
// 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
|
||||
float xvvr, /* yvvr, */ Vxx = 0.0, Vyy = 0.0, Vzz = 0.0;
|
||||
float Axx = 0.0, Ayy = 0.0, Azz = 0.0, total_vel = 0.0, pot_slope; //, t1;
|
||||
float up_vel, ground_vel, actslope = 0.0, psi = 0.0;
|
||||
float vel_x = 0.0, vel_y = 0.0, drift;
|
||||
float alpha;
|
||||
|
||||
if (_ground_velocity_vector || _velocity_vector) {
|
||||
Vxx = get__Vx();
|
||||
Vyy = get__Vy();
|
||||
Vzz = get__Vz();
|
||||
}
|
||||
|
||||
if (_ground_velocity_vector) {
|
||||
double gvel_x = atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES * _compression;
|
||||
double gvel_y = -atan2(Vzz, Vxx) * SGD_RADIANS_TO_DEGREES * _compression;
|
||||
|
||||
/* \ /
|
||||
|
|
||||
*/
|
||||
int outer = 8;
|
||||
int inner = 2;
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(gvel_x - outer, gvel_y + outer);
|
||||
glVertex2f(gvel_x - inner, gvel_y + inner);
|
||||
glEnd();
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(gvel_x + outer, gvel_y + outer);
|
||||
glVertex2f(gvel_x + inner, gvel_y + inner);
|
||||
glEnd();
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(gvel_x + 0, gvel_y - inner*3/2);
|
||||
glVertex2f(gvel_x + 0, gvel_y - outer*3/2);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
if (_velocity_vector) {
|
||||
drift = get__beta();
|
||||
alpha = get__alpha();
|
||||
|
||||
Axx = get__Ax();
|
||||
Ayy = get__Ay();
|
||||
Azz = get__Az();
|
||||
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 = drift * _compression;
|
||||
// drift = ((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi);
|
||||
// yvvr = (-alpha * _compression);
|
||||
// vel_y = (-alpha * cos(roll_value) + drift * sin(roll_value)) * _compression;
|
||||
// vel_x = (alpha * sin(roll_value) + drift * cos(roll_value))
|
||||
// * (_compression / globals->get_current_view()->get_aspect_ratio());
|
||||
vel_y = -alpha * _compression;
|
||||
vel_x = drift * _compression;
|
||||
// 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();
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
// OBJECT MOVING RETICLE
|
||||
// TYPE VELOCITY VECTOR
|
||||
// ATTRIB - ALWAYS
|
||||
// velocity vector
|
||||
draw_circle(vel_x, vel_y, 6);
|
||||
|
||||
//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
|
||||
int lgear = get__iaux3();
|
||||
int ihook = get__iaux6();
|
||||
|
||||
// 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
|
||||
|
||||
// draw hud markers on top of each AI/MP target
|
||||
if (_target_markers) {
|
||||
SGPropertyNode *models = globals->get_props()->getNode("/ai/models", true);
|
||||
for (int i = 0; i < models->nChildren(); i++) {
|
||||
SGPropertyNode *chld = models->getChild(i);
|
||||
string name;
|
||||
name = chld->getNameString();
|
||||
if (name == "tanker" || name == "aircraft" || name == "multiplayer") {
|
||||
bool valid = chld->getBoolValue("valid");
|
||||
bool in_range = chld->getBoolValue("radar/in-range", true);
|
||||
if (valid && in_range) {
|
||||
float h_deg = chld->getFloatValue("radar/h-offset");
|
||||
float v_deg = chld->getFloatValue("radar/v-offset");
|
||||
float pos_x = (h_deg * cos(roll_value) -
|
||||
v_deg * sin(roll_value)) * _compression;
|
||||
float pos_y = (v_deg * cos(roll_value) +
|
||||
h_deg * sin(roll_value)) * _compression;
|
||||
draw_circle(pos_x, pos_y, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************
|
||||
// OBJECT MOVING RETICLE
|
||||
// TYPE - SQUARE_BRACKET
|
||||
// ATTRIB - ON CONDITION
|
||||
// alpha bracket
|
||||
#ifdef ENABLE_SP_FDM
|
||||
alpha = get__alpha();
|
||||
|
||||
if (_alpha_bracket && ihook == 1) {
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(vel_x - 20, 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 - 20, vel_y - (14 - alpha) * _compression);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(vel_x + 20, 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 + 20, vel_y - (14 - alpha) * _compression);
|
||||
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
|
||||
float pla = get__throttleval();
|
||||
float t2 = 0.0;
|
||||
|
||||
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) * _compression + 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
|
||||
int ilcanclaw = get__iaux2();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
|
||||
_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
|
||||
// actual horizon.
|
||||
_vmin = pitch_value - _width_units * 0.5f;
|
||||
_vmax = pitch_value + _width_units * 0.5f;
|
||||
{
|
||||
// the hud ladder center point should move relative to alpha/beta
|
||||
// however the horizon line should always stay on the horizon. We
|
||||
// project the alpha/beta offset onto the horizon line to get the
|
||||
// result we want.
|
||||
|
||||
SGVec3d d(cos(roll_value), sin(roll_value), 0.0);
|
||||
SGRayd r(SGVec3d::zeros(), d);
|
||||
SGVec3d p = r.getClosestPointTo(SGVec3d(vel_x, vel_y, 0.0));
|
||||
glTranslatef(p[0], p[1], 0);
|
||||
}
|
||||
} else {
|
||||
// ladder position is fixed relative to the center of the screen.
|
||||
_vmin = pitch_value - _width_units * 0.5f;
|
||||
_vmax = pitch_value + _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
|
||||
float half_span = _w * 0.5f;
|
||||
float y = 0;
|
||||
struct { float x, y; } lo, li, ri, ro, numoffs; // left/right inner/outer
|
||||
|
||||
if (_div_units) {
|
||||
_locTextList.setFont(_hud->_font_renderer);
|
||||
_locTextList.erase();
|
||||
_locLineList.erase();
|
||||
_locStippleLineList.erase();
|
||||
|
||||
for (int i = int(_vmin); i < int(_vmax) + 1; i++) {
|
||||
if (i % _div_units)
|
||||
continue;
|
||||
|
||||
if (_type == PITCH)
|
||||
y = float(i - pitch_value) * _compression + .5;
|
||||
else // _type == CLIMB_DIVE
|
||||
y = float(i - actslope) * _compression + .5;
|
||||
|
||||
// OBJECT LADDER MARK
|
||||
// TYPE LINE
|
||||
// ATTRIB - ON CONDITION
|
||||
// draw approach glide slope marker
|
||||
#ifdef ENABLE_SP_FDM
|
||||
if (_glide_slope_marker && ihook) {
|
||||
draw_line(-half_span + 15, (_glide_slope - actslope) * _compression,
|
||||
-half_span + hole, (_glide_slope - actslope) * _compression);
|
||||
draw_line(half_span - 15, (_glide_slope - actslope) * _compression,
|
||||
half_span - hole, (_glide_slope - actslope) * _compression);
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
ro.x = half_span;
|
||||
li.x = ri.x = 0;
|
||||
lo.y = ro.y = li.y = ri.y = y;
|
||||
numoffs.x = 4;
|
||||
numoffs.y = 0;
|
||||
|
||||
if (i == 0) {
|
||||
lo.x -= _zero_bar_overlength;
|
||||
ro.x += _zero_bar_overlength;
|
||||
}
|
||||
|
||||
if (_scr_hole > 0.0f) {
|
||||
li.x = -_scr_hole;
|
||||
ri.x = _scr_hole;
|
||||
|
||||
if (_dive_bar_angle && i < 0) {
|
||||
float alpha = i * SG_DEGREES_TO_RADIANS * 0.5;
|
||||
float xoffs = (ro.x - ri.x) * cos(alpha);
|
||||
float yoffs = (ro.x - ri.x) * sin(alpha);
|
||||
lo.x = li.x - xoffs;
|
||||
ro.x = ri.x + xoffs;
|
||||
lo.y = ro.y = li.y + yoffs;
|
||||
numoffs.x = 0;
|
||||
numoffs.y = 4 - yoffs * 0.3;
|
||||
}
|
||||
}
|
||||
|
||||
// draw bars
|
||||
if (_scr_hole) {
|
||||
draw_line(li.x, li.y, lo.x, lo.y, i < 0);
|
||||
draw_line(ri.x, ri.y, ro.x, ro.y, i < 0);
|
||||
} else {
|
||||
draw_line(lo.x, lo.y, ro.x, ro.y, i < 0);
|
||||
}
|
||||
|
||||
// draw ticks
|
||||
if (_tick_length) {
|
||||
if (i < 0) {
|
||||
draw_line(li.x, li.y, li.x, li.y + _tick_length);
|
||||
draw_line(ri.x, ri.y, ri.x, ri.y + _tick_length);
|
||||
} else if (i > 0 || _zero_bar_overlength == 0) {
|
||||
if (_tick_length > 0) {
|
||||
numoffs.x = -0.3;
|
||||
numoffs.y = -0.3;
|
||||
draw_line(lo.x, lo.y, lo.x, lo.y - _tick_length);
|
||||
draw_line(ro.x, ro.y, ro.x, ro.y - _tick_length);
|
||||
} else {
|
||||
draw_line(li.x, li.y, li.x, li.y - _tick_length);
|
||||
draw_line(ri.x, ri.y, ri.x, ri.y - _tick_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw numbers
|
||||
std::ostringstream str;
|
||||
str << i;
|
||||
// must keep this string, otherwise it will free the c_str!
|
||||
string num_str = str.str();
|
||||
const char *num = num_str.c_str();
|
||||
int valign = numoffs.y > 0 ? BOTTOM : numoffs.y < 0 ? TOP : VCENTER;
|
||||
draw_text(lo.x - numoffs.x, lo.y + numoffs.y, num,
|
||||
valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? RIGHT : LEFT));
|
||||
draw_text(ro.x + numoffs.x, lo.y + numoffs.y, num,
|
||||
valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? LEFT : RIGHT));
|
||||
|
||||
}
|
||||
_locTextList.draw();
|
||||
|
||||
glLineWidth(0.2);
|
||||
|
||||
_locLineList.draw();
|
||||
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple(1, 0x00FF);
|
||||
_locStippleLineList.draw();
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
_clip_box->unset();
|
||||
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 = get__aux2() * SGD_DEGREES_TO_RADIANS;
|
||||
towp_lat = get__aux1() * 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(_center_x, _center_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) {
|
||||
glBegin(GL_LINE_LOOP);
|
||||
GLfloat x = (brg - psi) * 60 / 25;
|
||||
glVertex2f(x + 320, 240.0);
|
||||
glVertex2f(x + 326, 240.0 - 4);
|
||||
glVertex2f(x + 323, 240.0 - 4);
|
||||
glVertex2f(x + 323, 240.0 - 8);
|
||||
glVertex2f(x + 317, 240.0 - 8);
|
||||
glVertex2f(x + 317, 240.0 - 4);
|
||||
glVertex2f(x + 314, 240.0 - 4);
|
||||
glEnd();
|
||||
|
||||
} else { // if (_hat)
|
||||
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 * SG_PI * 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);
|
||||
}
|
||||
|
||||
} //brg<12
|
||||
} // if _waypoint_marker
|
||||
#endif
|
||||
}//draw
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
// draws the zenith symbol (highest possible climb angle i.e. 90 degree climb angle)
|
||||
//
|
||||
void HUD::Ladder::draw_zenith(float x, float y)
|
||||
{
|
||||
draw_line(x - 9.0, y, x - 3.0, y + 1.3);
|
||||
draw_line(x - 9.0, y, x - 3.0, y - 1.3);
|
||||
|
||||
draw_line(x + 9.0, y, x + 3.0, y + 1.3);
|
||||
draw_line(x + 9.0, y, x + 3.0, y - 1.3);
|
||||
|
||||
draw_line(x, y + 9.0, x - 1.3, y + 3.0);
|
||||
draw_line(x, y + 9.0, x + 1.3, y + 3.0);
|
||||
|
||||
draw_line(x - 3.9, y + 3.9, x - 3.0, y + 1.3);
|
||||
draw_line(x - 3.9, y + 3.9, x - 1.3, y + 3.0);
|
||||
|
||||
draw_line(x + 3.9, y + 3.9, x + 1.3, y + 3.0);
|
||||
draw_line(x + 3.9, y + 3.9, x + 3.0, y + 1.3);
|
||||
|
||||
draw_line(x - 3.9, y - 3.9, x - 3.0, y - 1.3);
|
||||
draw_line(x - 3.9, y - 3.9, x - 1.3, y - 2.6);
|
||||
|
||||
draw_line(x + 3.9, y - 3.9, x + 3.0, y - 1.3);
|
||||
draw_line(x + 3.9, y - 3.9, x + 1.3, y - 2.6);
|
||||
|
||||
draw_line(x - 1.3, y - 2.6, x, y - 27.0);
|
||||
draw_line(x + 1.3, y - 2.6, x, y - 27.0);
|
||||
}
|
||||
|
||||
|
||||
// draws the nadir symbol (lowest possible dive angle i.e. 90 degree dive angle))
|
||||
//
|
||||
void HUD::Ladder::draw_nadir(float x, float y)
|
||||
{
|
||||
const float R = 7.5;
|
||||
|
||||
draw_circle(x, y, R);
|
||||
draw_line(x, y + R, x, y + 22.5); // line above the circle
|
||||
draw_line(x - R, y, x + R, y); // line at middle of circle
|
||||
|
||||
float theta = asin(2.5 / R);
|
||||
float theta1 = asin(5.0 / R);
|
||||
float x1, y1, x2, y2;
|
||||
|
||||
x1 = x + R * cos(theta);
|
||||
y1 = y + 2.5;
|
||||
x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta);
|
||||
y2 = y + 2.5;
|
||||
draw_line(x1, y1, x2, y2);
|
||||
|
||||
x1 = x + R * cos(theta1);
|
||||
y1 = y + 5.0;
|
||||
x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1);
|
||||
y2 = y + 5.0;
|
||||
draw_line(x1, y1, x2, y2);
|
||||
|
||||
x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta);
|
||||
y1 = y - 2.5;
|
||||
x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta);
|
||||
y2 = y - 2.5;
|
||||
draw_line(x1, y1, x2, y2);
|
||||
|
||||
x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1);
|
||||
y1 = y - 5.0;
|
||||
x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1);
|
||||
y2 = y - 5.0;
|
||||
draw_line(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
132
src/Instrumentation/HUD/HUD_misc.cxx
Normal file
132
src/Instrumentation/HUD/HUD_misc.cxx
Normal file
@@ -0,0 +1,132 @@
|
||||
// HUD_misc.cxx -- HUD miscellaneous elements
|
||||
//
|
||||
// Written by Melchior FRANZ, started September 2006.
|
||||
//
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
|
||||
// MIL-STD-1787B aiming reticle
|
||||
|
||||
HUD::AimingReticle::AimingReticle(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Item(hud, n, x, y),
|
||||
_active_condition(0),
|
||||
_tachy_condition(0),
|
||||
_align_condition(0),
|
||||
_diameter(n->getNode("diameter-input", false)),
|
||||
_pitch(n->getNode("pitch-input", false)),
|
||||
_yaw(n->getNode("yaw-input", false)),
|
||||
_speed(n->getNode("speed-input", false)),
|
||||
_range(n->getNode("range-input", false)),
|
||||
_t0(n->getNode("arc-start-input", false)),
|
||||
_t1(n->getNode("arc-stop-input", false)),
|
||||
_offset_x(n->getNode("offset-x-input", false)),
|
||||
_offset_y(n->getNode("offset-y-input", false)),
|
||||
_bullet_size(_w / 6.0),
|
||||
_inner_radius(_w / 2.0),
|
||||
_compression(n->getFloatValue("compression-factor")),
|
||||
_limit_x(n->getFloatValue("limit-x")),
|
||||
_limit_y(n->getFloatValue("limit-y"))
|
||||
|
||||
{
|
||||
const SGPropertyNode *node = n->getNode("active-condition");
|
||||
if (node)
|
||||
_active_condition = sgReadCondition(globals->get_props(), node);
|
||||
|
||||
const SGPropertyNode *tnode = n->getNode("tachy-condition");
|
||||
if (tnode)
|
||||
_tachy_condition = sgReadCondition(globals->get_props(), tnode);
|
||||
|
||||
const SGPropertyNode *anode = n->getNode("align-condition");
|
||||
if (anode)
|
||||
_align_condition = sgReadCondition(globals->get_props(), anode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void HUD::AimingReticle::draw(void)
|
||||
{
|
||||
bool active = _active_condition ? _active_condition->test() : true;
|
||||
bool tachy = _tachy_condition ? _tachy_condition->test() : false;
|
||||
bool align = _align_condition ? _align_condition->test() : false;
|
||||
|
||||
float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle
|
||||
float x = _center_x + (_offset_x.isValid() ? _offset_x.getFloatValue() : 0);
|
||||
float y = _center_y + (_offset_y.isValid() ? _offset_y.getFloatValue() : 0);
|
||||
|
||||
if (active) { // stadiametric (4.2.4.4)
|
||||
draw_bullet(x, y, _bullet_size);
|
||||
draw_circle(x, y, _inner_radius);
|
||||
draw_circle(x, y, diameter * _inner_radius);
|
||||
} else if (tachy){//tachiametric
|
||||
float t0 = _t0.isValid() ? _t0.getFloatValue() : 2.0f; // start arc
|
||||
float t1 = _t1.isValid() ? _t1.getFloatValue() : 2.0f; // stop arc
|
||||
float yaw_value = _yaw.getFloatValue();
|
||||
float pitch_value = _pitch.getFloatValue();
|
||||
float tof_value = _range.getFloatValue()* 3 / _speed.getFloatValue();
|
||||
draw_bullet(x, y, _bullet_size);
|
||||
draw_circle(x, y, _inner_radius);
|
||||
draw_line(x + _inner_radius, y, x + _inner_radius * 3, y);
|
||||
draw_line(x - _inner_radius, y, x - _inner_radius * 3, y);
|
||||
draw_line(x, y + _inner_radius, x, y + _inner_radius * 3);
|
||||
draw_line(x, y - _inner_radius, x, y - _inner_radius * 3);
|
||||
|
||||
if(align){
|
||||
draw_line(x + _limit_x, y + _limit_y, x - _limit_x, y + _limit_y);
|
||||
draw_line(x + _limit_x, y - _limit_y, x - _limit_x, y - _limit_y);
|
||||
draw_line(x + _limit_x, y + _limit_y, x + _limit_x, y - _limit_y);
|
||||
draw_line(x - _limit_x, y + _limit_y, x - _limit_x, y - _limit_y);
|
||||
}
|
||||
|
||||
float limit_offset = diameter * _inner_radius;
|
||||
|
||||
float pos_x = x + (yaw_value * tof_value)
|
||||
* _compression;
|
||||
|
||||
pos_x > x + _limit_x - limit_offset ?
|
||||
pos_x = x + _limit_x - limit_offset : pos_x;
|
||||
|
||||
pos_x < x - _limit_x + limit_offset ?
|
||||
pos_x = x - _limit_x + limit_offset: pos_x;
|
||||
|
||||
float pos_y = y + (pitch_value * tof_value)
|
||||
* _compression;
|
||||
|
||||
pos_y > y + _limit_y - limit_offset ?
|
||||
pos_y = y + _limit_y - limit_offset : pos_y;
|
||||
|
||||
pos_y < y - _limit_y + limit_offset?
|
||||
pos_y = y - _limit_y + limit_offset: pos_y;
|
||||
|
||||
draw_circle(pos_x, pos_y, diameter * _inner_radius);
|
||||
|
||||
draw_arc(x, y, t0, t1, (diameter + 2) * _inner_radius );
|
||||
|
||||
} else { // standby (4.2.4.5)
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
427
src/Instrumentation/HUD/HUD_private.hxx
Normal file
427
src/Instrumentation/HUD/HUD_private.hxx
Normal file
@@ -0,0 +1,427 @@
|
||||
// HUD_private.hxx -- Intenral delcerations for the HUD
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifndef _HUD_PRIVATE_HXX
|
||||
#define _HUD_PRIVATE_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/props/condition.hxx>
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <cassert>
|
||||
|
||||
#include <osg/State>
|
||||
|
||||
#include <simgear/math/SGLimits.hxx>
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/props/props.hxx>
|
||||
|
||||
#include <plib/sg.h> // for lingering sgdVec3 usage below
|
||||
|
||||
class FGFontCache;
|
||||
class fntRenderer;
|
||||
class fntTexFont;
|
||||
class FGViewer;
|
||||
class FGRunway;
|
||||
|
||||
class ClipBox {
|
||||
public:
|
||||
ClipBox(const SGPropertyNode *, float xoffset = 0, float yoffset = 0);
|
||||
void set();
|
||||
void unset();
|
||||
|
||||
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 HUD::Input {
|
||||
public:
|
||||
Input(const SGPropertyNode *n, float factor = 1.0, float offset = 0.0,
|
||||
float min = -SGLimitsf::max(), float max = SGLimitsf::max());
|
||||
|
||||
bool getBoolValue() const {
|
||||
assert(_property);
|
||||
return _property->getBoolValue();
|
||||
}
|
||||
|
||||
std::string getStringValue() const {
|
||||
assert(_property);
|
||||
return _property->getStringValue();
|
||||
}
|
||||
|
||||
float getFloatValue() {
|
||||
assert(_property);
|
||||
float f = _property->getFloatValue() * _factor + _offset;
|
||||
if (_damped == SGLimitsf::max())
|
||||
_damped = f;
|
||||
if (_coeff > 0.0f)
|
||||
f = _damped = f * (1.0f - _coeff) + _damped * _coeff;
|
||||
return clamp(f);
|
||||
}
|
||||
|
||||
inline float isValid() const { return _valid; }
|
||||
inline float min() const { return _min; }
|
||||
inline float max() const { return _max; }
|
||||
inline float factor() const { return _factor; }
|
||||
float clamp(float v) const { return v < _min ? _min : v > _max ? _max : v; }
|
||||
|
||||
void set_min(float m, bool force = true) {
|
||||
if (force || _min == -SGLimitsf::max())
|
||||
_min = m;
|
||||
}
|
||||
void set_max(float m, bool force = true) {
|
||||
if (force || _max == SGLimitsf::max())
|
||||
_max = m;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _valid;
|
||||
SGConstPropertyNode_ptr _property;
|
||||
float _factor;
|
||||
float _offset;
|
||||
float _min;
|
||||
float _max;
|
||||
float _coeff;
|
||||
float _damped;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUD::Item {
|
||||
public:
|
||||
Item(HUD *parent, const SGPropertyNode *, float x = 0.0f, float y = 0.0f);
|
||||
virtual ~Item () {}
|
||||
virtual void draw() = 0;
|
||||
virtual bool isEnabled();
|
||||
|
||||
protected:
|
||||
enum Format {
|
||||
INVALID,
|
||||
NONE,
|
||||
INT,
|
||||
LONG,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
STRING,
|
||||
};
|
||||
|
||||
Format check_format(const char *) const;
|
||||
inline float get_span() const { return _scr_span; }
|
||||
inline int get_digits() const { return _digits; }
|
||||
|
||||
inline bool option_vert() const { return (_options & VERTICAL) == VERTICAL; }
|
||||
inline bool option_left() const { return (_options & LEFT) == LEFT; }
|
||||
inline bool option_right() const { return (_options & RIGHT) == RIGHT; }
|
||||
inline bool option_both() const { return (_options & BOTH) == BOTH; }
|
||||
inline bool option_noticks() const { return (_options & NOTICKS) == NOTICKS; }
|
||||
inline bool option_notext() const { return (_options & NOTEXT) == NOTEXT; }
|
||||
inline bool option_top() const { return (_options & TOP) == TOP; }
|
||||
inline bool option_bottom() const { return (_options & BOTTOM) == BOTTOM; }
|
||||
|
||||
void draw_line(float x1, float y1, float x2, float y2);
|
||||
void draw_stipple_line(float x1, float y1, float x2, float y2);
|
||||
void draw_text(float x, float y, const char *msg, int align = 0, int digit = 0);
|
||||
void draw_circle(float x1, float y1, float r) const;
|
||||
void draw_arc(float x1, float y1, float t0, float t1, float r) const;
|
||||
void draw_bullet(float, float, float);
|
||||
|
||||
HUD *_hud;
|
||||
std::string _name;
|
||||
int _options;
|
||||
float _x, _y, _w, _h;
|
||||
float _center_x, _center_y;
|
||||
|
||||
private:
|
||||
SGSharedPtr<SGCondition> _condition;
|
||||
float _scr_span; // Working values for draw;
|
||||
int _digits;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUD::Label : public Item {
|
||||
public:
|
||||
Label(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
bool blink();
|
||||
|
||||
Input _input;
|
||||
Format _mode;
|
||||
std::string _format;
|
||||
int _halign; // HUDText alignment
|
||||
bool _box;
|
||||
float _pointer_width;
|
||||
float _pointer_length;
|
||||
|
||||
SGSharedPtr<SGCondition> _blink_condition;
|
||||
double _blink_interval;
|
||||
double _blink_target; // time for next blink state change
|
||||
bool _blink_state;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// abstract base class for both moving scale and moving needle (fixed scale)
|
||||
// indicators.
|
||||
//
|
||||
class HUD::Scale : public Item {
|
||||
public:
|
||||
Scale(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw ( void ) {} // No-op here. Defined in derived classes.
|
||||
|
||||
protected:
|
||||
inline float factor() const { return _display_factor; }
|
||||
inline float range_to_show() const { return _range_shown; }
|
||||
|
||||
Input _input;
|
||||
float _major_divs; // major division marker units
|
||||
float _minor_divs; // minor division marker units
|
||||
unsigned int _modulo; // Roll over point
|
||||
|
||||
private:
|
||||
float _range_shown; // Width Units.
|
||||
float _display_factor; // factor => screen units/range values.
|
||||
};
|
||||
|
||||
|
||||
class HUD::Gauge : public Scale {
|
||||
public:
|
||||
Gauge(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
};
|
||||
|
||||
|
||||
|
||||
// displays the indicated quantity on a scale that moves past the
|
||||
// pointer. It may be horizontal or vertical.
|
||||
//
|
||||
class HUD::Tape : public Scale {
|
||||
public:
|
||||
Tape(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
|
||||
protected:
|
||||
void draw_vertical(float);
|
||||
void draw_horizontal(float);
|
||||
void draw_fixed_pointer(float, float, float, float, float, float);
|
||||
char *format_value(float);
|
||||
|
||||
private:
|
||||
float _val_span;
|
||||
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;
|
||||
float _label_offset;
|
||||
float _label_gap;
|
||||
bool _pointer;
|
||||
Format _label_fmt;
|
||||
std::string _format;
|
||||
int _div_ratio; // _major_divs/_minor_divs
|
||||
bool _odd_type; // whether to put numbers at 0/2/4 or 1/3/5
|
||||
|
||||
enum { BUFSIZE = 64 };
|
||||
char _buf[BUFSIZE];
|
||||
|
||||
enum PointerType { FIXED, MOVING } _pointer_type;
|
||||
enum TickType { LINE, CIRCLE } _tick_type;
|
||||
enum TickLength { VARIABLE, CONSTANT } _tick_length;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUD::Dial : public Scale {
|
||||
public:
|
||||
Dial(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
float _radius;
|
||||
int _divisions;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUD::TurnBankIndicator : public Item {
|
||||
public:
|
||||
TurnBankIndicator(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
void draw_scale();
|
||||
void draw_tee();
|
||||
void draw_line(float, float, float, float);
|
||||
void draw_tick(float angle, float r1, float r2, int side);
|
||||
|
||||
Input _bank;
|
||||
Input _sideslip;
|
||||
|
||||
float _gap_width;
|
||||
bool _bank_scale;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HUD::Ladder : public Item {
|
||||
public:
|
||||
Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
~Ladder();
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
void draw_zenith(float, float);
|
||||
void draw_nadir(float, float);
|
||||
|
||||
void draw_text(float x, float y, const char *s, int align = 0) {
|
||||
_locTextList.add(x, y, s, align, 0);
|
||||
}
|
||||
|
||||
void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
|
||||
if (stipple)
|
||||
_locStippleLineList.add(LineSegment(x1, y1, x2, y2));
|
||||
else
|
||||
_locLineList.add(LineSegment(x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
enum Type { PITCH, CLIMB_DIVE } _type;
|
||||
Input _pitch;
|
||||
Input _roll;
|
||||
float _width_units;
|
||||
int _div_units;
|
||||
float _scr_hole;
|
||||
float _zero_bar_overlength;
|
||||
bool _dive_bar_angle;
|
||||
float _tick_length;
|
||||
float _vmax;
|
||||
float _vmin;
|
||||
float _compression;
|
||||
bool _dynamic_origin;
|
||||
bool _frl; // fuselage reference line
|
||||
bool _target_spot;
|
||||
bool _target_markers;
|
||||
bool _velocity_vector;
|
||||
bool _ground_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;
|
||||
bool _zenith;
|
||||
bool _nadir;
|
||||
bool _hat;
|
||||
|
||||
ClipBox *_clip_box;
|
||||
// The Ladder has its own temporary display lists
|
||||
TextList _locTextList;
|
||||
LineList _locLineList;
|
||||
LineList _locStippleLineList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// responsible for rendering the active runway in the hud (if visible).
|
||||
//
|
||||
class HUD::Runway : public Item {
|
||||
public:
|
||||
Runway(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
|
||||
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();
|
||||
|
||||
SGPropertyNode_ptr _agl;
|
||||
sgdVec3 _points3d[6], _points2d[6];
|
||||
double _mm[16];
|
||||
double _pm[16];
|
||||
double _arrow_scale; // scales of runway indication arrow
|
||||
double _arrow_radius;
|
||||
double _line_scale; // maximum line scale
|
||||
double _scale_dist; // distance where to start scaling the lines
|
||||
double _default_pitch;
|
||||
double _default_heading;
|
||||
GLint _view[4];
|
||||
FGRunway* _runway;
|
||||
unsigned short _stipple_out; // stipple pattern of the outline of the runway
|
||||
unsigned short _stipple_center; // stipple pattern of the center line of the runway
|
||||
bool _draw_arrow; // draw arrow when runway is not visible in HUD
|
||||
bool _draw_arrow_always; // always draws arrow
|
||||
float _left, _right, _top, _bottom;
|
||||
};
|
||||
|
||||
|
||||
class HUD::AimingReticle : public Item {
|
||||
public:
|
||||
AimingReticle(HUD *parent, const SGPropertyNode *, float x, float y);
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
SGSharedPtr<SGCondition> _active_condition; // stadiametric (true) or standby (false)
|
||||
SGSharedPtr<SGCondition> _tachy_condition; // tachymetric (true) or standby (false)
|
||||
SGSharedPtr<SGCondition> _align_condition; // tachymetric (true) or standby (false)
|
||||
|
||||
Input _diameter; // inner/outer radius relation
|
||||
Input _pitch;
|
||||
Input _yaw;
|
||||
Input _speed;
|
||||
Input _range;
|
||||
Input _t0;
|
||||
Input _t1;
|
||||
Input _offset_x;
|
||||
Input _offset_y;
|
||||
|
||||
float _bullet_size;
|
||||
float _inner_radius;
|
||||
float _compression;
|
||||
float _limit_x;
|
||||
float _limit_y;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // _HUD_HXX
|
||||
422
src/Instrumentation/HUD/HUD_runway.cxx
Normal file
422
src/Instrumentation/HUD/HUD_runway.cxx
Normal file
@@ -0,0 +1,422 @@
|
||||
// HUD_runway.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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/scene/util/project.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Aircraft/controls.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Environment/environment.hxx>
|
||||
#include <Environment/environment_mgr.hxx>
|
||||
#include <Viewer/view.hxx>
|
||||
#include <Viewer/viewmgr.hxx>
|
||||
#include <Airports/airport.hxx>
|
||||
|
||||
#include "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
HUD::Runway::Runway(HUD *hud, const SGPropertyNode *node, float x, float y) :
|
||||
Item(hud, node, x, y),
|
||||
_agl(fgGetNode("/position/altitude-agl-ft", true)),
|
||||
_arrow_scale(node->getDoubleValue("arrow-scale", 1.0)),
|
||||
_arrow_radius(node->getDoubleValue("arrow-radius")),
|
||||
_line_scale(node->getDoubleValue("line-scale", 1.0)),
|
||||
_scale_dist(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)),
|
||||
_stipple_out(node->getIntValue("outer_stipple", 0xFFFF)),
|
||||
_stipple_center(node->getIntValue("center-stipple", 0xFFFF)),
|
||||
_draw_arrow(_arrow_scale > 0 ? true : false),
|
||||
_draw_arrow_always(_arrow_scale > 0 ? node->getBoolValue("arrow-always") : false)
|
||||
{
|
||||
_view[0] = 0;
|
||||
_view[1] = 0;
|
||||
_view[2] = 640;
|
||||
_view[3] = 480;
|
||||
|
||||
_center_x = _view[2] / 2;
|
||||
_center_y = _view[3] / 2;
|
||||
|
||||
_left = _center_x - (_w / 2) + _x;
|
||||
_right = _center_x + (_w / 2) + _x;
|
||||
_bottom = _center_y - (_h / 2) + _y;
|
||||
_top = _center_y + (_h / 2) + _y;
|
||||
}
|
||||
|
||||
void HUD::Runway::draw()
|
||||
{
|
||||
_runway = get_active_runway();
|
||||
if (!_runway)
|
||||
return;
|
||||
|
||||
glPushAttrib(GL_LINE_STIPPLE | GL_LINE_STIPPLE_PATTERN | GL_LINE_WIDTH);
|
||||
float projMat[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
|
||||
float modelView[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();
|
||||
|
||||
flightgear::View* cockpitView = globals->get_viewmgr()->get_view(0);
|
||||
|
||||
double yaw = -(cockpitView->getHeadingOffset_deg() - _default_heading) * SG_DEGREES_TO_RADIANS;
|
||||
double pitch = (cockpitView->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, _stipple_out);
|
||||
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, _stipple_center);
|
||||
anyLines |= drawLine(_points3d[5], _points3d[4], _points2d[5], _points2d[4]); //draw center
|
||||
|
||||
//Check to see if arrow needs drawn
|
||||
if ((!anyLines && _draw_arrow) || _draw_arrow_always) {
|
||||
drawArrow(); //draw indication arrow
|
||||
}
|
||||
|
||||
//Set the camera back to the current view
|
||||
// OSGFIXME
|
||||
// ssgSetCamera((sgVec4 *)curr_view);
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
|
||||
FGRunway* HUD::Runway::get_active_runway()
|
||||
{
|
||||
const FGAirport* apt = fgFindAirportID(fgGetString("/sim/presets/airport-id"));
|
||||
if (!apt) return NULL;
|
||||
|
||||
return apt->getActiveRunwayForUsage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HUD::Runway::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;
|
||||
|
||||
geo_direct_wgs_84(alt, _runway->latitude(), _runway->longitude(), _runway->headingDeg(), length, &backLat, &backLon, &az);
|
||||
sgGeodToCart(backLat * SG_DEGREES_TO_RADIANS, backLon * SG_DEGREES_TO_RADIANS, alt, _points3d[4]);
|
||||
|
||||
geo_direct_wgs_84(alt, _runway->latitude(), _runway->longitude(), _runway->headingDeg() + 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, _runway->headingDeg() + 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, _runway->headingDeg() - 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, _runway->headingDeg() - 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, _runway->headingDeg() + 90, width, &tempLat, &tempLon, &az);
|
||||
sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, _points3d[3]);
|
||||
}
|
||||
|
||||
|
||||
bool HUD::Runway::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] >= _left && p1[0] <= _right && p1[1] >= _bottom && p1[1] <= _top);
|
||||
bool p1Insight = (p1[2] >= 0.0 && p1[2] < 1.0);
|
||||
bool p1Valid = p1Insight && p1Inside;
|
||||
bool p2Inside = (p2[0] >= _left && p2[0] <= _right && p2[1] >= _bottom && p2[1] <= _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 HUD::Runway::boundPoint(const sgdVec3& v, sgdVec3& m)
|
||||
{
|
||||
double y = v[1];
|
||||
if (m[1] < v[1])
|
||||
y = _bottom;
|
||||
else if (m[1] > v[1])
|
||||
y = _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] < _left) {
|
||||
m[0] = _left;
|
||||
m[1] = slope * (_left - v[0]) + v[1];
|
||||
|
||||
} else if (m[0] > _right) {
|
||||
m[0] = _right;
|
||||
m[1] = slope * (_right - v[0]) + v[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool HUD::Runway::boundOutsidePoints(sgdVec3& v, sgdVec3& m)
|
||||
{
|
||||
bool pointsInvalid = (v[1] > _top && m[1] > _top) ||
|
||||
(v[1] < _bottom && m[1] < _bottom) ||
|
||||
(v[0] > _right && m[0] > _right) ||
|
||||
(v[0] < _left && m[0] < _left);
|
||||
if (pointsInvalid)
|
||||
return false;
|
||||
|
||||
if (m[0] == v[0]) {//x's are equal, vertical line
|
||||
if (m[1] > v[1]) {
|
||||
m[1] = _top;
|
||||
v[1] = _bottom;
|
||||
} else {
|
||||
v[1] = _top;
|
||||
m[1] = _bottom;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m[1] == v[1]) { //y's are equal, horizontal line
|
||||
if (m[0] > v[0]) {
|
||||
m[0] = _right;
|
||||
v[0] = _left;
|
||||
} else {
|
||||
v[0] = _right;
|
||||
m[0] = _left;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
double slope = (m[1] - v[1]) / (m[0] - v[0]);
|
||||
double b = v[1] - (slope * v[0]);
|
||||
double y1 = slope * _left + b;
|
||||
double y2 = slope * _right + b;
|
||||
double x1 = (_bottom - b) / slope;
|
||||
double x2 = (_top - b) / slope;
|
||||
int counter = 0;
|
||||
|
||||
if (y1 >= _bottom && y1 <= _top) {
|
||||
v[0] = _left;
|
||||
v[1] = y1;
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (y2 >= _bottom && y2 <= _top) {
|
||||
if (counter > 0) {
|
||||
m[0] = _right;
|
||||
m[1] = y2;
|
||||
} else {
|
||||
v[0] = _right;
|
||||
v[1] = y2;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (x1 >= _left && x1 <= _right) {
|
||||
if (counter > 0) {
|
||||
m[0] = x1;
|
||||
m[1] = _bottom;
|
||||
} else {
|
||||
v[0] = x1;
|
||||
v[1] = _bottom;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (x2 >= _left && x2 <= _right) {
|
||||
m[0] = x1;
|
||||
m[1] = _bottom;
|
||||
counter++;
|
||||
}
|
||||
return (counter == 2);
|
||||
}
|
||||
|
||||
|
||||
void HUD::Runway::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((_right + _left) / 2.0, (_top + _bottom) / 2.0, 0.0);
|
||||
glRotated(theta, 0.0, 0.0, 1.0);
|
||||
glTranslated(0.0, _arrow_radius, 0.0);
|
||||
glScaled(_arrow_scale, _arrow_scale, 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 HUD::Runway::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 = _agl->getDoubleValue();
|
||||
|
||||
if (_hud->getUnits() == FEET)
|
||||
alt_nm *= SG_FEET_TO_METER;
|
||||
|
||||
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 < _scale_dist)
|
||||
glLineWidth(1.0 + ((_line_scale - 1) * ((_scale_dist - distance) / _scale_dist)));
|
||||
else
|
||||
glLineWidth(1.0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
43
src/Instrumentation/HUD/HUD_scale.cxx
Normal file
43
src/Instrumentation/HUD/HUD_scale.cxx
Normal file
@@ -0,0 +1,43 @@
|
||||
// HUD_scale.cxx -- HUD Common Scale Base (inherited from Gauge/Tape/Dial)
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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 "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
HUD::Scale::Scale( HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Item(hud, n, x, y),
|
||||
_input(n->getNode("input", false)),
|
||||
_major_divs(n->getFloatValue("major-divisions")),
|
||||
_minor_divs(n->getFloatValue("minor-divisions")),
|
||||
_modulo(n->getIntValue("modulo"))
|
||||
{
|
||||
if (n->hasValue("display-span"))
|
||||
_range_shown = n->getFloatValue("display-span");
|
||||
else
|
||||
_range_shown = _input.max() - _input.min();
|
||||
|
||||
_display_factor = get_span() / _range_shown;
|
||||
if (_range_shown < 0)
|
||||
_range_shown = -_range_shown;
|
||||
|
||||
}
|
||||
|
||||
|
||||
561
src/Instrumentation/HUD/HUD_tape.cxx
Normal file
561
src/Instrumentation/HUD/HUD_tape.cxx
Normal file
@@ -0,0 +1,561 @@
|
||||
// HUD_tape.cxx -- HUD Tape Instrument
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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 "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
static const float TICK_OFFSET = 2.f;
|
||||
|
||||
|
||||
HUD::Tape::Tape(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Scale(hud, n, x, y),
|
||||
_draw_tick_bottom(n->getBoolValue("tick-bottom", false)),
|
||||
_draw_tick_top(n->getBoolValue("tick-top", false)),
|
||||
_draw_tick_right(n->getBoolValue("tick-right", false)),
|
||||
_draw_tick_left(n->getBoolValue("tick-left", false)),
|
||||
_draw_cap_bottom(n->getBoolValue("cap-bottom", false)),
|
||||
_draw_cap_top(n->getBoolValue("cap-top", false)),
|
||||
_draw_cap_right(n->getBoolValue("cap-right", false)),
|
||||
_draw_cap_left(n->getBoolValue("cap-left", false)),
|
||||
_marker_offset(n->getFloatValue("marker-offset")),
|
||||
_label_offset(n->getFloatValue("label-offset", 3.0)),
|
||||
_label_gap(n->getFloatValue("label-gap-width") / 2.0),
|
||||
_pointer(n->getBoolValue("enable-pointer", true)),
|
||||
_format(n->getStringValue("format", "%d"))
|
||||
{
|
||||
_half_width_units = range_to_show() / 2.0;
|
||||
|
||||
string s = n->getStringValue("pointer-type");
|
||||
_pointer_type = s != "moving" ? FIXED : MOVING; // "fixed", "moving"
|
||||
|
||||
s = n->getStringValue("tick-type");
|
||||
_tick_type = s != "bullet" ? LINE : CIRCLE; // "bullet", "line"
|
||||
|
||||
s = n->getStringValue("tick-length"); // "variable", "constant"
|
||||
_tick_length = s != "constant" ? VARIABLE : CONSTANT;
|
||||
|
||||
_label_fmt = check_format(_format.c_str());
|
||||
if (_label_fmt != INT && _label_fmt != LONG
|
||||
&& _label_fmt != FLOAT && _label_fmt != DOUBLE) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid <format> '" << _format.c_str()
|
||||
<< "' in <tape> '" << _name << "' (must be number format)");
|
||||
_label_fmt = INT;
|
||||
_format = "%d";
|
||||
}
|
||||
|
||||
if (_minor_divs != 0.0f)
|
||||
_div_ratio = int(_major_divs / _minor_divs + 0.5f);
|
||||
else
|
||||
_div_ratio = 0, _minor_divs = _major_divs;
|
||||
|
||||
// int k; //odd or even values for ticks // FIXME odd scale
|
||||
_odd_type = false;
|
||||
if (_input.max() + .5f < float(SGLimits<long>::max()))
|
||||
_odd_type = long(floorf(_input.max() + 0.5f)) & 1 ? true : false;
|
||||
}
|
||||
|
||||
|
||||
void HUD::Tape::draw(void) // (HUD_scale * pscale)
|
||||
{
|
||||
if (!_input.isValid())
|
||||
return;
|
||||
|
||||
float value = _input.getFloatValue();
|
||||
|
||||
if (option_vert())
|
||||
draw_vertical(value);
|
||||
else
|
||||
draw_horizontal(value);
|
||||
}
|
||||
|
||||
|
||||
void HUD::Tape::draw_vertical(float value)
|
||||
{
|
||||
float vmin = 0.0;//, vmax = 0.0;
|
||||
float marker_xs;
|
||||
float marker_xe;
|
||||
float marker_ye;
|
||||
float text_y = 0.0;
|
||||
|
||||
float top = _y + _h;
|
||||
float right = _x + _w;
|
||||
|
||||
|
||||
if (!_pointer) {
|
||||
vmin = value - _half_width_units; // width units == needle travel
|
||||
// vmax = value + _half_width_units; // or picture unit span.
|
||||
text_y = _center_y;
|
||||
|
||||
} else if (_pointer_type == MOVING) {
|
||||
vmin = _input.min();
|
||||
// vmax = _input.max();
|
||||
|
||||
} else { // FIXED
|
||||
vmin = value - _half_width_units; // width units == needle travel
|
||||
// vmax = value + _half_width_units; // or picture unit span.
|
||||
text_y = _center_y;
|
||||
}
|
||||
|
||||
// Bottom tick bar
|
||||
if (_draw_tick_bottom)
|
||||
draw_line(_x, _y, right, _y);
|
||||
|
||||
// Top tick bar
|
||||
if (_draw_tick_top)
|
||||
draw_line(_x, top, right, top);
|
||||
|
||||
marker_xs = _x; // x start
|
||||
marker_xe = right; // x extent
|
||||
marker_ye = top;
|
||||
|
||||
// We do not use else in the following so that combining the
|
||||
// two options produces a "caged" display with double
|
||||
// carrots. The same is done for horizontal card indicators.
|
||||
|
||||
// draw capping lines and pointers
|
||||
if (option_left()) { // Calculate x marker offset
|
||||
|
||||
if (_draw_cap_right)
|
||||
draw_line(marker_xe, _y, marker_xe, marker_ye);
|
||||
|
||||
marker_xs = marker_xe - _w / 3.0;
|
||||
|
||||
// draw_line(marker_xs, _center_y, marker_xe, _center_y + _w / 6);
|
||||
// draw_line(marker_xs, _center_y, marker_xe, _center_y - _w / 6);
|
||||
|
||||
if (_pointer) {
|
||||
if (_pointer_type == MOVING) {
|
||||
float ycentre, ypoint, xpoint;
|
||||
float range, right;
|
||||
|
||||
if (_input.min() >= 0.0)
|
||||
ycentre = _y;
|
||||
else if (_input.max() + _input.min() == 0.0)
|
||||
ycentre = _center_y;
|
||||
else if (_odd_type)
|
||||
ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
|
||||
else
|
||||
ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
|
||||
|
||||
range = _h;
|
||||
right = _x + _w;
|
||||
|
||||
if (_odd_type)
|
||||
ypoint = ycentre + ((value - 1.0) * range / _val_span);
|
||||
else
|
||||
ypoint = ycentre + (value * range / _val_span);
|
||||
|
||||
xpoint = right + _marker_offset;
|
||||
draw_line(xpoint, ycentre, xpoint, ypoint);
|
||||
draw_line(xpoint, ypoint, xpoint - _marker_offset, ypoint);
|
||||
draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint + 5.0);
|
||||
draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint - 5.0);
|
||||
|
||||
} else { // FIXED
|
||||
draw_fixed_pointer(_marker_offset + marker_xe, text_y + _w / 6,
|
||||
_marker_offset + marker_xs, text_y, _marker_offset + marker_xe,
|
||||
text_y - _w / 6);
|
||||
}
|
||||
}
|
||||
} // if (option_left())
|
||||
|
||||
|
||||
// draw capping lines and pointers
|
||||
if (option_right()) {
|
||||
|
||||
if (_draw_cap_left)
|
||||
draw_line(_x, _y, _x, marker_ye);
|
||||
|
||||
marker_xe = _x + _w / 3.0;
|
||||
// Indicator carrot
|
||||
// draw_line(_x, _center_y + _w / 6, marker_xe, _center_y);
|
||||
// draw_line(_x, _center_y - _w / 6, marker_xe, _center_y);
|
||||
|
||||
if (_pointer) {
|
||||
if (_pointer_type == MOVING) {
|
||||
float ycentre, ypoint, xpoint;
|
||||
float range;
|
||||
|
||||
if (_input.min() >= 0.0)
|
||||
ycentre = _y;
|
||||
else if (_input.max() + _input.min() == 0.0)
|
||||
ycentre = _center_y;
|
||||
else if (_odd_type)
|
||||
ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
|
||||
else
|
||||
ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
|
||||
|
||||
range = _h;
|
||||
|
||||
if (_odd_type)
|
||||
ypoint = ycentre + ((value - 1.0) * range / _val_span);
|
||||
else
|
||||
ypoint = ycentre + (value * range / _val_span);
|
||||
|
||||
xpoint = _x - _marker_offset;
|
||||
draw_line(xpoint, ycentre, xpoint, ypoint);
|
||||
draw_line(xpoint, ypoint, xpoint + _marker_offset, ypoint);
|
||||
draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint + 5.0);
|
||||
draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint - 5.0);
|
||||
|
||||
} else { // FIXED
|
||||
draw_fixed_pointer(-_marker_offset + _x, text_y + _w / 6,
|
||||
-_marker_offset + marker_xe, text_y, -_marker_offset + _x,
|
||||
text_y - _w / 6);
|
||||
}
|
||||
} // if (_pointer)
|
||||
} // if (option_right())
|
||||
|
||||
|
||||
// At this point marker x_start and x_end values are transposed.
|
||||
// To keep this from confusing things they are now swapped.
|
||||
if (option_both())
|
||||
marker_ye = marker_xs, marker_xs = marker_xe, marker_xe = marker_ye;
|
||||
|
||||
|
||||
|
||||
// Work through from bottom to top of scale. Calculating where to put
|
||||
// minor and major ticks.
|
||||
|
||||
// draw scale or tape
|
||||
float vstart = floorf(vmin / _major_divs) * _major_divs;
|
||||
float min_diff = _w / 6.0; // length difference between major & minor tick
|
||||
|
||||
// FIXME consider oddtype
|
||||
for (int i = 0; ; i++) {
|
||||
float v = vstart + i * _minor_divs;
|
||||
|
||||
if (!_modulo) {
|
||||
if (v < _input.min())
|
||||
continue;
|
||||
else if (v > _input.max())
|
||||
break;
|
||||
}
|
||||
|
||||
float y = _y + (v - vmin) * factor();
|
||||
|
||||
if (y < _y + TICK_OFFSET)
|
||||
continue;
|
||||
if (y > top - TICK_OFFSET)
|
||||
break;
|
||||
|
||||
if (_div_ratio && i % _div_ratio) { // minor div
|
||||
if (option_both()) {
|
||||
if (_tick_type == LINE) {
|
||||
if (_tick_length == VARIABLE) {
|
||||
draw_line(_x, y, marker_xs, y);
|
||||
draw_line(marker_xe, y, right, y);
|
||||
} else {
|
||||
draw_line(_x, y, marker_xs, y);
|
||||
draw_line(marker_xe, y, right, y);
|
||||
}
|
||||
|
||||
} else { // _tick_type == CIRCLE
|
||||
draw_bullet(_x, y, 3.0);
|
||||
}
|
||||
|
||||
} else if (option_left()) {
|
||||
if (_tick_type == LINE) {
|
||||
if (_tick_length == VARIABLE) {
|
||||
draw_line(marker_xs + min_diff, y, marker_xe, y);
|
||||
} else {
|
||||
draw_line(marker_xs, y, marker_xe, y);
|
||||
}
|
||||
} else { // _tick_type == CIRCLE
|
||||
draw_bullet(marker_xs + 4, y, 3.0);
|
||||
}
|
||||
|
||||
} else { // if (option_right())
|
||||
if (_tick_type == LINE) {
|
||||
if (_tick_length == VARIABLE) {
|
||||
draw_line(marker_xs, y, marker_xe - min_diff, y);
|
||||
} else {
|
||||
draw_line(marker_xs, y, marker_xe, y);
|
||||
}
|
||||
|
||||
} else { // _tick_type == CIRCLE
|
||||
draw_bullet(marker_xe - 4, y, 3.0);
|
||||
}
|
||||
} // end huds both
|
||||
|
||||
} else { // major div
|
||||
if (_modulo)
|
||||
v = fmodf(v + _modulo, _modulo);
|
||||
|
||||
float x;
|
||||
int align;
|
||||
|
||||
if (option_both()) {
|
||||
if (_tick_type == LINE) {
|
||||
draw_line(_x, y, marker_xs, y);
|
||||
draw_line(marker_xs, y, right, y);
|
||||
|
||||
} else { // _tick_type == CIRCLE
|
||||
draw_bullet(_x, y, 5.0);
|
||||
}
|
||||
|
||||
x = marker_xs, align = CENTER;
|
||||
|
||||
} else {
|
||||
if (_tick_type == LINE)
|
||||
draw_line(marker_xs, y, marker_xe, y);
|
||||
else // _tick_type == CIRCLE
|
||||
draw_bullet(marker_xs + 4, y, 5.0);
|
||||
|
||||
if (option_left())
|
||||
x = marker_xs - _label_offset, align = RIGHT|VCENTER;
|
||||
else
|
||||
x = marker_xe + _label_offset, align = LEFT|VCENTER;
|
||||
}
|
||||
|
||||
if (!option_notext()) {
|
||||
char *s = format_value(v);
|
||||
|
||||
float l, r, b, t;
|
||||
_hud->_text_list.align(s, align, &x, &y, &l, &r, &b, &t);
|
||||
|
||||
if (b < _y || t > top)
|
||||
continue;
|
||||
|
||||
if (_label_gap == 0.0
|
||||
|| (b < _center_y - _label_gap && t < _center_y - _label_gap)
|
||||
|| (b > _center_y + _label_gap && t > _center_y + _label_gap)) {
|
||||
draw_text(x, y, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // for
|
||||
}
|
||||
|
||||
|
||||
void HUD::Tape::draw_horizontal(float value)
|
||||
{
|
||||
float vmin = 0.0;//, vmax = 0.0;
|
||||
float marker_xs;
|
||||
// float marker_xe;
|
||||
float marker_ys;
|
||||
float marker_ye;
|
||||
// float text_y = 0.0;
|
||||
|
||||
float top = _y + _h;
|
||||
float right = _x + _w;
|
||||
|
||||
|
||||
if (!_pointer) {
|
||||
vmin = value - _half_width_units; // width units == needle travel
|
||||
// vmax = value + _half_width_units; // or picture unit span.
|
||||
// text_y = _center_y;
|
||||
|
||||
} else if (_pointer_type == MOVING) {
|
||||
vmin = _input.min();
|
||||
// vmax = _input.max();
|
||||
|
||||
} else { // FIXED
|
||||
vmin = value - _half_width_units; // width units == needle travel
|
||||
// vmax = value + _half_width_units; // or picture unit span.
|
||||
// text_y = _center_y;
|
||||
}
|
||||
|
||||
// left tick bar
|
||||
if (_draw_tick_left)
|
||||
draw_line(_x, _y, _x, top);
|
||||
|
||||
// right tick bar
|
||||
if (_draw_tick_right)
|
||||
draw_line(right, _y, right, top);
|
||||
|
||||
marker_ys = _y; // Starting point for
|
||||
marker_ye = top; // tick y location calcs
|
||||
// marker_xe = right;
|
||||
marker_xs = _x + ((value - vmin) * factor());
|
||||
|
||||
if (option_top()) {
|
||||
if (_draw_cap_bottom)
|
||||
draw_line(_x, _y, right, _y);
|
||||
|
||||
// Tick point adjust
|
||||
marker_ye = _y + _h / 2;
|
||||
// Bottom arrow
|
||||
// draw_line(_center_x, marker_ye, _center_x - _h / 4, _y);
|
||||
// draw_line(_center_x, marker_ye, _center_x + _h / 4, _y);
|
||||
// draw pointer
|
||||
if (_pointer) {
|
||||
if (_pointer_type == MOVING) {
|
||||
float xcentre = _center_x;
|
||||
float range = _w;
|
||||
float xpoint = xcentre + (value * range / _val_span);
|
||||
float ypoint = _y - _marker_offset;
|
||||
draw_line(xcentre, ypoint, xpoint, ypoint);
|
||||
draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
|
||||
draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
|
||||
draw_line(xpoint, ypoint + _marker_offset, xpoint - 5.0, ypoint + 5.0);
|
||||
|
||||
} else { // FIXED
|
||||
draw_fixed_pointer(marker_xs - _h / 4, _y, marker_xs,
|
||||
marker_ye, marker_xs + _h / 4, _y);
|
||||
}
|
||||
}
|
||||
} // if (option_top())
|
||||
|
||||
if (option_bottom()) {
|
||||
if (_draw_cap_top)
|
||||
draw_line(_x, top, right, top);
|
||||
|
||||
// Tick point adjust
|
||||
marker_ys = top - _h / 2;
|
||||
// Top arrow
|
||||
// draw_line(_center_x + _h / 4, _y + _h, _center_x, marker_ys);
|
||||
// draw_line(_center_x - _h / 4, _y + _h, _center_x , marker_ys);
|
||||
|
||||
if (_pointer) {
|
||||
if (_pointer_type == MOVING) {
|
||||
float xcentre = _center_x;
|
||||
float range = _w;
|
||||
float hgt = _y + _h;
|
||||
float xpoint = xcentre + (value * range / _val_span);
|
||||
float ypoint = hgt + _marker_offset;
|
||||
draw_line(xcentre, ypoint, xpoint, ypoint);
|
||||
draw_line(xpoint, ypoint, xpoint, ypoint - _marker_offset);
|
||||
draw_line(xpoint, ypoint - _marker_offset, xpoint + 5.0, ypoint - 5.0);
|
||||
draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
|
||||
|
||||
} else { // FIXED
|
||||
draw_fixed_pointer(marker_xs + _h / 4, top, marker_xs, marker_ys,
|
||||
marker_xs - _h / 4, top);
|
||||
}
|
||||
}
|
||||
} // if (option_bottom())
|
||||
|
||||
|
||||
float vstart = floorf(vmin / _major_divs) * _major_divs;
|
||||
float min_diff = _h / 6.0; // length difference between major & minor tick
|
||||
|
||||
// FIXME consider oddtype
|
||||
for (int i = 0; ; i++) {
|
||||
float v = vstart + i * _minor_divs;
|
||||
|
||||
if (!_modulo) {
|
||||
if (v < _input.min())
|
||||
continue;
|
||||
else if (v > _input.max())
|
||||
break;
|
||||
}
|
||||
|
||||
float x = _x + (v - vmin) * factor();
|
||||
|
||||
if (x < _x + TICK_OFFSET)
|
||||
continue;
|
||||
if (x > right - TICK_OFFSET)
|
||||
break;
|
||||
|
||||
if (_div_ratio && i % _div_ratio) { // minor div
|
||||
if (option_both()) {
|
||||
if (_tick_length == VARIABLE) {
|
||||
draw_line(x, _y, x, marker_ys - 4);
|
||||
draw_line(x, marker_ye + 4, x, top);
|
||||
} else {
|
||||
draw_line(x, _y, x, marker_ys);
|
||||
draw_line(x, marker_ye, x, top);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (option_top()) {
|
||||
// draw minor ticks
|
||||
if (_tick_length == VARIABLE)
|
||||
draw_line(x, marker_ys, x, marker_ye - min_diff);
|
||||
else
|
||||
draw_line(x, marker_ys, x, marker_ye);
|
||||
|
||||
} else if (_tick_length == VARIABLE) {
|
||||
draw_line(x, marker_ys + 4, x, marker_ye);
|
||||
} else {
|
||||
draw_line(x, marker_ys, x, marker_ye);
|
||||
}
|
||||
}
|
||||
|
||||
} else { // major divs
|
||||
if (_modulo)
|
||||
v = fmodf(v + _modulo, _modulo);
|
||||
|
||||
float y;
|
||||
int align;
|
||||
|
||||
if (option_both()) {
|
||||
draw_line(x, _y, x, marker_ye);
|
||||
draw_line(x, marker_ye, x, _y + _h);
|
||||
y = marker_ys, align = CENTER;
|
||||
|
||||
} else {
|
||||
draw_line(x, marker_ys, x, marker_ye);
|
||||
|
||||
if (option_top())
|
||||
y = top - _label_offset, align = TOP|HCENTER;
|
||||
else
|
||||
y = _y + _label_offset, align = BOTTOM|HCENTER;
|
||||
}
|
||||
|
||||
if (!option_notext()) {
|
||||
char *s = format_value(v);
|
||||
|
||||
float l, r, b, t;
|
||||
_hud->_text_list.align(s, align, &x, &y, &l, &r, &b, &t);
|
||||
|
||||
if (l < _x || r > right)
|
||||
continue;
|
||||
|
||||
if (_label_gap == 0.0
|
||||
|| (l < _center_x - _label_gap && r < _center_x - _label_gap)
|
||||
|| (l > _center_x + _label_gap && r > _center_x + _label_gap)) {
|
||||
draw_text(x, y, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // for
|
||||
}
|
||||
|
||||
|
||||
char *HUD::Tape::format_value(float v)
|
||||
{
|
||||
if (fabs(v) < 1e-8) // avoid -0.0
|
||||
v = 0.0f;
|
||||
|
||||
if (_label_fmt == INT)
|
||||
snprintf(_buf, BUFSIZE, _format.c_str(), int(v));
|
||||
else if (_label_fmt == LONG)
|
||||
snprintf(_buf, BUFSIZE, _format.c_str(), long(v));
|
||||
else if (_label_fmt == FLOAT)
|
||||
snprintf(_buf, BUFSIZE, _format.c_str(), v);
|
||||
else // _label_fmt == DOUBLE
|
||||
snprintf(_buf, BUFSIZE, _format.c_str(), double(v));
|
||||
return _buf;
|
||||
}
|
||||
|
||||
|
||||
void HUD::Tape::draw_fixed_pointer(float x1, float y1, float x2, float y2, float x3, float y3)
|
||||
{
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(x1, y1);
|
||||
glVertex2f(x2, y2);
|
||||
glVertex2f(x3, y3);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
220
src/Instrumentation/HUD/HUD_tbi.cxx
Normal file
220
src/Instrumentation/HUD/HUD_tbi.cxx
Normal file
@@ -0,0 +1,220 @@
|
||||
// HUD_tbi.cxx -- HUD Turn-Bank-Indicator Instrument
|
||||
//
|
||||
// Written by Michele America, started September 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
||||
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
||||
//
|
||||
// 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 "HUD.hxx"
|
||||
#include "HUD_private.hxx"
|
||||
|
||||
HUD::TurnBankIndicator::TurnBankIndicator(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
||||
Item(hud, n, x, y),
|
||||
_bank(n->getNode("bank-input", false)),
|
||||
_sideslip(n->getNode("sideslip-input", false)),
|
||||
_gap_width(n->getFloatValue("gap-width", 5)),
|
||||
_bank_scale(n->getBoolValue("bank-scale", false))
|
||||
{
|
||||
if (!_bank_scale) {
|
||||
_bank.set_max(30.0, false);
|
||||
_bank.set_min(-30.0, false);
|
||||
_sideslip.set_max(20.0, false);
|
||||
_sideslip.set_min(-20.0, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HUD::TurnBankIndicator::draw(void)
|
||||
{
|
||||
if (!_bank.isValid() || !_sideslip.isValid())
|
||||
return;
|
||||
|
||||
if (_bank_scale)
|
||||
draw_scale();
|
||||
else
|
||||
draw_tee();
|
||||
}
|
||||
|
||||
|
||||
void HUD::TurnBankIndicator::draw_tee()
|
||||
{
|
||||
// ___________ /\ ___________
|
||||
// | \/ |
|
||||
|
||||
float bank = _bank.getFloatValue();
|
||||
float sideslip = _sideslip.getFloatValue();
|
||||
|
||||
float span = get_span();
|
||||
float tee = -_h;
|
||||
|
||||
// sideslip angle pixels per deg (width represents 40 deg)
|
||||
float ss_const = 2 * sideslip * span / 40.0;
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(_center_x, _center_y, 0.0);
|
||||
glRotatef(-bank, 0.0, 0.0, 1.0);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
|
||||
if (!_gap_width) {
|
||||
glVertex2f(-span, 0.0);
|
||||
glVertex2f(span, 0.0);
|
||||
|
||||
} else {
|
||||
glVertex2f(-span, 0.0);
|
||||
glVertex2f(-_gap_width, 0.0);
|
||||
glVertex2f(_gap_width, 0.0);
|
||||
glVertex2f(span, 0.0);
|
||||
}
|
||||
|
||||
// draw teemarks
|
||||
glVertex2f(_gap_width, 0.0);
|
||||
glVertex2f(_gap_width, tee);
|
||||
glVertex2f(-_gap_width, 0.0);
|
||||
glVertex2f(-_gap_width, tee);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex2f(ss_const, -_gap_width);
|
||||
glVertex2f(ss_const + _gap_width, 0.0);
|
||||
glVertex2f(ss_const, _gap_width);
|
||||
glVertex2f(ss_const - _gap_width, 0.0);
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void HUD::TurnBankIndicator::draw_scale()
|
||||
{
|
||||
// MIL-STD 1878B/4.2.2.4 bank scale
|
||||
float bank = _bank.getFloatValue();
|
||||
float sideslip = _sideslip.getFloatValue();
|
||||
|
||||
float cx = _center_x;
|
||||
float cy = _center_y;
|
||||
|
||||
float r = _w / 2.0;
|
||||
float minor = r - r * 3.0 / 70.0;
|
||||
float major = r - r * 5.0 / 70.0;
|
||||
|
||||
// hollow 0 degree mark
|
||||
float w = r / 70.0;
|
||||
if (w < 1.0)
|
||||
w = 1.0;
|
||||
float h = r * 6.0 / 70.0;
|
||||
draw_line(cx - w, _y, cx + w, _y);
|
||||
draw_line(cx - w, _y, cx - w, _y + h);
|
||||
draw_line(cx + w, _y, cx + w, _y + h);
|
||||
draw_line(cx - w, _y + h, cx + w, _y + h);
|
||||
|
||||
// tick lines
|
||||
draw_tick(10, r, minor, 0);
|
||||
draw_tick(20, r, minor, 0);
|
||||
draw_tick(30, r, major, 0);
|
||||
|
||||
int dir = bank > 0 ? 1 : -1;
|
||||
|
||||
if (fabs(bank) > 25) {
|
||||
draw_tick(45, r, minor, dir);
|
||||
draw_tick(60, r, major, dir);
|
||||
}
|
||||
|
||||
if (fabs(bank) > 55) {
|
||||
draw_tick(90, r, major, dir);
|
||||
draw_tick(135, r, major, dir);
|
||||
}
|
||||
|
||||
// bank marker
|
||||
float a;
|
||||
float rr = r + r * 0.5 / 70.0; // little gap for the arrow peak
|
||||
|
||||
a = (bank + 270.0) * SGD_DEGREES_TO_RADIANS;
|
||||
float x1 = cx + rr * cos(a);
|
||||
float y1 = cy + rr * sin(a);
|
||||
|
||||
rr = r * 3.0 / 70.0;
|
||||
a = (bank + 240.0) * SGD_DEGREES_TO_RADIANS;
|
||||
float x2 = x1 + rr * cos(a);
|
||||
float y2 = y1 + rr * sin(a);
|
||||
|
||||
a = (bank + 300.0) * SGD_DEGREES_TO_RADIANS;
|
||||
float x3 = x1 + rr * cos(a);
|
||||
float y3 = y1 + rr * sin(a);
|
||||
|
||||
draw_line(x1, y1, x2, y2);
|
||||
draw_line(x2, y2, x3, y3);
|
||||
draw_line(x3, y3, x1, y1);
|
||||
|
||||
|
||||
// sideslip marker
|
||||
rr = r + r * 0.5 / 70.0;
|
||||
a = (bank + sideslip + 270.0) * SGD_DEGREES_TO_RADIANS;
|
||||
x1 = cx + rr * cos(a);
|
||||
y1 = cy + rr * sin(a);
|
||||
|
||||
rr = r * 3.0 / 70.0;
|
||||
a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
|
||||
x2 = x1 + rr * cos(a);
|
||||
y2 = y1 + rr * sin(a);
|
||||
|
||||
a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
|
||||
x3 = x1 + rr * cos(a);
|
||||
y3 = y1 + rr * sin(a);
|
||||
|
||||
rr = r * 6.0 / 70.0;
|
||||
a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
|
||||
float x4 = x1 + rr * cos(a);
|
||||
float y4 = y1 + rr * sin(a);
|
||||
|
||||
a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
|
||||
float x5 = x1 + rr * cos(a);
|
||||
float y5 = y1 + rr * sin(a);
|
||||
|
||||
draw_line(x2, y2, x3, y3);
|
||||
draw_line(x3, y3, x5, y5);
|
||||
draw_line(x5, y5, x4, y4);
|
||||
draw_line(x4, y4, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
void HUD::TurnBankIndicator::draw_tick(float angle, float r1, float r2, int side)
|
||||
{
|
||||
float a = (270 - angle) * SGD_DEGREES_TO_RADIANS;
|
||||
float c = cos(a);
|
||||
float s = sin(a);
|
||||
float x1 = r1 * c;
|
||||
float x2 = r2 * c;
|
||||
float y1 = _center_y + r1 * s;
|
||||
float y2 = _center_y + r2 * s;
|
||||
if (side >= 0)
|
||||
draw_line(_center_x - x1, y1, _center_x - x2, y2);
|
||||
if (side <= 0)
|
||||
draw_line(_center_x + x1, y1, _center_x + x2, y2);
|
||||
}
|
||||
|
||||
|
||||
void HUD::TurnBankIndicator::draw_line(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
if (option_top()) {
|
||||
float y = 2.0 * _center_y; // mirror vertically
|
||||
Item::draw_line(x1, y - y1, x2, y - y2);
|
||||
} else
|
||||
Item::draw_line(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user