Example #1
0
    private void Generate()
    {
        generateVertices();
        generateFaces();

        for (int i = 0; i < this.subdivisions; i++)
        {
            //Vertices werden modifizert.. unschöne sideeffects
            Faces = Faces.ConvertAll(face =>
            {
                // check if near player
                int middlepoint1 = calculateMiddlepoint(face.V1, face.V2);
                int middlepoint2 = calculateMiddlepoint(face.V2, face.V3);
                int middlepoint3 = calculateMiddlepoint(face.V3, face.V1);

                return(new List <Face> ()
                {
                    new Face(face.V1, Vertices.ElementAt(middlepoint1), Vertices.ElementAt(middlepoint3)),
                    new Face(face.V2, Vertices.ElementAt(middlepoint2), Vertices.ElementAt(middlepoint1)),
                    new Face(face.V3, Vertices.ElementAt(middlepoint3), Vertices.ElementAt(middlepoint2)),
                    new Face(Vertices.ElementAt(middlepoint1), Vertices.ElementAt(middlepoint2), Vertices.ElementAt(middlepoint3))
                });
            })
                    .SelectMany(nestedFaceList => nestedFaceList)
                    .ToList();
        }

        this.Triangles = this.Faces
                         .ConvertAll(face =>
        {
            return(new List <int> ()
            {
                this.Vertices.IndexOf(face.V1),
                this.Vertices.IndexOf(face.V2),
                this.Vertices.IndexOf(face.V3)
            });
        })
                         .SelectMany(l => l)
                         .ToList();
    }