changed Polygon[DF]_Divide functions to also be able to return an on-plane points...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 23 Feb 2006 11:08:14 +0000 (11:08 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 23 Feb 2006 11:08:14 +0000 (11:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6016 d7cf8633-e32d-0410-b094-e92efae38249

collision.c
gl_rmain.c
model_brush.c
polygon.c
polygon.h
portals.c

index 32d5395..225caab 100644 (file)
@@ -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;
                        }
                }
index fa27831..b2c5683 100644 (file)
@@ -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)
index c05eaf7..4c2a104 100644 (file)
@@ -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)
                {
index 403dca3..997cb23 100644 (file)
--- 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;
 }
 
index e5826b8..21537f8 100644 (file)
--- 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
index 2eae879..eb192b7 100644 (file)
--- 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));