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

Revision 4507, 2.5 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#if UseDouble
26using Scalar = System.Double;
27#else
28using Scalar = System.Single;
29#endif
30using System;
31
32using AdvanceMath;
33
34namespace Physics2DDotNet.PhysicsLogics
35{
36
37    /// <summary>
38    /// A Gravity Field that apply gravity pulling in one direction regardless of the Body's position with zero dropoff.
39    /// </summary>
40#if !(WINDOWS_PHONE || XBOX)
41    [Serializable]
42#endif
43    public sealed class GravityField : PhysicsLogic
44    {
45        Vector2D gravity;
46        /// <summary>
47        /// Creates a new GravityField Instance.
48        /// </summary>
49        /// <param name="gravity">The direction and magnitude of the gravity.</param>
50        /// <param name="lifeTime">A object Describing how long the object will be in the engine.</param>
51        public GravityField(Vector2D gravity, Lifespan lifetime)
52            : base(lifetime)
53        {
54            this.gravity = gravity;
55        }
56        protected internal override void RunLogic(TimeStep step)
57        {
58            foreach (Body e in this.Bodies)
59            {
60                if (e.IgnoresGravity ||
61                    e.IgnoresPhysicsLogics)
62                {
63                    continue;
64                }
65                Vector2D.Add(ref e.State.Acceleration.Linear, ref gravity, out e.State.Acceleration.Linear);
66
67            }
68        }
69    }
70}
Note: See TracBrowser for help on using the repository browser.