Improved floating point random number generation.
Fixed loading RGB images, as reported in issue 15. Moved pixel format conversion helpers to PixelFormat.h
This commit is contained in:
@ -28,8 +28,8 @@ void SampleDistribution::redistributeRandom(const Distribution dist)
|
||||
// This is the worst method possible!
|
||||
for(uint i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float x = m_rand.getReal();
|
||||
float y = m_rand.getReal();
|
||||
float x = m_rand.getFloat();
|
||||
float y = m_rand.getFloat();
|
||||
|
||||
// Map uniform distribution in the square to the (hemi)sphere.
|
||||
if( dist == Distribution_Uniform ) {
|
||||
@ -53,8 +53,8 @@ void SampleDistribution::redistributeStratified(const Distribution dist)
|
||||
// Create a uniform distribution of points on the hemisphere with low variance.
|
||||
for(uint v = 0, i = 0; v < sqrtSampleCount; v++) {
|
||||
for(uint u = 0; u < sqrtSampleCount; u++, i++) {
|
||||
float x = (u + m_rand.getReal()) / float(sqrtSampleCount);
|
||||
float y = (v + m_rand.getReal()) / float(sqrtSampleCount);
|
||||
float x = (u + m_rand.getFloat()) / float(sqrtSampleCount);
|
||||
float y = (v + m_rand.getFloat()) / float(sqrtSampleCount);
|
||||
|
||||
// Map uniform distribution in the square to the (hemi)sphere.
|
||||
if( dist == Distribution_Uniform ) {
|
||||
@ -82,7 +82,7 @@ void SampleDistribution::multiStageNRooks(const int size, int* cells)
|
||||
int size2 = size >> 1;
|
||||
|
||||
if (size & 1) {
|
||||
if (m_rand.getReal() > 0.5) {
|
||||
if (m_rand.getFloat() > 0.5) {
|
||||
size1++;
|
||||
}
|
||||
else {
|
||||
@ -138,8 +138,8 @@ void SampleDistribution::redistributeNRook(const Distribution dist)
|
||||
|
||||
for(uint i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float x = (i + m_rand.getReal()) / sampleCount;
|
||||
float y = (cells[i] + m_rand.getReal()) / sampleCount;
|
||||
float x = (i + m_rand.getFloat()) / sampleCount;
|
||||
float y = (cells[i] + m_rand.getFloat()) / sampleCount;
|
||||
|
||||
// Map uniform distribution in the square to the (hemi)sphere.
|
||||
if( dist == Distribution_Uniform ) {
|
||||
|
@ -35,6 +35,20 @@ public:
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Random number on [0.0, 1.0] interval.
|
||||
float getFloat()
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32 i;
|
||||
float f;
|
||||
} pun;
|
||||
|
||||
pun.i = 0x3f800000UL | (get() & 0x007fffffUL);
|
||||
return pun.f - 1.0f;
|
||||
}
|
||||
|
||||
/*
|
||||
/// Random number on [0.0, 1.0] interval.
|
||||
double getReal()
|
||||
{
|
||||
@ -45,7 +59,8 @@ public:
|
||||
double getRealExclusive()
|
||||
{
|
||||
return double(get()) * (1.0/4294967296.0); // 2^32
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// Get the max value of the random number.
|
||||
uint max() const { return 4294967295U; }
|
||||
@ -301,7 +316,7 @@ public:
|
||||
}
|
||||
|
||||
/** Get a random number. */
|
||||
virtual uint Get() {
|
||||
virtual uint get() {
|
||||
|
||||
advance();
|
||||
|
||||
|
Reference in New Issue
Block a user