- floatified the global view variables.

The software renderer still uses internal copies of the fixed point version.
This commit is contained in:
Christoph Oelckers 2016-04-01 12:22:16 +02:00
parent a5e14425aa
commit 8680391e0b
14 changed files with 142 additions and 168 deletions

View file

@ -1953,13 +1953,13 @@ void AM_drawSubsectors()
double secx; double secx;
double secy; double secy;
double seczb, seczt; double seczb, seczt;
double cmpz = FIXED2DBL(viewz); double cmpz = ViewPos.Z;
if (players[consoleplayer].camera && sec == players[consoleplayer].camera->Sector) if (players[consoleplayer].camera && sec == players[consoleplayer].camera->Sector)
{ {
// For the actual camera sector use the current viewpoint as reference. // For the actual camera sector use the current viewpoint as reference.
secx = FIXED2DBL(viewx); secx = ViewPos.X;
secy = FIXED2DBL(viewy); secy = ViewPos.Y;
} }
else else
{ {

View file

@ -156,6 +156,11 @@ inline double AngleToFloat(unsigned f)
return f * (90. / 0x40000000); return f * (90. / 0x40000000);
} }
inline double AngleToFloat(int f)
{
return f * (90. / 0x40000000);
}
#define FLOAT2FIXED(f) FloatToFixed(f) #define FLOAT2FIXED(f) FloatToFixed(f)
#define FIXED2FLOAT(f) float(FixedToFloat(f)) #define FIXED2FLOAT(f) float(FixedToFloat(f))
#define FIXED2DBL(f) FixedToFloat(f) #define FIXED2DBL(f) FixedToFloat(f)

View file

@ -692,7 +692,7 @@ void P_DrawRailTrail(AActor *source, const DVector3 &start, const DVector3 &end,
point = start + r * dir; point = start + r * dir;
dir.Z = dirz; dir.Z = dirz;
S_Sound (DVector3(point.X, point.Y, viewz), CHAN_WEAPON, sound, 1, ATTN_NORM); S_Sound (DVector3(point.X, point.Y, ViewPos.Z), CHAN_WEAPON, sound, 1, ATTN_NORM);
} }
} }
} }

View file

@ -38,12 +38,12 @@ struct intercept_t
inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line) inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line)
{ {
return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > -EQUAL_EPSILON; return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON;
} }
inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line) inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line)
{ {
return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > -EQUAL_EPSILON; return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON;
} }
inline int P_PointOnLineSide (double x, double y, const line_t *line) inline int P_PointOnLineSide (double x, double y, const line_t *line)
@ -73,12 +73,12 @@ inline int P_PointOnLineSide(const DVector2 & p, const line_t *line)
inline int P_PointOnDivlineSide(double x, double y, const divline_t *line) inline int P_PointOnDivlineSide(double x, double y, const divline_t *line)
{ {
return (y - line->y) * line->dx + (line->x - x) * line->dy > -EQUAL_EPSILON; return (y - line->y) * line->dx + (line->x - x) * line->dy > EQUAL_EPSILON;
} }
inline int P_PointOnDivlineSide(const DVector2 &pos, const divline_t *line) inline int P_PointOnDivlineSide(const DVector2 &pos, const divline_t *line)
{ {
return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > -EQUAL_EPSILON; return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > EQUAL_EPSILON;
} }
//========================================================================== //==========================================================================

View file

@ -180,10 +180,10 @@ static int DoomSpecificInfo (char *buffer, char *end)
} }
else else
{ {
p += snprintf (buffer+p, size-p, "\n\nviewx = %d", (int)viewx); p += snprintf (buffer+p, size-p, "\n\nviewx = %f", ViewPos.X);
p += snprintf (buffer+p, size-p, "\nviewy = %d", (int)viewy); p += snprintf (buffer+p, size-p, "\nviewy = %f", ViewPos.Y);
p += snprintf (buffer+p, size-p, "\nviewz = %d", (int)viewz); p += snprintf (buffer+p, size-p, "\nviewz = %f", ViewPos.Z);
p += snprintf (buffer+p, size-p, "\nviewangle = %x", (unsigned int)viewangle); p += snprintf (buffer+p, size-p, "\nviewangle = %f", ViewAngle.Degrees);
} }
} }
buffer[p++] = '\n'; buffer[p++] = '\n';

View file

@ -38,6 +38,7 @@
#include "p_lnspec.h" #include "p_lnspec.h"
#include "p_setup.h" #include "p_setup.h"
#include "r_local.h"
#include "r_main.h" #include "r_main.h"
#include "r_plane.h" #include "r_plane.h"
#include "r_draw.h" #include "r_draw.h"

View file

@ -352,6 +352,12 @@ public:
return TMulScale16(a,x, b,y, c,z) + d; return TMulScale16(a,x, b,y, c,z) + d;
} }
int PointOnSide(const DVector3 &pos) const
{
double v = a * pos.X + b * pos.Y + c * pos.Z;
return v < -EQUAL_EPSILON ? -1 : v > EQUAL_EPSILON ? 1 : 0;
}
// Returns the value of z at (0,0) This is used by the 3D floor code which does not handle slopes // Returns the value of z at (0,0) This is used by the 3D floor code which does not handle slopes
fixed_t Zat0 () const fixed_t Zat0 () const
{ {
@ -375,6 +381,13 @@ public:
return (d + a*pos.X + b*pos.Y) * ic / (-65536.0 * 65536.0); return (d + a*pos.X + b*pos.Y) * ic / (-65536.0 * 65536.0);
} }
// This is for the software renderer
fixed_t ZatPointFixed(const DVector2 &pos) const
{
return xs_CRoundToInt((d + a*pos.X + b*pos.Y) * ic / (-65536.0));
}
double ZatPoint(const vertex_t *v) const double ZatPoint(const vertex_t *v) const
{ {
return FIXED2DBL(FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY()))); return FIXED2DBL(FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY())));

View file

@ -38,4 +38,8 @@
#include "r_things.h" #include "r_things.h"
#include "r_draw.h" #include "r_draw.h"
extern fixed_t viewx, viewy, viewz;
extern angle_t viewangle;
extern int viewpitch;
#endif // __R_LOCAL_H__ #endif // __R_LOCAL_H__

View file

@ -68,6 +68,10 @@
#define TEST_ANGLE 2468347904 #define TEST_ANGLE 2468347904
#endif #endif
fixed_t viewx, viewy, viewz;
angle_t viewangle;
int viewpitch;
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
@ -550,6 +554,12 @@ void R_SetupColormap(player_t *player)
void R_SetupFreelook() void R_SetupFreelook()
{ {
viewx = FLOAT2FIXED(ViewPos.X);
viewy = FLOAT2FIXED(ViewPos.Y);
viewz = FLOAT2FIXED(ViewPos.Z);
viewangle = ViewAngle.BAMs();
viewpitch = ViewPitch.BAMs();
{ {
fixed_t dy; fixed_t dy;
@ -727,6 +737,7 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
viewx = FLOAT2FIXED((x1 + r * dx)*2 - x); viewx = FLOAT2FIXED((x1 + r * dx)*2 - x);
viewy = FLOAT2FIXED((y1 + r * dy)*2 - y); viewy = FLOAT2FIXED((y1 + r * dy)*2 - y);
} }
ViewAngle = pds->src->Delta().Angle();
viewangle = 2*R_PointToAngle2 (pds->src->v1->fixX(), pds->src->v1->fixY(), viewangle = 2*R_PointToAngle2 (pds->src->v1->fixX(), pds->src->v1->fixY(),
pds->src->v2->fixX(), pds->src->v2->fixY()) - startang; pds->src->v2->fixX(), pds->src->v2->fixY()) - startang;
@ -743,6 +754,7 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
viewz = FLOAT2FIXED(view.Z); viewz = FLOAT2FIXED(view.Z);
viewangle = va.BAMs(); viewangle = va.BAMs();
} }
ViewAngle = AngleToFloat(viewangle);
viewsin = finesine[viewangle>>ANGLETOFINESHIFT]; viewsin = finesine[viewangle>>ANGLETOFINESHIFT];
viewcos = finecosine[viewangle>>ANGLETOFINESHIFT]; viewcos = finecosine[viewangle>>ANGLETOFINESHIFT];
@ -821,6 +833,7 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
viewx = startx; viewx = startx;
viewy = starty; viewy = starty;
viewz = startz; viewz = startz;
ViewAngle = AngleToFloat(viewangle);
} }
//========================================================================== //==========================================================================

View file

@ -1082,6 +1082,7 @@ void R_DrawHeightPlanes(fixed_t height)
viewy = pl->viewy; viewy = pl->viewy;
viewz = pl->viewz; viewz = pl->viewz;
viewangle = pl->viewangle; viewangle = pl->viewangle;
ViewAngle = AngleToFloat(viewangle);
MirrorFlags = pl->MirrorFlags; MirrorFlags = pl->MirrorFlags;
R_DrawSinglePlane (pl, pl->sky & 0x7FFFFFFF, pl->Additive, true); R_DrawSinglePlane (pl, pl->sky & 0x7FFFFFFF, pl->Additive, true);
} }
@ -1092,6 +1093,7 @@ void R_DrawHeightPlanes(fixed_t height)
viewy = oViewY; viewy = oViewY;
viewz = oViewZ; viewz = oViewZ;
viewangle = oViewAngle; viewangle = oViewAngle;
ViewAngle = AngleToFloat(viewangle);
} }
@ -1248,11 +1250,12 @@ void R_DrawSkyBoxes ()
{ {
extralight = pl->extralight; extralight = pl->extralight;
R_SetVisibility (pl->visibility); R_SetVisibility (pl->visibility);
viewx = pl->viewx - FLOAT2FIXED(sky->Mate->X() + sky->X()); viewx = pl->viewx + FLOAT2FIXED(-sky->Mate->X() + sky->X());
viewy = pl->viewy - FLOAT2FIXED(sky->Mate->Y() + sky->Y()); viewy = pl->viewy + FLOAT2FIXED(-sky->Mate->Y() + sky->Y());
viewz = pl->viewz; viewz = pl->viewz;
viewangle = pl->viewangle; viewangle = pl->viewangle;
} }
ViewAngle = AngleToFloat(viewangle);
sky->bInSkybox = true; sky->bInSkybox = true;
if (mate != NULL) mate->bInSkybox = true; if (mate != NULL) mate->bInSkybox = true;
@ -1367,6 +1370,7 @@ void R_DrawSkyBoxes ()
R_SetVisibility (savedvisibility); R_SetVisibility (savedvisibility);
extralight = savedextralight; extralight = savedextralight;
viewangle = savedangle; viewangle = savedangle;
ViewAngle = AngleToFloat(viewangle);
R_SetViewAngle (); R_SetViewAngle ();
CurrentPortalInSkybox = false; CurrentPortalInSkybox = false;

View file

@ -802,7 +802,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
{ {
// choose a different rotation based on player view // choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[tex->Rotations]; spriteframe_t *sprframe = &SpriteFrames[tex->Rotations];
angle_t ang = R_PointToAngle (fx, fy); angle_t ang = R_PointToAngle2 (viewx, viewy, fx, fy);
angle_t rot; angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1]) if (sprframe->Texture[0] == sprframe->Texture[1])
{ {
@ -841,7 +841,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
//picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0];
// choose a different rotation based on player view // choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame];
angle_t ang = R_PointToAngle (fx, fy); angle_t ang = R_PointToAngle2 (viewx, viewy, fx, fy);
angle_t rot; angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1]) if (sprframe->Texture[0] == sprframe->Texture[1])
{ {

View file

@ -70,12 +70,15 @@ EXTERN_CVAR (Bool, cl_capfps)
struct InterpolationViewer struct InterpolationViewer
{ {
struct instance
{
DVector3 Pos;
DRotator Angles;
};
AActor *ViewActor; AActor *ViewActor;
int otic; int otic;
fixed_t oviewx, oviewy, oviewz; instance Old, New;
fixed_t nviewx, nviewy, nviewz;
int oviewpitch, nviewpitch;
angle_t oviewangle, nviewangle;
}; };
// PRIVATE DATA DECLARATIONS ----------------------------------------------- // PRIVATE DATA DECLARATIONS -----------------------------------------------
@ -102,11 +105,9 @@ DCanvas *RenderTarget; // [RH] canvas to render to
int viewwindowx; int viewwindowx;
int viewwindowy; int viewwindowy;
fixed_t viewx; DVector3 ViewPos;
fixed_t viewy; DAngle ViewAngle;
fixed_t viewz; DAngle ViewPitch;
int viewpitch;
angle_t viewangle;
extern "C" extern "C"
{ {
@ -574,27 +575,20 @@ EXTERN_CVAR (Bool, cl_noprediction)
void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *iview) void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *iview)
{ {
fixed_t frac = FLOAT2FIXED(Frac);
if (NoInterpolateView) if (NoInterpolateView)
{ {
InterpolationPath.Clear(); InterpolationPath.Clear();
NoInterpolateView = false; NoInterpolateView = false;
iview->oviewx = iview->nviewx; iview->Old = iview->New;
iview->oviewy = iview->nviewy;
iview->oviewz = iview->nviewz;
iview->oviewpitch = iview->nviewpitch;
iview->oviewangle = iview->nviewangle;
} }
int oldgroup = R_PointInSubsector(iview->oviewx, iview->oviewy)->sector->PortalGroup; int oldgroup = R_PointInSubsector(iview->Old.Pos)->sector->PortalGroup;
int newgroup = R_PointInSubsector(iview->nviewx, iview->nviewy)->sector->PortalGroup; int newgroup = R_PointInSubsector(iview->New.Pos)->sector->PortalGroup;
fixed_t oviewangle = iview->oviewangle; DAngle oviewangle = iview->Old.Angles.Yaw;
fixed_t nviewangle = iview->nviewangle; DAngle nviewangle = iview->New.Angles.Yaw;
if ((iview->oviewx != iview->nviewx || iview->oviewy != iview->nviewy) && InterpolationPath.Size() > 0) if ((iview->Old.Pos.X != iview->New.Pos.X || iview->Old.Pos.Y != iview->New.Pos.Y) && InterpolationPath.Size() > 0)
{ {
viewx = iview->nviewx; DVector3 view = iview->New.Pos;
viewy = iview->nviewy;
viewz = iview->nviewz;
// Interpolating through line portals is a messy affair. // Interpolating through line portals is a messy affair.
// What needs be done is to store the portal transitions of the camera actor as waypoints // What needs be done is to store the portal transitions of the camera actor as waypoints
@ -602,49 +596,47 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie
// Needless to say, this doesn't work for chasecam mode. // Needless to say, this doesn't work for chasecam mode.
if (!r_showviewer) if (!r_showviewer)
{ {
fixed_t pathlen = 0; double pathlen = 0;
fixed_t zdiff = 0; double zdiff = 0;
fixed_t totalzdiff = 0; double totalzdiff = 0;
angle_t adiff = 0; DAngle adiff = 0.;
angle_t totaladiff = 0; DAngle totaladiff = 0.;
fixed_t oviewz = iview->oviewz; double oviewz = iview->Old.Pos.Z;
fixed_t nviewz = iview->nviewz; double nviewz = iview->New.Pos.Z;
DVector3a oldpos = { {FIXED2DBL(iview->oviewx), FIXED2DBL(iview->oviewy), 0.}, 0. }; DVector3a oldpos = { { iview->Old.Pos.X, iview->Old.Pos.Y, 0 }, 0. };
DVector3a newpos = { {FIXED2DBL(iview->nviewx), FIXED2DBL(iview->nviewy), 0. }, 0. }; DVector3a newpos = { { iview->New.Pos.X, iview->New.Pos.Y, 0 }, 0. };
InterpolationPath.Push(newpos); // add this to the array to simplify the loops below InterpolationPath.Push(newpos); // add this to the array to simplify the loops below
for (unsigned i = 0; i < InterpolationPath.Size(); i += 2) for (unsigned i = 0; i < InterpolationPath.Size(); i += 2)
{ {
DVector3a &start = i == 0 ? oldpos : InterpolationPath[i - 1]; DVector3a &start = i == 0 ? oldpos : InterpolationPath[i - 1];
DVector3a &end = InterpolationPath[i]; DVector3a &end = InterpolationPath[i];
pathlen += FLOAT2FIXED((end.pos-start.pos).Length()); pathlen += (end.pos-start.pos).Length();
totalzdiff += FLOAT2FIXED(start.pos.Z); totalzdiff += start.pos.Z;
totaladiff += start.angle.BAMs(); totaladiff += start.angle;
} }
fixed_t interpolatedlen = FixedMul(frac, pathlen); double interpolatedlen = Frac * pathlen;
for (unsigned i = 0; i < InterpolationPath.Size(); i += 2) for (unsigned i = 0; i < InterpolationPath.Size(); i += 2)
{ {
DVector3a &start = i == 0 ? oldpos : InterpolationPath[i - 1]; DVector3a &start = i == 0 ? oldpos : InterpolationPath[i - 1];
DVector3a &end = InterpolationPath[i]; DVector3a &end = InterpolationPath[i];
fixed_t fraglen = FLOAT2FIXED((end.pos - start.pos).Length()); double fraglen = (end.pos - start.pos).Length();
zdiff += FLOAT2FIXED(start.pos.Z); zdiff += start.pos.Z;
adiff += start.angle.BAMs(); adiff += start.angle;
if (fraglen <= interpolatedlen) if (fraglen <= interpolatedlen)
{ {
interpolatedlen -= fraglen; interpolatedlen -= fraglen;
} }
else else
{ {
double fragfrac = FIXED2DBL(FixedDiv(interpolatedlen, fraglen)); double fragfrac = interpolatedlen / fraglen;
oviewz += zdiff; oviewz += zdiff;
nviewz -= totalzdiff - zdiff; nviewz -= totalzdiff - zdiff;
oviewangle += adiff; oviewangle += adiff;
nviewangle -= totaladiff - adiff; nviewangle -= totaladiff - adiff;
DVector2 viewpos = start.pos + (fragfrac * (end.pos - start.pos)); DVector2 viewpos = start.pos + (fragfrac * (end.pos - start.pos));
viewx = FLOAT2FIXED(viewpos.X); ViewPos = { viewpos, oviewz + Frac * (nviewz - oviewz) };
viewy = FLOAT2FIXED(viewpos.Y);
viewz = oviewz + FixedMul(frac, nviewz - oviewz);
break; break;
} }
} }
@ -654,17 +646,15 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie
else else
{ {
DVector2 disp = Displacements.getOffset(oldgroup, newgroup); DVector2 disp = Displacements.getOffset(oldgroup, newgroup);
viewx = iview->oviewx + FixedMul(frac, iview->nviewx - iview->oviewx - FLOAT2FIXED(disp.X)); ViewPos = iview->Old.Pos + (iview->New.Pos - iview->Old.Pos - disp) * Frac;
viewy = iview->oviewy + FixedMul(frac, iview->nviewy - iview->oviewy - FLOAT2FIXED(disp.Y));
viewz = iview->oviewz + FixedMul(frac, iview->nviewz - iview->oviewz);
} }
if (player != NULL && if (player != NULL &&
!(player->cheats & CF_INTERPVIEW) && !(player->cheats & CF_INTERPVIEW) &&
player - players == consoleplayer && player - players == consoleplayer &&
camera == player->mo && camera == player->mo &&
!demoplayback && !demoplayback &&
iview->nviewx == camera->_f_X() && iview->New.Pos.X == camera->X() &&
iview->nviewy == camera->_f_Y() && iview->New.Pos.Y == camera->Y() &&
!(player->cheats & (CF_TOTALLYFROZEN|CF_FROZEN)) && !(player->cheats & (CF_TOTALLYFROZEN|CF_FROZEN)) &&
player->playerstate == PST_LIVE && player->playerstate == PST_LIVE &&
player->mo->reactiontime == 0 && player->mo->reactiontime == 0 &&
@ -673,53 +663,26 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie
(!netgame || !cl_noprediction) && (!netgame || !cl_noprediction) &&
!LocalKeyboardTurner) !LocalKeyboardTurner)
{ {
viewangle = nviewangle + (LocalViewAngle & 0xFFFF0000); ViewAngle = (nviewangle + AngleToFloat(LocalViewAngle & 0xFFFF0000)).Normalized180();
DAngle delta = player->centering ? DAngle(0.) : AngleToFloat(int(LocalViewPitch & 0xFFFF0000));
fixed_t delta = player->centering ? 0 : -(signed)(LocalViewPitch & 0xFFFF0000); ViewPitch = clamp<DAngle>((iview->New.Angles.Pitch - delta).Normalized180(), player->MinPitch, player->MaxPitch);
viewpitch = iview->nviewpitch;
if (delta > 0)
{
// Avoid overflowing viewpitch (can happen when a netgame is stalled)
if (viewpitch > INT_MAX - delta)
{
viewpitch = player->MaxPitch.BAMs();
} }
else else
{ {
viewpitch = MIN<int>(viewpitch + delta, player->MaxPitch.BAMs()); ViewPitch = (iview->Old.Angles.Pitch + (iview->New.Angles.Pitch - iview->Old.Angles.Pitch) * Frac).Normalized180();
} ViewAngle = (oviewangle + (nviewangle - oviewangle) * Frac).Normalized180();
}
else if (delta < 0)
{
// Avoid overflowing viewpitch (can happen when a netgame is stalled)
if (viewpitch < INT_MIN - delta)
{
viewpitch = player->MinPitch.BAMs();
}
else
{
viewpitch = MAX<int>(viewpitch + delta, player->MinPitch.BAMs());
}
}
}
else
{
viewpitch = iview->oviewpitch + FixedMul (frac, iview->nviewpitch - iview->oviewpitch);
viewangle = oviewangle + FixedMul (frac, nviewangle - oviewangle);
} }
// Due to interpolation this is not necessarily the same as the sector the camera is in. // Due to interpolation this is not necessarily the same as the sector the camera is in.
viewsector = R_PointInSubsector(viewx, viewy)->sector; viewsector = R_PointInSubsector(ViewPos)->sector;
bool moved = false; bool moved = false;
while (!viewsector->PortalBlocksMovement(sector_t::ceiling)) while (!viewsector->PortalBlocksMovement(sector_t::ceiling))
{ {
AActor *point = viewsector->SkyBoxes[sector_t::ceiling]; AActor *point = viewsector->SkyBoxes[sector_t::ceiling];
if (viewz > FLOAT2FIXED(point->specialf1)) if (ViewPos.Z > point->specialf1)
{ {
viewx += FLOAT2FIXED(point->Scale.X); ViewPos += point->Scale;
viewy += FLOAT2FIXED(point->Scale.Y); viewsector = R_PointInSubsector(ViewPos)->sector;
viewsector = R_PointInSubsector(viewx, viewy)->sector;
moved = true; moved = true;
} }
else break; else break;
@ -729,11 +692,10 @@ void R_InterpolateView (player_t *player, double Frac, InterpolationViewer *ivie
while (!viewsector->PortalBlocksMovement(sector_t::floor)) while (!viewsector->PortalBlocksMovement(sector_t::floor))
{ {
AActor *point = viewsector->SkyBoxes[sector_t::floor]; AActor *point = viewsector->SkyBoxes[sector_t::floor];
if (viewz < FLOAT2FIXED(point->specialf1)) if (ViewPos.Z < point->specialf1)
{ {
viewx += FLOAT2FIXED(point->Scale.X); ViewPos += point->Scale;
viewy += FLOAT2FIXED(point->Scale.Y); viewsector = R_PointInSubsector(ViewPos)->sector;
viewsector = R_PointInSubsector(viewx, viewy)->sector;
moved = true; moved = true;
} }
else break; else break;
@ -761,10 +723,8 @@ void R_ResetViewInterpolation ()
void R_SetViewAngle () void R_SetViewAngle ()
{ {
angle_t ang = viewangle >> ANGLETOFINESHIFT; viewsin = FLOAT2FIXED(ViewAngle.Sin());
viewcos = FLOAT2FIXED(ViewAngle.Cos());
viewsin = finesine[ang];
viewcos = finecosine[ang];
viewtansin = FixedMul (FocalTangent, viewsin); viewtansin = FixedMul (FocalTangent, viewsin);
viewtancos = FixedMul (FocalTangent, viewcos); viewtancos = FixedMul (FocalTangent, viewcos);
@ -787,7 +747,8 @@ static InterpolationViewer *FindPastViewer (AActor *actor)
} }
// Not found, so make a new one // Not found, so make a new one
InterpolationViewer iview = { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; InterpolationViewer iview;
memset(&iview, 0, sizeof(iview));
iview.ViewActor = actor; iview.ViewActor = actor;
iview.otic = -1; iview.otic = -1;
InterpolationPath.Clear(); InterpolationPath.Clear();
@ -851,11 +812,7 @@ void R_RebuildViewInterpolation(player_t *player)
InterpolationViewer *iview = FindPastViewer(player->camera); InterpolationViewer *iview = FindPastViewer(player->camera);
iview->oviewx = iview->nviewx; iview->Old = iview->New;
iview->oviewy = iview->nviewy;
iview->oviewz = iview->nviewz;
iview->oviewpitch = iview->nviewpitch;
iview->oviewangle = iview->nviewangle;
InterpolationPath.Clear(); InterpolationPath.Clear();
} }
@ -955,52 +912,39 @@ void R_SetupFrame (AActor *actor)
if (iview->otic != -1 && nowtic > iview->otic) if (iview->otic != -1 && nowtic > iview->otic)
{ {
iview->otic = nowtic; iview->otic = nowtic;
iview->oviewx = iview->nviewx; iview->Old = iview->New;
iview->oviewy = iview->nviewy;
iview->oviewz = iview->nviewz;
iview->oviewpitch = iview->nviewpitch;
iview->oviewangle = iview->nviewangle;
} }
if (player != NULL && gamestate != GS_TITLELEVEL && if (player != NULL && gamestate != GS_TITLELEVEL &&
((player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0))) ((player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)))
{ {
sector_t *oldsector = R_PointInSubsector(iview->oviewx, iview->oviewy)->sector; sector_t *oldsector = R_PointInSubsector(iview->Old.Pos)->sector;
// [RH] Use chasecam view // [RH] Use chasecam view
DVector3 campos; DVector3 campos;
P_AimCamera (camera, campos, viewsector, unlinked); P_AimCamera (camera, campos, viewsector, unlinked); // fixme: This needs to translate the angle, too.
iview->nviewx = FLOAT2FIXED(campos.X); iview->New.Pos = campos;
iview->nviewy = FLOAT2FIXED(campos.Y);
iview->nviewz = FLOAT2FIXED(campos.Z);
r_showviewer = true; r_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 // 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. // it's probably best to just reset the interpolation for this move.
// Note that this can still cause problems with unusually linked portals // Note that this can still cause problems with unusually linked portals
if (viewsector->PortalGroup != oldsector->PortalGroup || (unlinked && P_AproxDistance(iview->oviewx - iview->nviewx, iview->oviewy - iview->nviewy) > 256 * FRACUNIT)) if (viewsector->PortalGroup != oldsector->PortalGroup || (unlinked && ((iview->New.Pos.XY() - iview->Old.Pos.XY()).LengthSquared()) > 256*256))
{ {
iview->otic = nowtic; iview->otic = nowtic;
iview->oviewx = iview->nviewx; iview->Old = iview->New;
iview->oviewy = iview->nviewy;
iview->oviewz = iview->nviewz;
iview->oviewpitch = iview->nviewpitch;
iview->oviewangle = iview->nviewangle;
} }
} }
else else
{ {
iview->nviewx = camera->_f_X(); iview->New.Pos = { camera->Pos().XY(), camera->player ? camera->player->viewz : camera->Z() + camera->GetCameraHeight() };
iview->nviewy = camera->_f_Y();
iview->nviewz = FLOAT2FIXED(camera->player ? camera->player->viewz : camera->Z() + camera->GetCameraHeight());
viewsector = camera->Sector; viewsector = camera->Sector;
r_showviewer = false; r_showviewer = false;
} }
iview->nviewpitch = camera->Angles.Pitch.BAMs(); iview->New.Angles = camera->Angles;
if (camera->player != 0) if (camera->player != 0)
{ {
player = camera->player; player = camera->player;
} }
iview->nviewangle = camera->Angles.Yaw.BAMs();
if (iview->otic == -1 || r_NoInterpolate) if (iview->otic == -1 || r_NoInterpolate)
{ {
R_ResetViewInterpolation (); R_ResetViewInterpolation ();
@ -1014,13 +958,6 @@ void R_SetupFrame (AActor *actor)
} }
R_InterpolateView (player, r_TicFracF, iview); R_InterpolateView (player, r_TicFracF, iview);
#ifdef TEST_X
viewx = TEST_X;
viewy = TEST_Y;
viewz = TEST_Z;
viewangle = TEST_ANGLE;
#endif
R_SetViewAngle (); R_SetViewAngle ();
interpolator.DoInterpolations (r_TicFracF); interpolator.DoInterpolations (r_TicFracF);
@ -1028,19 +965,19 @@ void R_SetupFrame (AActor *actor)
// Keep the view within the sector's floor and ceiling // Keep the view within the sector's floor and ceiling
if (viewsector->PortalBlocksMovement(sector_t::ceiling)) if (viewsector->PortalBlocksMovement(sector_t::ceiling))
{ {
fixed_t theZ = viewsector->ceilingplane.ZatPoint(viewx, viewy) - 4 * FRACUNIT; double theZ = viewsector->ceilingplane.ZatPoint(ViewPos) - 4;
if (viewz > theZ) if (ViewPos.Z > theZ)
{ {
viewz = theZ; ViewPos.Z = theZ;
} }
} }
if (viewsector->PortalBlocksMovement(sector_t::floor)) if (viewsector->PortalBlocksMovement(sector_t::floor))
{ {
fixed_t theZ = viewsector->floorplane.ZatPoint(viewx, viewy) + 4 * FRACUNIT; double theZ = viewsector->floorplane.ZatPoint(ViewPos) + 4;
if (viewz < theZ) if (ViewPos.Z < theZ)
{ {
viewz = theZ; ViewPos.Z = theZ;
} }
} }
@ -1058,32 +995,30 @@ void R_SetupFrame (AActor *actor)
{ {
an = camera->Angles.Yaw; an = camera->Angles.Yaw;
double power = QuakePower(quakefactor, jiggers.RelIntensity.X, jiggers.RelOffset.X, jiggers.Falloff, jiggers.WFalloff); double power = QuakePower(quakefactor, jiggers.RelIntensity.X, jiggers.RelOffset.X, jiggers.Falloff, jiggers.WFalloff);
viewx += FLOAT2FIXED(an.Cos() * power); ViewPos += an.ToVector(power);
viewy += FLOAT2FIXED(an.Sin() * power);
} }
if (jiggers.RelIntensity.Y != 0 || jiggers.RelOffset.Y != 0) if (jiggers.RelIntensity.Y != 0 || jiggers.RelOffset.Y != 0)
{ {
an = camera->Angles.Yaw + 90; an = camera->Angles.Yaw + 90;
double power = QuakePower(quakefactor, jiggers.RelIntensity.Y, jiggers.RelOffset.Y, jiggers.Falloff, jiggers.WFalloff); double power = QuakePower(quakefactor, jiggers.RelIntensity.Y, jiggers.RelOffset.Y, jiggers.Falloff, jiggers.WFalloff);
viewx += FLOAT2FIXED(an.Cos() * power); ViewPos += an.ToVector(power);
viewy += FLOAT2FIXED(an.Sin() * power);
} }
// FIXME: Relative Z is not relative // FIXME: Relative Z is not relative
if (jiggers.RelIntensity.Z != 0 || jiggers.RelOffset.Z != 0) if (jiggers.RelIntensity.Z != 0 || jiggers.RelOffset.Z != 0)
{ {
viewz += FLOAT2FIXED(QuakePower(quakefactor, jiggers.RelIntensity.Z, jiggers.RelOffset.Z, jiggers.Falloff, jiggers.WFalloff)); ViewPos.Z += QuakePower(quakefactor, jiggers.RelIntensity.Z, jiggers.RelOffset.Z, jiggers.Falloff, jiggers.WFalloff);
} }
if (jiggers.Intensity.X != 0 || jiggers.Offset.X != 0) if (jiggers.Intensity.X != 0 || jiggers.Offset.X != 0)
{ {
viewx += FLOAT2FIXED(QuakePower(quakefactor, jiggers.Intensity.X, jiggers.Offset.X, jiggers.Falloff, jiggers.WFalloff)); ViewPos.Z += QuakePower(quakefactor, jiggers.Intensity.X, jiggers.Offset.X, jiggers.Falloff, jiggers.WFalloff);
} }
if (jiggers.Intensity.Y != 0 || jiggers.Offset.Y != 0) if (jiggers.Intensity.Y != 0 || jiggers.Offset.Y != 0)
{ {
viewy += FLOAT2FIXED(QuakePower(quakefactor, jiggers.Intensity.Y, jiggers.Offset.Y, jiggers.Falloff, jiggers.WFalloff)); ViewPos.Z += QuakePower(quakefactor, jiggers.Intensity.Y, jiggers.Offset.Y, jiggers.Falloff, jiggers.WFalloff);
} }
if (jiggers.Intensity.Z != 0 || jiggers.Offset.Z != 0) if (jiggers.Intensity.Z != 0 || jiggers.Offset.Z != 0)
{ {
viewz += FLOAT2FIXED(QuakePower(quakefactor, jiggers.Intensity.Z, jiggers.Offset.Z, jiggers.Falloff, jiggers.WFalloff)); ViewPos.Z += QuakePower(quakefactor, jiggers.Intensity.Z, jiggers.Offset.Z, jiggers.Falloff, jiggers.WFalloff);
} }
} }
} }
@ -1102,7 +1037,7 @@ void R_SetupFrame (AActor *actor)
secplane_t *plane; secplane_t *plane;
int viewside; int viewside;
plane = (i < lightlist.Size()-1) ? &lightlist[i+1].plane : &viewsector->floorplane; plane = (i < lightlist.Size()-1) ? &lightlist[i+1].plane : &viewsector->floorplane;
viewside = plane->PointOnSide(viewx, viewy, viewz); viewside = plane->PointOnSide(ViewPos);
// Reverse the direction of the test if the plane was downward facing. // 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. // We want to know if the view is above it, whatever its orientation may be.
if (plane->fC() < 0) if (plane->fC() < 0)
@ -1124,9 +1059,9 @@ void R_SetupFrame (AActor *actor)
const sector_t *s = viewsector->GetHeightSec(); const sector_t *s = viewsector->GetHeightSec();
if (s != NULL) if (s != NULL)
{ {
newblend = s->floorplane.PointOnSide(viewx, viewy, viewz) < 0 newblend = s->floorplane.PointOnSide(ViewPos) < 0
? s->bottommap ? s->bottommap
: s->ceilingplane.PointOnSide(viewx, viewy, viewz) < 0 : s->ceilingplane.PointOnSide(ViewPos) < 0
? s->topmap ? s->topmap
: s->midmap; : s->midmap;
if (APART(newblend) == 0 && newblend >= numfakecmaps) if (APART(newblend) == 0 && newblend >= numfakecmaps)

View file

@ -2,6 +2,7 @@
#define __R_UTIL_H #define __R_UTIL_H
#include "r_state.h" #include "r_state.h"
#include "vectors.h"
// //
// Stuff from r_main.h that's needed outside the rendering code. // Stuff from r_main.h that's needed outside the rendering code.
@ -11,10 +12,9 @@
extern DCanvas *RenderTarget; extern DCanvas *RenderTarget;
extern fixed_t viewx; extern DVector3 ViewPos;
extern fixed_t viewy; extern DAngle ViewAngle;
extern fixed_t viewz; extern DAngle ViewPitch;
extern int viewpitch;
extern "C" int centerx, centerxwide; extern "C" int centerx, centerxwide;
extern "C" int centery; extern "C" int centery;
@ -65,7 +65,6 @@ inline int R_PointOnSide(const DVector2 &pos, const node_t *node)
} }
angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2);
inline angle_t R_PointToAngle (fixed_t x, fixed_t y) { return R_PointToAngle2 (viewx, viewy, x, y); }
inline angle_t R_PointToAnglePrecise (fixed_t viewx, fixed_t viewy, fixed_t x, fixed_t y) inline angle_t R_PointToAnglePrecise (fixed_t viewx, fixed_t viewy, fixed_t x, fixed_t y)
{ {
return xs_RoundToUInt(g_atan2(double(y-viewy), double(x-viewx)) * (ANGLE_180/M_PI)); return xs_RoundToUInt(g_atan2(double(y-viewy), double(x-viewx)) * (ANGLE_180/M_PI));

View file

@ -1080,10 +1080,10 @@ void DoomSpecificInfo (char *buffer, size_t bufflen)
} }
else else
{ {
buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %d", viewx); buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", ViewPos.X);
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %d", viewy); buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", ViewPos.Y);
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %d", viewz); buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", ViewPos.Z);
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %x", viewangle); buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", ViewAngle);
} }
} }
*buffer++ = '\r'; *buffer++ = '\r';