From 0c9014b9841bdc40f3bea9cbcce19f38e72078be Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 11 Mar 2017 23:28:07 +0100 Subject: [PATCH] - move r_utility globals into r_viewpoint and r_viewwindow - change r_utility functions to only work on FRenderViewpoint and FViewWindow --- src/am_map.cpp | 6 +- src/d_main.cpp | 6 +- src/events.cpp | 12 +- src/g_game.cpp | 2 +- src/g_shared/a_quake.cpp | 2 +- src/g_shared/shared_hud.cpp | 6 +- src/g_statusbar/shared_sbar.cpp | 2 +- src/g_statusbar/strife_sbar.cpp | 4 +- src/gl/compatibility/gl_20.cpp | 4 +- src/gl/data/gl_data.h | 4 +- src/gl/models/gl_models.cpp | 2 +- src/gl/scene/gl_bsp.cpp | 4 +- src/gl/scene/gl_clipper.cpp | 12 +- src/gl/scene/gl_drawinfo.cpp | 16 +- src/gl/scene/gl_flats.cpp | 12 +- src/gl/scene/gl_portal.cpp | 154 ++++++------ src/gl/scene/gl_portal.h | 2 +- src/gl/scene/gl_renderhacks.cpp | 12 +- src/gl/scene/gl_scene.cpp | 63 +++-- src/gl/scene/gl_sky.cpp | 6 +- src/gl/scene/gl_skydome.cpp | 2 +- src/gl/scene/gl_sprite.cpp | 39 +-- src/gl/scene/gl_walls.cpp | 10 +- src/gl/scene/gl_weapon.cpp | 18 +- src/gl/stereo3d/scoped_view_shifter.cpp | 6 +- src/gl/textures/gl_material.cpp | 4 +- src/gl/utility/gl_clock.cpp | 2 +- src/p_effect.cpp | 2 +- src/p_mobj.cpp | 2 +- src/polyrenderer/math/tri_matrix.cpp | 12 +- src/polyrenderer/poly_renderer.cpp | 31 ++- src/polyrenderer/scene/poly_cull.cpp | 24 +- src/polyrenderer/scene/poly_decal.cpp | 2 +- src/polyrenderer/scene/poly_particle.cpp | 6 +- src/polyrenderer/scene/poly_plane.cpp | 14 +- src/polyrenderer/scene/poly_playersprite.cpp | 32 +-- src/polyrenderer/scene/poly_portal.cpp | 142 ++++++----- src/polyrenderer/scene/poly_portal.h | 4 +- src/polyrenderer/scene/poly_scene.cpp | 6 +- src/polyrenderer/scene/poly_sky.cpp | 2 +- src/polyrenderer/scene/poly_sprite.cpp | 26 +- src/polyrenderer/scene/poly_wall.cpp | 2 +- src/polyrenderer/scene/poly_wallsprite.cpp | 6 +- src/r_sky.cpp | 4 +- src/r_utility.cpp | 245 +++++++++---------- src/r_utility.h | 47 ++-- src/swrenderer/drawers/r_draw_pal.cpp | 6 +- src/swrenderer/drawers/r_draw_rgba.cpp | 6 +- src/swrenderer/line/r_line.cpp | 68 ++--- src/swrenderer/line/r_renderdrawsegment.cpp | 30 +-- src/swrenderer/line/r_walldraw.cpp | 22 +- src/swrenderer/line/r_wallsetup.cpp | 10 +- src/swrenderer/plane/r_flatplane.cpp | 22 +- src/swrenderer/plane/r_skyplane.cpp | 4 +- src/swrenderer/plane/r_slopeplane.cpp | 16 +- src/swrenderer/plane/r_visibleplanelist.cpp | 18 +- src/swrenderer/r_swrenderer.cpp | 6 +- src/swrenderer/scene/r_3dfloors.cpp | 2 +- src/swrenderer/scene/r_light.cpp | 15 +- src/swrenderer/scene/r_light.h | 4 +- src/swrenderer/scene/r_opaque_pass.cpp | 54 ++-- src/swrenderer/scene/r_portal.cpp | 114 ++++----- src/swrenderer/scene/r_portal.h | 2 +- src/swrenderer/scene/r_scene.cpp | 16 +- src/swrenderer/scene/r_translucent_pass.cpp | 4 +- src/swrenderer/things/r_decal.cpp | 6 +- src/swrenderer/things/r_particle.cpp | 16 +- src/swrenderer/things/r_playersprite.cpp | 46 ++-- src/swrenderer/things/r_sprite.cpp | 22 +- src/swrenderer/things/r_visiblesprite.cpp | 14 +- src/swrenderer/things/r_voxel.cpp | 40 +-- src/swrenderer/things/r_wallsprite.cpp | 12 +- src/swrenderer/viewport/r_viewport.cpp | 44 ++-- src/textures/warptexture.cpp | 8 +- src/win32/i_main.cpp | 8 +- 75 files changed, 817 insertions(+), 839 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index ba7c301d8d..f0108c81b3 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -1959,13 +1959,13 @@ void AM_drawSubsectors() double secx; double secy; double seczb, seczt; - double cmpz = ViewPos.Z; + double cmpz = r_viewpoint.Pos.Z; if (players[consoleplayer].camera && sec == players[consoleplayer].camera->Sector) { // For the actual camera sector use the current viewpoint as reference. - secx = ViewPos.X; - secy = ViewPos.Y; + secx = r_viewpoint.Pos.X; + secy = r_viewpoint.Pos.Y; } else { diff --git a/src/d_main.cpp b/src/d_main.cpp index 0da9cfdad6..a706bb5384 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -111,6 +111,7 @@ #include "fragglescript/t_fs.h" #include "g_levellocals.h" #include "events.h" +#include "r_utility.h" EXTERN_CVAR(Bool, hud_althud) void DrawHUD(); @@ -124,7 +125,6 @@ void DrawHUD(); extern void ReadStatistics(); extern void M_RestoreMode (); extern void M_SetDefaultMode (); -extern void R_ExecuteSetViewSize (); extern void G_NewInit (); extern void SetupPlayerClasses (); extern void HUD_InitHud(); @@ -670,7 +670,7 @@ void D_Display () if (viewactive) { - R_SetFOV (players[consoleplayer].camera && players[consoleplayer].camera->player ? + R_SetFOV (r_viewpoint, players[consoleplayer].camera && players[consoleplayer].camera->player ? players[consoleplayer].camera->player->FOV : 90.f); } @@ -700,7 +700,7 @@ void D_Display () // change the view size if needed if (setsizeneeded && StatusBar != NULL) { - R_ExecuteSetViewSize (); + R_ExecuteSetViewSize (r_viewpoint, r_viewwindow); } setmodeneeded = false; diff --git a/src/events.cpp b/src/events.cpp index bd2b512ce1..5a40a39835 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -776,12 +776,12 @@ void DStaticEventHandler::WorldTick() static FRenderEvent E_SetupRenderEvent() { FRenderEvent e; - e.ViewPos = ::ViewPos; - e.ViewAngle = ::ViewAngle; - e.ViewPitch = ::ViewPitch; - e.ViewRoll = ::ViewRoll; - e.FracTic = ::r_TicFracF; - e.Camera = ::camera; + e.ViewPos = r_viewpoint.Pos; + e.ViewAngle = r_viewpoint.Angles.Yaw; + e.ViewPitch = r_viewpoint.Angles.Pitch; + e.ViewRoll = r_viewpoint.Angles.Roll; + e.FracTic = r_viewpoint.TicFrac; + e.Camera = r_viewpoint.camera; return e; } diff --git a/src/g_game.cpp b/src/g_game.cpp index ad10555ee8..11c5210e52 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -233,7 +233,7 @@ FString shotfile; AActor* bodyque[BODYQUESIZE]; int bodyqueslot; -void R_ExecuteSetViewSize (void); +void R_ExecuteSetViewSize (FViewWindow &viewwindow); FString savename; FString BackupSaveName; diff --git a/src/g_shared/a_quake.cpp b/src/g_shared/a_quake.cpp index 6835cefeb8..feb7e62560 100644 --- a/src/g_shared/a_quake.cpp +++ b/src/g_shared/a_quake.cpp @@ -159,7 +159,7 @@ void DEarthquake::Tick () double DEarthquake::GetModWave(double waveMultiplier) const { - double time = m_Countdown - r_TicFracF; + double time = m_Countdown - r_viewpoint.TicFrac; return g_sin(waveMultiplier * time * (M_PI * 2 / TICRATE)); } diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 97b1b54d6e..f4a3d2c6eb 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -1101,13 +1101,13 @@ void DrawHUD() } else { - if (AspectTallerThanWide(WidescreenRatio)) + if (AspectTallerThanWide(r_viewwindow.WidescreenRatio)) { - hudheight = hudwidth * 30 / AspectMultiplier(WidescreenRatio); // BaseRatioSizes is inverted for this mode + hudheight = hudwidth * 30 / AspectMultiplier(r_viewwindow.WidescreenRatio); // BaseRatioSizes is inverted for this mode } else { - hudheight = hudwidth * 30 / (48*48/AspectMultiplier(WidescreenRatio)); + hudheight = hudwidth * 30 / (48*48/AspectMultiplier(r_viewwindow.WidescreenRatio)); } } } diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index db3b5deb5a..7be5073ef1 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -611,7 +611,7 @@ void DBaseStatusBar::DrawCrosshair () ST_LoadCrosshair(); // Don't draw the crosshair if there is none - if (CrosshairImage == NULL || gamestate == GS_TITLELEVEL || camera->health <= 0) + if (CrosshairImage == NULL || gamestate == GS_TITLELEVEL || r_viewpoint.camera->health <= 0) { return; } diff --git a/src/g_statusbar/strife_sbar.cpp b/src/g_statusbar/strife_sbar.cpp index e0bf96dcea..13410e8f86 100644 --- a/src/g_statusbar/strife_sbar.cpp +++ b/src/g_statusbar/strife_sbar.cpp @@ -557,7 +557,7 @@ private: int bars = (CurrentPop == POP_Status) ? imgINVPOP : imgINVPOP2; int back = (CurrentPop == POP_Status) ? imgINVPBAK : imgINVPBAK2; // Extrapolate the height of the popscreen for smoother movement - int height = clamp (PopHeight + int(r_TicFracF * PopHeightChange), -POP_HEIGHT, 0); + int height = clamp (PopHeight + int(r_viewpoint.TicFrac * PopHeightChange), -POP_HEIGHT, 0); xscale = CleanXfac; yscale = CleanYfac; @@ -608,7 +608,7 @@ private: if (KeyPopScroll > 0) { // Extrapolate the scroll position for smoother scrolling - int scroll = MAX (0,KeyPopScroll - int(r_TicFracF * (280./KEY_TIME))); + int scroll = MAX (0,KeyPopScroll - int(r_viewpoint.TicFrac * (280./KEY_TIME))); pos -= 10; leftcol = leftcol - 280 + scroll; } diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 923c3e9895..66a7bc5f9a 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -518,8 +518,8 @@ void GLWall::RenderFogBoundaryCompat() // as the shader version but it's an acceptable compromise. float fogdensity = gl_GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.fogdensity); - float dist1 = Dist2(ViewPos.X, ViewPos.Y, glseg.x1, glseg.y1); - float dist2 = Dist2(ViewPos.X, ViewPos.Y, glseg.x2, glseg.y2); + float dist1 = Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, glseg.x1, glseg.y1); + float dist2 = Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, glseg.x2, glseg.y2); // these values were determined by trial and error and are scale dependent! float fogd1 = (0.95f - exp(-fogdensity*dist1 / 62500.f)) * 1.05f; diff --git a/src/gl/data/gl_data.h b/src/gl/data/gl_data.h index 5173e56c11..f4fb4815aa 100644 --- a/src/gl/data/gl_data.h +++ b/src/gl/data/gl_data.h @@ -4,6 +4,7 @@ #include "doomtype.h" #include "vectors.h" +#include "r_utility.h" struct GLRenderSettings { @@ -36,12 +37,11 @@ extern GLRenderSettings glset; #include "a_sharedglobal.h" #include "c_cvars.h" -extern int extralight; EXTERN_CVAR(Int, gl_weaponlight); inline int getExtraLight() { - return extralight * gl_weaponlight; + return r_viewpoint.extralight * gl_weaponlight; } void gl_RecalcVertexHeights(vertex_t * v); diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index fe974f4dfd..b8dcc8c7ca 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -1023,7 +1023,7 @@ void gl_RenderModel(GLSprite * spr) if (spr->actor->renderflags & RF_INTERPOLATEANGLES) { // [Nash] use interpolated angles - DRotator Angles = spr->actor->InterpolatedAngles(r_TicFracF); + DRotator Angles = spr->actor->InterpolatedAngles(r_viewpoint.TicFrac); angle = Angles.Yaw.Degrees; } diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index 86efce9920..853fc7d693 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -374,7 +374,7 @@ static inline void RenderThings(subsector_t * sub, sector_t * sector) FIntCVar *cvar = thing->GetClass()->distancecheck; if (cvar != NULL && *cvar >= 0) { - double dist = (thing->Pos() - ViewPos).LengthSquared(); + double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) { @@ -391,7 +391,7 @@ static inline void RenderThings(subsector_t * sub, sector_t * sector) FIntCVar *cvar = thing->GetClass()->distancecheck; if (cvar != NULL && *cvar >= 0) { - double dist = (thing->Pos() - ViewPos).LengthSquared(); + double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) { diff --git a/src/gl/scene/gl_clipper.cpp b/src/gl/scene/gl_clipper.cpp index f1d79c7274..7e74d7ac3d 100644 --- a/src/gl/scene/gl_clipper.cpp +++ b/src/gl/scene/gl_clipper.cpp @@ -393,14 +393,14 @@ fixed_t viewx, viewy; void R_SetView() { - viewx = FLOAT2FIXED(ViewPos.X); - viewy = FLOAT2FIXED(ViewPos.Y); + viewx = FLOAT2FIXED(r_viewpoint.Pos.X); + viewy = FLOAT2FIXED(r_viewpoint.Pos.Y); } angle_t R_PointToPseudoAngle(double x, double y) { - double vecx = x - ViewPos.X; - double vecy = y - ViewPos.Y; + double vecx = x - r_viewpoint.Pos.X; + double vecy = y - r_viewpoint.Pos.Y; if (vecx == 0 && vecy == 0) { @@ -451,8 +451,8 @@ bool Clipper::CheckBox(const float *bspcoord) // Find the corners of the box // that define the edges from current viewpoint. - boxpos = (ViewPos.X <= bspcoord[BOXLEFT] ? 0 : ViewPos.X < bspcoord[BOXRIGHT ] ? 1 : 2) + - (ViewPos.Y >= bspcoord[BOXTOP ] ? 0 : ViewPos.Y > bspcoord[BOXBOTTOM] ? 4 : 8); + boxpos = (r_viewpoint.Pos.X <= bspcoord[BOXLEFT] ? 0 : r_viewpoint.Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) + + (r_viewpoint.Pos.Y >= bspcoord[BOXTOP ] ? 0 : r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8); if (boxpos == 5) return true; diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 7e9a3e6d28..a3de4b1cc9 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -299,7 +299,7 @@ void GLDrawList::SortWallIntoPlane(SortNode * head,SortNode * sort) GLFlat * fh=&flats[drawitems[head->itemindex].index]; GLWall * ws=&walls[drawitems[sort->itemindex].index]; - bool ceiling = fh->z > ViewPos.Z; + bool ceiling = fh->z > r_viewpoint.Pos.Z; if ((ws->ztop[0] > fh->z || ws->ztop[1] > fh->z) && (ws->zbottom[0] < fh->z || ws->zbottom[1] < fh->z)) { @@ -362,7 +362,7 @@ void GLDrawList::SortSpriteIntoPlane(SortNode * head,SortNode * sort) GLFlat * fh=&flats[drawitems[head->itemindex].index]; GLSprite * ss=&sprites[drawitems[sort->itemindex].index]; - bool ceiling = fh->z > ViewPos.Z; + bool ceiling = fh->z > r_viewpoint.Pos.Z; if ((ss->z1>fh->z && ss->z2z) || ss->modelframe) { @@ -770,7 +770,7 @@ void GLDrawList::DoDrawSorted(SortNode * head) if (drawitems[head->itemindex].rendertype == GLDIT_FLAT) { z = flats[drawitems[head->itemindex].index].z; - relation = z > ViewPos.Z ? 1 : -1; + relation = z > r_viewpoint.Pos.Z ? 1 : -1; } @@ -1186,9 +1186,9 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo gl_SetFog(lightlevel, rel, &Colormap, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); - float fviewx = ViewPos.X; - float fviewy = ViewPos.Y; - float fviewz = ViewPos.Z; + float fviewx = r_viewpoint.Pos.X; + float fviewy = r_viewpoint.Pos.Y; + float fviewz = r_viewpoint.Pos.Z; gl_SetPlaneTextureRotation(&plane, gltexture); gl_RenderState.Apply(); @@ -1239,7 +1239,7 @@ void FDrawInfo::FloodUpperGap(seg_t * seg) double frontz = fakefsector->ceilingplane.ZatPoint(seg->v1); if (fakebsector->GetTexture(sector_t::ceiling)==skyflatnum) return; - if (backz < ViewPos.Z) return; + if (backz < r_viewpoint.Pos.Z) return; if (seg->sidedef == seg->linedef->sidedef[0]) { @@ -1292,7 +1292,7 @@ void FDrawInfo::FloodLowerGap(seg_t * seg) if (fakebsector->GetTexture(sector_t::floor) == skyflatnum) return; - if (fakebsector->GetPlaneTexZ(sector_t::floor) > ViewPos.Z) return; + if (fakebsector->GetPlaneTexZ(sector_t::floor) > r_viewpoint.Pos.Z) return; if (seg->sidedef == seg->linedef->sidedef[0]) { diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 2e539e7a4d..1197fa6f36 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -611,7 +611,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) // // // - if (frontsector->floorplane.ZatPoint(ViewPos) <= ViewPos.Z) + if (frontsector->floorplane.ZatPoint(r_viewpoint.Pos) <= r_viewpoint.Pos.Z) { // process the original floor first. @@ -671,7 +671,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) // // // - if (frontsector->ceilingplane.ZatPoint(ViewPos) >= ViewPos.Z) + if (frontsector->ceilingplane.ZatPoint(r_viewpoint.Pos) >= r_viewpoint.Pos.Z) { // process the original ceiling first. @@ -761,7 +761,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) double ff_top = rover->top.plane->ZatPoint(sector->centerspot); if (ff_top < lastceilingheight) { - if (ViewPos.Z <= rover->top.plane->ZatPoint(ViewPos)) + if (r_viewpoint.Pos.Z <= rover->top.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->ColorMap->Fade; @@ -775,7 +775,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); if (ff_bottom < lastceilingheight) { - if (ViewPos.Z <= rover->bottom.plane->ZatPoint(ViewPos)) + if (r_viewpoint.Pos.Z <= rover->bottom.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->ColorMap->Fade; @@ -801,7 +801,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); if (ff_bottom > lastfloorheight || (rover->flags&FF_FIX)) { - if (ViewPos.Z >= rover->bottom.plane->ZatPoint(ViewPos)) + if (r_viewpoint.Pos.Z >= rover->bottom.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->ColorMap->Fade; @@ -822,7 +822,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) double ff_top = rover->top.plane->ZatPoint(sector->centerspot); if (ff_top > lastfloorheight) { - if (ViewPos.Z >= rover->top.plane->ZatPoint(ViewPos)) + if (r_viewpoint.Pos.Z >= rover->top.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->ColorMap->Fade; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 4a16b03ebd..139df2105c 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -72,8 +72,6 @@ EXTERN_CVAR(Bool, gl_portals) EXTERN_CVAR(Bool, gl_noquery) EXTERN_CVAR(Int, r_mirror_recursions) -extern bool r_showviewer; - TArray GLPortal::portals; TArray GLPortal::planestack; int GLPortal::recursion; @@ -284,15 +282,15 @@ bool GLPortal::Start(bool usestencil, bool doquery) } // save viewpoint - savedViewPos = ViewPos; - savedViewActorPos = ViewActorPos; - savedshowviewer = r_showviewer; - savedAngle = ViewAngle; + savedViewPos = r_viewpoint.Pos; + savedViewActorPos = r_viewpoint.ActorPos; + savedshowviewer = r_viewpoint.showviewer; + savedAngles = r_viewpoint.Angles; savedviewactor=GLRenderer->mViewActor; savedviewarea=in_area; - savedviewpath[0] = ViewPath[0]; - savedviewpath[1] = ViewPath[1]; - savedvisibility = camera ? camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0); + savedviewpath[0] = r_viewpoint.Path[0]; + savedviewpath[1] = r_viewpoint.Path[1]; + savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0); PrevPortal = GLRenderer->mCurrentPortal; @@ -308,7 +306,7 @@ bool GLPortal::Start(bool usestencil, bool doquery) inline void GLPortal::ClearClipper() { - DAngle angleOffset = deltaangle(savedAngle, ViewAngle); + DAngle angleOffset = deltaangle(savedAngles.Yaw, r_viewpoint.Angles.Yaw); clipper.Clear(); @@ -329,7 +327,7 @@ inline void GLPortal::ClearClipper() // and finally clip it to the visible area angle_t a1 = GLRenderer->FrustumAngle(); - if (a1 < ANGLE_180) clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1); + if (a1 < ANGLE_180) clipper.SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs() + a1, r_viewpoint.Angles.Yaw.BAMs() - a1); // lock the parts that have just been clipped out. clipper.SetSilhouette(); @@ -354,16 +352,16 @@ void GLPortal::End(bool usestencil) if (needdepth) FDrawInfo::EndDrawInfo(); // Restore the old view - ViewPath[0] = savedviewpath[0]; - ViewPath[1] = savedviewpath[1]; - ViewPos = savedViewPos; - r_showviewer = savedshowviewer; - ViewActorPos = savedViewActorPos; - ViewAngle = savedAngle; + r_viewpoint.Path[0] = savedviewpath[0]; + r_viewpoint.Path[1] = savedviewpath[1]; + r_viewpoint.Pos = savedViewPos; + r_viewpoint.showviewer = savedshowviewer; + r_viewpoint.ActorPos = savedViewActorPos; + r_viewpoint.Angles = savedAngles; GLRenderer->mViewActor=savedviewactor; in_area=savedviewarea; - if (camera != nullptr) camera->renderflags = (camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags = (r_viewpoint.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); { ScopedColorMask colorMask(0, 0, 0, 0); // glColorMask(0, 0, 0, 0); // no graphics @@ -415,14 +413,14 @@ void GLPortal::End(bool usestencil) glDepthMask(true); } // Restore the old view - r_showviewer = savedshowviewer; - ViewActorPos = savedViewActorPos; - ViewPos = savedViewPos; - ViewAngle = savedAngle; + r_viewpoint.showviewer = savedshowviewer; + r_viewpoint.ActorPos = savedViewActorPos; + r_viewpoint.Pos = savedViewPos; + r_viewpoint.Angles = savedAngles; GLRenderer->mViewActor=savedviewactor; in_area=savedviewarea; - if (camera != nullptr) camera->renderflags |= savedvisibility; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags |= savedvisibility; + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); // This draws a valid z-buffer into the stencil's contents to ensure it // doesn't get overwritten by the level's geometry. @@ -619,7 +617,7 @@ static int skyboxrecursion=0; void GLSkyboxPortal::DrawContents() { int old_pm = PlaneMirrorMode; - int saved_extralight = extralight; + int saved_extralight = r_viewpoint.extralight; if (skyboxrecursion >= 3) { @@ -630,29 +628,29 @@ void GLSkyboxPortal::DrawContents() skyboxrecursion++; AActor *origin = portal->mSkybox; portal->mFlags |= PORTSF_INSKYBOX; - extralight = 0; + r_viewpoint.extralight = 0; PlaneMirrorMode = 0; bool oldclamp = gl_RenderState.SetDepthClamp(false); - ViewPos = origin->InterpolatedPosition(r_TicFracF); - ViewActorPos = origin->Pos(); - ViewAngle += (origin->PrevAngles.Yaw + deltaangle(origin->PrevAngles.Yaw, origin->Angles.Yaw) * r_TicFracF); + r_viewpoint.Pos = origin->InterpolatedPosition(r_viewpoint.TicFrac); + r_viewpoint.ActorPos = origin->Pos(); + r_viewpoint.Angles.Yaw += (origin->PrevAngles.Yaw + deltaangle(origin->PrevAngles.Yaw, origin->Angles.Yaw) * r_viewpoint.TicFrac); // Don't let the viewpoint be too close to a floor or ceiling double floorh = origin->Sector->floorplane.ZatPoint(origin->Pos()); double ceilh = origin->Sector->ceilingplane.ZatPoint(origin->Pos()); - if (ViewPos.Z < floorh + 4) ViewPos.Z = floorh + 4; - if (ViewPos.Z > ceilh - 4) ViewPos.Z = ceilh - 4; + if (r_viewpoint.Pos.Z < floorh + 4) r_viewpoint.Pos.Z = floorh + 4; + if (r_viewpoint.Pos.Z > ceilh - 4) r_viewpoint.Pos.Z = ceilh - 4; GLRenderer->mViewActor = origin; inskybox = true; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); GLRenderer->SetViewArea(); ClearClipper(); - int mapsection = R_PointInSubsector(ViewPos)->mapsection; + int mapsection = R_PointInSubsector(r_viewpoint.Pos)->mapsection; SaveMapSection(); currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7); @@ -664,7 +662,7 @@ void GLSkyboxPortal::DrawContents() skyboxrecursion--; PlaneMirrorMode = old_pm; - extralight = saved_extralight; + r_viewpoint.extralight = saved_extralight; RestoreMapSection(); } @@ -737,21 +735,21 @@ void GLSectorStackPortal::DrawContents() { FPortal *portal = origin; - ViewPos += origin->mDisplacement; - ViewActorPos += origin->mDisplacement; + r_viewpoint.Pos += origin->mDisplacement; + r_viewpoint.ActorPos += origin->mDisplacement; GLRenderer->mViewActor = NULL; // avoid recursions! if (origin->plane != -1) instack[origin->plane]++; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); SaveMapSection(); SetupCoverage(); ClearClipper(); // If the viewpoint is not within the portal, we need to invalidate the entire clip area. // The portal will re-validate the necessary parts when its subsectors get traversed. - subsector_t *sub = R_PointInSubsector(ViewPos); + subsector_t *sub = R_PointInSubsector(r_viewpoint.Pos); if (!(gl_drawinfo->ss_renderflags[sub - ::subsectors] & SSRF_SEEN)) { clipper.SafeAddClipRange(0, ANGLE_MAX); @@ -793,15 +791,15 @@ void GLPlaneMirrorPortal::DrawContents() int old_pm = PlaneMirrorMode; // the player is always visible in a mirror. - r_showviewer = true; + r_viewpoint.showviewer = true; - double planez = origin->ZatPoint(ViewPos); - ViewPos.Z = 2 * planez - ViewPos.Z; + double planez = origin->ZatPoint(r_viewpoint.Pos); + r_viewpoint.Pos.Z = 2 * planez - r_viewpoint.Pos.Z; GLRenderer->mViewActor = NULL; PlaneMirrorMode = origin->fC() < 0 ? -1 : 1; PlaneMirrorFlag++; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); ClearClipper(); gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f); @@ -863,7 +861,7 @@ int GLLinePortal::ClipSeg(seg_t *seg) { return PClip_Inside; // should be handled properly. } - return P_ClipLineToPortal(linedef, line(), ViewPos) ? PClip_InFront : PClip_Inside; + return P_ClipLineToPortal(linedef, line(), r_viewpoint.Pos) ? PClip_InFront : PClip_Inside; } int GLLinePortal::ClipSubsector(subsector_t *sub) @@ -910,32 +908,32 @@ void GLMirrorPortal::DrawContents() } GLRenderer->mClipPortal = this; - DAngle StartAngle = ViewAngle; - DVector3 StartPos = ViewPos; + DAngle StartAngle = r_viewpoint.Angles.Yaw; + DVector3 StartPos = r_viewpoint.Pos; vertex_t *v1 = linedef->v1; vertex_t *v2 = linedef->v2; // the player is always visible in a mirror. - r_showviewer = true; + r_viewpoint.showviewer = true; // Reflect the current view behind the mirror. if (linedef->Delta().X == 0) { // vertical mirror - ViewPos.X = 2 * v1->fX() - StartPos.X; + r_viewpoint.Pos.X = 2 * v1->fX() - StartPos.X; // Compensation for reendering inaccuracies - if (StartPos.X < v1->fX()) ViewPos.X -= 0.1; - else ViewPos.X += 0.1; + if (StartPos.X < v1->fX()) r_viewpoint.Pos.X -= 0.1; + else r_viewpoint.Pos.X += 0.1; } else if (linedef->Delta().Y == 0) { // horizontal mirror - ViewPos.Y = 2*v1->fY() - StartPos.Y; + r_viewpoint.Pos.Y = 2*v1->fY() - StartPos.Y; // Compensation for reendering inaccuracies - if (StartPos.YfY()) ViewPos.Y -= 0.1; - else ViewPos.Y += 0.1; + if (StartPos.YfY()) r_viewpoint.Pos.Y -= 0.1; + else r_viewpoint.Pos.Y += 0.1; } else { @@ -952,27 +950,27 @@ void GLMirrorPortal::DrawContents() // the above two cases catch len == 0 double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); - ViewPos.X = (x1 + r * dx)*2 - x; - ViewPos.Y = (y1 + r * dy)*2 - y; + r_viewpoint.Pos.X = (x1 + r * dx)*2 - x; + r_viewpoint.Pos.Y = (y1 + r * dy)*2 - y; // Compensation for reendering inaccuracies FVector2 v(-dx, dy); v.MakeUnit(); - ViewPos.X+= v[1] * renderdepth / 2; - ViewPos.Y+= v[0] * renderdepth / 2; + r_viewpoint.Pos.X+= v[1] * renderdepth / 2; + r_viewpoint.Pos.Y+= v[0] * renderdepth / 2; } - ViewAngle = linedef->Delta().Angle() * 2. - StartAngle; + r_viewpoint.Angles.Yaw = linedef->Delta().Angle() * 2. - StartAngle; GLRenderer->mViewActor = NULL; MirrorFlag++; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); clipper.Clear(); angle_t af = GLRenderer->FrustumAngle(); - if (afv1->GetClipAngle(); angle_t a1 = linedef->v2->GetClipAngle(); @@ -1013,23 +1011,23 @@ void GLLineToLinePortal::DrawContents() GLRenderer->mClipPortal = this; line_t *origin = glport->lines[0]->mOrigin; - P_TranslatePortalXY(origin, ViewPos.X, ViewPos.Y); - P_TranslatePortalXY(origin, ViewActorPos.X, ViewActorPos.Y); - P_TranslatePortalAngle(origin, ViewAngle); - P_TranslatePortalZ(origin, ViewPos.Z); - P_TranslatePortalXY(origin, ViewPath[0].X, ViewPath[0].Y); - P_TranslatePortalXY(origin, ViewPath[1].X, ViewPath[1].Y); - if (!r_showviewer && camera != nullptr && P_PointOnLineSidePrecise(ViewPath[0], glport->lines[0]->mDestination) != P_PointOnLineSidePrecise(ViewPath[1], glport->lines[0]->mDestination)) + P_TranslatePortalXY(origin, r_viewpoint.Pos.X, r_viewpoint.Pos.Y); + P_TranslatePortalXY(origin, r_viewpoint.ActorPos.X, r_viewpoint.ActorPos.Y); + P_TranslatePortalAngle(origin, r_viewpoint.Angles.Yaw); + P_TranslatePortalZ(origin, r_viewpoint.Pos.Z); + P_TranslatePortalXY(origin, r_viewpoint.Path[0].X, r_viewpoint.Path[0].Y); + P_TranslatePortalXY(origin, r_viewpoint.Path[1].X, r_viewpoint.Path[1].Y); + if (!r_viewpoint.showviewer && r_viewpoint.camera != nullptr && P_PointOnLineSidePrecise(r_viewpoint.Path[0], glport->lines[0]->mDestination) != P_PointOnLineSidePrecise(r_viewpoint.Path[1], glport->lines[0]->mDestination)) { - double distp = (ViewPath[0] - ViewPath[1]).Length(); + double distp = (r_viewpoint.Path[0] - r_viewpoint.Path[1]).Length(); if (distp > EQUAL_EPSILON) { - double dist1 = (ViewPos - ViewPath[0]).Length(); - double dist2 = (ViewPos - ViewPath[1]).Length(); + double dist1 = (r_viewpoint.Pos - r_viewpoint.Path[0]).Length(); + double dist2 = (r_viewpoint.Pos - r_viewpoint.Path[1]).Length(); if (dist1 + dist2 < distp + 1) { - camera->renderflags |= RF_MAYBEINVISIBLE; + r_viewpoint.camera->renderflags |= RF_MAYBEINVISIBLE; } } } @@ -1049,7 +1047,7 @@ void GLLineToLinePortal::DrawContents() } GLRenderer->mViewActor = nullptr; - GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); + GLRenderer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); ClearClipper(); gl_RenderState.SetClipLine(glport->lines[0]->mDestination); @@ -1093,9 +1091,9 @@ GLHorizonPortal::GLHorizonPortal(GLHorizonInfo * pt, bool local) // create the vertex data for this horizon portal. GLSectorPlane * sp = &origin->plane; - const float vx = ViewPos.X; - const float vy = ViewPos.Y; - const float vz = ViewPos.Z; + const float vx = r_viewpoint.Pos.X; + const float vy = r_viewpoint.Pos.Y; + const float vz = r_viewpoint.Pos.Z; const float z = sp->Texheight; const float tz = (z - vz); @@ -1166,7 +1164,7 @@ void GLHorizonPortal::DrawContents() PortalAll.Unclock(); return; } - gl_RenderState.SetCameraPos(ViewPos.X, ViewPos.Y, ViewPos.Z); + gl_RenderState.SetCameraPos(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z); if (gltexture && gltexture->tex->isFullbright()) @@ -1243,7 +1241,7 @@ void GLEEHorizonPortal::DrawContents() horz.colormap = sector->ColorMap; if (portal->mType == PORTS_PLANE) { - horz.plane.Texheight = ViewPos.Z + fabs(horz.plane.Texheight); + horz.plane.Texheight = r_viewpoint.Pos.Z + fabs(horz.plane.Texheight); } GLHorizonPortal ceil(&horz, true); ceil.DrawContents(); @@ -1256,7 +1254,7 @@ void GLEEHorizonPortal::DrawContents() horz.colormap = sector->ColorMap; if (portal->mType == PORTS_PLANE) { - horz.plane.Texheight = ViewPos.Z - fabs(horz.plane.Texheight); + horz.plane.Texheight = r_viewpoint.Pos.Z - fabs(horz.plane.Texheight); } GLHorizonPortal floor(&horz, true); floor.DrawContents(); diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index a49f03563c..7c8eeedcb7 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -101,7 +101,7 @@ private: DVector3 savedviewpath[2]; DVector3 savedViewPos; DVector3 savedViewActorPos; - DAngle savedAngle; + DRotator savedAngles; bool savedshowviewer; AActor * savedviewactor; area_t savedviewarea; diff --git a/src/gl/scene/gl_renderhacks.cpp b/src/gl/scene/gl_renderhacks.cpp index 6b47e704d8..f942584af4 100644 --- a/src/gl/scene/gl_renderhacks.cpp +++ b/src/gl/scene/gl_renderhacks.cpp @@ -493,7 +493,7 @@ void FDrawInfo::HandleMissingTextures() HandledSubsectors.Clear(); validcount++; - if (MissingUpperTextures[i].Planez > ViewPos.Z) + if (MissingUpperTextures[i].Planez > r_viewpoint.Pos.Z) { // close the hole only if all neighboring sectors are an exact height match // Otherwise just fill in the missing textures. @@ -565,7 +565,7 @@ void FDrawInfo::HandleMissingTextures() HandledSubsectors.Clear(); validcount++; - if (MissingLowerTextures[i].Planez < ViewPos.Z) + if (MissingLowerTextures[i].Planez < r_viewpoint.Pos.Z) { // close the hole only if all neighboring sectors are an exact height match // Otherwise just fill in the missing textures. @@ -655,7 +655,7 @@ void FDrawInfo::DrawUnhandledMissingTextures() // already done! if (seg->linedef->validcount == validcount) continue; // already done seg->linedef->validcount = validcount; - if (seg->frontsector->GetPlaneTexZ(sector_t::ceiling) < ViewPos.Z) continue; // out of sight + if (seg->frontsector->GetPlaneTexZ(sector_t::ceiling) < r_viewpoint.Pos.Z) continue; // out of sight // FIXME: The check for degenerate subsectors should be more precise if (seg->PartnerSeg && (seg->PartnerSeg->Subsector->flags & SSECF_DEGENERATE)) continue; @@ -677,7 +677,7 @@ void FDrawInfo::DrawUnhandledMissingTextures() if (seg->linedef->validcount == validcount) continue; // already done seg->linedef->validcount = validcount; if (!(sectorrenderflags[seg->backsector->sectornum] & SSRF_RENDERFLOOR)) continue; - if (seg->frontsector->GetPlaneTexZ(sector_t::floor) > ViewPos.Z) continue; // out of sight + if (seg->frontsector->GetPlaneTexZ(sector_t::floor) > r_viewpoint.Pos.Z) continue; // out of sight if (seg->backsector->transdoor) continue; if (seg->backsector->GetTexture(sector_t::floor) == skyflatnum) continue; if (seg->backsector->ValidatePortal(sector_t::floor) != NULL) continue; @@ -787,7 +787,7 @@ bool FDrawInfo::CollectSubsectorsFloor(subsector_t * sub, sector_t * anchor) sub->render_sector->GetPlaneTexZ(sector_t::floor) != anchor->GetPlaneTexZ(sector_t::floor) || sub->render_sector->GetFloorLight() != anchor->GetFloorLight()) { - if (sub == viewsubsector && ViewPos.Z < anchor->GetPlaneTexZ(sector_t::floor)) inview = true; + if (sub == viewsubsector && r_viewpoint.Pos.Z < anchor->GetPlaneTexZ(sector_t::floor)) inview = true; HandledSubsectors.Push(sub); } } @@ -937,7 +937,7 @@ void FDrawInfo::HandleHackedSubsectors() totalssms.Reset(); totalssms.Clock(); - viewsubsector = R_PointInSubsector(ViewPos); + viewsubsector = R_PointInSubsector(r_viewpoint.Pos); // Each subsector may only be processed once in this loop! validcount++; diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index d5c1838609..e047dec77b 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -88,7 +88,6 @@ EXTERN_CVAR (Float, underwater_fade_scalar) extern int viewpitch; extern bool NoInterpolateView; -extern bool r_showviewer; int gl_fixedcolormap; area_t in_area; @@ -111,7 +110,7 @@ angle_t FGLRenderer::FrustumAngle() // ok, this is a gross hack that barely works... // but at least it doesn't overestimate too much... - double floatangle=2.0+(45.0+((tilt/1.9)))*mCurrentFoV*48.0/AspectMultiplier(WidescreenRatio)/90.0; + double floatangle=2.0+(45.0+((tilt/1.9)))*mCurrentFoV*48.0/AspectMultiplier(r_viewwindow.WidescreenRatio)/90.0; angle_t a1 = DAngle(floatangle).BAMs(); if (a1>=ANGLE_180) return 0xffffffff; return a1; @@ -125,14 +124,14 @@ angle_t FGLRenderer::FrustumAngle() void FGLRenderer::SetViewArea() { // The render_sector is better suited to represent the current position in GL - viewsector = R_PointInSubsector(ViewPos)->render_sector; + r_viewpoint.sector = R_PointInSubsector(r_viewpoint.Pos)->render_sector; // Get the heightsec state from the render sector, not the current one! - if (viewsector->heightsec && !(viewsector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC)) + if (r_viewpoint.sector->heightsec && !(r_viewpoint.sector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC)) { - in_area = ViewPos.Z <= viewsector->heightsec->floorplane.ZatPoint(ViewPos) ? area_below : - (ViewPos.Z > viewsector->heightsec->ceilingplane.ZatPoint(ViewPos) && - !(viewsector->heightsec->MoreFlags&SECF_FAKEFLOORONLY)) ? area_above : area_normal; + in_area = r_viewpoint.Pos.Z <= r_viewpoint.sector->heightsec->floorplane.ZatPoint(r_viewpoint.Pos) ? area_below : + (r_viewpoint.Pos.Z > r_viewpoint.sector->heightsec->ceilingplane.ZatPoint(r_viewpoint.Pos) && + !(r_viewpoint.sector->heightsec->MoreFlags&SECF_FAKEFLOORONLY)) ? area_above : area_normal; } else { @@ -197,11 +196,11 @@ void FGLRenderer::Set3DViewport(bool mainview) void FGLRenderer::SetViewAngle(DAngle viewangle) { mAngles.Yaw = float(270.0-viewangle.Degrees); - DVector2 v = ViewAngle.ToVector(); + DVector2 v = r_viewpoint.Angles.Yaw.ToVector(); mViewVector.X = v.X; mViewVector.Y = v.Y; - R_SetViewAngle(); + R_SetViewAngle(r_viewpoint, r_viewwindow); } @@ -312,7 +311,7 @@ void FGLRenderer::RenderScene(int recursion) glDepthMask(true); if (!gl_no_skyclear) GLPortal::RenderFirstSkyPortal(recursion); - gl_RenderState.SetCameraPos(ViewPos.X, ViewPos.Y, ViewPos.Z); + gl_RenderState.SetCameraPos(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z); gl_RenderState.EnableFog(true); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); @@ -449,7 +448,7 @@ void FGLRenderer::RenderTranslucent() RenderAll.Clock(); glDepthMask(false); - gl_RenderState.SetCameraPos(ViewPos.X, ViewPos.Y, ViewPos.Z); + gl_RenderState.SetCameraPos(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z); // final pass: translucent stuff gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); @@ -497,11 +496,11 @@ void FGLRenderer::DrawScene(int drawmode) ssao_portals_available--; } - if (camera != nullptr) + if (r_viewpoint.camera != nullptr) { - ActorRenderFlags savedflags = camera->renderflags; + ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; CreateScene(); - camera->renderflags = savedflags; + r_viewpoint.camera->renderflags = savedflags; } else { @@ -582,11 +581,11 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) { double lightbottom; if (i < lightlist.Size() - 1) - lightbottom = lightlist[i + 1].plane.ZatPoint(ViewPos); + lightbottom = lightlist[i + 1].plane.ZatPoint(r_viewpoint.Pos); else - lightbottom = viewsector->floorplane.ZatPoint(ViewPos); + lightbottom = viewsector->floorplane.ZatPoint(r_viewpoint.Pos); - if (lightbottom < ViewPos.Z && (!lightlist[i].caster || !(lightlist[i].caster->flags&FF_FADEWALLS))) + if (lightbottom < r_viewpoint.Pos.Z && (!lightlist[i].caster || !(lightlist[i].caster->flags&FF_FADEWALLS))) { // 3d floor 'fog' is rendered as a blending value blendv = lightlist[i].blend; @@ -735,7 +734,7 @@ void FGLRenderer::ProcessScene(bool toscreen) iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; GLPortal::BeginScene(); - int mapsection = R_PointInSubsector(ViewPos)->mapsection; + int mapsection = R_PointInSubsector(r_viewpoint.Pos)->mapsection; memset(¤tmapsection[0], 0, currentmapsection.Size()); currentmapsection[mapsection>>3] |= 1 << (mapsection & 7); DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN); @@ -760,7 +759,7 @@ void FGLRenderer::SetFixedColormap (player_t *player) if (cplayer->extralight == INT_MIN) { gl_fixedcolormap=CM_FIRSTSPECIALCOLORMAP + INVERSECOLORMAP; - extralight=0; + r_viewpoint.extralight=0; } else if (cplayer->fixedcolormap != NOFIXEDCOLORMAP) { @@ -801,17 +800,17 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo mSceneClearColor[0] = 0.0f; mSceneClearColor[1] = 0.0f; mSceneClearColor[2] = 0.0f; - R_SetupFrame (camera); + R_SetupFrame (r_viewpoint, r_viewwindow, camera); 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. - double radPitch = ViewPitch.Normalized180().Radians(); + double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); - mAngles.Roll.Degrees = ViewRoll.Degrees; + mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; // Scroll the sky mSky1Pos = (float)fmod(gl_frameMS * level.skyspeed1, 1024.f) * 90.f/256.f; @@ -830,7 +829,7 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo } // 'viewsector' will not survive the rendering so it cannot be used anymore below. - lviewsector = viewsector; + lviewsector = r_viewpoint.sector; // Render (potentially) multiple views for stereo 3d float viewShift[3]; @@ -847,16 +846,16 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo // Stereo mode specific perspective projection SetProjection( eye->GetProjection(fov, ratio, fovratio) ); // SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper - SetViewAngle(ViewAngle); + SetViewAngle(r_viewpoint.Angles.Yaw); // Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos eye->GetViewShift(GLRenderer->mAngles.Yaw.Degrees, viewShift); s3d::ScopedViewShifter viewShifter(viewShift); - SetViewMatrix(ViewPos.X, ViewPos.Y, ViewPos.Z, false, false); + SetViewMatrix(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, false, false); gl_RenderState.ApplyMatrices(); clipper.Clear(); angle_t a1 = FrustumAngle(); - clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1); + clipper.SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs() + a1, r_viewpoint.Angles.Yaw.BAMs() - a1); ProcessScene(toscreen); if (mainview && toscreen) EndDrawScene(lviewsector); // do not call this for camera textures. @@ -916,8 +915,8 @@ void FGLRenderer::RenderView (player_t* player) ResetProfilingData(); // Get this before everything else - if (cl_capfps || r_NoInterpolate) r_TicFracF = 1.; - else r_TicFracF = I_GetTimeFrac (&r_FrameTime); + if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; + else r_viewpoint.TicFrac = I_GetTimeFrac (&r_viewpoint.FrameTime); gl_frameMS = I_MSTime(); P_FindParticleSubsectors (); @@ -934,8 +933,8 @@ void FGLRenderer::RenderView (player_t* player) // now render the main view float fovratio; - float ratio = WidescreenRatio; - if (WidescreenRatio >= 1.3f) + float ratio = r_viewwindow.WidescreenRatio; + if (r_viewwindow.WidescreenRatio >= 1.3f) { fovratio = 1.333333f; } @@ -950,7 +949,7 @@ void FGLRenderer::RenderView (player_t* player) TThinkerIterator it(STAT_DLIGHT); GLRenderer->mLightCount = ((it.Next()) != NULL); - sector_t * viewsector = RenderViewpoint(player->camera, NULL, FieldOfView.Degrees, ratio, fovratio, true, true); + sector_t * viewsector = RenderViewpoint(player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); All.Unclock(); } @@ -980,7 +979,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i GLRenderer->mLightCount = ((it.Next()) != NULL); sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, - FieldOfView.Degrees, 1.6f, 1.6f, true, false); + r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetSoftLightLevel(-1); diff --git a/src/gl/scene/gl_sky.cpp b/src/gl/scene/gl_sky.cpp index 7fe92b8905..70e2686a7d 100644 --- a/src/gl/scene/gl_sky.cpp +++ b/src/gl/scene/gl_sky.cpp @@ -159,8 +159,8 @@ void GLWall::SkyPlane(sector_t *sector, int plane, bool allowreflect) } else if (allowreflect && sector->GetReflect(plane) > 0) { - if ((plane == sector_t::ceiling && ViewPos.Z > sector->ceilingplane.fD()) || - (plane == sector_t::floor && ViewPos.Z < -sector->floorplane.fD())) return; + if ((plane == sector_t::ceiling && r_viewpoint.Pos.Z > sector->ceilingplane.fD()) || + (plane == sector_t::floor && r_viewpoint.Pos.Z < -sector->floorplane.fD())) return; ptype = PORTALTYPE_PLANEMIRROR; planemirror = plane == sector_t::ceiling ? §or->ceilingplane : §or->floorplane; } @@ -345,7 +345,7 @@ void GLWall::SkyBottom(seg_t * seg,sector_t * fs,sector_t * bs,vertex_t * v1,ver else { // Special hack for Vrack2b - if (bs->floorplane.ZatPoint(ViewPos) > ViewPos.Z) return; + if (bs->floorplane.ZatPoint(r_viewpoint.Pos) > r_viewpoint.Pos.Z) return; } } zbottom[0]=zbottom[1]=-32768.0f; diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 1d9cf9b3b9..a988bdfec9 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -519,7 +519,7 @@ void GLSkyPortal::DrawContents() bool oldClamp = gl_RenderState.SetDepthClamp(true); gl_MatrixStack.Push(gl_RenderState.mViewMatrix); - GLRenderer->SetupView(0, 0, 0, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); + GLRenderer->SetupView(0, 0, 0, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO); if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index a0338255e5..ff2d5189fe 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -78,7 +78,6 @@ EXTERN_CVAR (Float, transsouls) extern TArray sprites; extern TArray SpriteFrames; extern TArray BloodTranslationColors; -extern bool r_showviewer; enum HWRenderStyle { @@ -189,8 +188,8 @@ void GLSprite::CalculateVertices(FVector3 *v) { // [CMB] Rotate relative to camera XY position, not just camera direction, // which is nicer in VR - float xrel = xcenter - ViewPos.X; - float yrel = ycenter - ViewPos.Y; + float xrel = xcenter - r_viewpoint.Pos.X; + float yrel = ycenter - r_viewpoint.Pos.Y; float absAngleDeg = RAD2DEG(atan2(-yrel, xrel)); float counterRotationDeg = 270. - GLRenderer->mAngles.Yaw.Degrees; // counteracts existing sprite rotation float relAngleDeg = counterRotationDeg + absAngleDeg; @@ -298,7 +297,7 @@ void GLSprite::Draw(int pass) // fog + fuzz don't work well without some fiddling with the alpha value! if (!gl_isBlack(Colormap.FadeColor)) { - float dist=Dist2(ViewPos.X, ViewPos.Y, x,y); + float dist=Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, x,y); int fogd = gl_GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.fogdensity); // this value was determined by trial and error and is scale dependent! @@ -396,7 +395,7 @@ void GLSprite::Draw(int pass) secplane_t *lowplane = i == (*lightlist).Size() - 1 ? &bottomp : &(*lightlist)[i + 1].plane; int thislight = (*lightlist)[i].caster != NULL ? gl_ClampLight(*(*lightlist)[i].p_lightlevel) : lightlevel; - int thisll = actor == nullptr? thislight : (uint8_t)gl_CheckSpriteGlow(actor->Sector, thislight, actor->InterpolatedPosition(r_TicFracF)); + int thisll = actor == nullptr? thislight : (uint8_t)gl_CheckSpriteGlow(actor->Sector, thislight, actor->InterpolatedPosition(r_viewpoint.TicFrac)); FColormap thiscm; thiscm.FadeColor = Colormap.FadeColor; @@ -671,6 +670,8 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) return; } + AActor *camera = r_viewpoint.camera; + if (thing->renderflags & RF_INVISIBLE || !thing->RenderStyle.IsVisible(thing->Alpha)) { if (!(thing->flags & MF_STEALTH) || !gl_fixedcolormap || !gl_enhanced_nightvision || thing == camera) @@ -687,26 +688,26 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) if (!thruportal && !(currentmapsection[thing->subsector->mapsection >> 3] & (1 << (thing->subsector->mapsection & 7)))) return; // [RH] Interpolate the sprite's position to make it look smooth - DVector3 thingpos = thing->InterpolatedPosition(r_TicFracF); + DVector3 thingpos = thing->InterpolatedPosition(r_viewpoint.TicFrac); if (thruportal == 1) thingpos += Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); // Some added checks if the camera actor is not supposed to be seen. It can happen that some portal setup has this actor in view in which case it may not be skipped here - if (thing == camera && !r_showviewer) + if (thing == camera && !r_viewpoint.showviewer) { DVector3 thingorigin = thing->Pos(); if (thruportal == 1) thingorigin += Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); - if (fabs(thingorigin.X - ViewActorPos.X) < 2 && fabs(thingorigin.Y - ViewActorPos.Y) < 2) return; + if (fabs(thingorigin.X - r_viewpoint.ActorPos.X) < 2 && fabs(thingorigin.Y - r_viewpoint.ActorPos.Y) < 2) return; } // Thing is invisible if close to the camera. if (thing->renderflags & RF_MAYBEINVISIBLE) { - if (fabs(thingpos.X - ViewPos.X) < 32 && fabs(thingpos.Y - ViewPos.Y) < 32) return; + if (fabs(thingpos.X - r_viewpoint.Pos.X) < 32 && fabs(thingpos.Y - r_viewpoint.Pos.Y) < 32) return; } // Too close to the camera. This doesn't look good if it is a sprite. - if (fabs(thingpos.X - ViewPos.X) < 2 && fabs(thingpos.Y - ViewPos.Y) < 2) + if (fabs(thingpos.X - r_viewpoint.Pos.X) < 2 && fabs(thingpos.Y - r_viewpoint.Pos.Y) < 2) { - if (ViewPos.Z >= thingpos.Z - 2 && ViewPos.Z <= thingpos.Z + thing->Height + 2) + if (r_viewpoint.Pos.Z >= thingpos.Z - 2 && r_viewpoint.Pos.Z <= thingpos.Z + thing->Height + 2) { // exclude vertically moving objects from this check. if (!thing->Vel.isZero()) @@ -728,7 +729,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) if (speed >= thing->target->radius / 2) { double clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius * 2); - if ((thingpos - ViewPos).LengthSquared() < clipdist * clipdist) return; + if ((thingpos - r_viewpoint.Pos).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. @@ -741,7 +742,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) } // disabled because almost none of the actual game code is even remotely prepared for this. If desired, use the INTERPOLATE flag. if (thing->renderflags & RF_INTERPOLATEANGLES) - Angles = thing->InterpolatedAngles(r_TicFracF); + Angles = thing->InterpolatedAngles(r_viewpoint.TicFrac); else Angles = thing->Angles; @@ -768,7 +769,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) // [RH] Make floatbobbing a renderer-only effect. if (thing->flags2 & MF2_FLOATBOB) { - float fz = thing->GetBobOffset(r_TicFracF); + float fz = thing->GetBobOffset(r_viewpoint.TicFrac); z += fz; } @@ -776,7 +777,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) if (!modelframe) { bool mirror; - DAngle ang = (thingpos - ViewPos).Angle(); + DAngle ang = (thingpos - r_viewpoint.Pos).Angle(); FTextureID patch; // [ZZ] add direct picnum override if (isPicnumOverride) @@ -879,7 +880,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) gltexture=NULL; } - depth = FloatToFixed((x - ViewPos.X) * ViewTanCos + (y - ViewPos.Y) * ViewTanSin); + depth = FloatToFixed((x - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin); // light calculation @@ -1188,7 +1189,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s z1=z-scalefac; z2=z+scalefac; - depth = FloatToFixed((x - ViewPos.X) * ViewTanCos + (y - ViewPos.Y) * ViewTanSin); + depth = FloatToFixed((x - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin); actor=NULL; this->particle=particle; @@ -1242,9 +1243,9 @@ void gl_RenderActorsInPortal(FGLLinePortal *glport) DVector3 newpos = savedpos; sector_t fakesector; - if (!r_showviewer && th == camera) + if (!r_viewpoint.showviewer && th == r_viewpoint.camera) { - if (fabs(savedpos.X - ViewActorPos.X) < 2 && fabs(savedpos.Y - ViewActorPos.Y) < 2) + if (fabs(savedpos.X - r_viewpoint.ActorPos.X) < 2 && fabs(savedpos.Y - r_viewpoint.ActorPos.Y) < 2) { continue; } diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index 6267ac82bc..647c1b7e73 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -87,7 +87,7 @@ void GLWall::PutWall(bool translucent) if (translucent) // translucent walls { - ViewDistance = (ViewPos - (seg->linedef->v1->fPos() + seg->linedef->Delta() / 2)).XY().LengthSquared(); + ViewDistance = (r_viewpoint.Pos - (seg->linedef->v1->fPos() + seg->linedef->Delta() / 2)).XY().LengthSquared(); if (gl.buffermethod == BM_DEFERRED) MakeVertices(true); gl_drawinfo->drawlists[GLDL_TRANSLUCENT].AddWall(this); } @@ -430,10 +430,10 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) ztop[1] = ztop[0] = fs->GetPlaneTexZ(sector_t::ceiling); zbottom[1] = zbottom[0] = fs->GetPlaneTexZ(sector_t::floor); - if (ViewPos.Z < fs->GetPlaneTexZ(sector_t::ceiling)) + if (r_viewpoint.Pos.Z < fs->GetPlaneTexZ(sector_t::ceiling)) { - if (ViewPos.Z > fs->GetPlaneTexZ(sector_t::floor)) - zbottom[1] = zbottom[0] = ViewPos.Z; + if (r_viewpoint.Pos.Z > fs->GetPlaneTexZ(sector_t::floor)) + zbottom[1] = zbottom[0] = r_viewpoint.Pos.Z; if (fs->GetTexture(sector_t::ceiling) == skyflatnum) { @@ -460,7 +460,7 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) ztop[1] = ztop[0] = zbottom[0]; } - if (ViewPos.Z > fs->GetPlaneTexZ(sector_t::floor)) + if (r_viewpoint.Pos.Z > fs->GetPlaneTexZ(sector_t::floor)) { zbottom[1] = zbottom[0] = fs->GetPlaneTexZ(sector_t::floor); if (fs->GetTexture(sector_t::floor) == skyflatnum) diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 62a051e582..0734c580a0 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -96,7 +96,7 @@ void FGLRenderer::DrawPSprite (player_t * player,DPSprite *psp, float sx, float tex->GetSpriteRect(&r); // calculate edges of the shape - scalex = (320.0f / (240.0f * WidescreenRatio)) * vw / 320; + scalex = (320.0f / (240.0f * r_viewwindow.WidescreenRatio)) * vw / 320; tx = sx - (160 - r.left); x1 = tx * scalex + vw/2; @@ -201,6 +201,8 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) s3d::Stereo3DMode::getCurrentMode().AdjustPlayerSprites(); + AActor *camera = r_viewpoint.camera; + // this is the same as the software renderer if (!player || !r_drawplayersprites || @@ -212,7 +214,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) float bobx, boby, wx, wy; DPSprite *weapon; - P_BobWeapon(camera->player, &bobx, &boby, r_TicFracF); + P_BobWeapon(camera->player, &bobx, &boby, r_viewpoint.TicFrac); // Interpolate the main weapon layer once so as to be able to add it to other layers. if ((weapon = camera->player->FindPSprite(PSP_WEAPON)) != nullptr) @@ -224,8 +226,8 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) } else { - wx = weapon->oldx + (weapon->x - weapon->oldx) * r_TicFracF; - wy = weapon->oldy + (weapon->y - weapon->oldy) * r_TicFracF; + wx = weapon->oldx + (weapon->x - weapon->oldx) * r_viewpoint.TicFrac; + wy = weapon->oldy + (weapon->y - weapon->oldy) * r_viewpoint.TicFrac; } } else @@ -257,11 +259,11 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) if (ifloorplane.ZatPoint(ViewPos); + lightbottom=viewsector->floorplane.ZatPoint(r_viewpoint.Pos); } if (lightbottomviewz) @@ -427,8 +429,8 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) psp->oldy = psp->y; } - float sx = psp->oldx + (psp->x - psp->oldx) * r_TicFracF; - float sy = psp->oldy + (psp->y - psp->oldy) * r_TicFracF; + float sx = psp->oldx + (psp->x - psp->oldx) * r_viewpoint.TicFrac; + float sy = psp->oldy + (psp->y - psp->oldy) * r_viewpoint.TicFrac; if (psp->Flags & PSPF_ADDBOB) { diff --git a/src/gl/stereo3d/scoped_view_shifter.cpp b/src/gl/stereo3d/scoped_view_shifter.cpp index b0eb13ef90..ac2b89a278 100644 --- a/src/gl/stereo3d/scoped_view_shifter.cpp +++ b/src/gl/stereo3d/scoped_view_shifter.cpp @@ -34,15 +34,15 @@ namespace s3d { ScopedViewShifter::ScopedViewShifter(float dxyz[3]) // in meters { // save original values - cachedView = ViewPos; + cachedView = r_viewpoint.Pos; // modify values - ViewPos += DVector3(dxyz[0], dxyz[1], dxyz[2]); + r_viewpoint.Pos += DVector3(dxyz[0], dxyz[1], dxyz[2]); } ScopedViewShifter::~ScopedViewShifter() { // restore original values - ViewPos = cachedView; + r_viewpoint.Pos = cachedView; } } \ No newline at end of file diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index e2be0b35b4..b4a13af7ce 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -319,10 +319,10 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla // need to do software warping FWarpTexture *wt = static_cast(tex); unsigned char *warpbuffer = new unsigned char[w*h*4]; - WarpBuffer((uint32_t*)warpbuffer, (const uint32_t*)buffer, w, h, wt->WidthOffsetMultiplier, wt->HeightOffsetMultiplier, r_FrameTime, wt->Speed, tex->bWarped); + WarpBuffer((uint32_t*)warpbuffer, (const uint32_t*)buffer, w, h, wt->WidthOffsetMultiplier, wt->HeightOffsetMultiplier, r_viewpoint.FrameTime, wt->Speed, tex->bWarped); delete[] buffer; buffer = warpbuffer; - wt->GenTime = r_FrameTime; + wt->GenTime = r_viewpoint.FrameTime; } tex->ProcessData(buffer, w, h, false); } diff --git a/src/gl/utility/gl_clock.cpp b/src/gl/utility/gl_clock.cpp index 984e1a3f31..81cb52b011 100644 --- a/src/gl/utility/gl_clock.cpp +++ b/src/gl/utility/gl_clock.cpp @@ -231,7 +231,7 @@ void CheckBench() FString compose; 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(), ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle.Degrees, ViewPitch.Degrees); + level.MapName.GetChars(), level.LevelName.GetChars(), r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw.Degrees, r_viewpoint.Angles.Pitch.Degrees); AppendRenderStats(compose); AppendRenderTimes(compose); diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 0928a0e6a5..200fc367d3 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -732,7 +732,7 @@ void P_DrawRailTrail(AActor *source, TArray &portalhits, int color1, { if (shortest == NULL || shortest->sounddist > seg.sounddist) shortest = &seg; } - S_Sound (DVector3(shortest->soundpos, ViewPos.Z), CHAN_WEAPON, sound, 1, ATTN_NORM); + S_Sound (DVector3(shortest->soundpos, r_viewpoint.Pos.Z), CHAN_WEAPON, sound, 1, ATTN_NORM); } } } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 5bac8847f2..e48e49954c 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1494,7 +1494,7 @@ bool AActor::IsInsideVisibleAngles() const if (mo != nullptr) { - DVector3 diffang = ViewPos - Pos(); + DVector3 diffang = r_viewpoint.Pos - Pos(); DAngle to = diffang.Angle(); if (!(renderflags & RF_ABSMASKANGLE)) diff --git a/src/polyrenderer/math/tri_matrix.cpp b/src/polyrenderer/math/tri_matrix.cpp index daa549587a..b924322ad4 100644 --- a/src/polyrenderer/math/tri_matrix.cpp +++ b/src/polyrenderer/math/tri_matrix.cpp @@ -135,13 +135,13 @@ TriMatrix TriMatrix::frustum(float left, float right, float bottom, float top, f TriMatrix TriMatrix::worldToView() { TriMatrix m = null(); - m.matrix[0 + 0 * 4] = (float)ViewSin; - m.matrix[0 + 1 * 4] = (float)-ViewCos; + m.matrix[0 + 0 * 4] = (float)r_viewpoint.Sin; + m.matrix[0 + 1 * 4] = (float)-r_viewpoint.Cos; m.matrix[1 + 2 * 4] = 1.0f; - m.matrix[2 + 0 * 4] = (float)-ViewCos; - m.matrix[2 + 1 * 4] = (float)-ViewSin; + m.matrix[2 + 0 * 4] = (float)-r_viewpoint.Cos; + m.matrix[2 + 1 * 4] = (float)-r_viewpoint.Sin; m.matrix[3 + 3 * 4] = 1.0f; - return m * translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z); + return m * translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); } TriMatrix TriMatrix::viewToClip() @@ -149,7 +149,7 @@ TriMatrix TriMatrix::viewToClip() auto viewport = swrenderer::RenderViewport::Instance(); float near = 5.0f; float far = 65536.0f; - float width = (float)(FocalTangent * near); + float width = (float)(r_viewwindow.FocalTangent * near); float top = (float)(viewport->CenterY / viewport->InvZtoScale * near); float bottom = (float)(top - viewheight / viewport->InvZtoScale * near); return frustum(-width, width, bottom, top, near, far); diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index 77b59ac4bc..83fc037043 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -40,7 +40,6 @@ EXTERN_CVAR(Bool, r_shadercolormaps) EXTERN_CVAR(Int, screenblocks) void InitGLRMapinfoData(); -extern bool r_showviewer; ///////////////////////////////////////////////////////////////////////////// @@ -89,8 +88,8 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int viewwidth = width; viewport->RenderTarget = canvas; - R_SetWindow(12, width, height, height, true); - viewport->SetViewport(width, height, WidescreenRatio); + R_SetWindow(r_viewpoint, r_viewwindow, 12, width, height, height, true); + viewport->SetViewport(width, height, r_viewwindow.WidescreenRatio); viewwindowx = x; viewwindowy = y; viewactive = true; @@ -103,10 +102,10 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int canvas->Unlock(); viewport->RenderTarget = screen; - R_ExecuteSetViewSize(); + R_ExecuteSetViewSize(r_viewpoint, r_viewwindow); float trueratio; ActiveRatio(width, height, &trueratio); - viewport->SetViewport(width, height, WidescreenRatio); + viewport->SetViewport(width, height, r_viewwindow.WidescreenRatio); viewactive = savedviewactive; } @@ -118,14 +117,14 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) P_FindParticleSubsectors(); PO_LinkToSubsectors(); - R_SetupFrame(actor); + R_SetupFrame(r_viewpoint, r_viewwindow, actor); swrenderer::CameraLight::Instance()->SetCamera(actor); swrenderer::RenderViewport::Instance()->SetupFreelook(); - ActorRenderFlags savedflags = camera->renderflags; + ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; // Never draw the player unless in chasecam mode - if (!r_showviewer) - camera->renderflags |= RF_INVISIBLE; + if (!r_viewpoint.showviewer) + r_viewpoint.camera->renderflags |= RF_INVISIBLE; ClearBuffers(); SetSceneViewport(); @@ -136,7 +135,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) MainPortal.RenderTranslucent(0); PlayerSprites.Render(); - camera->renderflags = savedflags; + r_viewpoint.camera->renderflags = savedflags; interpolator.RestoreInterpolations (); NetUpdate(); @@ -193,23 +192,23 @@ void PolyRenderer::SetupPerspectiveMatrix() // Code provided courtesy of Graf Zahl. Now we just have to plug it into the viewmatrix code... // 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.Normalized180().Radians(); + double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); float adjustedPitch = (float)asin(angy / alen); - float adjustedViewAngle = (float)(ViewAngle - 90).Radians(); + float adjustedViewAngle = (float)(r_viewpoint.Angles.Yaw - 90).Radians(); - float ratio = WidescreenRatio; - float fovratio = (WidescreenRatio >= 1.3f) ? 1.333333f : ratio; - float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(FieldOfView.Radians() / 2) / fovratio)).Degrees); + float ratio = r_viewwindow.WidescreenRatio; + float fovratio = (r_viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; + float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(r_viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); TriMatrix worldToView = TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) * TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) * TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) * TriMatrix::swapYZ() * - TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z); + TriMatrix::translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); WorldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; } diff --git a/src/polyrenderer/scene/poly_cull.cpp b/src/polyrenderer/scene/poly_cull.cpp index e46e897931..8e0348a329 100644 --- a/src/polyrenderer/scene/poly_cull.cpp +++ b/src/polyrenderer/scene/poly_cull.cpp @@ -50,7 +50,7 @@ void PolyCull::CullNode(void *node) node_t *bsp = (node_t *)node; // Decide which side the view point is on. - int side = PointOnSide(ViewPos, bsp); + int side = PointOnSide(r_viewpoint.Pos, bsp); // Recursively divide front space (toward the viewer). CullNode(bsp->children[side]); @@ -84,8 +84,8 @@ void PolyCull::CullSubsector(subsector_t *sub) if ((line->sidedef == nullptr || !(line->sidedef->Flags & WALLF_POLYOBJ)) && line->backsector == nullptr) { // Skip lines not facing viewer - DVector2 pt1 = line->v1->fPos() - ViewPos; - DVector2 pt2 = line->v2->fPos() - ViewPos; + DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) continue; @@ -179,7 +179,7 @@ bool PolyCull::CheckBBox(float *bspcoord) { // Start using a quick frustum AABB test: - AxisAlignedBoundingBox aabb(Vec3f(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM], (float)ViewPos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)ViewPos.Z + 1000.0f)); + AxisAlignedBoundingBox aabb(Vec3f(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM], (float)r_viewpoint.Pos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)r_viewpoint.Pos.Z + 1000.0f)); auto result = IntersectionTest::frustum_aabb(frustumPlanes, aabb); if (result == IntersectionTest::outside) return false; @@ -266,14 +266,14 @@ LineSegmentRange PolyCull::GetSegmentRangeForLine(double x1, double y1, double x } // Transform to 2D view space: - x1 = x1 - ViewPos.X; - y1 = y1 - ViewPos.Y; - x2 = x2 - ViewPos.X; - y2 = y2 - ViewPos.Y; - double rx1 = x1 * ViewSin - y1 * ViewCos; - double rx2 = x2 * ViewSin - y2 * ViewCos; - double ry1 = x1 * ViewCos + y1 * ViewSin; - double ry2 = x2 * ViewCos + y2 * ViewSin; + x1 = x1 - r_viewpoint.Pos.X; + y1 = y1 - r_viewpoint.Pos.Y; + x2 = x2 - r_viewpoint.Pos.X; + y2 = y2 - r_viewpoint.Pos.Y; + double rx1 = x1 * r_viewpoint.Sin - y1 * r_viewpoint.Cos; + double rx2 = x2 * r_viewpoint.Sin - y2 * r_viewpoint.Cos; + double ry1 = x1 * r_viewpoint.Cos + y1 * r_viewpoint.Sin; + double ry2 = x2 * r_viewpoint.Cos + y2 * r_viewpoint.Sin; // Is it potentially visible when looking straight up or down? if (!(ry1 < updownnear && ry2 < updownnear) && !(ry1 > znear && ry2 > znear) && diff --git a/src/polyrenderer/scene/poly_decal.cpp b/src/polyrenderer/scene/poly_decal.cpp index 0812f3a79f..3f4c222858 100644 --- a/src/polyrenderer/scene/poly_decal.cpp +++ b/src/polyrenderer/scene/poly_decal.cpp @@ -107,7 +107,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan return; bool foggy = false; - int actualextralight = foggy ? 0 : extralight << 4; + int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; std::pair offsets[4] = { diff --git a/src/polyrenderer/scene/poly_particle.cpp b/src/polyrenderer/scene/poly_particle.cpp index fd9ee5c88f..229bbb233c 100644 --- a/src/polyrenderer/scene/poly_particle.cpp +++ b/src/polyrenderer/scene/poly_particle.cpp @@ -37,8 +37,8 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP DVector2 points[2] = { - { pos.X - ViewSin * psize, pos.Y + ViewCos * psize }, - { pos.X + ViewSin * psize, pos.Y - ViewCos * psize } + { pos.X - r_viewpoint.Sin * psize, pos.Y + r_viewpoint.Cos * psize }, + { pos.X + r_viewpoint.Sin * psize, pos.Y - r_viewpoint.Cos * psize } }; TriVertex *vertices = PolyVertexBuffer::GetVertices(4); @@ -46,7 +46,7 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP return; bool foggy = false; - int actualextralight = foggy ? 0 : extralight << 4; + int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; std::pair offsets[4] = { diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index 00a283b0ab..8eddd52a72 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -57,7 +57,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl //fakeFloor->alpha double fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight < ViewPos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) + if (fakeHeight < r_viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) { plane.Render3DFloor(worldToClip, clipPlane, sub, subsectorDepth, stencilValue, false, fakeFloor); } @@ -78,7 +78,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl //fakeFloor->alpha double fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight > ViewPos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) + if (fakeHeight > r_viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) { plane.Render3DFloor(worldToClip, clipPlane, sub, subsectorDepth, stencilValue, true, fakeFloor); } @@ -187,8 +187,8 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan { seg_t *line = &sub->firstline[i]; - DVector2 pt1 = line->v1->fPos() - ViewPos; - DVector2 pt2 = line->v2->fPos() - ViewPos; + DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) inside = false; @@ -218,7 +218,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan else if(polyportal->PortalPlane == Vec4f(0.0f) || Vec4f::dot(polyportal->PortalPlane, Vec4f((float)v.X, (float)v.Y, 0.0f, 1.0f)) > 0.0f) { DVector2 planePos = v; - DVector2 planeNormal = v - ViewPos; + DVector2 planeNormal = v - r_viewpoint.Pos; planeNormal.MakeUnit(); double planeD = -(planeNormal | (planePos + planeNormal * 0.001)); polyportal->PortalPlane = Vec4f((float)planeNormal.X, (float)planeNormal.Y, 0.0f, (float)planeD); @@ -238,7 +238,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan { // Floor and ceiling texture needs to be swapped sometimes? Why?? :( - if (ViewPos.Z < fakesector->floorplane.Zat0()) // In water + if (r_viewpoint.Pos.Z < fakesector->floorplane.Zat0()) // In water { if (ceiling) { @@ -254,7 +254,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan ccw = true; } } - else if (ViewPos.Z >= fakesector->ceilingplane.Zat0() && !fakeflooronly) // In ceiling water + else if (r_viewpoint.Pos.Z >= fakesector->ceilingplane.Zat0() && !fakeflooronly) // In ceiling water { if (ceiling) { diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index 0288725a93..a8354f8cc0 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -43,18 +43,18 @@ void RenderPolyPlayerSprites::Render() // draws the canvas textures between this call and the final call to RenderRemainingSprites.. if (!r_drawplayersprites || - !camera || - !camera->player || + !r_viewpoint.camera || + !r_viewpoint.camera->player || (players[consoleplayer].cheats & CF_CHASECAM) || - (r_deathcamera && camera->health <= 0)) + (r_deathcamera && r_viewpoint.camera->health <= 0)) return; float bobx, boby; - P_BobWeapon(camera->player, &bobx, &boby, r_TicFracF); + P_BobWeapon(r_viewpoint.camera->player, &bobx, &boby, r_viewpoint.TicFrac); // Interpolate the main weapon layer once so as to be able to add it to other layers. double wx, wy; - DPSprite *weapon = camera->player->FindPSprite(PSP_WEAPON); + DPSprite *weapon = r_viewpoint.camera->player->FindPSprite(PSP_WEAPON); if (weapon) { if (weapon->firstTic) @@ -64,8 +64,8 @@ void RenderPolyPlayerSprites::Render() } else { - wx = weapon->oldx + (weapon->x - weapon->oldx) * r_TicFracF; - wy = weapon->oldy + (weapon->y - weapon->oldy) * r_TicFracF; + wx = weapon->oldx + (weapon->x - weapon->oldx) * r_viewpoint.TicFrac; + wy = weapon->oldy + (weapon->y - weapon->oldy) * r_viewpoint.TicFrac; } } else @@ -74,7 +74,7 @@ void RenderPolyPlayerSprites::Render() wy = 0; } - for (DPSprite *sprite = camera->player->psprites; sprite != nullptr; sprite = sprite->GetNext()) + for (DPSprite *sprite = r_viewpoint.camera->player->psprites; sprite != nullptr; sprite = sprite->GetNext()) { // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. // It's possible this psprite's caller is now null but the layer itself hasn't been destroyed @@ -82,7 +82,7 @@ void RenderPolyPlayerSprites::Render() // In this case let's simply not draw it to avoid crashing. if ((sprite->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr) && sprite->GetCaller() != nullptr) { - RenderSprite(sprite, camera, bobx, boby, wx, wy, r_TicFracF); + RenderSprite(sprite, r_viewpoint.camera, bobx, boby, wx, wy, r_viewpoint.TicFrac); } } } @@ -143,7 +143,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa auto viewport = swrenderer::RenderViewport::Instance(); - double pspritexscale = centerxwide / 160.0; + double pspritexscale = r_viewwindow.centerxwide / 160.0; double pspriteyscale = pspritexscale * viewport->YaspectMul; double pspritexiscale = 1 / pspritexscale; @@ -167,7 +167,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa double texturemid = (BaseYCenter - sy) * tex->Scale.Y + tex->TopOffset; // Adjust PSprite for fullscreen views - if (camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale))) + if (r_viewpoint.camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale))) { AWeapon *weapon = dyn_cast(sprite->GetCaller()); if (weapon != nullptr && weapon->YAdjust != 0) @@ -186,7 +186,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa // Move the weapon down for 1280x1024. if (sprite->GetID() < PSP_TARGETCENTER) { - texturemid -= AspectPspriteOffset(WidescreenRatio); + texturemid -= AspectPspriteOffset(r_viewwindow.WidescreenRatio); } int clipped_x1 = MAX(x1, 0); @@ -212,7 +212,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa bool noaccel = false; - FDynamicColormap *basecolormap = viewsector->ColorMap; + FDynamicColormap *basecolormap = r_viewpoint.sector->ColorMap; FDynamicColormap *colormap_to_use = basecolormap; int ColormapNum = 0; @@ -222,7 +222,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa RenderStyle = STYLE_Normal; bool foggy = false; - int actualextralight = foggy ? 0 : extralight << 4; + int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; int spriteshade = swrenderer::LightVisibility::LightLevelToShade(owner->Sector->lightlevel + actualextralight, foggy); double minz = double((2048 * 4) / double(1 << 20)); ColormapNum = GETPALOOKUP(swrenderer::LightVisibility::Instance()->SpriteGlobVis(foggy) / minz, spriteshade); @@ -287,14 +287,14 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa } */ - if (camera->Inventory != nullptr) + if (r_viewpoint.camera->Inventory != nullptr) { visstyle_t visstyle; visstyle.Alpha = Alpha; visstyle.RenderStyle = STYLE_Count; visstyle.Invert = false; - camera->Inventory->AlterWeaponSprite(&visstyle); + r_viewpoint.camera->Inventory->AlterWeaponSprite(&visstyle); Alpha = visstyle.Alpha; diff --git a/src/polyrenderer/scene/poly_portal.cpp b/src/polyrenderer/scene/poly_portal.cpp index 9ef0f3bdd8..a225b54778 100644 --- a/src/polyrenderer/scene/poly_portal.cpp +++ b/src/polyrenderer/scene/poly_portal.cpp @@ -32,8 +32,6 @@ #include "swrenderer/scene/r_light.h" #include "gl/data/gl_data.h" -extern bool r_showviewer; - ///////////////////////////////////////////////////////////////////////////// PolyDrawSectorPortal::PolyDrawSectorPortal(FSectorPortal *portal, bool ceiling) : Portal(portal), Ceiling(ceiling) @@ -49,21 +47,21 @@ void PolyDrawSectorPortal::Render(int portalDepth) SaveGlobals(); // To do: get this information from PolyRenderer instead of duplicating the code.. - double radPitch = ViewPitch.Normalized180().Radians(); + double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); float adjustedPitch = (float)asin(angy / alen); - float adjustedViewAngle = (float)(ViewAngle - 90).Radians(); - float ratio = WidescreenRatio; - float fovratio = (WidescreenRatio >= 1.3f) ? 1.333333f : ratio; - float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(FieldOfView.Radians() / 2) / fovratio)).Degrees); + float adjustedViewAngle = (float)(r_viewpoint.Angles.Yaw - 90).Radians(); + float ratio = r_viewwindow.WidescreenRatio; + float fovratio = (r_viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; + float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(r_viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); TriMatrix worldToView = TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) * TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) * TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) * TriMatrix::swapYZ() * - TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z); + TriMatrix::translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; RenderPortal.SetViewpoint(worldToClip, PortalPlane, StencilValue); @@ -87,33 +85,33 @@ void PolyDrawSectorPortal::RenderTranslucent(int portalDepth) void PolyDrawSectorPortal::SaveGlobals() { - savedextralight = extralight; - savedpos = ViewPos; - savedangle = ViewAngle; + savedextralight = r_viewpoint.extralight; + savedpos = r_viewpoint.Pos; + savedangles = r_viewpoint.Angles; savedvisibility = swrenderer::LightVisibility::Instance()->GetVisibility(); - savedcamera = camera; - savedsector = viewsector; + savedcamera = r_viewpoint.camera; + savedsector = r_viewpoint.sector; if (Portal->mType == PORTS_SKYVIEWPOINT) { // Don't let gun flashes brighten the sky box AActor *sky = Portal->mSkybox; - extralight = 0; + r_viewpoint.extralight = 0; swrenderer::LightVisibility::Instance()->SetVisibility(sky->args[0] * 0.25f); - ViewPos = sky->InterpolatedPosition(r_TicFracF); - ViewAngle = savedangle + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_TicFracF); + r_viewpoint.Pos = sky->InterpolatedPosition(r_viewpoint.TicFrac); + r_viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_viewpoint.TicFrac); } else //if (Portal->mType == PORTS_STACKEDSECTORTHING || Portal->mType == PORTS_PORTAL || Portal->mType == PORTS_LINKEDPORTAL) { //extralight = pl->extralight; //swrenderer::R_SetVisibility(pl->visibility); - ViewPos.X += Portal->mDisplacement.X; - ViewPos.Y += Portal->mDisplacement.Y; + r_viewpoint.Pos.X += Portal->mDisplacement.X; + r_viewpoint.Pos.Y += Portal->mDisplacement.Y; } - camera = nullptr; - viewsector = Portal->mDestination; - R_SetViewAngle(); + r_viewpoint.camera = nullptr; + r_viewpoint.sector = Portal->mDestination; + R_SetViewAngle(r_viewpoint, r_viewwindow); Portal->mFlags |= PORTSF_INSKYBOX; if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].mFlags |= PORTSF_INSKYBOX; @@ -124,13 +122,13 @@ void PolyDrawSectorPortal::RestoreGlobals() Portal->mFlags &= ~PORTSF_INSKYBOX; if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].mFlags &= ~PORTSF_INSKYBOX; - camera = savedcamera; - viewsector = savedsector; - ViewPos = savedpos; + r_viewpoint.camera = savedcamera; + r_viewpoint.sector = savedsector; + r_viewpoint.Pos = savedpos; swrenderer::LightVisibility::Instance()->SetVisibility(savedvisibility); - extralight = savedextralight; - ViewAngle = savedangle; - R_SetViewAngle(); + r_viewpoint.extralight = savedextralight; + r_viewpoint.Angles = savedangles; + R_SetViewAngle(r_viewpoint, r_viewwindow); } ///////////////////////////////////////////////////////////////////////////// @@ -150,21 +148,21 @@ void PolyDrawLinePortal::Render(int portalDepth) SaveGlobals(); // To do: get this information from PolyRenderer instead of duplicating the code.. - double radPitch = ViewPitch.Normalized180().Radians(); + double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); float adjustedPitch = (float)asin(angy / alen); - float adjustedViewAngle = (float)(ViewAngle - 90).Radians(); - float ratio = WidescreenRatio; - float fovratio = (WidescreenRatio >= 1.3f) ? 1.333333f : ratio; - float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(FieldOfView.Radians() / 2) / fovratio)).Degrees); + float adjustedViewAngle = (float)(r_viewpoint.Angles.Yaw - 90).Radians(); + float ratio = r_viewwindow.WidescreenRatio; + float fovratio = (r_viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; + float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(r_viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); TriMatrix worldToView = TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) * TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) * TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) * TriMatrix::swapYZ() * - TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z); + TriMatrix::translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); if (Mirror) worldToView = TriMatrix::scale(-1.0f, 1.0f, 1.0f) * worldToView; TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; @@ -193,30 +191,30 @@ void PolyDrawLinePortal::RenderTranslucent(int portalDepth) void PolyDrawLinePortal::SaveGlobals() { - savedextralight = extralight; - savedpos = ViewPos; - savedangle = ViewAngle; - savedcamera = camera; - savedsector = viewsector; - savedinvisibility = camera ? (camera->renderflags & RF_INVISIBLE) == RF_INVISIBLE : false; - savedViewPath[0] = ViewPath[0]; - savedViewPath[1] = ViewPath[1]; + savedextralight = r_viewpoint.extralight; + savedpos = r_viewpoint.Pos; + savedangles = r_viewpoint.Angles; + savedcamera = r_viewpoint.camera; + savedsector = r_viewpoint.sector; + savedinvisibility = r_viewpoint.camera ? (r_viewpoint.camera->renderflags & RF_INVISIBLE) == RF_INVISIBLE : false; + savedViewPath[0] = r_viewpoint.Path[0]; + savedViewPath[1] = r_viewpoint.Path[1]; if (Mirror) { - DAngle startang = ViewAngle; - DVector3 startpos = ViewPos; + DAngle startang = r_viewpoint.Angles.Yaw; + DVector3 startpos = r_viewpoint.Pos; vertex_t *v1 = Mirror->v1; // Reflect the current view behind the mirror. if (Mirror->Delta().X == 0) { // vertical mirror - ViewPos.X = v1->fX() - startpos.X + v1->fX(); + r_viewpoint.Pos.X = v1->fX() - startpos.X + v1->fX(); } else if (Mirror->Delta().Y == 0) { // horizontal mirror - ViewPos.Y = v1->fY() - startpos.Y + v1->fY(); + r_viewpoint.Pos.Y = v1->fY() - startpos.Y + v1->fY(); } else { // any mirror @@ -232,36 +230,36 @@ void PolyDrawLinePortal::SaveGlobals() // the above two cases catch len == 0 double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); - ViewPos.X = (x1 + r * dx) * 2 - x; - ViewPos.Y = (y1 + r * dy) * 2 - y; + r_viewpoint.Pos.X = (x1 + r * dx) * 2 - x; + r_viewpoint.Pos.Y = (y1 + r * dy) * 2 - y; } - ViewAngle = Mirror->Delta().Angle() * 2 - startang; + r_viewpoint.Angles.Yaw = Mirror->Delta().Angle() * 2 - startang; - if (camera) - camera->renderflags &= ~RF_INVISIBLE; + if (r_viewpoint.camera) + r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; } else { auto src = Portal->mOrigin; auto dst = Portal->mDestination; - P_TranslatePortalXY(src, ViewPos.X, ViewPos.Y); - P_TranslatePortalZ(src, ViewPos.Z); - P_TranslatePortalAngle(src, ViewAngle); - P_TranslatePortalXY(src, ViewPath[0].X, ViewPath[0].Y); - P_TranslatePortalXY(src, ViewPath[1].X, ViewPath[1].Y); + P_TranslatePortalXY(src, r_viewpoint.Pos.X, r_viewpoint.Pos.Y); + P_TranslatePortalZ(src, r_viewpoint.Pos.Z); + P_TranslatePortalAngle(src, r_viewpoint.Angles.Yaw); + P_TranslatePortalXY(src, r_viewpoint.Path[0].X, r_viewpoint.Path[0].Y); + P_TranslatePortalXY(src, r_viewpoint.Path[1].X, r_viewpoint.Path[1].Y); - if (!r_showviewer && camera && P_PointOnLineSidePrecise(ViewPath[0], dst) != P_PointOnLineSidePrecise(ViewPath[1], dst)) + if (!r_viewpoint.showviewer && r_viewpoint.camera && P_PointOnLineSidePrecise(r_viewpoint.Path[0], dst) != P_PointOnLineSidePrecise(r_viewpoint.Path[1], dst)) { - double distp = (ViewPath[0] - ViewPath[1]).Length(); + double distp = (r_viewpoint.Path[0] - r_viewpoint.Path[1]).Length(); if (distp > EQUAL_EPSILON) { - double dist1 = (ViewPos - ViewPath[0]).Length(); - double dist2 = (ViewPos - ViewPath[1]).Length(); + double dist1 = (r_viewpoint.Pos - r_viewpoint.Path[0]).Length(); + double dist2 = (r_viewpoint.Pos - r_viewpoint.Path[1]).Length(); if (dist1 + dist2 < distp + 1) { - camera->renderflags |= RF_INVISIBLE; + r_viewpoint.camera->renderflags |= RF_INVISIBLE; } } } @@ -269,7 +267,7 @@ void PolyDrawLinePortal::SaveGlobals() //camera = nullptr; //viewsector = R_PointInSubsector(ViewPos)->sector; - R_SetViewAngle(); + R_SetViewAngle(r_viewpoint, r_viewwindow); if (Mirror) PolyTriangleDrawer::toggle_mirror(); @@ -277,21 +275,21 @@ void PolyDrawLinePortal::SaveGlobals() void PolyDrawLinePortal::RestoreGlobals() { - if (camera) + if (r_viewpoint.camera) { if (savedinvisibility) - camera->renderflags |= RF_INVISIBLE; + r_viewpoint.camera->renderflags |= RF_INVISIBLE; else - camera->renderflags &= ~RF_INVISIBLE; + r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; } - camera = savedcamera; - viewsector = savedsector; - ViewPos = savedpos; - extralight = savedextralight; - ViewAngle = savedangle; - ViewPath[0] = savedViewPath[0]; - ViewPath[1] = savedViewPath[1]; - R_SetViewAngle(); + r_viewpoint.camera = savedcamera; + r_viewpoint.sector = savedsector; + r_viewpoint.Pos = savedpos; + r_viewpoint.extralight = savedextralight; + r_viewpoint.Angles = savedangles; + r_viewpoint.Path[0] = savedViewPath[0]; + r_viewpoint.Path[1] = savedViewPath[1]; + R_SetViewAngle(r_viewpoint, r_viewwindow); if (Mirror) PolyTriangleDrawer::toggle_mirror(); diff --git a/src/polyrenderer/scene/poly_portal.h b/src/polyrenderer/scene/poly_portal.h index 24a812a4f5..3f8d526426 100644 --- a/src/polyrenderer/scene/poly_portal.h +++ b/src/polyrenderer/scene/poly_portal.h @@ -63,7 +63,7 @@ private: int savedextralight; DVector3 savedpos; - DAngle savedangle; + DRotator savedangles; double savedvisibility; AActor *savedcamera; sector_t *savedsector; @@ -92,7 +92,7 @@ private: int savedextralight; DVector3 savedpos; - DAngle savedangle; + DRotator savedangles; AActor *savedcamera; sector_t *savedsector; bool savedinvisibility; diff --git a/src/polyrenderer/scene/poly_scene.cpp b/src/polyrenderer/scene/poly_scene.cpp index 95e866bc29..4be2e90d95 100644 --- a/src/polyrenderer/scene/poly_scene.cpp +++ b/src/polyrenderer/scene/poly_scene.cpp @@ -187,8 +187,8 @@ void RenderPolyScene::RenderSprite(AActor *thing, double sortDistance, DVector2 void RenderPolyScene::RenderLine(subsector_t *sub, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth) { // Reject lines not facing viewer - DVector2 pt1 = line->v1->fPos() - ViewPos; - DVector2 pt2 = line->v2->fPos() - ViewPos; + DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) return; @@ -335,7 +335,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth) DVector2 left, right; if (!RenderPolySprite::GetLine(thing, left, right)) continue; - double distanceSquared = (thing->Pos() - ViewPos).LengthSquared(); + double distanceSquared = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); RenderSprite(thing, distanceSquared, left, right); } } diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 507319e26c..2bf4601a68 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -50,7 +50,7 @@ void PolySkyDome::Render(const TriMatrix &worldToClip) if (level.flags & LEVEL_DOUBLESKY) backskytex = TexMan(sky2tex, true); - TriMatrix objectToWorld = TriMatrix::translate((float)ViewPos.X, (float)ViewPos.Y, (float)ViewPos.Z); + TriMatrix objectToWorld = TriMatrix::translate((float)r_viewpoint.Pos.X, (float)r_viewpoint.Pos.Y, (float)r_viewpoint.Pos.Z); objectToClip = worldToClip * objectToWorld; int rc = mRows + 1; diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index e2ca59b240..a96ac88a91 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -38,7 +38,7 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) if (IsThingCulled(thing)) return false; - DVector3 pos = thing->InterpolatedPosition(r_TicFracF); + DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = GetSpriteTexture(thing, flipTextureX); @@ -59,8 +59,8 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) pos.X += spriteHalfWidth; - left = DVector2(pos.X - ViewSin * spriteHalfWidth, pos.Y + ViewCos * spriteHalfWidth); - right = DVector2(pos.X + ViewSin * spriteHalfWidth, pos.Y - ViewCos * spriteHalfWidth); + left = DVector2(pos.X - r_viewpoint.Sin * spriteHalfWidth, pos.Y + r_viewpoint.Cos * spriteHalfWidth); + right = DVector2(pos.X + r_viewpoint.Sin * spriteHalfWidth, pos.Y - r_viewpoint.Cos * spriteHalfWidth); return true; } @@ -70,8 +70,8 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla if (!GetLine(thing, line[0], line[1])) return; - DVector3 pos = thing->InterpolatedPosition(r_TicFracF); - pos.Z += thing->GetBobOffset(r_TicFracF); + DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = GetSpriteTexture(thing, flipTextureX); @@ -105,7 +105,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla return; bool foggy = false; - int actualextralight = foggy ? 0 : extralight << 4; + int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; std::pair offsets[4] = { @@ -273,7 +273,7 @@ bool RenderPolySprite::IsThingCulled(AActor *thing) FIntCVar *cvar = thing->GetClass()->distancecheck; if (cvar != nullptr && *cvar >= 0) { - double dist = (thing->Pos() - ViewPos).LengthSquared(); + double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) return true; @@ -385,9 +385,9 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) { // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[tex->Rotations]; - DVector3 pos = thing->InterpolatedPosition(r_TicFracF); - pos.Z += thing->GetBobOffset(r_TicFracF); - DAngle ang = (pos - ViewPos).Angle(); + DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); + DAngle ang = (pos - r_viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { @@ -420,9 +420,9 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; - DVector3 pos = thing->InterpolatedPosition(r_TicFracF); - pos.Z += thing->GetBobOffset(r_TicFracF); - DAngle ang = (pos - ViewPos).Angle(); + DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); + DAngle ang = (pos - r_viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index 2e42bb4883..4ce7e5f8e4 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -362,7 +362,7 @@ int RenderPolyWall::GetLightLevel() else { bool foggy = false; - int actualextralight = foggy ? 0 : extralight << 4; + int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; return clamp(Side->GetLightLevel(foggy, LineSeg->frontsector->lightlevel) + actualextralight, 0, 255); } } diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index cee3641a16..a249bc14a9 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -34,8 +34,8 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli if (RenderPolySprite::IsThingCulled(thing)) return; - DVector3 pos = thing->InterpolatedPosition(r_TicFracF); - pos.Z += thing->GetBobOffset(r_TicFracF); + DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = RenderPolySprite::GetSpriteTexture(thing, flipTextureX); @@ -73,7 +73,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli return; bool foggy = false; - int actualextralight = foggy ? 0 : extralight << 4; + int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; std::pair offsets[4] = { diff --git a/src/r_sky.cpp b/src/r_sky.cpp index ac7db73a40..c3d8de1a07 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -133,8 +133,8 @@ void R_InitSkyMap () skyiscale = float(r_Yaspect / freelookviewheight); skyscale = freelookviewheight / r_Yaspect; - skyiscale *= float(FieldOfView.Degrees / 90.); - skyscale *= float(90. / FieldOfView.Degrees); + skyiscale *= float(r_viewpoint.FieldOfView.Degrees / 90.); + skyscale *= float(90. / r_viewpoint.FieldOfView.Degrees); } if (skystretch) diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 9ea78cf3b0..a125fa3480 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -106,46 +106,43 @@ int viewwindowy; int viewwidth; int viewheight; -DVector3 ViewPos; -DVector3 ViewActorPos; // the actual position of the viewing actor, without interpolation and quake offsets. -DAngle ViewAngle; -DAngle ViewPitch; -DAngle ViewRoll; -DVector3 ViewPath[2]; -double ViewCos, ViewTanCos; -double ViewSin, ViewTanSin; +FRenderViewpoint::FRenderViewpoint() +{ + player = nullptr; + Pos = { 0.0, 0.0, 0.0 }; + ActorPos = { 0.0, 0.0, 0.0 }; + Angles = { 0.0, 0.0, 0.0 }; + Path[0] = { 0.0, 0.0, 0.0 }; + Path[1] = { 0.0, 0.0, 0.0 }; + Cos = 0.0; + Sin = 0.0; + TanCos = 0.0; + TanSin = 0.0; + camera = nullptr; + sector = nullptr; + FieldOfView = 90.; // Angles in the SCREENWIDTH wide window + TicFrac = 0.0; + FrameTime = 0; + extralight = 0; + showviewer = false; +} - -int centerx; -int centery; -int centerxwide; +FRenderViewpoint r_viewpoint; +FViewWindow r_viewwindow; int otic; -sector_t *viewsector; - - -AActor *camera; // [RH] camera to draw from. doesn't have to be a player - -double r_TicFracF; // same as floating point -uint32_t r_FrameTime; // [RH] Time this frame started drawing (in ms) bool r_NoInterpolate; -bool r_showviewer; angle_t LocalViewAngle; int LocalViewPitch; bool LocalKeyboardTurner; -float WidescreenRatio; int setblocks; -int extralight; bool setsizeneeded; -double FocalTangent; unsigned int R_OldBlend = ~0; int validcount = 1; // increment every time a check is made -DAngle FieldOfView = 90.; // Angles in the SCREENWIDTH wide window - FCanvasTextureInfo *FCanvasTextureInfo::List; DVector3a view; @@ -163,14 +160,14 @@ static void R_Shutdown (); // //========================================================================== -void R_SetFOV (DAngle fov) +void R_SetFOV (FRenderViewpoint &viewpoint, DAngle fov) { if (fov < 5.) fov = 5.; else if (fov > 170.) fov = 170.; - if (fov != FieldOfView) + if (fov != viewpoint.FieldOfView) { - FieldOfView = fov; + viewpoint.FieldOfView = fov; setsizeneeded = true; } } @@ -196,7 +193,7 @@ void R_SetViewSize (int blocks) // //========================================================================== -void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, bool renderingToCanvas) +void R_SetWindow (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, int windowSize, int fullWidth, int fullHeight, int stHeight, bool renderingToCanvas) { if (windowSize >= 11) { @@ -218,11 +215,11 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, b if (renderingToCanvas) { - WidescreenRatio = fullWidth / (float)fullHeight; + viewwindow.WidescreenRatio = fullWidth / (float)fullHeight; } else { - WidescreenRatio = ActiveRatio(fullWidth, fullHeight); + viewwindow.WidescreenRatio = ActiveRatio(fullWidth, fullHeight); } DrawFSHUD = (windowSize == 11); @@ -230,28 +227,28 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, b // [RH] Sky height fix for screens not 200 (or 240) pixels tall R_InitSkyMap (); - centery = viewheight/2; - centerx = viewwidth/2; - if (AspectTallerThanWide(WidescreenRatio)) + viewwindow.centery = viewheight/2; + viewwindow.centerx = viewwidth/2; + if (AspectTallerThanWide(viewwindow.WidescreenRatio)) { - centerxwide = centerx; + viewwindow.centerxwide = viewwindow.centerx; } else { - centerxwide = centerx * AspectMultiplier(WidescreenRatio) / 48; + viewwindow.centerxwide = viewwindow.centerx * AspectMultiplier(viewwindow.WidescreenRatio) / 48; } - DAngle fov = FieldOfView; + DAngle fov = viewpoint.FieldOfView; // For widescreen displays, increase the FOV so that the middle part of the // screen that would be visible on a 4:3 display has the requested FOV. - if (centerxwide != centerx) + if (viewwindow.centerxwide != viewwindow.centerx) { // centerxwide is what centerx would be if the display was not widescreen - fov = DAngle::ToDegrees(2 * atan(centerx * tan(fov.Radians()/2) / double(centerxwide))); + fov = DAngle::ToDegrees(2 * atan(viewwindow.centerx * tan(fov.Radians()/2) / double(viewwindow.centerxwide))); if (fov > 170.) fov = 170.; } - FocalTangent = tan(fov.Radians() / 2); + viewwindow.FocalTangent = tan(fov.Radians() / 2); } //========================================================================== @@ -260,12 +257,12 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, b // //========================================================================== -void R_ExecuteSetViewSize () +void R_ExecuteSetViewSize (FRenderViewpoint &viewpoint, FViewWindow &viewwindow) { setsizeneeded = false; V_SetBorderNeedRefresh(); - R_SetWindow (setblocks, SCREENWIDTH, SCREENHEIGHT, gST_Y); + R_SetWindow (viewpoint, viewwindow, setblocks, SCREENWIDTH, SCREENHEIGHT, gST_Y); // Handle resize, e.g. smaller view windows with border and/or status bar. viewwindowx = (screen->GetWidth() - viewwidth) >> 1; @@ -361,7 +358,7 @@ static void R_Shutdown () //CVAR (Int, tf, 0, 0) EXTERN_CVAR (Bool, cl_noprediction) -void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *iview) +void R_InterpolateView (FRenderViewpoint &viewpoint, player_t *player, double Frac, InterpolationViewer *iview) { if (NoInterpolateView) { @@ -384,7 +381,7 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie // What needs be done is to store the portal transitions of the camera actor as waypoints // and then find out on which part of the path the current view lies. // Needless to say, this doesn't work for chasecam mode. - if (!r_showviewer) + if (!viewpoint.showviewer) { double pathlen = 0; double zdiff = 0; @@ -426,34 +423,34 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie oviewangle += adiff; nviewangle -= totaladiff - adiff; DVector2 viewpos = start.pos + (fragfrac * (end.pos - start.pos)); - ViewPos = { viewpos, oviewz + Frac * (nviewz - oviewz) }; + viewpoint.Pos = { viewpos, oviewz + Frac * (nviewz - oviewz) }; break; } } InterpolationPath.Pop(); - ViewPath[0] = iview->Old.Pos; - ViewPath[1] = ViewPath[0] + (InterpolationPath[0].pos - ViewPath[0]).XY().MakeResize(pathlen); + viewpoint.Path[0] = iview->Old.Pos; + viewpoint.Path[1] = viewpoint.Path[0] + (InterpolationPath[0].pos - viewpoint.Path[0]).XY().MakeResize(pathlen); } } else { DVector2 disp = Displacements.getOffset(oldgroup, newgroup); - ViewPos = iview->Old.Pos + (iview->New.Pos - iview->Old.Pos - disp) * Frac; - ViewPath[0] = ViewPath[1] = iview->New.Pos; + viewpoint.Pos = iview->Old.Pos + (iview->New.Pos - iview->Old.Pos - disp) * Frac; + viewpoint.Path[0] = viewpoint.Path[1] = iview->New.Pos; } } else { - ViewPos = iview->New.Pos; - ViewPath[0] = ViewPath[1] = iview->New.Pos; + viewpoint.Pos = iview->New.Pos; + viewpoint.Path[0] = viewpoint.Path[1] = iview->New.Pos; } if (player != NULL && !(player->cheats & CF_INTERPVIEW) && player - players == consoleplayer && - camera == player->mo && + viewpoint.camera == player->mo && !demoplayback && - iview->New.Pos.X == camera->X() && - iview->New.Pos.Y == camera->Y() && + iview->New.Pos.X == viewpoint.camera->X() && + iview->New.Pos.Y == viewpoint.camera->Y() && !(player->cheats & (CF_TOTALLYFROZEN|CF_FROZEN)) && player->playerstate == PST_LIVE && player->mo->reactiontime == 0 && @@ -462,41 +459,41 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie (!netgame || !cl_noprediction) && !LocalKeyboardTurner) { - ViewAngle = (nviewangle + AngleToFloat(LocalViewAngle & 0xFFFF0000)).Normalized180(); + viewpoint.Angles.Yaw = (nviewangle + AngleToFloat(LocalViewAngle & 0xFFFF0000)).Normalized180(); DAngle delta = player->centering ? DAngle(0.) : AngleToFloat(int(LocalViewPitch & 0xFFFF0000)); - ViewPitch = clamp((iview->New.Angles.Pitch - delta).Normalized180(), player->MinPitch, player->MaxPitch); - ViewRoll = iview->New.Angles.Roll.Normalized180(); + viewpoint.Angles.Pitch = clamp((iview->New.Angles.Pitch - delta).Normalized180(), player->MinPitch, player->MaxPitch); + viewpoint.Angles.Roll = iview->New.Angles.Roll.Normalized180(); } else { - ViewPitch = (iview->Old.Angles.Pitch + deltaangle(iview->Old.Angles.Pitch, iview->New.Angles.Pitch) * Frac).Normalized180(); - ViewAngle = (oviewangle + deltaangle(oviewangle, nviewangle) * Frac).Normalized180(); - ViewRoll = (iview->Old.Angles.Roll + deltaangle(iview->Old.Angles.Roll, iview->New.Angles.Roll) * Frac).Normalized180(); + viewpoint.Angles.Pitch = (iview->Old.Angles.Pitch + deltaangle(iview->Old.Angles.Pitch, iview->New.Angles.Pitch) * Frac).Normalized180(); + viewpoint.Angles.Yaw = (oviewangle + deltaangle(oviewangle, nviewangle) * Frac).Normalized180(); + viewpoint.Angles.Roll = (iview->Old.Angles.Roll + deltaangle(iview->Old.Angles.Roll, iview->New.Angles.Roll) * Frac).Normalized180(); } // Due to interpolation this is not necessarily the same as the sector the camera is in. - viewsector = R_PointInSubsector(ViewPos)->sector; + viewpoint.sector = R_PointInSubsector(viewpoint.Pos)->sector; bool moved = false; - while (!viewsector->PortalBlocksMovement(sector_t::ceiling)) + while (!viewpoint.sector->PortalBlocksMovement(sector_t::ceiling)) { - if (ViewPos.Z > viewsector->GetPortalPlaneZ(sector_t::ceiling)) + if (viewpoint.Pos.Z > viewpoint.sector->GetPortalPlaneZ(sector_t::ceiling)) { - ViewPos += viewsector->GetPortalDisplacement(sector_t::ceiling); - ViewActorPos += viewsector->GetPortalDisplacement(sector_t::ceiling); - viewsector = R_PointInSubsector(ViewPos)->sector; + viewpoint.Pos += viewpoint.sector->GetPortalDisplacement(sector_t::ceiling); + viewpoint.ActorPos += viewpoint.sector->GetPortalDisplacement(sector_t::ceiling); + viewpoint.sector = R_PointInSubsector(viewpoint.Pos)->sector; moved = true; } else break; } if (!moved) { - while (!viewsector->PortalBlocksMovement(sector_t::floor)) + while (!viewpoint.sector->PortalBlocksMovement(sector_t::floor)) { - if (ViewPos.Z < viewsector->GetPortalPlaneZ(sector_t::floor)) + if (viewpoint.Pos.Z < viewpoint.sector->GetPortalPlaneZ(sector_t::floor)) { - ViewPos += viewsector->GetPortalDisplacement(sector_t::floor); - ViewActorPos += viewsector->GetPortalDisplacement(sector_t::floor); - viewsector = R_PointInSubsector(ViewPos)->sector; + viewpoint.Pos += viewpoint.sector->GetPortalDisplacement(sector_t::floor); + viewpoint.ActorPos += viewpoint.sector->GetPortalDisplacement(sector_t::floor); + viewpoint.sector = R_PointInSubsector(viewpoint.Pos)->sector; moved = true; } else break; @@ -522,13 +519,13 @@ void R_ResetViewInterpolation () // //========================================================================== -void R_SetViewAngle () +void R_SetViewAngle (FRenderViewpoint &viewpoint, const FViewWindow &viewwindow) { - ViewSin = ViewAngle.Sin(); - ViewCos = ViewAngle.Cos(); + viewpoint.Sin = viewpoint.Angles.Yaw.Sin(); + viewpoint.Cos = viewpoint.Angles.Yaw.Cos(); - ViewTanSin = FocalTangent * ViewSin; - ViewTanCos = FocalTangent * ViewCos; + viewpoint.TanSin = viewwindow.FocalTangent * viewpoint.Sin; + viewpoint.TanCos = viewwindow.FocalTangent * viewpoint.Cos; } //========================================================================== @@ -677,7 +674,7 @@ static double QuakePower(double factor, double intensity, double offset) // //========================================================================== -void R_SetupFrame (AActor *actor) +void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor *actor) { if (actor == NULL) { @@ -691,23 +688,23 @@ void R_SetupFrame (AActor *actor) if (player != NULL && player->mo == actor) { // [RH] Use camera instead of viewplayer - camera = player->camera; - if (camera == NULL) + viewpoint.camera = player->camera; + if (viewpoint.camera == NULL) { - camera = player->camera = player->mo; + viewpoint.camera = player->camera = player->mo; } } else { - camera = actor; + viewpoint.camera = actor; } - if (camera == NULL) + if (viewpoint.camera == NULL) { I_Error ("You lost your body. Bad dehacked work is likely to blame."); } - iview = FindPastViewer (camera); + iview = FindPastViewer (viewpoint.camera); int nowtic = I_GetTime (false); if (iview->otic != -1 && nowtic > iview->otic) @@ -717,38 +714,38 @@ void R_SetupFrame (AActor *actor) } if (player != NULL && gamestate != GS_TITLELEVEL && - ((player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0))) + ((player->cheats & CF_CHASECAM) || (r_deathcamera && viewpoint.camera->health <= 0))) { sector_t *oldsector = R_PointInSubsector(iview->Old.Pos)->sector; // [RH] Use chasecam view DVector3 campos; DAngle camangle; - P_AimCamera (camera, campos, camangle, viewsector, unlinked); // fixme: This needs to translate the angle, too. + P_AimCamera (viewpoint.camera, campos, camangle, viewpoint.sector, unlinked); // fixme: This needs to translate the angle, too. iview->New.Pos = campos; iview->New.Angles.Yaw = camangle; - r_showviewer = true; + viewpoint.showviewer = true; // Interpolating this is a very complicated thing because nothing keeps track of the aim camera's movement, so whenever we detect a portal transition // it's probably best to just reset the interpolation for this move. // Note that this can still cause problems with unusually linked portals - if (viewsector->PortalGroup != oldsector->PortalGroup || (unlinked && ((iview->New.Pos.XY() - iview->Old.Pos.XY()).LengthSquared()) > 256*256)) + if (viewpoint.sector->PortalGroup != oldsector->PortalGroup || (unlinked && ((iview->New.Pos.XY() - iview->Old.Pos.XY()).LengthSquared()) > 256*256)) { iview->otic = nowtic; iview->Old = iview->New; r_NoInterpolate = true; } - ViewActorPos = campos; + viewpoint.ActorPos = campos; } else { - ViewActorPos = iview->New.Pos = { camera->Pos().XY(), camera->player ? camera->player->viewz : camera->Z() + camera->GetCameraHeight() }; - viewsector = camera->Sector; - r_showviewer = false; + viewpoint.ActorPos = iview->New.Pos = { viewpoint.camera->Pos().XY(), viewpoint.camera->player ? viewpoint.camera->player->viewz : viewpoint.camera->Z() + viewpoint.camera->GetCameraHeight() }; + viewpoint.sector = viewpoint.camera->Sector; + viewpoint.showviewer = false; } - iview->New.Angles = camera->Angles; - if (camera->player != 0) + iview->New.Angles = viewpoint.camera->Angles; + if (viewpoint.camera->player != 0) { - player = camera->player; + player = viewpoint.camera->player; } if (iview->otic == -1 || r_NoInterpolate) @@ -757,33 +754,33 @@ void R_SetupFrame (AActor *actor) iview->otic = nowtic; } - r_TicFracF = I_GetTimeFrac (&r_FrameTime); + viewpoint.TicFrac = I_GetTimeFrac (&viewpoint.FrameTime); if (cl_capfps || r_NoInterpolate) { - r_TicFracF = 1.; + viewpoint.TicFrac = 1.; } - R_InterpolateView (player, r_TicFracF, iview); + R_InterpolateView (viewpoint, player, viewpoint.TicFrac, iview); - R_SetViewAngle (); + R_SetViewAngle (viewpoint, viewwindow); - interpolator.DoInterpolations (r_TicFracF); + interpolator.DoInterpolations (viewpoint.TicFrac); // Keep the view within the sector's floor and ceiling - if (viewsector->PortalBlocksMovement(sector_t::ceiling)) + if (viewpoint.sector->PortalBlocksMovement(sector_t::ceiling)) { - double theZ = viewsector->ceilingplane.ZatPoint(ViewPos) - 4; - if (ViewPos.Z > theZ) + double theZ = viewpoint.sector->ceilingplane.ZatPoint(viewpoint.Pos) - 4; + if (viewpoint.Pos.Z > theZ) { - ViewPos.Z = theZ; + viewpoint.Pos.Z = theZ; } } - if (viewsector->PortalBlocksMovement(sector_t::floor)) + if (viewpoint.sector->PortalBlocksMovement(sector_t::floor)) { - double theZ = viewsector->floorplane.ZatPoint(ViewPos) + 4; - if (ViewPos.Z < theZ) + double theZ = viewpoint.sector->floorplane.ZatPoint(viewpoint.Pos) + 4; + if (viewpoint.Pos.Z < theZ) { - ViewPos.Z = theZ; + viewpoint.Pos.Z = theZ; } } @@ -792,62 +789,62 @@ void R_SetupFrame (AActor *actor) FQuakeJiggers jiggers; memset(&jiggers, 0, sizeof(jiggers)); - if (DEarthquake::StaticGetQuakeIntensities(camera, jiggers) > 0) + if (DEarthquake::StaticGetQuakeIntensities(viewpoint.camera, jiggers) > 0) { double quakefactor = r_quakeintensity; DAngle an; if (jiggers.RollIntensity != 0 || jiggers.RollWave != 0) { - ViewRoll += QuakePower(quakefactor, jiggers.RollIntensity, jiggers.RollWave); + viewpoint.Angles.Roll += QuakePower(quakefactor, jiggers.RollIntensity, jiggers.RollWave); } if (jiggers.RelIntensity.X != 0 || jiggers.RelOffset.X != 0) { - an = camera->Angles.Yaw; + an = viewpoint.camera->Angles.Yaw; double power = QuakePower(quakefactor, jiggers.RelIntensity.X, jiggers.RelOffset.X); - ViewPos += an.ToVector(power); + viewpoint.Pos += an.ToVector(power); } if (jiggers.RelIntensity.Y != 0 || jiggers.RelOffset.Y != 0) { - an = camera->Angles.Yaw + 90; + an = viewpoint.camera->Angles.Yaw + 90; double power = QuakePower(quakefactor, jiggers.RelIntensity.Y, jiggers.RelOffset.Y); - ViewPos += an.ToVector(power); + viewpoint.Pos += an.ToVector(power); } // FIXME: Relative Z is not relative if (jiggers.RelIntensity.Z != 0 || jiggers.RelOffset.Z != 0) { - ViewPos.Z += QuakePower(quakefactor, jiggers.RelIntensity.Z, jiggers.RelOffset.Z); + viewpoint.Pos.Z += QuakePower(quakefactor, jiggers.RelIntensity.Z, jiggers.RelOffset.Z); } if (jiggers.Intensity.X != 0 || jiggers.Offset.X != 0) { - ViewPos.X += QuakePower(quakefactor, jiggers.Intensity.X, jiggers.Offset.X); + viewpoint.Pos.X += QuakePower(quakefactor, jiggers.Intensity.X, jiggers.Offset.X); } if (jiggers.Intensity.Y != 0 || jiggers.Offset.Y != 0) { - ViewPos.Y += QuakePower(quakefactor, jiggers.Intensity.Y, jiggers.Offset.Y); + viewpoint.Pos.Y += QuakePower(quakefactor, jiggers.Intensity.Y, jiggers.Offset.Y); } if (jiggers.Intensity.Z != 0 || jiggers.Offset.Z != 0) { - ViewPos.Z += QuakePower(quakefactor, jiggers.Intensity.Z, jiggers.Offset.Z); + viewpoint.Pos.Z += QuakePower(quakefactor, jiggers.Intensity.Z, jiggers.Offset.Z); } } } - extralight = camera->player ? camera->player->extralight : 0; + viewpoint.extralight = viewpoint.camera->player ? viewpoint.camera->player->extralight : 0; // killough 3/20/98, 4/4/98: select colormap based on player status // [RH] Can also select a blend newblend = 0; - TArray &lightlist = viewsector->e->XFloor.lightlist; + TArray &lightlist = viewpoint.sector->e->XFloor.lightlist; if (lightlist.Size() > 0) { for(unsigned int i = 0; i < lightlist.Size(); i++) { secplane_t *plane; int viewside; - plane = (i < lightlist.Size()-1) ? &lightlist[i+1].plane : &viewsector->floorplane; - viewside = plane->PointOnSide(ViewPos); + plane = (i < lightlist.Size()-1) ? &lightlist[i+1].plane : &viewpoint.sector->floorplane; + viewside = plane->PointOnSide(viewpoint.Pos); // Reverse the direction of the test if the plane was downward facing. // We want to know if the view is above it, whatever its orientation may be. if (plane->fC() < 0) @@ -866,12 +863,12 @@ void R_SetupFrame (AActor *actor) } else { - const sector_t *s = viewsector->GetHeightSec(); + const sector_t *s = viewpoint.sector->GetHeightSec(); if (s != NULL) { - newblend = s->floorplane.PointOnSide(ViewPos) < 0 + newblend = s->floorplane.PointOnSide(viewpoint.Pos) < 0 ? s->bottommap - : s->ceilingplane.PointOnSide(ViewPos) < 0 + : s->ceilingplane.PointOnSide(viewpoint.Pos) < 0 ? s->topmap : s->midmap; if (APART(newblend) == 0 && newblend >= numfakecmaps) diff --git a/src/r_utility.h b/src/r_utility.h index 2c474d5571..8a938cc01a 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -14,11 +14,13 @@ class FSerializer; struct FRenderViewpoint { + FRenderViewpoint(); + player_t *player; // For which player is this viewpoint being renderered? (can be null for camera textures) DVector3 Pos; // Camera position DVector3 ActorPos; // Camera actor's position DRotator Angles; // Camera angles - DVector3 Path; // View path for portal calculations + DVector3 Path[2]; // View path for portal calculations double Cos; // cos(Angles.Yaw) double Sin; // sin(Angles.Yaw) double TanCos; // FocalTangent * cos(Angles.Yaw) @@ -35,38 +37,19 @@ struct FRenderViewpoint bool showviewer; // show the camera actor? }; -extern DVector3 ViewPos; -extern DVector3 ViewActorPos; -extern DAngle ViewAngle; -extern DAngle ViewPitch; -extern DAngle ViewRoll; -extern DVector3 ViewPath[2]; -extern double ViewCos; -extern double ViewSin; -extern double ViewTanCos; -extern double ViewTanSin; -extern AActor* camera; // [RH] camera instead of viewplayer -extern sector_t* viewsector; // [RH] keep track of sector viewing from -extern DAngle FieldOfView; -extern double r_TicFracF; -extern uint32_t r_FrameTime; -extern int extralight; -extern bool r_showviewer; +extern FRenderViewpoint r_viewpoint; //----------------------------------- struct FViewWindow { - double FocalTangent; - int centerx; - int centerxwide; - int centery; - float WidescreenRatio; + double FocalTangent = 0.0; + int centerx = 0; + int centerxwide = 0; + int centery = 0; + float WidescreenRatio = 0.0f; }; -extern int centerx, centerxwide; -extern int centery; -extern double FocalTangent; -extern float WidescreenRatio; +extern FViewWindow r_viewwindow; //----------------------------------- @@ -127,17 +110,17 @@ bool R_GetViewInterpolationStatus(); void R_ClearInterpolationPath(); void R_AddInterpolationPoint(const DVector3a &vec); void R_SetViewSize (int blocks); -void R_SetFOV (DAngle fov); -void R_SetupFrame (AActor * camera); -void R_SetViewAngle (); +void R_SetFOV (FRenderViewpoint &viewpoint, DAngle fov); +void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor * camera); +void R_SetViewAngle (FRenderViewpoint &viewpoint, const FViewWindow &viewwindow); // Called by startup code. void R_Init (void); -void R_ExecuteSetViewSize (void); +void R_ExecuteSetViewSize (FRenderViewpoint &viewpoint, FViewWindow &viewwindow); // Called by M_Responder. void R_SetViewSize (int blocks); -void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, bool renderingToCanvas = false); +void R_SetWindow (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, int windowSize, int fullWidth, int fullHeight, int stHeight, bool renderingToCanvas = false); extern void R_FreePastViewers (); diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index 0e08427cfd..50762072fe 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -2686,7 +2686,7 @@ namespace swrenderer uint32_t u, v; int i; - iz = plane_sz[2] + plane_sz[1] * (centery - y) + plane_sz[0] * (x1 - centerx); + iz = plane_sz[2] + plane_sz[1] * (r_viewwindow.centery - y) + plane_sz[0] * (x1 - r_viewwindow.centerx); // Lighting is simple. It's just linear interpolation from start to end if (plane_shade) @@ -2703,8 +2703,8 @@ namespace swrenderer } } - uz = plane_su[2] + plane_su[1] * (centery - y) + plane_su[0] * (x1 - centerx); - vz = plane_sv[2] + plane_sv[1] * (centery - y) + plane_sv[0] * (x1 - centerx); + uz = plane_su[2] + plane_su[1] * (r_viewwindow.centery - y) + plane_su[0] * (x1 - r_viewwindow.centerx); + vz = plane_sv[2] + plane_sv[1] * (r_viewwindow.centery - y) + plane_sv[0] * (x1 - r_viewwindow.centerx); fb = _dest; diff --git a/src/swrenderer/drawers/r_draw_rgba.cpp b/src/swrenderer/drawers/r_draw_rgba.cpp index b4e3628c38..011d509030 100644 --- a/src/swrenderer/drawers/r_draw_rgba.cpp +++ b/src/swrenderer/drawers/r_draw_rgba.cpp @@ -474,7 +474,7 @@ namespace swrenderer int count = _x2 - _x1 + 1; // Depth (Z) change across the span - double iz = _plane_sz[2] + _plane_sz[1] * (centery - _y) + _plane_sz[0] * (_x1 - centerx); + double iz = _plane_sz[2] + _plane_sz[1] * (r_viewwindow.centery - _y) + _plane_sz[0] * (_x1 - r_viewwindow.centerx); // Light change across the span fixed_t lightstart = _light; @@ -491,8 +491,8 @@ namespace swrenderer fixed_t steplight = (lightend - lightstart) / count; // Texture coordinates - double uz = _plane_su[2] + _plane_su[1] * (centery - _y) + _plane_su[0] * (_x1 - centerx); - double vz = _plane_sv[2] + _plane_sv[1] * (centery - _y) + _plane_sv[0] * (_x1 - centerx); + double uz = _plane_su[2] + _plane_su[1] * (r_viewwindow.centery - _y) + _plane_su[0] * (_x1 - r_viewwindow.centerx); + double vz = _plane_sv[2] + _plane_sv[1] * (r_viewwindow.centery - _y) + _plane_sv[0] * (_x1 - r_viewwindow.centerx); double startz = 1.f / iz; double startu = uz*startz; double startv = vz*startz; diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index 963e3d17b2..d8eee70bb5 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -73,8 +73,8 @@ namespace swrenderer basecolormap = colormap; mLineSegment = line; - DVector2 pt1 = line->v1->fPos() - ViewPos; - DVector2 pt2 = line->v2->fPos() - ViewPos; + DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; // Reject lines not facing viewer if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) @@ -98,7 +98,7 @@ namespace swrenderer // reject lines that aren't seen from the portal (if any) // [ZZ] 10.01.2016: lines inside a skybox shouldn't be clipped, although this imposes some limitations on portals in skyboxes. - if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, ViewPos)) + if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, r_viewpoint.Pos)) return; vertex_t *v1 = line->linedef->v1; @@ -114,7 +114,7 @@ namespace swrenderer { swapvalues(v1, v2); } - WallT.InitFromLine(Thread, v1->fPos() - ViewPos, v2->fPos() - ViewPos); + WallT.InitFromLine(Thread, v1->fPos() - r_viewpoint.Pos, v2->fPos() - r_viewpoint.Pos); } mFrontCeilingZ1 = mFrontSector->ceilingplane.ZatPoint(line->v1); @@ -363,13 +363,13 @@ namespace swrenderer draw_segment->silhouette = 0; if (mFrontFloorZ1 > mBackFloorZ1 || mFrontFloorZ2 > mBackFloorZ2 || - mBackSector->floorplane.PointOnSide(ViewPos) < 0) + mBackSector->floorplane.PointOnSide(r_viewpoint.Pos) < 0) { draw_segment->silhouette = SIL_BOTTOM; } if (mFrontCeilingZ1 < mBackCeilingZ1 || mFrontCeilingZ2 < mBackCeilingZ2 || - mBackSector->ceilingplane.PointOnSide(ViewPos) < 0) + mBackSector->ceilingplane.PointOnSide(r_viewpoint.Pos) < 0) { draw_segment->silhouette |= SIL_TOP; } @@ -564,7 +564,7 @@ namespace swrenderer // deep water check if (mFrontSector->GetHeightSec() == nullptr) { - int planeside = mFrontSector->floorplane.PointOnSide(ViewPos); + int planeside = mFrontSector->floorplane.PointOnSide(r_viewpoint.Pos); if (mFrontSector->floorplane.fC() < 0) // 3D floors have the floor backwards planeside = -planeside; if (planeside <= 0) // above view plane @@ -621,7 +621,7 @@ namespace swrenderer // deep water check if (mFrontSector->GetHeightSec() == nullptr && mFrontSector->GetTexture(sector_t::ceiling) != skyflatnum) { - int planeside = mFrontSector->ceilingplane.PointOnSide(ViewPos); + int planeside = mFrontSector->ceilingplane.PointOnSide(r_viewpoint.Pos); if (mFrontSector->ceilingplane.fC() > 0) // 3D floors have the ceiling backwards planeside = -planeside; if (planeside <= 0) // below view plane @@ -718,8 +718,8 @@ namespace swrenderer if (mLineSegment->linedef->special == Line_Horizon) { // Be aware: Line_Horizon does not work properly with sloped planes - fillshort(walltop.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, centery); - fillshort(wallbottom.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, centery); + fillshort(walltop.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, r_viewwindow.centery); + fillshort(wallbottom.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, r_viewwindow.centery); } else { @@ -819,7 +819,7 @@ namespace swrenderer { // normal orientation if (linedef->flags & ML_DONTPEGTOP) { // top of texture at top - mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat; + mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat; if (rowoffset < 0 && mTopPart.Texture != NULL) { rowoffset += mTopPart.Texture->GetHeight(); @@ -827,7 +827,7 @@ namespace swrenderer } else { // bottom of texture at bottom - mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat + mTopPart.Texture->GetHeight(); + mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat + mTopPart.Texture->GetHeight(); } } else @@ -835,11 +835,11 @@ namespace swrenderer rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGTOP) { // bottom of texture at top - mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat + mTopPart.Texture->GetHeight(); + mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat + mTopPart.Texture->GetHeight(); } else { // top of texture at bottom - mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat; + mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat; } } if (mTopPart.Texture->bWorldPanning) @@ -875,11 +875,11 @@ namespace swrenderer { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); } else { // top of texture at top - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat; + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat; if (rowoffset < 0 && mMiddlePart.Texture != NULL) { rowoffset += mMiddlePart.Texture->GetHeight(); @@ -891,11 +891,11 @@ namespace swrenderer rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat; + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat; } else { // bottom of texture at top - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); } } if (mMiddlePart.Texture->bWorldPanning) @@ -940,11 +940,11 @@ namespace swrenderer { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - mBottomPart.TextureMid = (frontlowertop - ViewPos.Z) * yrepeat; + mBottomPart.TextureMid = (frontlowertop - r_viewpoint.Pos.Z) * yrepeat; } else { // top of texture at top - mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat; + mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat; if (rowoffset < 0 && mBottomPart.Texture != NULL) { rowoffset += mBottomPart.Texture->GetHeight(); @@ -956,11 +956,11 @@ namespace swrenderer rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - mBottomPart.TextureMid = (frontlowertop - ViewPos.Z) * yrepeat; + mBottomPart.TextureMid = (frontlowertop - r_viewpoint.Pos.Z) * yrepeat; } else { // bottom of texture at top - mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat + mBottomPart.Texture->GetHeight(); + mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat + mBottomPart.Texture->GetHeight(); } } if (mBottomPart.Texture->bWorldPanning) @@ -1271,11 +1271,11 @@ namespace swrenderer // Transform and clip coordinates. Returns true if it was clipped away bool FWallCoords::Init(RenderThread *thread, const DVector2 &pt1, const DVector2 &pt2, double too_close) { - tleft.X = float(pt1.X * ViewSin - pt1.Y * ViewCos); - tright.X = float(pt2.X * ViewSin - pt2.Y * ViewCos); + tleft.X = float(pt1.X * r_viewpoint.Sin - pt1.Y * r_viewpoint.Cos); + tright.X = float(pt2.X * r_viewpoint.Sin - pt2.Y * r_viewpoint.Cos); - tleft.Y = float(pt1.X * ViewTanCos + pt1.Y * ViewTanSin); - tright.Y = float(pt2.X * ViewTanCos + pt2.Y * ViewTanSin); + tleft.Y = float(pt1.X * r_viewpoint.TanCos + pt1.Y * r_viewpoint.TanSin); + tright.Y = float(pt2.X * r_viewpoint.TanCos + pt2.Y * r_viewpoint.TanSin); RenderPortal *renderportal = thread->Portal.get(); auto viewport = RenderViewport::Instance(); @@ -1342,9 +1342,9 @@ namespace swrenderer { swapvalues(left, right); } - UoverZorg = left->X * centerx; + UoverZorg = left->X * r_viewwindow.centerx; UoverZstep = -left->Y; - InvZorg = (left->X - right->X) * centerx; + InvZorg = (left->X - right->X) * r_viewwindow.centerx; InvZstep = right->Y - left->Y; } @@ -1352,10 +1352,10 @@ namespace swrenderer { // Coordinates should have already had viewx,viewy subtracted - double fullx1 = left.X * ViewSin - left.Y * ViewCos; - double fullx2 = right.X * ViewSin - right.Y * ViewCos; - double fully1 = left.X * ViewTanCos + left.Y * ViewTanSin; - double fully2 = right.X * ViewTanCos + right.Y * ViewTanSin; + double fullx1 = left.X * r_viewpoint.Sin - left.Y * r_viewpoint.Cos; + double fullx2 = right.X * r_viewpoint.Sin - right.Y * r_viewpoint.Cos; + double fully1 = left.X * r_viewpoint.TanCos + left.Y * r_viewpoint.TanSin; + double fully2 = right.X * r_viewpoint.TanCos + right.Y * r_viewpoint.TanSin; RenderPortal *renderportal = thread->Portal.get(); @@ -1365,9 +1365,9 @@ namespace swrenderer fullx2 = -fullx2; } - UoverZorg = float(fullx1 * centerx); + UoverZorg = float(fullx1 * r_viewwindow.centerx); UoverZstep = float(-fully1); - InvZorg = float((fullx1 - fullx2) * centerx); + InvZorg = float((fullx1 - fullx2) * r_viewwindow.centerx); InvZstep = float(fully2 - fully1); } } diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index f157a89b68..2d18a79fa2 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -118,7 +118,7 @@ namespace swrenderer { if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) { - clip3d->sclipTop = sec->ceilingplane.ZatPoint(ViewPos); + clip3d->sclipTop = sec->ceilingplane.ZatPoint(r_viewpoint.Pos); } for (i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { @@ -202,7 +202,7 @@ namespace swrenderer { // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - texturemid += rowoffset - ViewPos.Z; + texturemid += rowoffset - r_viewpoint.Pos.Z; textop = texturemid; texturemid *= MaskedScaleY; } @@ -210,8 +210,8 @@ namespace swrenderer { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - textop = texturemid + rowoffset / MaskedScaleY - ViewPos.Z; - texturemid = (texturemid - ViewPos.Z) * MaskedScaleY + rowoffset; + textop = texturemid + rowoffset / MaskedScaleY - r_viewpoint.Pos.Z; + texturemid = (texturemid - r_viewpoint.Pos.Z) * MaskedScaleY + rowoffset; } if (sprflipvert) { @@ -230,12 +230,12 @@ namespace swrenderer goto clearfog; } - if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && textop < clip3d->sclipBottom - ViewPos.Z) + if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && textop < clip3d->sclipBottom - r_viewpoint.Pos.Z) { notrelevant = true; goto clearfog; } - if ((clip3d->fake3D & FAKE3D_CLIPTOP) && textop - texheight > clip3d->sclipTop - ViewPos.Z) + if ((clip3d->fake3D & FAKE3D_CLIPTOP) && textop - texheight > clip3d->sclipTop - r_viewpoint.Pos.Z) { notrelevant = true; goto clearfog; @@ -248,7 +248,7 @@ namespace swrenderer if (clip3d->fake3D & FAKE3D_CLIPTOP) { - wallupper.Project(textop < clip3d->sclipTop - ViewPos.Z ? textop : clip3d->sclipTop - ViewPos.Z, &WallC); + wallupper.Project(textop < clip3d->sclipTop - r_viewpoint.Pos.Z ? textop : clip3d->sclipTop - r_viewpoint.Pos.Z, &WallC); } else { @@ -256,7 +256,7 @@ namespace swrenderer } if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) { - walllower.Project(textop - texheight > clip3d->sclipBottom - ViewPos.Z ? textop - texheight : clip3d->sclipBottom - ViewPos.Z, &WallC); + walllower.Project(textop - texheight > clip3d->sclipBottom - r_viewpoint.Pos.Z ? textop - texheight : clip3d->sclipBottom - r_viewpoint.Pos.Z, &WallC); } else { @@ -319,13 +319,13 @@ namespace swrenderer { // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - texturemid = (texturemid - ViewPos.Z + rowoffset) * MaskedScaleY; + texturemid = (texturemid - r_viewpoint.Pos.Z + rowoffset) * MaskedScaleY; } else { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - texturemid = (texturemid - ViewPos.Z) * MaskedScaleY + rowoffset; + texturemid = (texturemid - r_viewpoint.Pos.Z) * MaskedScaleY + rowoffset; } WallC.sz1 = ds->sz1; @@ -347,7 +347,7 @@ namespace swrenderer if (clip3d->fake3D & FAKE3D_CLIPTOP) { - wallupper.Project(clip3d->sclipTop - ViewPos.Z, &WallC); + wallupper.Project(clip3d->sclipTop - r_viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { if (wallupper.ScreenY[i] < mceilingclip[i]) @@ -357,7 +357,7 @@ namespace swrenderer } if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) { - walllower.Project(clip3d->sclipBottom - ViewPos.Z, &WallC); + walllower.Project(clip3d->sclipBottom - r_viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { if (walllower.ScreenY[i] > mfloorclip[i]) @@ -450,7 +450,7 @@ namespace swrenderer { rowoffset += rw_pic->GetHeight(); } - double texturemid = (planez - ViewPos.Z) * yscale; + double texturemid = (planez - r_viewpoint.Pos.Z) * yscale; if (rw_pic->bWorldPanning) { // rowoffset is added before the multiply so that the masked texture will @@ -483,8 +483,8 @@ namespace swrenderer WallT = ds->tmapvals; Clip3DFloors *clip3d = Thread->Clip3D.get(); - wallupper.Project(clip3d->sclipTop - ViewPos.Z, &WallC); - walllower.Project(clip3d->sclipBottom - ViewPos.Z, &WallC); + wallupper.Project(clip3d->sclipTop - r_viewpoint.Pos.Z, &WallC); + walllower.Project(clip3d->sclipBottom - r_viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 6864ff9874..8dce6c4aba 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -207,12 +207,12 @@ namespace swrenderer { if (!(cur_node->lightsource->flags2&MF2_DORMANT)) { - double lightX = cur_node->lightsource->X() - ViewPos.X; - double lightY = cur_node->lightsource->Y() - ViewPos.Y; - double lightZ = cur_node->lightsource->Z() - ViewPos.Z; + double lightX = cur_node->lightsource->X() - r_viewpoint.Pos.X; + double lightY = cur_node->lightsource->Y() - r_viewpoint.Pos.Y; + double lightZ = cur_node->lightsource->Z() - r_viewpoint.Pos.Z; - float lx = (float)(lightX * ViewSin - lightY * ViewCos) - drawerargs.dc_viewpos.X; - float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - drawerargs.dc_viewpos.Y; + float lx = (float)(lightX * r_viewpoint.Sin - lightY * r_viewpoint.Cos) - drawerargs.dc_viewpos.X; + float ly = (float)(lightX * r_viewpoint.TanCos + lightY * r_viewpoint.TanSin) - drawerargs.dc_viewpos.Y; float lz = (float)lightZ; // Precalculate the constant part of the dot here so the drawer doesn't have to. @@ -446,17 +446,17 @@ namespace swrenderer if (yrepeat >= 0) { // normal orientation: draw strips from top to bottom - partition = top - fmod(top - texturemid / yrepeat - ViewPos.Z, scaledtexheight); + partition = top - fmod(top - texturemid / yrepeat - r_viewpoint.Pos.Z, scaledtexheight); if (partition == top) { partition -= scaledtexheight; } const short *up = uwal; short *down = most1.ScreenY; - texturemid = (partition - ViewPos.Z) * yrepeat + texheight; + texturemid = (partition - r_viewpoint.Pos.Z) * yrepeat + texheight; while (partition > bot) { - ProjectedWallCull j = most3.Project(partition - ViewPos.Z, &WallC); + ProjectedWallCull j = most3.Project(partition - r_viewpoint.Pos.Z, &WallC); if (j != ProjectedWallCull::OutsideAbove) { for (int j = x1; j < x2; ++j) @@ -474,13 +474,13 @@ namespace swrenderer } else { // upside down: draw strips from bottom to top - partition = bot - fmod(bot - texturemid / yrepeat - ViewPos.Z, scaledtexheight); + partition = bot - fmod(bot - texturemid / yrepeat - r_viewpoint.Pos.Z, scaledtexheight); short *up = most1.ScreenY; const short *down = dwal; - texturemid = (partition - ViewPos.Z) * yrepeat + texheight; + texturemid = (partition - r_viewpoint.Pos.Z) * yrepeat + texheight; while (partition < top) { - ProjectedWallCull j = most3.Project(partition - ViewPos.Z, &WallC); + ProjectedWallCull j = most3.Project(partition - r_viewpoint.Pos.Z, &WallC); if (j != ProjectedWallCull::OutsideBelow) { for (int j = x1; j < x2; ++j) diff --git a/src/swrenderer/line/r_wallsetup.cpp b/src/swrenderer/line/r_wallsetup.cpp index 579ff21f21..38420586bf 100644 --- a/src/swrenderer/line/r_wallsetup.cpp +++ b/src/swrenderer/line/r_wallsetup.cpp @@ -80,7 +80,7 @@ namespace swrenderer { if (!plane.isSlope()) { - return Project(plane.Zat0() - ViewPos.Z, wallc); + return Project(plane.Zat0() - r_viewpoint.Pos.Z, wallc); } else { @@ -96,7 +96,7 @@ namespace swrenderer x -= frac * (x - curline->v1->fX()); y -= frac * (y - curline->v1->fY()); } - z1 = plane.ZatPoint(x, y) - ViewPos.Z; + z1 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; if (wallc->sx2 > wallc->sx1 + 1) { @@ -108,7 +108,7 @@ namespace swrenderer x += frac * (curline->v2->fX() - x); y += frac * (curline->v2->fY() - y); } - z2 = plane.ZatPoint(x, y) - ViewPos.Z; + z2 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; } else { @@ -125,7 +125,7 @@ namespace swrenderer x += frac * (curline->v2->fX() - x); y += frac * (curline->v2->fY() - y); } - z1 = plane.ZatPoint(x, y) - ViewPos.Z; + z1 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; if (wallc->sx2 > wallc->sx1 + 1) { @@ -137,7 +137,7 @@ namespace swrenderer x -= frac * (x - curline->v1->fX()); y -= frac * (y - curline->v1->fY()); } - z2 = plane.ZatPoint(x, y) - ViewPos.Z; + z2 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; } else { diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index c7cadfbab0..5ac1f8a319 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -68,20 +68,20 @@ namespace swrenderer if (planeang != 0) { double cosine = cos(planeang), sine = sin(planeang); - pviewx = pl->xform.xOffs + ViewPos.X * cosine - ViewPos.Y * sine; - pviewy = pl->xform.yOffs + pl->xform.baseyOffs - ViewPos.X * sine - ViewPos.Y * cosine; + pviewx = pl->xform.xOffs + r_viewpoint.Pos.X * cosine - r_viewpoint.Pos.Y * sine; + pviewy = pl->xform.yOffs + pl->xform.baseyOffs - r_viewpoint.Pos.X * sine - r_viewpoint.Pos.Y * cosine; } else { - pviewx = pl->xform.xOffs + ViewPos.X; - pviewy = pl->xform.yOffs - ViewPos.Y; + pviewx = pl->xform.xOffs + r_viewpoint.Pos.X; + pviewy = pl->xform.yOffs - r_viewpoint.Pos.Y; } pviewx = _xscale * pviewx; pviewy = _yscale * pviewy; // left to right mapping - planeang += (ViewAngle - 90).Radians(); + planeang += (r_viewpoint.Angles.Yaw - 90).Radians(); auto viewport = RenderViewport::Instance(); @@ -113,7 +113,7 @@ namespace swrenderer minx = pl->left; - planeheight = fabs(pl->height.Zat0() - ViewPos.Z); + planeheight = fabs(pl->height.Zat0() - r_viewpoint.Pos.Z); basecolormap = colormap; @@ -231,12 +231,12 @@ namespace swrenderer cur_node = light_list; while (cur_node) { - double lightX = cur_node->lightsource->X() - ViewPos.X; - double lightY = cur_node->lightsource->Y() - ViewPos.Y; - double lightZ = cur_node->lightsource->Z() - ViewPos.Z; + double lightX = cur_node->lightsource->X() - r_viewpoint.Pos.X; + double lightY = cur_node->lightsource->Y() - r_viewpoint.Pos.Y; + double lightZ = cur_node->lightsource->Z() - r_viewpoint.Pos.Z; - float lx = (float)(lightX * ViewSin - lightY * ViewCos); - float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin) - drawerargs.dc_viewpos.Y; + float lx = (float)(lightX * r_viewpoint.Sin - lightY * r_viewpoint.Cos); + float ly = (float)(lightX * r_viewpoint.TanCos + lightY * r_viewpoint.TanSin) - drawerargs.dc_viewpos.Y; float lz = (float)lightZ - drawerargs.dc_viewpos.Z; // Precalculate the constant part of the dot here so the drawer doesn't have to. diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index dd1848f7a1..433d32ee73 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -70,7 +70,7 @@ namespace swrenderer } sky2tex = sky2texture; skymid = skytexturemid; - skyangle = ViewAngle.BAMs(); + skyangle = r_viewpoint.Angles.Yaw.BAMs(); if (pl->picnum == skyflatnum) { @@ -188,7 +188,7 @@ namespace swrenderer if (r_linearsky) { - angle_t xangle = (angle_t)((0.5 - x / (double)viewwidth) * FocalTangent * ANGLE_90); + angle_t xangle = (angle_t)((0.5 - x / (double)viewwidth) * r_viewwindow.FocalTangent * ANGLE_90); ang = (skyangle + xangle) ^ skyflip; } else diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index 833fefe86e..3f396b0f31 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -86,7 +86,7 @@ namespace swrenderer lyscale = _yscale * ifloatpow2[drawerargs.TextureHeightBits()]; xscale = 64.f / lxscale; yscale = 64.f / lyscale; - zeroheight = pl->height.ZatPoint(ViewPos); + zeroheight = pl->height.ZatPoint(r_viewpoint.Pos); pviewx = xs_ToFixed(32 - drawerargs.TextureWidthBits(), pl->xform.xOffs * pl->xform.xScale); pviewy = xs_ToFixed(32 - drawerargs.TextureHeightBits(), pl->xform.yOffs * pl->xform.yScale); @@ -95,11 +95,11 @@ namespace swrenderer // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. - ang = M_PI * 3 / 2 - ViewAngle.Radians(); + ang = M_PI * 3 / 2 - r_viewpoint.Angles.Yaw.Radians(); cosine = cos(ang), sine = sin(ang); - p[0] = ViewPos.X * cosine - ViewPos.Y * sine; - p[2] = ViewPos.X * sine + ViewPos.Y * cosine; - p[1] = pl->height.ZatPoint(0.0, 0.0) - ViewPos.Z; + p[0] = r_viewpoint.Pos.X * cosine - r_viewpoint.Pos.Y * sine; + p[2] = r_viewpoint.Pos.X * sine + r_viewpoint.Pos.Y * cosine; + p[1] = pl->height.ZatPoint(0.0, 0.0) - r_viewpoint.Pos.Z; // m is the v direction vector in view space ang = ang - M_PI / 2 - planeang; @@ -126,8 +126,8 @@ namespace swrenderer // how much you slope the surface. Use the commented-out code above instead to keep // the textures a constant size across the surface's plane instead. cosine = cos(planeang), sine = sin(planeang); - m[1] = pl->height.ZatPoint(ViewPos.X + yscale * sine, ViewPos.Y + yscale * cosine) - zeroheight; - n[1] = -(pl->height.ZatPoint(ViewPos.X - xscale * cosine, ViewPos.Y + xscale * sine) - zeroheight); + m[1] = pl->height.ZatPoint(r_viewpoint.Pos.X + yscale * sine, r_viewpoint.Pos.Y + yscale * cosine) - zeroheight; + n[1] = -(pl->height.ZatPoint(r_viewpoint.Pos.X - xscale * cosine, r_viewpoint.Pos.Y + xscale * sine) - zeroheight); plane_su = p ^ m; plane_sv = p ^ n; @@ -157,7 +157,7 @@ namespace swrenderer basecolormap = colormap; bool foggy = level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE);; - planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos) - ViewPos.Z)) / 65536.f; + planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(r_viewpoint.Pos) - r_viewpoint.Pos.Z)) / 65536.f; if (pl->height.fC() > 0) planelightfloat = -planelightfloat; diff --git a/src/swrenderer/plane/r_visibleplanelist.cpp b/src/swrenderer/plane/r_visibleplanelist.cpp index 4467410575..e624629507 100644 --- a/src/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/swrenderer/plane/r_visibleplanelist.cpp @@ -167,7 +167,7 @@ namespace swrenderer *xform == check->xform ) ) && - check->viewangle == renderportal->stacked_angle + check->viewangle == renderportal->stacked_angle.Yaw ) ) ) @@ -191,7 +191,7 @@ namespace swrenderer renderportal->CurrentPortalUniq == check->CurrentPortalUniq && renderportal->MirrorFlags == check->MirrorFlags && Thread->Clip3D->CurrentSkybox == check->CurrentSkybox && - ViewPos == check->viewpos + r_viewpoint.Pos == check->viewpos ) { return check; @@ -210,7 +210,7 @@ namespace swrenderer check->extralight = renderportal->stacked_extralight; check->visibility = renderportal->stacked_visibility; check->viewpos = renderportal->stacked_viewpos; - check->viewangle = renderportal->stacked_angle; + check->viewangle = renderportal->stacked_angle.Yaw; check->Alpha = alpha; check->Additive = additive; check->CurrentPortalUniq = renderportal->CurrentPortalUniq; @@ -350,8 +350,8 @@ namespace swrenderer VisiblePlane *pl; int i; - DVector3 oViewPos = ViewPos; - DAngle oViewAngle = ViewAngle; + DVector3 oViewPos = r_viewpoint.Pos; + DAngle oViewAngle = r_viewpoint.Angles.Yaw; RenderPortal *renderportal = Thread->Portal.get(); @@ -364,15 +364,15 @@ namespace swrenderer if (pl->sky < 0 && pl->height.Zat0() == height) { - ViewPos = pl->viewpos; - ViewAngle = pl->viewangle; + r_viewpoint.Pos = pl->viewpos; + r_viewpoint.Angles.Yaw = pl->viewangle; renderportal->MirrorFlags = pl->MirrorFlags; pl->Render(Thread, pl->sky & 0x7FFFFFFF, pl->Additive, true); } } } - ViewPos = oViewPos; - ViewAngle = oViewAngle; + r_viewpoint.Pos = oViewPos; + r_viewpoint.Angles.Yaw = oViewAngle; } } diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 2034520043..367e498f7c 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -256,15 +256,15 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin // These get clobbered by rendering to a camera texture but they need to be preserved so the final rendering can be done with the correct palette. CameraLight savedCameraLight = *CameraLight::Instance(); - DAngle savedfov = FieldOfView; - R_SetFOV ((double)fov); + DAngle savedfov = r_viewpoint.FieldOfView; + R_SetFOV (r_viewpoint, (double)fov); if (r_polyrenderer) PolyRenderer::Instance()->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); else mScene.RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); - R_SetFOV (savedfov); + R_SetFOV (r_viewpoint, savedfov); if (Canvas->IsBgra()) { diff --git a/src/swrenderer/scene/r_3dfloors.cpp b/src/swrenderer/scene/r_3dfloors.cpp index f49def6b38..b9bf28c127 100644 --- a/src/swrenderer/scene/r_3dfloors.cpp +++ b/src/swrenderer/scene/r_3dfloors.cpp @@ -68,7 +68,7 @@ namespace swrenderer HeightLevel *near; HeightLevel *curr; - double height = add->ZatPoint(ViewPos); + double height = add->ZatPoint(r_viewpoint.Pos); if (height >= sec->CenterCeiling()) return; if (height <= sec->CenterFloor()) return; diff --git a/src/swrenderer/scene/r_light.cpp b/src/swrenderer/scene/r_light.cpp index 3407fb4bb7..877ba095bf 100644 --- a/src/swrenderer/scene/r_light.cpp +++ b/src/swrenderer/scene/r_light.cpp @@ -47,6 +47,7 @@ namespace swrenderer void CameraLight::SetCamera(AActor *actor) { + AActor *camera = r_viewpoint.camera; player_t *player = actor->player; if (camera && camera->player != nullptr) player = camera->player; @@ -84,10 +85,10 @@ namespace swrenderer } } // [RH] Inverse light for shooting the Sigil - if (fixedcolormap == nullptr && extralight == INT_MIN) + if (fixedcolormap == nullptr && r_viewpoint.extralight == INT_MIN) { fixedcolormap = &SpecialColormaps[INVERSECOLORMAP]; - extralight = 0; + r_viewpoint.extralight = 0; } } @@ -108,7 +109,7 @@ namespace swrenderer CurrentVisibility = vis; auto viewport = RenderViewport::Instance(); - if (FocalTangent == 0 || viewport->FocalLengthY == 0) + if (r_viewwindow.FocalTangent == 0 || viewport->FocalLengthY == 0) { // If r_visibility is called before the renderer is all set up, don't // divide by zero. This will be called again later, and the proper // values can be initialized then. @@ -117,7 +118,7 @@ namespace swrenderer BaseVisibility = vis; - MaxVisForWall = (viewport->InvZtoScale * (SCREENWIDTH*r_Yaspect) / (viewwidth*SCREENHEIGHT * FocalTangent)); + MaxVisForWall = (viewport->InvZtoScale * (SCREENWIDTH*r_Yaspect) / (viewwidth*SCREENHEIGHT * r_viewwindow.FocalTangent)); MaxVisForWall = 32767.0 / MaxVisForWall; MaxVisForFloor = 32767.0 / (viewheight >> 2) * viewport->FocalLengthY / 160; @@ -129,8 +130,8 @@ namespace swrenderer else WallVisibility = BaseVisibility; - WallVisibility = (viewport->InvZtoScale * SCREENWIDTH*AspectBaseHeight(WidescreenRatio) / - (viewwidth*SCREENHEIGHT * 3)) * (WallVisibility * FocalTangent); + WallVisibility = (viewport->InvZtoScale * SCREENWIDTH*AspectBaseHeight(r_viewwindow.WidescreenRatio) / + (viewwidth*SCREENHEIGHT * 3)) * (WallVisibility * r_viewwindow.FocalTangent); // Prevent overflow on floors/ceilings. Note that the calculation of // MaxVisForFloor means that planes less than two units from the player's @@ -145,7 +146,7 @@ namespace swrenderer FloorVisibility = 160.0 * FloorVisibility / viewport->FocalLengthY; - TiltVisibility = float(vis * FocalTangent * (16.f * 320.f) / viewwidth); + TiltVisibility = float(vis * r_viewwindow.FocalTangent * (16.f * 320.f) / viewwidth); NoLightFade = glset.nolightfade; } diff --git a/src/swrenderer/scene/r_light.h b/src/swrenderer/scene/r_light.h index 843faedd16..22b2c03e5e 100644 --- a/src/swrenderer/scene/r_light.h +++ b/src/swrenderer/scene/r_light.h @@ -84,10 +84,10 @@ namespace swrenderer double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; } double SpriteVis(double screenZ, bool foggy) const { return SpriteGlobVis(foggy) / screenZ; } double ParticleVis(double screenZ, bool foggy) const { return ParticleGlobVis(foggy) / screenZ; } - double FlatPlaneVis(int screenY, double planeZ, bool foggy) const { return FlatPlaneGlobVis(foggy) / fabs(planeZ - ViewPos.Z) * fabs(RenderViewport::Instance()->CenterY - screenY); } + double FlatPlaneVis(int screenY, double planeZ, bool foggy) const { return FlatPlaneGlobVis(foggy) / fabs(planeZ - r_viewpoint.Pos.Z) * fabs(RenderViewport::Instance()->CenterY - screenY); } static fixed_t LightLevelToShade(int lightlevel, bool foggy); - static int ActualExtraLight(bool fog) { return fog ? 0 : extralight << 4; } + static int ActualExtraLight(bool fog) { return fog ? 0 : r_viewpoint.extralight << 4; } private: double BaseVisibility = 0.0; diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 9a359896f0..b7540ff805 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -98,9 +98,9 @@ namespace swrenderer const sector_t *s = sec->GetHeightSec(); if (s != nullptr) { - sector_t *heightsec = viewsector->heightsec; + sector_t *heightsec = r_viewpoint.sector->heightsec; bool underwater = r_fakingunderwater || - (heightsec && heightsec->floorplane.PointOnSide(ViewPos) <= 0); + (heightsec && heightsec->floorplane.PointOnSide(r_viewpoint.Pos) <= 0); bool doorunderwater = false; int diffTex = (s->MoreFlags & SECF_CLIPFAKEPLANES); @@ -159,8 +159,8 @@ namespace swrenderer } } - double refceilz = s->ceilingplane.ZatPoint(ViewPos); - double orgceilz = sec->ceilingplane.ZatPoint(ViewPos); + double refceilz = s->ceilingplane.ZatPoint(r_viewpoint.Pos); + double orgceilz = sec->ceilingplane.ZatPoint(r_viewpoint.Pos); #if 1 // [RH] Allow viewing underwater areas through doors/windows that @@ -234,7 +234,7 @@ namespace swrenderer } FakeSide = WaterFakeSide::BelowFloor; } - else if (heightsec && heightsec->ceilingplane.PointOnSide(ViewPos) <= 0 && + else if (heightsec && heightsec->ceilingplane.PointOnSide(r_viewpoint.Pos) <= 0 && orgceilz > refceilz && !(s->MoreFlags & SECF_FAKEFLOORONLY)) { // Above-ceiling hack tempsec->ceilingplane = s->ceilingplane; @@ -307,16 +307,16 @@ namespace swrenderer // Find the corners of the box // that define the edges from current viewpoint. - if (ViewPos.X <= bspcoord[BOXLEFT]) + if (r_viewpoint.Pos.X <= bspcoord[BOXLEFT]) boxx = 0; - else if (ViewPos.X < bspcoord[BOXRIGHT]) + else if (r_viewpoint.Pos.X < bspcoord[BOXRIGHT]) boxx = 1; else boxx = 2; - if (ViewPos.Y >= bspcoord[BOXTOP]) + if (r_viewpoint.Pos.Y >= bspcoord[BOXTOP]) boxy = 0; - else if (ViewPos.Y > bspcoord[BOXBOTTOM]) + else if (r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM]) boxy = 1; else boxy = 2; @@ -325,10 +325,10 @@ namespace swrenderer if (boxpos == 5) return true; - x1 = bspcoord[checkcoord[boxpos][0]] - ViewPos.X; - y1 = bspcoord[checkcoord[boxpos][1]] - ViewPos.Y; - x2 = bspcoord[checkcoord[boxpos][2]] - ViewPos.X; - y2 = bspcoord[checkcoord[boxpos][3]] - ViewPos.Y; + x1 = bspcoord[checkcoord[boxpos][0]] - r_viewpoint.Pos.X; + y1 = bspcoord[checkcoord[boxpos][1]] - r_viewpoint.Pos.Y; + x2 = bspcoord[checkcoord[boxpos][2]] - r_viewpoint.Pos.X; + y2 = bspcoord[checkcoord[boxpos][3]] - r_viewpoint.Pos.Y; // check clip list for an open space @@ -336,10 +336,10 @@ namespace swrenderer if (y1 * (x1 - x2) + x1 * (y2 - y1) >= -EQUAL_EPSILON) return true; - rx1 = x1 * ViewSin - y1 * ViewCos; - rx2 = x2 * ViewSin - y2 * ViewCos; - ry1 = x1 * ViewTanCos + y1 * ViewTanSin; - ry2 = x2 * ViewTanCos + y2 * ViewTanSin; + rx1 = x1 * r_viewpoint.Sin - y1 * r_viewpoint.Cos; + rx2 = x2 * r_viewpoint.Sin - y2 * r_viewpoint.Cos; + ry1 = x1 * r_viewpoint.TanCos + y1 * r_viewpoint.TanSin; + ry2 = x2 * r_viewpoint.TanCos + y2 * r_viewpoint.TanSin; if (Thread->Portal->MirrorFlags & RF_XFLIP) { @@ -501,7 +501,7 @@ namespace swrenderer portal = frontsector->ValidatePortal(sector_t::ceiling); - VisiblePlane *ceilingplane = frontsector->ceilingplane.PointOnSide(ViewPos) > 0 || + VisiblePlane *ceilingplane = frontsector->ceilingplane.PointOnSide(r_viewpoint.Pos) > 0 || frontsector->GetTexture(sector_t::ceiling) == skyflatnum || portal != nullptr || (frontsector->heightsec && @@ -542,7 +542,7 @@ namespace swrenderer // killough 10/98: add support for skies transferred from sidedefs portal = frontsector->ValidatePortal(sector_t::floor); - VisiblePlane *floorplane = frontsector->floorplane.PointOnSide(ViewPos) > 0 || // killough 3/7/98 + VisiblePlane *floorplane = frontsector->floorplane.PointOnSide(r_viewpoint.Pos) > 0 || // killough 3/7/98 frontsector->GetTexture(sector_t::floor) == skyflatnum || portal != nullptr || (frontsector->heightsec && @@ -591,7 +591,7 @@ namespace swrenderer clip3d->NewClip(); } double fakeHeight = clip3d->fakeFloor->fakeFloor->top.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight < ViewPos.Z && + if (fakeHeight < r_viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) { clip3d->fake3D = FAKE3D_FAKEFLOOR; @@ -654,7 +654,7 @@ namespace swrenderer clip3d->NewClip(); } double fakeHeight = clip3d->fakeFloor->fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight > ViewPos.Z && + if (fakeHeight > r_viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) { clip3d->fake3D = FAKE3D_FAKECEILING; @@ -798,7 +798,7 @@ namespace swrenderer node_t *bsp = (node_t *)node; // Decide which side the view point is on. - int side = R_PointOnSide(ViewPos, bsp); + int side = R_PointOnSide(r_viewpoint.Pos, bsp); // Recursively divide front space (toward the viewer). RenderBSPNode(bsp->children[side]); @@ -848,7 +848,7 @@ namespace swrenderer FIntCVar *cvar = thing->GetClass()->distancecheck; if (cvar != nullptr && *cvar >= 0) { - double dist = (thing->Pos() - ViewPos).LengthSquared(); + double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) { @@ -930,8 +930,8 @@ namespace swrenderer bool RenderOpaquePass::GetThingSprite(AActor *thing, ThingSprite &sprite) { - sprite.pos = thing->InterpolatedPosition(r_TicFracF); - sprite.pos.Z += thing->GetBobOffset(r_TicFracF); + sprite.pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + sprite.pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); sprite.spritenum = thing->sprite; sprite.tex = nullptr; @@ -958,7 +958,7 @@ namespace swrenderer { // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[sprite.tex->Rotations]; - DAngle ang = (sprite.pos - ViewPos).Angle(); + DAngle ang = (sprite.pos - r_viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { @@ -1001,7 +1001,7 @@ namespace swrenderer //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; - DAngle ang = (sprite.pos - ViewPos).Angle(); + DAngle ang = (sprite.pos - r_viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { diff --git a/src/swrenderer/scene/r_portal.cpp b/src/swrenderer/scene/r_portal.cpp index 8c2768c92a..ed7f6eb9d0 100644 --- a/src/swrenderer/scene/r_portal.cpp +++ b/src/swrenderer/scene/r_portal.cpp @@ -101,12 +101,12 @@ namespace swrenderer Thread->Clip3D->EnterSkybox(); CurrentPortalInSkybox = true; - int savedextralight = extralight; - DVector3 savedpos = ViewPos; - DAngle savedangle = ViewAngle; + int savedextralight = r_viewpoint.extralight; + DVector3 savedpos = r_viewpoint.Pos; + DRotator savedangles = r_viewpoint.Angles; double savedvisibility = LightVisibility::Instance()->GetVisibility(); - AActor *savedcamera = camera; - sector_t *savedsector = viewsector; + AActor *savedcamera = r_viewpoint.camera; + sector_t *savedsector = r_viewpoint.sector; for (VisiblePlane *pl = planes->PopFirstPortalPlane(); pl != nullptr; pl = planes->PopFirstPortalPlane()) { @@ -125,11 +125,11 @@ namespace swrenderer { // Don't let gun flashes brighten the sky box AActor *sky = port->mSkybox; - extralight = 0; + r_viewpoint.extralight = 0; LightVisibility::Instance()->SetVisibility(sky->args[0] * 0.25f); - ViewPos = sky->InterpolatedPosition(r_TicFracF); - ViewAngle = savedangle + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_TicFracF); + r_viewpoint.Pos = sky->InterpolatedPosition(r_viewpoint.TicFrac); + r_viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_viewpoint.TicFrac); CopyStackedViewParameters(); break; @@ -138,12 +138,12 @@ namespace swrenderer case PORTS_STACKEDSECTORTHING: case PORTS_PORTAL: case PORTS_LINKEDPORTAL: - extralight = pl->extralight; + r_viewpoint.extralight = pl->extralight; LightVisibility::Instance()->SetVisibility(pl->visibility); - ViewPos.X = pl->viewpos.X + port->mDisplacement.X; - ViewPos.Y = pl->viewpos.Y + port->mDisplacement.Y; - ViewPos.Z = pl->viewpos.Z; - ViewAngle = pl->viewangle; + r_viewpoint.Pos.X = pl->viewpos.X + port->mDisplacement.X; + r_viewpoint.Pos.Y = pl->viewpos.Y + port->mDisplacement.Y; + r_viewpoint.Pos.Z = pl->viewpos.Z; + r_viewpoint.Angles.Yaw = pl->viewangle; break; case PORTS_HORIZON: @@ -158,10 +158,10 @@ namespace swrenderer port->mFlags |= PORTSF_INSKYBOX; if (port->mPartner > 0) level.sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX; - camera = nullptr; - viewsector = port->mDestination; + r_viewpoint.camera = nullptr; + r_viewpoint.sector = port->mDestination; assert(viewsector != nullptr); - R_SetViewAngle(); + R_SetViewAngle(r_viewpoint, r_viewwindow); Thread->OpaquePass->ClearSeenSprites(); Thread->Clip3D->ClearFakeFloors(); @@ -188,7 +188,7 @@ namespace swrenderer drawseglist->PushPortal(); Thread->SpriteList->PushPortal(); - viewposStack.Push(ViewPos); + viewposStack.Push(r_viewpoint.Pos); visplaneStack.Push(pl); // Create a drawseg to clip sprites to the sky plane @@ -227,7 +227,7 @@ namespace swrenderer while (viewposStack.Size() > 0) { // Masked textures and planes need the view coordinates restored for proper positioning. - viewposStack.Pop(ViewPos); + viewposStack.Pop(r_viewpoint.Pos); Thread->TranslucentPass->Render(); @@ -242,13 +242,13 @@ namespace swrenderer drawseglist->PopPortal(); } - camera = savedcamera; - viewsector = savedsector; - ViewPos = savedpos; + r_viewpoint.camera = savedcamera; + r_viewpoint.sector = savedsector; + r_viewpoint.Pos = savedpos; LightVisibility::Instance()->SetVisibility(savedvisibility); - extralight = savedextralight; - ViewAngle = savedangle; - R_SetViewAngle(); + r_viewpoint.extralight = savedextralight; + r_viewpoint.Angles = savedangles; + R_SetViewAngle(r_viewpoint, r_viewwindow); CurrentPortalInSkybox = false; Thread->Clip3D->LeaveSkybox(); @@ -318,12 +318,12 @@ namespace swrenderer return; } - DAngle startang = ViewAngle; - DVector3 startpos = ViewPos; - DVector3 savedpath[2] = { ViewPath[0], ViewPath[1] }; - ActorRenderFlags savedvisibility = camera ? camera->renderflags & RF_INVISIBLE : ActorRenderFlags::FromInt(0); + DAngle startang = r_viewpoint.Angles.Yaw; + DVector3 startpos = r_viewpoint.Pos; + DVector3 savedpath[2] = { r_viewpoint.Path[0], r_viewpoint.Path[1] }; + ActorRenderFlags savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_INVISIBLE : ActorRenderFlags::FromInt(0); - camera->renderflags &= ~RF_INVISIBLE; + r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; CurrentPortalUniq++; @@ -337,11 +337,11 @@ namespace swrenderer // Reflect the current view behind the mirror. if (pds->src->Delta().X == 0) { // vertical mirror - ViewPos.X = v1->fX() - startpos.X + v1->fX(); + r_viewpoint.Pos.X = v1->fX() - startpos.X + v1->fX(); } else if (pds->src->Delta().Y == 0) { // horizontal mirror - ViewPos.Y = v1->fY() - startpos.Y + v1->fY(); + r_viewpoint.Pos.Y = v1->fY() - startpos.Y + v1->fY(); } else { // any mirror @@ -357,40 +357,40 @@ namespace swrenderer // the above two cases catch len == 0 double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); - ViewPos.X = (x1 + r * dx) * 2 - x; - ViewPos.Y = (y1 + r * dy) * 2 - y; + r_viewpoint.Pos.X = (x1 + r * dx) * 2 - x; + r_viewpoint.Pos.Y = (y1 + r * dy) * 2 - y; } - ViewAngle = pds->src->Delta().Angle() * 2 - startang; + r_viewpoint.Angles.Yaw = pds->src->Delta().Angle() * 2 - startang; } else { - P_TranslatePortalXY(pds->src, ViewPos.X, ViewPos.Y); - P_TranslatePortalZ(pds->src, ViewPos.Z); - P_TranslatePortalAngle(pds->src, ViewAngle); - P_TranslatePortalXY(pds->src, ViewPath[0].X, ViewPath[0].Y); - P_TranslatePortalXY(pds->src, ViewPath[1].X, ViewPath[1].Y); + P_TranslatePortalXY(pds->src, r_viewpoint.Pos.X, r_viewpoint.Pos.Y); + P_TranslatePortalZ(pds->src, r_viewpoint.Pos.Z); + P_TranslatePortalAngle(pds->src, r_viewpoint.Angles.Yaw); + P_TranslatePortalXY(pds->src, r_viewpoint.Path[0].X, r_viewpoint.Path[0].Y); + P_TranslatePortalXY(pds->src, r_viewpoint.Path[1].X, r_viewpoint.Path[1].Y); - if (!r_showviewer && camera && P_PointOnLineSidePrecise(ViewPath[0], pds->dst) != P_PointOnLineSidePrecise(ViewPath[1], pds->dst)) + if (!r_viewpoint.showviewer && r_viewpoint.camera && P_PointOnLineSidePrecise(r_viewpoint.Path[0], pds->dst) != P_PointOnLineSidePrecise(r_viewpoint.Path[1], pds->dst)) { - double distp = (ViewPath[0] - ViewPath[1]).Length(); + double distp = (r_viewpoint.Path[0] - r_viewpoint.Path[1]).Length(); if (distp > EQUAL_EPSILON) { - double dist1 = (ViewPos - ViewPath[0]).Length(); - double dist2 = (ViewPos - ViewPath[1]).Length(); + double dist1 = (r_viewpoint.Pos - r_viewpoint.Path[0]).Length(); + double dist2 = (r_viewpoint.Pos - r_viewpoint.Path[1]).Length(); if (dist1 + dist2 < distp + 1) { - camera->renderflags |= RF_INVISIBLE; + r_viewpoint.camera->renderflags |= RF_INVISIBLE; } } } } - ViewSin = ViewAngle.Sin(); - ViewCos = ViewAngle.Cos(); + r_viewpoint.Sin = r_viewpoint.Angles.Yaw.Sin(); + r_viewpoint.Cos = r_viewpoint.Angles.Yaw.Cos(); - ViewTanSin = FocalTangent * ViewSin; - ViewTanCos = FocalTangent * ViewCos; + r_viewpoint.TanSin = r_viewwindow.FocalTangent * r_viewpoint.Sin; + r_viewpoint.TanCos = r_viewwindow.FocalTangent * r_viewpoint.Cos; CopyStackedViewParameters(); @@ -425,14 +425,14 @@ namespace swrenderer Thread->OpaquePass->RenderScene(); Thread->Clip3D->ResetClip(); // reset clips (floor/ceiling) - if (!savedvisibility && camera) camera->renderflags &= ~RF_INVISIBLE; + if (!savedvisibility && r_viewpoint.camera) r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; PlaneCycles.Clock(); Thread->PlaneList->Render(); RenderPlanePortals(); PlaneCycles.Unclock(); - double vzp = ViewPos.Z; + double vzp = r_viewpoint.Pos.Z; int prevuniq = CurrentPortalUniq; // depth check is in another place right now @@ -463,10 +463,10 @@ namespace swrenderer CurrentPortal = prevpds; MirrorFlags = prevmf; - ViewAngle = startang; - ViewPos = startpos; - ViewPath[0] = savedpath[0]; - ViewPath[1] = savedpath[1]; + r_viewpoint.Angles.Yaw = startang; + r_viewpoint.Pos = startpos; + r_viewpoint.Path[0] = savedpath[0]; + r_viewpoint.Path[1] = savedpath[1]; } void RenderPortal::RenderLinePortalHighlight(PortalDrawseg* pds) @@ -513,9 +513,9 @@ namespace swrenderer void RenderPortal::CopyStackedViewParameters() { - stacked_viewpos = ViewPos; - stacked_angle = ViewAngle; - stacked_extralight = extralight; + stacked_viewpos = r_viewpoint.Pos; + stacked_angle = r_viewpoint.Angles; + stacked_extralight = r_viewpoint.extralight; stacked_visibility = LightVisibility::Instance()->GetVisibility(); } diff --git a/src/swrenderer/scene/r_portal.h b/src/swrenderer/scene/r_portal.h index 0d65bfa749..00322e2b61 100644 --- a/src/swrenderer/scene/r_portal.h +++ b/src/swrenderer/scene/r_portal.h @@ -50,7 +50,7 @@ namespace swrenderer int stacked_extralight = 0; double stacked_visibility = 0.0; DVector3 stacked_viewpos; - DAngle stacked_angle; + DRotator stacked_angle; int numskyboxes = 0; // For ADD_STAT(skyboxes) diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index f7b8c9c88a..2a5cf28aef 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -132,7 +132,7 @@ namespace swrenderer MaskedCycles.Reset(); WallScanCycles.Reset(); - R_SetupFrame(actor); + R_SetupFrame(r_viewpoint, r_viewwindow, actor); CameraLight::Instance()->SetCamera(actor); RenderViewport::Instance()->SetupFreelook(); @@ -146,18 +146,18 @@ namespace swrenderer // Link the polyobjects right before drawing the scene to reduce the amounts of calls to this function PO_LinkToSubsectors(); - ActorRenderFlags savedflags = camera->renderflags; + ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; // Never draw the player unless in chasecam mode - if (!r_showviewer) + if (!r_viewpoint.showviewer) { - camera->renderflags |= RF_INVISIBLE; + r_viewpoint.camera->renderflags |= RF_INVISIBLE; } RenderThreadSlices(); MainThread()->PlayerSprites->Render(); RenderDrawQueues(); - camera->renderflags = savedflags; + r_viewpoint.camera->renderflags = savedflags; interpolator.RestoreInterpolations(); // If we don't want shadered colormaps, NULL it now so that the @@ -331,17 +331,17 @@ namespace swrenderer viewwidth = width; viewport->RenderTarget = canvas; - R_SetWindow(12, width, height, height, true); + R_SetWindow(r_viewpoint, r_viewwindow, 12, width, height, height, true); viewwindowx = x; viewwindowy = y; viewactive = true; - viewport->SetViewport(width, height, WidescreenRatio); + viewport->SetViewport(width, height, r_viewwindow.WidescreenRatio); RenderActorView(actor, dontmaplines); viewport->RenderTarget = screen; - R_ExecuteSetViewSize(); + R_ExecuteSetViewSize(r_viewpoint, r_viewwindow); float trueratio; ActiveRatio(width, height, &trueratio); screen->Lock(true); diff --git a/src/swrenderer/scene/r_translucent_pass.cpp b/src/swrenderer/scene/r_translucent_pass.cpp index 2e360a5e6a..d7e096bbdf 100644 --- a/src/swrenderer/scene/r_translucent_pass.cpp +++ b/src/swrenderer/scene/r_translucent_pass.cpp @@ -175,7 +175,7 @@ namespace swrenderer else { // kg3D - correct sorting // ceilings - for (HeightLevel *hl = clip3d->height_cur; hl != nullptr && hl->height >= ViewPos.Z; hl = hl->prev) + for (HeightLevel *hl = clip3d->height_cur; hl != nullptr && hl->height >= r_viewpoint.Pos.Z; hl = hl->prev) { if (hl->next) { @@ -195,7 +195,7 @@ namespace swrenderer clip3d->fake3D = FAKE3D_DOWN2UP | FAKE3D_CLIPTOP; clip3d->sclipTop = clip3d->height_top->height; DrawMaskedSingle(true); - for (HeightLevel *hl = clip3d->height_top; hl != nullptr && hl->height < ViewPos.Z; hl = hl->next) + for (HeightLevel *hl = clip3d->height_top; hl != nullptr && hl->height < r_viewpoint.Pos.Z; hl = hl->next) { Thread->PlaneList->RenderHeight(hl->height); if (hl->next) diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp index c33769691d..d12117b3ab 100644 --- a/src/swrenderer/things/r_decal.cpp +++ b/src/swrenderer/things/r_decal.cpp @@ -144,8 +144,8 @@ namespace swrenderer DVector2 angvec = (curline->v2->fPos() - curline->v1->fPos()).Unit(); float maskedScaleY; - decal_left = decal_pos - edge_left * angvec - ViewPos; - decal_right = decal_pos + edge_right * angvec - ViewPos; + decal_left = decal_pos - edge_left * angvec - r_viewpoint.Pos; + decal_right = decal_pos + edge_right * angvec - r_viewpoint.Pos; CameraLight *cameraLight; double texturemid; @@ -222,7 +222,7 @@ namespace swrenderer } yscale = decal->ScaleY; - texturemid = WallSpriteTile->TopOffset + (zpos - ViewPos.Z) / yscale; + texturemid = WallSpriteTile->TopOffset + (zpos - r_viewpoint.Pos.Z) / yscale; // Clip sprite to drawseg x1 = MAX(clipper->x1, x1); diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index c121936158..b415fa6708 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -77,16 +77,16 @@ namespace swrenderer return; // transform the origin point - tr_x = particle->Pos.X - ViewPos.X; - tr_y = particle->Pos.Y - ViewPos.Y; + tr_x = particle->Pos.X - r_viewpoint.Pos.X; + tr_y = particle->Pos.Y - r_viewpoint.Pos.Y; - tz = tr_x * ViewTanCos + tr_y * ViewTanSin; + tz = tr_x * r_viewpoint.TanCos + tr_y * r_viewpoint.TanSin; // particle is behind view plane? if (tz < MINZ) return; - tx = tr_x * ViewSin - tr_y * ViewCos; + tx = tr_x * r_viewpoint.Sin - tr_y * r_viewpoint.Cos; // Flip for mirrors if (renderportal->MirrorFlags & RF_XFLIP) @@ -99,13 +99,13 @@ namespace swrenderer return; tiz = 1 / tz; - xscale = centerx * tiz; + xscale = r_viewwindow.centerx * tiz; // calculate edges of the shape double psize = particle->size / 8.0; - x1 = MAX(renderportal->WindowLeft, centerx + xs_RoundToInt((tx - psize) * xscale)); - x2 = MIN(renderportal->WindowRight, centerx + xs_RoundToInt((tx + psize) * xscale)); + x1 = MAX(renderportal->WindowLeft, r_viewwindow.centerx + xs_RoundToInt((tx - psize) * xscale)); + x2 = MIN(renderportal->WindowRight, r_viewwindow.centerx + xs_RoundToInt((tx + psize) * xscale)); if (x1 >= x2) return; @@ -113,7 +113,7 @@ namespace swrenderer auto viewport = RenderViewport::Instance(); yscale = xscale; // YaspectMul is not needed for particles as they should always be square - ty = particle->Pos.Z - ViewPos.Z; + ty = particle->Pos.Z - r_viewpoint.Pos.Z; y1 = xs_RoundToInt(viewport->CenterY - (ty + psize) * yscale); y2 = xs_RoundToInt(viewport->CenterY - (ty - psize) * yscale); diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 6fda2ab9a9..b68523d89e 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -82,37 +82,37 @@ namespace swrenderer F3DFloor *rover; if (!r_drawplayersprites || - !camera || - !camera->player || + !r_viewpoint.camera || + !r_viewpoint.camera->player || (players[consoleplayer].cheats & CF_CHASECAM) || - (r_deathcamera && camera->health <= 0)) + (r_deathcamera && r_viewpoint.camera->health <= 0)) return; FDynamicColormap *basecolormap; CameraLight *cameraLight = CameraLight::Instance(); - if (cameraLight->FixedLightLevel() < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) + if (cameraLight->FixedLightLevel() < 0 && r_viewpoint.sector->e && r_viewpoint.sector->e->XFloor.lightlist.Size()) { - for (i = viewsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) + for (i = r_viewpoint.sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { - if (ViewPos.Z <= viewsector->e->XFloor.lightlist[i].plane.Zat0()) + if (r_viewpoint.Pos.Z <= r_viewpoint.sector->e->XFloor.lightlist[i].plane.Zat0()) { - rover = viewsector->e->XFloor.lightlist[i].caster; + rover = r_viewpoint.sector->e->XFloor.lightlist[i].caster; if (rover) { - if (rover->flags & FF_DOUBLESHADOW && ViewPos.Z <= rover->bottom.plane->Zat0()) + if (rover->flags & FF_DOUBLESHADOW && r_viewpoint.Pos.Z <= rover->bottom.plane->Zat0()) break; sec = rover->model; if (rover->flags & FF_FADEWALLS) basecolormap = sec->ColorMap; else - basecolormap = viewsector->e->XFloor.lightlist[i].extra_colormap; + basecolormap = r_viewpoint.sector->e->XFloor.lightlist[i].extra_colormap; } break; } } if (!sec) { - sec = viewsector; + sec = r_viewpoint.sector; basecolormap = sec->ColorMap; } floorlight = ceilinglight = sec->lightlevel; @@ -120,7 +120,7 @@ namespace swrenderer else { // This used to use camera->Sector but due to interpolation that can be incorrect // when the interpolated viewpoint is in a different sector than the camera. - sec = Thread->OpaquePass->FakeFlat(viewsector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0); + sec = Thread->OpaquePass->FakeFlat(r_viewpoint.sector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0); // [RH] set basecolormap basecolormap = sec->ColorMap; @@ -133,7 +133,7 @@ namespace swrenderer lightnum = ((floorlight + ceilinglight) >> 1) + LightVisibility::ActualExtraLight(foggy); int spriteshade = LightVisibility::LightLevelToShade(lightnum, foggy) - 24 * FRACUNIT; - if (camera->player != NULL) + if (r_viewpoint.camera->player != NULL) { auto viewport = RenderViewport::Instance(); @@ -143,10 +143,10 @@ namespace swrenderer viewport->CenterY = viewheight / 2; - P_BobWeapon(camera->player, &bobx, &boby, r_TicFracF); + P_BobWeapon(r_viewpoint.camera->player, &bobx, &boby, r_viewpoint.TicFrac); // Interpolate the main weapon layer once so as to be able to add it to other layers. - if ((weapon = camera->player->FindPSprite(PSP_WEAPON)) != nullptr) + if ((weapon = r_viewpoint.camera->player->FindPSprite(PSP_WEAPON)) != nullptr) { if (weapon->firstTic) { @@ -155,8 +155,8 @@ namespace swrenderer } else { - wx = weapon->oldx + (weapon->x - weapon->oldx) * r_TicFracF; - wy = weapon->oldy + (weapon->y - weapon->oldy) * r_TicFracF; + wx = weapon->oldx + (weapon->x - weapon->oldx) * r_viewpoint.TicFrac; + wy = weapon->oldy + (weapon->y - weapon->oldy) * r_viewpoint.TicFrac; } } else @@ -166,7 +166,7 @@ namespace swrenderer } // add all active psprites - psp = camera->player->psprites; + psp = r_viewpoint.camera->player->psprites; while (psp) { // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. @@ -176,7 +176,7 @@ namespace swrenderer if ((psp->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr) && psp->GetCaller() != nullptr) { - RenderSprite(psp, camera, bobx, boby, wx, wy, r_TicFracF, spriteshade, basecolormap, foggy); + RenderSprite(psp, r_viewpoint.camera, bobx, boby, wx, wy, r_viewpoint.TicFrac, spriteshade, basecolormap, foggy); } psp = psp->GetNext(); @@ -245,7 +245,7 @@ namespace swrenderer auto viewport = RenderViewport::Instance(); - double pspritexscale = centerxwide / 160.0; + double pspritexscale = r_viewwindow.centerxwide / 160.0; double pspriteyscale = pspritexscale * viewport->YaspectMul; double pspritexiscale = 1 / pspritexscale; @@ -273,7 +273,7 @@ namespace swrenderer vis.texturemid = (BASEYCENTER - sy) * tex->Scale.Y + tex->TopOffset; - if (camera->player && (viewport->RenderTarget != screen || + if (r_viewpoint.camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BASEXCENTER * 2) && !st_scale))) { // Adjust PSprite for fullscreen views @@ -292,7 +292,7 @@ namespace swrenderer } if (pspr->GetID() < PSP_TARGETCENTER) { // Move the weapon down for 1280x1024. - vis.texturemid -= AspectPspriteOffset(WidescreenRatio); + vis.texturemid -= AspectPspriteOffset(r_viewwindow.WidescreenRatio); } vis.x1 = x1 < 0 ? 0 : x1; vis.x2 = x2 >= viewwidth ? viewwidth : x2; @@ -447,14 +447,14 @@ namespace swrenderer colormap_to_use = (FDynamicColormap*)vis.Light.BaseColormap; - if (camera->Inventory != nullptr) + if (r_viewpoint.camera->Inventory != nullptr) { visstyle_t visstyle; visstyle.Alpha = vis.Alpha; visstyle.RenderStyle = STYLE_Count; visstyle.Invert = false; - camera->Inventory->AlterWeaponSprite(&visstyle); + r_viewpoint.camera->Inventory->AlterWeaponSprite(&visstyle); vis.Alpha = visstyle.Alpha; diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 0979291972..06b6ec9bb3 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -66,16 +66,16 @@ namespace swrenderer void RenderSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { // transform the origin point - double tr_x = pos.X - ViewPos.X; - double tr_y = pos.Y - ViewPos.Y; + double tr_x = pos.X - r_viewpoint.Pos.X; + double tr_y = pos.Y - r_viewpoint.Pos.Y; - double tz = tr_x * ViewTanCos + tr_y * ViewTanSin; + double tz = tr_x * r_viewpoint.TanCos + tr_y * r_viewpoint.TanSin; // thing is behind view plane? if (tz < MINZ) return; - double tx = tr_x * ViewSin - tr_y * ViewCos; + double tx = tr_x * r_viewpoint.Sin - tr_y * r_viewpoint.Cos; // [RH] Flip for mirrors RenderPortal *renderportal = thread->Portal.get(); @@ -129,7 +129,7 @@ namespace swrenderer double xscale = viewport->CenterX / tz; // [RH] Reject sprites that are off the top or bottom of the screen - if (viewport->globaluclip * tz > ViewPos.Z - gzb || viewport->globaldclip * tz < ViewPos.Z - gzt) + if (viewport->globaluclip * tz > r_viewpoint.Pos.Z - gzb || viewport->globaldclip * tz < r_viewpoint.Pos.Z - gzt) { return; } @@ -142,14 +142,14 @@ namespace swrenderer tx -= ((renderflags & RF_XFLIP) ? (tex->GetWidth() - tex->LeftOffset - 1) : tex->LeftOffset) * thingxscalemul; double dtx1 = tx * xscale; - int x1 = centerx + xs_RoundToInt(dtx1); + int x1 = r_viewwindow.centerx + xs_RoundToInt(dtx1); // off the right side? if (x1 >= renderportal->WindowRight) return; tx += tex->GetWidth() * thingxscalemul; - int x2 = centerx + xs_RoundToInt(tx * xscale); + int x2 = r_viewwindow.centerx + xs_RoundToInt(tx * xscale); // off the left side or too small? if ((x2 < renderportal->WindowLeft || x2 <= x1)) @@ -168,7 +168,7 @@ namespace swrenderer vis->yscale = float(viewport->InvZtoScale * yscale / tz); vis->idepth = float(1 / tz); vis->floorclip = thing->Floorclip / yscale; - vis->texturemid = tex->TopOffset - (ViewPos.Z - pos.Z + thing->Floorclip) / yscale; + vis->texturemid = tex->TopOffset - (r_viewpoint.Pos.Z - pos.Z + thing->Floorclip) / yscale; vis->x1 = x1 < renderportal->WindowLeft ? renderportal->WindowLeft : x1; vis->x2 = x2 > renderportal->WindowRight ? renderportal->WindowRight : x2; //vis->Angle = thing->Angles.Yaw; @@ -184,7 +184,7 @@ namespace swrenderer vis->xiscale = iscale; } - vis->startfrac += (fixed_t)(vis->xiscale * (vis->x1 - centerx + 0.5 - dtx1)); + vis->startfrac += (fixed_t)(vis->xiscale * (vis->x1 - r_viewwindow.centerx + 0.5 - dtx1)); // killough 3/27/98: save sector for special clipping later vis->heightsec = heightsec; @@ -194,8 +194,8 @@ namespace swrenderer vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; vis->gzb = (float)gzb; // [RH] use gzb, not thing->z vis->gzt = (float)gzt; // killough 3/27/98 - vis->deltax = float(pos.X - ViewPos.X); - vis->deltay = float(pos.Y - ViewPos.Y); + vis->deltax = float(pos.X - r_viewpoint.Pos.X); + vis->deltay = float(pos.Y - r_viewpoint.Pos.Y); vis->renderflags = renderflags; if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index f636afa282..a535ae565c 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -95,7 +95,7 @@ namespace swrenderer { if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) { - clip3d->sclipTop = spr->sector->ceilingplane.ZatPoint(ViewPos); + clip3d->sclipTop = spr->sector->ceilingplane.ZatPoint(r_viewpoint.Pos); } sector_t *sec = nullptr; FDynamicColormap *mybasecolormap = nullptr; @@ -169,7 +169,7 @@ namespace swrenderer if (spr->FakeFlatStat != WaterFakeSide::AboveCeiling) { double hz = spr->heightsec->floorplane.ZatPoint(spr->gpos); - int h = xs_RoundToInt(viewport->CenterY - (hz - ViewPos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); if (spr->FakeFlatStat == WaterFakeSide::BelowFloor) { // seen below floor: clip top @@ -191,7 +191,7 @@ namespace swrenderer if (spr->FakeFlatStat != WaterFakeSide::BelowFloor && !(spr->heightsec->MoreFlags & SECF_FAKEFLOORONLY)) { double hz = spr->heightsec->ceilingplane.ZatPoint(spr->gpos); - int h = xs_RoundToInt(viewport->CenterY - (hz - ViewPos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); if (spr->FakeFlatStat == WaterFakeSide::AboveCeiling) { // seen above ceiling: clip bottom @@ -230,12 +230,12 @@ namespace swrenderer if (spr->fakefloor) { double floorz = spr->fakefloor->top.plane->Zat0(); - if (ViewPos.Z > floorz && floorz == clip3d->sclipBottom) + if (r_viewpoint.Pos.Z > floorz && floorz == clip3d->sclipBottom) { hz = spr->fakefloor->bottom.plane->Zat0(); } } - int h = xs_RoundToInt(viewport->CenterY - (hz - ViewPos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); if (h < botclip) { botclip = MAX(0, h); @@ -251,12 +251,12 @@ namespace swrenderer if (spr->fakeceiling != nullptr) { double ceilingZ = spr->fakeceiling->bottom.plane->Zat0(); - if (ViewPos.Z < ceilingZ && ceilingZ == clip3d->sclipTop) + if (r_viewpoint.Pos.Z < ceilingZ && ceilingZ == clip3d->sclipTop) { hz = spr->fakeceiling->top.plane->Zat0(); } } - int h = xs_RoundToInt(viewport->CenterY - (hz - ViewPos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); if (h > topclip) { topclip = short(MIN(h, viewheight)); diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index 3d27ac903e..1a20379227 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -45,11 +45,11 @@ namespace swrenderer void RenderVoxel::Project(RenderThread *thread, AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { // transform the origin point - double tr_x = pos.X - ViewPos.X; - double tr_y = pos.Y - ViewPos.Y; + double tr_x = pos.X - r_viewpoint.Pos.X; + double tr_y = pos.Y - r_viewpoint.Pos.Y; - double tz = tr_x * ViewTanCos + tr_y * ViewTanSin; - double tx = tr_x * ViewSin - tr_y * ViewCos; + double tz = tr_x * r_viewpoint.TanCos + tr_y * r_viewpoint.TanSin; + double tx = tr_x * r_viewpoint.Sin - tr_y * r_viewpoint.Cos; // [RH] Flip for mirrors RenderPortal *renderportal = thread->Portal.get(); @@ -121,8 +121,8 @@ namespace swrenderer vis->Angle -= ang; } - vis->pa.vpos = { (float)ViewPos.X, (float)ViewPos.Y, (float)ViewPos.Z }; - vis->pa.vang = FAngle((float)ViewAngle.Degrees); + vis->pa.vpos = { (float)r_viewpoint.Pos.X, (float)r_viewpoint.Pos.Y, (float)r_viewpoint.Pos.Z }; + vis->pa.vang = FAngle((float)r_viewpoint.Angles.Yaw.Degrees); // killough 3/27/98: save sector for special clipping later vis->heightsec = heightsec; @@ -132,8 +132,8 @@ namespace swrenderer vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; vis->gzb = (float)gzb; // [RH] use gzb, not thing->z vis->gzt = (float)gzt; // killough 3/27/98 - vis->deltax = float(pos.X - ViewPos.X); - vis->deltay = float(pos.Y - ViewPos.Y); + vis->deltax = float(pos.X - r_viewpoint.Pos.X); + vis->deltay = float(pos.Y - r_viewpoint.Pos.Y); vis->renderflags = renderflags; if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D @@ -267,9 +267,9 @@ namespace swrenderer auto viewport = RenderViewport::Instance(); - const int nytooclose = centerxwide * 2100, nytoofar = 32768*32768 - 1048576; - const int xdimenscale = FLOAT2FIXED(centerxwide * viewport->YaspectMul / 160); - const double centerxwide_f = centerxwide; + const int nytooclose = r_viewwindow.centerxwide * 2100, nytoofar = 32768*32768 - 1048576; + const int xdimenscale = FLOAT2FIXED(r_viewwindow.centerxwide * viewport->YaspectMul / 160); + const double centerxwide_f = r_viewwindow.centerxwide; const double centerxwidebig_f = centerxwide_f * 65536*65536*8; // Convert to Build's coordinate system. @@ -315,8 +315,8 @@ namespace swrenderer daxscale <<= (k+8); dayscale <<= (k+8); dazscale = FixedDiv(dayscale, FLOAT2FIXED(viewport->BaseYaspectMul)); daxscale = fixed_t(daxscale / viewport->YaspectMul); - daxscale = Scale(daxscale, xdimenscale, centerxwide << 9); - dayscale = Scale(dayscale, FixedMul(xdimenscale, viewport->viewingrangerecip), centerxwide << 9); + daxscale = Scale(daxscale, xdimenscale, r_viewwindow.centerxwide << 9); + dayscale = Scale(dayscale, FixedMul(xdimenscale, viewport->viewingrangerecip), r_viewwindow.centerxwide << 9); daxscalerecip = (1<<30) / daxscale; dayscalerecip = (1<<30) / dayscale; @@ -432,9 +432,9 @@ namespace swrenderer voxend = (kvxslab_t *)(slabxoffs + xyoffs[y+1]); if (voxptr >= voxend) continue; - lx = xs_RoundToInt(nx * centerxwide_f / (ny + y1)) + centerx; + lx = xs_RoundToInt(nx * centerxwide_f / (ny + y1)) + r_viewwindow.centerx; if (lx < 0) lx = 0; - rx = xs_RoundToInt((nx + nxoff) * centerxwide_f / (ny + y2)) + centerx; + rx = xs_RoundToInt((nx + nxoff) * centerxwide_f / (ny + y2)) + r_viewwindow.centerx; if (rx > viewwidth) rx = viewwidth; if (rx <= lx) continue; @@ -475,20 +475,20 @@ namespace swrenderer if (k < 0) { if ((voxptr->backfacecull & oand32) == 0) continue; - z2 = MulScale32(l2, k) + centery; /* Below slab */ + z2 = MulScale32(l2, k) + r_viewwindow.centery; /* Below slab */ } else { if ((voxptr->backfacecull & oand) == 0) continue; /* Middle of slab */ - z2 = MulScale32(l1, k) + centery; + z2 = MulScale32(l1, k) + r_viewwindow.centery; } - z1 = MulScale32(l1, j) + centery; + z1 = MulScale32(l1, j) + r_viewwindow.centery; } else { if ((voxptr->backfacecull & oand16) == 0) continue; - z1 = MulScale32(l2, j) + centery; /* Above slab */ - z2 = MulScale32(l1, j + (zleng << 15)) + centery; + z1 = MulScale32(l2, j) + r_viewwindow.centery; /* Above slab */ + z2 = MulScale32(l1, j + (zleng << 15)) + r_viewwindow.centery; } if (z2 <= z1) continue; diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index d4d8f9b58e..c152880c98 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -82,8 +82,8 @@ namespace swrenderer x1 *= scale.X; x2 *= scale.X; - left.X = pos.X - x1 * angcos - ViewPos.X; - left.Y = pos.Y - x1 * angsin - ViewPos.Y; + left.X = pos.X - x1 * angcos - r_viewpoint.Pos.X; + left.Y = pos.Y - x1 * angsin - r_viewpoint.Pos.Y; right.X = left.X + x2 * angcos; right.Y = right.Y + x2 * angsin; @@ -98,7 +98,7 @@ namespace swrenderer // Sprite sorting should probably treat these as walls, not sprites, // but right now, I just want to get them drawing. - tz = (pos.X - ViewPos.X) * ViewTanCos + (pos.Y - ViewPos.Y) * ViewTanSin; + tz = (pos.X - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (pos.Y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin; int scaled_to = pic->GetScaledTopOffset(); int scaled_bo = scaled_to - pic->GetScaledHeight(); @@ -117,8 +117,8 @@ namespace swrenderer vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; vis->gzb = (float)gzb; vis->gzt = (float)gzt; - vis->deltax = float(pos.X - ViewPos.X); - vis->deltay = float(pos.Y - ViewPos.Y); + vis->deltax = float(pos.X - r_viewpoint.Pos.X); + vis->deltay = float(pos.Y - r_viewpoint.Pos.Y); vis->renderflags = renderflags; if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D vis->RenderStyle = thing->RenderStyle; @@ -158,7 +158,7 @@ namespace swrenderer walltexcoords.Project(spr->pic->GetWidth() << FRACBITS, x1, x2, WallT); iyscale = 1 / spr->yscale; - double texturemid = (spr->gzt - ViewPos.Z) * iyscale; + double texturemid = (spr->gzt - r_viewpoint.Pos.Z) * iyscale; if (spr->renderflags & RF_XFLIP) { int right = (spr->pic->GetWidth() << FRACBITS) - 1; diff --git a/src/swrenderer/viewport/r_viewport.cpp b/src/swrenderer/viewport/r_viewport.cpp index 6182976d70..384c37c6a5 100644 --- a/src/swrenderer/viewport/r_viewport.cpp +++ b/src/swrenderer/viewport/r_viewport.cpp @@ -70,8 +70,8 @@ namespace swrenderer fuzzviewheight = viewheight - 2; // Maximum row the fuzzer can draw to - CenterX = centerx; - CenterY = centery; + CenterX = r_viewwindow.centerx; + CenterY = r_viewwindow.centery; virtwidth = virtwidth2 = fullWidth; virtheight = virtheight2 = fullHeight; @@ -85,13 +85,13 @@ namespace swrenderer virtwidth2 = virtwidth2 * AspectMultiplier(trueratio) / 48; } - if (AspectTallerThanWide(WidescreenRatio)) + if (AspectTallerThanWide(r_viewwindow.WidescreenRatio)) { - virtheight = virtheight * AspectMultiplier(WidescreenRatio) / 48; + virtheight = virtheight * AspectMultiplier(r_viewwindow.WidescreenRatio) / 48; } else { - virtwidth = virtwidth * AspectMultiplier(WidescreenRatio) / 48; + virtwidth = virtwidth * AspectMultiplier(r_viewwindow.WidescreenRatio) / 48; } BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2); @@ -117,9 +117,9 @@ namespace swrenderer { double dy; - if (camera != NULL) + if (r_viewpoint.camera != NULL) { - dy = FocalLengthY * (-ViewPitch).Tan(); + dy = FocalLengthY * (-r_viewpoint.Angles.Pitch).Tan(); } else { @@ -127,7 +127,7 @@ namespace swrenderer } CenterY = (viewheight / 2.0) + dy; - centery = xs_ToInt(CenterY); + r_viewwindow.centery = xs_ToInt(CenterY); globaluclip = -CenterY / InvZtoScale; globaldclip = (viewheight - CenterY) / InvZtoScale; } @@ -153,23 +153,23 @@ namespace swrenderer int i; // Calc focallength so FieldOfView angles cover viewwidth. - FocalLengthX = CenterX / FocalTangent; + FocalLengthX = CenterX / r_viewwindow.FocalTangent; FocalLengthY = FocalLengthX * YaspectMul; // This is 1/FocalTangent before the widescreen extension of FOV. - viewingrangerecip = FLOAT2FIXED(1. / tan(FieldOfView.Radians() / 2)); + viewingrangerecip = FLOAT2FIXED(1. / tan(r_viewpoint.FieldOfView.Radians() / 2)); // Now generate xtoviewangle for sky texture mapping. // [RH] Do not generate viewangletox, because texture mapping is no // longer done with trig, so it's not needed. - const double slopestep = FocalTangent / centerx; + const double slopestep = r_viewwindow.FocalTangent / r_viewwindow.centerx; double slope; - for (i = centerx, slope = 0; i <= viewwidth; i++, slope += slopestep) + for (i = r_viewwindow.centerx, slope = 0; i <= viewwidth; i++, slope += slopestep) { xtoviewangle[i] = angle_t((2 * M_PI - atan(slope)) * (ANGLE_180 / M_PI)); } - for (i = 0; i < centerx; i++) + for (i = 0; i < r_viewwindow.centerx; i++) { xtoviewangle[i] = 0 - xtoviewangle[viewwidth - i - 1]; } @@ -177,23 +177,23 @@ namespace swrenderer DVector2 RenderViewport::PointWorldToView(const DVector2 &worldPos) const { - double translatedX = worldPos.X - ViewPos.X; - double translatedY = worldPos.Y - ViewPos.Y; + double translatedX = worldPos.X - r_viewpoint.Pos.X; + double translatedY = worldPos.Y - r_viewpoint.Pos.Y; return { - translatedX * ViewSin - translatedY * ViewCos, - translatedX * ViewTanCos + translatedY * ViewTanSin + translatedX * r_viewpoint.Sin - translatedY * r_viewpoint.Cos, + translatedX * r_viewpoint.TanCos + translatedY * r_viewpoint.TanSin }; } DVector3 RenderViewport::PointWorldToView(const DVector3 &worldPos) const { - double translatedX = worldPos.X - ViewPos.X; - double translatedY = worldPos.Y - ViewPos.Y; - double translatedZ = worldPos.Z - ViewPos.Z; + double translatedX = worldPos.X - r_viewpoint.Pos.X; + double translatedY = worldPos.Y - r_viewpoint.Pos.Y; + double translatedZ = worldPos.Z - r_viewpoint.Pos.Z; return { - translatedX * ViewSin - translatedY * ViewCos, + translatedX * r_viewpoint.Sin - translatedY * r_viewpoint.Cos, translatedZ, - translatedX * ViewTanCos + translatedY * ViewTanSin + translatedX * r_viewpoint.TanCos + translatedY * r_viewpoint.TanSin }; } diff --git a/src/textures/warptexture.cpp b/src/textures/warptexture.cpp index c39410522f..08ce3103d6 100644 --- a/src/textures/warptexture.cpp +++ b/src/textures/warptexture.cpp @@ -80,12 +80,12 @@ void FWarpTexture::Unload () bool FWarpTexture::CheckModified () { - return r_FrameTime != GenTime; + return r_viewpoint.FrameTime != GenTime; } const uint8_t *FWarpTexture::GetPixels () { - uint32_t time = r_FrameTime; + uint32_t time = r_viewpoint.FrameTime; if (Pixels == NULL || time != GenTime) { @@ -96,7 +96,7 @@ const uint8_t *FWarpTexture::GetPixels () const uint32_t *FWarpTexture::GetPixelsBgra() { - uint32_t time = r_FrameTime; + uint32_t time = r_viewpoint.FrameTime; if (Pixels == NULL || time != GenTime) { MakeTexture(time); @@ -115,7 +115,7 @@ const uint32_t *FWarpTexture::GetPixelsBgra() const uint8_t *FWarpTexture::GetColumn (unsigned int column, const Span **spans_out) { - uint32_t time = r_FrameTime; + uint32_t time = r_viewpoint.FrameTime; if (Pixels == NULL || time != GenTime) { diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 138266946c..99706c9a96 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -1112,10 +1112,10 @@ void DoomSpecificInfo (char *buffer, size_t bufflen) } else { - buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", ViewPos.X); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", ViewPos.Y); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", ViewPos.Z); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", ViewAngle); + buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", r_viewpoint.Pos.X); + buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", r_viewpoint.Pos.Y); + buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", r_viewpoint.Pos.Z); + buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", r_viewpoint.Angles.Yaw); } } *buffer++ = '\r';