UTIL AngleDistance: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with '{{wrongtitle|UTIL_AngleDistance}} UTIL_AngleDistance does the '''exact''' same thing as UTIL_AngleDiff. Category:Programming Category:UTIL')
 
No edit summary
Line 1: Line 1:
{{wrongtitle|UTIL_AngleDistance}}
{{wrongtitle|UTIL_AngleDistance}}
UTIL_AngleDistance does the '''exact''' same thing as [[UTIL_AngleDiff]].
UTIL_AngleDistance does '''a similar''' thing to [[UTIL_AngleDiff]], but does not clamp in a range from -180 to 180. Instead, it brings them up to 360 closer to these values.
 
{{todo|
 
== Usage ==
<source lang=cpp>
//-----------------------------------------------------------------------------
// Purpose: Returns the difference between two values as a float.
// Input  : next - Value "B" to compare against
// Input  : cur - Value "A" to compare with
// Output : float - Difference between the two values, interpreted as an angle
//-----------------------------------------------------------------------------
inline float UTIL_AngleDistance( float next, float cur )
</source>
 
== Examples ==
 
<source lang=cpp>
//Note! In this example they used the UNCLAMPED version (UTIL_AngleDistance is UNCLAMPED),
//Instead of the pre-clamped version (UTIL_AngleDiff)
//They then clamp the value. This is only provided for documentation's sake
//But it's probably just easier to use UTIL_AngleDiff which will always be between -180 and 180.
 
 
// Move toward target at rate or less
float distX = UTIL_AngleDistance( angles.x, GetLocalAngles().x );
vecAngVel.x = distX  * 10;
vecAngVel.x = clamp( vecAngVel.x, -m_pitchRate, m_pitchRate );
SetLocalAngularVelocity( vecAngVel );
</source>


[[Category:Programming]]
[[Category:Programming]]
[[Category:UTIL]]
[[Category:UTIL]]

Revision as of 00:10, 10 April 2011

Template:Wrongtitle UTIL_AngleDistance does a similar thing to UTIL_AngleDiff, but does not clamp in a range from -180 to 180. Instead, it brings them up to 360 closer to these values.

{{todo|

Usage

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

Examples

//Note! In this example they used the UNCLAMPED version (UTIL_AngleDistance is UNCLAMPED),
//Instead of the pre-clamped version (UTIL_AngleDiff)
//They then clamp the value. This is only provided for documentation's sake
//But it's probably just easier to use UTIL_AngleDiff which will always be between -180 and 180.


// Move toward target at rate or less
float distX = UTIL_AngleDistance( angles.x, GetLocalAngles().x );
vecAngVel.x = distX  * 10;
vecAngVel.x = clamp( vecAngVel.x, -m_pitchRate, m_pitchRate );
SetLocalAngularVelocity( vecAngVel );