public BoxOutline(BoundingBox boundingBox) { this.boundingBox = boundingBox; if (boxBuffer == null) { boxBuffer = new DynamicVertexIndexBuffer <VertexPositionColor>(); var axis = new[] { Vector3.Right, Vector3.Up, Vector3.Backward }; for (int i = 0; i < 12; i++) { var color = Color.White; var mainAxis = axis[i % 3]; var otherAxis = axis.Where(x => x != mainAxis).ToArray(); var offset = Vector3.Zero; if (i / 3 % 2 == 1) { offset += otherAxis[0]; } if (i / 3 / 2 == 1) { offset += otherAxis[1]; } boxBuffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(offset, color) }); boxBuffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(offset + mainAxis, color) }); boxBuffer.AddIndices(new List <int>() { i * 2, i * 2 + 1 }); } } if (emptyBuffer == null) { emptyBuffer = new DynamicVertexIndexBuffer <VertexPositionColor>(); var axis = new[] { Vector3.Right, Vector3.Up, Vector3.Backward }; for (int i = 0; i < axis.Length; i++) { var color = Color.White; emptyBuffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(-axis[i], color) }); emptyBuffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(axis[i], color) }); emptyBuffer.AddIndices(new List <int>() { i * 2, i * 2 + 1 }); } } }
public void RecalculateEverything() { if (buffer != null) { buffer.Dispose(); } buffer = new DynamicVertexIndexBuffer <VertexPositionNormalTexture>(); int verticesAdded = 0; foreach (var item in items) { var normal = CalculateNormal(item.Select(x => x.position).ToArray()); var vertices = item.Select(x => new VertexPositionNormalTexture(x.position, normal, new Vector2(0, 0))).ToList(); var indices = new List <int>(); for (int i = 0; i < item.Length - 2; i++) { indices.Add(verticesAdded); indices.Add(verticesAdded + i + 1); indices.Add(verticesAdded + i + 2); } buffer.AddVertices(vertices); buffer.AddIndices(indices); verticesAdded += vertices.Count(); } }
public void RecalculateEverything() { if (buffer != null) { buffer.Dispose(); } buffer = new DynamicVertexIndexBuffer <VertexPositionColor>(); Dictionary <VertexData, int> verticesAdded = new Dictionary <VertexData, int>(); foreach (var item in items) { foreach (var v in item) { if (!verticesAdded.ContainsKey(v)) { buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(v.position, v.color) }); verticesAdded.Add(v, verticesAdded.Count); } } var indices = item.Select(x => verticesAdded[x]).ToList(); buffer.AddIndices(indices); } }
public void RecalculateEverything() { if (buffer != null) { buffer.Dispose(); } buffer = new DynamicVertexIndexBuffer <VertexPositionColorTexture>(); int verticesAdded = 0; foreach (var item in items) { var vertices = new List <VertexPositionColorTexture>(); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(0, 0))); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(1, 0))); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(1, 1))); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(0, 1))); var indices = new List <int>(); indices.Add(verticesAdded * 4); indices.Add(verticesAdded * 4 + 1); indices.Add(verticesAdded * 4 + 2); indices.Add(verticesAdded * 4); indices.Add(verticesAdded * 4 + 2); indices.Add(verticesAdded * 4 + 3); buffer.AddVertices(vertices); buffer.AddIndices(indices); verticesAdded++; } }
public PlaneGrid() { int count = 0; for (int i = -10; i <= 10; i++) { Color color = Color.White; if (i == 0) { color = new Color(0, 0, 255); // z-axis } buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(Vector3.Right * i + Vector3.Forward * 10, color) }); buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(Vector3.Right * i + Vector3.Backward * 10, color) }); if (i == 0) { color = new Color(255, 0, 0); // x-axis } buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(Vector3.Forward * i + Vector3.Right * 10, color) }); buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(Vector3.Forward * i + Vector3.Left * 10, color) }); buffer.AddIndices(new List <int>() { count * 4, count * 4 + 1, count * 4 + 2, count * 4 + 3 }); count++; } // y-axis buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(Vector3.Up * 10, new Color(0, 255, 0)) }); buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(Vector3.Down * 10, new Color(0, 255, 0)) }); buffer.AddIndices(new List <int>() { count * 4, count * 4 + 1 }); }