mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 17:01:28 +00:00
- added a Sum function to TVector familiy
Duke uses this kind of distance check quite a lot so it makes sense to add it to the vectors.
This commit is contained in:
parent
1d7f2c81b6
commit
3352783be2
3 changed files with 24 additions and 6 deletions
|
@ -237,6 +237,12 @@ struct TVector2
|
||||||
{
|
{
|
||||||
return X*X + Y*Y;
|
return X*X + Y*Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Sum() const
|
||||||
|
{
|
||||||
|
return abs(X) + abs(Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a unit vector facing the same direction as this one
|
// Return a unit vector facing the same direction as this one
|
||||||
TVector2 Unit() const
|
TVector2 Unit() const
|
||||||
|
@ -601,6 +607,12 @@ struct TVector3
|
||||||
{
|
{
|
||||||
return X*X + Y*Y + Z*Z;
|
return X*X + Y*Y + Z*Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Sum() const
|
||||||
|
{
|
||||||
|
return abs(X) + abs(Y) + abs(Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a unit vector facing the same direction as this one
|
// Return a unit vector facing the same direction as this one
|
||||||
TVector3 Unit() const
|
TVector3 Unit() const
|
||||||
|
@ -900,6 +912,12 @@ struct TVector4
|
||||||
{
|
{
|
||||||
return X*X + Y*Y + Z*Z + W*W;
|
return X*X + Y*Y + Z*Z + W*W;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Sum() const
|
||||||
|
{
|
||||||
|
return abs(X) + abs(Y) + abs(Z) + abs(W);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a unit vector facing the same direction as this one
|
// Return a unit vector facing the same direction as this one
|
||||||
TVector4 Unit() const
|
TVector4 Unit() const
|
||||||
|
|
|
@ -4928,7 +4928,7 @@ DAngle furthestangle(DDukeActor *actor, int angs)
|
||||||
{
|
{
|
||||||
hitscan(actor->spr.pos.plusZ(-8), actor->sector(), DVector3(j.ToVector() * 1024, 0), hit, CLIPMASK1);
|
hitscan(actor->spr.pos.plusZ(-8), actor->sector(), DVector3(j.ToVector() * 1024, 0), hit, CLIPMASK1);
|
||||||
|
|
||||||
d = abs(hit.hitpos.X - actor->spr.pos.X) + abs(hit.hitpos.Y - actor->spr.pos.Y);
|
d = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum();
|
||||||
|
|
||||||
if (d > greatestd)
|
if (d > greatestd)
|
||||||
{
|
{
|
||||||
|
@ -4960,8 +4960,8 @@ int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, DVector2& pos)
|
||||||
{
|
{
|
||||||
hitscan(tosee->spr.pos.plusZ(-16), tosee->sector(), vec3_t(bcos(j), bsin(j), 16384 - (krand() & 32767)), hit, CLIPMASK1);
|
hitscan(tosee->spr.pos.plusZ(-16), tosee->sector(), vec3_t(bcos(j), bsin(j), 16384 - (krand() & 32767)), hit, CLIPMASK1);
|
||||||
|
|
||||||
double d = abs(hit.hitpos.X - tosee->spr.pos.X) + abs(hit.hitpos.Y - tosee->spr.pos.Y);
|
double d = (hit.hitpos.XY() - tosee->spr.pos.XY()).Sum();
|
||||||
double da = abs(hit.hitpos.X - actor->spr.pos.X) + abs(hit.hitpos.Y - actor->spr.pos.Y);
|
double da = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum();
|
||||||
|
|
||||||
if (d < da && hit.hitSector)
|
if (d < da && hit.hitSector)
|
||||||
if (cansee(hit.hitpos, hit.hitSector, actor->spr.pos.plusZ(-16), actor->sector()))
|
if (cansee(hit.hitpos, hit.hitSector, actor->spr.pos.plusZ(-16), actor->sector()))
|
||||||
|
|
|
@ -227,7 +227,7 @@ int findplayer(const DDukeActor* actor, double* d)
|
||||||
|
|
||||||
if (ud.multimode < 2)
|
if (ud.multimode < 2)
|
||||||
{
|
{
|
||||||
if (d) *d = abs(ps[myconnectindex].opos.X - s.X) + abs(ps[myconnectindex].opos.Y - s.Y) + abs(ps[myconnectindex].opos.Z - s.Z + 28);
|
if (d) *d = (ps[myconnectindex].opos - s).plusZ(28).Sum();
|
||||||
return myconnectindex;
|
return myconnectindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ int findplayer(const DDukeActor* actor, double* d)
|
||||||
|
|
||||||
for (j = connecthead; j >= 0; j = connectpoint2[j])
|
for (j = connecthead; j >= 0; j = connectpoint2[j])
|
||||||
{
|
{
|
||||||
x = abs(ps[j].opos.X - s.X) + abs(ps[j].opos.Y - s.Y) + abs(ps[j].opos.Z - s.Z + 28);
|
x = (ps[j].opos - s).plusZ(28).Sum();
|
||||||
if (x < closest && ps[j].GetActor()->spr.extra > 0)
|
if (x < closest && ps[j].GetActor()->spr.extra > 0)
|
||||||
{
|
{
|
||||||
closest_player = j;
|
closest_player = j;
|
||||||
|
@ -265,7 +265,7 @@ int findotherplayer(int p, double* d)
|
||||||
for (j = connecthead; j >= 0; j = connectpoint2[j])
|
for (j = connecthead; j >= 0; j = connectpoint2[j])
|
||||||
if (p != j && ps[j].GetActor()->spr.extra > 0)
|
if (p != j && ps[j].GetActor()->spr.extra > 0)
|
||||||
{
|
{
|
||||||
x = abs(ps[j].opos.X - ps[p].pos.X) + abs(ps[j].opos.Y - ps[p].pos.Y) + abs(ps[j].opos.Z - ps[p].pos.Z);
|
x = (ps[j].opos - ps[p].pos).Sum();
|
||||||
|
|
||||||
if (x < closest)
|
if (x < closest)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue