Пример #1
0
void main(int argc,String *argv) {
  ArgParser a=ArgParser(argc,argv);
  String fname=a.argafter("-i","Font file (.jf)");
  float fw=a.floatafter("-fw","Font width",0.1);
  // We parse from
  List<String> lines=parsefileintolines(fname);
  // into
  List<FontChar> fcs=List<FontChar>();
  for(int i=1;i<=lines.len;i++) {
    String current=lines.num(i);
//    printf("Parsing line %s\n",current);
    StringParser s=StringParser(current);
    String character=s.getbefore(":");
//    printf("Reading character %s ...",character);
    FontChar fc=FontChar(character);
    while (s.someleft()) {
      char whatisit=s.getchar();
      printf("It is a %c\n",whatisit);
      switch (whatisit) {

        case 'L':
          printf("Found a line\n");
          float xa=tofloat(s.getbefore(","));
          float ya=tofloat(s.getbefore("_"));
          bool keepgoing=true;
          while (keepgoing) {
            float xb=tofloat(s.getbefore(","));
            float yb=s.getfloat();
            fc.bs.add(FLine(xa,ya,xb,yb,fw));
            char c=s.getchar();
            if (c==';')
              keepgoing=false;
            else
              if (c!='_')
                printf("Expected _");
          }
          break;

/*        case 'C':
          String type=s.getanyof("TBLRNESW");
          float x=tofloat(s.getbefore(","));
          float y=tofloat(s.getbefore(","));
          float r=tofloat(s.getbefore(";"));
          FArc fa=FArc(x,y,r);
          if (Seq(type,"T") {
            fa.aa=0;
            fa.ab=2*pi;
          }
          if (Seq(type,"T") {
           fa.aa=-pi/2.0;
           fa.ab=pi/2.0;
          }
          if (Seq(type,"B") {
            fa.aa=pi/2.0;
            fa.ab=2*pi-pi/2.0;
          }
          if (Seq(type,"L") {
            fa.aa=-pi;
            fa.ab=0;
          }
          if (Seq(type,"R") {
            fa.aa=0;
           fa.ab=pi;
          }
          if (Seq(type,"NW") {
            fa.aa=-pi/2.0;
            fa.ab=0;
          }
          if (Seq(type,"NE") {
            fa.aa=0;
            fa.ab=pi/2.0;
          }
          if (Seq(type,"SE") {
            fa.aa=pi/2.0;
            fa.ab=pi;
          }
          if (Seq(type,"SW") {
            fa.aa=-pi;
            fa.ab=-pi/2.0;
          }
          fc.bs.add(fa);
          break;

        case '+':
          String search=s.getbefore(";");
          int find=0;
          for (int j=1;j<i && find==0;j++) {
            if (Seq(search,fcs.p2num(j)->name))
              find=j;
          }
          if (find==0)
            printf("You haven't defined character %s before %s",find,character);
          fc.bs.add(fcs.p2num(j)->bs);
          break;

        default:
          printf("What kind of FontBit is a %s?",toString(whatisit));
          break;
*/
      }
    };
    fcs.add(fc);
    printf(" has %i bits\n",fc.bs.len);
  }
}
Пример #2
0
/**
 * Adds a triangle to be visualized.
 * @param P1	First vertex of the line
 * @param P2	Second vertex of the line
 * @param Color	Color of the line
 */
void F3DVisualizer::AddLine( const FVector4& P1, const FVector4& P2, FColor Color )
{
	Lines.Add( FLine(P1, P2, Color) );
}
Пример #3
0
Export int PathFind_Vector(FPoint *start, FPoint *end, FLine *obstructions, int obstructioncount, FPoint *pathbuffer, int pathbuffersize, Image* drawbuffer, drawcbk* drawcallback) {
  if (!start) return Failure;
  if (!end) return Failure;
  if (!obstructions) return Failure;
  //if (!pathbuffer) return Failure;
  //if (pathbuffersize < 2) return Failure;
  if (obstructioncount < 1) {
    pathbuffer[0] = *start;
    pathbuffer[1] = *end;
    return Trivial_Success;
  }
  treeNode *root = new treeNode(*start);
  treeNode *tail = new treeNode(*end);
  treeNode *current, *newnode;
  root->pushLeft(tail);
  FLine currentLine;
  FPoint where, newpoint;
  FPoint vector, newvector;
  float vector_length, vector_angle;
  int leaf = 0, closest_obstruction;
  float closest_obstruction_distance;
  stateStack stack;
  stack.push_front(buildState(root, Null));
  drawbuffer->clear();
  drawTree(drawbuffer, root);
  drawcallback();
  while (stack.size() > 0) {
    leaf = stack.front().leaf;
    switch (leaf) {
      case 0:
        current = stack.front().node->left;
        stack.front().leaf++;
        break;
      case 1:
        current = stack.front().node->right;
        stack.front().leaf++;
        break;
      case 2:
        stack.pop_front();
        continue;
        break;
    }
    if (current) {
      currentLine.Start = current->up->point;
      currentLine.End = current->point;
      closest_obstruction = -1;
      closest_obstruction_distance = 999999;
      for (int o = 0; o < obstructioncount; o++) {
        bool skip = false;
        if (currentLine.intersect(obstructions[o], where)) {
          for (stateStack::iterator iter = stack.begin(); iter != stack.end(); iter++) {
            if (iter->obstruction == &(obstructions[o])) {
              skip = true;
              break;
            }
          }
          if (!skip) {
            vector = FLine(current->up->point, where).vector();
            if (vector.length() < closest_obstruction_distance) {
              closest_obstruction = o;
              closest_obstruction_distance = vector.length();
            }
          }
        }
      }
      if (closest_obstruction > -1) {
        if (stack.front().node->depth < max_tree_depth) {
          vector = FLine(obstructions[closest_obstruction].Start, obstructions[closest_obstruction].End).vector();
          vector_length = vector.length();
          vector_angle = AngleBetween(obstructions[closest_obstruction].Start, obstructions[closest_obstruction].End);
          vector.X = sin(vector_angle * Radian);
          vector.Y = -cos(vector_angle * Radian);
          newvector = vector;
          newvector *= (-1);
          newpoint = obstructions[closest_obstruction].Start;
          newpoint += FPoint(newvector.X, newvector.Y);
          newnode = new treeNode(newpoint);
          newnode->pushLeft(new treeNode(*end));
          current->up->pushLeft(newnode);
          newvector = vector;
          newvector *= (vector_length + 1);
          newpoint = obstructions[closest_obstruction].Start;
          newpoint += FPoint(newvector.X, newvector.Y);
          newnode = new treeNode(newpoint);
          newnode->pushLeft(new treeNode(*end));
          current->up->pushRight(newnode);
          if (leaf == 0) {
            if (current->up->left)
              stack.push_front(buildState(current->up->left, &(obstructions[closest_obstruction])));
          } else {
            if (current->up->right)
              stack.push_front(buildState(current->up->right, &(obstructions[closest_obstruction])));
          }
        }
      }
    }
    drawbuffer->clear();
    drawTree(drawbuffer, root);
    if (current)
      drawbuffer->setPixelAA(current->point.X, current->point.Y, Pixel(0,0,255,255));
    drawcallback();
  }
  return Success;
}