+ int i, j, lastvert;
+ vec_t d, max, viewdist, average;
+ transpolyindices = 0;
+ viewdist = DotProduct(r_refdef.vieworg, vpn);
+ for (i = 0;i < currenttranspoly;i++)
+ {
+ if (transpoly[i].verts < 3) // only process valid polygons
+ continue;
+ max = -1000000;
+ lastvert = transpoly[i].firstvert + transpoly[i].verts;
+ average = 0;
+ for (j = transpoly[i].firstvert;j < lastvert;j++)
+ {
+ d = DotProduct(transvert[j].v, vpn)-viewdist;
+ average += d;
+ if (d > max)
+ max = d;
+ }
+ if (max < 4) // free to check here, so skip polys behind the view
+ continue;
+ transpoly[i].distance = average / transpoly[i].verts;
+ transpolyindex[transpolyindices++] = i;
+ }
+ qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort);
+}
+/*