📄 movieoutput.c
字号:
#include "Movie.h"#include "MovieObject.h"#include "List.h"#include <iostream.h>#include "movieoutput.h"#include "cell.h"#include "line.h"#include "assert.h"#include "pursuer.h"#include "vispoly.h"#include "pgraph.h"void MV_movietest(void);void MakeMovie(char **argv, int argc, PInfo *pInfo){ // potential problem: is cout going to the right place? PursuerMovie M; M.movieDimension() = MD_2D; M.infoBit() = 1; M.SetOutput(argv, argc); M.resolution = M.CalculateWidth(pInfo->wInfo->border) * RESOLUTION; if( M.resolution < 1 ) M.resolution = 1; M.AddObstacles(pInfo->wInfo); if( M.bDrawCells ) M.AddCells(pInfo); M.AddRobot(pInfo->wInfo, pInfo); if( M.bDrawPolys ) M.AddVPolys(pInfo->cellInfo); else M.AddFrames(pInfo); cout << M;}void MakeMultiMovie(char **argv, int argc, PInfo *pInfo1, PInfo *pInfo2){ MultiMovie M; M.movieDimension() = MD_2D; M.infoBit() = 1; M.SetOutput(argv, argc); M.resolution = M.CalculateWidth(pInfo1->wInfo->border) * RESOLUTION; if( M.resolution < 1 ) M.resolution = 1; M.AddObstacles(pInfo1->wInfo); // pInfo2 has same obstacles if( M.bDrawCells ) M.AddCells(pInfo2); M.AddRobot(pInfo1->wInfo, pInfo1); M.AddRobot(pInfo2->wInfo, pInfo2); M.AddFrames(pInfo1, pInfo2); cout << M;}void PursuerMovie::SetOutput(char **argv, int argc){ int i; bDrawCells = FALSE; bDrawPolys = FALSE; bDrawGaps = FALSE; bFast = FALSE; for( i = 2; i < argc; i++ ) { if( argv[i][0] == 'c' ) bDrawCells = TRUE; if( argv[i][0] == 'p' ) bDrawPolys = TRUE; if( argv[i][0] == 'v' ) bDrawPolys = TRUE; if( argv[i][0] == 'e') bDrawGaps = TRUE; if( argv[i][0] == 'f') bFast = TRUE; } if( bDrawCells ) printf("Drawing cell borders\n"); if( bDrawPolys ) printf("Drawing vispolys\n"); if( bDrawGaps ) printf("Drawing gap edges\n");}/* add border & obstacles to the movie as static components */void PursuerMovie::AddObstacles(WorldInfo *wInfo){ List<MC_MovieObject> staticList; MC_Polygon *ob; MC_MovieObject mOb; MC_Coord x[MOVIE_MAXPTS], y[MOVIE_MAXPTS]; int i,j; double width; width = CalculateWidth(wInfo->border) * BORDER_WIDTH; /* draw border as a bunch of lines */ for( i = 0; i < wInfo->border->nPts; i++ ) { DumpLine(&staticList, width, MC_Obstacle, 0, wInfo->border->pts[i].x, wInfo->border->pts[i].y, wInfo->border->pts[(i + 1)%wInfo->border->nPts].x, wInfo->border->pts[(i + 1)%wInfo->border->nPts].y); } /* create a static poly for each other obstacle */ for( i = 0; i < wInfo->nObs; i++ ) { for( j = 0; j < wInfo->obs[i]->nPts; j++ ) { x[j] = wInfo->obs[i]->pts[j].x; y[j] = wInfo->obs[i]->pts[j].y; } ob = new MC_Polygon; ob->setXY(j, x, y); mOb.setObject(ob); mOb.nature() = MC_Obstacle; staticList.add2Top(mOb); } staticObjects() = staticList;}void PursuerMovie::AddCells(PInfo *pInfo){ int i, j; CellInfo *cInfo; Cell *c; double width; List<MC_MovieObject> list; cInfo = pInfo->cellInfo; list = staticObjects(); width = CalculateWidth(pInfo->wInfo->border) * PATH_WIDTH; for( i = 0; i < cInfo->nCells; i++ ) { c = cInfo->cells[i]; /* printf("\n\nCell\n----\n"); */ for( j = 0; j < c->nEdges; j++ ) { /* printf(" (%f, %f), (%f, %f)\n", c->edges[j]->A->x, c->edges[j]->A->y, c->edges[j]->B->x, c->edges[j]->B->y);*/ DumpLine(&list, width, MC_Decomposition, 0, c->edges[j]->A->x, c->edges[j]->A->y, c->edges[j]->B->x, c->edges[j]->B->y); } /* now output cell's center */ MC_MovieObject mOb; MC_Ball *ob; ob = new MC_Ball; ob->setCenter(c->pt->x, c->pt->y); ob->setRadius(width / 2); mOb.setObject(ob); mOb.nature() = MC_Path; list.add2Bottom(mOb); } printf("Cells: %d\n\n", cInfo->nCells); staticObjects() = list;}/* add the frames illustrating a solution to the p/e problem */void PursuerMovie::AddFrames(PInfo *pinfo){ 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 lastx, lasty; Point newP; VPoly newVPoly; MC_Transform *transform; // make an array if we have multiple moving obs List <MC_Transform> *transformList; frame = new MC_Frame[pinfo->nSteps * 20];/* add the frames we've built to the movie */ animated = &movingObjects(); stationary = &staticObjects(); lastx = pinfo->sln[0]->NodeCell()->pt->x; lasty = pinfo->sln[0]->NodeCell()->pt->y; frameCount = 0; for( i = 0; i < pinfo->nSteps; i++ ) { // new: interpolate between cell points in steps of size resolution. if( i < pinfo->nSteps - 1 && !bFast && !bDrawGaps) { dist = LineDistance(pinfo->sln[i]->NodeCell()->pt, pinfo->sln[i + 1]->NodeCell()->pt); } else { dist = 0.1; // force one step only } for( currdist = 0; currdist < dist; currdist += resolution ) { if( i < pinfo->nSteps - 1 && !bFast && !bDrawGaps ) { newP.x = pinfo->sln[i]->NodeCell()->pt->x + currdist/dist * ( pinfo->sln[i + 1]->NodeCell()->pt->x - pinfo->sln[i]->NodeCell()->pt->x ); newP.y = pinfo->sln[i]->NodeCell()->pt->y + currdist/dist * ( pinfo->sln[i + 1]->NodeCell()->pt->y - pinfo->sln[i]->NodeCell()->pt->y ); newP.w = 1; assert(MakeVisPoly(pinfo->edgeInfo, &newP, &newVPoly) ); } else { newP.x = pinfo->sln[i]->NodeCell()->pt->x; newP.y = pinfo->sln[i]->NodeCell()->pt->y; newVPoly = *pinfo->sln[i]->NodeCell()->vPoly; } gList = new List<MC_MovieObject>; if( bDrawGaps ) { width = CalculateWidth(pinfo->wInfo->border) * BORDER_WIDTH; DumpGaps(gList, width, MC_Goal, MC_Landmark, pinfo->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>; transform = new MC_Transform; transform->shift() = MC_Point(newP.x - lastx, newP.y - lasty, 1); transformList->add2Top(*transform); //lastx = pinfo->sln[i]->NodeCell()->pt->x; //lasty = pinfo->sln[i]->NodeCell()->pt->y; frame[frameCount++].setFrame(stationary, animated, *transformList, *gList); } } setFrames(frameCount, frame); assert(checkIntegrity(1));}void PursuerMovie::AddVPolys(CellInfo *cInfo){ 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; MC_Transform *transform; // make an array if we have multiple moving obs List <MC_Transform> *transformList; frame = new MC_Frame[cInfo->nCells];/* add the frames we've built to the movie */ animated = &movingObjects(); stationary = &staticObjects(); for( i = 0; i < cInfo->nCells; i++ ) { transformList = new List<MC_Transform>; transform = new MC_Transform; // default transformation transformList->add2Top(*transform); gList = new List<MC_MovieObject>; /* now mark the cell center so we can see where we start from */ MC_MovieObject mOb; MC_Ball *ob; ob = new MC_Ball; ob->setCenter(cInfo->cells[i]->pt->x, cInfo->cells[i]->pt->y); ob->setRadius(2); mOb.setObject(ob); mOb.nature() = MC_Goal; gList->add2Top(mOb); DumpVisPoly(gList, MC_Path, cInfo->cells[i]->vPoly); frame[i].setFrame(stationary, animated, *transformList, *gList); } setFrames(cInfo->nCells, frame); assert(checkIntegrity(1));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -