Well **** me.  I missed the second "+ UTIL_SharedRandomFloat( shared_rand +
iShot, -0.5, 0.5 )" in the goldsrc method - which takes it back up to +/-1 max
range.

At least I know a) the code better and b) not to trust my math :^)

Quoting Tim Holt <[EMAIL PROTECTED]>:

> Answering my own question a bit maybe. Someone check my math on this?  I may
> have missed something...
>
> If you go with straight default values, you have...
>
>    bias = 1.0;
>    shotBiasMin = -1.0;
>    shotBiasMax = 1.0;
>
> Applying those values to the forumula below, you get
>
>    shotBias = ((1.0 - -1.0) * 1.0) + -1.0
>             = ((2.0) * 1.0) + -1.0
>             = 1.0
>    flatness = 1.0 * 0.5
>             = 0.5
>
> Now - the random number generators use that flatness value, and essentially
> are
> going to be cranking out values of X and Y that will vary from -1 to +1.  And
> this is where it really changes from GoldSrc.  GoldSrc calculates a random
> number from -0.5 to +0.5.  Meaning GoldSrc has a shot pattern that's HALF THE
> SIZE of Source, if I did my math right.  Which means (again if I did this
> right) you need to make your vecSpread be half the size in Source that it was
> in GoldSrc to get the same accuracy.
>
> The other difference is the while loop.  The while look in the Source version
> keeps all points inside of a circle, whereas the GoldSrc version ends up
> creating a distribution of points in a square.
>
> It's worth noting that an alternate way to calculate a random point in a
> circle
> without the randomness would be as follows...
>
> float x, y, r, theta;
>
> r = RandomFloat(0, 1);
> theta  = RandomFloat (0, 2_PI);
> x = sqrt(r) * cos(theta);
> y = sqrt(r) * sin(theta);
>
> More trig, less looping until you get a good number.
>
> This is from http://mathworld.wolfram.com/DiskPointPicking.html
>
>
>
>
> > 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
> >
> >
>
>
>



_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to