X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=polygon.c;h=2bc897fbe8baec206093b5fe6bb26308b1a15793;hb=e5c94e1dacbd569f6638687feedb1fb050bde1dc;hp=403dca3520922c2f846c4085a94477397ce431ab;hpb=9fa8ce6f31c95105ed4ac684b37f79f133b9c960;p=xonotic%2Fdarkplaces.git diff --git a/polygon.c b/polygon.c index 403dca35..2bc897fb 100644 --- a/polygon.c +++ b/polygon.c @@ -96,13 +96,11 @@ void PolygonD_QuadForPlane(double *outpoints, double planenormalx, double planen outpoints[11] = planedist * planenormalz - quadsize * quadright[2] - quadsize * quadup[2]; } -void PolygonF_Divide(int innumpoints, const float *inpoints, float planenormalx, float planenormaly, float planenormalz, float planedist, float epsilon, int outfrontmaxpoints, float *outfrontpoints, int *neededfrontpoints, int outbackmaxpoints, float *outbackpoints, int *neededbackpoints) +void PolygonF_Divide(int innumpoints, const float *inpoints, float planenormalx, float planenormaly, float planenormalz, float planedist, float epsilon, int outfrontmaxpoints, float *outfrontpoints, int *neededfrontpoints, int outbackmaxpoints, float *outbackpoints, int *neededbackpoints, int *oncountpointer) { - int i, frontcount, backcount; + int i, frontcount = 0, backcount = 0, oncount = 0; const float *n, *p; - float frac, pdist, ndist; - frontcount = 0; - backcount = 0; + double frac, pdist, ndist; for (i = 0;i < innumpoints;i++) { p = inpoints + i * 3; @@ -111,6 +109,8 @@ void PolygonF_Divide(int innumpoints, const float *inpoints, float planenormalx, ndist = n[0] * planenormalx + n[1] * planenormaly + n[2] * planenormalz - planedist; if (pdist >= -epsilon) { + if (pdist <= epsilon) + oncount++; if (frontcount < outfrontmaxpoints) { *outfrontpoints++ = p[0]; @@ -131,19 +131,20 @@ void PolygonF_Divide(int innumpoints, const float *inpoints, float planenormalx, } if ((pdist > epsilon && ndist < -epsilon) || (pdist < -epsilon && ndist > epsilon)) { + oncount++; frac = pdist / (pdist - ndist); if (frontcount < outfrontmaxpoints) { - *outfrontpoints++ = p[0] + frac * (n[0] - p[0]); - *outfrontpoints++ = p[1] + frac * (n[1] - p[1]); - *outfrontpoints++ = p[2] + frac * (n[2] - p[2]); + *outfrontpoints++ = (float)(p[0] + frac * (n[0] - p[0])); + *outfrontpoints++ = (float)(p[1] + frac * (n[1] - p[1])); + *outfrontpoints++ = (float)(p[2] + frac * (n[2] - p[2])); } frontcount++; if (backcount < outbackmaxpoints) { - *outbackpoints++ = p[0] + frac * (n[0] - p[0]); - *outbackpoints++ = p[1] + frac * (n[1] - p[1]); - *outbackpoints++ = p[2] + frac * (n[2] - p[2]); + *outbackpoints++ = (float)(p[0] + frac * (n[0] - p[0])); + *outbackpoints++ = (float)(p[1] + frac * (n[1] - p[1])); + *outbackpoints++ = (float)(p[2] + frac * (n[2] - p[2])); } backcount++; } @@ -152,15 +153,15 @@ void PolygonF_Divide(int innumpoints, const float *inpoints, float planenormalx, *neededfrontpoints = frontcount; if (neededbackpoints) *neededbackpoints = backcount; + if (oncountpointer) + *oncountpointer = oncount; } -void PolygonD_Divide(int innumpoints, const double *inpoints, double planenormalx, double planenormaly, double planenormalz, double planedist, double epsilon, int outfrontmaxpoints, double *outfrontpoints, int *neededfrontpoints, int outbackmaxpoints, double *outbackpoints, int *neededbackpoints) +void PolygonD_Divide(int innumpoints, const double *inpoints, double planenormalx, double planenormaly, double planenormalz, double planedist, double epsilon, int outfrontmaxpoints, double *outfrontpoints, int *neededfrontpoints, int outbackmaxpoints, double *outbackpoints, int *neededbackpoints, int *oncountpointer) { - int i, frontcount, backcount; + int i, frontcount = 0, backcount = 0, oncount = 0; const double *n, *p; double frac, pdist, ndist; - frontcount = 0; - backcount = 0; for (i = 0;i < innumpoints;i++) { p = inpoints + i * 3; @@ -169,6 +170,8 @@ void PolygonD_Divide(int innumpoints, const double *inpoints, double planenormal ndist = n[0] * planenormalx + n[1] * planenormaly + n[2] * planenormalz - planedist; if (pdist >= -epsilon) { + if (pdist <= epsilon) + oncount++; if (frontcount < outfrontmaxpoints) { *outfrontpoints++ = p[0]; @@ -189,6 +192,7 @@ void PolygonD_Divide(int innumpoints, const double *inpoints, double planenormal } if ((pdist > epsilon && ndist < -epsilon) || (pdist < -epsilon && ndist > epsilon)) { + oncount++; frac = pdist / (pdist - ndist); if (frontcount < outfrontmaxpoints) { @@ -210,5 +214,7 @@ void PolygonD_Divide(int innumpoints, const double *inpoints, double planenormal *neededfrontpoints = frontcount; if (neededbackpoints) *neededbackpoints = backcount; + if (oncountpointer) + *oncountpointer = oncount; }