// Deletes points with 3 or 4 neighbors void Mesh::deleteVertex() { for(int i = 0; i < (int)pts.size(); i++) { Vertex &p = pts[i]; int j = p.neib.size(); if (j == 3) { delVertex(i); sortNeigbor(i); changeTria(p.neibTria[0], p.neib[1], p.neib[0], p.neib[2]); delTria (p.neibTria[1]); delTria (p.neibTria[2]); } else if( j == 4 ){ delVertex(i); sortNeigbor(i); int n1 = pts[p.neib[0]].neib.size() - 7; int n2 = pts[p.neib[1]].neib.size() - 7; int n3 = pts[p.neib[2]].neib.size() - 7; int n4 = pts[p.neib[3]].neib.size() - 7; int sum = (n1+1)*(n1+1) + (n3+1)*(n3+1) + n2*n2 + n4*n4; int swap = (n2+1)*(n2+1) + (n4+1)*(n4+1) + n1*n1 + n3*n3; if (swap < sum) { changeTria(p.neibTria[0], p.neib[1], p.neib[0], p.neib[3]); changeTria(p.neibTria[1], p.neib[3], p.neib[2], p.neib[1]); } else { changeTria(p.neibTria[0], p.neib[1], p.neib[0], p.neib[2]); changeTria(p.neibTria[1], p.neib[3], p.neib[2], p.neib[0]); } delTria(p.neibTria[2]); delTria(p.neibTria[3]); } } pack(); calcNeigTria(); calcNeigbor(); }
void wdFree(World *W) { while (!lstEmpty(&W->Polygons)) { /* On retire le centre du polygon de la liste de vertices */ if(polyGetCenter((Polygon*) nodeGetData(lstFirst(&W->Polygons))) != NULL) { lstDel(&W->Vertices, polyGetCenter((Polygon*) nodeGetData(lstFirst(&W->Polygons)))); } delPolygon((Polygon*) nodeGetData(lstFirst(&W->Polygons))); lstRem(&W->Polygons, lstFirst(&W->Polygons)); } while (!lstEmpty(&W->Elastics)) { delElastic((Elastic*) nodeGetData(lstFirst(&W->Elastics))); lstRem(&W->Elastics, lstFirst(&W->Elastics)); } while (!lstEmpty(&W->Rigids)) { delRigid((Rigid*) nodeGetData(lstFirst(&W->Rigids))); lstRem(&W->Rigids, lstFirst(&W->Rigids)); } while (!lstEmpty(&W->Vertices)) { delVertex((Vertex*) nodeGetData(lstFirst(&W->Vertices))); lstRem(&W->Vertices, lstFirst(&W->Vertices)); } gridFree(&W->CollisionGrid); }
// Merges two points with 5 neibs void Mesh::mergeVertex() { calcEdge(); for(size_t i = 0; i < vb.size(); i++){ int v1 = vb[i]; int v2 = ve[i]; int n1 = pts[v1].neib.size(); int n2 = pts[v2].neib.size(); if( n1 == 5 && n2 == 5 ){ // Dont merge futher these points pts[v1].neib.push_back(-1); pts[v2].neib.push_back(-1); changeVertex(v1, v2); delVertex(v2); for (const int itr : pts[v2].neibTria) { Triangle &tr = tri[itr]; if( tr.v1 == v2 ) tr.v1 = v1; if( tr.v2 == v2 ) tr.v2 = v1; if( tr.v3 == v2 ) tr.v3 = v1; } delTria(tria1[i]); delTria(tria2[i]); } } pack(); calcNeigTria(); calcNeigbor(); }
SRDAGGraph::~SRDAGGraph() { while(edges_.getN()){ delEdge(edges_[0]); } while(vertices_.getN()){ delVertex(vertices_[0]); } }
PiSDFGraph::~PiSDFGraph() { while(edges_.getN() > 0) delEdge(edges_[0]); while(bodies_.getN() > 0){ if(bodies_[0]->isHierarchical()){ bodies_[0]->getSubGraph()->~PiSDFGraph(); StackMonitor::free(PISDF_STACK, bodies_[0]->getSubGraph()); } delVertex(bodies_[0]); } while(configs_.getN() > 0) delVertex(configs_[0]); while(inputIfs_.getN() > 0) delVertex(inputIfs_[0]); while(outputIfs_.getN() > 0) delVertex(outputIfs_[0]); while(params_.getN() > 0) delParam(params_[0]); }
void flFree(Flag* F) { for(unsigned int i = 0; i < daGetSize(&F->Vertices); i++) { delVertex((Vertex*) daGet(&F->Vertices, i)); } for(unsigned int i = 0; i < daGetSize(&F->Rigids); i++) { delRigid((Rigid*) daGet(&F->Rigids, i)); } daFree(&F->Vertices); daFree(&F->Rigids); }
void plFree(Player* P) { if(P->Shape != NULL) delPolygon(P->Shape); P->Shape = NULL; if(P->GrabR != NULL) delRigid(P->GrabR); if(P->GrabL != NULL) delRigid(P->GrabL); P->GrabR = NULL; P->GrabL = NULL; for (int i=0; i<12; i++) delVertex(P->vxBodyParts[i]), delRigid(P->BodyRigids[i]); delAnimation(P->aniFall); delAnimation(P->aniJump); delAnimation(P->aniRun); delAnimation(P->aniHello); delAnimation(P->aniStand); }
void delPolygon(Polygon* P) { unsigned int i; /* Destruction des liaisons */ for(i = 0; i < daGetSize(&P->Rigids); i++) { delRigid((Rigid*)daGet(&P->Rigids, i)); } for(i = 0; i < daGetSize(&P->InternalRigids); i++) { delRigid((Rigid*)daGet(&P->InternalRigids, i)); } /* Libération des Dynamic Arrays */ daFree(&P->Rigids); daFree(&P->Vertices); daFree(&P->InternalRigids); if(P->Center != NULL) delVertex(P->Center), P->Center = NULL; free(P); }
graph *updateGraph(graph *G,int sig) { //switch to the updation type switch(sig) { case 1: { //ADDING NUMBER OF EDGES// //variable declaration int i,j,edgeCount;//i.e number of edges //take number of edges printf("Enter the number of edges to be added: "); scanf("%d",&edgeCount); //take arrays to store edge end names char *from[edgeCount],*to[edgeCount]; //TAKING EDGES STARTS HERE printf("\n\tEnter the names of ends of edges:\n"); fflush(stdin); for(i=0;i<edgeCount;i++) { printf("\n\t\tEnd names for %dth Edge:\n",i+1); from[i]=(char *)malloc(sizeof(char)); to[i]=(char *)malloc(sizeof(char)); printf("\t\t\tEdge from end: "); from[i]=takeString(); printf("\t\t\tEdge to end: "); to[i]=takeString(); } //TAKING EDGES ENDS HERE //Add these edges to graph G=addEdge(G,from,to,edgeCount); //show message showMessage(4); break; } case 2: { //ADDING NUMBER OF VERTICES// //Variable declaration int i,noOfVert;//i.e number of vertices //Take number of vertices printf("Enter the number of vertices to be added: "); scanf("%d",&noOfVert); //take array to store the names char *vertName[noOfVert]; //TAKING VERTICES STARTS HERE printf("Enter the names of vertices:\n"); fflush(stdin); for(i=0;i<noOfVert;i++) { printf("Name of Vertex-%d: ",i+1); vertName[i]=(char *)malloc(sizeof(char)); vertName[i]=takeString(); } //TAKING VERTICES ENDS HERE //Add them to the Graph G=addVertex(G,vertName,noOfVert); //show message showMessage(5); break; } case 3: { //DELETING NUMBER OF EDGES// //variable declaration int i,j,edgeCount;//i.e number of edges //take number of edges printf("Enter the number of edges to be deleted: "); scanf("%d",&edgeCount); //take arrays to store edge end names char *from[edgeCount],*to[edgeCount]; //TAKING EDGES STARTS HERE printf("\n\tEnter the names of ends of edges:\n"); fflush(stdin); for(i=0;i<edgeCount;i++) { printf("\n\t\tEnd names for %dth Edge:\n",i+1); from[i]=(char *)malloc(sizeof(char)); to[i]=(char *)malloc(sizeof(char)); printf("\t\t\tEdge from end: "); from[i]=takeString(); printf("\t\t\tEdge to end: "); to[i]=takeString(); } //TAKING EDGES ENDS HERE //Delete the edges from the graph G=delEdge(G,from,to,edgeCount); //show message showMessage(6); break; } case 4: { //DELETING NUMBER OF VERTICES// //Variable declaration int i,noOfVert;//i.e number of vertices //Take number of vertices printf("Enter the number of vertices to be deleted: "); scanf("%d",&noOfVert); //take array to store the names char *vertName[noOfVert]; //TAKING VERTICES STARTS HERE printf("Enter the names of vertices:\n"); fflush(stdin); for(i=0;i<noOfVert;i++) { printf("Name of Vertex-%d: ",i+1); vertName[i]=(char *)malloc(sizeof(char)); vertName[i]=takeString(); } //TAKING VERTICES ENDS HERE //Delete them from the Graph G=delVertex(G,vertName,noOfVert); //show message showMessage(7); break; } default: { showMessage(3); break; } } return G; }
void polyRegressionTest() { printf("\n === Debut du test de regression de Polygon === \n\n"); unsigned int i; float prevdt = 1.f, dt = 1.f; Vertex* V1 = newVertex(); Vertex* V2 = newVertex(); Vertex* V3 = newVertex(); Vertex* V10 = newVertex(); Vertex* V11 = newVertex(); Vertex* V12 = newVertex(); Vertex* V13 = newVertex(); vxSetPosition(V1, vec2(0.f, 0.f)); vxSetPosition(V2, vec2(10.f, 0.f)); vxSetPosition(V3, vec2(0.f, 10.f)); vxSetPosition(V10, vec2(20.f, 0.f)); vxSetPosition(V11, vec2(30.f, 0.f)); vxSetPosition(V12, vec2(30.f, 10.f)); vxSetPosition(V13, vec2(20.f, 10.f)); Polygon* Poly = newPolygon(3, V1, V2, V3); Polygon* Rectangle = polyRectangle(V10, V11, V12, V13); for(i = 0; i < 10; i++) { printf("Frame #%d\n", i); printf("Triangle : (%f, %f) (%f, %f) (%f, %f)\n\n", vxGetPosition(V1).x, vxGetPosition(V1).y, vxGetPosition(V2).x, vxGetPosition(V2).y, vxGetPosition(V3).x, vxGetPosition(V3).y); printf("Rectangle : (%f, %f) (%f, %f) \n (%f, %f), (%f, %f)\n\n", vxGetPosition(V10).x, vxGetPosition(V10).y, vxGetPosition(V11).x, vxGetPosition(V11).y, vxGetPosition(V12).x, vxGetPosition(V12).y, vxGetPosition(V13).x, vxGetPosition(V13).y); vxApplyForce(V1, vec2(1.f, 0.f), 0); vxApplyForce(V10, vec2(1.f, 0.f), 0); vxResolve(V1, prevdt, dt); vxResolve(V2, prevdt, dt); vxResolve(V3, prevdt, dt); vxResolve(V10, prevdt, dt); vxResolve(V11, prevdt, dt); vxResolve(V12, prevdt, dt); vxResolve(V13, prevdt, dt); polyResolve(Poly); polyResolve(Rectangle); } delPolygon(Rectangle); delPolygon(Poly); delVertex(V13); delVertex(V12); delVertex(V11); delVertex(V10); delVertex(V3); delVertex(V2); delVertex(V1); printf("\n === Fin du test de regression de Polygon === \n\n"); }