PerceiverElement.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using fun.Basics.Shapes;
  2. using fun.Communication;
  3. using fun.Core;
  4. using OpenTK;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using Environment = fun.Core.Environment;
  9. namespace fun.Basics
  10. {
  11. /// <summary>
  12. /// Defines the element of an entity, which is able to draw other seen entities on the monitor.
  13. /// </summary>
  14. public sealed class PerceiverElement : Element, IPerceiver
  15. {
  16. private readonly TransformElement transform;
  17. public IEnumerable<Entity> Seen { get; private set; }
  18. public Sphere Sphere{ get; set; }
  19. /// <summary>
  20. /// Creates a camera-Object.
  21. /// </summary>
  22. /// <param name="environment">environment of element</param>
  23. /// <param name="entity">entity of element</param>
  24. public PerceiverElement(Environment environment, Entity entity)
  25. : base(environment, entity)
  26. {
  27. if (!entity.ContainsElement<TransformElement>())
  28. // TODO: write message
  29. throw new NotImplementedException();
  30. transform = entity.GetElement<TransformElement>() as TransformElement;
  31. Sphere = new Sphere(Vector3.Zero, 100f);
  32. }
  33. public override void Initialize()
  34. {
  35. }
  36. public override void Update(double time)
  37. {
  38. // TODO: effizienter gestalten
  39. Seen = environment.Entities
  40. .Where(e =>
  41. Sphere.Contains((e.GetElement<TransformElement>() as TransformElement).Position - transform.Position) &&
  42. e.ContainsElement<PerceivedElement>());
  43. }
  44. }
  45. }