GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


noise code by MrDutchy
1
 
void noisetohmap(float * noisearr,int startfreq, float startamp, int octaves,int size)
{
    int oct; int inc; int frequency=startfreq; float amp=startamp;
    float incx; float incy;
    double ni[2];
    int x; int y;
    float value;
    bool firstoct=true;

    for (oct=0, inc = 0; oct<octaves; ++oct, frequency *=2, amp*=0.5)
    {
        SetNoiseFrequency(frequency);
        ni[0] = ni[1] = 0;

        incx = 1.0f / (size/frequency);
        for (x=0; x<size; ++x, ni[0] += incx)
        {
            incy = 1.0f / (size/frequency);
            for (y=0; y<size; ++y, ni[1] +=incy)
            {
                value = (float) ( (((noise2(ni)+1.0f) * amp)) * 0.5f);
                if (firstoct) noisearr [x + (y * size)] = value;
                else noisearr [x + (y * size)] += value;

                if (noisearr [x + (y * size)]>maxval) maxval = noisearr [x + (y * size)];
                if (noisearr [x + (y * size)]<minval) minval = noisearr [x + (y * size)];
            }
        }
        firstoct=false;
    }
}