Added ability to give offset and gain to every noise (mappedNoise) +

bugfixes
This commit is contained in:
Remi Beges 2012-09-30 19:13:25 +02:00
parent ed200354cb
commit a41a2ddcb3
14 changed files with 31 additions and 33 deletions

View File

@ -10,13 +10,12 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/MappedNoiseBase.hpp> #include <Nazara/Noise/MappedNoiseBase.hpp>
template <typename T> class NAZARA_API NzAbstract2DNoise : public NzMappedNoiseBase<T> template <typename T> class NzAbstract2DNoise : public NzMappedNoiseBase<T>
{ {
public: public:
virtual T GetBasicValue(T x, T y);
virtual T GetMappedValue(T x, T y); virtual T GetMappedValue(T x, T y);
virtual T GetValue(T x, T y, T resolution) = 0; virtual T GetValue(T x, T y, T resolution) = 0;
virtual T GetValue(T x, T y);
}; };
#include <Nazara/Noise/Abstract2DNoise.inl> #include <Nazara/Noise/Abstract2DNoise.inl>

View File

@ -9,15 +9,15 @@
#include <Nazara/Noise/Debug.hpp> #include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
T NzAbstract2DNoise<T>::GetMappedValue(T x, T y) T NzAbstract2DNoise<T>::GetBasicValue(T x, T y)
{ {
return GetValue(x,y,this->m_resolution) * this->m_gain + this->m_offset; return this->GetValue(x,y,this->m_resolution);
} }
template <typename T> template <typename T>
T NzAbstract2DNoise<T>::GetValue(T x, T y) T NzAbstract2DNoise<T>::GetMappedValue(T x, T y)
{ {
return GetValue(x,y,this->m_resolution); return (this->GetValue(x,y,this->m_resolution) + this->m_offset) * this->m_gain;
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -10,12 +10,12 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/MappedNoiseBase.hpp> #include <Nazara/Noise/MappedNoiseBase.hpp>
template <typename T> class NAZARA_API NzAbstract3DNoise : public NzMappedNoiseBase template<typename T> class NzAbstract3DNoise : public NzMappedNoiseBase<T>
{ {
public: public:
virtual T GetBasicValue(T x, T y, T z);
virtual T GetMappedValue(T x, T y, T z); virtual T GetMappedValue(T x, T y, T z);
virtual T GetValue(T x, T y, T z) = 0; virtual T GetValue(T x, T y, T z, T resolution) = 0;
virtual T GetValue(T x, T y, T z, T resolution);
}; };
#include <Nazara/Noise/Abstract3DNoise.inl> #include <Nazara/Noise/Abstract3DNoise.inl>

View File

@ -9,15 +9,15 @@
#include <Nazara/Noise/Debug.hpp> #include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
T NzAbstract3DNoise<T>::GetMappedValue(T x, T y, T z) T NzAbstract3DNoise<T>::GetBasicValue(T x, T y, T z)
{ {
return GetValue(x,y,z) * m_gain + m_offset; return this->GetValue(x,y,z,this->m_resolution);
} }
template <typename T> template <typename T>
T NzAbstract3DNoise<T>::GetValue(T x, T y, T z, T resolution) T NzAbstract3DNoise<T>::GetMappedValue(T x, T y, T z)
{ {
return GetValue(x,y,z,this->m_resolution); return (this->GetValue(x,y,z,this->m_resolution) + this->m_offset) * this->m_gain ;
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -10,13 +10,12 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/MappedNoiseBase.hpp> #include <Nazara/Noise/MappedNoiseBase.hpp>
template <typename T> class NAZARA_API NzAbstract4DNoise : public NzMappedNoiseBase template <typename T> class NzAbstract4DNoise : public NzMappedNoiseBase<T>
{ {
public: public:
virtual T GetBasicValue(T x, T y, T z, T w);
virtual T GetMappedValue(T x, T y, T z, T w); virtual T GetMappedValue(T x, T y, T z, T w);
virtual T GetValue(T x, T y, T z, T w) = 0; virtual T GetValue(T x, T y, T z, T w, T resolution) = 0;
virtual T GetValue(T x, T y, T z, T w, T resolution);
}; };
#include <Nazara/Noise/Abstract4DNoise.inl> #include <Nazara/Noise/Abstract4DNoise.inl>

View File

@ -9,15 +9,15 @@
#include <Nazara/Noise/Debug.hpp> #include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
T NzAbstract4DNoise<T>::GetMappedValue(T x, T y, T z, T w) T NzAbstract4DNoise<T>::GetBasicValue(T x, T y, T z, T w)
{ {
return GetValue(x,y,z,w) * m_gain + m_offset; return this->GetValue(x,y,z,w,this->m_resolution);
} }
template <typename T> template <typename T>
T NzAbstract3DNoise<T>::GetValue(T x, T y, T z, T resolution) T NzAbstract4DNoise<T>::GetMappedValue(T x, T y, T z, T w)
{ {
return GetValue(x,y,z,w,this->m_resolution); return (this->GetValue(x,y,z,w,this->m_resolution) + this->m_offset) * this->m_gain ;
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -52,11 +52,11 @@ void NzMappedNoiseBase<T>::SetResolution(T resolution)
if (NzNumberEquals(resolution, static_cast<T>(0.0))) if (NzNumberEquals(resolution, static_cast<T>(0.0)))
{ {
NzStringStream ss; NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; ss << __FILE__ << ':' << __LINE__ << " : resolution cannot be 0.0f";
throw std::domain_error(ss.ToString()); throw std::domain_error(ss.ToString());
} }
m_resolution = static_cast<T>(1.0)/resolution; m_resolution = resolution;
} }
#include <Nazara/Core/DebugOff.hpp> #include <Nazara/Core/DebugOff.hpp>

View File

@ -12,7 +12,7 @@
#include <Nazara/Noise/Abstract2DNoise.hpp> #include <Nazara/Noise/Abstract2DNoise.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
template <typename T> class NAZARA_API NzPerlin2D : public NzAbstract2DNoise<T>, public NzNoiseBase template <typename T> class NzPerlin2D : public NzAbstract2DNoise<T>, public NzNoiseBase
{ {
public: public:
NzPerlin2D(); NzPerlin2D();

View File

@ -12,7 +12,7 @@
#include <Nazara/Noise/Abstract3DNoise.hpp> #include <Nazara/Noise/Abstract3DNoise.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
template <typename T> class NAZARA_API NzPerlin3D : public NzAbstract3DNoise<T>, public NzNoiseBase template <typename T> class NzPerlin3D : public NzAbstract3DNoise<T>, public NzNoiseBase
{ {
public: public:
NzPerlin3D(); NzPerlin3D();

View File

@ -24,9 +24,9 @@ NzPerlin3D<T>::NzPerlin3D()
template <typename T> template <typename T>
T NzPerlin3D<T>::GetValue(T x, T y, T z, T resolution) T NzPerlin3D<T>::GetValue(T x, T y, T z, T resolution)
{ {
x *= resolution; x /= resolution;
y *= resolution; y /= resolution;
z *= resolution; z /= resolution;
x0 = fastfloor(x); x0 = fastfloor(x);
y0 = fastfloor(y); y0 = fastfloor(y);

View File

@ -12,7 +12,7 @@
#include <Nazara/Noise/Abstract4DNoise.hpp> #include <Nazara/Noise/Abstract4DNoise.hpp>
#include <Nazara/Math/Vector4.hpp> #include <Nazara/Math/Vector4.hpp>
template <typename T> class NAZARA_API NzPerlin4D : public NzAbstract4DNoise<T>, public NzNoiseBase template <typename T> class NzPerlin4D : public NzAbstract4DNoise<T>, public NzNoiseBase
{ {
public: public:
NzPerlin4D(); NzPerlin4D();

View File

@ -12,7 +12,7 @@
#include <Nazara/Noise/Abstract2DNoise.hpp> #include <Nazara/Noise/Abstract2DNoise.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
template <typename T> class NAZARA_API NzSimplex2D : public NzAbstract2DNoise<T>, public NzNoiseBase template <typename T> class NzSimplex2D : public NzAbstract2DNoise<T>, public NzNoiseBase
{ {
public: public:
NzSimplex2D(); NzSimplex2D();

View File

@ -12,7 +12,7 @@
#include <Nazara/Noise/Abstract3DNoise.hpp> #include <Nazara/Noise/Abstract3DNoise.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
template <typename T> class NAZARA_API NzSimplex3D : public NzAbstract3DNoise<T>, public NzNoiseBase template <typename T> class NzSimplex3D : public NzAbstract3DNoise<T>, public NzNoiseBase
{ {
public: public:
NzSimplex3D(); NzSimplex3D();

View File

@ -12,7 +12,7 @@
#include <Nazara/Noise/Abstract4DNoise.hpp> #include <Nazara/Noise/Abstract4DNoise.hpp>
#include <Nazara/Math/Vector4.hpp> #include <Nazara/Math/Vector4.hpp>
template <typename T> class NAZARA_API NzSimplex4D : public NzAbstract4DNoise<T>, public NzNoiseBase template <typename T> class NzSimplex4D : public NzAbstract4DNoise<T>, public NzNoiseBase
{ {
public: public:
NzSimplex4D(); NzSimplex4D();