0 Members and 2 Guests are viewing this topic.
int* D3_sortFaces(Vertex *vertexTable, Vertex camera, int **faces, int numberOfFaces, int *verticesPerFace){ int i, j, flag, intermediate; char *order; int *zAverage; order = malloc(numberOfFaces * sizeof(char)); if(order == NULL) { printf("error with order"); return NULL; } zAverage = malloc(numberOfFaces * sizeof(int)); if(zAverage == NULL) { free(order); printf("error with zAverage"); return NULL; } for(i = 0; i < numberOfFaces; i++) { order[i] = i; zAverage[i] = 0; for(j = 0; j < verticesPerFace[i]; j++) { printf("%d,%d\n",i,j); zAverage[i] += vertexTable[faces[i][j]].z - camera.z; // crashes here } zAverage[i] /= verticesPerFace[i]; } printf("zAverage passed"); // etc
char faces[6][4] = { {0, 1, 2, 3}, {4, 5, 6, 7}, {0, 4, 7, 3}, {3, 2, 6, 7}, {0, 1, 5, 4}, {1, 5, 6, 2 } };char *order;int vpf[6] = { 4, 4, 4, 4, 4, 4 };// ...// rotated is a 8 elements-large table of bunches of 3 valuesorder = D3_sortFaces(rotated, (Vertex){0, 0, -150}, faces, 6, vpf);