private void InitializeVertices() { var vertices = new List <VertexPositionColorNormal>(); foreach (var t in Tiles) { int startingVerticesLength = vertices.Count; // "0-level" tiles (bottom) for (int j = 0; j < t.Corners.Length - 2; ++j) { Vector3 a = new Vector3(t.Corners[j + 2].X * Radius, t.Corners[j + 2].Y * Radius, t.Corners[j + 2].Z * Radius); Vector3 b = new Vector3(t.Corners[j + 1].X * Radius, t.Corners[j + 1].Y * Radius, t.Corners[j + 1].Z * Radius); Vector3 c = new Vector3(t.Corners[0].X * Radius, t.Corners[0].Y * Radius, t.Corners[0].Z * Radius); Vector3 normA = t.Corners[j + 2].V.ToVector3(); Vector3 normB = t.Corners[j + 1].V.ToVector3(); Vector3 normC = t.Corners[0].V.ToVector3(); vertices.Add(CreateVertex(a, normA, t.Height)); vertices.Add(CreateVertex(b, normB, t.Height)); vertices.Add(CreateVertex(c, normC, t.Height)); } // "Raised" tiles (top) float height = t.IsWater ? (float)(Radius + WaterHeight * GroundHeight) : (float)(Radius + t.Height * GroundHeight); for (int j = 0; j < t.Corners.Length - 2; ++j) { vertices.Add(CreateVertex(new Vector3(t.Corners[j + 2].X * height, t.Corners[j + 2].Y * height, t.Corners[j + 2].Z * height), t)); vertices.Add(CreateVertex(new Vector3(t.Corners[j + 1].X * height, t.Corners[j + 1].Y * height, t.Corners[j + 1].Z * height), t)); vertices.Add(CreateVertex(new Vector3(t.Corners[0].X * height, t.Corners[0].Y * height, t.Corners[0].Z * height), t)); } // Sides of raised tiles for (int i = 0; i < t.Corners.Length; ++i) { // Two points of "0-level" edge var a1 = new Vector3(t.Corners[i].X * Radius, t.Corners[i].Y * Radius, t.Corners[i].Z * Radius); var a2 = new Vector3(t.Corners[(i + 1) % t.Corners.Length].X * Radius, t.Corners[(i + 1) % t.Corners.Length].Y * Radius, t.Corners[(i + 1) % t.Corners.Length].Z * Radius); // Two points of "height-level" edge var b1 = new Vector3(t.Corners[i].X * height, t.Corners[i].Y * height, t.Corners[i].Z * height); var b2 = new Vector3(t.Corners[(i + 1) % t.Corners.Length].X * height, t.Corners[(i + 1) % t.Corners.Length].Y * height, t.Corners[(i + 1) % t.Corners.Length].Z * height); var normal = (a2 - b1) * (a2 - a1); normal = new Vector3(t.X, t.Y, t.Z); normal.Normalize(); vertices.Add(CreateVertex(b1, normal, t.Height)); vertices.Add(CreateVertex(a2, normal, t.Height)); vertices.Add(CreateVertex(a1, normal, t.Height)); vertices.Add(CreateVertex(b1, normal, t.Height)); vertices.Add(CreateVertex(b2, normal, t.Height)); vertices.Add(CreateVertex(a2, normal, t.Height)); } t.VerticeIndices = Enumerable.Repeat(startingVerticesLength, vertices.Count - startingVerticesLength).Select((value, index) => value + index).ToArray(); t.TopHexVerticeIndices = t.VerticeIndices.Skip((t.Corners.Length - 2) * 3).Take((t.Corners.Length - 2) * 3).ToArray(); t.BoundingBox = BoundingBox.CreateFromPoints(t.TopHexVerticeIndices.Select(vi => vertices[vi].Position)); } _intersectionChecker = IntersectionCheckNode.CreateFromTiles(Tiles, Radius + GroundHeight); _vertices = vertices.ToArray(); }