42 #ifdef CHECK_MEMORY_LEAKS
44 #endif // CHECK_MEMORY_LEAKS
47 #define CIRCLE_RESOLUTION (SUMOReal)10 // inverse in degrees
56 GLdouble* vertex_data[4],
57 GLfloat weight[4], GLdouble** dataOut) {
62 vertex = (GLdouble*)malloc(7 *
sizeof(GLdouble));
64 vertex[0] = coords[0];
65 vertex[1] = coords[1];
66 vertex[2] = coords[2];
80 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
82 for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) {
84 glVertex2d(p.
x(), p.
y());
88 glVertex2d(p.
x(), p.
y());
99 GLUtesselator* tobj = gluNewTess();
100 gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv);
101 gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &glBegin);
102 gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &glEnd);
103 gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &
combCallback);
104 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
105 gluTessBeginPolygon(tobj, NULL);
106 gluTessBeginContour(tobj);
107 double* points =
new double[(v.size() + int(close)) * 3];
109 for (
int i = 0; i != (int)v.size(); ++i) {
110 points[3 * i] = v[i].x();
111 points[3 * i + 1] = v[i].y();
112 points[3 * i + 2] = 0;
113 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
116 const int i = (int)v.size();
117 points[3 * i] = v[0].x();
118 points[3 * i + 1] = v[0].y();
119 points[3 * i + 2] = 0;
120 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
122 gluTessEndContour(tobj);
123 gluTessEndPolygon(tobj);
133 glTranslated(beg.
x(), beg.
y(), 0);
134 glRotated(rot, 0, 0, 1);
136 glVertex2d(-width - offset, 0);
137 glVertex2d(-width - offset, -visLength);
138 glVertex2d(width - offset, -visLength);
139 glVertex2d(width - offset, 0);
150 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
151 glRotated(rot, 0, 0, 1);
153 glVertex2d(-width, 0);
154 glVertex2d(-width, -visLength);
155 glVertex2d(width, -visLength);
156 glVertex2d(width, 0);
165 while (delta > 180) {
168 while (delta < -180) {
177 const std::vector<SUMOReal>& rots,
178 const std::vector<SUMOReal>& lengths,
181 int e = (int) geom.size() - 1;
182 for (
int i = 0; i < e; i++) {
183 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
186 if (cornerDetail > 0) {
187 for (
int i = 1; i < e; i++) {
189 glTranslated(geom[i].x(), geom[i].y(), 0.1);
198 if (angleEnd - angleBeg > 360) {
201 if (angleEnd - angleBeg < -360) {
205 if (angleEnd > angleBeg) {
219 const std::vector<SUMOReal>& rots,
220 const std::vector<SUMOReal>& lengths,
221 const std::vector<RGBColor>& cols,
223 int e = (int) geom.size() - 1;
224 for (
int i = 0; i < e; i++) {
226 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
228 if (cornerDetail > 0) {
229 for (
int i = 1; i < e; i++) {
232 glTranslated(geom[i].x(), geom[i].y(), 0);
244 const std::vector<SUMOReal>& rots,
245 const std::vector<SUMOReal>& lengths,
247 int minS = (int)
MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size());
248 for (
int i = 0; i < minS; i++) {
256 int e = (int) geom.size() - 1;
257 for (
int i = 0; i < e; i++) {
271 glTranslated(beg.
x(), beg.
y(), 0);
272 glRotated(rot, 0, 0, 1);
275 glVertex2d(0, -visLength);
285 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
286 glRotated(rot, 0, 0, 1);
289 glVertex2d(0, -visLength);
299 int e = (int) v.size() - 1;
300 for (
int i = 0; i < e; ++i) {
301 glVertex2d(v[i].x(), v[i].y());
302 glVertex2d(v[i + 1].x(), v[i + 1].y());
311 int e = (int) v.size() - 1;
312 for (
int i = 0; i < e; ++i) {
314 glVertex2d(v[i].x(), v[i].y());
315 glVertex2d(v[i + 1].x(), v[i + 1].y());
325 glVertex2d(beg.
x(), beg.
y());
326 glVertex2d(end.
x(), end.
y());
359 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
362 for (
int i = 0; i <= steps; ++i) {
364 glBegin(GL_TRIANGLES);
365 glVertex2d(p1.first * width, p1.second * width);
366 glVertex2d(p2.first * width, p2.second * width);
384 for (
int i = 0; i < 360; i += 10) {
390 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
391 std::pair<SUMOReal, SUMOReal> p1 =
393 for (
int i = (
int)(beg / 10); i < steps && (36.0 / (
SUMOReal) steps * (
SUMOReal) i) * 10 < end; i++) {
394 const std::pair<SUMOReal, SUMOReal>& p2 =
396 glBegin(GL_TRIANGLES);
397 glVertex2d(p1.first * width, p1.second * width);
398 glVertex2d(p2.first * width, p2.second * width);
399 glVertex2d(p2.first * iwidth, p2.second * iwidth);
401 glVertex2d(p2.first * iwidth, p2.second * iwidth);
402 glVertex2d(p1.first * iwidth, p1.second * iwidth);
403 glVertex2d(p1.first * width, p1.second * width);
407 const std::pair<SUMOReal, SUMOReal>& p2 =
409 glBegin(GL_TRIANGLES);
410 glVertex2d(p1.first * width, p1.second * width);
411 glVertex2d(p2.first * width, p2.second * width);
412 glVertex2d(p2.first * iwidth, p2.second * iwidth);
414 glVertex2d(p2.first * iwidth, p2.second * iwidth);
415 glVertex2d(p1.first * iwidth, p1.second * iwidth);
416 glVertex2d(p1.first * width, p1.second * width);
425 if (length < tLength) {
426 tWidth *= length / tLength;
431 glTranslated(rl.
x(), rl.
y(), 0);
433 glBegin(GL_TRIANGLES);
434 glVertex2d(0, tLength);
435 glVertex2d(-tWidth, 0);
436 glVertex2d(+tWidth, 0);
451 glGetDoublev(GL_CURRENT_COLOR, current);
452 return RGBColor(static_cast<unsigned char>(current[0] * 255. + 0.5),
453 static_cast<unsigned char>(current[1] * 255. + 0.5),
454 static_cast<unsigned char>(current[2] * 255. + 0.5),
455 static_cast<unsigned char>(current[3] * 255. + 0.5));
464 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
466 glTranslated(pos.
x(), pos.
y(), layer);
470 glRotated(180, 1, 0, 0);
471 glRotated(angle, 0, 0, 1);
472 glTranslated(-w / 2., size / 4, 0);
483 if (boxAngle > 360) {
488 const SUMOReal borderWidth = size / 20;
489 const SUMOReal boxHeight = size * 0.8;
490 const SUMOReal boxWidth = stringWidth + size / 2;
492 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
493 glTranslated(0, 0, layer);
496 left.
sub(boxWidth / 2, -boxHeight / 2.7);
498 left.
add(borderWidth * 1.5, 0);
500 glTranslated(0, 0, 0.01);
501 drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth);
506 glTranslated(pos.
x(), pos.
y(), 0.01);
509 glRotated(180, 1, 0, 0);
510 glRotated(angle, 0, 0, 1);
511 glTranslated(-stringWidth / 2., 0, 0);
520 for (
int i = 0; i < (int)shape.size(); ++i) {
void sub(SUMOReal dx, SUMOReal dy)
Substracts the given position from this one.
int pfDrawString(const char *c)
static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v)
Converts the given hsv-triplet to rgb.
void add(const Position &pos)
Adds the given position to this one.
static void debugVertices(const PositionVector &shape, SUMOReal size, SUMOReal layer=256)
draw vertex numbers for the given shape (in a random color)
T MIN4(T a, T b, T c, T d)
static void drawOutlineCircle(SUMOReal width, SUMOReal iwidth, int steps=8)
Draws an unfilled circle around (0,0)
static SUMOReal rand()
Returns a random real number in [0, 1)
void pfSetPosition(SUMOReal x, SUMOReal y)
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
static void drawBoxLine(const Position &beg, SUMOReal rot, SUMOReal visLength, SUMOReal width, SUMOReal offset=0)
Draws a thick line.
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
static void drawText(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &col=RGBColor::BLACK, const SUMOReal angle=0)
draw Text with given parameters
SUMOReal x() const
Returns the x-position.
#define UNUSED_PARAMETER(x)
static void drawTriangleAtEnd(const Position &p1, const Position &p2, SUMOReal tLength, SUMOReal tWidth)
Draws a triangle at the end of the given line.
unsigned char blue() const
Returns the blue-amount of the color.
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
static bool rightTurn(SUMOReal angle1, SUMOReal angle2)
whether the road makes a right turn (or goes straight)
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
static std::vector< std::pair< SUMOReal, SUMOReal > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
A point in 2D or 3D with translation and scaling methods.
unsigned char alpha() const
Returns the alpha-amount of the color.
static int angleLookup(SUMOReal angleDeg)
normalize angle for lookup in myCircleCoords
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
static void drawTextBox(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &txtColor=RGBColor::BLACK, const RGBColor &bgColor=RGBColor::WHITE, const RGBColor &borderColor=RGBColor::BLACK, const SUMOReal angle=0)
draw Text box with given parameters
static SUMOReal naviDegree(const SUMOReal angle)
void APIENTRY combCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut)
void pfSetScale(SUMOReal s)
SUMOReal y() const
Returns the y-position.
#define CIRCLE_RESOLUTION
SUMOReal pfdkGetStringWidth(const char *c)
static void drawLine(const Position &beg, SUMOReal rot, SUMOReal visLength)
Draws a thin line.
unsigned char green() const
Returns the green-amount of the color.
unsigned char red() const
Returns the red-amount of the color.
SUMOReal angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position ...
static RGBColor getColor()
gets the gl-color