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

Revision 5974, 3.5 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
32using System;
33using System.Collections.Generic;
34using AdvanceMath;
35using System.Runtime.Serialization;
36namespace Physics2DDotNet
37{
38    /// <summary>
39    /// This is a Proxy. That keeps 2 bodies velocities synchronized.
40    /// </summary>
41#if !(WINDOWS_PHONE || XBOX)
42    [Serializable]
43#endif
44    public sealed class BodyProxy 
45#if !WINDOWS_PHONE
46        : IDeserializationCallback
47#endif
48    {
49        Body body1;
50        Body body2;
51        internal Matrix2x2 transformation;
52#if !WINDOWS_PHONE
53        [NonSerialized]
54#endif
55        internal LinkedListNode<BodyProxy> node;
56        internal BodyProxy invertedTwin;
57        internal BodyProxy(Body body1, Body body2, Matrix2x2 transformaiton)
58        {
59            this.body1 = body1;
60            this.body2 = body2;
61            this.transformation = transformaiton;
62            this.node = new LinkedListNode<BodyProxy>(this);
63        }
64        /// <summary>
65        /// This is the other body to be Synchronized with.
66        /// </summary>
67        public Body Body1 { get { return body1; } }
68        /// <summary>
69        /// This is the other body to be Synchronized with.
70        /// </summary>
71        public Body Body2 { get { return body2; } }
72        /// <summary>
73        /// This is how the Velocity will be transformed when syncronized.
74        /// </summary>
75        public Matrix2x2 Transformation { get { return transformation; } }
76        /// <summary>
77        /// This is the inverted twin of this velocity. It's matrix will be invert of this one's.
78        /// And its body will be the body that contains this.
79        /// </summary>
80        public BodyProxy InvertedTwin { get { return invertedTwin; } }
81
82#if !WINDOWS_PHONE
83        void IDeserializationCallback.OnDeserialization(object sender)
84        {
85            if (this.invertedTwin == null) { return; }
86            for (LinkedListNode<BodyProxy> node = this.invertedTwin.body2.proxies.First;
87                node != null;
88                node = node.Next)
89            {
90                if (node.Value == this)
91                {
92                    this.node = node;
93                    return;
94                }
95            }
96            throw new SerializationException();
97        }
98#endif
99    }
100}
Note: See TracBrowser for help on using the repository browser.