src/RotatedGridSampleGenerator.h

Go to the documentation of this file.
00001 #ifndef ROTATEDGRIDSAMPLEGENERATOR_H
00002 #define ROTATEDGRIDSAMPLEGENERATOR_H
00003 
00004 #include "RegularSampleGenerator.h"
00005 #include <cmath>
00006 
00011 class RotatedGridSampleGenerator : public RegularSampleGenerator
00012 {
00013 public:
00018     RotatedGridSampleGenerator(float angle = 45.0f)
00019         :   RegularSampleGenerator(),
00020             mSin(sinf(angle*M_PI/180.0)),
00021             mCos(cosf(angle*M_PI/180.0))
00022     {
00023     }
00024 
00028     void samples(int n, float u[], float v[], float weight[]) const
00029     {
00030         // get samples on a regular grid
00031         RegularSampleGenerator::samples(n, u, v, weight);
00032 
00033         for (int i=0; i < n; i++)
00034         {
00035             // move pixel center to (0, 0)
00036             u[i] -= 0.5f;
00037             v[i] -= 0.5f;
00038 
00039             // rotate by angle
00040             float tmpU = u[i];
00041             u[i] = u[i]*mCos - v[i]*mSin;
00042             v[i] = tmpU*mSin + v[i]*mCos;
00043 
00044             // move back
00045             u[i] += 0.5f;
00046             v[i] += 0.5f;
00047         }
00048     }
00049 
00050 private:
00051     float mSin;
00052     float mCos;
00053 };
00054 
00055 #endif

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