FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SimpleEarth/src/Hud.cpp at master · MAPSWorks/SimpleEarth · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
MAPSWorks
/
SimpleEarth
Public
forked from
hmendoza2001/SimpleEarth
Notifications
You must be signed in to change notification settings
Fork
2
Star
4
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SimpleEarth
/
src
/
Hud.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
223 lines (199 loc) · 6.74 KB
Breadcrumbs
SimpleEarth
/
src
/
Hud.cpp
Copy path
File metadata and controls
223 lines (199 loc) · 6.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* The Simple Earth Project
* Copyright (C) 2016 HueSoft LLC
* Author: Hector Mendoza, hector.mendoza@huesoftllc.com
*
* This file is part of the Simple Earth Project.
*
* The Simple Earth Project is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version
* 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#
include
"
Hud.h
"
#
include
"
globals.h
"
#
include
"
WorldObjectManager.h
"
#
include
"
Utilities.h
"
#
include
"
Camera.h
"
Hud* Hud::
mInstance
=
NULL
;
//
Singleton implementation
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Constructor. Initializes attributes.
*/
Hud::Hud
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mShowHud
=
true
;
mShowLabels
=
false
;
mPainter
=
NULL
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Destructor.
*/
Hud::~Hud
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mInstance
=
NULL
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Singleton pattern implementation. Returns the single instance of this class.
*
* @return The single instance of this class
*/
Hud*
Hud::getInstance
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
if
(
mInstance
==
NULL
)
{
mInstance
=
new
Hud
();
}
return
mInstance
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Returns true if Heads Up Display (HUD) is shown.
*
* @return True if Heads Up Display (HUD) is shown, false otherwise
*/
bool
Hud::getShowHud
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
return
mShowHud
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Returns true if world object labels are shown.
*
* @return True if world object labels are shown, false otherwise
*/
bool
Hud::getShowLabels
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
return
mShowLabels
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Sets the value of flag to show/hide Heads Up Display (HUD).
*
* @param show Set to true if you want the HUD to be shown
*/
void
Hud::setShowHud
(
bool
show)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mShowHud
= show;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Sets the value of flag to show/hide world object labels.
*
* @param show Set to true if you want world object labels to be shown
*/
void
Hud::setShowLabels
(
bool
show)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mShowLabels
= show;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Sets the handle to the painter object. This handle is used to invoke Qt's
* OpenGL text rendering capabilities.
*
* @param painter Handle to Qt painter object
*/
void
Hud::setPainter
(QPainter* painter)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mPainter
= painter;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Renders the Heads Up Display (HUD). Currently, the HUD renders the camera's
* position on the upper left corner of the screen and also renders all the
* world object labels.
*/
void
Hud::renderHud
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mPainter
->
setBrush
(
QBrush
(
QColor
(
0
,
0
,
0
,
100
)));
mPainter
->
setFont
(
QFont
(
"
Arial
"
,
13
));
if
(
mShowHud
)
{
//
draw semi-transparent black rectangle
mPainter
->
drawRect
(
12
,
10
,
195
,
68
);
GeodeticPosition cameraPosition =
Camera::getInstance
()->
getGeodeticPosition
();
QString latStr =
"
Lat:
"
+
Utilities::decimalDegreesToDMS
(cameraPosition.
latitude
,
true
);
QString lonStr =
"
Lon:
"
+
Utilities::decimalDegreesToDMS
(cameraPosition.
longitude
,
false
);
//
display camera altitude in Km or m
float
altitudeKm = cameraPosition.
altitude
;
QString altStr;
if
(altitudeKm <
1
.
0f
)
{
int
altitudeMeters = altitudeKm *
1000
.
0f
;
altStr =
"
Alt:
"
+
QString::number
(altitudeMeters) +
"
m
"
;
}
else
{
altStr =
"
Alt:
"
+
QString::number
(altitudeKm,
'
f
'
,
1
) +
"
Km
"
;
}
mPainter
->
setPen
(Qt::white);
mPainter
->
drawText
(
20
,
30
, latStr);
mPainter
->
drawText
(
20
,
50
, lonStr);
mPainter
->
drawText
(
20
,
70
, altStr);
}
if
(
mShowLabels
)
{
//
render world object labels
renderWorldObjectLabels
();
}
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Renders the labels for all world objects.
*/
void
Hud::renderWorldObjectLabels
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
WorldObjectManager* worldObjectManager =
WorldObjectManager::getInstance
();
Camera* camera =
Camera::getInstance
();
WorldObject* worldObject =
NULL
;
SimpleVector screenLocation;
QString label;
ScreenCoordinates screenSize =
Camera::getInstance
()->
getScreenSize
();
for
(
int
i =
0
; i < worldObjectManager->
getNumberOfObjects
(); i++)
{
worldObject = worldObjectManager->
getWorldObject
(i);
if
(worldObject !=
NULL
&& !worldObject->
getHasExpired
())
{
screenLocation = worldObject->
getScreenLocation
();
//
only draw the label if world object is not being obscured by the earth
//
and if projection is not negative (not behind the camera, which means
//
screenZ is below 1.0)
if
(screenLocation.
z
<
1
.
0f
&&
!
Utilities::checkObscure
(camera->
getGeodeticPosition
(),worldObject->
getGeodeticPosition
()) &&
worldObject->
getIsVisible
())
{
label = worldObject->
getLabel
();
//
set pen color to world object color
SimpleColor color = worldObject->
getColor
();
int
red = color.
red
*
255
.
0f
;
int
green = color.
green
*
255
.
0f
;
int
blue = color.
blue
*
255
.
0f
;
mPainter
->
setPen
(
QColor
(red, green, blue));
//
reverse Y to screen coordinates
screenLocation.
y
= (
float
)screenSize.
y
- screenLocation.
y
;
mPainter
->
drawText
((
int
)(screenLocation.
x
+
20.0
), (
int
)screenLocation.
y
, label);
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL