/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Transform.cs
ViewVC logotype

Annotation of /trunk/gr2lib/core/coretypes/implementation/Transform.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (hide annotations) (download)
Thu Jul 29 07:47:26 2010 UTC (9 years, 4 months ago) by william
File size: 5427 byte(s)
bulk commit

1 william 83 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using gr2lib.core.interfaces;
6     using gr2lib.core.helpers;
7 william 196 using System.ComponentModel;
8     using System.Drawing.Design;
9     using gr2lib.core.ui.typeeditors;
10 william 83
11     namespace gr2lib.core.coretypes.implementation
12     {
13 william 186 /// <summary>
14     /// Transform class
15     /// </summary>
16 william 196 [Editor(typeof(TransformDialogEditor),typeof(UITypeEditor))]
17 william 83 public class Transform : ITransform
18     {
19 william 186 /// <summary>
20     /// default constructor
21     /// </summary>
22 william 83 public Transform()
23     {
24     this.Initialize();
25     }
26    
27    
28    
29     private void Initialize()
30     {
31     this.MakeIdentity();
32     }
33 william 186 /// <summary>
34     /// Gets string representation
35     /// </summary>
36     /// <returns></returns>
37 william 83 public override string ToString()
38     {
39     StringBuilder builder = new StringBuilder();
40     builder.Append("{");
41     builder.AppendFormat("{0}", this.Dimensions);
42     builder.Append(", {");
43     builder.AppendFormat("{0}, {1}, {2}", this.Origin.x, this.Origin.y, this.Origin.z);
44     builder.Append("}, {");
45     builder.AppendFormat("{0}, {1}, {2}, {3}", this.Rotation.v.x, this.Rotation.v.y, this.Rotation.v.z, this.Rotation.n);
46     builder.Append("}, {");
47     builder.AppendFormat("{0:F2}, {1:F2}, {2:F2}, {3:F2}, {4:F2}, {5:F2}, {6:F2}, {7:F2}, {8:F2}",
48     this.Scale.right.x,
49     this.Scale.right.y,
50     this.Scale.right.z,
51     this.Scale.up.x,
52     this.Scale.up.y,
53     this.Scale.up.z,
54     this.Scale.at.x,
55     this.Scale.at.y,
56     this.Scale.at.z);
57     builder.Append("}}");
58     return builder.ToString();
59     }
60    
61     internal static Transform ReadFromMemory(IntPtr pointer)
62     {
63     native.Transform native = Helpers.ReadFromMemory<native.Transform>(pointer);
64     return ReadFromNative(native);
65     }
66    
67     internal static Transform ReadFromNative(native.Transform native)
68     {
69     Transform managed = new Transform();
70     managed.Dimensions = native.Dimensions;
71 william 95 managed.Origin = new Vector3(native.Origin.X, native.Origin.Y, native.Origin.Z);
72 william 83 managed.Rotation = new Quaternion(native.Rotation.X, native.Rotation.Y, native.Rotation.Z, native.Rotation.W);
73     managed.Scale = new Matrix33(native.Scale);
74     managed.Matrix = managed.ToMatrix44();
75     return managed;
76     }
77    
78     #region ITransform Members
79 william 186 /// <summary>
80     /// ToMatrix44
81     /// </summary>
82     /// <returns></returns>
83 william 83 public Matrix44 ToMatrix44()
84     {
85     Matrix33 rotator = this.Rotation.Inverse().ToMatrix33();
86     rotator *= this.Scale;
87     Matrix44 result = rotator.ToMatrix44();
88     result.pos = this.Origin.P4;
89     return result;
90     }
91 william 186 /// <summary>
92     /// ToMatrix44EA
93     /// </summary>
94     /// <returns></returns>
95 william 83 public Matrix44 ToMatrix44EA()
96     {
97     Matrix33 rotator = this.Rotation.Inverse().ToMatrix33EA();
98     rotator *= this.Scale;
99     Matrix44 result = rotator.ToMatrix44();
100     result.pos = this.Origin.P4;
101     return result;
102     }
103 william 186 /// <summary>
104     /// MakeIdentity
105     /// </summary>
106 william 83 public void MakeIdentity()
107     {
108     this.Dimensions = 7;
109     this.Origin = new Vector3(0f, 0f, 0f);
110     this.Rotation = new Quaternion(0f, 0f, 0f, 1f);
111     this.Scale = Matrix33.CopyMatrix(Matrix33.Identity);
112     this.Matrix = Matrix44.CopyMatrix(Matrix44.Identity);
113     }
114 william 186 /// <summary>
115     /// MakeIdentity
116     /// </summary>
117     /// <param name="t">the transform to return</param>
118 william 83 public void MakeIdentity(out Transform t)
119     {
120     t = new Transform();
121     t.Dimensions = 7;
122     t.Origin = new Vector3(0f, 0f, 0f);
123     t.Rotation = new Quaternion(0f, 0f, 0f, 1f);
124     t.Scale = Matrix33.CopyMatrix(Matrix33.Identity);
125     t.Matrix = Matrix44.CopyMatrix(Matrix44.Identity);
126     }
127    
128     private Int32 _Dimensions;
129     private Vector3 _Origin;
130     private Quaternion _Rotation;
131     private Matrix33 _Scale;
132     private Matrix44 _Matrix;
133 william 186 /// <summary>
134     /// Dimensions
135     /// </summary>
136 william 83 public Int32 Dimensions { get { return _Dimensions; } set { _Dimensions = value; } }
137 william 186 /// <summary>
138     /// Origin
139     /// </summary>
140 william 83 public Vector3 Origin { get { return _Origin; } set { _Origin = value; } }
141 william 186 /// <summary>
142     /// Rotation
143     /// </summary>
144 william 83 public Quaternion Rotation { get { return _Rotation; } set { _Rotation = value; } }
145 william 186 /// <summary>
146     /// Scale
147     /// </summary>
148 william 83 public Matrix33 Scale { get { return _Scale; } set { _Scale = value; } }
149 william 186 /// <summary>
150     /// Matrix
151     /// </summary>
152 william 83 public Matrix44 Matrix { get { return _Matrix; } set { _Matrix = value; } }
153     #endregion
154     }
155     }

  ViewVC Help
Powered by ViewVC 1.1.22