mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-19 07:01:09 +00:00
- Floatify chase cam code, providing an inline interface for legacy setup.
This commit is contained in:
parent
977d8f8109
commit
056bb9b0cd
2 changed files with 45 additions and 48 deletions
|
@ -34,58 +34,52 @@ IntRect viewport3d;
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
int cameradist, cameraclock;
|
double cameradist, cameraclock;
|
||||||
|
|
||||||
bool calcChaseCamPos(int* px, int* py, int* pz, DCoreActor* act, sectortype** psect, DAngle ang, fixedhoriz horiz, double const smoothratio)
|
bool calcChaseCamPos(DVector3& ppos, DCoreActor* act, sectortype** psect, DAngle ang, fixedhoriz horiz, double const smoothratio)
|
||||||
{
|
{
|
||||||
HitInfoBase hitinfo;
|
HitInfoBase hitinfo;
|
||||||
DAngle daang;
|
DAngle daang;
|
||||||
int newdist;
|
double newdist;
|
||||||
|
|
||||||
if (!*psect) return false;
|
if (!*psect) return false;
|
||||||
// Calculate new pos to shoot backwards, using averaged values from the big three.
|
|
||||||
|
// Calculate new pos to shoot backwards
|
||||||
DVector3 npos = gi->chaseCamPos(ang, horiz);
|
DVector3 npos = gi->chaseCamPos(ang, horiz);
|
||||||
vec3_t np = {int(npos.X * worldtoint), int(npos.Y * worldtoint), int(npos.Z * zworldtoint)};
|
|
||||||
|
|
||||||
auto bakcstat = act->spr.cstat;
|
auto bakcstat = act->spr.cstat;
|
||||||
act->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
|
act->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
|
||||||
updatesectorz(*px, *py, *pz, psect);
|
updatesectorz(ppos, psect);
|
||||||
hitscan(vec3_t( *px, *py, *pz ), *psect, np, hitinfo, CLIPMASK1);
|
hitscan(ppos, *psect, npos, hitinfo, CLIPMASK1);
|
||||||
act->spr.cstat = bakcstat;
|
act->spr.cstat = bakcstat;
|
||||||
|
auto hpos = hitinfo.hitpos.XY() - ppos.XY();
|
||||||
|
|
||||||
int hx = hitinfo.int_hitpos().X - *px;
|
if (!*psect) return false;
|
||||||
int hy = hitinfo.int_hitpos().Y - *py;
|
|
||||||
|
|
||||||
if (*psect == nullptr)
|
// If something is in the way, make cameradist lower if necessary
|
||||||
{
|
if (fabs(npos.X) + fabs(npos.Y) > fabs(hpos.X) + fabs(hpos.Y))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If something is in the way, make pp->camera_dist lower if necessary
|
|
||||||
if (abs(np.X) + abs(np.Y) > abs(hx) + abs(hy))
|
|
||||||
{
|
{
|
||||||
if (hitinfo.hitWall != nullptr)
|
if (hitinfo.hitWall != nullptr)
|
||||||
{
|
{
|
||||||
// Push you a little bit off the wall
|
// Push you a little bit off the wall
|
||||||
*psect = hitinfo.hitSector;
|
*psect = hitinfo.hitSector;
|
||||||
daang = VecToAngle(hitinfo.hitWall->point2Wall()->pos.X - hitinfo.hitWall->pos.X,
|
daang = (hitinfo.hitWall->point2Wall()->pos - hitinfo.hitWall->pos).Angle();
|
||||||
hitinfo.hitWall->point2Wall()->pos.Y - hitinfo.hitWall->pos.Y);
|
newdist = (npos.X * daang.Sin() + npos.Y * -daang.Cos()) * (1. / 1024.);
|
||||||
newdist = int(np.X * daang.Sin() * (1 << BUILDSINBITS) + np.Y * -daang.Cos() * (1 << BUILDSINBITS));
|
|
||||||
|
|
||||||
if (abs(np.X) > abs(np.Y))
|
if (fabs(npos.X) > fabs(npos.Y))
|
||||||
hx -= MulScale(np.X, newdist, 28);
|
hpos.X -= npos.X * newdist;
|
||||||
else
|
else
|
||||||
hy -= MulScale(np.Y, newdist, 28);
|
hpos.Y -= npos.Y * newdist;
|
||||||
}
|
}
|
||||||
else if (hitinfo.hitActor == nullptr)
|
else if (hitinfo.hitActor == nullptr)
|
||||||
{
|
{
|
||||||
// Push you off the ceiling/floor
|
// Push you off the ceiling/floor
|
||||||
*psect = hitinfo.hitSector;
|
*psect = hitinfo.hitSector;
|
||||||
|
|
||||||
if (abs(np.X) > abs(np.Y))
|
if (fabs(npos.X) > fabs(npos.Y))
|
||||||
hx -= (np.X >> 5);
|
hpos.X -= npos.X * (1. / 32.);
|
||||||
else
|
else
|
||||||
hy -= (np.Y >> 5);
|
hpos.Y -= npos.Y * (1. / 32.);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -96,7 +90,7 @@ bool calcChaseCamPos(int* px, int* py, int* pz, DCoreActor* act, sectortype** ps
|
||||||
{
|
{
|
||||||
bakcstat = hit->spr.cstat;
|
bakcstat = hit->spr.cstat;
|
||||||
hit->spr.cstat &= ~(CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN);
|
hit->spr.cstat &= ~(CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN);
|
||||||
calcChaseCamPos(px, py, pz, act, psect, ang, horiz, smoothratio);
|
calcChaseCamPos(ppos, act, psect, ang, horiz, smoothratio);
|
||||||
hit->spr.cstat = bakcstat;
|
hit->spr.cstat = bakcstat;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -104,43 +98,36 @@ bool calcChaseCamPos(int* px, int* py, int* pz, DCoreActor* act, sectortype** ps
|
||||||
{
|
{
|
||||||
// same as wall calculation.
|
// same as wall calculation.
|
||||||
daang = act->spr.angle - DAngle90;
|
daang = act->spr.angle - DAngle90;
|
||||||
newdist = int(np.X * daang.Sin() * (1 << BUILDSINBITS) + np.Y * -daang.Cos() * (1 << BUILDSINBITS));
|
newdist = (npos.X * daang.Sin() + npos.Y * -daang.Cos()) * (1. / 1024.);
|
||||||
|
|
||||||
if (abs(np.X) > abs(np.Y))
|
if (fabs(npos.X) > fabs(npos.Y))
|
||||||
hx -= MulScale(np.X, newdist, 28);
|
hpos.X -= npos.X * newdist;
|
||||||
else
|
else
|
||||||
hy -= MulScale(np.Y, newdist, 28);
|
hpos.Y -= npos.Y * newdist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abs(np.X) > abs(np.Y))
|
newdist = fabs(npos.X) > fabs(npos.Y) ? hpos.X / npos.X : hpos.Y / npos.Y;
|
||||||
newdist = DivScale(hx, np.X, 16);
|
if (newdist < cameradist) cameradist = newdist;
|
||||||
else
|
|
||||||
newdist = DivScale(hy, np.Y, 16);
|
|
||||||
|
|
||||||
if (newdist < cameradist)
|
|
||||||
cameradist = newdist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actually move you! (Camerdist is 65536 if nothing is in the way)
|
// Actually move you! (camerdist is 1 if nothing is in the way)
|
||||||
*px += MulScale(np.X, cameradist, 16);
|
ppos += npos * cameradist;
|
||||||
*py += MulScale(np.Y, cameradist, 16);
|
|
||||||
*pz += MulScale(np.Z, cameradist, 16);
|
|
||||||
|
|
||||||
// Caculate clock using GameTicRate so it increases the same rate on all speed computers.
|
// Calculate clock using GameTicRate so it increases the same rate on all speed computers.
|
||||||
int myclock = PlayClock + MulScale(120 / GameTicRate, int(smoothratio), 16);
|
double myclock = PlayClock + 120 / GameTicRate * smoothratio * (1. / MaxSmoothRatio);
|
||||||
if (cameraclock == INT_MIN)
|
if (cameraclock == INT_MIN)
|
||||||
{
|
{
|
||||||
// Third person view was just started.
|
// Third person view was just started.
|
||||||
cameraclock = myclock;
|
cameraclock = myclock;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slowly increase cameradist until it reaches 65536.
|
// Slowly increase cameradist until it reaches 1.
|
||||||
cameradist = min(cameradist + ((myclock - cameraclock) << 10), 65536);
|
cameradist = min(cameradist + ((myclock - cameraclock) * (1. / 64.)), 1.);
|
||||||
cameraclock = myclock;
|
cameraclock = myclock;
|
||||||
|
|
||||||
// Make sure psectnum is correct.
|
// Make sure psectnum is correct.
|
||||||
updatesectorz(*px, *py, *pz, psect);
|
updatesectorz(ppos, psect);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,11 +252,21 @@ inline constexpr int getincangle(unsigned a, unsigned na)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int cameradist, cameraclock;
|
extern double cameradist, cameraclock;
|
||||||
|
|
||||||
void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false);
|
void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false);
|
||||||
|
|
||||||
bool calcChaseCamPos(int* px, int* py, int* pz, DCoreActor* pspr, sectortype** psectnum, DAngle ang, fixedhoriz horiz, double const smoothratio);
|
bool calcChaseCamPos(DVector3& ppos, DCoreActor* pspr, sectortype** psectnum, DAngle ang, fixedhoriz horiz, double const smoothratio);
|
||||||
|
|
||||||
|
inline bool calcChaseCamPos(int* px, int* py, int* pz, DCoreActor* pspr, sectortype** psectnum, DAngle ang, fixedhoriz horiz, double const smoothratio)
|
||||||
|
{
|
||||||
|
auto pos = DVector3((*px) * inttoworld, (*py) * inttoworld, (*pz) * zinttoworld);
|
||||||
|
auto res = calcChaseCamPos(pos, pspr, psectnum, ang, horiz, smoothratio);
|
||||||
|
(*px) = pos.X * worldtoint;
|
||||||
|
(*py) = pos.Y * worldtoint;
|
||||||
|
(*pz) = pos.Z * zworldtoint;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz);
|
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue