light: move NeighbouringFaces_new to phong.cc

This commit is contained in:
Eric Wasylishen 2017-12-06 00:23:21 -07:00
parent 75bc7b86d0
commit 71d9f8ce8a
3 changed files with 26 additions and 23 deletions

View File

@ -60,6 +60,7 @@ const bsp2_dface_t *Face_EdgeIndexSmoothed(const mbsp_t *bsp, const bsp2_dface_t
/// a directed edge can be used by more than one face, e.g. two cube touching just along an edge
using edgeToFaceMap_t = std::map<std::pair<int,int>, std::vector<const bsp2_dface_t *>>;
std::vector<neighbour_t> NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face);
std::vector<const bsp2_dface_t *> FacesUsingVert(int vertnum);
const edgeToFaceMap_t &GetEdgeToFaceMap();
@ -70,6 +71,7 @@ private:
qvec4f m_plane;
std::vector<qvec4f> m_edgePlanes;
std::vector<qvec3f> m_pointsShrunkBy1Unit;
std::vector<neighbour_t> m_neighbours;
public:
face_cache_t(const mbsp_t *bsp, const bsp2_dface_t *face, const std::vector<qvec3f> &normals) :
@ -77,7 +79,8 @@ public:
m_normals(normals),
m_plane(Face_Plane_E(bsp, face).vec4()),
m_edgePlanes(GLM_MakeInwardFacingEdgePlanes(m_points)),
m_pointsShrunkBy1Unit(GLM_ShrinkPoly(m_points, 1.0f))
m_pointsShrunkBy1Unit(GLM_ShrinkPoly(m_points, 1.0f)),
m_neighbours(NeighbouringFaces_new(bsp, face))
{ }
const std::vector<qvec3f> &points() const {

View File

@ -422,28 +422,6 @@ std::vector<const bsp2_dface_t *> NeighbouringFaces_old(const mbsp_t *bsp, const
return result;
}
std::vector<neighbour_t> NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face)
{
std::vector<neighbour_t> result;
std::set<const bsp2_dface_t *> used_faces;
for (int i=0; i<face->numedges; i++) {
vec3_t p0, p1;
Face_PointAtIndex(bsp, face, i, p0);
Face_PointAtIndex(bsp, face, (i + 1) % face->numedges, p1);
const std::vector<neighbour_t> tmp = FacesOverlappingEdge(p0, p1, bsp, &bsp->dmodels[0]);
for (const auto &neighbour : tmp) {
if (neighbour.face != face && used_faces.find(neighbour.face) == used_faces.end()) {
used_faces.insert(neighbour.face);
result.push_back(neighbour);
}
}
}
return result;
}
position_t CalcPointNormal(const mbsp_t *bsp, const bsp2_dface_t *face, const qvec3f &origPoint, bool phongShaded, float face_lmscale, int recursiondepth,
const qvec3f &modelOffset)
{

View File

@ -109,6 +109,28 @@ FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const
return result;
}
std::vector<neighbour_t> NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face)
{
std::vector<neighbour_t> result;
std::set<const bsp2_dface_t *> used_faces;
for (int i=0; i<face->numedges; i++) {
vec3_t p0, p1;
Face_PointAtIndex(bsp, face, i, p0);
Face_PointAtIndex(bsp, face, (i + 1) % face->numedges, p1);
const std::vector<neighbour_t> tmp = FacesOverlappingEdge(p0, p1, bsp, &bsp->dmodels[0]);
for (const auto &neighbour : tmp) {
if (neighbour.face != face && used_faces.find(neighbour.face) == used_faces.end()) {
used_faces.insert(neighbour.face);
result.push_back(neighbour);
}
}
}
return result;
}
/* return 0 if either vector is zero-length */
static float
AngleBetweenVectors(const qvec3f &d1, const qvec3f &d2)