diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-12-26 03:13:40 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-12-26 03:13:40 +0100 |
commit | c35db25269ea9549b996cd18c65b05a9f8d43387 (patch) | |
tree | 87c8ef140849ed116d59fdfdc88ac4385d3ce5b7 /source/cNoise.inc | |
parent | - Ignoring Debug and Release makes it easier to check what should be committed (diff) | |
download | cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.tar cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.tar.gz cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.tar.bz2 cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.tar.lz cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.tar.xz cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.tar.zst cuberite-c35db25269ea9549b996cd18c65b05a9f8d43387.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cNoise.inc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/source/cNoise.inc b/source/cNoise.inc new file mode 100644 index 000000000..a63bb0c2f --- /dev/null +++ b/source/cNoise.inc @@ -0,0 +1,54 @@ +#ifndef __C_NOISE_INC__
+#define __C_NOISE_INC__
+
+#include <math.h>
+
+/****************
+ * Random value generator
+ **/
+float cNoise::IntNoise( int a_X ) const
+{
+ int x = ((a_X*m_Seed)<<13) ^ a_X;
+ return ( 1.0f - ( (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f);
+}
+
+float cNoise::IntNoise2D( int a_X, int a_Y ) const
+{
+ int n = a_X + a_Y * 57 + m_Seed*57*57;
+ n = (n<<13) ^ n;
+ return ( 1.0f - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f);
+}
+
+float cNoise::IntNoise3D( int a_X, int a_Y, int a_Z ) const
+{
+ int n = a_X + a_Y * 57 + a_Z * 57*57 + m_Seed*57*57*57;
+ n = (n<<13) ^ n;
+ return ( 1.0f - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f);
+}
+
+/****************
+ * Interpolation functions
+ **/
+float cNoise::CubicInterpolate( float a_A, float a_B, float a_C, float a_D, float a_Pct ) const
+{
+ float P = (a_D - a_C) - (a_A - a_B);
+ float Q = (a_A - a_B) - P;
+ float R = a_C - a_A;
+ float S = a_B;
+
+ return P*(a_Pct*a_Pct*a_Pct) + Q*(a_Pct*a_Pct) + R*a_Pct + S;
+}
+
+float cNoise::CosineInterpolate( float a_A, float a_B, float a_Pct ) const
+{
+ const float ft = a_Pct * 3.1415927f;
+ const float f = (1.f - cosf(ft)) * 0.5f;
+ return a_A*(1-f) + a_B*f;
+}
+
+float cNoise::LinearInterpolate( float a_A, float a_B, float a_Pct ) const
+{
+ return a_A*(1.f-a_Pct) + a_B*a_Pct;
+}
+
+#endif
\ No newline at end of file |