Skip to content

Commit

Permalink
Update Bsp.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Jan 28, 2024
1 parent 7cfc698 commit 52c3020
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7078,10 +7078,12 @@ int Bsp::merge_two_models(int src_model, int dst_model)
memcpy(newLump, &all_faces[0], sizeof(BSPFACE32) * all_faces.size());
replace_lump(LUMP_FACES, newLump, sizeof(BSPFACE32) * all_faces.size());

vec3 amin = models[dst_model].nMins;
vec3 amax = models[dst_model].nMaxs;
vec3 bmin = models[src_model].nMins;
vec3 bmax = models[src_model].nMaxs;
vec3 amin = models[dst_model].nMins + models[dst_model].vOrigin;
vec3 amax = models[dst_model].nMaxs + models[dst_model].vOrigin;
vec3 bmin = models[src_model].nMins + models[src_model].vOrigin;
vec3 bmax = models[src_model].nMaxs + models[src_model].vOrigin;

BSPPLANE separate_plane = getSeparatePlane(bmin, bmax,amin, amax);

std::vector<vec3> veclist;
veclist.push_back(amin);
Expand All @@ -7093,7 +7095,6 @@ int Bsp::merge_two_models(int src_model, int dst_model)

getBoundingBox(veclist, new_min, new_max);

BSPPLANE separate_plane = getSeparatePlane(amin, amax, bmin, bmax);

int separationPlaneIdx = planeCount;

Expand All @@ -7110,8 +7111,8 @@ int Bsp::merge_two_models(int src_model, int dst_model)
{
BSPNODE32 headNode = {
separationPlaneIdx, // plane idx
{ models[src_model].iHeadnodes[0],
models[dst_model].iHeadnodes[0] }, // child nodes
{ models[dst_model].iHeadnodes[0],
models[src_model].iHeadnodes[0] }, // child nodes
{ new_min.x, new_min.y, new_min.z }, // mins
{ new_max.x, new_max.y, new_max.z }, // maxs
0, // first face
Expand Down Expand Up @@ -7144,11 +7145,20 @@ int Bsp::merge_two_models(int src_model, int dst_model)
newHeadNodes[i] = {
separationPlaneIdx, // plane idx
{ // child nodes
models[src_model].iHeadnodes[i + 1],
models[dst_model].iHeadnodes[i + 1]
models[dst_model].iHeadnodes[i + 1],
models[src_model].iHeadnodes[i + 1]
},
};

if (models[dst_model].iHeadnodes[i + 1] < 0)
{
newHeadNodes[i].iChildren[0] = CONTENTS_EMPTY;
}
if (models[src_model].iHeadnodes[i + 1] < 0)
{
newHeadNodes[i].iChildren[1] = CONTENTS_EMPTY;
}

if (swapNodeChildren)
{
int temp = newHeadNodes[i].iChildren[0];
Expand Down

0 comments on commit 52c3020

Please sign in to comment.