/[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 186 - (hide annotations) (download)
Sat Jul 24 02:23:18 2010 UTC (9 years, 4 months ago) by william
File size: 5266 byte(s)
continue to add xml documentation

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

  ViewVC Help
Powered by ViewVC 1.1.22