From 5795eb6be48d5e29a3861904b764747c4a54451b Mon Sep 17 00:00:00 2001 From: pixhawk Date: Wed, 19 Jan 2011 18:05:11 +0100 Subject: [PATCH] Adjusted minor paths and destructors --- src/ui/HUD.cc | 352 +++++++++++++++++++++++++++----------------------- 1 file changed, 190 insertions(+), 162 deletions(-) diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 235e8988a..a55f73a08 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -142,11 +142,11 @@ HUD::HUD(int width, int height, QWidget* parent) fill.setColor(2, qRgb(0, 0, 0)); fill.fill(0); - QString imagePath = "/Users/user/Desktop/frame0000.png"; - qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath; - fill = QImage(imagePath); + //QString imagePath = "/Users/user/Desktop/frame0000.png"; + //qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath; + //fill = QImage(imagePath); - glImage = QGLWidget::convertToGLFormat(fill); + //glImage = QGLWidget::convertToGLFormat(fill); // Refresh timer refreshTimer->setInterval(updateInterval); @@ -154,8 +154,7 @@ HUD::HUD(int width, int height, QWidget* parent) connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintHUD())); // Resize to correct size and fill with image - resize(fill.size()); - glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); + //glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); // Set size once //setFixedSize(fill.size()); @@ -189,7 +188,7 @@ HUD::HUD(int width, int height, QWidget* parent) HUD::~HUD() { - + refreshTimer->stop(); } QSize HUD::sizeHint() const @@ -551,206 +550,235 @@ void HUD::paintEvent(QPaintEvent *event) void HUD::paintHUD() { - // static quint64 interval = 0; - // qDebug() << "INTERVAL:" << MG::TIME::getGroundTimeNow() - interval << __FILE__ << __LINE__; - // interval = MG::TIME::getGroundTimeNow(); + if (isVisible()) + { + // static quint64 interval = 0; + // qDebug() << "INTERVAL:" << MG::TIME::getGroundTimeNow() - interval << __FILE__ << __LINE__; + // interval = MG::TIME::getGroundTimeNow(); #if (QGC_EVENTLOOP_DEBUG) - qDebug() << "EVENTLOOP:" << __FILE__ << __LINE__; + qDebug() << "EVENTLOOP:" << __FILE__ << __LINE__; #endif - // Read out most important values to limit hash table lookups - // Low-pass roll, pitch and yaw - rollLP = rollLP * 0.2f + 0.8f * roll; - pitchLP = pitchLP * 0.2f + 0.8f * pitch; - yawLP = yawLP * 0.2f + 0.8f * yaw; - - // Translate for yaw - const float maxYawTrans = 60.0f; - - float newYawDiff = yawDiff; - if (isinf(newYawDiff)) newYawDiff = yawDiff; - if (newYawDiff > M_PI) newYawDiff = newYawDiff - M_PI; - - if (newYawDiff < -M_PI) newYawDiff = newYawDiff + M_PI; - - newYawDiff = yawDiff * 0.8 + newYawDiff * 0.2; - - yawDiff = newYawDiff; - - yawInt += newYawDiff; - - if (yawInt > M_PI) yawInt = M_PI; - if (yawInt < -M_PI) yawInt = -M_PI; - - float yawTrans = yawInt * (double)maxYawTrans; - yawInt *= 0.6f; + // Read out most important values to limit hash table lookups + // Low-pass roll, pitch and yaw + rollLP = rollLP * 0.2f + 0.8f * roll; + pitchLP = pitchLP * 0.2f + 0.8f * pitch; + yawLP = yawLP * 0.2f + 0.8f * yaw; - if ((yawTrans < 5.0) && (yawTrans > -5.0)) yawTrans = 0; + // Translate for yaw + const float maxYawTrans = 60.0f; - // Negate to correct direction - yawTrans = -yawTrans; + float newYawDiff = yawDiff; + if (isinf(newYawDiff)) newYawDiff = yawDiff; + if (newYawDiff > M_PI) newYawDiff = newYawDiff - M_PI; - //qDebug() << "yaw translation" << yawTrans << "integral" << yawInt << "difference" << yawDiff << "yaw" << yaw; + if (newYawDiff < -M_PI) newYawDiff = newYawDiff + M_PI; - // 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; + newYawDiff = yawDiff * 0.8 + newYawDiff * 0.2; + yawDiff = newYawDiff; + yawInt += newYawDiff; - // OPEN GL PAINTING - // Store model view matrix to be able to reset it to the previous state - makeCurrent(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (yawInt > M_PI) yawInt = M_PI; + if (yawInt < -M_PI) yawInt = -M_PI; - // Blue / Brown background - if (noCamera) paintCenterBackground(roll, pitch, yawTrans); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + float yawTrans = yawInt * (double)maxYawTrans; + yawInt *= 0.6f; - // END OF OPENGL PAINTING + if ((yawTrans < 5.0) && (yawTrans > -5.0)) yawTrans = 0; + // Negate to correct direction + yawTrans = -yawTrans; + //qDebug() << "yaw translation" << yawTrans << "integral" << yawInt << "difference" << yawDiff << "yaw" << yaw; - //glEnable(GL_MULTISAMPLE); + // 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; - // QT PAINTING - //makeCurrent(); - QPainter painter; - painter.begin(this); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setRenderHint(QPainter::HighQualityAntialiasing, true); - painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor); + // OPEN GL PAINTING + // Store model view matrix to be able to reset it to the previous state + makeCurrent(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // 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 + // Blue / Brown background + if (noCamera) + { + paintCenterBackground(roll, pitch, yawTrans); + } + // else { + // Fill with black background + QString imagePath = "/Users/user/Desktop/frame0000.png"; + if (QFileInfo(imagePath).exists()) + { + //qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath; + QImage fill = QImage(imagePath); - // 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); + glImage = QGLWidget::convertToGLFormat(fill); + float xFactor; + float yFactor; - // 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)); + xFactor = width() / (float)fill.width(); + yFactor = height() / (float)fill.height(); - 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))); + glPixelZoom(xFactor, yFactor); + // Resize to correct size and fill with image + glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); + // FIXME Adjust viewport to scale image into view + } + // } + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + // END OF OPENGL PAINTING + + + + //glEnable(GL_MULTISAMPLE); + + // QT PAINTING + //makeCurrent(); + QPainter painter; + painter.begin(this); + 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); - // 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; + // CENTER -// const float yawDeg = ((values.value("yaw", 0.0f)/M_PI)*180.0f)+180.f; + // 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); - // YAW is in compass-human readable format, so 0 - 360deg. This is normal in aviation, not -180 - +180. - const float yawDeg = ((yawLP/M_PI)*180.0f)+180.0f; - 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, -zSpeed, &painter); + // 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)); - // CHANGE RATE STRIPS - drawChangeRateStrip(49.0f, -50.0f, 15.0f, -1.0f, 1.0f, xSpeed, &painter); + 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))); - // GAUGES - // Left altitude gauge - drawChangeIndicatorGauge(-vGaugeSpacing, -15.0f, 10.0f, 2.0f, -zPos, defaultColor, &painter, false); - // Right speed gauge - drawChangeIndicatorGauge(vGaugeSpacing, -15.0f, 10.0f, 5.0f, xSpeed, defaultColor, &painter, false); + // 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; - // Waypoint name - if (waypointName != "") paintText(waypointName, defaultColor, 2.0f, (-vwidth/3.0) + 10, +vheight/3.0 + 15, &painter); + // YAW is in compass-human readable format, so 0 - 360deg. This is normal in aviation, not -180 - +180. + const float yawDeg = ((yawLP/M_PI)*180.0f)+180.0f; + yawAngle.sprintf("%03d", (int)yawDeg); + paintText(yawAngle, defaultColor, 3.5f, -3.7f, compassY+ 0.9f, &painter); - // MOVING PARTS + // CHANGE RATE STRIPS + drawChangeRateStrip(-51.0f, -50.0f, 15.0f, -1.0f, 1.0f, -zSpeed, &painter); + // CHANGE RATE STRIPS + drawChangeRateStrip(49.0f, -50.0f, 15.0f, -1.0f, 1.0f, xSpeed, &painter); + + // GAUGES - painter.translate(refToScreenX(yawTrans), 0); + // Left altitude gauge + drawChangeIndicatorGauge(-vGaugeSpacing, -15.0f, 10.0f, 2.0f, -zPos, defaultColor, &painter, false); - // Rotate view and draw all roll-dependent indicators - painter.rotate((rollLP/M_PI)* -180.0f); + // Right speed gauge + drawChangeIndicatorGauge(vGaugeSpacing, -15.0f, 10.0f, 5.0f, xSpeed, defaultColor, &painter, false); - painter.translate(0, (-pitchLP/M_PI)* -180.0f * refToScreenY(1.8)); - //qDebug() << "ROLL" << roll << "PITCH" << pitch << "YAW DIFF" << valuesDot.value("roll", 0.0f); + // Waypoint name + if (waypointName != "") paintText(waypointName, defaultColor, 2.0f, (-vwidth/3.0) + 10, +vheight/3.0 + 15, &painter); + + // MOVING PARTS + + + painter.translate(refToScreenX(yawTrans), 0); + + // Rotate view and draw all roll-dependent indicators + painter.rotate((rollLP/M_PI)* -180.0f); + + painter.translate(0, (-pitchLP/M_PI)* -180.0f * refToScreenY(1.8)); - // PITCH + //qDebug() << "ROLL" << roll << "PITCH" << pitch << "YAW DIFF" << valuesDot.value("roll", 0.0f); + + // PITCH - paintPitchLines(pitchLP, &painter); - painter.end(); - //glDisable(GL_MULTISAMPLE); + paintPitchLines(pitchLP, &painter); + painter.end(); + //glDisable(GL_MULTISAMPLE); - //glFlush(); + //glFlush(); + } } /* -- 2.22.0