src/RegularSampleGenerator.h

Go to the documentation of this file.
00001 #ifndef REGULARSAMPLEGENERATOR_H
00002 #define REGULARSAMPLEGENERATOR_H
00003 
00004 #include "SampleGenerator.h"
00005 #include <cmath>
00006 
00012 class RegularSampleGenerator : public SampleGenerator
00013 {
00014 public:
00018     void samples(int n, float u[], float v[], float weight[]) const
00019     {
00020         int x = static_cast<int>(floorf(sqrtf(n)));
00021         assert(x*x == n);
00022 
00023         // create grid of sample coordinates
00024         float offset = 0.5/x;
00025         for (int i=0; i < x; i++)
00026         {
00027             for (int j=0; j < x; j++)
00028             {
00029                 if (i*x+j >= n)
00030                     return;
00031                 u[i*x+j] = static_cast<float>(i)/x + offset;
00032                 v[i*x+j] = static_cast<float>(j)/x + offset;
00033                 weight[i*x+j] = 1.0 / float(n);
00034             }
00035         }
00036     }
00037 };
00038 
00039 #endif

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1