From 9e4bba1f0ee6a27ff8b04e6f25db0ac7c9f8ab86 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Wed, 31 May 2023 10:08:00 -0700 Subject: [PATCH] NSEntity: new method DistanceFromYaw --- src/shared/NSEntity.h | 2 ++ src/shared/NSEntity.qc | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/shared/NSEntity.h b/src/shared/NSEntity.h index f40f8a7b..73c1fbd0 100644 --- a/src/shared/NSEntity.h +++ b/src/shared/NSEntity.h @@ -321,6 +321,8 @@ public: nonvirtual bool Visible(entity); /** Returns if the entity is visible from a given position and a field of view of 90 degrees. */ nonvirtual bool VisibleVec(vector); + /** Returns a normalized value of how far away the target is from the entity's view direction. 1 means dead-center. 0 means it's behind.*/ + nonvirtual bool DistanceFromYaw(entity); /** Returns if the entity has any spawnflags set. */ nonvirtual bool HasSpawnFlags(float); /** Returns if the entity is aligned to the ground. */ diff --git a/src/shared/NSEntity.qc b/src/shared/NSEntity.qc index 4b0ba3be..fadb3513 100644 --- a/src/shared/NSEntity.qc +++ b/src/shared/NSEntity.qc @@ -98,15 +98,8 @@ bool NSEntity::VisibleVec( vector org ) { } bool NSEntity::Visible( entity ent ) { - vector flDelta; - float flFoV; - - makevectors( angles ); - flDelta = normalize( ent.origin - origin ); - flFoV = flDelta * v_forward; - /* is it in our field of view? */ - if ( flFoV > 0.3f ) { + if ( DistanceFromYaw(ent) > 0.3f ) { traceline( origin, ent.origin, MOVE_NORMAL, this ); if ( trace_fraction == 1.0f || trace_ent == ent ) { print( sprintf( "%s can see %s\n", classname, ent.classname ) ); @@ -117,6 +110,16 @@ bool NSEntity::Visible( entity ent ) { return ( false ); } +bool NSEntity::DistanceFromYaw( entity ent ) { + vector flDelta; + float flFoV; + + makevectors( angles ); + flDelta = normalize( ent.origin - origin ); + return flDelta * v_forward; +} + + bool NSEntity::HasSpawnFlags( float sf ) { return ( spawnflags & sf ) ? true : false; }