source: 2014/24/EemeliK/Zombieland/Jypeli/Physics2DDotNet/DataTypes/PhysicsState.cs @ 5974

Revision 5974, 4.6 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
27#if UseDouble
28using Scalar = System.Double;
29#else
30using Scalar = System.Single;
31#endif
32
33using System;
34using System.Runtime.InteropServices;
35
36using AdvanceMath;
37using AdvanceMath.Design;
38
39
40namespace Physics2DDotNet
41{
42    /// <summary>
43    /// This class holds the variables usually changed mulitple times  each update like the postion of an object.
44    /// </summary>
45    [StructLayout(LayoutKind.Sequential, Size = PhysicsState.Size)]
46    [AdvBrowsableOrder("Position,Velocity,Acceleration,ForceAccumulator")]
47#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE
48    [Serializable]
49    [System.ComponentModel.TypeConverter(typeof(AdvTypeConverter<PhysicsState>))]
50#endif
51    public sealed class PhysicsState : IDuplicateable<PhysicsState>
52    {
53        public const int Size = ALVector2D.Size * 4;
54        /// <summary>
55        /// This is Position and Orientation.
56        /// </summary>
57        /// <remarks>
58        /// <seealso href="http://en.wikipedia.org/wiki/Position"/>
59        /// </remarks>
60        [AdvBrowsable]
61        public ALVector2D Position;
62        /// <summary>
63        /// Angular and Linear Velocity.
64        /// </summary>
65        /// <remarks>
66        /// <seealso href="http://en.wikipedia.org/wiki/Velocity"/>
67        /// </remarks>
68        [AdvBrowsable]
69        public ALVector2D Velocity;
70        /// <summary>
71        /// Angular and Linear Acceleration.
72        /// </summary>
73        /// <remarks>
74        /// <seealso href="http://en.wikipedia.org/wiki/Acceleration"/>
75        /// </remarks>
76#if !WINDOWS_PHONE
77        [NonSerialized]
78#endif
79        [AdvBrowsable]
80        public ALVector2D Acceleration;
81        /// <summary>
82        /// Torque and Force
83        /// </summary>
84        /// <remarks>
85        /// <seealso href="http://en.wikipedia.org/wiki/Torque"/>
86        /// <seealso href="http://en.wikipedia.org/wiki/Force"/>
87        /// </remarks>
88#if !WINDOWS_PHONE
89        [NonSerialized]
90#endif
91        [AdvBrowsable]
92        public ALVector2D ForceAccumulator;
93        public PhysicsState()
94        {
95            this.Position = ALVector2D.Zero;
96            this.Velocity = ALVector2D.Zero;
97            this.Acceleration = ALVector2D.Zero;
98            this.ForceAccumulator = ALVector2D.Zero;
99        }
100        public PhysicsState(ALVector2D position)
101        {
102            this.Position = position;
103            this.Velocity = ALVector2D.Zero;
104            this.Acceleration = ALVector2D.Zero;
105            this.ForceAccumulator = ALVector2D.Zero;
106        }
107        public PhysicsState(ALVector2D position, ALVector2D velocity)
108        {
109            this.Position = position;
110            this.Velocity = velocity;
111            this.Acceleration = ALVector2D.Zero;
112            this.ForceAccumulator = ALVector2D.Zero;
113        }
114        public PhysicsState(PhysicsState state)
115        {
116            if (state == null) { throw new ArgumentNullException("state"); }
117            this.Position = state.Position;
118            this.Velocity = state.Velocity;
119            this.Acceleration = state.Acceleration;
120            this.ForceAccumulator = state.ForceAccumulator;
121        }
122
123        public PhysicsState Duplicate()
124        {
125            return new PhysicsState(this);
126        }
127        public object Clone()
128        {
129            return Duplicate();
130        }
131
132    }
133}
Note: See TracBrowser for help on using the repository browser.