diff --git a/src/renderer/tr_marks.c b/src/renderer/tr_marks.c index c114a9d30..a2d8596c5 100644 --- a/src/renderer/tr_marks.c +++ b/src/renderer/tr_marks.c @@ -304,244 +304,6 @@ void R_AddMarkFragments(int numClipPoints, vec3_t clipPoints[2][MAX_VERTS_ON_POL (*returnedFragments)++; } -/* -================= -R_OldMarkFragments -================= -*/ -int R_OldMarkFragments(int numPoints, const vec3_t *points, const vec3_t projection, - int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer) -{ - int numsurfaces, numPlanes; - int i, j, k, m, n; - surfaceType_t *surfaces[64]; - vec3_t mins, maxs; - int returnedFragments; - int returnedPoints; - vec3_t normals[MAX_VERTS_ON_POLY + 2]; - float dists[MAX_VERTS_ON_POLY + 2]; - vec3_t clipPoints[2][MAX_VERTS_ON_POLY]; - int numClipPoints; - float *v; - srfSurfaceFace_t *surf; - srfGridMesh_t *cv; - drawVert_t *dv; - vec3_t normal; - vec3_t projectionDir; - vec3_t v1, v2; - int *indexes; - - if (numPoints <= 0) - { - return 0; - } - - //increment view count for double check prevention - tr.viewCount++; - - VectorNormalize2(projection, projectionDir); - // find all the brushes that are to be considered - ClearBounds(mins, maxs); - for (i = 0 ; i < numPoints ; i++) - { - vec3_t temp; - - AddPointToBounds(points[i], mins, maxs); - VectorAdd(points[i], projection, temp); - AddPointToBounds(temp, mins, maxs); - // make sure we get all the leafs (also the one(s) in front of the hit surface) - VectorMA(points[i], -20, projectionDir, temp); - AddPointToBounds(temp, mins, maxs); - } - - if (numPoints > MAX_VERTS_ON_POLY) - { - numPoints = MAX_VERTS_ON_POLY; - } - // create the bounding planes for the to be projected polygon - for (i = 0 ; i < numPoints ; i++) - { - VectorSubtract(points[(i + 1) % numPoints], points[i], v1); - VectorAdd(points[i], projection, v2); - VectorSubtract(points[i], v2, v2); - CrossProduct(v1, v2, normals[i]); - VectorNormalizeFast(normals[i]); - dists[i] = DotProduct(normals[i], points[i]); - } - // add near and far clipping planes for projection - VectorCopy(projectionDir, normals[numPoints]); - dists[numPoints] = DotProduct(normals[numPoints], points[0]) - 32; - VectorCopy(projectionDir, normals[numPoints + 1]); - VectorInverse(normals[numPoints + 1]); - dists[numPoints + 1] = DotProduct(normals[numPoints + 1], points[0]) - 20; - numPlanes = numPoints + 2; - - numsurfaces = 0; - R_BoxSurfaces_r(tr.world->nodes, mins, maxs, surfaces, 64, &numsurfaces, projectionDir); - //assert(numsurfaces <= 64); - //assert(numsurfaces != 64); - - returnedPoints = 0; - returnedFragments = 0; - - for (i = 0 ; i < numsurfaces ; i++) - { - if (*surfaces[i] == SF_GRID) - { - cv = (srfGridMesh_t *) surfaces[i]; - for (m = 0 ; m < cv->height - 1 ; m++) - { - for (n = 0 ; n < cv->width - 1 ; n++) - { - // We triangulate the grid and chop all triangles within - // the bounding planes of the to be projected polygon. - // LOD is not taken into account, not such a big deal though. - // - // It's probably much nicer to chop the grid itself and deal - // with this grid as a normal SF_GRID surface so LOD will - // be applied. However the LOD of that chopped grid must - // be synced with the LOD of the original curve. - // One way to do this; the chopped grid shares vertices with - // the original curve. When LOD is applied to the original - // curve the unused vertices are flagged. Now the chopped curve - // should skip the flagged vertices. This still leaves the - // problems with the vertices at the chopped grid edges. - // - // To avoid issues when LOD applied to "hollow curves" (like - // the ones around many jump pads) we now just add a 2 unit - // offset to the triangle vertices. - // The offset is added in the vertex normal vector direction - // so all triangles will still fit together. - // The 2 unit offset should avoid pretty much all LOD problems. - - numClipPoints = 3; - - dv = cv->verts + m * cv->width + n; - - VectorCopy(dv[0].xyz, clipPoints[0][0]); - VectorMA(clipPoints[0][0], MARKER_OFFSET, dv[0].normal, clipPoints[0][0]); - VectorCopy(dv[cv->width].xyz, clipPoints[0][1]); - VectorMA(clipPoints[0][1], MARKER_OFFSET, dv[cv->width].normal, clipPoints[0][1]); - VectorCopy(dv[1].xyz, clipPoints[0][2]); - VectorMA(clipPoints[0][2], MARKER_OFFSET, dv[1].normal, clipPoints[0][2]); - // check the normal of this triangle - VectorSubtract(clipPoints[0][0], clipPoints[0][1], v1); - VectorSubtract(clipPoints[0][2], clipPoints[0][1], v2); - CrossProduct(v1, v2, normal); - VectorNormalizeFast(normal); - if (DotProduct(normal, projectionDir) < -0.1) - { - // add the fragments of this triangle - R_AddMarkFragments(numClipPoints, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - - VectorCopy(dv[1].xyz, clipPoints[0][0]); - VectorMA(clipPoints[0][0], MARKER_OFFSET, dv[1].normal, clipPoints[0][0]); - VectorCopy(dv[cv->width].xyz, clipPoints[0][1]); - VectorMA(clipPoints[0][1], MARKER_OFFSET, dv[cv->width].normal, clipPoints[0][1]); - VectorCopy(dv[cv->width + 1].xyz, clipPoints[0][2]); - VectorMA(clipPoints[0][2], MARKER_OFFSET, dv[cv->width + 1].normal, clipPoints[0][2]); - // check the normal of this triangle - VectorSubtract(clipPoints[0][0], clipPoints[0][1], v1); - VectorSubtract(clipPoints[0][2], clipPoints[0][1], v2); - CrossProduct(v1, v2, normal); - VectorNormalizeFast(normal); - if (DotProduct(normal, projectionDir) < -0.05) - { - // add the fragments of this triangle - R_AddMarkFragments(numClipPoints, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - } - } - } - else if (*surfaces[i] == SF_FACE) - { - surf = ( srfSurfaceFace_t * ) surfaces[i]; - // check the normal of this face - if (DotProduct(surf->plane.normal, projectionDir) > -0.5) - { - continue; - } - - indexes = ( int * )((byte *)surf + surf->ofsIndices); - for (k = 0 ; k < surf->numIndices ; k += 3) - { - for (j = 0 ; j < 3 ; j++) - { - v = surf->points[0] + VERTEXSIZE * indexes[k + j]; - VectorMA(v, MARKER_OFFSET, surf->plane.normal, clipPoints[0][j]); - } - // add the fragments of this face - R_AddMarkFragments(3, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - continue; - } - // Arnout: projection on models (mainly for terrain though) - else if (*surfaces[i] == SF_TRIANGLES) - { - srfTriangles_t *cts; - cts = ( srfTriangles_t * ) surfaces[i]; - - indexes = cts->indexes; - for (k = 0 ; k < cts->numIndexes ; k += 3) - { - for (j = 0 ; j < 3 ; j++) - { - v = cts->verts[indexes[k + j]].xyz; - VectorMA(v, MARKER_OFFSET, cts->verts[indexes[k + j]].normal, clipPoints[0][j]); - } - // add the fragments of this face - R_AddMarkFragments(3, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - continue; - } - else - { - // ignore all other world surfaces - // might be cool to also project polygons on a triangle soup - // however this will probably create huge amounts of extra polys - // even more than the projection onto curves - continue; - } - } - return returnedFragments; -} - /* ================= R_MarkFragments @@ -583,8 +345,7 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti if (maxFragments < 0) { maxFragments = -maxFragments; - //return R_OldMarkFragments( numPoints, points, projection, maxPoints, pointBuffer, maxFragments, fragmentBuffer ); - oldMapping = qtrue; + oldMapping = qtrue; } VectorClear(center); @@ -593,7 +354,7 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti VectorAdd(points[i], center, center); } VectorScale(center, 1.0 / numPoints, center); - // + radius = VectorNormalize2(projection, projectionDir) / 2.0; bestdist = 0; VectorNegate(projectionDir, bestnormal); @@ -611,10 +372,12 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti AddPointToBounds(temp, mins, maxs); } - if (numPoints > MAX_VERTS_ON_POLY) - { - numPoints = MAX_VERTS_ON_POLY; - } + // numPoints has static value of 4 atm + //if (numPoints > MAX_VERTS_ON_POLY) + //{ + // numPoints = MAX_VERTS_ON_POLY; + //} + // create the bounding planes for the to be projected polygon for (i = 0 ; i < numPoints ; i++) { @@ -899,7 +662,7 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti continue; } - // Arnout: projection on models (mainly for terrain though) + // projection on models (mainly for terrain though) else if (*surfaces[i] == SF_TRIANGLES) { // duplicated so we don't mess with the original clips for the curved surfaces diff --git a/src/rendererGLES/tr_marks.c b/src/rendererGLES/tr_marks.c index 37b8aaa6c..ffad002ff 100644 --- a/src/rendererGLES/tr_marks.c +++ b/src/rendererGLES/tr_marks.c @@ -305,245 +305,6 @@ void R_AddMarkFragments(int numClipPoints, vec3_t clipPoints[2][MAX_VERTS_ON_POL (*returnedFragments)++; } -/* -================= -R_OldMarkFragments -================= -*/ -int R_OldMarkFragments(int numPoints, const vec3_t *points, const vec3_t projection, - int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer) -{ - int numsurfaces, numPlanes; - int i, j, k, m, n; - surfaceType_t *surfaces[64]; - vec3_t mins, maxs; - int returnedFragments; - int returnedPoints; - vec3_t normals[MAX_VERTS_ON_POLY + 2]; - float dists[MAX_VERTS_ON_POLY + 2]; - vec3_t clipPoints[2][MAX_VERTS_ON_POLY]; - int numClipPoints; - float *v; - srfSurfaceFace_t *surf; - srfGridMesh_t *cv; - drawVert_t *dv; - vec3_t normal; - vec3_t projectionDir; - vec3_t v1, v2; - int *indexes; - - if (numPoints <= 0) - { - return 0; - } - - //increment view count for double check prevention - tr.viewCount++; - - // - VectorNormalize2(projection, projectionDir); - // find all the brushes that are to be considered - ClearBounds(mins, maxs); - for (i = 0 ; i < numPoints ; i++) - { - vec3_t temp; - - AddPointToBounds(points[i], mins, maxs); - VectorAdd(points[i], projection, temp); - AddPointToBounds(temp, mins, maxs); - // make sure we get all the leafs (also the one(s) in front of the hit surface) - VectorMA(points[i], -20, projectionDir, temp); - AddPointToBounds(temp, mins, maxs); - } - - if (numPoints > MAX_VERTS_ON_POLY) - { - numPoints = MAX_VERTS_ON_POLY; - } - // create the bounding planes for the to be projected polygon - for (i = 0 ; i < numPoints ; i++) - { - VectorSubtract(points[(i + 1) % numPoints], points[i], v1); - VectorAdd(points[i], projection, v2); - VectorSubtract(points[i], v2, v2); - CrossProduct(v1, v2, normals[i]); - VectorNormalizeFast(normals[i]); - dists[i] = DotProduct(normals[i], points[i]); - } - // add near and far clipping planes for projection - VectorCopy(projectionDir, normals[numPoints]); - dists[numPoints] = DotProduct(normals[numPoints], points[0]) - 32; - VectorCopy(projectionDir, normals[numPoints + 1]); - VectorInverse(normals[numPoints + 1]); - dists[numPoints + 1] = DotProduct(normals[numPoints + 1], points[0]) - 20; - numPlanes = numPoints + 2; - - numsurfaces = 0; - R_BoxSurfaces_r(tr.world->nodes, mins, maxs, surfaces, 64, &numsurfaces, projectionDir); - //assert(numsurfaces <= 64); - //assert(numsurfaces != 64); - - returnedPoints = 0; - returnedFragments = 0; - - for (i = 0 ; i < numsurfaces ; i++) - { - if (*surfaces[i] == SF_GRID) - { - cv = (srfGridMesh_t *) surfaces[i]; - for (m = 0 ; m < cv->height - 1 ; m++) - { - for (n = 0 ; n < cv->width - 1 ; n++) - { - // We triangulate the grid and chop all triangles within - // the bounding planes of the to be projected polygon. - // LOD is not taken into account, not such a big deal though. - // - // It's probably much nicer to chop the grid itself and deal - // with this grid as a normal SF_GRID surface so LOD will - // be applied. However the LOD of that chopped grid must - // be synced with the LOD of the original curve. - // One way to do this; the chopped grid shares vertices with - // the original curve. When LOD is applied to the original - // curve the unused vertices are flagged. Now the chopped curve - // should skip the flagged vertices. This still leaves the - // problems with the vertices at the chopped grid edges. - // - // To avoid issues when LOD applied to "hollow curves" (like - // the ones around many jump pads) we now just add a 2 unit - // offset to the triangle vertices. - // The offset is added in the vertex normal vector direction - // so all triangles will still fit together. - // The 2 unit offset should avoid pretty much all LOD problems. - - numClipPoints = 3; - - dv = cv->verts + m * cv->width + n; - - VectorCopy(dv[0].xyz, clipPoints[0][0]); - VectorMA(clipPoints[0][0], MARKER_OFFSET, dv[0].normal, clipPoints[0][0]); - VectorCopy(dv[cv->width].xyz, clipPoints[0][1]); - VectorMA(clipPoints[0][1], MARKER_OFFSET, dv[cv->width].normal, clipPoints[0][1]); - VectorCopy(dv[1].xyz, clipPoints[0][2]); - VectorMA(clipPoints[0][2], MARKER_OFFSET, dv[1].normal, clipPoints[0][2]); - // check the normal of this triangle - VectorSubtract(clipPoints[0][0], clipPoints[0][1], v1); - VectorSubtract(clipPoints[0][2], clipPoints[0][1], v2); - CrossProduct(v1, v2, normal); - VectorNormalizeFast(normal); - if (DotProduct(normal, projectionDir) < -0.1) - { - // add the fragments of this triangle - R_AddMarkFragments(numClipPoints, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - - VectorCopy(dv[1].xyz, clipPoints[0][0]); - VectorMA(clipPoints[0][0], MARKER_OFFSET, dv[1].normal, clipPoints[0][0]); - VectorCopy(dv[cv->width].xyz, clipPoints[0][1]); - VectorMA(clipPoints[0][1], MARKER_OFFSET, dv[cv->width].normal, clipPoints[0][1]); - VectorCopy(dv[cv->width + 1].xyz, clipPoints[0][2]); - VectorMA(clipPoints[0][2], MARKER_OFFSET, dv[cv->width + 1].normal, clipPoints[0][2]); - // check the normal of this triangle - VectorSubtract(clipPoints[0][0], clipPoints[0][1], v1); - VectorSubtract(clipPoints[0][2], clipPoints[0][1], v2); - CrossProduct(v1, v2, normal); - VectorNormalizeFast(normal); - if (DotProduct(normal, projectionDir) < -0.05) - { - // add the fragments of this triangle - R_AddMarkFragments(numClipPoints, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - } - } - } - else if (*surfaces[i] == SF_FACE) - { - surf = ( srfSurfaceFace_t * ) surfaces[i]; - // check the normal of this face - if (DotProduct(surf->plane.normal, projectionDir) > -0.5) - { - continue; - } - - indexes = ( int * )((byte *)surf + surf->ofsIndices); - for (k = 0 ; k < surf->numIndices ; k += 3) - { - for (j = 0 ; j < 3 ; j++) - { - v = surf->points[0] + VERTEXSIZE * indexes[k + j]; - VectorMA(v, MARKER_OFFSET, surf->plane.normal, clipPoints[0][j]); - } - // add the fragments of this face - R_AddMarkFragments(3, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - continue; - } - // Arnout: projection on models (mainly for terrain though) - else if (*surfaces[i] == SF_TRIANGLES) - { - srfTriangles_t *cts; - cts = ( srfTriangles_t * ) surfaces[i]; - - indexes = cts->indexes; - for (k = 0 ; k < cts->numIndexes ; k += 3) - { - for (j = 0 ; j < 3 ; j++) - { - v = cts->verts[indexes[k + j]].xyz; - VectorMA(v, MARKER_OFFSET, cts->verts[indexes[k + j]].normal, clipPoints[0][j]); - } - // add the fragments of this face - R_AddMarkFragments(3, clipPoints, - numPlanes, normals, dists, - maxPoints, pointBuffer, - maxFragments, fragmentBuffer, - &returnedPoints, &returnedFragments, mins, maxs); - - if (returnedFragments == maxFragments) - { - return returnedFragments; // not enough space for more fragments - } - } - continue; - } - else - { - // ignore all other world surfaces - // might be cool to also project polygons on a triangle soup - // however this will probably create huge amounts of extra polys - // even more than the projection onto curves - continue; - } - } - return returnedFragments; -} - /* ================= R_MarkFragments @@ -585,8 +346,7 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti if (maxFragments < 0) { maxFragments = -maxFragments; - //return R_OldMarkFragments( numPoints, points, projection, maxPoints, pointBuffer, maxFragments, fragmentBuffer ); - oldMapping = qtrue; + oldMapping = qtrue; } VectorClear(center); @@ -595,7 +355,7 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti VectorAdd(points[i], center, center); } VectorScale(center, 1.0 / numPoints, center); - // + radius = VectorNormalize2(projection, projectionDir) / 2.0; bestdist = 0; VectorNegate(projectionDir, bestnormal); @@ -613,10 +373,12 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti AddPointToBounds(temp, mins, maxs); } - if (numPoints > MAX_VERTS_ON_POLY) - { - numPoints = MAX_VERTS_ON_POLY; - } + // numPoints has static value of 4 atm + //if (numPoints > MAX_VERTS_ON_POLY) + //{ + // numPoints = MAX_VERTS_ON_POLY; + //} + // create the bounding planes for the to be projected polygon for (i = 0 ; i < numPoints ; i++) { @@ -834,7 +596,6 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti } numPlanes = numPoints; - indexes = ( int * )((byte *)surf + surf->ofsIndices); for (k = 0 ; k < surf->numIndices ; k += 3) { @@ -901,7 +662,7 @@ int R_MarkFragments(int orientation, const vec3_t *points, const vec3_t projecti continue; } - // Arnout: projection on models (mainly for terrain though) + // projection on models (mainly for terrain though) else if (*surfaces[i] == SF_TRIANGLES) { // duplicated so we don't mess with the original clips for the curved surfaces