- updated GL renderer.

This commit is contained in:
Christoph Oelckers 2016-04-02 23:17:16 +02:00
parent 348c384bb6
commit af78937a15
22 changed files with 238 additions and 306 deletions

View File

@ -47,8 +47,7 @@ struct GLSectorStackPortal;
struct FPortal struct FPortal
{ {
fixed_t xDisplacement; DVector2 mDisplacement;
fixed_t yDisplacement;
int plane; int plane;
GLSectorStackPortal *glportal; // for quick access to the render data. This is only valid during BSP traversal! GLSectorStackPortal *glportal; // for quick access to the render data. This is only valid during BSP traversal!

View File

@ -64,15 +64,13 @@
struct FPortalID struct FPortalID
{ {
fixed_t mXDisplacement; DVector2 mDisplacement;
fixed_t mYDisplacement;
// for the hash code // for the hash code
operator intptr_t() const { return (mXDisplacement >> 8) + (mYDisplacement << 8); } operator intptr_t() const { return (FLOAT2FIXED(mDisplacement.X) >> 8) + (FLOAT2FIXED(mDisplacement.Y) << 8); }
bool operator != (const FPortalID &other) const bool operator != (const FPortalID &other) const
{ {
return mXDisplacement != other.mXDisplacement || return mDisplacement != other.mDisplacement;
mYDisplacement != other.mYDisplacement;
} }
}; };
@ -331,8 +329,8 @@ void gl_BuildPortalCoverage(FPortalCoverage *coverage, subsector_t *subsector, F
shape.Resize(subsector->numlines); shape.Resize(subsector->numlines);
for(unsigned i=0; i<subsector->numlines; i++) for(unsigned i=0; i<subsector->numlines; i++)
{ {
centerx += (shape[i].x = subsector->firstline[i].v1->fixX() + portal->xDisplacement); centerx += (shape[i].x = FLOAT2FIXED(subsector->firstline[i].v1->fX() + portal->mDisplacement.X));
centery += (shape[i].y = subsector->firstline[i].v1->fixY() + portal->yDisplacement); centery += (shape[i].y = FLOAT2FIXED(subsector->firstline[i].v1->fY() + portal->mDisplacement.Y));
} }
FCoverageBuilder build(subsector, portal); FCoverageBuilder build(subsector, portal);
@ -361,7 +359,7 @@ static void CollectPortalSectors(FPortalMap &collection)
ASkyViewpoint *SkyBox = barrier_cast<ASkyViewpoint*>(sec->SkyBoxes[j]); ASkyViewpoint *SkyBox = barrier_cast<ASkyViewpoint*>(sec->SkyBoxes[j]);
if (SkyBox != NULL && SkyBox->bAlways && SkyBox->Mate != NULL) if (SkyBox != NULL && SkyBox->bAlways && SkyBox->Mate != NULL)
{ {
FPortalID id = { SkyBox->_f_X() - SkyBox->Mate->_f_X(), SkyBox->_f_Y() - SkyBox->Mate->_f_Y() }; FPortalID id = { {SkyBox->X() - SkyBox->Mate->X(), SkyBox->Y() - SkyBox->Mate->Y()} };
FPortalSectors &sss = collection[id]; FPortalSectors &sss = collection[id];
FPortalSector ss = { sec, j }; FPortalSector ss = { sec, j };
@ -406,8 +404,7 @@ void gl_InitPortals()
if (planeflags & i) if (planeflags & i)
{ {
FPortal *portal = new FPortal; FPortal *portal = new FPortal;
portal->xDisplacement = pair->Key.mXDisplacement; portal->mDisplacement = pair->Key.mDisplacement;
portal->yDisplacement = pair->Key.mYDisplacement;
portal->plane = (i==1? sector_t::floor : sector_t::ceiling); /**/ portal->plane = (i==1? sector_t::floor : sector_t::ceiling); /**/
portal->glportal = NULL; portal->glportal = NULL;
portals.Push(portal); portals.Push(portal);
@ -505,8 +502,8 @@ CCMD(dumpportals)
{ {
for(unsigned i=0;i<portals.Size(); i++) for(unsigned i=0;i<portals.Size(); i++)
{ {
double xdisp = portals[i]->xDisplacement/65536.; double xdisp = portals[i]->mDisplacement.X;
double ydisp = portals[i]->yDisplacement/65536.; double ydisp = portals[i]->mDisplacement.Y;
Printf(PRINT_LOG, "Portal #%d, %s, displacement = (%f,%f)\n", i, portals[i]->plane==0? "floor":"ceiling", Printf(PRINT_LOG, "Portal #%d, %s, displacement = (%f,%f)\n", i, portals[i]->plane==0? "floor":"ceiling",
xdisp, ydisp); xdisp, ydisp);
Printf(PRINT_LOG, "Coverage:\n"); Printf(PRINT_LOG, "Coverage:\n");

View File

@ -93,8 +93,8 @@ public:
void SetViewport(GL_IRECT *bounds); void SetViewport(GL_IRECT *bounds);
sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
void RenderView(player_t *player); void RenderView(player_t *player);
void SetViewAngle(angle_t viewangle); void SetViewAngle(DAngle viewangle);
void SetupView(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle, bool mirror, bool planemirror); void SetupView(float viewx, float viewy, float viewz, DAngle viewangle, bool mirror, bool planemirror);
void Initialize(); void Initialize();
@ -132,7 +132,7 @@ public:
void SetProjection(float fov, float ratio, float fovratio); void SetProjection(float fov, float ratio, float fovratio);
void SetProjection(VSMatrix matrix); // raw matrix input from stereo 3d modes void SetProjection(VSMatrix matrix); // raw matrix input from stereo 3d modes
void SetViewMatrix(fixed_t viewx, fixed_t viewy, fixed_t viewz, bool mirror, bool planemirror); void SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror);
void ProcessScene(bool toscreen = false); void ProcessScene(bool toscreen = false);
bool StartOffscreen(); bool StartOffscreen();

View File

@ -388,7 +388,13 @@ angle_t Clipper::AngleToPseudo(angle_t ang)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
angle_t R_PointToPseudoAngle (fixed_t viewx, fixed_t viewy, fixed_t x, fixed_t y) void R_SetView()
{
viewx = FLOAT2FIXED(ViewPos.X);
viewy = FLOAT2FIXED(ViewPos.Y);
}
angle_t R_PointToPseudoAngle (fixed_t x, fixed_t y)
{ {
// Note: float won't work here as it's less precise than the BAM values being passed as parameters // Note: float won't work here as it's less precise than the BAM values being passed as parameters
double vecx = double(x-viewx); double vecx = double(x-viewx);
@ -450,8 +456,8 @@ bool Clipper::CheckBox(const fixed_t *bspcoord)
if (boxpos == 5) return true; if (boxpos == 5) return true;
check = checkcoord[boxpos]; check = checkcoord[boxpos];
angle1 = R_PointToPseudoAngle (viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]); angle1 = R_PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]);
angle2 = R_PointToPseudoAngle (viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]); angle2 = R_PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]);
return SafeCheckRange(angle2, angle1); return SafeCheckRange(angle2, angle1);
} }

View File

@ -136,12 +136,13 @@ public:
extern Clipper clipper; extern Clipper clipper;
angle_t R_PointToPseudoAngle (fixed_t viewx, fixed_t viewy, fixed_t x, fixed_t y); angle_t R_PointToPseudoAngle (fixed_t x, fixed_t y);
void R_SetView();
// Used to speed up angle calculations during clipping // Used to speed up angle calculations during clipping
inline angle_t vertex_t::GetClipAngle() inline angle_t vertex_t::GetClipAngle()
{ {
return angletime == Clipper::anglecache? viewangle : (angletime = Clipper::anglecache, viewangle = R_PointToPseudoAngle(viewx, viewy, x,y)); return angletime == Clipper::anglecache? viewangle : (angletime = Clipper::anglecache, viewangle = R_PointToPseudoAngle(x,y));
} }
#endif #endif

View File

@ -243,39 +243,39 @@ SortNode * GLDrawList::FindSortPlane(SortNode * head)
//========================================================================== //==========================================================================
SortNode * GLDrawList::FindSortWall(SortNode * head) SortNode * GLDrawList::FindSortWall(SortNode * head)
{ {
fixed_t farthest=INT_MIN; float farthest = -FLT_MAX;
fixed_t nearest=INT_MAX; float nearest = FLT_MAX;
SortNode * best=NULL; SortNode * best = NULL;
SortNode * node=head; SortNode * node = head;
fixed_t bestdist=INT_MAX; float bestdist = FLT_MAX;
while (node) while (node)
{ {
GLDrawItem * it=&drawitems[node->itemindex]; GLDrawItem * it = &drawitems[node->itemindex];
if (it->rendertype==GLDIT_WALL) if (it->rendertype == GLDIT_WALL)
{ {
fixed_t d=walls[it->index].viewdistance; float d = walls[it->index].ViewDistance;
if (d>farthest) farthest=d; if (d > farthest) farthest = d;
if (d<nearest) nearest=d; if (d < nearest) nearest = d;
} }
node=node->next; node = node->next;
} }
if (farthest==INT_MIN) return NULL; if (farthest == INT_MIN) return NULL;
node=head; node = head;
farthest=(farthest+nearest)>>1; farthest = (farthest + nearest) / 2;
while (node) while (node)
{ {
GLDrawItem * it=&drawitems[node->itemindex]; GLDrawItem * it = &drawitems[node->itemindex];
if (it->rendertype==GLDIT_WALL) if (it->rendertype == GLDIT_WALL)
{ {
fixed_t di=abs(walls[it->index].viewdistance-farthest); float di = fabsf(walls[it->index].ViewDistance - farthest);
if (!best || di<bestdist) if (!best || di < bestdist)
{ {
best=node; best = node;
bestdist=di; bestdist = di;
} }
} }
node=node->next; node = node->next;
} }
return best; return best;
} }
@ -309,7 +309,7 @@ void GLDrawList::SortWallIntoPlane(SortNode * head,SortNode * sort)
GLFlat * fh=&flats[drawitems[head->itemindex].index]; GLFlat * fh=&flats[drawitems[head->itemindex].index];
GLWall * ws=&walls[drawitems[sort->itemindex].index]; GLWall * ws=&walls[drawitems[sort->itemindex].index];
bool ceiling = fh->z > FIXED2FLOAT(viewz); bool ceiling = fh->z > ViewPos.Z;
if ((ws->ztop[0] > fh->z || ws->ztop[1] > fh->z) && (ws->zbottom[0] < fh->z || ws->zbottom[1] < fh->z)) if ((ws->ztop[0] > fh->z || ws->ztop[1] > fh->z) && (ws->zbottom[0] < fh->z || ws->zbottom[1] < fh->z))
{ {
@ -350,7 +350,7 @@ void GLDrawList::SortSpriteIntoPlane(SortNode * head,SortNode * sort)
GLFlat * fh=&flats[drawitems[head->itemindex].index]; GLFlat * fh=&flats[drawitems[head->itemindex].index];
GLSprite * ss=&sprites[drawitems[sort->itemindex].index]; GLSprite * ss=&sprites[drawitems[sort->itemindex].index];
bool ceiling = fh->z > FIXED2FLOAT(viewz); bool ceiling = fh->z > ViewPos.Z;
if ((ss->z1>fh->z && ss->z2<fh->z) || ss->modelframe) if ((ss->z1>fh->z && ss->z2<fh->z) || ss->modelframe)
{ {
@ -708,7 +708,7 @@ void GLDrawList::DoDrawSorted(SortNode * head)
if (drawitems[head->itemindex].rendertype == GLDIT_FLAT) if (drawitems[head->itemindex].rendertype == GLDIT_FLAT)
{ {
z = flats[drawitems[head->itemindex].index].z; z = flats[drawitems[head->itemindex].index].z;
relation = z > FIXED2FLOAT(viewz)? 1 : -1; relation = z > ViewPos.Z ? 1 : -1;
} }
@ -1112,9 +1112,9 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo
gl_SetFog(lightlevel, rel, &Colormap, false); gl_SetFog(lightlevel, rel, &Colormap, false);
gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
float fviewx = FIXED2FLOAT(viewx); float fviewx = ViewPos.X;
float fviewy = FIXED2FLOAT(viewy); float fviewy = ViewPos.Y;
float fviewz = FIXED2FLOAT(viewz); float fviewz = ViewPos.Z;
gl_SetPlaneTextureRotation(&plane, gltexture); gl_SetPlaneTextureRotation(&plane, gltexture);
gl_RenderState.Apply(); gl_RenderState.Apply();
@ -1165,11 +1165,11 @@ void FDrawInfo::FloodUpperGap(seg_t * seg)
// Although the plane can be sloped this code will only be called // Although the plane can be sloped this code will only be called
// when the edge itself is not. // when the edge itself is not.
fixed_t backz = fakebsector->ceilingplane.ZatPoint(seg->v1->x, seg->v1->y); double backz = fakebsector->ceilingplane.ZatPoint(seg->v1);
fixed_t frontz = fakefsector->ceilingplane.ZatPoint(seg->v1->x, seg->v1->y); double frontz = fakefsector->ceilingplane.ZatPoint(seg->v1);
if (fakebsector->GetTexture(sector_t::ceiling)==skyflatnum) return; if (fakebsector->GetTexture(sector_t::ceiling)==skyflatnum) return;
if (backz < viewz) return; if (backz < ViewPos.Z) return;
if (seg->sidedef == seg->linedef->sidedef[0]) if (seg->sidedef == seg->linedef->sidedef[0])
{ {
@ -1187,8 +1187,8 @@ void FDrawInfo::FloodUpperGap(seg_t * seg)
ws.x2 = v2->fX(); ws.x2 = v2->fX();
ws.y2 = v2->fY(); ws.y2 = v2->fY();
ws.z1= FIXED2FLOAT(frontz); ws.z1= frontz;
ws.z2= FIXED2FLOAT(backz); ws.z2= backz;
// Step1: Draw a stencil into the gap // Step1: Draw a stencil into the gap
SetupFloodStencil(&ws); SetupFloodStencil(&ws);
@ -1217,12 +1217,12 @@ void FDrawInfo::FloodLowerGap(seg_t * seg)
// Although the plane can be sloped this code will only be called // Although the plane can be sloped this code will only be called
// when the edge itself is not. // when the edge itself is not.
fixed_t backz = fakebsector->floorplane.ZatPoint(seg->v1->x, seg->v1->y); double backz = fakebsector->floorplane.ZatPoint(seg->v1);
fixed_t frontz = fakefsector->floorplane.ZatPoint(seg->v1->x, seg->v1->y); double frontz = fakefsector->floorplane.ZatPoint(seg->v1);
if (fakebsector->GetTexture(sector_t::floor) == skyflatnum) return; if (fakebsector->GetTexture(sector_t::floor) == skyflatnum) return;
if (fakebsector->GetPlaneTexZ(sector_t::floor) > viewz) return; if (fakebsector->GetPlaneTexZF(sector_t::floor) > ViewPos.Z) return;
if (seg->sidedef == seg->linedef->sidedef[0]) if (seg->sidedef == seg->linedef->sidedef[0])
{ {
@ -1240,8 +1240,8 @@ void FDrawInfo::FloodLowerGap(seg_t * seg)
ws.x2 = v2->fX(); ws.x2 = v2->fX();
ws.y2 = v2->fY(); ws.y2 = v2->fY();
ws.z2= FIXED2FLOAT(frontz); ws.z2= frontz;
ws.z1= FIXED2FLOAT(backz); ws.z1= backz;
// Step1: Draw a stencil into the gap // Step1: Draw a stencil into the gap
SetupFloodStencil(&ws); SetupFloodStencil(&ws);

View File

@ -516,7 +516,7 @@ void GLFlat::ProcessSector(sector_t * frontsector)
// //
// //
// //
if (frontsector->floorplane.ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy)) <= FIXED2FLOAT(viewz)) if (frontsector->floorplane.ZatPoint(ViewPos) <= ViewPos.Z)
{ {
// process the original floor first. // process the original floor first.
@ -577,7 +577,7 @@ void GLFlat::ProcessSector(sector_t * frontsector)
// //
// //
// //
if (frontsector->ceilingplane.ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy)) >= FIXED2FLOAT(viewz)) if (frontsector->ceilingplane.ZatPoint(ViewPos) >= ViewPos.Z)
{ {
// process the original ceiling first. // process the original ceiling first.
@ -669,7 +669,7 @@ void GLFlat::ProcessSector(sector_t * frontsector)
fixed_t ff_top=FLOAT2FIXED(rover->top.plane->ZatPoint(sector->centerspot)); fixed_t ff_top=FLOAT2FIXED(rover->top.plane->ZatPoint(sector->centerspot));
if (ff_top<lastceilingheight) if (ff_top<lastceilingheight)
{ {
if (FIXED2FLOAT(viewz) <= rover->top.plane->ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy))) if (ViewPos.Z <= rover->top.plane->ZatPoint(ViewPos))
{ {
SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG));
Colormap.FadeColor=frontsector->ColorMap->Fade; Colormap.FadeColor=frontsector->ColorMap->Fade;
@ -683,7 +683,7 @@ void GLFlat::ProcessSector(sector_t * frontsector)
fixed_t ff_bottom=FLOAT2FIXED(rover->bottom.plane->ZatPoint(sector->centerspot)); fixed_t ff_bottom=FLOAT2FIXED(rover->bottom.plane->ZatPoint(sector->centerspot));
if (ff_bottom<lastceilingheight) if (ff_bottom<lastceilingheight)
{ {
if (FIXED2FLOAT(viewz)<=rover->bottom.plane->ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy))) if (ViewPos.Z <=rover->bottom.plane->ZatPoint(ViewPos))
{ {
SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG));
Colormap.FadeColor=frontsector->ColorMap->Fade; Colormap.FadeColor=frontsector->ColorMap->Fade;
@ -709,7 +709,7 @@ void GLFlat::ProcessSector(sector_t * frontsector)
fixed_t ff_bottom=FLOAT2FIXED(rover->bottom.plane->ZatPoint(sector->centerspot)); fixed_t ff_bottom=FLOAT2FIXED(rover->bottom.plane->ZatPoint(sector->centerspot));
if (ff_bottom>lastfloorheight || (rover->flags&FF_FIX)) if (ff_bottom>lastfloorheight || (rover->flags&FF_FIX))
{ {
if (FIXED2FLOAT(viewz) >= rover->bottom.plane->ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy))) if (ViewPos.Z >= rover->bottom.plane->ZatPoint(ViewPos))
{ {
SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG));
Colormap.FadeColor=frontsector->ColorMap->Fade; Colormap.FadeColor=frontsector->ColorMap->Fade;
@ -730,7 +730,7 @@ void GLFlat::ProcessSector(sector_t * frontsector)
fixed_t ff_top=FLOAT2FIXED(rover->top.plane->ZatPoint(sector->centerspot)); fixed_t ff_top=FLOAT2FIXED(rover->top.plane->ZatPoint(sector->centerspot));
if (ff_top>lastfloorheight) if (ff_top>lastfloorheight)
{ {
if (FIXED2FLOAT(viewz) >= rover->top.plane->ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy))) if (ViewPos.Z >= rover->top.plane->ZatPoint(ViewPos))
{ {
SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG));
Colormap.FadeColor=frontsector->ColorMap->Fade; Colormap.FadeColor=frontsector->ColorMap->Fade;

View File

@ -307,11 +307,9 @@ bool GLPortal::Start(bool usestencil, bool doquery)
gl_RenderState.SetClipHeightTop(65536.f); gl_RenderState.SetClipHeightTop(65536.f);
// save viewpoint // save viewpoint
savedviewx=viewx; savedViewPos = ViewPos;
savedviewy=viewy; savedAngle = ViewAngle;
savedviewz=viewz;
savedviewactor=GLRenderer->mViewActor; savedviewactor=GLRenderer->mViewActor;
savedviewangle=viewangle;
savedviewarea=in_area; savedviewarea=in_area;
savedshowviewer = r_showviewer; savedshowviewer = r_showviewer;
@ -324,7 +322,7 @@ bool GLPortal::Start(bool usestencil, bool doquery)
inline void GLPortal::ClearClipper() inline void GLPortal::ClearClipper()
{ {
fixed_t angleOffset = viewangle - savedviewangle; DAngle angleOffset = deltaangle(savedAngle, ViewAngle);
clipper.Clear(); clipper.Clear();
@ -332,23 +330,20 @@ inline void GLPortal::ClearClipper()
// Set the clipper to the minimal visible area // Set the clipper to the minimal visible area
clipper.SafeAddClipRange(0,0xffffffff); clipper.SafeAddClipRange(0,0xffffffff);
for(unsigned int i=0;i<lines.Size();i++) for (unsigned int i = 0; i < lines.Size(); i++)
{ {
angle_t startAngle = R_PointToAnglePrecise(savedviewx, savedviewy, DAngle startAngle = (DVector2(lines[i].glseg.x2, lines[i].glseg.y2) - savedViewPos).Angle() + angleOffset;
FLOAT2FIXED(lines[i].glseg.x2), FLOAT2FIXED(lines[i].glseg.y2)); DAngle endAngle = (DVector2(lines[i].glseg.x1, lines[i].glseg.y1) - savedViewPos).Angle() + angleOffset;
angle_t endAngle = R_PointToAnglePrecise(savedviewx, savedviewy, if (deltaangle(endAngle, startAngle) < 0)
FLOAT2FIXED(lines[i].glseg.x1), FLOAT2FIXED(lines[i].glseg.y1));
if (startAngle-endAngle>0)
{ {
clipper.SafeRemoveClipRangeRealAngles(startAngle + angleOffset, endAngle + angleOffset); clipper.SafeRemoveClipRangeRealAngles(startAngle.BAMs(), endAngle.BAMs());
} }
} }
// and finally clip it to the visible area // and finally clip it to the visible area
angle_t a1 = GLRenderer->FrustumAngle(); angle_t a1 = GLRenderer->FrustumAngle();
if (a1<ANGLE_180) clipper.SafeAddClipRangeRealAngles(viewangle+a1, viewangle-a1); if (a1 < ANGLE_180) clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1);
// lock the parts that have just been clipped out. // lock the parts that have just been clipped out.
clipper.SetSilhouette(); clipper.SetSilhouette();
@ -379,14 +374,12 @@ void GLPortal::End(bool usestencil)
if (needdepth) FDrawInfo::EndDrawInfo(); if (needdepth) FDrawInfo::EndDrawInfo();
// Restore the old view // Restore the old view
viewx=savedviewx; ViewPos = savedViewPos;
viewy=savedviewy; ViewAngle = savedAngle;
viewz=savedviewz;
viewangle=savedviewangle;
GLRenderer->mViewActor=savedviewactor; GLRenderer->mViewActor=savedviewactor;
in_area=savedviewarea; in_area=savedviewarea;
r_showviewer = savedshowviewer; r_showviewer = savedshowviewer;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
{ {
ScopedColorMask colorMask(0, 0, 0, 0); // glColorMask(0, 0, 0, 0); // no graphics ScopedColorMask colorMask(0, 0, 0, 0); // glColorMask(0, 0, 0, 0); // no graphics
@ -438,14 +431,12 @@ void GLPortal::End(bool usestencil)
glDepthMask(true); glDepthMask(true);
} }
// Restore the old view // Restore the old view
viewx=savedviewx; ViewPos = savedViewPos;
viewy=savedviewy; ViewAngle = savedAngle;
viewz=savedviewz;
viewangle=savedviewangle;
GLRenderer->mViewActor=savedviewactor; GLRenderer->mViewActor=savedviewactor;
in_area=savedviewarea; in_area=savedviewarea;
r_showviewer = savedshowviewer; r_showviewer = savedshowviewer;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
// This draws a valid z-buffer into the stencil's contents to ensure it // This draws a valid z-buffer into the stencil's contents to ensure it
// doesn't get overwritten by the level's geometry. // doesn't get overwritten by the level's geometry.
@ -655,28 +646,24 @@ void GLSkyboxPortal::DrawContents()
PlaneMirrorMode = 0; PlaneMirrorMode = 0;
bool oldclamp = gl_RenderState.SetDepthClamp(false); bool oldclamp = gl_RenderState.SetDepthClamp(false);
DVector3 viewpos = origin->InterpolatedPosition(r_TicFracF); ViewPos = origin->InterpolatedPosition(r_TicFracF);
viewangle += (origin->PrevAngles.Yaw + deltaangle(origin->PrevAngles.Yaw, origin->Angles.Yaw) * r_TicFracF).BAMs(); ViewAngle += (origin->PrevAngles.Yaw + deltaangle(origin->PrevAngles.Yaw, origin->Angles.Yaw) * r_TicFracF);
// Don't let the viewpoint be too close to a floor or ceiling // Don't let the viewpoint be too close to a floor or ceiling
double floorh = origin->Sector->floorplane.ZatPoint(origin->Pos()); double floorh = origin->Sector->floorplane.ZatPoint(origin->Pos());
double ceilh = origin->Sector->ceilingplane.ZatPoint(origin->Pos()); double ceilh = origin->Sector->ceilingplane.ZatPoint(origin->Pos());
if (viewpos.Z < floorh + 4) viewpos.Z = floorh + 4; if (ViewPos.Z < floorh + 4) ViewPos.Z = floorh + 4;
if (viewpos.Z > ceilh - 4) viewz = ceilh - 4; if (ViewPos.Z > ceilh - 4) ViewPos.Z = ceilh - 4;
viewx = FLOAT2FIXED(viewpos.X);
viewy = FLOAT2FIXED(viewpos.Y);
viewz = FLOAT2FIXED(viewpos.Z);
GLRenderer->mViewActor = origin; GLRenderer->mViewActor = origin;
validcount++; validcount++;
inskybox = true; inskybox = true;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
GLRenderer->SetViewArea(); GLRenderer->SetViewArea();
ClearClipper(); ClearClipper();
int mapsection = R_PointInSubsector(viewx, viewy)->mapsection; int mapsection = R_PointInSubsector(ViewPos)->mapsection;
SaveMapSection(); SaveMapSection();
currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7); currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7);
@ -761,8 +748,7 @@ void GLSectorStackPortal::DrawContents()
{ {
FPortal *portal = origin; FPortal *portal = origin;
viewx += origin->xDisplacement; ViewPos += origin->mDisplacement;
viewy += origin->yDisplacement;
GLRenderer->mViewActor = NULL; GLRenderer->mViewActor = NULL;
@ -771,7 +757,7 @@ void GLSectorStackPortal::DrawContents()
// avoid recursions! // avoid recursions!
if (origin->plane != -1) instack[origin->plane]++; if (origin->plane != -1) instack[origin->plane]++;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
SaveMapSection(); SaveMapSection();
SetupCoverage(); SetupCoverage();
ClearClipper(); ClearClipper();
@ -807,8 +793,8 @@ void GLPlaneMirrorPortal::DrawContents()
int old_pm=PlaneMirrorMode; int old_pm=PlaneMirrorMode;
fixed_t planez = origin->ZatPoint(viewx, viewy); double planez = origin->ZatPoint(ViewPos);
viewz = 2*planez - viewz; ViewPos.Z = 2 * planez - ViewPos.Z;
GLRenderer->mViewActor = NULL; GLRenderer->mViewActor = NULL;
PlaneMirrorMode = origin->fC() < 0 ? -1 : 1; PlaneMirrorMode = origin->fC() < 0 ? -1 : 1;
r_showviewer = true; r_showviewer = true;
@ -816,18 +802,17 @@ void GLPlaneMirrorPortal::DrawContents()
validcount++; validcount++;
PlaneMirrorFlag++; PlaneMirrorFlag++;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper(); ClearClipper();
float f = FIXED2FLOAT(planez);
if (PlaneMirrorMode < 0) if (PlaneMirrorMode < 0)
{ {
gl_RenderState.SetClipHeightTop(f); // ceiling mirror: clip everything with a z lower than the portal's ceiling gl_RenderState.SetClipHeightTop(planez); // ceiling mirror: clip everything with a z lower than the portal's ceiling
gl_RenderState.SetClipHeightBottom(-65536.f); gl_RenderState.SetClipHeightBottom(-65536.f);
} }
else else
{ {
gl_RenderState.SetClipHeightBottom(f); // floor mirror: clip everything with a z higher than the portal's floor gl_RenderState.SetClipHeightBottom(planez); // floor mirror: clip everything with a z higher than the portal's floor
gl_RenderState.SetClipHeightTop(65536.f); gl_RenderState.SetClipHeightTop(65536.f);
} }
@ -872,31 +857,30 @@ void GLMirrorPortal::DrawContents()
} }
GLRenderer->mCurrentPortal = this; GLRenderer->mCurrentPortal = this;
angle_t startang = viewangle; DAngle StartAngle = ViewAngle;
fixed_t startx = viewx; DVector3 StartPos = ViewPos;
fixed_t starty = viewy;
vertex_t *v1 = linedef->v1; vertex_t *v1 = linedef->v1;
vertex_t *v2 = linedef->v2; vertex_t *v2 = linedef->v2;
// Reflect the current view behind the mirror. // Reflect the current view behind the mirror.
if (linedef->Delta().X == 0) if (linedef->Delta().X == 0)
{ {
// vertical mirror // vertical mirror
viewx = v1->fixX() - startx + v1->fixX(); ViewPos.X = 2 * v1->fX() - StartPos.X;
// Compensation for reendering inaccuracies // Compensation for reendering inaccuracies
if (startx<v1->fixX()) viewx -= FRACUNIT/2; if (StartPos.X < v1->fX()) ViewPos.X -= 0.1;
else viewx += FRACUNIT/2; else ViewPos.X += 0.1;
} }
else if (linedef->Delta().Y == 0) else if (linedef->Delta().Y == 0)
{ {
// horizontal mirror // horizontal mirror
viewy = v1->fixY() - starty + v1->fixY(); ViewPos.Y = 2*v1->fY() - StartPos.Y;
// Compensation for reendering inaccuracies // Compensation for reendering inaccuracies
if (starty<v1->fixY()) viewy -= FRACUNIT/2; if (StartPos.Y<v1->fY()) ViewPos.Y -= 0.1;
else viewy += FRACUNIT/2; else ViewPos.Y += 0.1;
} }
else else
{ {
@ -907,25 +891,23 @@ void GLMirrorPortal::DrawContents()
double dy = v2->fY() - v1->fY(); double dy = v2->fY() - v1->fY();
double x1 = v1->fX(); double x1 = v1->fX();
double y1 = v1->fY(); double y1 = v1->fY();
double x = FIXED2DBL(startx); double x = StartPos.X;
double y = FIXED2DBL(starty); double y = StartPos.Y;
// the above two cases catch len == 0 // the above two cases catch len == 0
double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy);
viewx = FLOAT2FIXED((x1 + r * dx)*2 - x); ViewPos.X = (x1 + r * dx)*2 - x;
viewy = FLOAT2FIXED((y1 + r * dy)*2 - y); ViewPos.Y = (y1 + r * dy)*2 - y;
// Compensation for reendering inaccuracies // Compensation for reendering inaccuracies
FVector2 v(-dx, dy); FVector2 v(-dx, dy);
v.MakeUnit(); v.MakeUnit();
viewx+= FLOAT2FIXED(v[1] * renderdepth / 2); ViewPos.X+= v[1] * renderdepth / 2;
viewy+= FLOAT2FIXED(v[0] * renderdepth / 2); ViewPos.Y+= v[0] * renderdepth / 2;
} }
// we cannot afford any imprecisions caused by R_PointToAngle2 here. They'd be visible as seams around the mirror. ViewAngle = linedef->Delta().Angle() * 2. - StartAngle;
viewangle = 2*R_PointToAnglePrecise (linedef->v1->fixX(), linedef->v1->fixY(),
linedef->v2->fixX(), linedef->v2->fixY()) - startang;
GLRenderer->mViewActor = NULL; GLRenderer->mViewActor = NULL;
r_showviewer = true; r_showviewer = true;
@ -933,12 +915,12 @@ void GLMirrorPortal::DrawContents()
validcount++; validcount++;
MirrorFlag++; MirrorFlag++;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
clipper.Clear(); clipper.Clear();
angle_t af = GLRenderer->FrustumAngle(); angle_t af = GLRenderer->FrustumAngle();
if (af<ANGLE_180) clipper.SafeAddClipRangeRealAngles(viewangle+af, viewangle-af); if (af<ANGLE_180) clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs()+af, ViewAngle.BAMs()-af);
angle_t a2 = linedef->v1->GetClipAngle(); angle_t a2 = linedef->v1->GetClipAngle();
angle_t a1 = linedef->v2->GetClipAngle(); angle_t a1 = linedef->v2->GetClipAngle();
@ -952,7 +934,12 @@ void GLMirrorPortal::DrawContents()
int GLLinePortal::ClipSeg(seg_t *seg) int GLLinePortal::ClipSeg(seg_t *seg)
{ {
return PClip_Inside;// P_ClipLineToPortal(seg->linedef, line(), viewx, viewy) ? PClip_InFront : PClip_Inside; line_t *linedef = seg->linedef;
if (!linedef)
{
return PClip_Inside; // should be handled properly.
}
return P_ClipLineToPortal(linedef, line(), ViewPos) ? PClip_InFront : PClip_Inside;
} }
int GLLinePortal::ClipSubsector(subsector_t *sub) int GLLinePortal::ClipSubsector(subsector_t *sub)
@ -960,14 +947,14 @@ int GLLinePortal::ClipSubsector(subsector_t *sub)
// this seg is completely behind the mirror! // this seg is completely behind the mirror!
for(unsigned int i=0;i<sub->numlines;i++) for(unsigned int i=0;i<sub->numlines;i++)
{ {
if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fixX(), sub->firstline[i].v1->fixY(), line()) == 0) return PClip_Inside; if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside;
} }
return PClip_InFront; return PClip_InFront;
} }
int GLLinePortal::ClipPoint(fixed_t x, fixed_t y) int GLLinePortal::ClipPoint(const DVector2 &pos)
{ {
if (P_PointOnLineSidePrecise(x, y, line())) if (P_PointOnLineSidePrecise(pos, line()))
{ {
return PClip_InFront; return PClip_InFront;
} }
@ -1002,11 +989,9 @@ void GLLineToLinePortal::DrawContents()
GLRenderer->mCurrentPortal = this; GLRenderer->mCurrentPortal = this;
line_t *origin = glport->reference->mOrigin; line_t *origin = glport->reference->mOrigin;
P_TranslatePortalXY(origin, viewx, viewy); P_TranslatePortalXY(origin, ViewPos.X, ViewPos.Y);
DAngle va = ANGLE2DBL(viewangle); P_TranslatePortalAngle(origin, ViewAngle);
P_TranslatePortalAngle(origin, va); P_TranslatePortalZ(origin, ViewPos.Z);
viewangle = va.BAMs();
P_TranslatePortalZ(origin, viewz);
SaveMapSection(); SaveMapSection();
@ -1023,52 +1008,13 @@ void GLLineToLinePortal::DrawContents()
GLRenderer->mViewActor = NULL; GLRenderer->mViewActor = NULL;
validcount++; validcount++;
GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper(); ClearClipper();
GLRenderer->DrawScene(); GLRenderer->DrawScene();
RestoreMapSection(); RestoreMapSection();
} }
/*
int GLLineToLinePortal::ClipSeg(seg_t *seg)
{
line_t *linedef = lines[0].seg->linedef->getPortalDestination();
// this seg is completely behind the portal
//we cannot use P_PointOnLineSide here because it loses the special meaning of 0 == 'on the line'.
int side1 = DMulScale32(seg->v1->y - linedef->v1->y, linedef->dx, linedef->v1->x - seg->v1->x, linedef->dy);
int side2 = DMulScale32(seg->v2->y - linedef->v1->y, linedef->dx, linedef->v1->x - seg->v2->x, linedef->dy);
if (side1 >= 0 && side2 >= 0)
{
return PClip_InFront;
}
return PClip_Inside;
}
int GLLineToLinePortal::ClipSubsector(subsector_t *sub)
{
line_t *masterline = lines[0].seg->linedef->getPortalDestination();
for(unsigned int i=0;i<sub->numlines;i++)
{
if (P_PointOnLineSidePrecise(sub->firstline[i].v1->x, sub->firstline[i].v1->y, masterline) == 0) return PClip_Inside;
}
return PClip_InFront;
}
int GLLineToLinePortal::ClipPoint(fixed_t x, fixed_t y)
{
line_t *masterline = lines[0].seg->linedef->getPortalDestination();
if (P_PointOnLineSidePrecise(x, y, masterline))
{
return PClip_InFront;
}
return PClip_Inside;
}
*/
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
@ -1112,7 +1058,7 @@ void GLHorizonPortal::DrawContents()
PortalAll.Unclock(); PortalAll.Unclock();
return; return;
} }
gl_RenderState.SetCameraPos(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy), FIXED2FLOAT(viewz)); gl_RenderState.SetCameraPos(ViewPos.X, ViewPos.Y, ViewPos.Z);
z=sp->Texheight; z=sp->Texheight;
@ -1141,8 +1087,8 @@ void GLHorizonPortal::DrawContents()
float vx=FIXED2FLOAT(viewx); float vx= ViewPos.X;
float vy=FIXED2FLOAT(viewy); float vy= ViewPos.Y;
// Draw to some far away boundary // Draw to some far away boundary
// This is not drawn as larher strips because it causes visual glitches. // This is not drawn as larher strips because it causes visual glitches.
@ -1163,7 +1109,7 @@ void GLHorizonPortal::DrawContents()
} }
} }
float vz=FIXED2FLOAT(viewz); float vz= ViewPos.Z;
float tz=(z-vz);///64.0f; float tz=(z-vz);///64.0f;
// fill the gap between the polygon and the true horizon // fill the gap between the polygon and the true horizon
@ -1238,7 +1184,7 @@ void GLEEHorizonPortal::DrawContents()
horz.colormap = origin->Sector->ColorMap; horz.colormap = origin->Sector->ColorMap;
if (origin->special1 == SKYBOX_PLANE) if (origin->special1 == SKYBOX_PLANE)
{ {
horz.plane.Texheight = FIXED2FLOAT(viewz) + fabs(horz.plane.Texheight); horz.plane.Texheight = ViewPos.Z + fabs(horz.plane.Texheight);
} }
GLHorizonPortal ceil(&horz, true); GLHorizonPortal ceil(&horz, true);
ceil.DrawContents(); ceil.DrawContents();
@ -1251,7 +1197,7 @@ void GLEEHorizonPortal::DrawContents()
horz.colormap = origin->Sector->ColorMap; horz.colormap = origin->Sector->ColorMap;
if (origin->special1 == SKYBOX_PLANE) if (origin->special1 == SKYBOX_PLANE)
{ {
horz.plane.Texheight = FIXED2FLOAT(viewz) - fabs(horz.plane.Texheight); horz.plane.Texheight = ViewPos.Z - fabs(horz.plane.Texheight);
} }
GLHorizonPortal floor(&horz, true); GLHorizonPortal floor(&horz, true);
floor.DrawContents(); floor.DrawContents();

View File

@ -101,10 +101,8 @@ public:
private: private:
void DrawPortalStencil(); void DrawPortalStencil();
fixed_t savedviewx; DVector3 savedViewPos;
fixed_t savedviewy; DAngle savedAngle;
fixed_t savedviewz;
angle_t savedviewangle;
AActor * savedviewactor; AActor * savedviewactor;
area_t savedviewarea; area_t savedviewarea;
bool savedshowviewer; bool savedshowviewer;
@ -165,7 +163,7 @@ public:
virtual int ClipSeg(seg_t *seg) { return PClip_Inside; } virtual int ClipSeg(seg_t *seg) { return PClip_Inside; }
virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; } virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; }
virtual int ClipPoint(fixed_t x, fixed_t y) { return PClip_Inside; } virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; }
static void BeginScene(); static void BeginScene();
static void StartFrame(); static void StartFrame();
@ -186,8 +184,7 @@ struct GLLinePortal : public GLPortal
{ {
v1 = line->v1; v1 = line->v1;
v2 = line->v2; v2 = line->v2;
dx = FLOAT2FIXED(line->Delta().X); CalcDelta();
dy = FLOAT2FIXED(line->Delta().Y);
} }
GLLinePortal(FGLLinePortal *line) GLLinePortal(FGLLinePortal *line)
@ -198,17 +195,21 @@ struct GLLinePortal : public GLPortal
line_t *lline = line->reference->mDestination; line_t *lline = line->reference->mDestination;
v1 = lline->v1; v1 = lline->v1;
v2 = lline->v2; v2 = lline->v2;
dx = FLOAT2FIXED(lline->Delta().X);
dy = FLOAT2FIXED(lline->Delta().Y);
} }
else else
{ {
// For linked portals we can check the merged span. // For linked portals we can check the merged span.
v1 = line->v1; v1 = line->v1;
v2 = line->v2; v2 = line->v2;
dx = line->dx;
dy = line->dy;
} }
CalcDelta();
}
void CalcDelta()
{
DVector2 delta = v2->fPos() - v1->fPos();
dx = FLOAT2FIXED(delta.X);
dy = FLOAT2FIXED(delta.Y);
} }
line_t *line() line_t *line()
@ -219,7 +220,7 @@ struct GLLinePortal : public GLPortal
virtual int ClipSeg(seg_t *seg); virtual int ClipSeg(seg_t *seg);
virtual int ClipSubsector(subsector_t *sub); virtual int ClipSubsector(subsector_t *sub);
virtual int ClipPoint(fixed_t x, fixed_t y); virtual int ClipPoint(const DVector2 &pos);
virtual bool NeedCap() { return false; } virtual bool NeedCap() { return false; }
}; };

View File

@ -506,7 +506,7 @@ void FDrawInfo::HandleMissingTextures()
HandledSubsectors.Clear(); HandledSubsectors.Clear();
validcount++; validcount++;
if (MissingUpperTextures[i].planez > viewz) if (MissingUpperTextures[i].planez > FLOAT2FIXED(ViewPos.Z))
{ {
// close the hole only if all neighboring sectors are an exact height match // close the hole only if all neighboring sectors are an exact height match
// Otherwise just fill in the missing textures. // Otherwise just fill in the missing textures.
@ -578,7 +578,7 @@ void FDrawInfo::HandleMissingTextures()
HandledSubsectors.Clear(); HandledSubsectors.Clear();
validcount++; validcount++;
if (MissingLowerTextures[i].planez < viewz) if (MissingLowerTextures[i].planez < FLOAT2FIXED(ViewPos.Z))
{ {
// close the hole only if all neighboring sectors are an exact height match // close the hole only if all neighboring sectors are an exact height match
// Otherwise just fill in the missing textures. // Otherwise just fill in the missing textures.
@ -668,7 +668,7 @@ void FDrawInfo::DrawUnhandledMissingTextures()
// already done! // already done!
if (seg->linedef->validcount==validcount) continue; // already done if (seg->linedef->validcount==validcount) continue; // already done
seg->linedef->validcount=validcount; seg->linedef->validcount=validcount;
if (seg->frontsector->GetPlaneTexZ(sector_t::ceiling) < viewz) continue; // out of sight if (seg->frontsector->GetPlaneTexZF(sector_t::ceiling) < ViewPos.Z) continue; // out of sight
//if (seg->frontsector->ceilingpic==skyflatnum) continue; //if (seg->frontsector->ceilingpic==skyflatnum) continue;
// FIXME: The check for degenerate subsectors should be more precise // FIXME: The check for degenerate subsectors should be more precise
@ -692,7 +692,7 @@ void FDrawInfo::DrawUnhandledMissingTextures()
if (seg->linedef->validcount==validcount) continue; // already done if (seg->linedef->validcount==validcount) continue; // already done
seg->linedef->validcount=validcount; seg->linedef->validcount=validcount;
if (!(sectorrenderflags[seg->backsector->sectornum] & SSRF_RENDERFLOOR)) continue; if (!(sectorrenderflags[seg->backsector->sectornum] & SSRF_RENDERFLOOR)) continue;
if (seg->frontsector->GetPlaneTexZ(sector_t::floor) > viewz) continue; // out of sight if (seg->frontsector->GetPlaneTexZF(sector_t::floor) > ViewPos.Z) continue; // out of sight
if (seg->backsector->transdoor) continue; if (seg->backsector->transdoor) continue;
if (seg->backsector->GetTexture(sector_t::floor)==skyflatnum) continue; if (seg->backsector->GetTexture(sector_t::floor)==skyflatnum) continue;
if (seg->backsector->portals[sector_t::floor] != NULL) continue; if (seg->backsector->portals[sector_t::floor] != NULL) continue;
@ -793,17 +793,17 @@ bool FDrawInfo::CollectSubsectorsFloor(subsector_t * sub, sector_t * anchor)
// We must collect any subsector that either is connected to this one with a miniseg // We must collect any subsector that either is connected to this one with a miniseg
// or has the same visplane. // or has the same visplane.
// We must not collect any subsector that has the anchor's visplane! // We must not collect any subsector that has the anchor's visplane!
if (!(sub->flags & SSECF_DEGENERATE)) if (!(sub->flags & SSECF_DEGENERATE))
{ {
// Is not being rendered so don't bother. // Is not being rendered so don't bother.
if (!(ss_renderflags[DWORD(sub-subsectors)]&SSRF_PROCESSED)) return true; if (!(ss_renderflags[DWORD(sub - subsectors)] & SSRF_PROCESSED)) return true;
if (sub->render_sector->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) || if (sub->render_sector->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) ||
sub->render_sector->GetPlaneTexZ(sector_t::floor)!=anchor->GetPlaneTexZ(sector_t::floor) || sub->render_sector->GetPlaneTexZF(sector_t::floor) != anchor->GetPlaneTexZF(sector_t::floor) ||
sub->render_sector->GetFloorLight() != anchor->GetFloorLight()) sub->render_sector->GetFloorLight() != anchor->GetFloorLight())
{ {
if (sub==viewsubsector && viewz<anchor->GetPlaneTexZ(sector_t::floor)) inview=true; if (sub == viewsubsector && ViewPos.Z < anchor->GetPlaneTexZF(sector_t::floor)) inview = true;
HandledSubsectors.Push (sub); HandledSubsectors.Push(sub);
} }
} }
@ -952,7 +952,7 @@ void FDrawInfo::HandleHackedSubsectors()
totalssms.Reset(); totalssms.Reset();
totalssms.Clock(); totalssms.Clock();
viewsubsector = R_PointInSubsector(viewx, viewy); viewsubsector = R_PointInSubsector(ViewPos);
// Each subsector may only be processed once in this loop! // Each subsector may only be processed once in this loop!
validcount++; validcount++;

View File

@ -131,18 +131,18 @@ angle_t FGLRenderer::FrustumAngle()
void FGLRenderer::SetViewArea() void FGLRenderer::SetViewArea()
{ {
// The render_sector is better suited to represent the current position in GL // The render_sector is better suited to represent the current position in GL
viewsector = R_PointInSubsector(viewx, viewy)->render_sector; viewsector = R_PointInSubsector(ViewPos)->render_sector;
// Get the heightsec state from the render sector, not the current one! // Get the heightsec state from the render sector, not the current one!
if (viewsector->heightsec && !(viewsector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC)) if (viewsector->heightsec && !(viewsector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC))
{ {
in_area = viewz<=viewsector->heightsec->floorplane.ZatPoint(viewx,viewy) ? area_below : in_area = ViewPos.Z <= viewsector->heightsec->floorplane.ZatPoint(ViewPos) ? area_below :
(viewz>viewsector->heightsec->ceilingplane.ZatPoint(viewx,viewy) && (ViewPos.Z > viewsector->heightsec->ceilingplane.ZatPoint(ViewPos) &&
!(viewsector->heightsec->MoreFlags&SECF_FAKEFLOORONLY)) ? area_above:area_normal; !(viewsector->heightsec->MoreFlags&SECF_FAKEFLOORONLY)) ? area_above : area_normal;
} }
else else
{ {
in_area=area_default; // depends on exposed lower sectors in_area = area_default; // depends on exposed lower sectors
} }
} }
@ -218,12 +218,12 @@ void FGLRenderer::SetViewport(GL_IRECT *bounds)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FGLRenderer::SetViewAngle(angle_t viewangle) void FGLRenderer::SetViewAngle(DAngle viewangle)
{ {
float fviewangle=(float)(viewangle>>ANGLETOFINESHIFT)*360.0f/FINEANGLES; mAngles.Yaw = float(270.0-viewangle.Degrees);
DVector2 v = ViewAngle.ToVector();
mAngles.Yaw = 270.0f-fviewangle; mViewVector.X = v.X;
mViewVector = FVector2(cos(DEG2RAD(fviewangle)), sin(DEG2RAD(fviewangle))); mViewVector.Y = v.Y;
R_SetViewAngle(); R_SetViewAngle();
} }
@ -258,7 +258,7 @@ void FGLRenderer::SetProjection(VSMatrix matrix)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FGLRenderer::SetViewMatrix(fixed_t viewx, fixed_t viewy, fixed_t viewz, bool mirror, bool planemirror) void FGLRenderer::SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror)
{ {
float mult = mirror? -1:1; float mult = mirror? -1:1;
float planemult = planemirror? -glset.pixelstretch : glset.pixelstretch; float planemult = planemirror? -glset.pixelstretch : glset.pixelstretch;
@ -267,7 +267,7 @@ void FGLRenderer::SetViewMatrix(fixed_t viewx, fixed_t viewy, fixed_t viewz, boo
gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Roll.Degrees, 0.0f, 0.0f, 1.0f); gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Roll.Degrees, 0.0f, 0.0f, 1.0f);
gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Pitch.Degrees, 1.0f, 0.0f, 0.0f); gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Pitch.Degrees, 1.0f, 0.0f, 0.0f);
gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Yaw.Degrees, 0.0f, mult, 0.0f); gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Yaw.Degrees, 0.0f, mult, 0.0f);
gl_RenderState.mViewMatrix.translate(FIXED2FLOAT(viewx) * mult, -FIXED2FLOAT(viewz) * planemult , -FIXED2FLOAT(viewy)); gl_RenderState.mViewMatrix.translate(vx * mult, -vz * planemult , -vy);
gl_RenderState.mViewMatrix.scale(-mult, planemult, 1); gl_RenderState.mViewMatrix.scale(-mult, planemult, 1);
} }
@ -278,10 +278,10 @@ void FGLRenderer::SetViewMatrix(fixed_t viewx, fixed_t viewy, fixed_t viewz, boo
// Setup the view rotation matrix for the given viewpoint // Setup the view rotation matrix for the given viewpoint
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FGLRenderer::SetupView(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle, bool mirror, bool planemirror) void FGLRenderer::SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror)
{ {
SetViewAngle(viewangle); SetViewAngle(va);
SetViewMatrix(viewx, viewy, viewz, mirror, planemirror); SetViewMatrix(vx, vy, vz, mirror, planemirror);
gl_RenderState.ApplyMatrices(); gl_RenderState.ApplyMatrices();
} }
@ -305,6 +305,7 @@ void FGLRenderer::CreateScene()
for(unsigned i=0;i<portals.Size(); i++) portals[i]->glportal = NULL; for(unsigned i=0;i<portals.Size(); i++) portals[i]->glportal = NULL;
gl_spriteindex=0; gl_spriteindex=0;
Bsp.Clock(); Bsp.Clock();
R_SetView();
gl_RenderBSPNode (nodes + numnodes - 1); gl_RenderBSPNode (nodes + numnodes - 1);
Bsp.Unclock(); Bsp.Unclock();
@ -333,7 +334,7 @@ void FGLRenderer::RenderScene(int recursion)
glDepthMask(true); glDepthMask(true);
if (!gl_no_skyclear) GLPortal::RenderFirstSkyPortal(recursion); if (!gl_no_skyclear) GLPortal::RenderFirstSkyPortal(recursion);
gl_RenderState.SetCameraPos(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy), FIXED2FLOAT(viewz)); gl_RenderState.SetCameraPos(ViewPos.X, ViewPos.Y, ViewPos.Z);
gl_RenderState.EnableFog(true); gl_RenderState.EnableFog(true);
gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO);
@ -455,7 +456,7 @@ void FGLRenderer::RenderTranslucent()
RenderAll.Clock(); RenderAll.Clock();
glDepthMask(false); glDepthMask(false);
gl_RenderState.SetCameraPos(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy), FIXED2FLOAT(viewz)); gl_RenderState.SetCameraPos(ViewPos.X, ViewPos.Y, ViewPos.Z);
// final pass: translucent stuff // final pass: translucent stuff
gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold);
@ -567,13 +568,13 @@ void FGLRenderer::DrawBlend(sector_t * viewsector)
for (unsigned int i = 0; i < lightlist.Size(); i++) for (unsigned int i = 0; i < lightlist.Size(); i++)
{ {
fixed_t lightbottom; double lightbottom;
if (i < lightlist.Size() - 1) if (i < lightlist.Size() - 1)
lightbottom = lightlist[i + 1].plane.ZatPoint(viewx, viewy); lightbottom = lightlist[i + 1].plane.ZatPoint(ViewPos);
else else
lightbottom = viewsector->floorplane.ZatPoint(viewx, viewy); lightbottom = viewsector->floorplane.ZatPoint(ViewPos);
if (lightbottom < viewz && (!lightlist[i].caster || !(lightlist[i].caster->flags&FF_FADEWALLS))) if (lightbottom < ViewPos.Z && (!lightlist[i].caster || !(lightlist[i].caster->flags&FF_FADEWALLS)))
{ {
// 3d floor 'fog' is rendered as a blending value // 3d floor 'fog' is rendered as a blending value
blendv = lightlist[i].blend; blendv = lightlist[i].blend;
@ -706,7 +707,7 @@ void FGLRenderer::ProcessScene(bool toscreen)
iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0;
GLPortal::BeginScene(); GLPortal::BeginScene();
int mapsection = R_PointInSubsector(viewx, viewy)->mapsection; int mapsection = R_PointInSubsector(ViewPos)->mapsection;
memset(&currentmapsection[0], 0, currentmapsection.Size()); memset(&currentmapsection[0], 0, currentmapsection.Size());
currentmapsection[mapsection>>3] |= 1 << (mapsection & 7); currentmapsection[mapsection>>3] |= 1 << (mapsection & 7);
DrawScene(toscreen); DrawScene(toscreen);
@ -771,10 +772,7 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
SetViewArea(); SetViewArea();
// We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1. // We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1.
double radPitch = (viewpitch)* M_PI / 0x80000000; double radPitch = clamp(ViewPitch.Normalized180().Radians(), -PI / 2, PI / 2);
if (radPitch > PI) radPitch -= 2 * PI;
radPitch = clamp(radPitch, -PI / 2, PI / 2);
double angx = cos(radPitch); double angx = cos(radPitch);
double angy = sin(radPitch) * glset.pixelstretch; double angy = sin(radPitch) * glset.pixelstretch;
double alen = sqrt(angx*angx + angy*angy); double alen = sqrt(angx*angx + angy*angy);
@ -815,16 +813,16 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
// Stereo mode specific perspective projection // Stereo mode specific perspective projection
SetProjection( eye->GetProjection(fov, ratio, fovratio) ); SetProjection( eye->GetProjection(fov, ratio, fovratio) );
// SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper // SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper
SetViewAngle(viewangle); SetViewAngle(ViewAngle);
// Stereo mode specific viewpoint adjustment - temporarily shifts global viewx, viewy, viewz // Stereo mode specific viewpoint adjustment - temporarily shifts global viewx, viewy, viewz
eye->GetViewShift(GLRenderer->mAngles.Yaw.Degrees, viewShift); eye->GetViewShift(GLRenderer->mAngles.Yaw.Degrees, viewShift);
s3d::ScopedViewShifter viewShifter(viewShift); s3d::ScopedViewShifter viewShifter(viewShift);
SetViewMatrix(viewx, viewy, viewz, false, false); SetViewMatrix(ViewPos.X, ViewPos.Y, ViewPos.Z, false, false);
gl_RenderState.ApplyMatrices(); gl_RenderState.ApplyMatrices();
clipper.Clear(); clipper.Clear();
angle_t a1 = FrustumAngle(); angle_t a1 = FrustumAngle();
clipper.SafeAddClipRangeRealAngles(viewangle + a1, viewangle - a1); clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1);
ProcessScene(toscreen); ProcessScene(toscreen);
if (mainview) EndDrawScene(retval); // do not call this for camera textures. if (mainview) EndDrawScene(retval); // do not call this for camera textures.

View File

@ -173,8 +173,8 @@ void GLWall::SkyPlane(sector_t *sector, int plane, bool allowreflect)
} }
else if (allowreflect && sector->GetReflect(plane) > 0) else if (allowreflect && sector->GetReflect(plane) > 0)
{ {
if ((plane == sector_t::ceiling && FIXED2DBL(viewz) > sector->ceilingplane.fD()) || if ((plane == sector_t::ceiling && ViewPos.Z > sector->ceilingplane.fD()) ||
(plane == sector_t::floor && FIXED2DBL(viewz) < -sector->floorplane.fD())) return; (plane == sector_t::floor && ViewPos.Z < -sector->floorplane.fD())) return;
ptype = PORTALTYPE_PLANEMIRROR; ptype = PORTALTYPE_PLANEMIRROR;
planemirror = plane == sector_t::ceiling ? &sector->ceilingplane : &sector->floorplane; planemirror = plane == sector_t::ceiling ? &sector->ceilingplane : &sector->floorplane;
} }
@ -361,7 +361,7 @@ void GLWall::SkyBottom(seg_t * seg,sector_t * fs,sector_t * bs,vertex_t * v1,ver
else else
{ {
// Special hack for Vrack2b // Special hack for Vrack2b
if (bs->floorplane.ZatPoint(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy)) > FIXED2FLOAT(viewz)) return; if (bs->floorplane.ZatPoint(ViewPos) > ViewPos.Z) return;
} }
} }
zbottom[0]=zbottom[1]=-32768.0f; zbottom[0]=zbottom[1]=-32768.0f;

View File

@ -41,6 +41,7 @@
#include "sc_man.h" #include "sc_man.h"
#include "w_wad.h" #include "w_wad.h"
#include "r_state.h" #include "r_state.h"
#include "r_utility.h"
//#include "gl/gl_intern.h" //#include "gl/gl_intern.h"
#include "gl/system/gl_interface.h" #include "gl/system/gl_interface.h"
@ -492,7 +493,7 @@ void GLSkyPortal::DrawContents()
bool oldClamp = gl_RenderState.SetDepthClamp(true); bool oldClamp = gl_RenderState.SetDepthClamp(true);
gl_MatrixStack.Push(gl_RenderState.mViewMatrix); gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
GLRenderer->SetupView(0, 0, 0, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); GLRenderer->SetupView(0, 0, 0, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox) if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox)
{ {

View File

@ -154,10 +154,7 @@ void GLSprite::Draw(int pass)
// fog + fuzz don't work well without some fiddling with the alpha value! // fog + fuzz don't work well without some fiddling with the alpha value!
if (!gl_isBlack(Colormap.FadeColor)) if (!gl_isBlack(Colormap.FadeColor))
{ {
float xcamera=FIXED2FLOAT(viewx); float dist=Dist2(ViewPos.X, ViewPos.Y, x,y);
float ycamera=FIXED2FLOAT(viewy);
float dist=Dist2(xcamera,ycamera, x,y);
if (!Colormap.FadeColor.a) Colormap.FadeColor.a=clamp<int>(255-lightlevel,60,255); if (!Colormap.FadeColor.a) Colormap.FadeColor.a=clamp<int>(255-lightlevel,60,255);
@ -397,8 +394,8 @@ void GLSprite::PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_
for (unsigned int i = 0; i < x.ffloors.Size(); i++) for (unsigned int i = 0; i < x.ffloors.Size(); i++)
{ {
F3DFloor * ff = x.ffloors[i]; F3DFloor * ff = x.ffloors[i];
float floorh = FIXED2FLOAT(ff->top.plane->ZatPoint(thingx, thingy)); float floorh = FIXED2FLOAT(ff->top.plane->ZatPointFixed(thingx, thingy));
float ceilingh = FIXED2FLOAT(ff->bottom.plane->ZatPoint(thingx, thingy)); float ceilingh = FIXED2FLOAT(ff->bottom.plane->ZatPointFixed(thingx, thingy));
if (floorh == thing->floorz) if (floorh == thing->floorz)
{ {
btm = floorh; btm = floorh;
@ -416,7 +413,7 @@ void GLSprite::PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_
else if (thing->Sector->heightsec && !(thing->Sector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC)) else if (thing->Sector->heightsec && !(thing->Sector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC))
{ {
if (thing->flags2&MF2_ONMOBJ && thing->floorz == if (thing->flags2&MF2_ONMOBJ && thing->floorz ==
FIXED2FLOAT(thing->Sector->heightsec->floorplane.ZatPoint(thingx, thingy))) FIXED2FLOAT(thing->Sector->heightsec->floorplane.ZatPointFixed(thingx, thingy)))
{ {
btm = thing->floorz; btm = thing->floorz;
top = thing->ceilingz; top = thing->ceilingz;
@ -425,7 +422,7 @@ void GLSprite::PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_
if (btm == 1000000.0f) if (btm == 1000000.0f)
btm = thing->Sector->floorplane.ZatPoint(thing) - thing->Floorclip; btm = thing->Sector->floorplane.ZatPoint(thing) - thing->Floorclip;
if (top == -1000000.0f) if (top == -1000000.0f)
top = FIXED2FLOAT(thing->Sector->ceilingplane.ZatPoint(thingx, thingy)); top = FIXED2FLOAT(thing->Sector->ceilingplane.ZatPointFixed(thingx, thingy));
// +/-1 to account for the one pixel empty frame around the sprite. // +/-1 to account for the one pixel empty frame around the sprite.
float diffb = (z2+1) - btm; float diffb = (z2+1) - btm;
@ -512,9 +509,9 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
DVector3 thingpos = thing->InterpolatedPosition(r_TicFracF); DVector3 thingpos = thing->InterpolatedPosition(r_TicFracF);
// Too close to the camera. This doesn't look good if it is a sprite. // Too close to the camera. This doesn't look good if it is a sprite.
if (fabs(thingpos.X - FIXED2DBL(viewx) < 2 && fabs(thingpos.Y - FIXED2DBL(viewy) < 2))) if (fabs(thingpos.X - ViewPos.X) < 2 && fabs(thingpos.Y - ViewPos.Y) < 2)
{ {
if (FIXED2DBL(viewz) >= thingpos.Z - 2 && FIXED2DBL(viewz) <= thingpos.Z + thing->Height + 2) if (ViewPos.Z >= thingpos.Z - 2 && ViewPos.Z <= thingpos.Z + thing->Height + 2)
{ {
// exclude vertically moving objects from this check. // exclude vertically moving objects from this check.
if (!thing->Vel.isZero()) if (!thing->Vel.isZero())
@ -533,14 +530,14 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
if (!(thing->flags7 & MF7_FLYCHEAT) && thing->target==GLRenderer->mViewActor && GLRenderer->mViewActor != NULL) if (!(thing->flags7 & MF7_FLYCHEAT) && thing->target==GLRenderer->mViewActor && GLRenderer->mViewActor != NULL)
{ {
double clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius*2); double clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius*2);
if (P_AproxDistance(thingpos.X-viewx, thingpos.Y-viewy) < clipdist) return; if ((thingpos-ViewPos).LengthSquared() < clipdist * clipdist) return;
} }
thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again. thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again.
} }
if (GLRenderer->mCurrentPortal) if (GLRenderer->mCurrentPortal)
{ {
int clipres = GLRenderer->mCurrentPortal->ClipPoint(FLOAT2FIXED(thingpos.X), FLOAT2FIXED(thingpos.Y)); int clipres = GLRenderer->mCurrentPortal->ClipPoint(thingpos);
if (clipres == GLPortal::PClip_InFront) return; if (clipres == GLPortal::PClip_InFront) return;
} }
@ -571,10 +568,9 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
modelframe = gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); modelframe = gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED));
if (!modelframe) if (!modelframe)
{ {
angle_t ang = R_PointToAngle(FLOAT2FIXED(thingpos.X), FLOAT2FIXED(thingpos.Y));
bool mirror; bool mirror;
FTextureID patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, ang - thing->Angles.Yaw.BAMs(), &mirror); DAngle ang = (thingpos - ViewPos).Angle();
FTextureID patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (ang - thing->Angles.Yaw).BAMs(), &mirror);
if (!patch.isValid()) return; if (!patch.isValid()) return;
int type = thing->renderflags & RF_SPRITETYPEMASK; int type = thing->renderflags & RF_SPRITETYPEMASK;
gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false); gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false);
@ -644,7 +640,7 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
gltexture=NULL; gltexture=NULL;
} }
depth = DMulScale20 (FLOAT2FIXED(thingpos.X)-viewx, viewtancos, FLOAT2FIXED(thingpos.Y)-viewy, viewtansin); depth = (int)((x - ViewPos.X) * viewtancos + (y - ViewPos.Y) * viewtansin);
// light calculation // light calculation
@ -841,7 +837,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
{ {
if (GLRenderer->mCurrentPortal) if (GLRenderer->mCurrentPortal)
{ {
int clipres = GLRenderer->mCurrentPortal->ClipPoint(particle->x, particle->y); int clipres = GLRenderer->mCurrentPortal->ClipPoint(particle->Pos);
if (clipres == GLPortal::PClip_InFront) return; if (clipres == GLPortal::PClip_InFront) return;
} }
@ -860,15 +856,15 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
else if (!particle->bright) else if (!particle->bright)
{ {
TArray<lightlist_t> & lightlist=sector->e->XFloor.lightlist; TArray<lightlist_t> & lightlist=sector->e->XFloor.lightlist;
int lightbottom; double lightbottom;
Colormap = sector->ColorMap; Colormap = sector->ColorMap;
for(unsigned int i=0;i<lightlist.Size();i++) for(unsigned int i=0;i<lightlist.Size();i++)
{ {
if (i<lightlist.Size()-1) lightbottom = lightlist[i+1].plane.ZatPoint(particle->x,particle->y); if (i<lightlist.Size()-1) lightbottom = lightlist[i+1].plane.ZatPoint(particle->Pos);
else lightbottom = sector->floorplane.ZatPoint(particle->x,particle->y); else lightbottom = sector->floorplane.ZatPoint(particle->Pos);
if (lightbottom < particle->y) if (lightbottom < particle->Pos.Z)
{ {
lightlevel = *lightlist[i].p_lightlevel; lightlevel = *lightlist[i].p_lightlevel;
Colormap.LightColor = (lightlist[i].extra_colormap)->Color; Colormap.LightColor = (lightlist[i].extra_colormap)->Color;
@ -920,9 +916,9 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
} }
} }
x= FIXED2FLOAT(particle->x); x = particle->Pos.X;
y= FIXED2FLOAT(particle->y); y = particle->Pos.Y;
z= FIXED2FLOAT(particle->z); z = particle->Pos.Z;
float scalefac=particle->size/4.0f; float scalefac=particle->size/4.0f;
// [BB] The smooth particles are smaller than the other ones. Compensate for this here. // [BB] The smooth particles are smaller than the other ones. Compensate for this here.
@ -939,7 +935,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
z1=z-scalefac; z1=z-scalefac;
z2=z+scalefac; z2=z+scalefac;
depth = DMulScale20 (particle->x-viewx, viewtancos, particle->y-viewy, viewtansin); depth = (int)((x - ViewPos.X) * viewtancos + (y - ViewPos.Y) * viewtansin);
actor=NULL; actor=NULL;
this->particle=particle; this->particle=particle;

View File

@ -142,6 +142,6 @@ void gl_SetDynSpriteLight(AActor *thing, particle_t *particle)
} }
else if (particle != NULL) else if (particle != NULL)
{ {
gl_SetDynSpriteLight(NULL, FIXED2FLOAT(particle->x), FIXED2FLOAT(particle->y), FIXED2FLOAT(particle->z), particle->subsector); gl_SetDynSpriteLight(NULL, particle->Pos.X, particle->Pos.Y, particle->Pos.Z, particle->subsector);
} }
} }

View File

@ -128,7 +128,7 @@ public:
FColormap Colormap; FColormap Colormap;
ERenderStyle RenderStyle; ERenderStyle RenderStyle;
fixed_t viewdistance; float ViewDistance;
TArray<lightlist_t> *lightlist; TArray<lightlist_t> *lightlist;
int lightlevel; int lightlevel;

View File

@ -134,8 +134,7 @@ void GLWall::PutWall(bool translucent)
if (translucent) // translucent walls if (translucent) // translucent walls
{ {
viewdistance = P_AproxDistance(((seg->linedef->v1->fX() + seg->linedef->v2->fX()) /2) - viewx, ViewDistance = (ViewPos - (seg->linedef->v1->fPos() + seg->linedef->Delta() / 2)).XY().LengthSquared();
((seg->linedef->v1->fY() + seg->linedef->v2->fY()) /2) - viewy);
gl_drawinfo->drawlists[GLDL_TRANSLUCENT].AddWall(this); gl_drawinfo->drawlists[GLDL_TRANSLUCENT].AddWall(this);
} }
else else
@ -370,13 +369,13 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2)
lightlist_t * light; lightlist_t * light;
// ZDoom doesn't support slopes in a horizon sector so I won't either! // ZDoom doesn't support slopes in a horizon sector so I won't either!
ztop[1] = ztop[0] = FIXED2FLOAT(fs->GetPlaneTexZ(sector_t::ceiling)); ztop[1] = ztop[0] = fs->GetPlaneTexZF(sector_t::ceiling);
zbottom[1] = zbottom[0] = FIXED2FLOAT(fs->GetPlaneTexZ(sector_t::floor)); zbottom[1] = zbottom[0] = fs->GetPlaneTexZF(sector_t::floor);
if (viewz < fs->GetPlaneTexZ(sector_t::ceiling)) if (ViewPos.Z < fs->GetPlaneTexZF(sector_t::ceiling))
{ {
if (viewz > fs->GetPlaneTexZ(sector_t::floor)) if (ViewPos.Z > fs->GetPlaneTexZF(sector_t::floor))
zbottom[1] = zbottom[0] = FIXED2FLOAT(viewz); zbottom[1] = zbottom[0] = ViewPos.Z;
if (fs->GetTexture(sector_t::ceiling) == skyflatnum) if (fs->GetTexture(sector_t::ceiling) == skyflatnum)
{ {
@ -1105,8 +1104,8 @@ __forceinline void GLWall::GetPlanePos(F3DFloor::planeref *planeref, fixed_t &le
{ {
if (planeref->plane->isSlope()) if (planeref->plane->isSlope())
{ {
left=planeref->plane->ZatPoint(vertexes[0]->x, vertexes[0]->y); left=planeref->plane->ZatPointFixed(vertexes[0]);
right=planeref->plane->ZatPoint(vertexes[1]->x, vertexes[1]->y); right=planeref->plane->ZatPointFixed(vertexes[1]);
} }
else if(planeref->isceiling == sector_t::ceiling) else if(planeref->isceiling == sector_t::ceiling)
{ {
@ -1452,8 +1451,8 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector)
// Save a little time (up to 0.3 ms per frame ;) ) // Save a little time (up to 0.3 ms per frame ;) )
if (frontsector->floorplane.isSlope()) if (frontsector->floorplane.isSlope())
{ {
ffh1 = segfront->floorplane.ZatPoint(v1->x, v1->y); ffh1 = segfront->floorplane.ZatPointFixed(v1);
ffh2 = segfront->floorplane.ZatPoint(v2->x, v2->y); ffh2 = segfront->floorplane.ZatPointFixed(v2);
zfloor[0] = FIXED2FLOAT(ffh1); zfloor[0] = FIXED2FLOAT(ffh1);
zfloor[1] = FIXED2FLOAT(ffh2); zfloor[1] = FIXED2FLOAT(ffh2);
} }
@ -1465,8 +1464,8 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector)
if (segfront->ceilingplane.isSlope()) if (segfront->ceilingplane.isSlope())
{ {
fch1 = segfront->ceilingplane.ZatPoint(v1->x, v1->y); fch1 = segfront->ceilingplane.ZatPointFixed(v1);
fch2 = segfront->ceilingplane.ZatPoint(v2->x, v2->y); fch2 = segfront->ceilingplane.ZatPointFixed(v2);
zceil[0] = FIXED2FLOAT(fch1); zceil[0] = FIXED2FLOAT(fch1);
zceil[1] = FIXED2FLOAT(fch2); zceil[1] = FIXED2FLOAT(fch2);
} }
@ -1522,8 +1521,8 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector)
if (segback->floorplane.isSlope()) if (segback->floorplane.isSlope())
{ {
bfh1 = segback->floorplane.ZatPoint(v1->x, v1->y); bfh1 = segback->floorplane.ZatPointFixed(v1);
bfh2 = segback->floorplane.ZatPoint(v2->x, v2->y); bfh2 = segback->floorplane.ZatPointFixed(v2);
} }
else else
{ {
@ -1532,8 +1531,8 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector)
if (segback->ceilingplane.isSlope()) if (segback->ceilingplane.isSlope())
{ {
bch1 = segback->ceilingplane.ZatPoint(v1->x, v1->y); bch1 = segback->ceilingplane.ZatPointFixed(v1);
bch2 = segback->ceilingplane.ZatPoint(v2->x, v2->y); bch2 = segback->ceilingplane.ZatPointFixed(v2);
} }
else else
{ {

View File

@ -258,15 +258,15 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
TArray<lightlist_t> & lightlist = viewsector->e->XFloor.lightlist; TArray<lightlist_t> & lightlist = viewsector->e->XFloor.lightlist;
for(i=0;i<lightlist.Size();i++) for(i=0;i<lightlist.Size();i++)
{ {
int lightbottom; double lightbottom;
if (i<lightlist.Size()-1) if (i<lightlist.Size()-1)
{ {
lightbottom=lightlist[i+1].plane.ZatPoint(viewx,viewy); lightbottom=lightlist[i+1].plane.ZatPoint(ViewPos);
} }
else else
{ {
lightbottom=viewsector->floorplane.ZatPoint(viewx,viewy); lightbottom=viewsector->floorplane.ZatPoint(ViewPos);
} }
if (lightbottom<player->viewz) if (lightbottom<player->viewz)

View File

@ -42,24 +42,15 @@ namespace s3d {
ScopedViewShifter::ScopedViewShifter(float dxyz[3]) // in meters ScopedViewShifter::ScopedViewShifter(float dxyz[3]) // in meters
{ {
// save original values // save original values
cachedViewx = viewx; cachedView = ViewPos;
cachedViewy = viewy;
cachedViewz = viewz;
// modify values // modify values
float fViewx = FIXED2FLOAT(viewx) - dxyz[0]; ViewPos += DVector3(dxyz[0], dxyz[1], dxyz[2]);
float fViewy = FIXED2FLOAT(viewy) + dxyz[1];
float fViewz = FIXED2FLOAT(viewz) + dxyz[2];
viewx = FLOAT2FIXED(fViewx);
viewy = FLOAT2FIXED(fViewy);
viewz = FLOAT2FIXED(fViewz);
} }
ScopedViewShifter::~ScopedViewShifter() ScopedViewShifter::~ScopedViewShifter()
{ {
// restore original values // restore original values
viewx = cachedViewx; ViewPos = cachedView;
viewy = cachedViewy;
viewz = cachedViewz;
} }
} }

View File

@ -38,6 +38,7 @@
#define GL_STEREO3D_SCOPED_VIEW_SHIFTER_H_ #define GL_STEREO3D_SCOPED_VIEW_SHIFTER_H_
#include "basictypes.h" #include "basictypes.h"
#include "vectors.h"
namespace s3d { namespace s3d {
@ -51,9 +52,7 @@ namespace s3d {
~ScopedViewShifter(); ~ScopedViewShifter();
private: private:
fixed_t cachedViewx; DVector3 cachedView;
fixed_t cachedViewy;
fixed_t cachedViewz;
}; };
} /* namespace s3d */ } /* namespace s3d */

View File

@ -184,9 +184,8 @@ void CheckBench()
FString compose; FString compose;
compose.Format("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n", compose.Format("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n",
level.MapName.GetChars(), level.LevelName.GetChars(), FIXED2FLOAT(viewx), FIXED2FLOAT(viewy), FIXED2FLOAT(viewz), level.MapName.GetChars(), level.LevelName.GetChars(), ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle.Degrees, ViewPitch.Degrees);
AngleToFloat(viewangle), AngleToFloat(viewpitch));
AppendRenderStats(compose); AppendRenderStats(compose);
AppendRenderTimes(compose); AppendRenderTimes(compose);
AppendLightStats(compose); AppendLightStats(compose);

View File

@ -902,7 +902,6 @@ struct sector_t
return FIXED2DBL(planes[pos].TexZ); return FIXED2DBL(planes[pos].TexZ);
} }
void SetPlaneTexZ(int pos, double val)
void SetPlaneTexZ(int pos, double val, bool dirtify = false) // This mainly gets used by init code. The only place where it must set the vertex to dirty is the interpolation code. void SetPlaneTexZ(int pos, double val, bool dirtify = false) // This mainly gets used by init code. The only place where it must set the vertex to dirty is the interpolation code.
{ {
planes[pos].TexZ = FLOAT2FIXED(val); planes[pos].TexZ = FLOAT2FIXED(val);