light: FacesOverlappingEdge: return the edge that overlaps
This commit is contained in:
parent
8ce7a682b1
commit
92bacbe7e1
|
|
@ -35,7 +35,19 @@
|
|||
|
||||
#include <common/qvec.hh>
|
||||
|
||||
std::vector<const bsp2_dface_t *> FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const dmodel_t *model);
|
||||
class neighbour_t {
|
||||
public:
|
||||
const bsp2_dface_t *face;
|
||||
qvec3f p0, p1;
|
||||
|
||||
neighbour_t(const bsp2_dface_t *f, const qvec3f p0in, const qvec3f p1in)
|
||||
: face(f),
|
||||
p0(p0in),
|
||||
p1(p1in) {
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<neighbour_t> FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const dmodel_t *model);
|
||||
|
||||
void CalcualateVertexNormals(const mbsp_t *bsp);
|
||||
const qvec3f GetSurfaceVertexNormal(const mbsp_t *bsp, const bsp2_dface_t *f, const int vertindex);
|
||||
|
|
|
|||
|
|
@ -409,7 +409,6 @@ PositionSamplePointOnFace(const mbsp_t *bsp,
|
|||
const qvec3f &point,
|
||||
const qvec3f &modelOffset);
|
||||
|
||||
|
||||
std::vector<const bsp2_dface_t *> NeighbouringFaces_old(const mbsp_t *bsp, const bsp2_dface_t *face)
|
||||
{
|
||||
std::vector<const bsp2_dface_t *> result;
|
||||
|
|
@ -423,26 +422,25 @@ std::vector<const bsp2_dface_t *> NeighbouringFaces_old(const mbsp_t *bsp, const
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<const bsp2_dface_t *> NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face)
|
||||
std::vector<neighbour_t> NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face)
|
||||
{
|
||||
std::set<const bsp2_dface_t *> resultset;
|
||||
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<const bsp2_dface_t *> tmp = FacesOverlappingEdge(p0, p1, bsp, &bsp->dmodels[0]);
|
||||
for (const bsp2_dface_t *f : tmp) {
|
||||
if (f != face) {
|
||||
resultset.insert(f);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const bsp2_dface_t *> result;
|
||||
for (const bsp2_dface_t *f : resultset) {
|
||||
result.push_back(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -2062,10 +2060,10 @@ LightFace_DebugNeighbours(lightsurf_t *lightsurf, lightmapdict_t *lightmaps)
|
|||
|
||||
const int fnum = Face_GetNum(lightsurf->bsp, lightsurf->face);
|
||||
|
||||
std::vector<const bsp2_dface_t *> neighbours = NeighbouringFaces_new(lightsurf->bsp, BSP_GetFace(lightsurf->bsp, dump_facenum));
|
||||
std::vector<neighbour_t> neighbours = NeighbouringFaces_new(lightsurf->bsp, BSP_GetFace(lightsurf->bsp, dump_facenum));
|
||||
bool found = false;
|
||||
for (auto &f : neighbours) {
|
||||
if (f == lightsurf->face)
|
||||
if (f.face == lightsurf->face)
|
||||
found = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
static bool
|
||||
static neighbour_t
|
||||
FaceOverlapsEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const bsp2_dface_t *f)
|
||||
{
|
||||
for (int edgeindex = 0; edgeindex < f->numedges; edgeindex++) {
|
||||
|
|
@ -52,14 +52,14 @@ FaceOverlapsEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const bsp2
|
|||
const qvec3f v0point = Vertex_GetPos_E(bsp, v0);
|
||||
const qvec3f v1point = Vertex_GetPos_E(bsp, v1);
|
||||
if (LinesOverlap(vec3_t_to_glm(p0), vec3_t_to_glm(p1), v0point, v1point)) {
|
||||
return true;
|
||||
return neighbour_t{f, v0point, v1point};
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return neighbour_t{nullptr, qvec3f{}, qvec3f{}};
|
||||
}
|
||||
|
||||
static void
|
||||
FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int nodenum, vector<const bsp2_dface_t *> *result)
|
||||
FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int nodenum, vector<neighbour_t> *result)
|
||||
{
|
||||
if (nodenum < 0) {
|
||||
// we don't do anything for leafs.
|
||||
|
|
@ -67,7 +67,6 @@ FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
const bsp2_dnode_t *node = BSP_GetNode(bsp, nodenum);
|
||||
const dplane_t *plane = BSP_GetPlane(bsp, node->planenum);
|
||||
const vec_t p0dist = Plane_Dist(p0, plane);
|
||||
|
|
@ -77,8 +76,9 @@ FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int
|
|||
// check all faces on this node.
|
||||
for (int i=0; i<node->numfaces; i++) {
|
||||
const bsp2_dface_t *face = BSP_GetFace(bsp, node->firstface + i);
|
||||
if (FaceOverlapsEdge(p0, p1, bsp, face)) {
|
||||
result->push_back(face);
|
||||
const auto neighbour = FaceOverlapsEdge(p0, p1, bsp, face);
|
||||
if (neighbour.face != nullptr) {
|
||||
result->push_back(neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -101,10 +101,10 @@ FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int
|
|||
* Returns faces which have an edge that overlaps the given p0-p1 edge.
|
||||
* Uses hull 0.
|
||||
*/
|
||||
vector<const bsp2_dface_t *>
|
||||
vector<neighbour_t>
|
||||
FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const dmodel_t *model)
|
||||
{
|
||||
vector<const bsp2_dface_t *> result;
|
||||
vector<neighbour_t> result;
|
||||
FacesOverlappingEdge_r(p0, p1, bsp, model->headnode[0], &result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue