]> git.lizzy.rs Git - minetest.git/blobdiff - src/noise.h
Copy zlib and freetype dll to windows package too
[minetest.git] / src / noise.h
index 15df5c25b5d24a61fb1a59a023a47ce2f9328dfc..9f9e2af6df4210de55f1c9da1578a5902532a89d 100644 (file)
@@ -1,6 +1,7 @@
 /*
-Minetest-c55
-Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -67,9 +68,29 @@ struct NoiseParams {
        int seed;
        int octaves;
        float persist;
+
+       NoiseParams() {}
+
+       NoiseParams(float offset_, float scale_, v3f spread_,
+               int seed_, int octaves_, float persist_)
+       {
+               offset  = offset_;
+               scale   = scale_;
+               spread  = spread_;
+               seed    = seed_;
+               octaves = octaves_;
+               persist = persist_;
+       }
 };
 
 
+// Convenience macros for getting/setting NoiseParams in Settings
+
+#define NOISEPARAMS_FMT_STR "f,f,v3,s32,s32,f"
+
+#define getNoiseParams(x, y) getStruct((x), NOISEPARAMS_FMT_STR, &(y), sizeof(y))
+#define setNoiseParams(x, y) setStruct((x), NOISEPARAMS_FMT_STR, &(y))
+
 class Noise {
 public:
        NoiseParams *np;
@@ -83,9 +104,9 @@ class Noise {
 
        Noise(NoiseParams *np, int seed, int sx, int sy);
        Noise(NoiseParams *np, int seed, int sx, int sy, int sz);
-       ~Noise();
+       virtual ~Noise();
 
-       void init(NoiseParams *np, int seed, int sx, int sy, int sz);
+       virtual void init(NoiseParams *np, int seed, int sx, int sy, int sz);
        void setSize(int sx, int sy);
        void setSize(int sx, int sy, int sz);
        void setSpreadFactor(v3f spread);
@@ -101,6 +122,7 @@ class Noise {
                float step_x, float step_y, float step_z,
                int seed);
        float *perlinMap2D(float x, float y);
+       float *perlinMap2DModulated(float x, float y, float *persist_map);
        float *perlinMap3D(float x, float y, float z);
        void transformNoiseMap();
 };
@@ -128,9 +150,33 @@ inline float easeCurve(float t) {
        return t * t * t * (t * (6.f * t - 15.f) + 10.f);
 }
 
-#define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
-               noise2d_perlin((float)(x) * (np)->spread.X, (float)(y) * (np)->spread.Y, \
+#define NoisePerlin2D(np, x, y, s) \
+               ((np)->offset + (np)->scale * noise2d_perlin( \
+               (float)(x) / (np)->spread.X, \
+               (float)(y) / (np)->spread.Y, \
                (s) + (np)->seed, (np)->octaves, (np)->persist))
 
+#define NoisePerlin2DNoTxfm(np, x, y, s) \
+               (noise2d_perlin( \
+               (float)(x) / (np)->spread.X, \
+               (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DPosOffset(np, x, xoff, y, yoff, s) \
+               ((np)->offset + (np)->scale * noise2d_perlin( \
+               (float)(xoff) + (float)(x) / (np)->spread.X, \
+               (float)(yoff) + (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DNoTxfmPosOffset(np, x, xoff, y, yoff, s) \
+               (noise2d_perlin( \
+               (float)(xoff) + (float)(x) / (np)->spread.X, \
+               (float)(yoff) + (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin3D(np, x, y, z, s) ((np)->offset + (np)->scale * \
+               noise3d_perlin((float)(x) / (np)->spread.X, (float)(y) / (np)->spread.Y, \
+               (float)(z) / (np)->spread.Z, (s) + (np)->seed, (np)->octaves, (np)->persist))
+
 #endif