csharp/Alan-FGR/aelum/Farseer/Farseer%20Physics%20Engine%203.5/Common/PhysicsLogic/FilterData.cs

FilterData.cs
using FarseerPhysics.Dynamics;

namespace FarseerPhysics.Common.PhysicsLogic
{
    /// 
    /// Contains filter data that can determine whether an object should be processed or not.
    /// 
    public abstract clast FilterData
    {
        /// 
        /// Disable the logic on specific categories.
        /// Category.None by default.
        /// 
        public Category DisabledOnCategories = Category.None;

        /// 
        /// Disable the logic on specific groups
        /// 
        public int DisabledOnGroup;

        /// 
        /// Enable the logic on specific categories
        /// Category.All by default.
        /// 
        public Category EnabledOnCategories = Category.All;

        /// 
        /// Enable the logic on specific groups.
        /// 
        public int EnabledOnGroup;

        /// 
        /// 
        /// 
        /// 
        /// 
        public virtual bool IsActiveOn(Body body)
        {
            if (body == null || !body.Enabled || body.IsStatic)
                return false;

            if (body.FixtureList == null)
                return false;

            foreach (Fixture fixture in body.FixtureList)
            {
                //Disable
                if ((fixture.CollisionGroup == DisabledOnGroup) && fixture.CollisionGroup != 0 && DisabledOnGroup != 0)
                    return false;

                if ((fixture.CollisionCategories & DisabledOnCategories) != Category.None)
                    return false;

                if (EnabledOnGroup != 0 || EnabledOnCategories != Category.All)
                {
                    //Enable
                    if ((fixture.CollisionGroup == EnabledOnGroup) && fixture.CollisionGroup != 0 && EnabledOnGroup != 0)
                        return true;

                    if ((fixture.CollisionCategories & EnabledOnCategories) != Category.None &&
                        EnabledOnCategories != Category.All)
                        return true;
                }
                else
                {
                    return true;
                }
            }

            return false;
        }

        /// 
        /// Adds the category.
        /// 
        /// The category.
        public void AddDisabledCategory(Category category)
        {
            DisabledOnCategories |= category;
        }

        /// 
        /// Removes the category.
        /// 
        /// The category.
        public void RemoveDisabledCategory(Category category)
        {
            DisabledOnCategories &= ~category;
        }

        /// 
        /// Determines whether this body ignores the the specified controller.
        /// 
        /// The category.
        /// 
        /// 	true if the object has the specified category; otherwise, false.
        /// 
        public bool IsInDisabledCategory(Category category)
        {
            return (DisabledOnCategories & category) == category;
        }

        /// 
        /// Adds the category.
        /// 
        /// The category.
        public void AddEnabledCategory(Category category)
        {
            EnabledOnCategories |= category;
        }

        /// 
        /// Removes the category.
        /// 
        /// The category.
        public void RemoveEnabledCategory(Category category)
        {
            EnabledOnCategories &= ~category;
        }

        /// 
        /// Determines whether this body ignores the the specified controller.
        /// 
        /// The category.
        /// 
        /// 	true if the object has the specified category; otherwise, false.
        /// 
        public bool IsInEnabledInCategory(Category category)
        {
            return (EnabledOnCategories & category) == category;
        }
    }
}