source: 2014/24/EemeliK/Zombieland/Jypeli/Physics2DDotNet/DataTypes/Matrices.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 System.Collections.ObjectModel;
35using AdvanceMath;
36using AdvanceMath.Geometry2D;
37
38
39namespace Physics2DDotNet
40{
41#if !(WINDOWS_PHONE || XBOX)
42    [Serializable]
43#endif
44    public sealed class Matrices : IDuplicateable<Matrices>
45    {
46
47        /// <summary>
48        /// The matrix that is multiplied against to transform a vertex from relative
49        /// to the Body to the vertex relative to the World.
50        /// </summary>
51        public Matrix2x3 ToWorld;
52        /// <summary>
53        /// The matrix that is multiplied against to transform a vertex from relative
54        /// to the World to the vertex relative to the Body.
55        /// </summary>
56        public Matrix2x3 ToBody;
57        /// <summary>
58        /// The matrix that is multiplied against to transform a normal (unit vector) from relative
59        /// to the Body to the normal relative to the World.
60        /// </summary>
61        public Matrix2x2 ToWorldNormal;
62        /// The matrix that is multiplied against to transform a normal (unit vector) from relative
63        /// to the World to the normal relative to the Body.
64        /// </summary>
65        public Matrix2x2 ToBodyNormal;
66        public Matrices()
67        {
68            this.ToWorld = Matrix2x3.Identity;
69            this.ToBody = Matrix2x3.Identity;
70            this.ToWorldNormal = Matrix2x2.Identity;
71            this.ToBodyNormal = Matrix2x2.Identity;
72        }
73        private Matrices(Matrices copy)
74        {
75            this.ToWorld = copy.ToWorld;
76            this.ToBody = copy.ToBody;
77            this.ToWorldNormal = copy.ToWorldNormal;
78            this.ToBodyNormal = copy.ToBodyNormal;
79        }
80        public void SetToWorld(ref Matrix2x3 toWorld)
81        {
82            this.ToWorld = toWorld;
83            Matrix2x3.Invert(ref toWorld, out ToBody);
84            Matrix2x2.CreateNormal(ref toWorld, out ToWorldNormal);
85            Matrix2x2.CreateNormal(ref ToBody, out ToBodyNormal);
86        }
87        public Matrices Duplicate()
88        {
89            return new Matrices(this);
90        }
91        public object Clone()
92        {
93            return Duplicate();
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.