17 const std::string &font_name,
int font_enum,
18 int font_size,
int align,
int line_num)
23 if(
s.size() > 8 &&
s.substr(0, 7) ==
"file://") {
28 glRasterPos3d(x, y,
z);
30 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
31 if(valid == GL_FALSE)
return;
33 if(align > 0 || line_num) {
35 glGetDoublev(GL_CURRENT_RASTER_POSITION, pos);
36 double x[3], w[3] = {pos[0], pos[1], pos[2]};
80 if(line_num) w[1] -= line_num * (1.1 * height);
82 glRasterPos3d(x[0], x[1], x[2]);
123 gl2psTextOpt(tmp.c_str(), font_name.c_str(), font_size, opt, 0.);
131 gl2psText(
s.c_str(), font_name.c_str(), font_size);
148 double z,
int line_num)
155 double z,
int line_num)
162 double style,
int line_num)
164 unsigned int bits = (
unsigned int)style;
170 int size = (bits & 0xff);
171 int font = (bits >> 8 & 0xff);
172 int align = (bits >> 16 & 0xff);
176 drawString(
s, x, y,
z, font_name, font_enum, size, align, line_num);
187 size_t p = name.find_last_of(
'@');
188 std::string file = name, format;
189 if(p != std::string::npos) {
190 format = name.substr(p + 1);
191 file = name.substr(0, p);
193 double w = 0., h = 0., wx = 1., wy = 0., wz = 0., hx = 0., hy = 1., hz = 0.;
194 bool billboard =
false;
197 if(format.find(
',') != std::string::npos)
198 ok = (sscanf(format.c_str(),
"%lfx%lf,%lf,%lf,%lf,%lf,%lf,%lf", &w, &h,
199 &wx, &wy, &wz, &hx, &hy, &hz) == 8);
201 ok = (sscanf(format.c_str(),
"%lfx%lf", &w, &h) == 2);
203 Msg::Warning(
"Bad image format: use `@wxh' or `@wxh,wx,wy,wz,hx,hy,hz'");
204 if(format.find(
'#') != std::string::npos)
220 Msg::Debug(
"No texture for image - skipping image draw");
224 if(w == 0 && h == 0) {
229 h = w * img->
h / img->
w;
232 w = h * img->
w / img->
h;
235 GLboolean valid = GL_TRUE;
236 GLint matrixMode = 0;
238 glRasterPos3d(x, y,
z);
240 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
241 glGetIntegerv(GL_MATRIX_MODE, &matrixMode);
242 glMatrixMode(GL_PROJECTION);
245 glMatrixMode(GL_MODELVIEW);
256 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
258 if(valid == GL_TRUE) {
291 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
292 glEnable(GL_TEXTURE_2D);
293 glBindTexture(GL_TEXTURE_2D, img->
tex);
294 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
296 glTexCoord2f(1.0
f, 1.0
f);
297 glVertex3d(x + wx * w, y + wy * w,
z + wz * w);
298 glTexCoord2f(1.0
f, 0.0
f);
299 glVertex3d(x + wx * w + hx * h, y + wy * w + hy * h,
z + wz * w + hz * h);
300 glTexCoord2f(0.0
f, 0.0
f);
301 glVertex3d(x + hx * h, y + hy * h,
z + hz * h);
302 glTexCoord2f(0.0
f, 1.0
f);
305 glDisable(GL_TEXTURE_2D);
310 glMatrixMode(GL_PROJECTION);
312 glMatrixMode(matrixMode);
319 double d0[3] = {val[0], val[1], val[2]};
320 double d1[3] = {val[3], val[4], val[5]};
321 double d2[3] = {val[6], val[7], val[8]};
323 double x0[3] = {x + d1[0] + d1[0] + d2[0], x + d0[1] + d1[1] + d2[1],
324 z + d0[2] + d1[2] + d2[2]};
325 double x1[3] = {x - d1[0] + d1[0] + d2[0], x - d0[1] + d1[1] + d2[1],
326 z - d0[2] + d1[2] + d2[2]};
327 double x2[3] = {x - d1[0] - d1[0] + d2[0], x - d0[1] - d1[1] + d2[1],
328 z - d0[2] - d1[2] + d2[2]};
329 double x3[3] = {x + d1[0] - d1[0] + d2[0], x + d0[1] - d1[1] + d2[1],
330 z + d0[2] - d1[2] + d2[2]};
332 double x4[3] = {x + d1[0] + d1[0] - d2[0], x + d0[1] + d1[1] - d2[1],
333 z + d0[2] + d1[2] - d2[2]};
334 double x5[3] = {x - d1[0] + d1[0] - d2[0], x - d0[1] + d1[1] - d2[1],
335 z - d0[2] + d1[2] - d2[2]};
336 double x6[3] = {x - d1[0] - d1[0] - d2[0], x - d0[1] - d1[1] - d2[1],
337 z - d0[2] - d1[2] - d2[2]};
338 double x7[3] = {x + d1[0] - d1[0] - d2[0], x + d0[1] - d1[1] - d2[1],
339 z + d0[2] - d1[2] - d2[2]};
341 if(light) glEnable(GL_LIGHTING);
345 glColor3f(x0[0], x0[1], x0[2]);
346 glColor3f(x1[0], x1[1], x1[2]);
347 glColor3f(x2[0], x2[1], x2[2]);
348 glColor3f(x3[0], x3[1], x3[2]);
352 glColor3f(x4[0], x4[1], x4[2]);
353 glColor3f(x7[0], x7[1], x7[2]);
354 glColor3f(x6[0], x6[1], x6[2]);
355 glColor3f(x5[0], x5[1], x5[2]);
359 glColor3f(x0[0], x0[1], x0[2]);
360 glColor3f(x3[0], x3[1], x3[2]);
361 glColor3f(x7[0], x7[1], x7[2]);
362 glColor3f(x4[0], x4[1], x4[2]);
366 glColor3f(x1[0], x1[1], x1[2]);
367 glColor3f(x5[0], x5[1], x5[2]);
368 glColor3f(x6[0], x6[1], x6[2]);
369 glColor3f(x2[0], x2[1], x2[2]);
373 glColor3f(x0[0], x0[1], x0[2]);
374 glColor3f(x4[0], x4[1], x4[2]);
375 glColor3f(x5[0], x5[1], x5[2]);
376 glColor3f(x1[0], x1[1], x1[2]);
380 glColor3f(x3[0], x3[1], x3[2]);
381 glColor3f(x2[0], x2[1], x2[2]);
382 glColor3f(x6[0], x6[1], x6[2]);
383 glColor3f(x7[0], x7[1], x7[2]);
387 glDisable(GL_LIGHTING);
393 if(light) glEnable(GL_LIGHTING);
395 glTranslated(x, y,
z);
398 glDisable(GL_LIGHTING);
402 float v1[3],
int light)
404 if(light) glEnable(GL_LIGHTING);
406 GLfloat m[16] = {v0[0],
414 v0[1] * v1[2] - v0[2] * v1[1],
415 v0[2] * v1[0] - v0[0] * v1[2],
416 v0[0] * v1[1] - v0[1] * v1[0],
425 glDisable(GL_LIGHTING);
429 float v1[3],
float v2[3],
int light)
431 if(light) glEnable(GL_LIGHTING);
433 GLfloat m[16] = {v0[0], v0[1], v0[2], .0f, v1[0], v1[1],
434 v1[2], .0f, v2[0], v2[1], v2[2], .0f,
435 (GLfloat)x, (GLfloat)y, (GLfloat)
z, 1.
f};
439 glDisable(GL_LIGHTING);
446 if(light) glEnable(GL_LIGHTING);
448 glTranslated(x, y,
z);
449 glScaled(ss, ss, ss);
452 glDisable(GL_LIGHTING);
456 double ValMin,
double ValMax,
double *x,
457 double *y,
double *
z,
int light)
459 if(light) glEnable(GL_LIGHTING);
461 double dx = x[1] - x[0];
462 double dy = y[1] - y[0];
463 double dz =
z[1] -
z[0];
464 double const length = std::sqrt(dx * dx + dy * dy + dz * dz);
466 double radius1 = (val1 - ValMin) * fact;
467 double radius2 = (val2 - ValMin) * fact;
468 double zdir[3] = {0., 0., 1.};
472 double const cosphi =
prosca(zdir, vdir);
478 phi = 180. *
myacos(cosphi) / M_PI;
481 glTranslated(x[0], y[0],
z[0]);
482 glRotated(phi, axis[0], axis[1], axis[2]);
487 glDisable(GL_LIGHTING);
493 if(light) glEnable(GL_LIGHTING);
495 double dx = x[1] - x[0];
496 double dy = y[1] - y[0];
497 double dz =
z[1] -
z[0];
498 double const length = std::sqrt(dx * dx + dy * dy + dz * dz);
500 double zdir[3] = {0., 0., 1.};
504 double const cosphi =
prosca(zdir, vdir);
510 phi = 180. *
myacos(cosphi) / M_PI;
513 glTranslated(x[0], y[0],
z[0]);
514 glRotated(phi, axis[0], axis[1], axis[2]);
519 glDisable(GL_LIGHTING);
523 double dx,
double dy,
double dz,
double d,
526 double n[3], t[3], u[3];
532 if((fabs(n[0]) >= fabs(n[1]) && fabs(n[0]) >= fabs(n[2])) ||
533 (fabs(n[1]) >= fabs(n[0]) && fabs(n[1]) >= fabs(n[2]))) {
544 double l = sqrt(t[0] * t[0] + t[1] * t[1] + t[2] * t[2]);
549 u[0] = n[1] * t[2] - n[2] * t[1];
550 u[1] = n[2] * t[0] - n[0] * t[2];
551 u[2] = n[0] * t[1] - n[1] * t[0];
553 l = sqrt(u[0] * u[0] + u[1] * u[1] + u[2] * u[2]);
567 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
570 if(light && fill) glEnable(GL_LIGHTING);
571 glBegin(GL_TRIANGLES);
572 if(light) glNormal3dv(u);
573 glVertex3d(x + dx, y + dy,
z + dz);
574 glVertex3d(x + f2 * dx + b * (t[0]), y + f2 * dy + b * (t[1]),
575 z + f2 * dz + b * (t[2]));
576 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
578 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
579 glVertex3d(x + f2 * dx + b * (-t[0]), y + f2 * dy + b * (-t[1]),
580 z + f2 * dz + b * (-t[2]));
581 glVertex3d(x + dx, y + dy,
z + dz);
583 if(light) glNormal3dv(t);
584 glVertex3d(x + dx, y + dy,
z + dz);
585 glVertex3d(x + f2 * dx + b * (-u[0]), y + f2 * dy + b * (-u[1]),
586 z + f2 * dz + b * (-u[2]));
587 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
589 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
590 glVertex3d(x + f2 * dx + b * (u[0]), y + f2 * dy + b * (u[1]),
591 z + f2 * dz + b * (u[2]));
592 glVertex3d(x + dx, y + dy,
z + dz);
594 glDisable(GL_LIGHTING);
597 glBegin(GL_LINE_STRIP);
599 glVertex3d(x + dx, y + dy,
z + dz);
600 glVertex3d(x + f2 * dx + b * (t[0]), y + f2 * dy + b * (t[1]),
601 z + f2 * dz + b * (t[2]));
602 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
603 glVertex3d(x + f2 * dx + b * (-t[0]), y + f2 * dy + b * (-t[1]),
604 z + f2 * dz + b * (-t[2]));
605 glVertex3d(x + dx, y + dy,
z + dz);
606 glVertex3d(x + f2 * dx + b * (-u[0]), y + f2 * dy + b * (-u[1]),
607 z + f2 * dz + b * (-u[2]));
608 glVertex3d(x + f1 * dx, y + f1 * dy,
z + f1 * dz);
609 glVertex3d(x + f2 * dx + b * (u[0]), y + f2 * dy + b * (u[1]),
610 z + f2 * dz + b * (u[2]));
611 glVertex3d(x + dx, y + dy,
z + dz);
617 double top[3] = {x + dx, y + dy,
z + dz};
618 double tp[3] = {x + b * t[0], y + b * t[1],
z + b * t[2]};
619 double tm[3] = {x - b * t[0], y - b * t[1],
z - b * t[2]};
620 double up[3] = {x + b * u[0], y + b * u[1],
z + b * u[2]};
621 double um[3] = {x - b * u[0], y - b * u[1],
z - b * u[2]};
624 if(light && fill) glEnable(GL_LIGHTING);
625 glBegin(GL_TRIANGLES);
627 normal3points(tm[0], tm[1], tm[2], um[0], um[1], um[2], top[0], top[1],
631 glVertex3d(tm[0], tm[1], tm[2]);
632 glVertex3d(um[0], um[1], um[2]);
633 glVertex3d(top[0], top[1], top[2]);
636 normal3points(um[0], um[1], um[2], tp[0], tp[1], tp[2], top[0], top[1],
640 glVertex3d(um[0], um[1], um[2]);
641 glVertex3d(tp[0], tp[1], tp[2]);
642 glVertex3d(top[0], top[1], top[2]);
645 normal3points(tp[0], tp[1], tp[2], up[0], up[1], up[2], top[0], top[1],
649 glVertex3d(tp[0], tp[1], tp[2]);
650 glVertex3d(up[0], up[1], up[2]);
651 glVertex3d(top[0], top[1], top[2]);
654 normal3points(up[0], up[1], up[2], tm[0], tm[1], tm[2], top[0], top[1],
658 glVertex3d(up[0], up[1], up[2]);
659 glVertex3d(tm[0], tm[1], tm[2]);
660 glVertex3d(top[0], top[1], top[2]);
662 glDisable(GL_LIGHTING);
665 glBegin(GL_LINE_LOOP);
666 glVertex3d(x + b * (t[0]), y + b * (t[1]),
z + b * (t[2]));
667 glVertex3d(x + b * (-u[0]), y + b * (-u[1]),
z + b * (-u[2]));
668 glVertex3d(x + b * (-t[0]), y + b * (-t[1]),
z + b * (-t[2]));
669 glVertex3d(x + b * (u[0]), y + b * (u[1]),
z + b * (u[2]));
673 glVertex3d(x + b * (t[0]), y + b * (t[1]),
z + b * (t[2]));
674 glVertex3d(x + dx, y + dy,
z + dz);
676 glVertex3d(x + b * (-u[0]), y + b * (-u[1]),
z + b * (-u[2]));
677 glVertex3d(x + dx, y + dy,
z + dz);
679 glVertex3d(x + b * (-t[0]), y + b * (-t[1]),
z + b * (-t[2]));
680 glVertex3d(x + dx, y + dy,
z + dz);
682 glVertex3d(x + b * (u[0]), y + b * (u[1]),
z + b * (u[2]));
683 glVertex3d(x + dx, y + dy,
z + dz);
690 double dy,
double dz,
double length,
int light)
692 double zdir[3] = {0., 0., 1.};
696 double const cosphi =
prosca(zdir, vdir);
702 double phi = 180. *
myacos(cosphi) / M_PI;
704 if(light) glEnable(GL_LIGHTING);
706 glTranslated(x, y,
z);
708 glRotated(phi, axis[0], axis[1], axis[2]);
711 glDisable(GL_LIGHTING);
715 double dx,
double dy,
double dz,
int light)
717 double length = sqrt(dx * dx + dy * dy + dz * dz);
725 glVertex3d(x + dx, y + dy,
z + dz);
731 glVertex3d(x + dx, y + dy,
z + dz);
735 glVertex3d(x + dx, y + dy,
z + dz);
753 point() : x(0.), y(0.),
z(0.), valid(false) {}
754 point(
double xi,
double yi,
double zi) : x(xi), y(yi),
z(zi), valid(true) {}
759 double _a, _b, _c, _d;
762 plane(
double a,
double b,
double c,
double d) : _a(a), _b(b), _c(
c), _d(d) {}
763 double val(point &p) {
return _a * p.x + _b * p.y + _c * p.z + _d; };
766 double v1 = val(p1), v2 = val(p2);
767 if(fabs(v1) < 1.e-12) {
768 if(fabs(v2) < 1.e-12)
771 return point(p1.x, p1.y, p1.z);
773 else if(fabs(v2) < 1.e-12) {
774 return point(p2.x, p2.y, p2.z);
776 else if(v1 * v2 < 0.) {
777 double coef = -v1 / (v2 - v1);
778 return point(coef * (p2.x - p1.x) + p1.x, coef * (p2.y - p1.y) + p1.y,
779 coef * (p2.z - p1.z) + p1.z);
788 double ymax,
double zmax,
bool labels)
790 glBegin(GL_LINE_LOOP);
791 glVertex3d(xmin, ymin, zmin);
792 glVertex3d(xmax, ymin, zmin);
793 glVertex3d(xmax, ymax, zmin);
794 glVertex3d(xmin, ymax, zmin);
796 glBegin(GL_LINE_LOOP);
797 glVertex3d(xmin, ymin, zmax);
798 glVertex3d(xmax, ymin, zmax);
799 glVertex3d(xmax, ymax, zmax);
800 glVertex3d(xmin, ymax, zmax);
803 glVertex3d(xmin, ymin, zmin);
804 glVertex3d(xmin, ymin, zmax);
805 glVertex3d(xmax, ymin, zmin);
806 glVertex3d(xmax, ymin, zmax);
807 glVertex3d(xmax, ymax, zmin);
808 glVertex3d(xmax, ymax, zmax);
809 glVertex3d(xmin, ymax, zmin);
810 glVertex3d(xmin, ymax, zmax);
815 sprintf(label,
"(%g,%g,%g)", xmin, ymin, zmin);
816 drawString(label, xmin + offset /
s[0], ymin + offset /
s[1],
817 zmin + offset /
s[2]);
818 sprintf(label,
"(%g,%g,%g)", xmax, ymax, zmax);
819 drawString(label, xmax + offset /
s[0], ymax + offset /
s[1],
820 zmax + offset /
s[2]);
825 double xmax,
double ymax,
double zmax,
826 double a,
double b,
double c,
double d,
829 plane pl(a, b,
c, d);
830 point p1(xmin, ymin, zmin), p2(xmax, ymin, zmin);
831 point p3(xmax, ymax, zmin), p4(xmin, ymax, zmin);
832 point p5(xmin, ymin, zmax), p6(xmax, ymin, zmax);
833 point p7(xmax, ymax, zmax), p8(xmin, ymax, zmax);
836 edge[0] = pl.intersect(p1, p2);
837 edge[1] = pl.intersect(p1, p4);
838 edge[2] = pl.intersect(p1, p5);
839 edge[3] = pl.intersect(p2, p3);
840 edge[4] = pl.intersect(p2, p6);
841 edge[5] = pl.intersect(p3, p4);
842 edge[6] = pl.intersect(p3, p7);
843 edge[7] = pl.intersect(p4, p8);
844 edge[8] = pl.intersect(p5, p6);
845 edge[9] = pl.intersect(p5, p8);
846 edge[10] = pl.intersect(p6, p7);
847 edge[11] = pl.intersect(p7, p8);
849 int face[6][4] = {{0, 2, 4, 8}, {0, 1, 3, 5}, {1, 2, 7, 9},
850 {3, 4, 6, 10}, {5, 6, 7, 11}, {8, 9, 10, 11}};
852 double n[3] = {a, b,
c}, ll = 50;
859 double length = sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]);
864 for(
int i = 0; i < 6; i++) {
867 for(
int j = 0; j < 4; j++) {
868 if(edge[face[i][j]].valid ==
true) p[nb++] = edge[face[i][j]];
871 for(
int j = 1; j < nb; j++) {
872 double xx[2] = {p[j].x, p[j - 1].x};
873 double yy[2] = {p[j].y, p[j - 1].y};
874 double zz[2] = {p[j].z, p[j - 1].z};
877 for(
int j = 0; j < nb; j++) {
880 p_shade[n_shade].x = p[j].x;
881 p_shade[n_shade].y = p[j].y;
882 p_shade[n_shade].z = p[j].z;
892 glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &twoside);
893 glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
894 glEnable(GL_LIGHTING);
896 glNormal3d(n[0], n[1], n[2]);
897 for(
int j = 0; j < n_shade; j++) {
898 glVertex3d(p_shade[j].x, p_shade[j].y, p_shade[j].
z);
901 glDisable(GL_LIGHTING);
902 glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, twoside);