Esempio n. 1
0
        private static double interp_XY_2(double x, double y, double xs, double ys, int x0, int x1, int y0, int y1,
                                          uint seed, NoiseFunc noisefunc)
        {
            double v1 = interp_X_2(x, y, xs, x0, x1, y0, seed, noisefunc);
            double v2 = interp_X_2(x, y, xs, x0, x1, y1, seed, noisefunc);

            return(Lerp(ys, v1, v2));
        }
Esempio n. 2
0
        private static double interp_X_2(double x, double y, double xs, int x0, int x1, int iy, uint seed,
                                         NoiseFunc function)
        {
            double v1 = Noisefunc(x, y, x0, iy, seed, function);
            double v2 = Noisefunc(x, y, x1, iy, seed, function);

            return(Lerp(xs, v1, v2));
        }
Esempio n. 3
0
 private static double noisefunc(double x, double y, int ix, int iy, uint seed, NoiseFunc function)
 {
     switch (function)
     {
         case NoiseFunc.value_noise_2: return value_noise_2(x, y, ix, iy, seed);
         case NoiseFunc.grad_noise_2: return grad_noise_2(x, y, ix, iy, seed);
         default: return value_noise_2(x, y, ix, iy, seed);
     }
 }
Esempio n. 4
0
 //public static double simplex_noise2D(double x, double y, int seed, InterpTypes interp)
 //{
 //    double s = (x + y) * F2;
 //    int i=fast_floor(x+s);
 //    int j=fast_floor(y+s);
 //    double t = (i+j)*G2;
 //    double X0=i-t;
 //    double Y0=j-t;
 //    double x0=x-X0;
 //    double y0=y-Y0;
 //    int i1,j1;
 //    if(x0>y0)
 //    {
 //        i1=1; j1=0;
 //    }
 //    else
 //    {
 //        i1=0; j1=1;
 //    }
 //    double x1=x0-(double)i1+G2;
 //    double y1=y0-(double)j1+G2;
 //    double x2=x0-1.0+2.0*G2;
 //    double y2=y0-1.0+2.0*G2;
 //    // Hash the triangle coordinates to index the gradient table
 //    uint h0=hash_coords_2(i,j,seed);
 //    uint h1=hash_coords_2(i+i1,j+j1,seed);
 //    uint h2=hash_coords_2(i+1,j+1,seed);
 //    // Now, index the tables
 //    double g0 = gradient2D_lut[h0,0];
 //    double g1 = gradient2D_lut[h1,0];
 //    double g2 = gradient2D_lut[h2,0];
 //    double n0,n1,n2;
 //    // Calculate the contributions from the 3 corners
 //    double t0=0.5-x0*x0-y0*y0;
 //    if(t0<0) n0=0;
 //    else
 //    {
 //        t0 *= t0;
 //        n0 = t0 * t0 * array_dot2(g0,x0,y0);
 //    }
 //    double t1=0.5-x1*x1-y1*y1;
 //    if(t1<0) n1=0;
 //    else
 //    {
 //        t1*=t1;
 //        n1=t1*t1*array_dot2(g1,x1,y1);
 //    }
 //    double t2=0.5-x2*x2-y2*y2;
 //    if(t2<0) n2=0;
 //    else
 //    {
 //        t2*=t2;
 //        n2=t2*t2*array_dot2(g2,x2,y2);
 //    }
 //    // Add contributions together
 //    return (70.0 * (n0+n1+n2)) *1.42188695 + 0.001054489;
 //}
 static double interp_X_2(double x, double y, double xs, int x0, int x1, int iy, uint seed, NoiseFunc function)
 {
     double v1 = noisefunc(x, y, x0, iy, seed, function);
     double v2 = noisefunc(x, y, x1, iy, seed, function);
     return lerp(xs,v1,v2);
 }
Esempio n. 5
0
 static double interp_XY_2(double x, double y, double xs, double ys, int x0, int x1, int y0, int y1, uint seed, NoiseFunc noisefunc)
 {
     double v1 = interp_X_2(x, y, xs, x0, x1, y0, seed, noisefunc);
     double v2 = interp_X_2(x, y, xs, x0, x1, y1, seed, noisefunc);
     return lerp(ys,v1,v2);
 }
        public Plane(float Width, int VertsPerSide, NoiseFunc NoiseFunction)
        {
            //The spacing between each of the vertices.
            float Interp = Width / VertsPerSide;
            //Half the width
            float hWidth = Width * 0.5f;
            //Number of indices
            int NumIndices = (VertsPerSide - 1) * (VertsPerSide - 1) * 6;

            Vertices = new Vector3[VertsPerSide * VertsPerSide];
            Normals = new Vector3[VertsPerSide * VertsPerSide];
            Indices = new int[NumIndices];

            //Create and displace vertices
            //Vertices are dispalced along the Y axis
            //Doing this in 3d wold normally be more complicated but with a plane it is simple
            Parallel.For(0, VertsPerSide, x =>
            {
                for (int z = 0; z < VertsPerSide; z++)
                {
                    Vertices[x * VertsPerSide + z] = new Vector3(Interp * x - hWidth, NoiseFunction(Interp * x - hWidth, 0, Interp * z - hWidth), Interp * z - hWidth);
                }
            });

            int idx = 0;

            //Create indices
            for (int y = 0; y < VertsPerSide - 1; y++)
            {
                for (int x = 0; x < VertsPerSide - 1; x++)
                {
                    //First triangle
                    Indices[idx++] = (y + 1) * VertsPerSide + x;
                    Indices[idx++] = y * VertsPerSide + x + 1;
                    Indices[idx++] = (y * VertsPerSide + x);

                    //Second triangle
                    Indices[idx++] = (y + 1) * VertsPerSide + x;
                    Indices[idx++] = (y + 1) * VertsPerSide + x + 1;
                    Indices[idx++] = y * VertsPerSide + x + 1;
                }
            }

            //Create normals using vector cross product
            for (int i = 0; i < idx; i += 3)
            {
                Vector3 v0 = Vertices[Indices[i]];
                Vector3 v1 = Vertices[Indices[i + 1]];
                Vector3 v2 = Vertices[Indices[i + 2]];

                Vector3 Normal = Vector3.Cross(v0 - v1, v0 - v2);

                Normals[Indices[i]] += Normal;
                Normals[Indices[i + 1]] += Normal;
                Normals[Indices[i + 2]] += Normal;
            }

            //Normalize all the normals
            for(int i = 0; i < Normals.Length; i++)
            {
                Normals[i].Normalize();
            }
        }
Esempio n. 7
0
 public Function(NoiseFunc Func)
 {
     this.Func = Func;
 }
Esempio n. 8
0
        private static double Noisefunc(double x, double y, int ix, int iy, uint seed, NoiseFunc function)
        {
            switch (function)
            {
            case NoiseFunc.value_noise_2:
                return(value_noise_2(x, y, ix, iy, seed));

            case NoiseFunc.grad_noise_2:
                return(grad_noise_2(x, y, ix, iy, seed));

            default:
                return(value_noise_2(x, y, ix, iy, seed));
            }
        }
Esempio n. 9
0
 public Function(NoiseFunc Func)
 {
     this.Func = Func;
 }