|
|
|
@ -127,7 +127,7 @@ HUD::HUD(int width, int height, QWidget* parent)
@@ -127,7 +127,7 @@ HUD::HUD(int width, int height, QWidget* parent)
|
|
|
|
|
|
|
|
|
|
// Refresh timer
|
|
|
|
|
refreshTimer->setInterval(40); // 25 Hz
|
|
|
|
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(updateGL())); |
|
|
|
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(repaint())); |
|
|
|
|
|
|
|
|
|
// Resize to correct size and fill with image
|
|
|
|
|
resize(fill.size()); |
|
|
|
@ -512,11 +512,199 @@ void HUD::paintRollPitchStrips()
@@ -512,11 +512,199 @@ void HUD::paintRollPitchStrips()
|
|
|
|
|
|
|
|
|
|
void HUD::paintGL() |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HUD::paintEvent(QPaintEvent *event) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
static float roll = 0.0; |
|
|
|
|
static float pitch = 0.0; |
|
|
|
|
static float yaw = 0.0; |
|
|
|
|
|
|
|
|
|
// Read out most important values to limit hash table lookups
|
|
|
|
|
float roll = roll * 0.5 + 0.5 * values.value("roll", 0.0f); |
|
|
|
|
float pitch = pitch * 0.5 + 0.5 * values.value("pitch", 0.0f); |
|
|
|
|
float yaw = yaw * 0.5 + 0.5 * values.value("yaw", 0.0f); |
|
|
|
|
roll = roll * 0.5 + 0.5 * values.value("roll", 0.0f); |
|
|
|
|
pitch = pitch * 0.5 + 0.5 * values.value("pitch", 0.0f); |
|
|
|
|
yaw = yaw * 0.5 + 0.5 * values.value("yaw", 0.0f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update scaling factor
|
|
|
|
|
// adjust scaling to fit both horizontally and vertically
|
|
|
|
|
scalingFactor = this->width()/vwidth; |
|
|
|
|
double scalingFactorH = this->height()/vheight; |
|
|
|
|
if (scalingFactorH < scalingFactor) scalingFactor = scalingFactorH; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OPEN GL PAINTING
|
|
|
|
|
makeCurrent(); |
|
|
|
|
//setupViewport(width(), height());
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
// Blue / Brown background
|
|
|
|
|
if (noCamera) paintCenterBackground(roll, pitch, yaw); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// QT PAINTING
|
|
|
|
|
QPainter painter; |
|
|
|
|
painter.begin(this); |
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
|
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true); |
|
|
|
|
painter.setRenderHint(QPainter::HighQualityAntialiasing, true); |
|
|
|
|
painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// COORDINATE FRAME IS NOW (0,0) at CENTER OF WIDGET
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw all fixed indicators
|
|
|
|
|
// MODE
|
|
|
|
|
paintText(mode, infoColor, 2.0f, (-vwidth/2.0) + 10, -vheight/2.0 + 10, &painter); |
|
|
|
|
// STATE
|
|
|
|
|
paintText(state, infoColor, 2.0f, (-vwidth/2.0) + 10, -vheight/2.0 + 15, &painter); |
|
|
|
|
// BATTERY
|
|
|
|
|
paintText(fuelStatus, fuelColor, 2.0f, (-vwidth/2.0) + 10, -vheight/2.0 + 20, &painter); |
|
|
|
|
// Waypoint
|
|
|
|
|
paintText(waypointName, defaultColor, 2.0f, (-vwidth/3.0) + 10, +vheight/3.0 + 15, &painter); |
|
|
|
|
|
|
|
|
|
// YAW INDICATOR
|
|
|
|
|
//
|
|
|
|
|
// .
|
|
|
|
|
// . .
|
|
|
|
|
// .......
|
|
|
|
|
//
|
|
|
|
|
const float yawIndicatorWidth = 4.0f; |
|
|
|
|
const float yawIndicatorY = vheight/2.0f - 10.0f; |
|
|
|
|
QPolygon yawIndicator(4); |
|
|
|
|
yawIndicator.setPoint(0, QPoint(refToScreenX(0.0f), refToScreenY(yawIndicatorY))); |
|
|
|
|
yawIndicator.setPoint(1, QPoint(refToScreenX(yawIndicatorWidth/2.0f), refToScreenY(yawIndicatorY+yawIndicatorWidth))); |
|
|
|
|
yawIndicator.setPoint(2, QPoint(refToScreenX(-yawIndicatorWidth/2.0f), refToScreenY(yawIndicatorY+yawIndicatorWidth))); |
|
|
|
|
yawIndicator.setPoint(3, QPoint(refToScreenX(0.0f), refToScreenY(yawIndicatorY))); |
|
|
|
|
painter.setPen(defaultColor); |
|
|
|
|
painter.drawPolyline(yawIndicator); |
|
|
|
|
|
|
|
|
|
// CENTER
|
|
|
|
|
|
|
|
|
|
// HEADING INDICATOR
|
|
|
|
|
//
|
|
|
|
|
// __ __
|
|
|
|
|
// \/\/
|
|
|
|
|
//
|
|
|
|
|
const float hIndicatorWidth = 7.0f; |
|
|
|
|
const float hIndicatorY = -25.0f; |
|
|
|
|
const float hIndicatorYLow = hIndicatorY + hIndicatorWidth / 6.0f; |
|
|
|
|
const float hIndicatorSegmentWidth = hIndicatorWidth / 7.0f; |
|
|
|
|
QPolygon hIndicator(7); |
|
|
|
|
hIndicator.setPoint(0, QPoint(refToScreenX(0.0f-hIndicatorWidth/2.0f), refToScreenY(hIndicatorY))); |
|
|
|
|
hIndicator.setPoint(1, QPoint(refToScreenX(0.0f-hIndicatorWidth/2.0f+hIndicatorSegmentWidth*1.75f), refToScreenY(hIndicatorY))); |
|
|
|
|
hIndicator.setPoint(2, QPoint(refToScreenX(0.0f-hIndicatorSegmentWidth*1.0f), refToScreenY(hIndicatorYLow))); |
|
|
|
|
hIndicator.setPoint(3, QPoint(refToScreenX(0.0f), refToScreenY(hIndicatorY))); |
|
|
|
|
hIndicator.setPoint(4, QPoint(refToScreenX(0.0f+hIndicatorSegmentWidth*1.0f), refToScreenY(hIndicatorYLow))); |
|
|
|
|
hIndicator.setPoint(5, QPoint(refToScreenX(0.0f+hIndicatorWidth/2.0f-hIndicatorSegmentWidth*1.75f), refToScreenY(hIndicatorY))); |
|
|
|
|
hIndicator.setPoint(6, QPoint(refToScreenX(0.0f+hIndicatorWidth/2.0f), refToScreenY(hIndicatorY))); |
|
|
|
|
painter.setPen(defaultColor); |
|
|
|
|
painter.drawPolyline(hIndicator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SETPOINT
|
|
|
|
|
const float centerWidth = 4.0f; |
|
|
|
|
painter.setPen(defaultColor); |
|
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
|
// TODO
|
|
|
|
|
//painter.drawEllipse(QPointF(refToScreenX(qMin(10.0f, values.value("roll desired", 0.0f) * 10.0f)), refToScreenY(qMin(10.0f, values.value("pitch desired", 0.0f) * 10.0f))), refToScreenX(centerWidth/2.0f), refToScreenX(centerWidth/2.0f));
|
|
|
|
|
|
|
|
|
|
const float centerCrossWidth = 10.0f; |
|
|
|
|
// left
|
|
|
|
|
painter.drawLine(QPointF(refToScreenX(-centerWidth / 2.0f), refToScreenY(0.0f)), QPointF(refToScreenX(-centerCrossWidth / 2.0f), refToScreenY(0.0f))); |
|
|
|
|
// right
|
|
|
|
|
painter.drawLine(QPointF(refToScreenX(centerWidth / 2.0f), refToScreenY(0.0f)), QPointF(refToScreenX(centerCrossWidth / 2.0f), refToScreenY(0.0f))); |
|
|
|
|
// top
|
|
|
|
|
painter.drawLine(QPointF(refToScreenX(0.0f), refToScreenY(-centerWidth / 2.0f)), QPointF(refToScreenX(0.0f), refToScreenY(-centerCrossWidth / 2.0f))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// COMPASS
|
|
|
|
|
const float compassY = -vheight/2.0f + 10.0f; |
|
|
|
|
QRectF compassRect(QPointF(refToScreenX(-5.0f), refToScreenY(compassY)), QSizeF(refToScreenX(10.0f), refToScreenY(5.0f))); |
|
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
|
painter.setPen(Qt::SolidLine); |
|
|
|
|
painter.setPen(defaultColor); |
|
|
|
|
painter.drawRoundedRect(compassRect, 2, 2); |
|
|
|
|
QString yawAngle; |
|
|
|
|
|
|
|
|
|
const float yawDeg = ((values.value("yaw", 0.0f)/M_PI)*180.0f)+180.f; |
|
|
|
|
//qDebug() << "YAW: " << yawDeg;
|
|
|
|
|
yawAngle.sprintf("%03d", (int)yawDeg); |
|
|
|
|
paintText(yawAngle, defaultColor, 3.5f, -3.7f, compassY+ 0.9f, &painter); |
|
|
|
|
|
|
|
|
|
// CHANGE RATE STRIPS
|
|
|
|
|
drawChangeRateStrip(-51.0f, -50.0f, 15.0f, -1.0f, 1.0f, valuesDot.value("z", 0.0f), &painter); |
|
|
|
|
|
|
|
|
|
// CHANGE RATE STRIPS
|
|
|
|
|
drawChangeRateStrip(49.0f, -50.0f, 15.0f, -1.0f, 1.0f, valuesDot.value("x", 0.0f), &painter); |
|
|
|
|
|
|
|
|
|
// GAUGES
|
|
|
|
|
|
|
|
|
|
// Left altitude gauge
|
|
|
|
|
drawChangeIndicatorGauge(-vGaugeSpacing, -15.0f, 10.0f, 2.0f, -values.value("z", 0.0f), defaultColor, &painter, false); |
|
|
|
|
|
|
|
|
|
// Right speed gauge
|
|
|
|
|
drawChangeIndicatorGauge(vGaugeSpacing, -15.0f, 10.0f, 5.0f, values.value("xSpeed", 0.0f), defaultColor, &painter, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MOVING PARTS
|
|
|
|
|
|
|
|
|
|
// Translate for yaw
|
|
|
|
|
const float maxYawTrans = 60.0f; |
|
|
|
|
float yawDiff = valuesDot.value("yaw", 0.0f); |
|
|
|
|
if (isinf(yawDiff)) yawDiff = 0.0f; |
|
|
|
|
if (yawDiff > M_PI) yawDiff = yawDiff - M_PI; |
|
|
|
|
|
|
|
|
|
if (yawDiff < -M_PI) yawDiff = yawDiff + M_PI; |
|
|
|
|
|
|
|
|
|
yawInt += yawDiff; |
|
|
|
|
|
|
|
|
|
if (yawInt > M_PI) yawInt = M_PI; |
|
|
|
|
if (yawInt < -M_PI) yawInt = -M_PI; |
|
|
|
|
|
|
|
|
|
float yawTrans = yawInt * (double)maxYawTrans; |
|
|
|
|
yawInt *= 0.6f; |
|
|
|
|
//qDebug() << "yaw translation" << yawTrans << "integral" << yawInt << "difference" << yawDiff << "yaw" << yaw << "asin(yawInt)" << asinYaw;
|
|
|
|
|
|
|
|
|
|
painter.translate(0, (pitch/M_PI)* -180.0f * refToScreenY(1.8)); |
|
|
|
|
|
|
|
|
|
painter.translate(refToScreenX(yawTrans), 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Rotate view and draw all roll-dependent indicators
|
|
|
|
|
painter.rotate((roll/M_PI)* -180.0f); |
|
|
|
|
|
|
|
|
|
//qDebug() << "ROLL" << roll << "PITCH" << pitch << "YAW DIFF" << valuesDot.value("roll", 0.0f);
|
|
|
|
|
|
|
|
|
|
// PITCH
|
|
|
|
|
|
|
|
|
|
paintPitchLines((pitch/M_PI)*180.0f, &painter); |
|
|
|
|
|
|
|
|
|
painter.end(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glFlush(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
void HUD::paintGL() |
|
|
|
|
{ |
|
|
|
|
static float roll = 0.0; |
|
|
|
|
static float pitch = 0.0; |
|
|
|
|
static float yaw = 0.0; |
|
|
|
|
|
|
|
|
|
// Read out most important values to limit hash table lookups
|
|
|
|
|
roll = roll * 0.5 + 0.5 * values.value("roll", 0.0f); |
|
|
|
|
pitch = pitch * 0.5 + 0.5 * values.value("pitch", 0.0f); |
|
|
|
|
yaw = yaw * 0.5 + 0.5 * values.value("yaw", 0.0f); |
|
|
|
|
|
|
|
|
|
//qDebug() << __FILE__ << __LINE__ << "ROLL:" << roll << "PITCH:" << pitch << "YAW:" << yaw;
|
|
|
|
|
|
|
|
|
@ -527,16 +715,16 @@ void HUD::paintGL()
@@ -527,16 +715,16 @@ void HUD::paintGL()
|
|
|
|
|
double scalingFactorH = this->height()/vheight; |
|
|
|
|
if (scalingFactorH < scalingFactor) scalingFactor = scalingFactorH; |
|
|
|
|
|
|
|
|
|
//makeCurrent();
|
|
|
|
|
makeCurrent(); |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
//if(!noCamera) glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());
|
|
|
|
|
glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); // FIXME Remove after testing
|
|
|
|
|
//glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); // FIXME Remove after testing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Blue / Brown background
|
|
|
|
|
if (noCamera) paintCenterBackground(roll, pitch, yaw); |
|
|
|
|
|
|
|
|
|
//glFlush();
|
|
|
|
|
glFlush(); |
|
|
|
|
|
|
|
|
|
// // Store current GL model view
|
|
|
|
|
// glMatrixMode(GL_MODELVIEW);
|
|
|
|
@ -554,8 +742,9 @@ void HUD::paintGL()
@@ -554,8 +742,9 @@ void HUD::paintGL()
|
|
|
|
|
|
|
|
|
|
// Position the coordinate frame according to the setup
|
|
|
|
|
|
|
|
|
|
makeOverlayCurrent(); |
|
|
|
|
QPainter painter(this); |
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true); |
|
|
|
|
//painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
//painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
|
|
|
|
|
painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor); |
|
|
|
|
|
|
|
|
@ -656,6 +845,7 @@ void HUD::paintGL()
@@ -656,6 +845,7 @@ void HUD::paintGL()
|
|
|
|
|
// Right speed gauge
|
|
|
|
|
drawChangeIndicatorGauge(vGaugeSpacing, -15.0f, 10.0f, 5.0f, values.value("xSpeed", 0.0f), defaultColor, &painter, false); |
|
|
|
|
|
|
|
|
|
glFlush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MOVING PARTS
|
|
|
|
@ -697,7 +887,8 @@ void HUD::paintGL()
@@ -697,7 +887,8 @@ void HUD::paintGL()
|
|
|
|
|
glFlush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param pitch pitch angle in degrees (-180 to 180) |
|
|
|
|