]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - portals.c
added Battlemech (thanks to Todd for submitting the patch, though I replaced his...
[xonotic/darkplaces.git] / portals.c
index 18e17b79e29c90eb00a19dccd10fbbb770675a19..dff58aef4eacd96b0d15f8006122d370b354e6ef 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -135,12 +135,12 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
                                {
                                        if (Portal_RecursiveFlowSearch(p->past, eye, firstclipplane + numclipplanes, newpoints))
                                                return true;
-                       }
+                               }
                                else
                                {
                                        if (Portal_RecursiveFlowSearch(p->past, eye, firstclipplane, numclipplanes))
                                                return true;
-                       }
+                               }
                        }
                }
        }
@@ -193,9 +193,9 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
        portal_markid++;
 
        Mod_CheckLoaded(model);
-       Portal_PolygonRecursiveMarkLeafs(model->nodes, polypoints, numpoints);
+       Portal_PolygonRecursiveMarkLeafs(model->brushq1.nodes, polypoints, numpoints);
 
-       eyeleaf = Mod_PointInLeaf(eye, model);
+       eyeleaf = model->brushq1.PointInLeaf(model, eye);
 
        // find the center by averaging
        VectorClear(center);
@@ -322,6 +322,7 @@ vec3_t trianglepoints[3];
 typedef struct portalrecursioninfo_s
 {
        int exact;
+       int numfrustumplanes;
        float nradius;
        qbyte *surfacemark;
        qbyte *leafmark;
@@ -339,7 +340,7 @@ void Portal_RecursiveFlow_ExactMarkSurfaces(portalrecursioninfo_t *info, int *ma
        {
                if (!info->surfacemark[*mark])
                {
-                       surf = info->model->surfaces + *mark;
+                       surf = info->model->brushq1.surfaces + *mark;
                        if (surf->poly_numverts)
                        {
                                if (surf->flags & SURF_PLANEBACK)
@@ -359,14 +360,12 @@ void Portal_RecursiveFlow_ExactMarkSurfaces(portalrecursioninfo_t *info, int *ma
                        {
                                for (surfmesh = surf->mesh;surfmesh;surfmesh = surfmesh->chain)
                                {
-                                       for (j = 0, elements = surfmesh->index;j < surfmesh->numtriangles;j++, elements += 3)
+                                       for (j = 0, elements = surfmesh->element3i;j < surfmesh->numtriangles;j++, elements += 3)
                                        {
-                                               VectorCopy((surfmesh->verts + elements[0] * 4), trianglepoints[0]);
-                                               VectorCopy((surfmesh->verts + elements[1] * 4), trianglepoints[1]);
-                                               VectorCopy((surfmesh->verts + elements[2] * 4), trianglepoints[2]);
-                                               if ((info->eye[0] - trianglepoints[0][0]) * ((trianglepoints[0][1] - trianglepoints[1][1]) * (trianglepoints[2][2] - trianglepoints[1][2]) - (trianglepoints[0][2] - trianglepoints[1][2]) * (trianglepoints[2][1] - trianglepoints[1][1]))
-                                                 + (info->eye[1] - trianglepoints[0][1]) * ((trianglepoints[0][2] - trianglepoints[1][2]) * (trianglepoints[2][0] - trianglepoints[1][0]) - (trianglepoints[0][0] - trianglepoints[1][0]) * (trianglepoints[2][2] - trianglepoints[1][2]))
-                                                 + (info->eye[2] - trianglepoints[0][2]) * ((trianglepoints[0][0] - trianglepoints[1][0]) * (trianglepoints[2][1] - trianglepoints[1][1]) - (trianglepoints[0][1] - trianglepoints[1][1]) * (trianglepoints[2][0] - trianglepoints[1][0])) > 0
+                                               VectorCopy((surfmesh->vertex3f + elements[0] * 3), trianglepoints[0]);
+                                               VectorCopy((surfmesh->vertex3f + elements[1] * 3), trianglepoints[1]);
+                                               VectorCopy((surfmesh->vertex3f + elements[2] * 3), trianglepoints[2]);
+                                               if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2])
                                                 && Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3)
                                                        break;
                                        }
@@ -390,7 +389,7 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
        tinyplane_t *newplanes;
 
        if (info->leafmark)
-               info->leafmark[leaf - info->model->leafs] = true;
+               info->leafmark[leaf - info->model->brushq1.leafs] = true;
 
        // mark surfaces in leaf that can be seen through portal
        if (leaf->nummarksurfaces && info->surfacemark)
@@ -446,6 +445,23 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
        }
 }
 
+void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
+{
+       if (node->contents)
+       {
+               if (node->contents != CONTENTS_SKY && node->contents != CONTENTS_SOLID)
+                       Portal_RecursiveFlow(info, (mleaf_t *)node, 0, info->numfrustumplanes);
+       }
+       else
+       {
+               float f = DotProduct(info->eye, node->plane->normal) - node->plane->dist;
+               if (f > -0.1)
+                       Portal_RecursiveFindLeafForFlow(info, node->children[0]);
+               if (f < 0.1)
+                       Portal_RecursiveFindLeafForFlow(info, node->children[1]);
+       }
+}
+
 void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius)
 {
        int i;
@@ -476,8 +492,9 @@ void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte
        info.leafmark = leafmark;
        info.model = model;
        VectorCopy(eye, info.eye);
+       info.numfrustumplanes = numfrustumplanes;
 
-       Portal_RecursiveFlow(&info, Mod_PointInLeaf(eye, model), 0, numfrustumplanes);
+       Portal_RecursiveFindLeafForFlow(&info, model->brushq1.nodes);
 
        if (ranoutofportalplanes)
                Con_Printf("Portal_RecursiveFlow: ran out of %d plane stack when recursing through portals\n", MAXRECURSIVEPORTALPLANES);