summaryrefslogtreecommitdiffstats
path: root/source/cNoise.inc
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-05-25 09:18:52 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-05-25 09:18:52 +0200
commita4a418a679f1ac760a8763edd856f0178cfc6dde (patch)
tree85300ca3a2b3a942998a0c864ae90894857ebf5f /source/cNoise.inc
parentFixed output directory structure in the "Release profiled" configuration (diff)
downloadcuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.gz
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.bz2
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.lz
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.xz
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.zst
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.zip
Diffstat (limited to '')
-rw-r--r--source/cNoise.inc79
1 files changed, 73 insertions, 6 deletions
diff --git a/source/cNoise.inc b/source/cNoise.inc
index fd52fef37..cde1f1609 100644
--- a/source/cNoise.inc
+++ b/source/cNoise.inc
@@ -1,34 +1,85 @@
+
#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);
+ 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);
+ 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);
+ n = (n<<13) ^ n;
+ return ( 1.0f - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f);
+}
+
+
+
+
+
+int cNoise::IntNoise1DInt( int a_X ) const
+{
+ int x = ((a_X*m_Seed)<<13) ^ a_X;
+ return ( (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff);
+}
+
+
+
+
+
+int cNoise::IntNoise2DInt( int a_X, int a_Y ) const
+{
+ int n = a_X + a_Y * 57 + m_Seed*57*57;
+ n = (n<<13) ^ n;
+ return ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff);
}
+
+
+
+
+int cNoise::IntNoise3DInt( 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 ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff);
+}
+
+
+
+
+
/****************
* 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);
@@ -39,6 +90,10 @@ float cNoise::CubicInterpolate( float a_A, float a_B, float a_C, float a_D, floa
return ((P * a_Pct + Q) * 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;
@@ -46,9 +101,21 @@ float cNoise::CosineInterpolate( float a_A, float a_B, float a_Pct ) const
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
+
+
+
+
+#endif
+
+
+
+