Exemplo n.º 1
0
void hersheyPrintLetterInfo2(char ch) {
  float lm, rm, x, y, ox, oy;
  int draw, odraw;
  hersheyhandle hh;

  hersheyDrawInitLetter(&hh, ch, &lm, &rm);
  printf("pretranslate(%f, %f, %f)\n", -lm, 0.0, 0.0);
  ox=0;
  oy=0;
  odraw=0;
  while (!hersheyDrawNextLine(&hh, &draw, &x, &y)) {
    if (draw && odraw) {
      printf("line: %g %g -> %g %g\n", ox, oy, x, y);
    }

    ox=x;
    oy=y;
    odraw=draw;    
  }

  printf("\nposttranslate(%f, %f, %f)\n", rm, 0.0, 0.0);
}
Exemplo n.º 2
0
void TachyonDisplayDevice::text(float *pos, float size, float thickness, 
                                const char *str) {
  float textpos[3];
  float textsize, textthickness;
  hersheyhandle hh;

  // transform the world coordinates
  (transMat.top()).multpoint3d(pos, textpos);
  textsize = size * 1.5f;
  textthickness = thickness*DEFAULT_RADIUS;

  while (*str != '\0') {
    float lm, rm, x, y, ox, oy;
    int draw, odraw;
    ox=oy=x=y=0.0f;
    draw=odraw=0;

    hersheyDrawInitLetter(&hh, *str, &lm, &rm);
    textpos[0] -= lm * textsize;

    while (!hersheyDrawNextLine(&hh, &draw, &x, &y)) {
      float oldpt[3], newpt[3];
      if (draw) {
        newpt[0] = textpos[0] + textsize * x;
        newpt[1] = textpos[1] + textsize * y;
        newpt[2] = textpos[2];

        if (odraw) {
          // if we have both previous and next points, connect them...
          oldpt[0] = textpos[0] + textsize * ox;
          oldpt[1] = textpos[1] + textsize * oy;
          oldpt[2] = textpos[2];

          fprintf(outfile, "FCylinder\n"); // flat-ended cylinder
          fprintf(outfile, "  Base %g %g %g\n", oldpt[0], oldpt[1], -oldpt[2]); 
          fprintf(outfile, "  Apex %g %g %g\n", newpt[0], newpt[1], -newpt[2]);
          fprintf(outfile, "  Rad %g \n", textthickness);
          write_cindexmaterial(colorIndex, materialIndex);

          fprintf(outfile, "Sphere \n");  // sphere
          fprintf(outfile, "  Center %g %g %g \n", newpt[0], newpt[1], -newpt[2]);
          fprintf(outfile, "  Rad %g \n", textthickness); 
          write_cindexmaterial(colorIndex, materialIndex);
        } else {
          // ...otherwise, just draw the next point
          fprintf(outfile, "Sphere \n");  // sphere
          fprintf(outfile, "  Center %g %g %g \n", newpt[0], newpt[1], -newpt[2]);
          fprintf(outfile, "  Rad %g \n", textthickness); 
          write_cindexmaterial(colorIndex, materialIndex);
        }
      }

      ox=x;
      oy=y;
      odraw=draw;
    }
    textpos[0] += rm * textsize;

    str++;
  }
}
Exemplo n.º 3
0
void GelatoDisplayDevice::text(float *pos, float size, float thickness,
                               const char *str) {
  float textpos[3];
  float textsize, textthickness;
  hersheyhandle hh;

  // transform the world coordinates
  (transMat.top()).multpoint3d(pos, textpos);
  textsize = size * 1.5f;
  textthickness = thickness*DEFAULT_RADIUS;

  while (*str != '\0') {
    float lm, rm, x, y, ox, oy;
    int draw, odraw;
    ox=oy=x=y=0.0f;
    draw=odraw=0;

    hersheyDrawInitLetter(&hh, *str, &lm, &rm);
    textpos[0] -= lm * textsize;

    while (!hersheyDrawNextLine(&hh, &draw, &x, &y)) {
      float oldpt[3], newpt[3];
      if (draw) {
        newpt[0] = textpos[0] + textsize * x;
        newpt[1] = textpos[1] + textsize * y;
        newpt[2] = textpos[2];

        if (odraw) {
          // if we have both previous and next points, connect them...
          oldpt[0] = textpos[0] + textsize * ox;
          oldpt[1] = textpos[1] + textsize * oy;
          oldpt[2] = textpos[2];

          cylinder_nurb_noxfrm(oldpt, newpt, textthickness, 0); 

          fprintf(outfile, "PushTransform()\n");
          write_materials(1);
          fprintf(outfile, "Translate(%g, %g, %g)\n", 
                  newpt[0], newpt[1], newpt[2]);
          fprintf(outfile, "Sphere(%g, %g, %g, 360)\n", 
                  textthickness, -textthickness, textthickness);
          fprintf(outfile, "PopTransform()\n");
        } else {
          // ...otherwise, just draw the next point
          fprintf(outfile, "PushTransform()\n");
          write_materials(1);
          fprintf(outfile, "Translate(%g, %g, %g)\n", 
                  newpt[0], newpt[1], newpt[2]);
          fprintf(outfile, "Sphere(%g, %g, %g, 360)\n", 
                  textthickness, -textthickness, textthickness);
          fprintf(outfile, "PopTransform()\n");
        }
      }

      ox=x;
      oy=y;
      odraw=draw;
    }
    textpos[0] += rm * textsize;

    str++;
  }
}
Exemplo n.º 4
0
// To write an X3DOM-compatible scene file, we cannot include
// LineProperties nodes.
void X3DOMDisplayDevice::text(float *pos, float size, float thickness,
                               const char *str) {
  float textpos[3];
  float textsize;
  hersheyhandle hh;

  // transform the world coordinates
  (transMat.top()).multpoint3d(pos, textpos);
  textsize = size * 1.5f;

  ResizeArray<int>   idxs; 
  ResizeArray<float> pnts;
  idxs.clear();
  pnts.clear();

  int idx=0;
  while (*str != '\0') {
    float lm, rm, x, y;
    int draw;
    x=y=0.0f;
    draw=0;

    hersheyDrawInitLetter(&hh, *str, &lm, &rm);
    textpos[0] -= lm * textsize;

    while (!hersheyDrawNextLine(&hh, &draw, &x, &y)) {
      float pt[3];

      if (draw) {
        // add another connected point to the line strip
        idxs.append(idx);

        pt[0] = textpos[0] + textsize * x;
        pt[1] = textpos[1] + textsize * y;
        pt[2] = textpos[2];

        pnts.append(pt[0]);
        pnts.append(pt[1]);
        pnts.append(pt[2]);

        idx++;
      } else {
        idxs.append(-1); // pen-up, end of the line strip
      }
    }
    idxs.append(-1); // pen-up, end of the line strip
    textpos[0] += rm * textsize;
    str++;
  }

  fprintf(outfile, "<Shape>\n");
  fprintf(outfile, "  ");

  // 
  // Emit the line properties
  // 
  fprintf(outfile, "<Appearance><Material ");
  fprintf(outfile, "ambientIntensity='%g' ", mat_ambient);
  fprintf(outfile, "diffuseColor='0 0 0' "); 

  const float *rgb = matData[colorIndex];
  fprintf(outfile, "emissiveColor='%g %g %g' ",
          mat_diffuse * rgb[0], mat_diffuse * rgb[1], mat_diffuse * rgb[2]);
  fprintf(outfile, "/>");

#if 0
  // XXX X3DOM v1.1 doesn't handle LineProperties nodes
  // emit a line thickness directive, if needed
  if (thickness < 0.99f || thickness > 1.01f) {
    fprintf(outfile, "  <LineProperties linewidthScaleFactor=\"%g\" "
            "containerField=\"lineProperties\"/>\n",
            (double) thickness);
  }
#endif
  fprintf(outfile, "</Appearance>\n");

  //
  // Emit the line set
  // 
  fprintf(outfile, "  <IndexedLineSet coordIndex='");
  int i, cnt;
  cnt = idxs.num();
  for (i=0; i<cnt; i++) {
    fprintf(outfile, "%d ", idxs[i]);
  }
  fprintf(outfile, "'>\n");

  fprintf(outfile, "    <Coordinate point='");
  cnt = pnts.num();
  for (i=0; i<cnt; i+=3) {
    fprintf(outfile, "%c%g %g %g", 
            (i==0) ? ' ' : ',',
            pnts[i], pnts[i+1], pnts[i+2]);
  }
  fprintf(outfile, "'/>\n");
  fprintf(outfile, "  </IndexedLineSet>\n");
  fprintf(outfile, "</Shape>\n");
}
Exemplo n.º 5
0
void POV3DisplayDevice::text(float *pos, float size, float thickness,
                                   const char *str) {
  float textpos[3];
  float textsize, textthickness;
  hersheyhandle hh;

  // transform the world coordinates
  (transMat.top()).multpoint3d(pos, textpos);
  textsize = size * 1.5f;
  textthickness = thickness*DEFAULT_RADIUS;

  while (*str != '\0') {
    float lm, rm, x, y, ox, oy;
    int draw, odraw;
    ox=oy=x=y=0.0f;
    draw=odraw=0;

    hersheyDrawInitLetter(&hh, *str, &lm, &rm);
    textpos[0] -= lm * textsize;

    while (!hersheyDrawNextLine(&hh, &draw, &x, &y)) {
      float oldpt[3], newpt[3];
      if (draw) {
        newpt[0] = textpos[0] + textsize * x;
        newpt[1] = textpos[1] + textsize * y;
        newpt[2] = textpos[2];

        if (odraw) {
          // if we have both previous and next points, connect them...
          oldpt[0] = textpos[0] + textsize * ox;
          oldpt[1] = textpos[1] + textsize * oy;
          oldpt[2] = textpos[2];

          fprintf(outfile, "VMD_cylinder(<%.8f,%.8f,%.8f>,<%.8f,%.8f,%.8f>",
                  oldpt[0], oldpt[1], -oldpt[2], newpt[0], newpt[1], -newpt[2]);
          fprintf(outfile, "%.4f,rgbt<%.3f,%.3f,%.3f,%.3f>,%d)\n",
                  textthickness, matData[colorIndex][0], matData[colorIndex][1],
                  matData[colorIndex][2], 1 - mat_opacity, 1);

          fprintf(outfile, "VMD_sphere(<%.4f,%.4f,%.4f>,%.4f,",
                  newpt[0], newpt[1], -newpt[2], textthickness);
          fprintf(outfile, "rgbt<%.3f,%.3f,%.3f,%.3f>)\n",
                  matData[colorIndex][0], matData[colorIndex][1], 
                  matData[colorIndex][2], 1 - mat_opacity);
        } else {
          // ...otherwise, just draw the next point
          fprintf(outfile, "VMD_sphere(<%.4f,%.4f,%.4f>,%.4f,",
                  newpt[0], newpt[1], -newpt[2], textthickness);
          fprintf(outfile, "rgbt<%.3f,%.3f,%.3f,%.3f>)\n",
                  matData[colorIndex][0], matData[colorIndex][1], 
                  matData[colorIndex][2], 1 - mat_opacity);
        }
      }

      ox=x;
      oy=y;
      odraw=draw;
    }
    textpos[0] += rm * textsize;

    str++;
  }
}