public void Add(Vector3 position, Vector3 color, Vector3 size, bool fill) { Matrix world = Matrix.CreateScale(size) * Matrix.CreateTranslation(position); var newTriangles = new Dictionary <Vector3, Triangle>(); if (fill) { for (int i = 0; i < 6; i++) { for (int j = 0; j < 2; j++) { Triangle t = TransformTriangle(triangles[j], sides[i] * world); Vector3 key = GetCentroid(t); if (Triangles.ContainsKey(key)) { return; } newTriangles.Add(key, t); } } } foreach (KeyValuePair <Vector3, Triangle> kvp in newTriangles) { Triangles.Add(kvp.Key, kvp.Value); } cubes.Add(new Cube() { World = world, Color = color, Fill = fill }); }