I was looking at the base code that calculates bullet "cone of fire" or
randomness in Source today, and comparing it with the calculation method in
GoldSrc (HL1). They are different. I'm curious if anyone could help me grok
the differences, and just what the effect would be for bullet spread.
First, here's the code in shot_manipulator.h that Source uses...
//---------------------------------------------------------
// Take a vector (direction) and another vector (spread)
// and modify the direction to point somewhere within the
// spread. This used to live iApplySpreadnside FireBullets.
//---------------------------------------------------------
inline const Vector &CShotManipulator::ApplySpread( const Vector &vecSpread,
float bias )
{
// get circular gaussian spread
float x, y, z;
if ( bias > 1.0 )
bias = 1.0;
else if ( bias < 0.0 )
bias = 0.0;
float shotBiasMin = ai_shot_bias_min.GetFloat();
float shotBiasMax = ai_shot_bias_max.GetFloat();
// 1.0 gaussian, 0.0 is flat, -1.0 is inverse gaussian
float shotBias = ( ( shotBiasMax - shotBiasMin ) * bias ) + shotBiasMin;
float flatness = ( fabsf(shotBias) * 0.5 );
do
{
x = random->RandomFloat(-1,1) * flatness +
random->RandomFloat(-1,1) * (1 -
flatness);
y = random->RandomFloat(-1,1) * flatness +
random->RandomFloat(-1,1) * (1 -
flatness);
if ( shotBias < 0 )
{
x = ( x >= 0 ) ? 1.0 - x : -1.0 - x;
y = ( y >= 0 ) ? 1.0 - y : -1.0 - y;
}
z = x*x+y*y;
} while (z > 1);
m_vecResult = m_vecShotDirection + x * vecSpread.x * m_vecRight + y *
vecSpread.y * m_vecUp;
return m_vecResult;
}
Here is the code that GoldSrc (HL1) uses...
x = UTIL_SharedRandomFloat( shared_rand + iShot, -0.5, 0.5 )
+ UTIL_SharedRandomFloat( shared_rand + ( 1 + iShot ) , -0.5, 0.5 );
y = UTIL_SharedRandomFloat( shared_rand + ( 2 + iShot ), -0.5, 0.5 )
+ UTIL_SharedRandomFloat( shared_rand + ( 3 + iShot ), -0.5, 0.5 );
z = x * x + y * y;
Vector vecDir = vecDirShooting
+ x * vecSpread.x * vecRight
+
y * vecSpread.y * vecUp;
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders