|
|
@ -5,20 +5,20 @@ using System; |
|
|
|
namespace SemiColinGames { |
|
|
|
class LinesOfSight : IDisposable { |
|
|
|
|
|
|
|
const int numEdgeVertices = 60; |
|
|
|
const int NUM_EDGE_VERTICES = 60; |
|
|
|
|
|
|
|
readonly VertexBuffer vertexBuffer; |
|
|
|
readonly IndexBuffer indexBuffer; |
|
|
|
// coneVertices[0] is the eye position; the rest are the edge vertices.
|
|
|
|
readonly VertexPositionColor[] coneVertices = new VertexPositionColor[numEdgeVertices + 1]; |
|
|
|
readonly VertexPositionColor[] coneVertices = new VertexPositionColor[NUM_EDGE_VERTICES + 1]; |
|
|
|
// The number of total triangles drawn is one less than the number of edge points.
|
|
|
|
readonly int[] indices = new int[(numEdgeVertices - 1) * 3]; |
|
|
|
readonly int[] indices = new int[(NUM_EDGE_VERTICES - 1) * 3]; |
|
|
|
|
|
|
|
Color color = Color.FromNonPremultiplied(new Vector4(0, 0, 1, 0.6f)); |
|
|
|
|
|
|
|
public LinesOfSight(GraphicsDevice graphics) { |
|
|
|
vertexBuffer = new VertexBuffer( |
|
|
|
graphics, typeof(VertexPositionColor), numEdgeVertices * 3, BufferUsage.WriteOnly); |
|
|
|
graphics, typeof(VertexPositionColor), NUM_EDGE_VERTICES * 3, BufferUsage.WriteOnly); |
|
|
|
indexBuffer = new IndexBuffer( |
|
|
|
graphics, typeof(int), indices.Length, BufferUsage.WriteOnly); |
|
|
|
} |
|
|
@ -40,10 +40,10 @@ namespace SemiColinGames { |
|
|
|
float fov = player.FieldOfView; |
|
|
|
|
|
|
|
float visionRangeSq = visionRange * visionRange; |
|
|
|
float fovStep = fov / (numEdgeVertices - 1); |
|
|
|
float fovStep = fov / (NUM_EDGE_VERTICES - 1); |
|
|
|
|
|
|
|
coneVertices[0] = new VertexPositionColor(new Vector3(player.EyePosition, 0), color); |
|
|
|
for (int i = 0; i < numEdgeVertices; i++) { |
|
|
|
for (int i = 0; i < NUM_EDGE_VERTICES; i++) { |
|
|
|
float angle = -fov / 2 + fovStep * i; |
|
|
|
Vector2 rotated = ray.Rotate(angle); |
|
|
|
Vector2 closestHit = Vector2.Add(eyePos, rotated); |
|
|
@ -77,7 +77,7 @@ namespace SemiColinGames { |
|
|
|
|
|
|
|
public void Draw(GraphicsDevice graphics, BasicEffect lightingEffect) { |
|
|
|
|
|
|
|
for (int i = 0; i < numEdgeVertices - 1; i++) { |
|
|
|
for (int i = 0; i < NUM_EDGE_VERTICES - 1; i++) { |
|
|
|
indices[i * 3] = 0; |
|
|
|
indices[i * 3 + 1] = i + 1; |
|
|
|
indices[i * 3 + 2] = i + 2; |
|
|
|