/* recalcul des normales */ void updtNorms(void) { int i,j; int ptrFlSize = sizeof(GLfloat*); char errMsg[] = "Erreur après realloc."; /* normales des faces dans lesquelles les sommets sont compris */ GLfloat** vrtxFacesNorm[VERTICES_BOX01]; GLfloat faceNormals[FACES_BOX01][3]; GLint currSize[VERTICES_BOX01]; for(i = 0; i < FACES_BOX01; i++) surfaceNormal( &vertices[3*faces[i][0]], &vertices[3*faces[i][1]], &vertices[3*faces[i][2]], &faceNormals[i][0]); memset(currSize, 0, VERTICES_BOX01*sizeof(GLint)); memset(vrtxFacesNorm, 0, VERTICES_BOX01*sizeof(GLfloat**)); /* initialisaition de vrtxFacesNorm */ for(i = 0; i < FACES_BOX01; i++) { for(j = 0; j < 3; j++) { currSize[faces[i][j]]++; vrtxFacesNorm[faces[i][j]] = (GLfloat**)realloc(vrtxFacesNorm[faces[i][j]], currSize[faces[i][j]]*ptrFlSize); if (vrtxFacesNorm[faces[i][j]] == NULL) { // AnsiToOem(errMsg, errMsg); printf(errMsg); exit(1); } vrtxFacesNorm[faces[i][j]][currSize[faces[i][j]]-1] = &faceNormals[i][0]; } } /* calcul des normales des sommets */ for(i = 0; i < VERTICES_BOX01; i++) vertexNormal(vrtxFacesNorm[i], currSize[i], &norm[i*3]); }
FVector UGridMesher::calculateVertexNormal(const FRectGridLocation& gridLoc, const TArray<float>& vertexRadii) const { FVector tilePos = myGrid->getNodeLocationOnSphere(gridLoc) * vertexRadii[gridLoc.tileIndex]; TArray<int32> tileNeighbors = myGrid->getTileNeighborIndexes(gridLoc); FVector vertexNormal(0.0,0.0,0.0); for (int32 neighborNum = 0; neighborNum < tileNeighbors.Num(); ++neighborNum) { int32 neighbor2Num = neighborNum + 1; if (neighbor2Num == tileNeighbors.Num()) { neighbor2Num = 0; } vertexNormal += FVector::CrossProduct(myGrid->getNodeLocationOnSphere(myGrid->gridLocationsM[tileNeighbors[neighborNum]])*vertexRadii[tileNeighbors[neighborNum]], myGrid->getNodeLocationOnSphere(myGrid->gridLocationsM[tileNeighbors[neighbor2Num]])*vertexRadii[tileNeighbors[neighbor2Num]]); } vertexNormal /= tileNeighbors.Num(); vertexNormal /= FMath::Sqrt(FVector::DotProduct(vertexNormal, vertexNormal)); vertexNormal *= -1; //need it to face out return vertexNormal; }
const Vector<Scalar,2>& Polygon<Scalar>::vertexNormal(const Vertex<Scalar> &vertex) const { unsigned int normal_idx = vertex.normalIndex(); return vertexNormal(normal_idx); }