Browse Source

Fixed finally HUD offset! Now working on antialiasing / flickering.

QGC4.4
pixhawk 15 years ago
parent
commit
adba60590b
  1. 2
      src/uas/UAS.cc
  2. 64
      src/ui/HUD.cc

2
src/uas/UAS.cc

@ -430,7 +430,7 @@ void UAS::sendMessage(LinkInterface* link, mavlink_message_t message)
*/ */
const float UAS::filterVoltage(float value) const float UAS::filterVoltage(float value)
{ {
return lpVoltage * 0.8f + value * 0.2f; return lpVoltage * 0.7f + value * 0.3f;
/* /*
currentVoltage = value; currentVoltage = value;
static QList<float> voltages<float>(20); static QList<float> voltages<float>(20);

64
src/ui/HUD.cc

@ -388,12 +388,17 @@ void HUD::paintCenterBackground(float roll, float pitch, float yaw)
// Move to the center of the window // Move to the center of the window
glTranslatef(referenceWidth/2.0f,referenceHeight/2.0f,0); glTranslatef(referenceWidth/2.0f,referenceHeight/2.0f,0);
// Move based on the yaw difference
glTranslatef(yaw, 0.0f, 0.0f);
// Rotate based on the bank // Rotate based on the bank
glRotatef((roll/M_PI)*180.0f, 0, 0, 1); glRotatef((roll/M_PI)*180.0f, 0.0f, 0.0f, 1.0f);
// Translate in the direction of the rotation based // Translate in the direction of the rotation based
// on the pitch. On the 777, a pitch of 1 degree = 2 mm // on the pitch. On the 777, a pitch of 1 degree = 2 mm
glTranslatef(0, ((-pitch/M_PI)*180.0f * vPitchPerDeg), 0); //glTranslatef(0, ((-pitch/M_PI)*180.0f * vPitchPerDeg), 0);
glTranslatef(0.0f, (pitch * vPitchPerDeg * 16.5f), 0.0f);
// Ground // Ground
glColor3ub(179,102,0); glColor3ub(179,102,0);
@ -528,6 +533,29 @@ void HUD::paintEvent(QPaintEvent *event)
pitch = pitch * 0.3 + 0.7 * values.value("pitch", 0.0f); pitch = pitch * 0.3 + 0.7 * values.value("pitch", 0.0f);
yaw = yaw * 0.3 + 0.7 * values.value("yaw", 0.0f); yaw = yaw * 0.3 + 0.7 * values.value("yaw", 0.0f);
// Translate for yaw
const float maxYawTrans = 60.0f;
static float yawDiff = 0.0f;
float newYawDiff = valuesDot.value("yaw", 0.0f);
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;
//qDebug() << "yaw translation" << yawTrans << "integral" << yawInt << "difference" << yawDiff << "yaw" << yaw << "asin(yawInt)" << asinYaw;
// Update scaling factor // Update scaling factor
// adjust scaling to fit both horizontally and vertically // adjust scaling to fit both horizontally and vertically
@ -545,7 +573,7 @@ void HUD::paintEvent(QPaintEvent *event)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Blue / Brown background // Blue / Brown background
if (noCamera) paintCenterBackground(roll, pitch, yaw); if (noCamera) paintCenterBackground(roll, pitch, yawTrans);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
@ -556,11 +584,11 @@ void HUD::paintEvent(QPaintEvent *event)
//glEnable(GL_MULTISAMPLE); //glEnable(GL_MULTISAMPLE);
// QT PAINTING // QT PAINTING
makeCurrent(); //makeCurrent();
QPainter painter; QPainter painter;
painter.begin(this); painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
//painter.setRenderHint(QPainter::HighQualityAntialiasing, true); painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor); painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor);
@ -665,37 +693,19 @@ void HUD::paintEvent(QPaintEvent *event)
// MOVING PARTS // 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);
painter.translate(refToScreenX(yawTrans), 0);
// Rotate view and draw all roll-dependent indicators // Rotate view and draw all roll-dependent indicators
painter.rotate((roll/M_PI)* -180.0f); painter.rotate((roll/M_PI)* -180.0f);
painter.translate(0, (pitch/M_PI)* -180.0f * refToScreenY(1.8));
//qDebug() << "ROLL" << roll << "PITCH" << pitch << "YAW DIFF" << valuesDot.value("roll", 0.0f); //qDebug() << "ROLL" << roll << "PITCH" << pitch << "YAW DIFF" << valuesDot.value("roll", 0.0f);
// PITCH // PITCH
paintPitchLines((pitch/M_PI)*180.0f, &painter); paintPitchLines(pitch, &painter);
painter.end(); painter.end();
//glDisable(GL_MULTISAMPLE); //glDisable(GL_MULTISAMPLE);

Loading…
Cancel
Save