Esempio n. 1
0
    // see https://en.wikipedia.org/wiki/Enneper_surface
    void Enneper(GeometricObject obj)
    {
        System.Func <int, int, Vector3> f = (r, c) => {
            var o = new Vector3();
            var u = (float)r / 10f;
            var v = (float)c / 10f;
            o.x = u * (1f - u * u + v * v) / 3f;
            o.y = v * (1f - v * v + u * u) / 3f;
            o.z = (u * u - v * v) / 3f;
            return(o * 0.5f);
        };

        var alpha  = 1.0f;
        var pcl    = new Color(1.0f, 1.0f, 1.0f, alpha);
        var fcl    = new Color(0.5f, 0.5f, 1.0f, alpha);
        var bcl    = new Color(0.5f, 0.5f, 0.0f, alpha);
        var rows   = 51;
        var cols   = 51;
        var idxs   = new int[rows, cols];
        var points = new List <Vector3> ();

        points.Clear();
        for (var r = -rows / 2; r <= rows / 2; r++)
        {
            for (var c = -cols / 2; c <= cols / 2; c++)
            {
                idxs [rows / 2 + r, cols / 2 + c] = points.Count;
                points.Add(f(r, c));
            }
        }

        obj.Begin();
        obj.SetPointFrontColor(pcl);
        for (var r = 0; r < rows; r++)
        {
            for (var c = 0; c < cols; c++)
            {
                obj.AddPoint(points [idxs[r, c]]);
            }
        }
        obj.SetMeshFrontColor(fcl);
        obj.SetMeshBackColor(bcl);
        obj.AddMesh(rows, cols, points, idxs);
        obj.End();
    }