Woops - hit send button while editing - here's the right one...
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...
> 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;
Here is the (I think) equivalent 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;
So you can see how the X and Y are calculated differently in the two. Source
has a "bias" value that influences how it works. Source also loops until you
get an X and Y that lay inside of a circle (that while loop on Z) but GoldSrc
doesn't.
So basically, what will the difference be between these two systems? What will
the bias value's influece be on the randomness?
I actually started looking into this because I want to code a weighted
randomness - with more points concentrated in the middle. Take a look at
http://mathworld.wolfram.com/DiskPointPicking.html for an article about how NOT
to do this (ironically).
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders