|
|
@ -33,16 +33,18 @@ namespace SemiColinGames { |
|
|
|
GC.SuppressFinalize(this); |
|
|
|
} |
|
|
|
|
|
|
|
public void Update(Player player, AABB[] collisionTargets) { |
|
|
|
Vector2 eyePos = player.EyePosition; |
|
|
|
float visionRange = player.VisionRange; |
|
|
|
Vector2 ray = player.VisionRay; |
|
|
|
float fov = player.FieldOfView; |
|
|
|
public void Update(NPC[] npcs, AABB[] collisionTargets) { |
|
|
|
NPC npc = npcs[0]; |
|
|
|
|
|
|
|
Vector2 eyePos = npc.EyePosition; |
|
|
|
float visionRange = npc.VisionRange; |
|
|
|
Vector2 ray = npc.VisionRay; |
|
|
|
float fov = npc.FieldOfView; |
|
|
|
|
|
|
|
float visionRangeSq = visionRange * visionRange; |
|
|
|
float fovStep = fov / (NUM_EDGE_VERTICES - 1); |
|
|
|
|
|
|
|
coneVertices[0] = new VertexPositionColor(new Vector3(player.EyePosition, 0), color); |
|
|
|
coneVertices[0] = new VertexPositionColor(new Vector3(npc.EyePosition, 0), color); |
|
|
|
for (int i = 0; i < NUM_EDGE_VERTICES; i++) { |
|
|
|
float angle = -fov / 2 + fovStep * i; |
|
|
|
Vector2 rotated = ray.Rotate(angle); |
|
|
@ -52,7 +54,7 @@ namespace SemiColinGames { |
|
|
|
Vector2 halfTileSize = new Vector2(World.TileSize / 2.0f, World.TileSize / 2.0f); |
|
|
|
for (int j = 0; j < collisionTargets.Length; j++) { |
|
|
|
AABB box = collisionTargets[j]; |
|
|
|
if (Math.Abs(box.Position.X - player.Position.X) > visionRange + halfTileSize.X) { |
|
|
|
if (Math.Abs(box.Position.X - npc.Position.X) > visionRange + halfTileSize.X) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
Vector2 delta = Vector2.Add(halfTileSize, Vector2.Subtract(box.Position, eyePos)); |
|
|
|