UTIL_AngleDiff

From Valve Developer Community
Jump to: navigation, search

UTIL_AngleDiff is a UTIL provided in the Source code for finding the difference between two values, clamped between -180° and 180°.

Usage

//-----------------------------------------------------------------------------
// Purpose: Returns the difference between two values as a float. 
// Input  : destAngle - Value "B" to compare against
// Input  : srcAngle - Value "A" to compare with
// Output : float - Difference between the two values, interpreted as an angle
//-----------------------------------------------------------------------------
inline float UTIL_AngleDiff( float destAngle, float srcAngle )

Examples

//Restricts a value from going too far beyond another one.
//This is used in the jeep to keep you from looking too far left/right, etc.
float flAngleDiff = AngleDiff( vecViewAngles.y, vehicleEyeAngles.y );
flAngleDiff = clamp( flAngleDiff, pYawBounds[0], pYawBounds[1] );
vecViewAngles.y = vehicleEyeAngles.y + flAngleDiff;