1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using FarseerPhysics.Dynamics;
- namespace FarseerPhysics.Controllers
- {
- [Flags]
- public enum ControllerType
- {
- GravityController = (1 << 0),
- VelocityLimitController = (1 << 1),
- AbstractForceController = (1 << 2),
- BuoyancyController = (1 << 3),
- }
- public struct ControllerFilter
- {
- public ControllerType ControllerFlags;
- /// <summary>
- /// Ignores the controller. The controller has no effect on this body.
- /// </summary>
- /// <param name="controller">The controller type.</param>
- public void IgnoreController(ControllerType controller)
- {
- ControllerFlags |= controller;
- }
- /// <summary>
- /// Restore the controller. The controller affects this body.
- /// </summary>
- /// <param name="controller">The controller type.</param>
- public void RestoreController(ControllerType controller)
- {
- ControllerFlags &= ~controller;
- }
- /// <summary>
- /// Determines whether this body ignores the the specified controller.
- /// </summary>
- /// <param name="controller">The controller type.</param>
- /// <returns>
- /// <c>true</c> if the body has the specified flag; otherwise, <c>false</c>.
- /// </returns>
- public bool IsControllerIgnored(ControllerType controller)
- {
- return (ControllerFlags & controller) == controller;
- }
- }
- public abstract class Controller : FilterData
- {
- public bool Enabled;
- public World World;
- private ControllerType _type;
- public Controller(ControllerType controllerType)
- {
- _type = controllerType;
- }
- public override bool IsActiveOn(Body body)
- {
- if (body.ControllerFilter.IsControllerIgnored(_type))
- return false;
- return base.IsActiveOn(body);
- }
- public abstract void Update(float dt);
- }
- }
|