|
@ -14,16 +14,19 @@ namespace SemiColinGames { |
|
|
readonly VertexBuffer vertexBuffer; |
|
|
readonly VertexBuffer vertexBuffer; |
|
|
readonly IndexBuffer indexBuffer; |
|
|
readonly IndexBuffer indexBuffer; |
|
|
readonly bool[] coneEnabled = new bool[MAX_NPCS]; |
|
|
readonly bool[] coneEnabled = new bool[MAX_NPCS]; |
|
|
// coneVertices[i][0] is the eye position; the rest are the edge vertices.
|
|
|
|
|
|
readonly VertexPositionColor[][] coneVertices = new VertexPositionColor[MAX_NPCS][]; |
|
|
|
|
|
|
|
|
// coneFillVertices[i][0] is the eye position; the rest are the edge vertices.
|
|
|
|
|
|
readonly VertexPositionColor[][] coneFillVertices = new VertexPositionColor[MAX_NPCS][]; |
|
|
|
|
|
readonly VertexPositionColor[][] coneOutlineVertices = new VertexPositionColor[MAX_NPCS][]; |
|
|
// 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.25f)); |
|
|
|
|
|
|
|
|
Color fill = Color.FromNonPremultiplied(new Vector4(1, 1, 1, 0.1f)); |
|
|
|
|
|
Color outline = Color.FromNonPremultiplied(new Vector4(1, 0, 0, 0.5f)); |
|
|
|
|
|
|
|
|
public LinesOfSight(GraphicsDevice graphics) { |
|
|
public LinesOfSight(GraphicsDevice graphics) { |
|
|
for (int i = 0; i < MAX_NPCS; i++) { |
|
|
for (int i = 0; i < MAX_NPCS; i++) { |
|
|
coneVertices[i] = new VertexPositionColor[NUM_EDGE_VERTICES + 1]; |
|
|
|
|
|
|
|
|
coneFillVertices[i] = new VertexPositionColor[NUM_EDGE_VERTICES + 1]; |
|
|
|
|
|
coneOutlineVertices[i] = new VertexPositionColor[NUM_EDGE_VERTICES + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
vertexBuffer = new VertexBuffer( |
|
|
vertexBuffer = new VertexBuffer( |
|
@ -61,7 +64,10 @@ namespace SemiColinGames { |
|
|
float visionRangeSq = visionRange * visionRange; |
|
|
float visionRangeSq = visionRange * visionRange; |
|
|
float fovStep = fov / (NUM_EDGE_VERTICES - 1); |
|
|
float fovStep = fov / (NUM_EDGE_VERTICES - 1); |
|
|
|
|
|
|
|
|
coneVertices[index][0] = new VertexPositionColor(new Vector3(npc.EyePosition, 0), color); |
|
|
|
|
|
|
|
|
coneFillVertices[index][0] = |
|
|
|
|
|
new VertexPositionColor(new Vector3(npc.EyePosition, 0), fill); |
|
|
|
|
|
coneOutlineVertices[index][0] = |
|
|
|
|
|
new VertexPositionColor(new Vector3(npc.EyePosition, 0), outline); |
|
|
for (int i = 0; i < NUM_EDGE_VERTICES; i++) { |
|
|
for (int i = 0; i < NUM_EDGE_VERTICES; i++) { |
|
|
float angle = -fov / 2 + fovStep * i; |
|
|
float angle = -fov / 2 + fovStep * i; |
|
|
Vector2 rotated = ray.Rotate(angle); |
|
|
Vector2 rotated = ray.Rotate(angle); |
|
@ -87,8 +93,10 @@ namespace SemiColinGames { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
coneVertices[index][i + 1] = new VertexPositionColor( |
|
|
|
|
|
new Vector3((int) closestHit.X, (int) closestHit.Y, 0), color); |
|
|
|
|
|
|
|
|
coneFillVertices[index][i + 1] = new VertexPositionColor( |
|
|
|
|
|
new Vector3((int) closestHit.X, (int) closestHit.Y, 0), fill); |
|
|
|
|
|
coneOutlineVertices[index][i + 1] = new VertexPositionColor( |
|
|
|
|
|
new Vector3((int) closestHit.X, (int) closestHit.Y, 0), outline); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -104,7 +112,7 @@ namespace SemiColinGames { |
|
|
if (!coneEnabled[npcIndex]) { |
|
|
if (!coneEnabled[npcIndex]) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
vertexBuffer.SetData(coneVertices[npcIndex]); |
|
|
|
|
|
|
|
|
vertexBuffer.SetData(coneFillVertices[npcIndex]); |
|
|
indexBuffer.SetData(indices); |
|
|
indexBuffer.SetData(indices); |
|
|
graphics.SetVertexBuffer(vertexBuffer); |
|
|
graphics.SetVertexBuffer(vertexBuffer); |
|
|
graphics.Indices = indexBuffer; |
|
|
graphics.Indices = indexBuffer; |
|
@ -125,15 +133,13 @@ namespace SemiColinGames { |
|
|
if (!coneEnabled[npcIndex]) { |
|
|
if (!coneEnabled[npcIndex]) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
vertexBuffer.SetData(coneVertices[npcIndex]); |
|
|
|
|
|
|
|
|
vertexBuffer.SetData(coneOutlineVertices[npcIndex]); |
|
|
indexBuffer.SetData(indices); |
|
|
indexBuffer.SetData(indices); |
|
|
graphics.SetVertexBuffer(vertexBuffer); |
|
|
graphics.SetVertexBuffer(vertexBuffer); |
|
|
graphics.Indices = indexBuffer; |
|
|
graphics.Indices = indexBuffer; |
|
|
|
|
|
|
|
|
foreach (EffectPass pass in lightingEffect.CurrentTechnique.Passes) { |
|
|
foreach (EffectPass pass in lightingEffect.CurrentTechnique.Passes) { |
|
|
pass.Apply(); |
|
|
pass.Apply(); |
|
|
// TODO: just draw a single opaque outline.
|
|
|
|
|
|
for (int i = 0; i < 4; i++) { |
|
|
|
|
|
graphics.DrawIndexedPrimitives( |
|
|
graphics.DrawIndexedPrimitives( |
|
|
PrimitiveType.LineStrip, 0, 0, NUM_EDGE_VERTICES + 1); |
|
|
PrimitiveType.LineStrip, 0, 0, NUM_EDGE_VERTICES + 1); |
|
|
} |
|
|
} |
|
@ -141,4 +147,3 @@ namespace SemiColinGames { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|