mirror of
https://github.com/FWGS/hlsdk-xash3d
synced 2024-11-21 17:36:18 +01:00
server: func_tank: prevent domain error on barrel adjust (#328)
When target is too close to the tank origin, `d2 - r2` expression may become negative causing domain error on square root, and poisoning other fields and even other entities with NaN
This commit is contained in:
parent
99dc2c519f
commit
1394637ce8
@ -626,12 +626,14 @@ void CFuncTank::AdjustAnglesForBarrel( Vector &angles, float distance )
|
||||
if( m_barrelPos.y )
|
||||
{
|
||||
r2 = m_barrelPos.y * m_barrelPos.y;
|
||||
angles.y += ( 180.0f / M_PI_F ) * atan2( m_barrelPos.y, sqrt( d2 - r2 ) );
|
||||
if( d2 > r2 )
|
||||
angles.y += ( 180.0f / M_PI_F ) * atan2( m_barrelPos.y, sqrt( d2 - r2 ) );
|
||||
}
|
||||
if( m_barrelPos.z )
|
||||
{
|
||||
r2 = m_barrelPos.z * m_barrelPos.z;
|
||||
angles.x += ( 180.0f / M_PI_F ) * atan2( -m_barrelPos.z, sqrt( d2 - r2 ) );
|
||||
if( d2 > r2 )
|
||||
angles.x += ( 180.0f / M_PI_F ) * atan2( -m_barrelPos.z, sqrt( d2 - r2 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user