From 862c4f3c80e0c8fe22a95e020ec3e8fbb68b754e Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 23 Feb 2006 11:08:14 +0000 Subject: [PATCH] changed Polygon[DF]_Divide functions to also be able to return an on-plane points count git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6016 d7cf8633-e32d-0410-b094-e92efae38249 --- collision.c | 2 +- gl_rmain.c | 2 +- model_brush.c | 4 ++-- polygon.c | 24 +++++++++++++++--------- polygon.h | 4 ++-- portals.c | 2 +- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/collision.c b/collision.c index 32d53958..225caab2 100644 --- a/collision.c +++ b/collision.c @@ -183,7 +183,7 @@ colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalpla { // we want to keep the inside of the brush plane so we flip // the cutting plane - PolygonD_Divide(pnumpoints, p[w], -originalplanes[k].normal[0], -originalplanes[k].normal[1], -originalplanes[k].normal[2], -originalplanes[k].dist, 1.0/32.0, pmaxpoints, p[!w], &pnumpoints, 0, NULL, NULL); + PolygonD_Divide(pnumpoints, p[w], -originalplanes[k].normal[0], -originalplanes[k].normal[1], -originalplanes[k].normal[2], -originalplanes[k].dist, 1.0/32.0, pmaxpoints, p[!w], &pnumpoints, 0, NULL, NULL, NULL); w = !w; } } diff --git a/gl_rmain.c b/gl_rmain.c index fa278314..b2c5683d 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1569,7 +1569,7 @@ void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *plane { if (planenum2 == planenum) continue; - PolygonF_Divide(tempnumpoints, temppoints[w], plane2->normal[0], plane2->normal[1], plane2->normal[2], plane2->dist, 1.0/32.0, 0, NULL, NULL, 256, temppoints[!w], &tempnumpoints); + PolygonF_Divide(tempnumpoints, temppoints[w], plane2->normal[0], plane2->normal[1], plane2->normal[2], plane2->dist, 1.0/32.0, 0, NULL, NULL, 256, temppoints[!w], &tempnumpoints, NULL); w = !w; } if (tempnumpoints < 3) diff --git a/model_brush.c b/model_brush.c index c05eaf72..4c2a104c 100644 --- a/model_brush.c +++ b/model_brush.c @@ -2789,7 +2789,7 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node) for (i = 0;i < nodeportal->numpoints*3;i++) frontpoints[i] = nodeportal->points[i]; - PolygonD_Divide(nodeportal->numpoints, frontpoints, clipplane.normal[0], clipplane.normal[1], clipplane.normal[2], clipplane.dist, 1.0/32.0, MAX_PORTALPOINTS, nodeportal->points, &nodeportal->numpoints, 0, NULL, NULL); + PolygonD_Divide(nodeportal->numpoints, frontpoints, clipplane.normal[0], clipplane.normal[1], clipplane.normal[2], clipplane.dist, 1.0/32.0, MAX_PORTALPOINTS, nodeportal->points, &nodeportal->numpoints, 0, NULL, NULL, NULL); if (nodeportal->numpoints <= 0 || nodeportal->numpoints >= MAX_PORTALPOINTS) break; } @@ -2827,7 +2827,7 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node) RemovePortalFromNodes(portal); // cut the portal into two portals, one on each side of the node plane - PolygonD_Divide(portal->numpoints, portal->points, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, 1.0/32.0, MAX_PORTALPOINTS, frontpoints, &numfrontpoints, MAX_PORTALPOINTS, backpoints, &numbackpoints); + PolygonD_Divide(portal->numpoints, portal->points, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, 1.0/32.0, MAX_PORTALPOINTS, frontpoints, &numfrontpoints, MAX_PORTALPOINTS, backpoints, &numbackpoints, NULL); if (!numfrontpoints) { diff --git a/polygon.c b/polygon.c index 403dca35..997cb23a 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,6 +131,7 @@ 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) { @@ -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; } diff --git a/polygon.h b/polygon.h index e5826b8a..21537f8b 100644 --- a/polygon.h +++ b/polygon.h @@ -8,7 +8,7 @@ Polygon clipping routines written by Forest Hale and placed into public domain. void PolygonF_QuadForPlane(float *outpoints, float planenormalx, float planenormaly, float planenormalz, float planedist, float quadsize); void PolygonD_QuadForPlane(double *outpoints, double planenormalx, double planenormaly, double planenormalz, double planedist, double quadsize); -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 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 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); +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); #endif diff --git a/portals.c b/portals.c index 2eae8792..eb192b79 100644 --- a/portals.c +++ b/portals.c @@ -24,7 +24,7 @@ static int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnum memcpy(&portaltemppoints[0][0][0], targpoints, numpoints * 3 * sizeof(float)); for (i = 0;i < clipnumplanes;i++) { - PolygonF_Divide(numpoints, &portaltemppoints[0][0][0], clipplanes[i].normal[0], clipplanes[i].normal[1], clipplanes[i].normal[2], clipplanes[i].dist, 1.0f/32.0f, 256, &portaltemppoints[1][0][0], &numpoints, 0, NULL, NULL); + PolygonF_Divide(numpoints, &portaltemppoints[0][0][0], clipplanes[i].normal[0], clipplanes[i].normal[1], clipplanes[i].normal[2], clipplanes[i].dist, 1.0f/32.0f, 256, &portaltemppoints[1][0][0], &numpoints, 0, NULL, NULL, NULL); if (numpoints < 3) return numpoints; memcpy(&portaltemppoints[0][0][0], &portaltemppoints[1][0][0], numpoints * 3 * sizeof(float)); -- 2.39.2