Skip to content

Commit

Permalink
Refactor: Defer calculation of surface tangents until after BSP build
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 31, 2012
1 parent 22fbfbb commit 2e2d274
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
21 changes: 0 additions & 21 deletions doomsday/engine/portable/src/edit_bsp.c
Expand Up @@ -188,27 +188,6 @@ static void buildHEdgesFromBSPHEdges(GameMap* dest, BinaryTree* rootNode)

if(hedge->length == 0)
hedge->length = 0.01f; // Hmm...

// Calculate the tangent space surface vectors.
if(hedge->lineDef && HEDGE_SIDEDEF(hedge))
{
SideDef* side = HEDGE_SIDEDEF(hedge);
Surface* surface = &side->SW_topsurface;

surface->normal[VY] = (hedge->HE_v1pos[VX] - hedge->HE_v2pos[VX]) / hedge->length;
surface->normal[VX] = (hedge->HE_v2pos[VY] - hedge->HE_v1pos[VY]) / hedge->length;
surface->normal[VZ] = 0;
V3f_BuildTangents(surface->tangent, surface->bitangent, surface->normal);

// All surfaces of a sidedef have the same tangent space vectors.
memcpy(side->SW_middletangent, surface->tangent, sizeof(surface->tangent));
memcpy(side->SW_middlebitangent, surface->bitangent, sizeof(surface->bitangent));
memcpy(side->SW_middlenormal, surface->normal, sizeof(surface->normal));

memcpy(side->SW_bottomtangent, surface->tangent, sizeof(surface->tangent));
memcpy(side->SW_bottombitangent, surface->bitangent, sizeof(surface->bitangent));
memcpy(side->SW_bottomnormal, surface->normal, sizeof(surface->normal));
}
}

// Free temporary storage
Expand Down
12 changes: 12 additions & 0 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -772,6 +772,17 @@ static void finishSectors(GameMap* map)
}
}

static void finishSideDefs(GameMap* map)
{
uint i;
// Calculate the tangent space surface vectors.
for(i = 0; i < map->numSideDefs; ++i)
{
SideDef* side = &map->sideDefs[i];
SideDef_UpdateSurfaceTangents(side);
}
}

static void finishLineDefs(GameMap* map)
{
uint i;
Expand Down Expand Up @@ -1764,6 +1775,7 @@ boolean MPE_End(void)
}

buildSectorLineLists(gamemap);
finishSideDefs(gamemap);
finishLineDefs(gamemap);
finishSectors(gamemap);
updateMapBounds(gamemap);
Expand Down

0 comments on commit 2e2d274

Please sign in to comment.