PhysicsLogic.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using FarseerPhysics.Dynamics;
  3. namespace FarseerPhysics.Common.PhysicsLogic
  4. {
  5. [Flags]
  6. public enum PhysicsLogicType
  7. {
  8. Explosion = (1 << 0)
  9. }
  10. public struct PhysicsLogicFilter
  11. {
  12. public PhysicsLogicType ControllerIgnores;
  13. /// <summary>
  14. /// Ignores the controller. The controller has no effect on this body.
  15. /// </summary>
  16. /// <param name="type">The logic type.</param>
  17. public void IgnorePhysicsLogic(PhysicsLogicType type)
  18. {
  19. ControllerIgnores |= type;
  20. }
  21. /// <summary>
  22. /// Restore the controller. The controller affects this body.
  23. /// </summary>
  24. /// <param name="type">The logic type.</param>
  25. public void RestorePhysicsLogic(PhysicsLogicType type)
  26. {
  27. ControllerIgnores &= ~type;
  28. }
  29. /// <summary>
  30. /// Determines whether this body ignores the the specified controller.
  31. /// </summary>
  32. /// <param name="type">The logic type.</param>
  33. /// <returns>
  34. /// <c>true</c> if the body has the specified flag; otherwise, <c>false</c>.
  35. /// </returns>
  36. public bool IsPhysicsLogicIgnored(PhysicsLogicType type)
  37. {
  38. return (ControllerIgnores & type) == type;
  39. }
  40. }
  41. public abstract class PhysicsLogic : FilterData
  42. {
  43. private PhysicsLogicType _type;
  44. public World World;
  45. public override bool IsActiveOn(Body body)
  46. {
  47. if (body.PhysicsLogicFilter.IsPhysicsLogicIgnored(_type))
  48. return false;
  49. return base.IsActiveOn(body);
  50. }
  51. public PhysicsLogic(World world, PhysicsLogicType type)
  52. {
  53. _type = type;
  54. World = world;
  55. }
  56. }
  57. }