/// <summary> /// See the documentation on the base class. /// <seealso cref="Module"/> /// </summary> /// <param name="x">X coordinate</param> /// <param name="y">Y coordinate</param> /// <param name="z">Z coordinate</param> /// <returns>Returns the computed value</returns> public override double GetValue(double x, double y, double z) { // Get the values from the three Perlin noise modules and // add each value to each coordinate of the input value. There are also // some offsets added to the coordinates of the input values. This prevents // the distortion modules from returning zero if the (x, y, z) coordinates, // when multiplied by the frequency, are near an integer boundary. This is // due to a property of gradient coherent noise, which returns zero at // integer boundaries. double x0, y0, z0; double x1, y1, z1; double x2, y2, z2; x0 = x + (12414D / 65536D); y0 = y + (65124D / 65536D); z0 = z + (31337D / 65536D); x1 = x + (26519D / 65536D); y1 = y + (18128D / 65536D); z1 = z + (60493D / 65536D); x2 = x + (53820D / 65536D); y2 = y + (11213D / 65536D); z2 = z + (44845D / 65536D); var xDistorted = x + (xDistort.GetValue(x0, y0, z0) * Power); var yDistorted = y + (yDistort.GetValue(x1, y1, z1) * Power); var zDistorted = z + (zDistort.GetValue(x2, y2, z2) * Power); // Retrieve the output value at the offsetted input value instead of the // original input value. return(SourceModules[0].GetValue(xDistorted, yDistorted, zDistorted)); }
public void ScalePointTest(double sx, double sy, double sz) { var source = new Perlin(); var module = new ScalePoint { XScale = sx, YScale = sy, ZScale = sz, Source0 = source, }; for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { for (int z = -1; z < 2; z++) { var expected = source.GetValue(x * sx, y * sy, z * sz); var actual = module.GetValue(x, y, z); Assert.Equal(expected, actual); } } } }