} // centroid indices, sorted by distance from center public Plate(int[] vertexToPlate, IComplexGeometry geometry, PlatePhysicsTraits traits, int plateIndex, int startIndex, ref Random rand) { this.geometry = geometry; this.startIndex = startIndex; this.vertexToPlate = vertexToPlate; this.plateIndex = plateIndex; this.Traits = traits; Corners = new List <int>(); allIndices = new List <int>(6); allIndices.Add(startIndex); outerIndices = new List <int>(6); outerIndices.Add(startIndex); hue = rand.Next(500) / 500.0f; Vector4 color = NextColor(0); geometry.Mesh.SetColor(startIndex, ref color); vertexToPlate[startIndex] = plateIndex; }
private void InitializePlates() { // Initialize vertexToPlate array to a value that isn't a valid plate index vertexToPlate = new int[geometry.Mesh.Length]; for (int i = 0; i < geometry.Mesh.Length; ++i) { vertexToPlate[i] = -1; } borders.Clear(); for (int plateIndex = 0; plateIndex < plates.Length; ++plateIndex) { int plate = -1; do { int vertexIndex = rand.Next(geometry.Mesh.Length); // prevent 2 plates spawning at the same vertex. plate = vertexToPlate[vertexIndex]; if (plate == -1) { var traits = new PlatePhysicsTraits(); traits.Pivot = new Vector3(rand.Next(100) - 50, rand.Next(100) - 50, rand.Next(100) - 50); traits.Pivot.Normalize(); traits.Center = geometry.Mesh.GetPosition(vertexIndex); if (Vector3.Dot(traits.Center, traits.Pivot) < 0) { traits.Pivot *= -1.0f; // Ensure pivot is at least in the same hemisphere as the plate center. } traits.CenterRotation = (rand.Next(200) - 100) * (float)Math.PI / 6000.0f; // -3 -> 3 degrees traits.PivotRotation = (rand.Next(200) - 100) * (float)Math.PI / 6000.0f; traits.Elevation = 0.0f; plates[plateIndex] = new Plate(vertexToPlate, geometry, traits, plateIndex, vertexIndex, ref rand); break; } } while (plate != -1); } }