source: 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/Physics2DDotNet/Detectors/BruteForceDetector.cs @ 4507

Revision 4507, 2.3 KB checked in by anlakane, 6 years ago (diff)

Talletus.

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
27#if UseDouble
28using Scalar = System.Double;
29#else
30using Scalar = System.Single;
31#endif
32using System;
33using System.Collections.Generic;
34
35using AdvanceMath.Geometry2D;
36
37namespace Physics2DDotNet.Detectors
38{
39#if !(WINDOWS_PHONE || XBOX)
40    [Serializable]
41#endif
42    public sealed class BruteForceDetector : BroadPhaseCollisionDetector
43    {
44        public override void Detect(TimeStep step)
45        {
46            for (int index1 = 0; index1 < this.Bodies.Count; index1++)
47            {
48                Body body1 = this.Bodies[index1];
49                for (int index2 = index1 + 1; index2 < this.Bodies.Count; index2++)
50                {
51                    Body body2 = this.Bodies[index2];
52                    if ((body1.Mass.MassInv != 0 || body2.Mass.MassInv != 0) &&
53                            Body.CanCollide(body1, body2) &&
54                            body1.Rectangle.Intersects(body2.Rectangle))
55                    {
56                        OnCollision(step, body1, body2);
57                    }
58                }
59            }
60        }
61    }
62
63}
Note: See TracBrowser for help on using the repository browser.