NSEntity: new method DistanceFromYaw

This commit is contained in:
Marco Cawthorne 2023-05-31 10:08:00 -07:00
parent bd7cb44784
commit 9e4bba1f0e
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
2 changed files with 13 additions and 8 deletions

View File

@ -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. */

View File

@ -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;
}