TilePath clPather::RunBase() { TilePath ret; if(FindVertex(en,graph)==-1) return ret; int stpos=FindVertex(st,graph); if(stpos==-1)return ret; graph[stpos]->dist=0; std::vector <TileVertex*> Q; Q=graph; while(Q.size()>0) { int pos=FindMinDist(Q); TileVertex *u=Q[pos]; if(u->a==en) //yeah cia bisky pagreitinimas... { Q.clear(); break; } Q.erase(Q.begin()+pos); for(int i=E_UP;i<E_LAST;i++) { int vind=FindVertex(u->a->GetSide((SIDES)i),Q); //int vind=FindVertex(u->a->GetSide((SIDES)i),graph); unsigned alt=u->dist+1; if(vind!=-1) { TileVertex *v=Q[vind]; if(alt<v->dist) { v->dist=alt; v->prev=u; } } } } TileVertex *cur=graph[FindVertex(en,graph)]; while(cur->prev!=NULL) { ret.push_back(cur->a); cur=cur->prev; } for(int i=0;i<graph.size();i++) delete graph[i]; graph.clear(); return ret; }
/* * ReadSlopeInfo: Read a SlopeInfo structure from the given file. * Return TRUE on success. */ BOOL ReadSlopeInfo(int infile, SlopeInfo *info) { int x, y; int i; SHORT z; if (!read(infile, &info->plane.a, 4)) return FALSE; if (!read(infile, &info->plane.b, 4)) return FALSE; if (!read(infile, &info->plane.c, 4)) return FALSE; if (!read(infile, &info->plane.d, 4)) return FALSE; if (!read(infile, &info->x, 4)) return FALSE; if (!read(infile, &info->y, 4)) return FALSE; if (!read(infile, &info->angle, 4)) return FALSE; info->angle = info->angle * 360 / NUMDEGREES; for (i=0; i < 3; i++) { if (!read(infile, &x, 2)) return FALSE; if (!read(infile, &y, 2)) return FALSE; info->points[i].vertex = FindVertex(x, y); if (!read(infile, &z, 2)) return FALSE; info->points[i].z = z; } return TRUE; }
/* * @brief */ static void EmitFaceVertexes(node_t *node, face_t *f) { winding_t *w; int32_t i; if (f->merged || f->split[0] || f->split[1]) return; w = f->w; for (i = 0; i < w->num_points; i++) { if (noweld) { // make every point unique if (d_bsp.num_vertexes == MAX_BSP_VERTS) Com_Error(ERR_FATAL, "MAX_BSP_VERTS\n"); superverts[i] = d_bsp.num_vertexes; VectorCopy(w->points[i], d_bsp.vertexes[d_bsp.num_vertexes].point); d_bsp.num_vertexes++; c_uniqueverts++; c_totalverts++; } else superverts[i] = FindVertex(w->points[i]); } num_superverts = w->num_points; // this may fragment the face if > MAXEDGES FaceFromSuperverts(node, f, 0); }
void DexSkinMesh::AddVertex(int8 meshId, const DexVector3& pos, const DexVector3& normal, const DexVector2& uv) { DexMesh* mesh = FindMesh(meshId); DEX_ENSURE(mesh); if (!FindVertex(pos)) {//添加新顶点并绑到根节点上 AddVertex(pos, NULL, NULL, 0); } mesh->AddVertex(pos, normal, uv.x, uv.y); }
/** Change the name of a vertex @param[in] i index number of vertex to be changed @param[in] n the new name @return 0 success @return 1 name already exists, no change made @return 2 index out of range, no change made */ int cGraph::setNameVertex( int i, const std::wstring& n ) { if( 0 > i || i >= getVertexCount() ) return 2; if( FindVertex( n ) ) return 1; graph_t::vertex_descriptor v = *vertices(myGraph).first; myGraph[v+i].myName = n; return 0; }
BOOL NewVertex(LEVEL_DATA *pLevel, LONG x, LONG y, LONG z) { INT nIndex; VERTEX vertex; VERTEX huge *p; if (pLevel->nVertices == MAX_NUM_VERTICES) { MsgBox( hwndMDIClient, MB_ICONEXCLAMATION, "Out of vertex data space" ); return FALSE; } _fmemset(&vertex, 0, sizeof(VERTEX)); vertex.flags = 0; vertex.x = (float)x; vertex.y = (float)y; vertex.z = (float)z; vertex.group_index = -1; vertex.sprite_index = -1; vertex.noise_index = -1; vertex.lifeform_index = -1; vertex.item_index = -1; vertex.trigger_index = -1; // // If we already have that vertex then just make sure it isn't hidden. // nIndex = FindVertex(pLevel, 0, &vertex); if (nIndex != -1) { p = pLevel->pVertexData + nIndex; p->flags &= ~VF_HIDDEN; return TRUE; } // // Record the new vertex. // _fmemcpy(pLevel->pVertexData + pLevel->nVertices, &vertex, sizeof(VERTEX)); ++pLevel->nVertices; pLevel->bRebuildZone = TRUE; return TRUE; } // NewVertex
void PrimALG(ALGraph * G){ char v; int i,j,k,parent,root; int Parent[MaxVertexNum] = {0}; int LowCost[MaxVertexNum]; //当前树与某个点的直接边的权值(若在树内则为0,无边则为INFINITY) EdgeNode * edge; printf("Spanning From the Vertex V(V must belong to the Graph):\n"); scanf("%c%*c",&v); root = FindVertex(G,v); edge = G->Adjlist[root].FirstEdge; for( i=0; i<G->n; i++){ LowCost[i] = INFINITY; } while(edge){ LowCost[(edge->AdjV)] = edge->Value; edge = edge->Next; } Parent[root] = -1; //根节点 LowCost[root] = 0; parent = root; for( j=0; j<G->n; j++){ //因为一共只需加入N次顶点即可 printf("Visited Vertex: %c \n",G->Adjlist[parent].Vertex); i = FindMin(G,LowCost); //搜索出距离当前树最近的顶点 if( i>=0 ){ //如果i>0,即搜索结果为还有未加入树的顶点 LowCost[i] = 0; Parent[i] = parent; parent = i; edge = G->Adjlist[i].FirstEdge; while( edge ){ //【重要】每次找到一个新的顶点都需要更新其他顶点对于树的距离 k = edge->AdjV; LowCost[k] = Min(LowCost[k],edge->Value); edge = edge->Next; } }else{ //这里加的else作用比较特殊(只有非连通图才能进来) printf("图非连通\n"); break; } } return ; }
hobj_t * BuildFixPolygonClass( polygon_t *p, hobj_t *vertexcls ) { hobj_t *fixpoly; hpair_t *pair; char tt[256]; int i; sprintf( tt, "#%u", HManagerGetFreeID() ); fixpoly = NewClass( "fixpolygon", tt ); sprintf( tt, "%d", p->pointnum ); pair = NewHPair2( "int", "pointnum", tt ); InsertHPair( fixpoly, pair ); for( i = 0; i < p->pointnum; i++ ) { sprintf( tt, "%d", i ); pair = NewHPair2( "ref", tt, FindVertex( p->p[i], vertexcls )->name ); InsertHPair( fixpoly, pair ); } return fixpoly; }
static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec) { int i, j; // Setting numvertexes to the same as numwalls is overly conservative, // but the extra vertices will be removed during the BSP building pass. numsides = numvertexes = numwalls; numlines = 0; sides = new side_t[numsides]; memset (sides, 0, numsides*sizeof(side_t)); vertexes = new vertex_t[numvertexes]; numvertexes = 0; // First mark each sidedef with the sector it belongs to for (i = 0; i < numsectors; ++i) { if (bsec[i].wallptr >= 0) { for (j = 0; j < bsec[i].wallnum; ++j) { sides[j + bsec[i].wallptr].sector = sectors + i; } } } // Now copy wall properties to their matching sidedefs for (i = 0; i < numwalls; ++i) { char tnam[9]; FTextureID overpic, pic; mysnprintf (tnam, countof(tnam), "BTIL%04d", LittleShort(walls[i].picnum)); pic = TexMan.GetTexture (tnam, FTexture::TEX_Build); mysnprintf (tnam, countof(tnam), "BTIL%04d", LittleShort(walls[i].overpicnum)); overpic = TexMan.GetTexture (tnam, FTexture::TEX_Build); walls[i].x = LittleLong(walls[i].x); walls[i].y = LittleLong(walls[i].y); walls[i].point2 = LittleShort(walls[i].point2); walls[i].cstat = LittleShort(walls[i].cstat); walls[i].nextwall = LittleShort(walls[i].nextwall); walls[i].nextsector = LittleShort(walls[i].nextsector); sides[i].SetTextureXOffset(walls[i].xpanning << FRACBITS); sides[i].SetTextureYOffset(walls[i].ypanning << FRACBITS); sides[i].SetTexture(side_t::top, pic); sides[i].SetTexture(side_t::bottom, pic); if (walls[i].nextsector < 0 || (walls[i].cstat & 32)) { sides[i].SetTexture(side_t::mid, pic); } else if (walls[i].cstat & 16) { sides[i].SetTexture(side_t::mid, overpic); } else { sides[i].SetTexture(side_t::mid, FNullTextureID()); } sides[i].TexelLength = walls[i].xrepeat * 8; sides[i].SetTextureYScale(walls[i].yrepeat << (FRACBITS - 3)); sides[i].SetTextureXScale(FRACUNIT); sides[i].SetLight(SHADE2LIGHT(walls[i].shade)); sides[i].Flags = WALLF_ABSLIGHTING; sides[i].RightSide = walls[i].point2; sides[walls[i].point2].LeftSide = i; if (walls[i].nextwall >= 0 && walls[i].nextwall <= i) { sides[i].linedef = sides[walls[i].nextwall].linedef; } else { sides[i].linedef = (line_t*)(intptr_t)(numlines++); } } // Set line properties that Doom doesn't store per-sidedef lines = new line_t[numlines]; memset (lines, 0, numlines*sizeof(line_t)); for (i = 0, j = -1; i < numwalls; ++i) { if (walls[i].nextwall >= 0 && walls[i].nextwall <= i) { continue; } j = int(intptr_t(sides[i].linedef)); lines[j].sidedef[0] = (side_t*)(intptr_t)i; lines[j].sidedef[1] = (side_t*)(intptr_t)walls[i].nextwall; lines[j].v1 = FindVertex (walls[i].x, walls[i].y); lines[j].v2 = FindVertex (walls[walls[i].point2].x, walls[walls[i].point2].y); lines[j].frontsector = sides[i].sector; lines[j].flags |= ML_WRAP_MIDTEX; if (walls[i].nextsector >= 0) { lines[j].backsector = sectors + walls[i].nextsector; lines[j].flags |= ML_TWOSIDED; } else { lines[j].backsector = NULL; } P_AdjustLine (&lines[j]); if (walls[i].cstat & 128) { if (walls[i].cstat & 512) { lines[j].Alpha = FRACUNIT/3; } else { lines[j].Alpha = FRACUNIT*2/3; } } if (walls[i].cstat & 1) { lines[j].flags |= ML_BLOCKING; } if (walls[i].nextwall < 0) { if (walls[i].cstat & 4) { lines[j].flags |= ML_DONTPEGBOTTOM; } } else { if (walls[i].cstat & 4) { lines[j].flags |= ML_DONTPEGTOP; } else { lines[j].flags |= ML_DONTPEGBOTTOM; } } if (walls[i].cstat & 64) { lines[j].flags |= ML_BLOCKEVERYTHING; } } // Finish setting sector properties that depend on walls for (i = 0; i < numsectors; ++i, ++bsec) { SlopeWork slope; slope.wal = &walls[bsec->wallptr]; slope.wal2 = &walls[slope.wal->point2]; slope.dx = slope.wal2->x - slope.wal->x; slope.dy = slope.wal2->y - slope.wal->y; slope.i = long (sqrt ((double)(slope.dx*slope.dx+slope.dy*slope.dy))) << 5; if (slope.i == 0) { continue; } if ((bsec->floorstat & 2) && (bsec->floorheinum != 0)) { // floor is sloped slope.heinum = -LittleShort(bsec->floorheinum); slope.z[0] = slope.z[1] = slope.z[2] = -bsec->floorz; CalcPlane (slope, sectors[i].floorplane); } if ((bsec->ceilingstat & 2) && (bsec->ceilingheinum != 0)) { // ceiling is sloped slope.heinum = -LittleShort(bsec->ceilingheinum); slope.z[0] = slope.z[1] = slope.z[2] = -bsec->ceilingz; CalcPlane (slope, sectors[i].ceilingplane); } int linenum = int(intptr_t(sides[bsec->wallptr].linedef)); int sidenum = int(intptr_t(lines[linenum].sidedef[1])); if (bsec->floorstat & 64) { // floor is aligned to first wall P_AlignFlat (linenum, sidenum == bsec->wallptr, 0); } if (bsec->ceilingstat & 64) { // ceiling is aligned to first wall P_AlignFlat (linenum, sidenum == bsec->wallptr, 0); } } for (i = 0; i < numlines; i++) { intptr_t front = intptr_t(lines[i].sidedef[0]); intptr_t back = intptr_t(lines[i].sidedef[1]); lines[i].sidedef[0] = front >= 0 ? &sides[front] : NULL; lines[i].sidedef[1] = back >= 0 ? &sides[back] : NULL; } for (i = 0; i < numsides; i++) { assert(sides[i].sector != NULL); sides[i].linedef = &lines[intptr_t(sides[i].linedef)]; } }