/// <summary> /// Calculate render and physics data. /// </summary> public void Calculate(GameWorld world) { var clipper = new Clipper(); List <List <IntPoint> > output = new List <List <IntPoint> >(); // Calculate difference clipper.AddPolygons(Polygons, PolyType.ptSubject); clipper.AddPolygons(Cavities, PolyType.ptClip); clipper.AddPolygons(Damage, PolyType.ptClip); clipper.Execute(ClipType.ctDifference, output, PolyFillType.pftNonZero, PolyFillType.pftNonZero); Hulls.Clear(); output.ForEach(o => { Vector2[] points = new Vector2[o.Count]; int index = 0; o.ForEach(p => points[index++] = new Vector2(p.X, p.Y)); Hulls.Add(new Penumbra.Hull(points)); }); // Triangulate background for rendering { var triangulation = TerrainHelper.Triangulate(Polygons); TriangulatedBackgroundVertices = new VertexPositionColor[triangulation.Count * 3]; int index = 0; for (int i = 0; i < triangulation.Count; ++i) { for (int b = 0; b < 3; ++b) { TriangulatedBackgroundVertices[index++] = new VertexPositionColor( new Vector3(triangulation[i][b].X, triangulation[i][b].Y, 0), world.Planet.BackgroundSoilTint); } } } // Triangulate foreground for rendering { var triangulation = TerrainHelper.Triangulate(output); TriangulatedForegroundVertices = new VertexPositionColor[triangulation.Count * 3]; int index = 0; for (int i = 0; i < triangulation.Count; ++i) { for (int b = 0; b < 3; ++b) { TriangulatedForegroundVertices[index++] = new VertexPositionColor( new Vector3(triangulation[i][b].X, triangulation[i][b].Y, 0), world.Planet.SoilTint); } } } // Convert to Farseer data PhysicsOutput.Clear(); output.ForEach(p => { PhysicsOutput.Add(TerrainHelper.PolygonToVertices(p)); }); }