00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <cmath>
00020 #include <string>
00021
00022 #include "HUDView.h"
00023 #include "uvsim/utilities/utilities.h"
00024
00025 namespace uvsim
00026 {
00027
00028 HUDView::HUDView(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& glade)
00029 : Gtk::DrawingArea(cobject), m_glade(glade), rolldegree(0), pitchangle(0), yaw(0), heading(0)
00030 {
00031 std::cout << "Constructing HUDView" << std::endl;
00032 add_events(Gdk::POINTER_MOTION_MASK | Gdk::POINTER_MOTION_HINT_MASK | Gdk::BUTTON_PRESS_MASK
00033 | Gdk::BUTTON_RELEASE_MASK);
00034 }
00035
00036 bool HUDView::on_expose_event(GdkEventExpose* ev)
00037 {
00038 drawHUD();
00039 }
00040
00041 void HUDView::drawHUD()
00042 {
00043 double height_window = this->get_height();
00044 double width_window = this->get_width();
00045 double radius = MIN(height_window, width_window) / 3;
00046 double pitch_length = radius / 10;
00047 double center_arc1x = width_window / 2;
00048 double center_arc1y = height_window / 2 - radius;
00049 double arcextension;
00050
00051 cr = get_window()->create_cairo_context();
00052 Glib::RefPtr<Pango::Layout> pangoLayout = Pango::Layout::create(cr);
00053 Pango::FontDescription font ("sans normal 20");
00054 pangoLayout->set_font_description(font);
00055
00056 cr->set_source_rgb(0,0,0);
00057 cr->paint();
00058 cr->stroke();
00059
00060 cr->set_line_width(5);
00061 cr->set_source_rgb(1,0,0);
00062 cr->arc(width_window / 2,height_window/2, radius, 0, 2 * M_PI);
00063 cr->stroke();
00064
00065 cr->set_line_width(3);
00066 cr->set_source_rgb(1,1,0);
00067 cr->move_to(center_arc1x + (height_window - center_arc1y - pitch_length / 2)
00068 * cos(3/4.0 * M_PI + arcextension) - pitch_length * 5, center_arc1y
00069 + (height_window - center_arc1y - 9/4.0 * pitch_length)
00070 * cos(-45 * M_PI / 180) - pitch_length * 3.5);
00071 pangoLayout->set_text("-45");
00072 pangoLayout->update_from_cairo_context(cr);
00073 pangoLayout->add_to_cairo_context(cr);
00074 cr->stroke();
00075
00076 cr->move_to(center_arc1x + (height_window - center_arc1y - pitch_length / 2)
00077 * cos(1/4.0 * M_PI + arcextension) + pitch_length * 1.5, center_arc1y
00078 + (height_window - center_arc1y - 9/4.0 * pitch_length)
00079 * cos(45 * M_PI / 180) - pitch_length * 3.5);
00080 pangoLayout->set_text("45");
00081 pangoLayout->update_from_cairo_context(cr);
00082 pangoLayout->add_to_cairo_context(cr);
00083 cr->stroke();
00084 drawTopPart();
00085 drawBottomPart();
00086 drawHeading();
00087 }
00088
00089 void HUDView::drawTopPart()
00090 {
00091 double height_window = this->get_height();
00092 double width_window = this->get_width();
00093 double radius = MIN(height_window, width_window) / 3;
00094 double pitch_length = radius / 10;
00095 double center_arc1x = width_window / 2;
00096 double center_arc1y = height_window / 2 - radius;
00097 double counter;
00098 double arcextension;
00099 double degree;
00100 double degreegroundarc;
00101 double pitchanglestore = pitchangle;
00102 std::string text;
00103
00104 cr = get_window()->create_cairo_context();
00105 cr->set_line_width(3);
00106 Glib::RefPtr<Pango::Layout> pangoLayout = Pango::Layout::create(cr);
00107 Pango::FontDescription font ("sans normal 20");
00108 pangoLayout->set_font_description(font);
00109
00110 cr->set_source_rgb(0.8,0.3,0.5);
00111 cr->set_line_width(3);
00112 if (pitchangle < 90 && pitchangle > -90)
00113 {
00114 cr->move_to(width_window / 2 - sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00115 , height_window / 2 + radius * pitchanglestore / 90);
00116 cr->line_to(width_window / 2 + sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00117 , height_window / 2 + radius * pitchanglestore / 90);
00118 }
00119 else if (pitchangle == -90 || pitchangle == 270)
00120 {
00121
00122 cr->arc(width_window / 2, height_window / 2 - radius, 1, 0, 2 * M_PI);
00123 }
00124 else if (pitchangle == 90 || pitchangle == -270)
00125 {
00126
00127 cr->arc(width_window / 2, height_window / 2 + radius, 1, 0, 2 * M_PI);
00128 }
00129 else if (pitchangle > 90 && pitchangle < 270)
00130 {
00131 pitchanglestore = 180 - pitchangle;
00132 cr->move_to(width_window / 2 - sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00133 , height_window / 2 + radius * pitchanglestore / 90);
00134 cr->line_to(width_window / 2 + sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00135 , height_window / 2 + radius * pitchanglestore / 90);
00136 }
00137 else if (pitchangle > 270)
00138 {
00139 pitchanglestore = pitchangle - 360;
00140 cr->move_to(width_window / 2 - sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00141 , height_window / 2 + radius * pitchanglestore / 90);
00142 cr->line_to(width_window / 2 + sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00143 , height_window / 2 + radius * pitchanglestore / 90);
00144 }
00145 else if (pitchangle < -90 && pitchangle > -270)
00146 {
00147 pitchanglestore = -180 - pitchangle;
00148 cr->move_to(width_window / 2 - sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00149 , height_window / 2 + radius * pitchanglestore / 90);
00150 cr->line_to(width_window / 2 + sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00151 , height_window / 2 + radius * pitchanglestore / 90);
00152 }
00153 else if (pitchangle < -270)
00154 {
00155 pitchanglestore = 360 + pitchangle;
00156 cr->move_to(width_window / 2 - sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00157 , height_window / 2 + radius * pitchanglestore / 90);
00158 cr->line_to(width_window / 2 + sqrt(pow(radius,2) - pow(radius * pitchanglestore / 90,2))
00159 , height_window / 2 + radius * pitchanglestore / 90);
00160 }
00161 cr->stroke();
00162
00163 cr->set_source_rgb(0.72, 0.53, 0.04);
00164 degreegroundarc = acos(radius * pitchanglestore / 90 / radius);
00165 cr->arc(width_window / 2, height_window / 2, radius, 0.5 * M_PI - degreegroundarc
00166 , 0.5 * M_PI + degreegroundarc);
00167 cr->close_path();
00168 cr->fill();
00169 cr->stroke();
00170
00171 cr->set_source_rgb(0, 0.85, 1);
00172 degreegroundarc = acos(radius * pitchanglestore / 90 / radius);
00173 cr->arc_negative(width_window / 2, height_window / 2, radius, 0.5 * M_PI - degreegroundarc
00174 , 0.5 * M_PI + degreegroundarc);
00175 cr->close_path();
00176 cr->fill();
00177 cr->stroke();
00178
00179 cr->set_source_rgb(0.76,0.83,0.91);
00180 cr->set_line_width(8);
00181 cr->move_to(width_window / 2 - radius * cos(rolldegree * M_PI / 180), height_window / 2
00182 + radius * sin(rolldegree * M_PI / 180));
00183 cr->line_to(width_window / 2 + radius * cos(rolldegree * M_PI / 180), height_window / 2
00184 - radius * sin(rolldegree * M_PI / 180));
00185 cr->stroke();
00186
00187 cr->set_source_rgb(1,1,1);
00188 cr->set_line_width(3);
00189 for (counter = -2 ; counter <= 2 ; counter++)
00190 {
00191 if (counter != 0)
00192 {
00193 cr->move_to (width_window / 2 - pitch_length, height_window / 2 - radius * counter / 3);
00194 cr->line_to (width_window / 2 + pitch_length, height_window / 2 - radius * counter / 3);
00195
00196 }
00197 else
00198 {
00199 cr->move_to (width_window / 2 - pitch_length * 2, height_window / 2 - radius * counter / 3);
00200 cr->line_to (width_window / 2 + pitch_length * 2, height_window / 2 - radius * counter / 3);
00201 }
00202 }
00203 cr->stroke();
00204
00205 for (counter = -2 ; counter <= 2 ; counter++)
00206 {
00207 cr->set_source_rgb(0.118, 0.564, 1);
00208 cr->move_to (width_window / 2 + pitch_length * 2.5, height_window / 2
00209 - radius * counter / 3 - pitch_length);
00210 degree = -30 * counter;
00211 text = doubleToString(degree);
00212 pangoLayout->set_text(text);
00213 pangoLayout->update_from_cairo_context(cr);
00214 pangoLayout->add_to_cairo_context(cr);
00215 cr->stroke();
00216 }
00217
00218 }
00219
00220 void HUDView::drawBottomPart()
00221 {
00222 double height_window = this->get_height();
00223 double width_window = this->get_width();
00224 double radius = MIN(height_window, width_window) / 3;
00225 double pitch_length = radius / 10;
00226 double center_arc1x = width_window / 2;
00227 double center_arc1y = height_window / 2 - radius;
00228 double arcextension;
00229
00230 cr = get_window()->create_cairo_context();
00231 cr->set_line_width(3);
00232
00233
00234 arcextension = asin((7/4.0 *pitch_length) / (height_window - center_arc1y - 9/4.0 * pitch_length));
00235 cr->set_source_rgb(0,1,0);
00236 cr->arc(center_arc1x, center_arc1y, height_window - center_arc1y - pitch_length / 2,
00237 1/4.0 * M_PI - arcextension, 3/4.0 * M_PI + arcextension);
00238 cr->arc_negative(center_arc1x, center_arc1y, height_window - center_arc1y - pitch_length * 4,
00239 3/4.0 * M_PI + arcextension, 1/4.0 * M_PI - arcextension);
00240 cr->close_path();
00241 cr->fill();
00242 cr->stroke();
00243
00244 cr->set_source_rgb(0,0,1);
00245 cr->arc(center_arc1x + (height_window - center_arc1y - 9/4.0 * pitch_length) * sin(yaw * M_PI / 180),
00246 center_arc1y + (height_window - center_arc1y - 9/4.0 * pitch_length) * cos(yaw * M_PI / 180),
00247 pitch_length * 7/4.0, 0, 2 * M_PI);
00248 cr->fill();
00249 cr->stroke();
00250
00251 }
00252
00253 void HUDView::drawHeading()
00254 {
00255 double height_window = this->get_height();
00256 double width_window = this->get_width();
00257 double radius = MIN(height_window, width_window) / 3;
00258 double pitch_length = radius / 10;
00259 std::string text;
00260
00261 cr = get_window()->create_cairo_context();
00262 cr->set_line_width(3);
00263 Glib::RefPtr<Pango::Layout> pangoLayout = Pango::Layout::create(cr);
00264 Pango::FontDescription font ("sans normal 20");
00265 pangoLayout->set_font_description(font);
00266
00267 cr->set_source_rgb(1,1,1);
00268 cr->move_to(width_window / 2 - pitch_length * 1.5, pitch_length);
00269
00270
00271 if (heading > 360)
00272 {
00273 heading = heading - 360;
00274 }
00275 else if (heading < 0)
00276 {
00277 heading = 360 + heading;
00278 }
00279 text = intToString(heading);
00280 pangoLayout->set_text(text);
00281 pangoLayout->update_from_cairo_context(cr);
00282 pangoLayout->add_to_cairo_context(cr);
00283 cr->stroke();
00284
00285 }
00286 }
00287