From ad12d2a34f5f25a4c1abaa3d40e33706aef3fe78 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 2 Mar 2011 23:58:20 +0000 Subject: [PATCH] fixed surface traceline code, bouncegrid looks a lot better now git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10882 d7cf8633-e32d-0410-b094-e92efae38249 --- model_brush.c | 73 ++++++++++++++++++++++++++------------------------- todo | 1 + 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/model_brush.c b/model_brush.c index 16d1c746..7a16f6d7 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1293,7 +1293,7 @@ void Mod_Q1BSP_LightPoint(dp_model_t *model, const vec3_t p, vec3_t ambientcolor Mod_Q1BSP_LightPoint_RecursiveBSPNode(model, ambientcolor, diffusecolor, diffusenormal, model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode, p[0], p[1], p[2] + 0.125, p[2] - 65536); } -static texture_t *Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(RecursiveHullCheckTraceInfo_t *t, const dp_model_t *model, const mnode_t *node, double mid[3]) +static const texture_t *Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(RecursiveHullCheckTraceInfo_t *t, const dp_model_t *model, const mnode_t *node, double mid[3]) { int i; int j; @@ -1305,8 +1305,12 @@ static texture_t *Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(RecursiveH float v1[3]; float edgedir[3]; float edgenormal[3]; - float p[3]; + float p[4]; + float midf; + float t1; + float t2; VectorCopy(mid, p); + p[3] = 1; surface = model->data_surfaces + node->firstsurface; for (i = 0;i < node->numsurfaces;i++, surface++) { @@ -1323,6 +1327,7 @@ static texture_t *Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(RecursiveH if (!(t->trace->hitsupercontentsmask & surface->texture->supercontents)) continue; VectorCopy(model->surfmesh.data_normal3f + 3 * surface->num_firstvertex, normal); + //VectorCopy(node->plane->normal, normal); for (j = 0, k = surface->num_vertices - 1;j < surface->num_vertices;k = j, j++) { VectorCopy(model->surfmesh.data_vertex3f + 3 * (surface->num_firstvertex + k), v0); @@ -1332,11 +1337,30 @@ static texture_t *Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(RecursiveH if (DotProduct(edgenormal, p) > DotProduct(edgenormal, v0)) break; } - if (j == surface->num_vertices) - { - // hit this surface - return surface->texture->currentframe; - } + if (j < surface->num_vertices) + continue; + + // we hit a surface, this is the impact point... + VectorCopy(normal, t->trace->plane.normal); + t->trace->plane.dist = DotProduct(normal, p); + + // calculate the true fraction + t1 = DotProduct(t->start, t->trace->plane.normal) - t->trace->plane.dist; + t2 = DotProduct(t->end, t->trace->plane.normal) - t->trace->plane.dist; + midf = t1 / (t1 - t2); + t->trace->realfraction = midf; + + // calculate the return fraction which is nudged off the surface a bit + midf = (t1 - DIST_EPSILON) / (t1 - t2); + t->trace->fraction = bound(0, midf, 1); + + if (collision_prefernudgedfraction.integer) + t->trace->realfraction = t->trace->fraction; + + t->trace->hittexture = surface->texture->currentframe; + t->trace->hitq3surfaceflags = t->trace->hittexture->surfaceflags; + t->trace->hitsupercontents = t->trace->hittexture->supercontents; + return surface->texture->currentframe; } return NULL; } @@ -1401,36 +1425,13 @@ static int Mod_Q1BSP_TraceLineAgainstSurfacesRecursiveBSPNode(RecursiveHullCheck if (Mod_Q1BSP_TraceLineAgainstSurfacesRecursiveBSPNode(t, model, node->children[side], p1, mid) == HULLCHECKSTATE_DONE) return HULLCHECKSTATE_DONE; - t->trace->hittexture = Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(t, model, node, mid); - if (!t->trace->hittexture) - return Mod_Q1BSP_TraceLineAgainstSurfacesRecursiveBSPNode(t, model, node->children[side ^ 1], mid, p2); - - // we hit a surface, this is the impact point... - if (side) - { - t->trace->plane.dist = -plane->dist; - VectorNegate (plane->normal, t->trace->plane.normal); - } - else - { - t->trace->plane.dist = plane->dist; - VectorCopy (plane->normal, t->trace->plane.normal); - } - - // calculate the true fraction - t->trace->realfraction = midf; - - // calculate the return fraction which is nudged off the surface a bit - midf = (t1 - DIST_EPSILON) / (t1 - t2); - t->trace->fraction = bound(0, midf, 1); - - if (collision_prefernudgedfraction.integer) - t->trace->realfraction = t->trace->fraction; - - t->trace->hitq3surfaceflags = t->trace->hittexture->surfaceflags; - t->trace->hitsupercontents = t->trace->hittexture->supercontents; + // test each surface on the node + Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(t, model, node, mid); + if (t->trace->hittexture) + return HULLCHECKSTATE_DONE; - return HULLCHECKSTATE_DONE; + // recurse back side + return Mod_Q1BSP_TraceLineAgainstSurfacesRecursiveBSPNode(t, model, node->children[side ^ 1], mid, p2); } leaf = (const mleaf_t *)node; side = Mod_Q1BSP_SuperContentsFromNativeContents(NULL, leaf->contents); diff --git a/todo b/todo index 0e26bcf1..ed03a343 100644 --- a/todo +++ b/todo @@ -1,4 +1,5 @@ - todo: difficulty ratings are: 0 = trivial, 1 = easy, 2 = easy-moderate, 3 = moderate, 4 = moderate-hard, 5 = hard, 6 = hard++, 7 = nightmare, d = done, -d = done but have not notified the people who asked for it, f = failed, -f = failed but have not notified the people who asked for it +0 bug darkplaces qw: tf skins not working (xavior) 0 bug darkplaces renderer: rtworld seems to mess up player pants/shirt colors 0 bug darkplaces d3d9: drawsetcliparea not working right (VorteX) 0 bug darkplaces d3d9: shadowmaps are clipped - does this mean r_shadows 2 or light shadowmaps? (VorteX) -- 2.39.2