From be3c84ec98379100ae5e967b4d1eebd6df5e1bd2 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 27 Nov 2016 00:29:13 -0700 Subject: [PATCH] light: add a EdgePlanes_PointInside() function to bsputils.{hh,cc} --- common/bsputils.cc | 12 ++++++++++++ include/common/bsputils.hh | 1 + light/trace.cc | 13 +++---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/common/bsputils.cc b/common/bsputils.cc index fd336706..c80c6012 100644 --- a/common/bsputils.cc +++ b/common/bsputils.cc @@ -217,3 +217,15 @@ Face_MakeInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face, pla dest->dist = DotProduct(dest->normal, v0); } } + +bool +EdgePlanes_PointInside(const bsp2_dface_t *face, const plane_t *edgeplanes, const vec3_t point) +{ + for (int i=0; inumedges; i++) { + vec_t planedist = DotProduct(point, edgeplanes[i].normal) - edgeplanes[i].dist; + if (planedist < 0) { + return false; + } + } + return true; +} diff --git a/include/common/bsputils.hh b/include/common/bsputils.hh index 6d12ee47..db9fd5fb 100644 --- a/include/common/bsputils.hh +++ b/include/common/bsputils.hh @@ -37,5 +37,6 @@ const dmodel_t *BSP_DModelForModelString(const bsp2_t *bsp, const std::string &s vec_t Plane_Dist(const vec3_t point, const dplane_t *plane); bool Light_PointInSolid(const bsp2_t *bsp, const vec3_t point ); void Face_MakeInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face, plane_t *out); +bool EdgePlanes_PointInside(const bsp2_dface_t *face, const plane_t *edgeplanes, const vec3_t point); #endif /* __COMMON_BSPUTILS_HH__ */ diff --git a/light/trace.cc b/light/trace.cc index a8dba2c8..00ffa5fb 100644 --- a/light/trace.cc +++ b/light/trace.cc @@ -95,6 +95,7 @@ typedef struct faceinfo_s { plane_t plane; const char *texturename; + const bsp2_dface_t *face; } faceinfo_t; static tnode_t *tnodes; @@ -187,6 +188,7 @@ static inline bool SphereCullPoint(const faceinfo_t *info, const vec3_t point) static void MakeFaceInfo(const bsp2_t *bsp, const bsp2_dface_t *face, faceinfo_t *info) { + info->face = face; info->numedges = face->numedges; info->edgeplanes = (plane_t *) calloc(face->numedges, sizeof(plane_t)); @@ -337,16 +339,7 @@ SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point) static inline qboolean TestHitFace(const faceinfo_t *fi, const vec3_t point) { - for (int i=0; inumedges; i++) - { - /* faces toward the center of the face */ - const plane_t *edgeplane = &fi->edgeplanes[i]; - - vec_t dist = DotProduct(point, edgeplane->normal) - edgeplane->dist; - if (dist < 0) - return false; - } - return true; + return EdgePlanes_PointInside(fi->face, fi->edgeplanes, point); } static inline bsp2_dface_t *