#include <GLHelper.h>
This class offers some static methods for drawing primitives in openGL.
Definition at line 47 of file GLHelper.h.
Static Public Member Functions | |
| static void | drawBoxLine (const Position2D &beg1, const Position2D &beg2, SUMOReal rot, SUMOReal visLength, SUMOReal width) throw () |
| Draws a thick line using the mean of both given points as begin position. | |
| static void | drawBoxLine (const Position2D &beg, SUMOReal rot, SUMOReal visLength, SUMOReal width) throw () |
| Draws a thick line. | |
| static void | drawBoxLines (const Position2DVector &geom, SUMOReal width) throw () |
| Draws thick lines. | |
| static void | drawBoxLines (const Position2DVector &geom1, const Position2DVector &geom2, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width) throw () |
| Draws thick lines using the mean of the points given in the point lists as begin positions. | |
| static void | drawBoxLines (const Position2DVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width) throw () |
| Draws thick lines. | |
| static void | drawFilledCircle (SUMOReal width, int steps, SUMOReal beg, SUMOReal end) throw () |
| Draws a filled circle around (0,0). | |
| static void | drawFilledCircle (SUMOReal width, int steps=8) throw () |
| Draws a filled circle around (0,0). | |
| static void | drawFilledPoly (const Position2DVector &v, bool close) throw () |
| Draws a filled polygon described by the list of points. | |
| static void | drawLine (const Position2D &beg, const Position2D &end) throw () |
| Draws a thin line between the two points. | |
| static void | drawLine (const Position2DVector &v) throw () |
| Draws a thin line along the given position vector. | |
| static void | drawLine (const Position2D &beg1, const Position2D &beg2, SUMOReal rot, SUMOReal visLength) throw () |
| Draws a thin line using the mean of both given points as begin position. | |
| static void | drawLine (const Position2D &beg, SUMOReal rot, SUMOReal visLength) throw () |
| Draws a thin line. | |
| static void | drawOutlineCircle (SUMOReal width, SUMOReal iwidth, int steps, SUMOReal beg, SUMOReal end) throw () |
| Draws an unfilled circle around (0,0). | |
| static void | drawOutlineCircle (SUMOReal width, SUMOReal iwidth, int steps=8) throw () |
| Draws an unfilled circle around (0,0). | |
| static void | drawTriangleAtEnd (const Line2D &l, SUMOReal tLength, SUMOReal tWidth) throw () |
| Draws a triangle at the end of the given line. | |
Static Private Attributes | |
| static std::vector< std::pair < SUMOReal, SUMOReal > > | myCircleCoords |
| Storage for precomputed sin/cos-values describing a circle. | |
| void GLHelper::drawBoxLine | ( | const Position2D & | beg1, | |
| const Position2D & | beg2, | |||
| SUMOReal | rot, | |||
| SUMOReal | visLength, | |||
| SUMOReal | width | |||
| ) | throw () [static] |
Draws a thick line using the mean of both given points as begin position.
The line is drawn as a GL_QUADS.
| [in] | beg1 | One of the begin positions of the line to use the mean of |
| [in] | beg2 | One of the begin positions of the line to use the mean of |
| [in] | rot | The direction the line shall be drawn to (in radiants) |
| [in] | visLength | The length of the line |
| [in] | width | The width of the line |
Definition at line 91 of file GLHelper.cpp.
00093 { 00094 glPushMatrix(); 00095 glTranslated((beg2.x()+beg1.x())*.5, (beg2.y()+beg1.y())*.5, 0); 00096 glRotated(rot, 0, 0, 1); 00097 glBegin(GL_QUADS); 00098 glVertex2d(-width, 0); 00099 glVertex2d(-width, -visLength); 00100 glVertex2d(width, -visLength); 00101 glVertex2d(width, 0); 00102 glEnd(); 00103 glPopMatrix(); 00104 }
| void GLHelper::drawBoxLine | ( | const Position2D & | beg, | |
| SUMOReal | rot, | |||
| SUMOReal | visLength, | |||
| SUMOReal | width | |||
| ) | throw () [static] |
Draws a thick line.
The line is drawn as a GL_QUADS.
| [in] | beg | The begin position of the line |
| [in] | rot | The direction the line shall be drawn to (in radiants) |
| [in] | visLength | The length of the line |
| [in] | width | The width of the line |
Definition at line 75 of file GLHelper.cpp.
Referenced by drawAction_drawVehicleAsPoly(), and drawBoxLines().
00076 { 00077 glPushMatrix(); 00078 glTranslated(beg.x(), beg.y(), 0); 00079 glRotated(rot, 0, 0, 1); 00080 glBegin(GL_QUADS); 00081 glVertex2d(-width, 0); 00082 glVertex2d(-width, -visLength); 00083 glVertex2d(width, -visLength); 00084 glVertex2d(width, 0); 00085 glEnd(); 00086 glPopMatrix(); 00087 }
| void GLHelper::drawBoxLines | ( | const Position2DVector & | geom, | |
| SUMOReal | width | |||
| ) | throw () [static] |
Draws thick lines.
Widths and length are computed internally by this method, each line is then drawn using drawBoxLine.
| [in] | geom | The list of begin positions of the lines |
| [in] | width | The width of the lines |
Definition at line 133 of file GLHelper.cpp.
References Position2D::distanceTo(), PI, SUMOReal, Position2D::x(), and Position2D::y().
00133 { 00134 int e = (int) geom.size() - 1; 00135 for (int i=0; i<e; i++) { 00136 const Position2D &f = geom[i]; 00137 const Position2D &s = geom[i+1]; 00138 drawBoxLine(f, 00139 (SUMOReal) atan2((s.x()-f.x()), (f.y()-s.y()))*(SUMOReal) 180.0/(SUMOReal) PI, 00140 f.distanceTo(s), 00141 width); 00142 } 00143 }
| void GLHelper::drawBoxLines | ( | const Position2DVector & | geom1, | |
| const Position2DVector & | geom2, | |||
| const std::vector< SUMOReal > & | rots, | |||
| const std::vector< SUMOReal > & | lengths, | |||
| SUMOReal | width | |||
| ) | throw () [static] |
Draws thick lines using the mean of the points given in the point lists as begin positions.
Each line is drawn using drawBoxLine.
| [in] | geom1 | One of the lists to obtain the lines' begin positions to use the mean of |
| [in] | geom2 | One of the lists to obtain the lines' begin positions to use the mean of |
| [in] | rots | The directions the lines shall be drawn to (in radiants) |
| [in] | lengths | The lengths of the lines |
| [in] | width | The width of the lines |
Definition at line 120 of file GLHelper.cpp.
References drawBoxLine(), and MIN4().
00124 { 00125 int minS = (int) MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size()); 00126 for (int i=0; i<minS; i++) { 00127 GLHelper::drawBoxLine(geom1[i], geom2[i], rots[i], lengths[i], width); 00128 } 00129 }
| void GLHelper::drawBoxLines | ( | const Position2DVector & | geom, | |
| const std::vector< SUMOReal > & | rots, | |||
| const std::vector< SUMOReal > & | lengths, | |||
| SUMOReal | width | |||
| ) | throw () [static] |
Draws thick lines.
Each line is drawn using drawBoxLine.
| [in] | geom | The list of begin positions of the lines |
| [in] | rots | The directions the lines shall be drawn to (in radiants) |
| [in] | lengths | The lengths of the lines |
| [in] | width | The width of the lines |
Definition at line 108 of file GLHelper.cpp.
Referenced by GUIViewTraffic::draw(), GUIViewTraffic::drawBestLanes(), GUIPolygon2D::drawGL(), GUILaneWrapper::drawGL(), GUIEmitter::drawGL(), GUIEdge::drawGL(), GUIBusStop::drawGL(), and GUI_E2_ZS_Collector::MyWrapper::drawGL().
00111 { 00112 int e = (int) geom.size() - 1; 00113 for (int i=0; i<e; i++) { 00114 drawBoxLine(geom[i], rots[i], lengths[i], width); 00115 } 00116 }
| void GLHelper::drawFilledCircle | ( | SUMOReal | width, | |
| int | steps, | |||
| SUMOReal | beg, | |||
| SUMOReal | end | |||
| ) | throw () [static] |
Draws a filled circle around (0,0).
The circle is drawn use GL_TRIANGLES.
| [in] | width | The width of the circle |
| [in] | steps | The number of steps to divide the circle into |
| [in] | beg | The begin angle in degress |
| [in] | end | The end angle in degress |
Definition at line 204 of file GLHelper.cpp.
00204 { 00205 if (myCircleCoords.size()==0) { 00206 for (int i=0; i<360; i+=10) { 00207 SUMOReal x = (SUMOReal) sin((SUMOReal) i / 180.0 * PI); 00208 SUMOReal y = (SUMOReal) cos((SUMOReal) i / 180.0 * PI); 00209 myCircleCoords.push_back(std::pair<SUMOReal, SUMOReal>(x, y)); 00210 } 00211 } 00212 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00213 std::pair<SUMOReal, SUMOReal> p1 = 00214 beg==0 ? myCircleCoords[0] : myCircleCoords[((int) beg/10)%36]; 00215 for (int i=(int)(beg/10); i<steps&&(36.0/(SUMOReal) steps *(SUMOReal) i)*10<end; i++) { 00216 const std::pair<SUMOReal, SUMOReal> &p2 = 00217 myCircleCoords[(size_t)(36.0/(SUMOReal) steps * (SUMOReal) i)]; 00218 glBegin(GL_TRIANGLES); 00219 glVertex2d(p1.first * width, p1.second * width); 00220 glVertex2d(p2.first * width, p2.second * width); 00221 glVertex2d(0, 0); 00222 glEnd(); 00223 p1 = p2; 00224 } 00225 const std::pair<SUMOReal, SUMOReal> &p2 = 00226 end==360 ? myCircleCoords[0] : myCircleCoords[((int) end/10)%36]; 00227 glBegin(GL_TRIANGLES); 00228 glVertex2d(p1.first * width, p1.second * width); 00229 glVertex2d(p2.first * width, p2.second * width); 00230 glVertex2d(0, 0); 00231 glEnd(); 00232 }
| void GLHelper::drawFilledCircle | ( | SUMOReal | width, | |
| int | steps = 8 | |||
| ) | throw () [static] |
Draws a filled circle around (0,0).
The circle is drawn by calling drawFilledCircle(width, steps, 0, 360).
| [in] | width | The width of the circle |
| [in] | steps | The number of steps to divide the circle into |
Definition at line 198 of file GLHelper.cpp.
Referenced by drawAction_drawVehicleAsPoly(), drawAction_drawVehicleBlinker(), GUITriggeredRerouter::drawGL(), GUIPointOfInterest::drawGL(), GUILaneSpeedTrigger::drawGL(), and GUIBusStop::drawGL().
00198 { 00199 drawFilledCircle(width, steps, 0, 360); 00200 }
| void GLHelper::drawFilledPoly | ( | const Position2DVector & | v, | |
| bool | close | |||
| ) | throw () [static] |
Draws a filled polygon described by the list of points.
| [in] | v | The polygon to draw |
| [in] | close | Whether the first point shall be appended |
Definition at line 55 of file GLHelper.cpp.
References Position2D::x(), and Position2D::y().
Referenced by GUIJunctionWrapper::drawGL().
00055 { 00056 if (v.size()==0) { 00057 return; 00058 } 00059 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00060 glBegin(GL_POLYGON); 00061 const Position2DVector::ContType &l = v.getCont(); 00062 for (Position2DVector::ContType ::const_iterator i=l.begin(); i!=l.end(); i++) { 00063 const Position2D &p = *i; 00064 glVertex2d(p.x(), p.y()); 00065 } 00066 if (close) { 00067 const Position2D &p = *(l.begin()); 00068 glVertex2d(p.x(), p.y()); 00069 } 00070 glEnd(); 00071 }
| void GLHelper::drawLine | ( | const Position2D & | beg, | |
| const Position2D & | end | |||
| ) | throw () [static] |
Draws a thin line between the two points.
The line is drawn as a GL_LINES.
| [in] | beg | Begin of the line |
| [in] | end | End of the line |
Definition at line 188 of file GLHelper.cpp.
00188 { 00189 glBegin(GL_LINES); 00190 glVertex2d(beg.x(), end.y()); 00191 glVertex2d(beg.x(), end.y()); 00192 glEnd(); 00193 }
| void GLHelper::drawLine | ( | const Position2DVector & | v | ) | throw () [static] |
Draws a thin line along the given position vector.
The line is drawn as a GL_LINES.
| [in] | v | The positions vector to use |
Definition at line 175 of file GLHelper.cpp.
00175 { 00176 glBegin(GL_LINES); 00177 int e = (int) v.size() - 1; 00178 for (int i=0; i<e; ++i) { 00179 glVertex2d(v[i].x(), v[i].y()); 00180 glVertex2d(v[i+1].x(), v[i+1].y()); 00181 } 00182 glEnd(); 00183 }
| void GLHelper::drawLine | ( | const Position2D & | beg1, | |
| const Position2D & | beg2, | |||
| SUMOReal | rot, | |||
| SUMOReal | visLength | |||
| ) | throw () [static] |
Draws a thin line using the mean of both given points as begin position.
The line is drawn as a GL_LINES.
| [in] | beg1 | One of the begin positions of the line to use the mean of |
| [in] | beg2 | One of the begin positions of the line to use the mean of |
| [in] | rot | The direction the line shall be drawn to (in radiants) |
| [in] | visLength | The length of the line |
Definition at line 160 of file GLHelper.cpp.
00161 { 00162 glPushMatrix(); 00163 glTranslated((beg2.x()+beg1.x())*.5, (beg2.y()+beg1.y())*.5, 0); 00164 glRotated(rot, 0, 0, 1); 00165 glBegin(GL_LINES); 00166 glVertex2d(0, 0); 00167 glVertex2d(0, -visLength); 00168 glEnd(); 00169 glPopMatrix(); 00170 }
| void GLHelper::drawLine | ( | const Position2D & | beg, | |
| SUMOReal | rot, | |||
| SUMOReal | visLength | |||
| ) | throw () [static] |
Draws a thin line.
The line is drawn as a GL_LINES.
| [in] | beg | The begin position of the line |
| [in] | rot | The direction the line shall be drawn to (in radiants) |
| [in] | visLength | The length of the line |
Definition at line 147 of file GLHelper.cpp.
Referenced by GUIViewTraffic::drawBestLanes(), GUIPolygon2D::drawGL(), GUILaneWrapper::drawGL(), and GUI_E2_ZS_Collector::MyWrapper::drawGL().
00147 { 00148 glPushMatrix(); 00149 glTranslated(beg.x(), beg.y(), 0); 00150 glRotated(rot, 0, 0, 1); 00151 glBegin(GL_LINES); 00152 glVertex2d(0, 0); 00153 glVertex2d(0, -visLength); 00154 glEnd(); 00155 glPopMatrix(); 00156 }
| void GLHelper::drawOutlineCircle | ( | SUMOReal | width, | |
| SUMOReal | iwidth, | |||
| int | steps, | |||
| SUMOReal | beg, | |||
| SUMOReal | end | |||
| ) | throw () [static] |
Draws an unfilled circle around (0,0).
The circle is drawn use GL_TRIANGLES.
| [in] | width | The (outer) width of the circle |
| [in] | iwidth | The inner width of the circle |
| [in] | steps | The number of steps to divide the circle into |
| [in] | beg | The begin angle in degress |
| [in] | end | The end angle in degress |
Definition at line 242 of file GLHelper.cpp.
00243 { 00244 if (myCircleCoords.size()==0) { 00245 for (int i=0; i<360; i+=10) { 00246 SUMOReal x = (SUMOReal) sin((SUMOReal) i / 180.0 * PI); 00247 SUMOReal y = (SUMOReal) cos((SUMOReal) i / 180.0 * PI); 00248 myCircleCoords.push_back(std::pair<SUMOReal, SUMOReal>(x, y)); 00249 } 00250 } 00251 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00252 std::pair<SUMOReal, SUMOReal> p1 = 00253 beg==0 ? myCircleCoords[0] : myCircleCoords[((int) beg/10)%36]; 00254 for (int i=(int)(beg/10); i<steps&&(36.0/(SUMOReal) steps *(SUMOReal) i)*10<end; i++) { 00255 const std::pair<SUMOReal, SUMOReal> &p2 = 00256 myCircleCoords[(size_t)(36.0/(SUMOReal) steps * (SUMOReal) i)]; 00257 glBegin(GL_TRIANGLES); 00258 glVertex2d(p1.first * width, p1.second * width); 00259 glVertex2d(p2.first * width, p2.second * width); 00260 glVertex2d(p2.first * iwidth, p2.second * iwidth); 00261 00262 glVertex2d(p2.first * iwidth, p2.second * iwidth); 00263 glVertex2d(p1.first * iwidth, p1.second * iwidth); 00264 glVertex2d(p1.first * width, p1.second * width); 00265 glEnd(); 00266 p1 = p2; 00267 } 00268 const std::pair<SUMOReal, SUMOReal> &p2 = 00269 end==360 ? myCircleCoords[0] : myCircleCoords[((int) end/10)%36]; 00270 glBegin(GL_TRIANGLES); 00271 glVertex2d(p1.first * width, p1.second * width); 00272 glVertex2d(p2.first * width, p2.second * width); 00273 glVertex2d(p2.first * iwidth, p2.second * iwidth); 00274 00275 glVertex2d(p2.first * iwidth, p2.second * iwidth); 00276 glVertex2d(p1.first * iwidth, p1.second * iwidth); 00277 glVertex2d(p1.first * width, p1.second * width); 00278 glEnd(); 00279 }
| void GLHelper::drawOutlineCircle | ( | SUMOReal | width, | |
| SUMOReal | iwidth, | |||
| int | steps = 8 | |||
| ) | throw () [static] |
Draws an unfilled circle around (0,0).
The circle is drawn by calling drawOutlineCircle(width, iwidth, steps, 0, 360).
| [in] | width | The (outer) width of the circle |
| [in] | iwidth | The inner width of the circle |
| [in] | steps | The number of steps to divide the circle into |
Definition at line 236 of file GLHelper.cpp.
00236 { 00237 drawOutlineCircle(width, iwidth, steps, 0, 360); 00238 }
| void GLHelper::drawTriangleAtEnd | ( | const Line2D & | l, | |
| SUMOReal | tLength, | |||
| SUMOReal | tWidth | |||
| ) | throw () [static] |
Draws a triangle at the end of the given line.
| [in] | l | The line at which end the triangle shall be drawn |
| [in] | tLength | The length of the triangle |
| [in] | tWidth | The width of the triangle |
Definition at line 283 of file GLHelper.cpp.
Referenced by ROWdrawAction_drawLane2LaneConnections().
00284 { 00285 if (l.length()<tLength) { 00286 tWidth = tWidth * l.length() / tLength; 00287 tLength = l.length(); 00288 } 00289 Line2D rl(l.getPositionAtDistance(l.length()-tLength), l.p2()); 00290 glPushMatrix(); 00291 glTranslated(rl.p1().x(), rl.p1().y(), 0); 00292 glRotated(-l.atan2DegreeAngle(), 0, 0, 1); 00293 glBegin(GL_TRIANGLES); 00294 glVertex2d(0, -tLength); 00295 glVertex2d(-tWidth, 0); 00296 glVertex2d(+tWidth, 0); 00297 glEnd(); 00298 glPopMatrix(); 00299 }
std::vector< std::pair< SUMOReal, SUMOReal > > GLHelper::myCircleCoords [static, private] |
Storage for precomputed sin/cos-values describing a circle.
Definition at line 232 of file GLHelper.h.
1.5.6