LinesOfSight: draw outlines around the vision cones.

This commit is contained in:
Colin McMillen 2020-03-09 16:13:52 -04:00
parent 06eac128c2
commit 275e535eac

View File

@ -19,7 +19,7 @@ namespace SemiColinGames {
// The number of total triangles drawn is one less than the number of edge points. // The number of total triangles drawn is one less than the number of edge points.
readonly int[] indices = new int[(NUM_EDGE_VERTICES - 1) * 3]; readonly int[] indices = new int[(NUM_EDGE_VERTICES - 1) * 3];
Color color = Color.FromNonPremultiplied(new Vector4(1, 0, 0, 0.5f)); Color color = Color.FromNonPremultiplied(new Vector4(1, 0, 0, 0.25f));
public LinesOfSight(GraphicsDevice graphics) { public LinesOfSight(GraphicsDevice graphics) {
for (int i = 0; i < MAX_NPCS; i++) { for (int i = 0; i < MAX_NPCS; i++) {
@ -88,11 +88,13 @@ namespace SemiColinGames {
} }
} }
coneVertices[index][i + 1] = new VertexPositionColor(new Vector3(closestHit, 0), color); coneVertices[index][i + 1] = new VertexPositionColor(
new Vector3((int) closestHit.X, (int) closestHit.Y, 0), color);
} }
} }
public void Draw(GraphicsDevice graphics, BasicEffect lightingEffect) { public void Draw(GraphicsDevice graphics, BasicEffect lightingEffect) {
// Draw the cones themselves.
for (int i = 0; i < NUM_EDGE_VERTICES - 1; i++) { for (int i = 0; i < NUM_EDGE_VERTICES - 1; i++) {
indices[i * 3] = 0; indices[i * 3] = 0;
indices[i * 3 + 1] = i + 1; indices[i * 3 + 1] = i + 1;
@ -113,6 +115,31 @@ namespace SemiColinGames {
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indices.Length / 3); graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indices.Length / 3);
} }
} }
// Draw the outlines of the cones.
for (int i = 0; i <= NUM_EDGE_VERTICES; i++) {
indices[i] = i;
}
indices[NUM_EDGE_VERTICES + 1] = 0;
for (int npcIndex = 0; npcIndex < MAX_NPCS; npcIndex++) {
if (!coneEnabled[npcIndex]) {
continue;
}
vertexBuffer.SetData(coneVertices[npcIndex]);
indexBuffer.SetData(indices);
graphics.SetVertexBuffer(vertexBuffer);
graphics.Indices = indexBuffer;
foreach (EffectPass pass in lightingEffect.CurrentTechnique.Passes) {
pass.Apply();
// TODO: just draw a single opaque outline.
for (int i = 0; i < 4; i++) {
graphics.DrawIndexedPrimitives(
PrimitiveType.LineStrip, 0, 0, NUM_EDGE_VERTICES + 1);
}
}
}
} }
} }
} }