Revert "Squashed commit of the following:"

This reverts commit d8ef27e0ed.
This commit is contained in:
Rachael Alexanderson 2024-02-09 12:27:00 -05:00
parent d8ef27e0ed
commit ccb2fc6792
No known key found for this signature in database
GPG key ID: 26A8ACCE97115EE0
11 changed files with 192 additions and 37 deletions

View file

@ -35,6 +35,7 @@
#include <time.h>
#include <stdexcept>
#include <cstdint>
#include "w_zip.h"
#include "ancientzip.h"
#include "resourcefile.h"

View file

@ -146,11 +146,27 @@ float VREyeInfo::getShift() const
return vr_swap_eyes ? -res : res;
}
VSMatrix VREyeInfo::GetProjection(float fov, float aspectRatio, float fovRatio) const
VSMatrix VREyeInfo::GetProjection(float fov, float aspectRatio, float fovRatio, bool iso_ortho) const
{
VSMatrix result;
if (mShiftFactor == 0)
if (iso_ortho) // Orthographic projection for isometric viewpoint
{
double zNear = -1.0; // screen->GetZNear();
double zFar = screen->GetZFar();
double fH = tan(DEG2RAD(fov) / 2) / fovRatio;
double fW = fH * aspectRatio * mScaleFactor;
double left = -fW;
double right = fW;
double bottom = -fH;
double top = fH;
VSMatrix fmat(1);
fmat.ortho((float)left, (float)right, (float)bottom, (float)top, (float)zNear, (float)zFar);
return fmat;
}
else if (mShiftFactor == 0)
{
float fovy = (float)(2 * RAD2DEG(atan(tan(DEG2RAD(fov) / 2) / fovRatio)));
result.perspective(fovy, aspectRatio, screen->GetZNear(), screen->GetZFar());

View file

@ -27,7 +27,7 @@ struct VREyeInfo
float mShiftFactor;
float mScaleFactor;
VSMatrix GetProjection(float fov, float aspectRatio, float fovRatio) const;
VSMatrix GetProjection(float fov, float aspectRatio, float fovRatio, bool iso_ortho) const;
DVector3 GetViewShift(float yaw) const;
private:
float getShift() const;

View file

@ -692,6 +692,9 @@ enum EViewPosFlags // [MC] Flags for SetViewPos.
{
VPSF_ABSOLUTEOFFSET = 1 << 1, // Don't include angles.
VPSF_ABSOLUTEPOS = 1 << 2, // Use absolute position.
VPSF_ALLOWOUTOFBOUNDS = 1 << 3, // Allow viewpoint to go out of bounds (hardware renderer only).
VPSF_ORTHOGRAPHIC = 1 << 4, // Use orthographic projection.
VPSF_ISOMETRICSPRITES = 1 << 5, // Displace sprites towards camera and don't billboard (drawn from isometric perspective).
};
enum EAnimOverrideFlags

View file

@ -163,7 +163,11 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou
di->Viewpoint.FieldOfView = DAngle::fromDeg(fov); // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint)
// Stereo mode specific perspective projection
di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio);
float inv_iso_dist = 1.0f;
bool iso_ortho = (camera->ViewPos != NULL) && (camera->ViewPos->Flags & VPSF_ORTHOGRAPHIC);
if (iso_ortho && (camera->ViewPos->Offset.XY().Length() > 0)) inv_iso_dist = 3.0f/camera->ViewPos->Offset.XY().Length();
di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio * inv_iso_dist, iso_ortho);
// Stereo mode specific viewpoint adjustment
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees());
di->SetupView(RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);

View file

@ -1,4 +1,4 @@
//
//
//---------------------------------------------------------------------------
//
// Copyright(C) 2002-2016 Christoph Oelckers
@ -94,7 +94,7 @@ CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE)
//==========================================================================
//
//
//
//
//==========================================================================
@ -103,7 +103,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
bool additivefog = false;
bool foglayer = false;
int rel = fullbright ? 0 : getExtraLight();
auto &vp = di->Viewpoint;
auto &vp = di->Viewpoint;
if (translucent)
{
@ -336,7 +336,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
//==========================================================================
//
//
//
//
//==========================================================================
@ -391,7 +391,7 @@ bool HWSprite::CalculateVertices(HWDrawInfo* di, FVector3* v, DVector3* vp)
return true;
}
// [BB] Billboard stuff
const bool drawWithXYBillboard = ((particle && gl_billboard_particles && !(particle->flags & SPF_NO_XY_BILLBOARD)) || (!(actor && actor->renderflags & RF_FORCEYBILLBOARD)
//&& di->mViewActor != nullptr
@ -453,7 +453,7 @@ bool HWSprite::CalculateVertices(HWDrawInfo* di, FVector3* v, DVector3* vp)
float rollDegrees = doRoll ? Angles.Roll.Degrees() : 0;
float angleRad = (FAngle::fromDeg(270.) - HWAngles.Yaw).Radians();
// [fgsfds] Rotate the sprite about the sight vector (roll)
// [fgsfds] Rotate the sprite about the sight vector (roll)
if (isWallSprite)
{
float yawvecX = Angles.Yaw.Cos();
@ -489,13 +489,13 @@ bool HWSprite::CalculateVertices(HWDrawInfo* di, FVector3* v, DVector3* vp)
}
else // traditional "Y" billboard mode
{
if (doRoll || !offset.isZero())
if (doRoll || !offset.isZero() || ((di->Viewpoint.camera->ViewPos != NULL) && (di->Viewpoint.camera->ViewPos->Flags & VPSF_ISOMETRICSPRITES)))
{
mat.MakeIdentity();
if (!offset.isZero())
HandleSpriteOffsets(&mat, &HWAngles, &offset, false);
if (doRoll)
{
// Compute center of sprite
@ -507,11 +507,21 @@ bool HWSprite::CalculateVertices(HWDrawInfo* di, FVector3* v, DVector3* vp)
mat.Translate(-center.X, -center.Z, -center.Y);
}
if ((di->Viewpoint.camera->ViewPos != NULL) && (di->Viewpoint.camera->ViewPos->Flags & VPSF_ISOMETRICSPRITES))
{
float angleRad = (FAngle::fromDeg(270.) - HWAngles.Yaw).Radians();
mat.Translate(center.X, center.Z, center.Y);
mat.Translate(0.0, z2 - center.Z, 0.0);
mat.Rotate(-sin(angleRad), 0, cos(angleRad), -HWAngles.Pitch.Degrees());
mat.Translate(0.0, center.Z - z2, 0.0);
mat.Translate(-center.X, -center.Z, -center.Y);
}
v[0] = mat * FVector3(x1, z1, y1);
v[1] = mat * FVector3(x2, z1, y2);
v[2] = mat * FVector3(x1, z2, y1);
v[3] = mat * FVector3(x2, z2, y2);
}
else
{
@ -520,14 +530,14 @@ bool HWSprite::CalculateVertices(HWDrawInfo* di, FVector3* v, DVector3* vp)
v[2] = FVector3(x1, z2, y1);
v[3] = FVector3(x2, z2, y2);
}
}
return false;
}
//==========================================================================
//
//
//
//
//==========================================================================
@ -552,7 +562,7 @@ inline void HWSprite::PutSprite(HWDrawInfo *di, bool translucent)
//==========================================================================
//
//
//
//
//==========================================================================
@ -577,7 +587,7 @@ void HWSprite::CreateVertices(HWDrawInfo *di)
//==========================================================================
//
//
//
//
//==========================================================================
@ -616,7 +626,7 @@ void HWSprite::SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool transluc
}
z1=copySprite.z2=lightbottom;
vt=copySprite.vb=copySprite.vt+
vt=copySprite.vb=copySprite.vt+
(lightbottom-copySprite.z1)*(copySprite.vb-copySprite.vt)/(z2-copySprite.z1);
copySprite.PutSprite(di, translucent);
put=true;
@ -626,7 +636,7 @@ void HWSprite::SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool transluc
//==========================================================================
//
//
//
//
//==========================================================================
@ -711,7 +721,7 @@ void HWSprite::PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingp
z1 -= difft;
}
}
if (diffb <= (0 - (float)gl_sclipthreshold)) // such a large displacement can't be correct!
if (diffb <= (0 - (float)gl_sclipthreshold)) // such a large displacement can't be correct!
{
// for living monsters standing on the floor allow a little more.
if (!(thing->flags3&MF3_ISMONSTER) || (thing->flags&MF_NOGRAVITY) || (thing->flags&MF_CORPSE) || diffb < (-1.8*(float)gl_sclipthreshold))
@ -726,7 +736,7 @@ void HWSprite::PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingp
//==========================================================================
//
//
//
//
//==========================================================================
@ -805,7 +815,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
if (thruportal == 1) vieworigin += di->Level->Displacements.getOffset(viewmaster->Sector->PortalGroup, sector->PortalGroup);
if (fabs(vieworigin.X - vp.ActorPos.X) < 2 && fabs(vieworigin.Y - vp.ActorPos.Y) < 2) return;
// Necessary in order to prevent sprite pop-ins with viewpos and models.
// Necessary in order to prevent sprite pop-ins with viewpos and models.
auto* sec = viewmaster->Sector;
if (sec && !sec->PortalBlocksMovement(sector_t::ceiling))
{
@ -900,6 +910,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
{
bool mirror = false;
DAngle ang = (thingpos - vp.Pos).Angle();
if((di->Viewpoint.camera->ViewPos != NULL) && (di->Viewpoint.camera->ViewPos->Flags & VPSF_ISOMETRICSPRITES)) ang = vp.Angles.Yaw;
FTextureID patch;
// [ZZ] add direct picnum override
if (isPicnumOverride)
@ -1019,6 +1030,20 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
x2 = x - viewvecY*rightfac;
y1 = y + viewvecX*leftfac;
y2 = y + viewvecX*rightfac;
if((di->Viewpoint.camera->ViewPos != NULL) && (di->Viewpoint.camera->ViewPos->Flags & VPSF_ISOMETRICSPRITES)) // If sprites are drawn from an isometric perspective
{
float signX = 1.0;
float signY = 1.0;
if(viewvecX < 0) signX = -1.0;
if(viewvecY < 0) signY = -1.0;
if(viewvecX == 0) signX = 0.0;
if(viewvecY == 0) signY = 0.0;
x1 -= signX * thing->radius;
x2 -= signX * thing->radius;
y1 -= signY * thing->radius;
y2 -= signY * thing->radius;
}
break;
}
case RF_FLATSPRITE:
@ -1059,6 +1084,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
}
depth = (float)((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin);
if(((di->Viewpoint.camera->ViewPos != NULL) && (di->Viewpoint.camera->ViewPos->Flags & VPSF_ISOMETRICSPRITES))) depth = depth * vp.PitchCos - vp.PitchSin * z2; // Helps with stacking actors with small xy offsets
if (isSpriteShadow) depth += 1.f/65536.f; // always sort shadows behind the sprite.
// light calculation
@ -1286,7 +1312,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
//==========================================================================
//
//
//
//
//==========================================================================
@ -1312,7 +1338,7 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s
this->particle = particle;
fullbright = particle->flags & SPF_FULLBRIGHT;
if (di->isFullbrightScene())
if (di->isFullbrightScene())
{
Colormap.Clear();
}
@ -1371,7 +1397,7 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s
{
bool has_texture = particle->texture.isValid();
bool custom_animated_texture = (particle->flags & SPF_LOCAL_ANIM) && particle->animData.ok;
int particle_style = has_texture ? 2 : gl_particles_style; // Treat custom texture the same as smooth particles
// [BB] Load the texture for round or smooth particles
@ -1430,7 +1456,7 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s
float rvf = (particle->RollVel) * timefrac;
Angles.Roll = TAngle<double>::fromDeg(particle->Roll + rvf);
}
float factor;
if (particle_style == 1) factor = 1.3f / 7.f;
else if (particle_style == 2) factor = 2.5f / 7.f;
@ -1448,7 +1474,7 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s
z2=z+scalefac;
depth = (float)((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin);
// [BB] Translucent particles have to be rendered without the alpha test.
if (particle_style != 2 && trans>=1.0f-FLT_EPSILON) hw_styleflags = STYLEHW_Solid;
else hw_styleflags = STYLEHW_NoAlphaTest;
@ -1464,7 +1490,7 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s
}
// [MC] VisualThinkers are to be rendered akin to actor sprites. The reason this whole system
// is hitching a ride on particle_t is because of the large number of checks with
// is hitching a ride on particle_t is because of the large number of checks with
// HWSprite elsewhere in the draw lists.
void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t* sector)
{
@ -1475,7 +1501,7 @@ void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t
if (paused || spr->isFrozen())
timefrac = 0.;
bool custom_anim = ((spr->PT.flags & SPF_LOCAL_ANIM) && spr->PT.animData.ok);
texture = TexMan.GetGameTexture(
@ -1507,7 +1533,7 @@ void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t
auto r = spi.GetSpriteRect();
r.Scale(spr->Scale.X, spr->Scale.Y);
if (spr->bXFlip)
if (spr->bXFlip)
{
std::swap(ul,ur);
r.left = -r.width - r.left; // mirror the sprite's x-offset
@ -1534,7 +1560,7 @@ void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t
//==========================================================================
//
//
//
//
//==========================================================================

View file

@ -66,6 +66,7 @@
#include "i_system.h"
#include "v_draw.h"
#include "i_interface.h"
#include "d_main.h"
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
@ -153,6 +154,8 @@ FRenderViewpoint::FRenderViewpoint()
Sin = 0.0;
TanCos = 0.0;
TanSin = 0.0;
PitchCos = 0.0;
PitchSin = 0.0;
camera = nullptr;
sector = nullptr;
FieldOfView = DAngle::fromDeg(90.); // Angles in the SCREENWIDTH wide window
@ -600,7 +603,7 @@ void R_InterpolateView (FRenderViewpoint &viewpoint, player_t *player, double Fr
else break;
}
}
if (moved) viewpoint.noviewer = true;
if (moved && !viewpoint.showviewer) viewpoint.noviewer = true;
}
//==========================================================================
@ -630,6 +633,9 @@ void FRenderViewpoint::SetViewAngle (const FViewWindow &viewwindow)
TanSin = viewwindow.FocalTangent * Sin;
TanCos = viewwindow.FocalTangent * Cos;
PitchSin = Angles.Pitch.Sin();
PitchCos = Angles.Pitch.Cos();
DVector2 v = Angles.Yaw.ToVector();
ViewVector.X = v.X;
ViewVector.Y = v.Y;
@ -859,6 +865,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
{
iview->otic = nowtic;
iview->Old = iview->New;
viewpoint.noviewer = false;
}
//==============================================================================================
// Handles offsetting the camera with ChaseCam and/or viewpos.
@ -881,7 +888,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
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;
viewpoint.noviewer = false;
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.
@ -948,7 +955,11 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
// Interpolation still happens with everything else though and seems to work fine.
DefaultDraw = false;
viewpoint.NoPortalPath = true;
P_AdjustViewPos(mo, orig, next, viewpoint.sector, unlinked, VP, &viewpoint);
// Allow VPSF_ALLOWOUTOFBOUNDS camera viewpoints to go out of bounds when using HW renderer
if (!(VP->Flags & VPSF_ALLOWOUTOFBOUNDS) || !V_IsHardwareRenderer())
{
P_AdjustViewPos(mo, orig, next, viewpoint.sector, unlinked, VP, &viewpoint);
}
if (viewpoint.sector->PortalGroup != oldsector->PortalGroup || (unlinked && ((iview->New.Pos.XY() - iview->Old.Pos.XY()).LengthSquared()) > 256 * 256))
{
@ -995,7 +1006,10 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
viewpoint.SetViewAngle (viewwindow);
// Keep the view within the sector's floor and ceiling
if (viewpoint.sector->PortalBlocksMovement(sector_t::ceiling))
// But allow VPSF_ALLOWOUTOFBOUNDS camera viewpoints to go out of bounds when using hardware renderer
bool disembodied = false;
if (viewpoint.camera->ViewPos != NULL) disembodied = viewpoint.camera->ViewPos->Flags & VPSF_ALLOWOUTOFBOUNDS;
if (viewpoint.sector->PortalBlocksMovement(sector_t::ceiling) && (!disembodied || !V_IsHardwareRenderer()))
{
double theZ = viewpoint.sector->ceilingplane.ZatPoint(viewpoint.Pos) - 4;
if (viewpoint.Pos.Z > theZ)
@ -1004,7 +1018,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
}
}
if (viewpoint.sector->PortalBlocksMovement(sector_t::floor))
if (viewpoint.sector->PortalBlocksMovement(sector_t::floor) && (!disembodied || !V_IsHardwareRenderer()))
{
double theZ = viewpoint.sector->floorplane.ZatPoint(viewpoint.Pos) + 4;
if (viewpoint.Pos.Z < theZ)

View file

@ -33,6 +33,8 @@ struct FRenderViewpoint
double Sin; // sin(Angles.Yaw)
double TanCos; // FocalTangent * cos(Angles.Yaw)
double TanSin; // FocalTangent * sin(Angles.Yaw)
double PitchCos; // cos(Angles.Pitch)
double PitchSin; // sin(Angles.Pitch)
AActor *camera; // camera actor
sector_t *sector; // [RH] keep track of sector viewing from

View file

@ -1693,7 +1693,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset)
PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals);
ACTION_RETURN_BOOL(self->IsFreelookAllowed());
}
//==========================================================================
//
// ZScript counterpart to ACS ChangeSky, uses TextureIDs

View file

@ -128,3 +128,89 @@ class AimingCamera : SecurityCamera
}
}
class SpectatorCamera : Actor
{
bool chasingtracer;
double lagdistance; // camera gives chase (lazy follow) if tracer gets > lagdistance away from camera.pos
int chasemode; // 0: chase until tracer centered, 1: same but only when tracer is moving, 2: stop chase if tracer within lagdistance
property lagdistance : lagdistance;
property chasingtracer : chasingtracer;
property chasemode : chasemode;
default
{
+NOBLOCKMAP
+NOGRAVITY
+NOSECTOR
+NOINTERACTION
RenderStyle "None";
CameraHeight 0;
SpectatorCamera.chasingtracer false;
SpectatorCamera.lagdistance 0.0;
SpectatorCamera.chasemode 0;
}
void Init(double dist, double yaw, double inpitch, int inflags)
{
if(((inflags > 0) && (inflags & VPSF_ORTHOGRAPHIC)) || ((inflags < 0) && (ViewPos.Flags & VPSF_ORTHOGRAPHIC))) dist *= 3.0;
double zshift = 0.0;
if(tracer != NULL)
{
if(player != NULL) zshift = -0.5*tracer.height;
else zshift = 0.5*tracer.height;
}
else if (player != NULL && player.mo != NULL) zshift = -0.5*player.mo.height;
SetViewPos((-dist*Cos(yaw), -dist*Sin(yaw), dist*Tan(inpitch)+zshift), inflags);
LookAtSelf(inpitch);
}
void LookAtSelf(double inpitch)
{
if(ViewPos.Offset != (0., 0., 0.))
{
Vector3 negviewpos = (-1.0) * ViewPos.Offset;
angle = negviewpos.Angle();
pitch = inpitch;
}
}
override void Tick()
{
if(tracer != NULL)
{
Vector3 distvec = tracer.pos - pos;
double dist = distvec.length();
if((dist <= 4 && chasingtracer) || lagdistance <= 0.0) // Keep tracer centered on screen
{
SetOrigin(tracer.pos, true);
chasingtracer = false;
}
else // Lazy follow tracer
{
if(dist >= 2*lagdistance)
{
SetOrigin(tracer.pos, true);
chasingtracer = false;
}
else if(dist > lagdistance && !chasingtracer) chasingtracer = true;
if(chasingtracer)
{
speed = tracer.vel.xy.length()/dist;
if((speed == 0.0) && (chasemode == 0)) speed = tracer.speed/dist;
SetOrigin(pos + 2*distvec*speed, true);
if(chasemode > 1) chasingtracer = false;
}
}
}
else if(player != NULL && player.mo != NULL)
{
cameraFOV = player.FOV;
SetOrigin(player.mo.pos, true);
}
}
}

View file

@ -420,6 +420,9 @@ enum EViewPosFlags
{
VPSF_ABSOLUTEOFFSET = 1 << 1, // Don't include angles.
VPSF_ABSOLUTEPOS = 1 << 2, // Use absolute position.
VPSF_ALLOWOUTOFBOUNDS = 1 << 3, // Allow viewpoint to go out of bounds (hardware renderer only).
VPSF_ORTHOGRAPHIC = 1 << 4, // Use orthographic projection.
VPSF_ISOMETRICSPRITES = 1 << 5, // Displace sprites towards camera and don't billboard (drawn from isometric perspective).
};
// Flags for A_TakeInventory and A_TakeFromTarget