Use FVector4 for plane in struct Surface

This commit is contained in:
RaveYard 2023-08-31 22:34:36 +02:00 committed by Christoph Oelckers
parent 9635a9f4fb
commit fc2704b902
2 changed files with 25 additions and 24 deletions

View file

@ -305,14 +305,15 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub,
Surface surf; Surface surf;
surf.bSky = IsSkySector(sector, sector_t::floor); surf.bSky = IsSkySector(sector, sector_t::floor);
secplane_t plane;
if (!is3DFloor) if (!is3DFloor)
{ {
surf.plane = sector->floorplane; plane = sector->floorplane;
} }
else else
{ {
surf.plane = sector->ceilingplane; plane = sector->ceilingplane;
surf.plane.FlipVert(); plane.FlipVert();
} }
surf.numVerts = sub->numlines; surf.numVerts = sub->numlines;
@ -327,12 +328,13 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub,
verts[j].X = v1.X; verts[j].X = v1.X;
verts[j].Y = v1.Y; verts[j].Y = v1.Y;
verts[j].Z = (float)surf.plane.ZatPoint(verts[j]); verts[j].Z = (float)plane.ZatPoint(verts[j]);
} }
surf.type = ST_FLOOR; surf.type = ST_FLOOR;
surf.typeIndex = typeIndex; surf.typeIndex = typeIndex;
surf.controlSector = is3DFloor ? sector : nullptr; surf.controlSector = is3DFloor ? sector : nullptr;
surf.plane = FVector4(plane.Normal().X, plane.Normal().Y, plane.Normal().Z, plane.D);
Surfaces.Push(surf); Surfaces.Push(surf);
} }
@ -342,14 +344,15 @@ void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub
Surface surf; Surface surf;
surf.bSky = IsSkySector(sector, sector_t::ceiling); surf.bSky = IsSkySector(sector, sector_t::ceiling);
secplane_t plane;
if (!is3DFloor) if (!is3DFloor)
{ {
surf.plane = sector->ceilingplane; plane = sector->ceilingplane;
} }
else else
{ {
surf.plane = sector->floorplane; plane = sector->floorplane;
surf.plane.FlipVert(); plane.FlipVert();
} }
surf.numVerts = sub->numlines; surf.numVerts = sub->numlines;
@ -364,12 +367,13 @@ void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub
verts[j].X = v1.X; verts[j].X = v1.X;
verts[j].Y = v1.Y; verts[j].Y = v1.Y;
verts[j].Z = (float)surf.plane.ZatPoint(verts[j]); verts[j].Z = (float)plane.ZatPoint(verts[j]);
} }
surf.type = ST_CEILING; surf.type = ST_CEILING;
surf.typeIndex = typeIndex; surf.typeIndex = typeIndex;
surf.controlSector = is3DFloor ? sector : nullptr; surf.controlSector = is3DFloor ? sector : nullptr;
surf.plane = FVector4(plane.Normal().X, plane.Normal().Y, plane.Normal().Z, plane.D);
Surfaces.Push(surf); Surfaces.Push(surf);
} }
@ -531,7 +535,7 @@ int DoomLevelMesh::SetupLightmapUvs(int lightmapSize)
surfaces.push_back(std::move(hwSurface)); surfaces.push_back(std::move(hwSurface));
SurfaceInfo info; SurfaceInfo info;
info.Normal = FVector3(surface.plane.Normal()); info.Normal = surface.plane.XYZ();
info.PortalIndex = 0; info.PortalIndex = 0;
info.SamplingDistance = surface.sampleDimension; info.SamplingDistance = surface.sampleDimension;
info.Sky = surface.bSky; info.Sky = surface.bSky;
@ -662,11 +666,11 @@ BBox DoomLevelMesh::GetBoundsFromSurface(const Surface& surface) const
return bounds; return bounds;
} }
DoomLevelMesh::PlaneAxis DoomLevelMesh::BestAxis(const secplane_t& p) DoomLevelMesh::PlaneAxis DoomLevelMesh::BestAxis(const FVector4& p)
{ {
float na = fabs(float(p.Normal().X)); float na = fabs(float(p.X));
float nb = fabs(float(p.Normal().Y)); float nb = fabs(float(p.Y));
float nc = fabs(float(p.Normal().Z)); float nc = fabs(float(p.Z));
// figure out what axis the plane lies on // figure out what axis the plane lies on
if (na >= nb && na >= nc) if (na >= nb && na >= nc)
@ -683,7 +687,6 @@ DoomLevelMesh::PlaneAxis DoomLevelMesh::BestAxis(const secplane_t& p)
void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTextureHeight, Surface& surface) void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTextureHeight, Surface& surface)
{ {
secplane_t* plane;
BBox bounds; BBox bounds;
FVector3 roundedSize; FVector3 roundedSize;
FVector3 tOrigin; FVector3 tOrigin;
@ -691,7 +694,7 @@ void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTex
int height; int height;
float d; float d;
plane = &surface.plane; const FVector4& plane = surface.plane;
bounds = GetBoundsFromSurface(surface); bounds = GetBoundsFromSurface(surface);
surface.bounds = bounds; surface.bounds = bounds;
@ -712,7 +715,7 @@ void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTex
FVector3 tCoords[2] = { FVector3(0.0f, 0.0f, 0.0f), FVector3(0.0f, 0.0f, 0.0f) }; FVector3 tCoords[2] = { FVector3(0.0f, 0.0f, 0.0f), FVector3(0.0f, 0.0f, 0.0f) };
PlaneAxis axis = BestAxis(*plane); PlaneAxis axis = BestAxis(plane);
switch (axis) switch (axis)
{ {
@ -770,13 +773,13 @@ void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTex
tOrigin = bounds.min; tOrigin = bounds.min;
// project tOrigin and tCoords so they lie on the plane // project tOrigin and tCoords so they lie on the plane
d = float(((bounds.min | FVector3(plane->Normal())) - plane->D) / plane->Normal()[axis]); //d = (plane->PointToDist(bounds.min)) / plane->Normal()[axis]; d = ((bounds.min | FVector3(plane.X, plane.Y, plane.Z)) - plane.W) / plane[axis]; //d = (plane->PointToDist(bounds.min)) / plane->Normal()[axis];
tOrigin[axis] -= d; tOrigin[axis] -= d;
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
tCoords[i].MakeUnit(); tCoords[i].MakeUnit();
d = (tCoords[i] | FVector3(plane->Normal())) / plane->Normal()[axis]; //d = dot(tCoords[i], plane->Normal()) / plane->Normal()[axis]; d = (tCoords[i] | FVector3(plane.X, plane.Y, plane.Z)) / plane[axis]; //d = dot(tCoords[i], plane->Normal()) / plane->Normal()[axis];
tCoords[i][axis] -= d; tCoords[i][axis] -= d;
} }

View file

@ -19,7 +19,7 @@ struct Surface
int numVerts; int numVerts;
unsigned int startVertIndex; unsigned int startVertIndex;
unsigned int startUvIndex; unsigned int startUvIndex;
secplane_t plane; FVector4 plane;
sector_t *controlSector; sector_t *controlSector;
bool bSky; bool bSky;
@ -86,13 +86,11 @@ private:
static bool IsSkySector(sector_t* sector, int plane); static bool IsSkySector(sector_t* sector, int plane);
static bool IsControlSector(sector_t* sector); static bool IsControlSector(sector_t* sector);
static secplane_t ToPlane(const FVector3& pt1, const FVector3& pt2, const FVector3& pt3) static FVector4 ToPlane(const FVector3& pt1, const FVector3& pt2, const FVector3& pt3)
{ {
FVector3 n = ((pt2 - pt1) ^ (pt3 - pt2)).Unit(); FVector3 n = ((pt2 - pt1) ^ (pt3 - pt2)).Unit();
float d = pt1 | n; float d = pt1 | n;
secplane_t p; return FVector4(n.X, n.Y, n.Z, d);
p.set(n.X, n.Y, n.Z, d);
return p;
} }
static FVector2 ToFVector2(const DVector2& v) { return FVector2((float)v.X, (float)v.Y); } static FVector2 ToFVector2(const DVector2& v) { return FVector2((float)v.X, (float)v.Y); }
@ -110,7 +108,7 @@ private:
AXIS_XY AXIS_XY
}; };
static PlaneAxis BestAxis(const secplane_t& p); static PlaneAxis BestAxis(const FVector4& p);
BBox GetBoundsFromSurface(const Surface& surface) const; BBox GetBoundsFromSurface(const Surface& surface) const;
inline int AllocUvs(int amount) { return LightmapUvs.Reserve(amount * 2); } inline int AllocUvs(int amount) { return LightmapUvs.Reserve(amount * 2); }