43 #define CIRCLE_RESOLUTION (double)10 // inverse in degrees 52 GLdouble* vertex_data[4],
53 GLfloat weight[4], GLdouble** dataOut) {
58 vertex = (GLdouble*)malloc(7 *
sizeof(GLdouble));
60 vertex[0] = coords[0];
61 vertex[1] = coords[1];
62 vertex[2] = coords[2];
76 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
78 for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) {
80 glVertex2d(p.
x(), p.
y());
84 glVertex2d(p.
x(), p.
y());
95 GLUtesselator* tobj = gluNewTess();
96 gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv);
97 gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &glBegin);
98 gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &glEnd);
99 gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &
combCallback);
100 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
101 gluTessBeginPolygon(tobj, NULL);
102 gluTessBeginContour(tobj);
103 double* points =
new double[(v.size() + int(close)) * 3];
105 for (
int i = 0; i != (int)v.size(); ++i) {
106 points[3 * i] = v[i].x();
107 points[3 * i + 1] = v[i].y();
108 points[3 * i + 2] = 0;
109 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
112 const int i = (int)v.size();
113 points[3 * i] = v[0].x();
114 points[3 * i + 1] = v[0].y();
115 points[3 * i + 2] = 0;
116 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
118 gluTessEndContour(tobj);
119 gluTessEndPolygon(tobj);
127 double width,
double offset) {
129 glTranslated(beg.
x(), beg.
y(), 0);
130 glRotated(rot, 0, 0, 1);
132 glVertex2d(-width - offset, 0);
133 glVertex2d(-width - offset, -visLength);
134 glVertex2d(width - offset, -visLength);
135 glVertex2d(width - offset, 0);
143 double rot,
double visLength,
146 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
147 glRotated(rot, 0, 0, 1);
149 glVertex2d(-width, 0);
150 glVertex2d(-width, -visLength);
151 glVertex2d(width, -visLength);
152 glVertex2d(width, 0);
160 double delta = angle2 - angle1;
161 while (delta > 180) {
164 while (delta < -180) {
173 const std::vector<double>& rots,
174 const std::vector<double>& lengths,
175 double width,
int cornerDetail,
double offset) {
177 int e = (int) geom.size() - 1;
178 for (
int i = 0; i < e; i++) {
179 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
182 if (cornerDetail > 0) {
183 for (
int i = 1; i < e; i++) {
185 glTranslated(geom[i].x(), geom[i].y(), 0.1);
191 double angleBeg = -rots[i - 1];
192 double angleEnd = 180 - rots[i];
194 if (angleEnd - angleBeg > 360) {
197 if (angleEnd - angleBeg < -360) {
201 if (angleEnd > angleBeg) {
215 const std::vector<double>& rots,
216 const std::vector<double>& lengths,
217 const std::vector<RGBColor>& cols,
218 double width,
int cornerDetail,
double offset) {
219 int e = (int) geom.size() - 1;
220 for (
int i = 0; i < e; i++) {
222 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
224 if (cornerDetail > 0) {
225 for (
int i = 1; i < e; i++) {
228 glTranslated(geom[i].x(), geom[i].y(), 0);
240 const std::vector<double>& rots,
241 const std::vector<double>& lengths,
243 int minS = (int)
MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size());
244 for (
int i = 0; i < minS; i++) {
252 int e = (int) geom.size() - 1;
253 for (
int i = 0; i < e; i++) {
267 glTranslated(beg.
x(), beg.
y(), 0);
268 glRotated(rot, 0, 0, 1);
271 glVertex2d(0, -visLength);
279 double rot,
double visLength) {
281 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
282 glRotated(rot, 0, 0, 1);
285 glVertex2d(0, -visLength);
295 int e = (int) v.size() - 1;
296 for (
int i = 0; i < e; ++i) {
297 glVertex2d(v[i].x(), v[i].y());
298 glVertex2d(v[i + 1].x(), v[i + 1].y());
307 int e = (int) v.size() - 1;
308 for (
int i = 0; i < e; ++i) {
310 glVertex2d(v[i].x(), v[i].y());
311 glVertex2d(v[i + 1].x(), v[i + 1].y());
321 glVertex2d(beg.
x(), beg.
y());
322 glVertex2d(end.
x(), end.
y());
354 const double inc = (end - beg) / (
double)steps;
355 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
358 for (
int i = 0; i <= steps; ++i) {
360 glBegin(GL_TRIANGLES);
361 glVertex2d(p1.first * width, p1.second * width);
362 glVertex2d(p2.first * width, p2.second * width);
378 double beg,
double end) {
380 for (
int i = 0; i < 360; i += 10) {
381 double x = (double) sin(
DEG2RAD(i));
382 double y = (double) cos(
DEG2RAD(i));
386 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
387 std::pair<double, double> p1 =
389 for (
int i = (
int)(beg / 10); i < steps && (36.0 / (double) steps * (
double) i) * 10 < end; i++) {
390 const std::pair<double, double>& p2 =
392 glBegin(GL_TRIANGLES);
393 glVertex2d(p1.first * width, p1.second * width);
394 glVertex2d(p2.first * width, p2.second * width);
395 glVertex2d(p2.first * iwidth, p2.second * iwidth);
397 glVertex2d(p2.first * iwidth, p2.second * iwidth);
398 glVertex2d(p1.first * iwidth, p1.second * iwidth);
399 glVertex2d(p1.first * width, p1.second * width);
403 const std::pair<double, double>& p2 =
405 glBegin(GL_TRIANGLES);
406 glVertex2d(p1.first * width, p1.second * width);
407 glVertex2d(p2.first * width, p2.second * width);
408 glVertex2d(p2.first * iwidth, p2.second * iwidth);
410 glVertex2d(p2.first * iwidth, p2.second * iwidth);
411 glVertex2d(p1.first * iwidth, p1.second * iwidth);
412 glVertex2d(p1.first * width, p1.second * width);
419 double tLength,
double tWidth) {
421 if (length < tLength) {
422 tWidth *= length / tLength;
427 glTranslated(rl.
x(), rl.
y(), 0);
429 glBegin(GL_TRIANGLES);
430 glVertex2d(0, tLength);
431 glVertex2d(-tWidth, 0);
432 glVertex2d(+tWidth, 0);
447 glGetDoublev(GL_CURRENT_COLOR, current);
448 return RGBColor(static_cast<unsigned char>(current[0] * 255. + 0.5),
449 static_cast<unsigned char>(current[1] * 255. + 0.5),
450 static_cast<unsigned char>(current[2] * 255. + 0.5),
451 static_cast<unsigned char>(current[3] * 255. + 0.5));
457 const double layer,
const double size,
458 const RGBColor& col,
const double angle) {
460 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
462 glTranslated(pos.
x(), pos.
y(), layer);
466 glRotated(180, 1, 0, 0);
467 glRotated(angle, 0, 0, 1);
468 glTranslated(-w / 2., size / 4, 0);
475 const double layer,
const double size,
477 const double angle) {
478 double boxAngle = angle + 90;
479 if (boxAngle > 360) {
484 const double borderWidth = size / 20;
485 const double boxHeight = size * 0.8;
486 const double boxWidth = stringWidth + size / 2;
488 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
489 glTranslated(0, 0, layer);
492 left.
sub(boxWidth / 2, -boxHeight / 2.7);
494 left.
add(borderWidth * 1.5, 0);
496 glTranslated(0, 0, 0.01);
497 drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth);
502 glTranslated(pos.
x(), pos.
y(), 0.01);
505 glRotated(180, 1, 0, 0);
506 glRotated(angle, 0, 0, 1);
507 glTranslated(-stringWidth / 2., 0, 0);
518 const double rot =
RAD2DEG(atan2((end.
x() - f.
x()), (f.
y() - end.
y())));
519 glTranslated(end.
x(), end.
y(), 0);
520 glRotated(rot, 0, 0, 1);
530 for (
int i = 0; i < (int)shape.size(); ++i) {
int pfDrawString(const char *c)
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
void add(const Position &pos)
Adds the given position to this one.
void pfSetScale(double s)
static void drawTextAtEnd(const std::string &text, const PositionVector &shape, double x, double size, RGBColor color)
draw text and the end of shape
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
unsigned char alpha() const
Returns the alpha-amount of the color.
T MIN4(T a, T b, T c, T d)
static void debugVertices(const PositionVector &shape, double size, double layer=256)
draw vertex numbers for the given shape (in a random color)
double y() const
Returns the y-position.
double x() const
Returns the x-position.
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position ...
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
unsigned char blue() const
Returns the blue-amount of the color.
void pfSetPosition(double x, double y)
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
#define UNUSED_PARAMETER(x)
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
static double naviDegree(const double angle)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
A point in 2D or 3D with translation and scaling methods.
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
static double rand()
Returns a random real number in [0, 1)
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
double pfdkGetStringWidth(const char *c)
static void drawTextBox(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &txtColor=RGBColor::BLACK, const RGBColor &bgColor=RGBColor::WHITE, const RGBColor &borderColor=RGBColor::BLACK, const double angle=0)
draw Text box with given parameters
void APIENTRY combCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut)
unsigned char green() const
Returns the green-amount of the color.
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
#define CIRCLE_RESOLUTION
unsigned char red() const
Returns the red-amount of the color.
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth)
Draws a triangle at the end of the given line.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0)
draw Text with given parameters
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static RGBColor getColor()
gets the gl-color
void sub(double dx, double dy)
Substracts the given position from this one.