⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 movieoutput.c

📁 source code to compute the visibility polygon of a point in a polygon.
💻 C
📖 第 1 页 / 共 2 页
字号:
void PursuerMovie::AddRobot(WorldInfo *wInfo, PInfo *pInfo){  /* todo: create a small ball that will be the pursuer robot. */  List<MC_MovieObject> movingList;  MC_MovieObject mOb;  MC_Ball *ob;  ob = new MC_Ball;  if( wInfo->robot != NULL ) {    //ob->setCenter(wInfo->robot->pts[0].x, wInfo->robot->pts[0].y);    ob->setCenter(pInfo->sln[0]->NodeCell()->pt->x,		  pInfo->sln[0]->NodeCell()->pt->y);    ob->setRadius(CalculateWidth(wInfo->border) * ROBOT_WIDTH);  } else {    //ob->setCenter(0, 0);    ob->setCenter(pInfo->sln[0]->NodeCell()->pt->x,		  pInfo->sln[0]->NodeCell()->pt->y);    ob->setRadius(CalculateWidth(wInfo->border) * ROBOT_WIDTH);  }      movingList = movingObjects(); // so we don't lose others  mOb.setObject(ob);  mOb.nature() = MC_Robot;  movingList.add2Top(mOb);  movingObjects() = movingList;}double PursuerMovie::CalculateWidth(Obstacle *border){  float minX, maxX, minY, maxY, widY, widX;  int i;  minX = minY = INFINITY;  maxX = maxY = -INFINITY;  for( i = 0; i < border->nPts; i++ ) {    if( border->pts[i].x < minX ) minX = border->pts[i].x;    if( border->pts[i].x > maxX ) maxX = border->pts[i].x;    if( border->pts[i].y < minY ) minY = border->pts[i].y;    if( border->pts[i].y > maxY ) maxY = border->pts[i].y;  }    widY = maxY - minY;  widX = maxX - minX;  if( widY > widX ) return(widY);  return(widX);}void PursuerMovie::DumpVisPoly(List<MC_MovieObject> *addList,	MC_ObjectNature nat, VPoly *vpoly){  int i;  MC_Polygon *ob;  MC_MovieObject mOb;  MC_Coord x[MOVIE_MAXPTS], y[MOVIE_MAXPTS];  /*  printf("Poly edges: %d\n\n", vpoly->nEdges);*/  for( i = 0; i < vpoly->nEdges; i++ ) {    x[i] = vpoly->edges[i]->A->x;    y[i] = vpoly->edges[i]->A->y;  }  ob = new MC_Polygon;  ob->setXY(i, x, y);  mOb.setObject(ob);  mOb.nature() = nat;  addList->add2Bottom(mOb);}/* draw the edges of the current visibility polygon. */void PursuerMovie::DumpGaps(List<MC_MovieObject> *addList, double width,        MC_ObjectNature dirty, MC_ObjectNature clean, PGNode *node,			    VPoly *vpoly){  int i, nGaps, tag;  double x1, x2, y1, y2;      //VPoly *vpoly;  MC_ObjectNature use;  Bitmap state;  nGaps = 0;  state = node->NodeState();  //vpoly = node->NodeCell()->vPoly;  for( i = 0; i < vpoly->nEdges; i++ ) {    if( vpoly->edges[i]->bGap ) {      if( state & ( 1 << nGaps )) {	use = dirty;	tag = 0;      } else {	use = clean;	tag = TAG2;      }      x1 = vpoly->edges[i]->A->x;      x2 = vpoly->edges[i]->B->x;      y1 = vpoly->edges[i]->A->y;      y2 = vpoly->edges[i]->B->y;      DumpLine(addList, width, use, tag, x1, y1, x2, y2);      nGaps++;    }  }}void PursuerMovie::DumpLine(List<MC_MovieObject> *addList, double width,			    MC_ObjectNature nat, int tag,			    double x1, double y1, double x2, double y2){  MC_Polygon *ob;  MC_MovieObject mOb;  MC_Coord x[5], y[5];  int i;  x[0] = x1 - width;  y[0] = y1 - width;  x[1] = x2 - width;  y[1] = y2 - width;  x[2] = x2 + width;  y[2] = y2 + width;  x[3] = x1 + width;  y[3] = y1 + width;    ob = new MC_Polygon;  ob->setXY(4, x, y);  mOb.setObject(ob);  if( tag != 0 ) {    mOb.tagNumber() = tag;  }  mOb.nature() = nat;  addList->add2Bottom(mOb);}/* add the frames illustrating a solution that involved 2 robots */void MultiMovie::AddFrames(PInfo *pinfo1, PInfo *pinfo2){  MC_Frame *frame; // make array to pass in multiple frames to movie  List<MC_MovieObject> *animated;  List<MC_MovieObject> *stationary;  List<MC_MovieObject> *gList;  int i, frameCount;  double width, currdist, dist;  double r1x, r1y, r2x, r2y;  Point newP;  VPoly newVPoly, r1poly;  MC_Transform *transform1, *transform2;  List <MC_Transform> *transformList;  frame = new MC_Frame[pinfo1->nSteps * 20 + pinfo2->nSteps * 20];  animated = &movingObjects();  stationary = &staticObjects();  r1x = pinfo1->sln[0]->NodeCell()->pt->x;  r1y = pinfo1->sln[0]->NodeCell()->pt->y;  r2x = pinfo2->sln[0]->NodeCell()->pt->x;  r2y = pinfo2->sln[0]->NodeCell()->pt->y;  frameCount = 0;  for( i = 0; i < pinfo1->nSteps; i++ ) {    // new: interpolate between cell points in steps of size resolution.    if( i < pinfo1->nSteps - 1 && !bFast && !bDrawGaps) {      dist = LineDistance(pinfo1->sln[i]->NodeCell()->pt,			  pinfo1->sln[i + 1]->NodeCell()->pt);    } else {      dist = 0.1; // force one step only    }    for( currdist = 0; currdist < dist; currdist += resolution ) {      if( i < pinfo1->nSteps - 1 && !bFast && !bDrawGaps ) {	newP.x = pinfo1->sln[i]->NodeCell()->pt->x + currdist/dist *	  ( pinfo1->sln[i + 1]->NodeCell()->pt->x - 	    pinfo1->sln[i]->NodeCell()->pt->x );	newP.y = pinfo1->sln[i]->NodeCell()->pt->y + currdist/dist *	  ( pinfo1->sln[i + 1]->NodeCell()->pt->y -	    pinfo1->sln[i]->NodeCell()->pt->y );	newP.w = 1;	assert(MakeVisPoly(pinfo1->edgeInfo, &newP, &newVPoly) );      } else {	newP.x = pinfo1->sln[i]->NodeCell()->pt->x;	newP.y = pinfo1->sln[i]->NodeCell()->pt->y;	newVPoly = *pinfo1->sln[i]->NodeCell()->vPoly;      }      gList = new List<MC_MovieObject>;      if( bDrawGaps ) {	width = CalculateWidth(pinfo1->wInfo->border) * BORDER_WIDTH;	DumpGaps(gList, width, MC_Goal, MC_Landmark, pinfo1->sln[i], 		 &newVPoly);      } else {	DumpVisPoly(gList, MC_Goal, &newVPoly);      }      /* now mark the cell center so we can see where we start from */            // use robot moving object      transformList = new List<MC_Transform>;      transform1 = new MC_Transform;      transform1->shift() = MC_Point(newP.x - r1x, newP.y - r1y, 1);      transformList->add2Top(*transform1);      transform2 = new MC_Transform;      transformList->add2Top(*transform2);            frame[frameCount++].setFrame(stationary,				   animated, *transformList, *gList);    }  }  r1poly = newVPoly;  /* now do the same thing for the second robot with the first stationary */  for( i = 0; i < pinfo2->nSteps; i++ ) {    // new: interpolate between cell points in steps of size resolution.    if( i < pinfo2->nSteps - 1 && !bFast && !bDrawGaps) {      dist = LineDistance(pinfo2->sln[i]->NodeCell()->pt,			  pinfo2->sln[i + 1]->NodeCell()->pt);    } else {      dist = 0.1; // force one step only    }    for( currdist = 0; currdist < dist; currdist += resolution ) {      if( i < pinfo2->nSteps - 1 && !bFast && !bDrawGaps ) {	newP.x = pinfo2->sln[i]->NodeCell()->pt->x + currdist/dist *	  ( pinfo2->sln[i + 1]->NodeCell()->pt->x - 	    pinfo2->sln[i]->NodeCell()->pt->x );	newP.y = pinfo2->sln[i]->NodeCell()->pt->y + currdist/dist *	  ( pinfo2->sln[i + 1]->NodeCell()->pt->y -	    pinfo2->sln[i]->NodeCell()->pt->y );	newP.w = 1;	assert(MakeVisPoly(pinfo2->edgeInfo, &newP, &newVPoly) );      } else {	newP.x = pinfo2->sln[i]->NodeCell()->pt->x;	newP.y = pinfo2->sln[i]->NodeCell()->pt->y;	newVPoly = *pinfo2->sln[i]->NodeCell()->vPoly;      }      gList = new List<MC_MovieObject>;      if( bDrawGaps ) {	width = CalculateWidth(pinfo2->wInfo->border) * BORDER_WIDTH;	DumpGaps(gList, width, MC_Goal, MC_Landmark, pinfo2->sln[i], 		 &newVPoly);      } else {	DumpVisPoly(gList, MC_Goal, &newVPoly);	DumpVisPoly(gList, MC_Goal, &r1poly);      }      /* now mark the cell center so we can see where we start from */            // use robot moving object      transformList = new List<MC_Transform>;      transform1 = new MC_Transform;      transformList->add2Top(*transform1);      transform2 = new MC_Transform;      transform2->shift() = MC_Point(newP.x - r2x, newP.y - r2y, 1);      transformList->add2Top(*transform2);            frame[frameCount++].setFrame(stationary,				   animated, *transformList, *gList);    }  }  setFrames(frameCount, frame);  assert(checkIntegrity(1));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -