From: Ian Jackson Date: Mon, 31 Dec 2007 02:25:15 +0000 (+0000) Subject: sort triangles by centroids X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=3228a46c1c7d345262324cad037d65cf7bbd62a4;p=moebius2.git sort triangles by centroids --- diff --git a/project.c b/project.c index a2e3f91..266237f 100644 --- a/project.c +++ b/project.c @@ -76,10 +76,14 @@ static void generate_display_list(void) { } static int dl_compare(const void *tav, const void *tbv) { + int i; const Triangle *const *tap= tav, *ta= *tap; const Triangle *const *tbp= tbp, *tb= *tbp; - double za= ta->vertex[0][2]; - double zb= tb->vertex[0][2]; + double za=0, zb=0; + for (i=0; i<3; i++) { + za += ta->vertex[i][2]; + zb += tb->vertex[i][2]; + } return za > zb ? -1 : za < zb ? +1 : 0; }