source: 2014/24/EemeliK/Zombieland/Jypeli/Physics2DDotNet/Ignorers/AdvGroupIgnorer.cs @ 5974

Revision 5974, 3.2 KB checked in by empaheik, 4 years ago (diff)
Line 
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26#if UseDouble
27using Scalar = System.Double;
28#else
29using Scalar = System.Single;
30#endif
31using System;
32
33namespace Physics2DDotNet.Ignorers
34{
35    /// <summary>
36    /// A collision ignorer that uses group numbers to do collision ignoring.
37    /// If a object is member of a group that the other body is ignoring then they will not collide.
38    /// </summary>
39#if !(WINDOWS_PHONE || XBOX)
40    [Serializable]
41#endif
42    public class AdvGroupIgnorer : Ignorer
43#if !(WINDOWS_PHONE || XBOX)
44        , ICloneable
45#endif
46    {
47        GroupCollection groups;
48        GroupCollection ignoredGroups;
49        public AdvGroupIgnorer()
50        {
51            this.groups = new GroupCollection();
52            this.ignoredGroups = new GroupCollection();
53        }
54        protected AdvGroupIgnorer(AdvGroupIgnorer copy)
55            : base(copy)
56        {
57            this.groups = new GroupCollection(copy.groups);
58            this.groups = new GroupCollection(copy.ignoredGroups);
59        }
60        public override bool BothNeeded
61        {
62            get { return true; }
63        }
64        public GroupCollection Groups { get { return groups; } }
65        public GroupCollection IgnoredGroups { get { return ignoredGroups; } }
66        public bool CanCollide(AdvGroupIgnorer other)
67        {
68            if (other == null) { throw new ArgumentNullException("other"); }
69            return CanCollideInternal(other);
70        }
71        private bool CanCollideInternal(AdvGroupIgnorer other)
72        {
73            return !GroupCollection.Intersect(ignoredGroups, other.groups);
74        }
75        protected override bool CanCollide(Body thisBody, Body otherBody, Ignorer other)
76        {
77            AdvGroupIgnorer value = other as AdvGroupIgnorer;
78            return
79                value == null ||
80                CanCollideInternal(value);
81        }
82        public virtual object Clone()
83        {
84            return new AdvGroupIgnorer(this);
85        }
86    }
87}
Note: See TracBrowser for help on using the repository browser.