mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-10 14:51:40 +00:00
- add support for slopes
This commit is contained in:
parent
ca2f4df032
commit
2bdf48bbcc
5 changed files with 122 additions and 24 deletions
|
@ -105,6 +105,9 @@ struct IntSector
|
|||
// empty is enough
|
||||
MapSector data;
|
||||
|
||||
kexPlane ceilingplane;
|
||||
kexPlane floorplane;
|
||||
|
||||
TArray<UDMFKey> props;
|
||||
};
|
||||
|
||||
|
|
|
@ -259,6 +259,16 @@ void FProcessor::LoadSectors ()
|
|||
for (int i = 0; i < NumSectors; ++i)
|
||||
{
|
||||
Level.Sectors[i].data = Sectors[i];
|
||||
|
||||
Level.Sectors[i].ceilingplane.a = 0.0f;
|
||||
Level.Sectors[i].ceilingplane.b = 0.0f;
|
||||
Level.Sectors[i].ceilingplane.c = -1.0f;
|
||||
Level.Sectors[i].ceilingplane.d = -Level.Sectors[i].data.ceilingheight;
|
||||
|
||||
Level.Sectors[i].floorplane.a = 0.0f;
|
||||
Level.Sectors[i].floorplane.b = 0.0f;
|
||||
Level.Sectors[i].floorplane.c = 1.0f;
|
||||
Level.Sectors[i].floorplane.d = Level.Sectors[i].data.floorheight;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -330,6 +330,8 @@ void FProcessor::ParseSector(IntSector *sec)
|
|||
memset(&sec->data, 0, sizeof(sec->data));
|
||||
sec->data.lightlevel = 160;
|
||||
|
||||
bool ceilingplane = false, floorplane = false;
|
||||
|
||||
SC_MustGetStringName("{");
|
||||
while (!SC_CheckString("}"))
|
||||
{
|
||||
|
@ -364,11 +366,85 @@ void FProcessor::ParseSector(IntSector *sec)
|
|||
{
|
||||
sec->data.tag = CheckInt(key);
|
||||
}
|
||||
else if (stricmp(key, "ceilingplane_a") == 0)
|
||||
{
|
||||
ceilingplane = true;
|
||||
sec->ceilingplane.a = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "ceilingplane_b") == 0)
|
||||
{
|
||||
ceilingplane = true;
|
||||
sec->ceilingplane.b = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "ceilingplane_c") == 0)
|
||||
{
|
||||
ceilingplane = true;
|
||||
sec->ceilingplane.c = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "ceilingplane_d") == 0)
|
||||
{
|
||||
ceilingplane = true;
|
||||
sec->ceilingplane.d = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "floorplane_a") == 0)
|
||||
{
|
||||
floorplane = true;
|
||||
sec->floorplane.a = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "floorplane_b") == 0)
|
||||
{
|
||||
floorplane = true;
|
||||
sec->floorplane.b = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "floorplane_c") == 0)
|
||||
{
|
||||
floorplane = true;
|
||||
sec->floorplane.c = CheckFloat(key);
|
||||
}
|
||||
else if (stricmp(key, "floorplane_d") == 0)
|
||||
{
|
||||
floorplane = true;
|
||||
sec->floorplane.d = CheckFloat(key);
|
||||
}
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
sec->props.Push(k);
|
||||
}
|
||||
|
||||
if (!ceilingplane)
|
||||
{
|
||||
sec->ceilingplane.a = 0.0f;
|
||||
sec->ceilingplane.b = 0.0f;
|
||||
sec->ceilingplane.c = -1.0f;
|
||||
sec->ceilingplane.d = -sec->data.ceilingheight;
|
||||
}
|
||||
else
|
||||
{
|
||||
float scale = 1.0f / sec->ceilingplane.Normal().Length();
|
||||
sec->ceilingplane.a *= scale;
|
||||
sec->ceilingplane.b *= scale;
|
||||
sec->ceilingplane.c *= scale;
|
||||
sec->ceilingplane.d *= scale;
|
||||
sec->ceilingplane.d = -sec->ceilingplane.d;
|
||||
}
|
||||
|
||||
if (!floorplane)
|
||||
{
|
||||
sec->floorplane.a = 0.0f;
|
||||
sec->floorplane.b = 0.0f;
|
||||
sec->floorplane.c = 1.0f;
|
||||
sec->floorplane.d = sec->data.floorheight;
|
||||
}
|
||||
else
|
||||
{
|
||||
float scale = 1.0f / sec->floorplane.Normal().Length();
|
||||
sec->floorplane.a *= scale;
|
||||
sec->floorplane.b *= scale;
|
||||
sec->floorplane.c *= scale;
|
||||
sec->floorplane.d *= scale;
|
||||
sec->floorplane.d = -sec->floorplane.d;
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
|
|
@ -409,6 +409,8 @@ public:
|
|||
const planeAxis_t BestAxis() const;
|
||||
kexVec3 GetInclination();
|
||||
|
||||
float zAt(float x, float y) const { return (d - a * x - b * y) / c; }
|
||||
|
||||
kexPlane &operator|(const kexQuat &quat);
|
||||
kexPlane &operator|=(const kexQuat &quat);
|
||||
kexPlane &operator|(const kexMatrix &mtx);
|
||||
|
|
|
@ -40,8 +40,6 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
{
|
||||
IntSideDef *side;
|
||||
surface_t *surf;
|
||||
float top, bTop;
|
||||
float bottom, bBottom;
|
||||
IntSector *front;
|
||||
IntSector *back;
|
||||
|
||||
|
@ -54,24 +52,27 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
front = doomMap.GetFrontSector(seg);
|
||||
back = doomMap.GetBackSector(seg);
|
||||
|
||||
top = front->data.ceilingheight;
|
||||
bottom = front->data.floorheight;
|
||||
|
||||
FloatVertex v1 = doomMap.GetSegVertex(seg->v1);
|
||||
FloatVertex v2 = doomMap.GetSegVertex(seg->v2);
|
||||
float v1Top = front->ceilingplane.zAt(v1.x, v1.y);
|
||||
float v1Bottom = front->floorplane.zAt(v1.x, v1.y);
|
||||
float v2Top = front->ceilingplane.zAt(v2.x, v2.y);
|
||||
float v2Bottom = front->floorplane.zAt(v2.x, v2.y);
|
||||
|
||||
if(back)
|
||||
{
|
||||
bTop = back->data.ceilingheight;
|
||||
bBottom = back->data.floorheight;
|
||||
float v1TopBack = back->ceilingplane.zAt(v1.x, v1.y);
|
||||
float v1BottomBack = back->floorplane.zAt(v1.x, v1.y);
|
||||
float v2TopBack = back->ceilingplane.zAt(v2.x, v2.y);
|
||||
float v2BottomBack = back->floorplane.zAt(v2.x, v2.y);
|
||||
|
||||
if(bTop == top && bBottom == bottom)
|
||||
if (v1Top == v1TopBack && v1Bottom == v1BottomBack && v2Top == v2TopBack && v2Bottom == v2BottomBack)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// bottom seg
|
||||
if(bottom < bBottom)
|
||||
if(v1Bottom < v1BottomBack || v2Bottom < v2BottomBack)
|
||||
{
|
||||
if(side->bottomtexture[0] != '-')
|
||||
{
|
||||
|
@ -83,8 +84,10 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
surf->verts[0].y = surf->verts[2].y = v1.y;
|
||||
surf->verts[1].x = surf->verts[3].x = v2.x;
|
||||
surf->verts[1].y = surf->verts[3].y = v2.y;
|
||||
surf->verts[0].z = surf->verts[1].z = bottom;
|
||||
surf->verts[2].z = surf->verts[3].z = bBottom;
|
||||
surf->verts[0].z = v1Bottom;
|
||||
surf->verts[1].z = v2Bottom;
|
||||
surf->verts[2].z = v1BottomBack;
|
||||
surf->verts[3].z = v2BottomBack;
|
||||
|
||||
surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]);
|
||||
surf->plane.SetDistance(surf->verts[0]);
|
||||
|
@ -98,11 +101,12 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
surfaces.Push(surf);
|
||||
}
|
||||
|
||||
bottom = bBottom;
|
||||
v1Bottom = v1BottomBack;
|
||||
v2Bottom = v2BottomBack;
|
||||
}
|
||||
|
||||
// top seg
|
||||
if(top > bTop)
|
||||
if(v1Top > v1TopBack || v2Top > v2TopBack)
|
||||
{
|
||||
bool bSky = false;
|
||||
int frontidx = front - &doomMap.Sectors[0];
|
||||
|
@ -126,8 +130,10 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
surf->verts[0].y = surf->verts[2].y = v1.y;
|
||||
surf->verts[1].x = surf->verts[3].x = v2.x;
|
||||
surf->verts[1].y = surf->verts[3].y = v2.y;
|
||||
surf->verts[0].z = surf->verts[1].z = bTop;
|
||||
surf->verts[2].z = surf->verts[3].z = top;
|
||||
surf->verts[0].z = v1TopBack;
|
||||
surf->verts[1].z = v2TopBack;
|
||||
surf->verts[2].z = v1Top;
|
||||
surf->verts[3].z = v2Top;
|
||||
|
||||
surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]);
|
||||
surf->plane.SetDistance(surf->verts[0]);
|
||||
|
@ -142,7 +148,8 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
surfaces.Push(surf);
|
||||
}
|
||||
|
||||
top = bTop;
|
||||
v1Top = v1TopBack;
|
||||
v2Top = v2TopBack;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,8 +164,10 @@ static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
|
|||
surf->verts[0].y = surf->verts[2].y = v1.y;
|
||||
surf->verts[1].x = surf->verts[3].x = v2.x;
|
||||
surf->verts[1].y = surf->verts[3].y = v2.y;
|
||||
surf->verts[0].z = surf->verts[1].z = bottom;
|
||||
surf->verts[2].z = surf->verts[3].z = top;
|
||||
surf->verts[0].z = v1Bottom;
|
||||
surf->verts[1].z = v2Bottom;
|
||||
surf->verts[2].z = v1Top;
|
||||
surf->verts[3].z = v2Top;
|
||||
|
||||
surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]);
|
||||
surf->plane.SetDistance(surf->verts[0]);
|
||||
|
@ -224,11 +233,10 @@ static void Surface_AllocateFromLeaf(FLevel &doomMap)
|
|||
|
||||
surf->verts[j].x = leaf->vertex.x;
|
||||
surf->verts[j].y = leaf->vertex.y;
|
||||
surf->verts[j].z = sector->data.floorheight;
|
||||
surf->verts[j].z = sector->floorplane.zAt(surf->verts[j].x, surf->verts[j].y);
|
||||
}
|
||||
|
||||
surf->plane.SetNormal(kexVec3(0, 0, 1));
|
||||
surf->plane.SetDistance(surf->verts[0]);
|
||||
surf->plane = sector->floorplane;
|
||||
surf->type = ST_FLOOR;
|
||||
surf->typeIndex = i;
|
||||
|
||||
|
@ -254,11 +262,10 @@ static void Surface_AllocateFromLeaf(FLevel &doomMap)
|
|||
|
||||
surf->verts[j].x = leaf->vertex.x;
|
||||
surf->verts[j].y = leaf->vertex.y;
|
||||
surf->verts[j].z = sector->data.ceilingheight;
|
||||
surf->verts[j].z = sector->ceilingplane.zAt(surf->verts[j].x, surf->verts[j].y);
|
||||
}
|
||||
|
||||
surf->plane.SetNormal(kexVec3(0, 0, -1));
|
||||
surf->plane.SetDistance(surf->verts[0]);
|
||||
surf->plane = sector->ceilingplane;
|
||||
surf->type = ST_CEILING;
|
||||
surf->typeIndex = i;
|
||||
|
||||
|
|
Loading…
Reference in a new issue