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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show annotations) (download)
Sat Jul 17 05:10:22 2010 UTC (9 years, 5 months ago) by william
File size: 4255 byte(s)
add StackTrace support for error handling (to see the stack calls)

1 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 public class Transform : ITransform
11 {
12
13 public Transform()
14 {
15 this.Initialize();
16 }
17
18
19
20 private void Initialize()
21 {
22 this.MakeIdentity();
23 }
24
25 public override string ToString()
26 {
27 StringBuilder builder = new StringBuilder();
28 builder.Append("{");
29 builder.AppendFormat("{0}", this.Dimensions);
30 builder.Append(", {");
31 builder.AppendFormat("{0}, {1}, {2}", this.Origin.x, this.Origin.y, this.Origin.z);
32 builder.Append("}, {");
33 builder.AppendFormat("{0}, {1}, {2}, {3}", this.Rotation.v.x, this.Rotation.v.y, this.Rotation.v.z, this.Rotation.n);
34 builder.Append("}, {");
35 builder.AppendFormat("{0:F2}, {1:F2}, {2:F2}, {3:F2}, {4:F2}, {5:F2}, {6:F2}, {7:F2}, {8:F2}",
36 this.Scale.right.x,
37 this.Scale.right.y,
38 this.Scale.right.z,
39 this.Scale.up.x,
40 this.Scale.up.y,
41 this.Scale.up.z,
42 this.Scale.at.x,
43 this.Scale.at.y,
44 this.Scale.at.z);
45 builder.Append("}}");
46 return builder.ToString();
47 }
48
49 internal static Transform ReadFromMemory(IntPtr pointer)
50 {
51 native.Transform native = Helpers.ReadFromMemory<native.Transform>(pointer);
52 return ReadFromNative(native);
53 }
54
55 internal static Transform ReadFromNative(native.Transform native)
56 {
57 Transform managed = new Transform();
58 managed.Dimensions = native.Dimensions;
59 managed.Origin = new Vector3(native.Origin.X, native.Origin.Y, native.Origin.Z);
60 managed.Rotation = new Quaternion(native.Rotation.X, native.Rotation.Y, native.Rotation.Z, native.Rotation.W);
61 managed.Scale = new Matrix33(native.Scale);
62 managed.Matrix = managed.ToMatrix44();
63 return managed;
64 }
65
66 #region ITransform Members
67 public Matrix44 ToMatrix44()
68 {
69 Matrix33 rotator = this.Rotation.Inverse().ToMatrix33();
70 rotator *= this.Scale;
71 Matrix44 result = rotator.ToMatrix44();
72 result.pos = this.Origin.P4;
73 return result;
74 }
75
76 public Matrix44 ToMatrix44EA()
77 {
78 Matrix33 rotator = this.Rotation.Inverse().ToMatrix33EA();
79 rotator *= this.Scale;
80 Matrix44 result = rotator.ToMatrix44();
81 result.pos = this.Origin.P4;
82 return result;
83 }
84
85 public void MakeIdentity()
86 {
87 this.Dimensions = 7;
88 this.Origin = new Vector3(0f, 0f, 0f);
89 this.Rotation = new Quaternion(0f, 0f, 0f, 1f);
90 this.Scale = Matrix33.CopyMatrix(Matrix33.Identity);
91 this.Matrix = Matrix44.CopyMatrix(Matrix44.Identity);
92 }
93 public void MakeIdentity(out Transform t)
94 {
95 t = new Transform();
96 t.Dimensions = 7;
97 t.Origin = new Vector3(0f, 0f, 0f);
98 t.Rotation = new Quaternion(0f, 0f, 0f, 1f);
99 t.Scale = Matrix33.CopyMatrix(Matrix33.Identity);
100 t.Matrix = Matrix44.CopyMatrix(Matrix44.Identity);
101 }
102
103 private Int32 _Dimensions;
104 private Vector3 _Origin;
105 private Quaternion _Rotation;
106 private Matrix33 _Scale;
107 private Matrix44 _Matrix;
108
109 public Int32 Dimensions { get { return _Dimensions; } set { _Dimensions = value; } }
110 public Vector3 Origin { get { return _Origin; } set { _Origin = value; } }
111 public Quaternion Rotation { get { return _Rotation; } set { _Rotation = value; } }
112 public Matrix33 Scale { get { return _Scale; } set { _Scale = value; } }
113 public Matrix44 Matrix { get { return _Matrix; } set { _Matrix = value; } }
114 #endregion
115 }
116 }

  ViewVC Help
Powered by ViewVC 1.1.22