Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
1c1f5379
Commit
1c1f5379
authored
Apr 14, 2010
by
pixhawk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Windows HUD issues
parent
a420adc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
201 additions
and
9 deletions
+201
-9
HUD.cc
src/ui/HUD.cc
+200
-9
HUD.h
src/ui/HUD.h
+1
-0
No files found.
src/ui/HUD.cc
View file @
1c1f5379
...
...
@@ -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
());
...
...
@@ -511,12 +511,200 @@ 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.0
f
);
float
pitch
=
pitch
*
0.5
+
0.5
*
values
.
value
(
"pitch"
,
0.0
f
);
float
yaw
=
yaw
*
0.5
+
0.5
*
values
.
value
(
"yaw"
,
0.0
f
);
roll
=
roll
*
0.5
+
0.5
*
values
.
value
(
"roll"
,
0.0
f
);
pitch
=
pitch
*
0.5
+
0.5
*
values
.
value
(
"pitch"
,
0.0
f
);
yaw
=
yaw
*
0.5
+
0.5
*
values
.
value
(
"yaw"
,
0.0
f
);
// 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.0
f
,
(
-
vwidth
/
2.0
)
+
10
,
-
vheight
/
2.0
+
10
,
&
painter
);
// STATE
paintText
(
state
,
infoColor
,
2.0
f
,
(
-
vwidth
/
2.0
)
+
10
,
-
vheight
/
2.0
+
15
,
&
painter
);
// BATTERY
paintText
(
fuelStatus
,
fuelColor
,
2.0
f
,
(
-
vwidth
/
2.0
)
+
10
,
-
vheight
/
2.0
+
20
,
&
painter
);
// Waypoint
paintText
(
waypointName
,
defaultColor
,
2.0
f
,
(
-
vwidth
/
3.0
)
+
10
,
+
vheight
/
3.0
+
15
,
&
painter
);
// YAW INDICATOR
//
// .
// . .
// .......
//
const
float
yawIndicatorWidth
=
4.0
f
;
const
float
yawIndicatorY
=
vheight
/
2.0
f
-
10.0
f
;
QPolygon
yawIndicator
(
4
);
yawIndicator
.
setPoint
(
0
,
QPoint
(
refToScreenX
(
0.0
f
),
refToScreenY
(
yawIndicatorY
)));
yawIndicator
.
setPoint
(
1
,
QPoint
(
refToScreenX
(
yawIndicatorWidth
/
2.0
f
),
refToScreenY
(
yawIndicatorY
+
yawIndicatorWidth
)));
yawIndicator
.
setPoint
(
2
,
QPoint
(
refToScreenX
(
-
yawIndicatorWidth
/
2.0
f
),
refToScreenY
(
yawIndicatorY
+
yawIndicatorWidth
)));
yawIndicator
.
setPoint
(
3
,
QPoint
(
refToScreenX
(
0.0
f
),
refToScreenY
(
yawIndicatorY
)));
painter
.
setPen
(
defaultColor
);
painter
.
drawPolyline
(
yawIndicator
);
// CENTER
// HEADING INDICATOR
//
// __ __
// \/\/
//
const
float
hIndicatorWidth
=
7.0
f
;
const
float
hIndicatorY
=
-
25.0
f
;
const
float
hIndicatorYLow
=
hIndicatorY
+
hIndicatorWidth
/
6.0
f
;
const
float
hIndicatorSegmentWidth
=
hIndicatorWidth
/
7.0
f
;
QPolygon
hIndicator
(
7
);
hIndicator
.
setPoint
(
0
,
QPoint
(
refToScreenX
(
0.0
f
-
hIndicatorWidth
/
2.0
f
),
refToScreenY
(
hIndicatorY
)));
hIndicator
.
setPoint
(
1
,
QPoint
(
refToScreenX
(
0.0
f
-
hIndicatorWidth
/
2.0
f
+
hIndicatorSegmentWidth
*
1.75
f
),
refToScreenY
(
hIndicatorY
)));
hIndicator
.
setPoint
(
2
,
QPoint
(
refToScreenX
(
0.0
f
-
hIndicatorSegmentWidth
*
1.0
f
),
refToScreenY
(
hIndicatorYLow
)));
hIndicator
.
setPoint
(
3
,
QPoint
(
refToScreenX
(
0.0
f
),
refToScreenY
(
hIndicatorY
)));
hIndicator
.
setPoint
(
4
,
QPoint
(
refToScreenX
(
0.0
f
+
hIndicatorSegmentWidth
*
1.0
f
),
refToScreenY
(
hIndicatorYLow
)));
hIndicator
.
setPoint
(
5
,
QPoint
(
refToScreenX
(
0.0
f
+
hIndicatorWidth
/
2.0
f
-
hIndicatorSegmentWidth
*
1.75
f
),
refToScreenY
(
hIndicatorY
)));
hIndicator
.
setPoint
(
6
,
QPoint
(
refToScreenX
(
0.0
f
+
hIndicatorWidth
/
2.0
f
),
refToScreenY
(
hIndicatorY
)));
painter
.
setPen
(
defaultColor
);
painter
.
drawPolyline
(
hIndicator
);
// SETPOINT
const
float
centerWidth
=
4.0
f
;
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.0
f
;
// left
painter
.
drawLine
(
QPointF
(
refToScreenX
(
-
centerWidth
/
2.0
f
),
refToScreenY
(
0.0
f
)),
QPointF
(
refToScreenX
(
-
centerCrossWidth
/
2.0
f
),
refToScreenY
(
0.0
f
)));
// right
painter
.
drawLine
(
QPointF
(
refToScreenX
(
centerWidth
/
2.0
f
),
refToScreenY
(
0.0
f
)),
QPointF
(
refToScreenX
(
centerCrossWidth
/
2.0
f
),
refToScreenY
(
0.0
f
)));
// top
painter
.
drawLine
(
QPointF
(
refToScreenX
(
0.0
f
),
refToScreenY
(
-
centerWidth
/
2.0
f
)),
QPointF
(
refToScreenX
(
0.0
f
),
refToScreenY
(
-
centerCrossWidth
/
2.0
f
)));
// COMPASS
const
float
compassY
=
-
vheight
/
2.0
f
+
10.0
f
;
QRectF
compassRect
(
QPointF
(
refToScreenX
(
-
5.0
f
),
refToScreenY
(
compassY
)),
QSizeF
(
refToScreenX
(
10.0
f
),
refToScreenY
(
5.0
f
)));
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.0
f
)
/
M_PI
)
*
180.0
f
)
+
180.
f
;
//qDebug() << "YAW: " << yawDeg;
yawAngle
.
sprintf
(
"%03d"
,
(
int
)
yawDeg
);
paintText
(
yawAngle
,
defaultColor
,
3.5
f
,
-
3.7
f
,
compassY
+
0.9
f
,
&
painter
);
// CHANGE RATE STRIPS
drawChangeRateStrip
(
-
51.0
f
,
-
50.0
f
,
15.0
f
,
-
1.0
f
,
1.0
f
,
valuesDot
.
value
(
"z"
,
0.0
f
),
&
painter
);
// CHANGE RATE STRIPS
drawChangeRateStrip
(
49.0
f
,
-
50.0
f
,
15.0
f
,
-
1.0
f
,
1.0
f
,
valuesDot
.
value
(
"x"
,
0.0
f
),
&
painter
);
// GAUGES
// Left altitude gauge
drawChangeIndicatorGauge
(
-
vGaugeSpacing
,
-
15.0
f
,
10.0
f
,
2.0
f
,
-
values
.
value
(
"z"
,
0.0
f
),
defaultColor
,
&
painter
,
false
);
// Right speed gauge
drawChangeIndicatorGauge
(
vGaugeSpacing
,
-
15.0
f
,
10.0
f
,
5.0
f
,
values
.
value
(
"xSpeed"
,
0.0
f
),
defaultColor
,
&
painter
,
false
);
// MOVING PARTS
// Translate for yaw
const
float
maxYawTrans
=
60.0
f
;
float
yawDiff
=
valuesDot
.
value
(
"yaw"
,
0.0
f
);
if
(
isinf
(
yawDiff
))
yawDiff
=
0.0
f
;
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.6
f
;
//qDebug() << "yaw translation" << yawTrans << "integral" << yawInt << "difference" << yawDiff << "yaw" << yaw << "asin(yawInt)" << asinYaw;
painter
.
translate
(
0
,
(
pitch
/
M_PI
)
*
-
180.0
f
*
refToScreenY
(
1.8
));
painter
.
translate
(
refToScreenX
(
yawTrans
),
0
);
// Rotate view and draw all roll-dependent indicators
painter
.
rotate
((
roll
/
M_PI
)
*
-
180.0
f
);
//qDebug() << "ROLL" << roll << "PITCH" << pitch << "YAW DIFF" << valuesDot.value("roll", 0.0f);
// PITCH
paintPitchLines
((
pitch
/
M_PI
)
*
180.0
f
,
&
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()
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()
// 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()
// 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()
glFlush();
}
}*/
/**
* @param pitch pitch angle in degrees (-180 to 180)
...
...
src/ui/HUD.h
View file @
1c1f5379
...
...
@@ -181,6 +181,7 @@ protected:
float
fineStrokeWidth
;
///< Fine line stroke width, used throughout the HUD
QString
waypointName
;
///< Waypoint name displayed in HUD
void
paintEvent
(
QPaintEvent
*
event
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment