diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/HelperTypes.cs | 110 |
1 files changed, 25 insertions, 85 deletions
diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index 2cb8d04..7491782 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs | |||
@@ -29,70 +29,10 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Diagnostics; | 30 | using System.Diagnostics; |
31 | using System.Globalization; | 31 | using System.Globalization; |
32 | using OpenMetaverse; | ||
32 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
33 | using OpenSim.Region.Physics.Meshing; | 34 | using OpenSim.Region.Physics.Meshing; |
34 | 35 | ||
35 | public class Quaternion | ||
36 | { | ||
37 | public float x = 0; | ||
38 | public float y = 0; | ||
39 | public float z = 0; | ||
40 | public float w = 1; | ||
41 | |||
42 | public Quaternion() | ||
43 | { | ||
44 | |||
45 | } | ||
46 | public Quaternion(float x1, float y1, float z1, float w1) | ||
47 | { | ||
48 | x = x1; y = y1; z = z1; w = w1; | ||
49 | } | ||
50 | public Quaternion(Vertex axis, float angle) | ||
51 | { | ||
52 | // using (* 0.5) instead of (/2) | ||
53 | w = (float)Math.Cos(angle * 0.5f); | ||
54 | float sin = (float)Math.Sin(angle * 0.5f); | ||
55 | //x = axis.X * (float)Math.Sin(angle * 0.5f); | ||
56 | //y = axis.Y * (float)Math.Sin(angle * 0.5f); | ||
57 | //z = axis.Z * (float)Math.Sin(angle * 0.5f); | ||
58 | x = axis.X * sin; | ||
59 | y = axis.Y * sin; | ||
60 | z = axis.Z * sin; | ||
61 | normalize(); | ||
62 | } | ||
63 | public static Quaternion operator *(Quaternion a, Quaternion b) | ||
64 | { | ||
65 | Quaternion c = new Quaternion(); | ||
66 | c.x = a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y; | ||
67 | c.y = a.w * b.y + a.y * b.w + a.z * b.x - a.x * b.z; | ||
68 | c.z = a.w * b.z + a.z * b.w + a.x * b.y - a.y * b.x; | ||
69 | c.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z; | ||
70 | return c; | ||
71 | } | ||
72 | |||
73 | public void normalize() | ||
74 | { | ||
75 | //float mag = length(); | ||
76 | |||
77 | //w /= mag; | ||
78 | //x /= mag; | ||
79 | //y /= mag; | ||
80 | //z /= mag; | ||
81 | float iMag = 1.0f / length(); | ||
82 | |||
83 | w *= iMag; | ||
84 | x *= iMag; | ||
85 | y *= iMag; | ||
86 | z *= iMag; | ||
87 | } | ||
88 | public float length() | ||
89 | { | ||
90 | return (float)Math.Sqrt(w * w + x * x + y * y + z * z); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | |||
95 | |||
96 | public class Vertex : PhysicsVector, IComparable<Vertex> | 36 | public class Vertex : PhysicsVector, IComparable<Vertex> |
97 | { | 37 | { |
98 | public Vertex(float x, float y, float z) | 38 | public Vertex(float x, float y, float z) |
@@ -129,34 +69,34 @@ public class Vertex : PhysicsVector, IComparable<Vertex> | |||
129 | 69 | ||
130 | Vertex v2 = new Vertex(0f, 0f, 0f); | 70 | Vertex v2 = new Vertex(0f, 0f, 0f); |
131 | 71 | ||
132 | v2.X = q.w * q.w * v.X + | 72 | v2.X = q.W * q.W * v.X + |
133 | 2f * q.y * q.w * v.Z - | 73 | 2f * q.Y * q.W * v.Z - |
134 | 2f * q.z * q.w * v.Y + | 74 | 2f * q.Z * q.W * v.Y + |
135 | q.x * q.x * v.X + | 75 | q.X * q.X * v.X + |
136 | 2f * q.y * q.x * v.Y + | 76 | 2f * q.Y * q.X * v.Y + |
137 | 2f * q.z * q.x * v.Z - | 77 | 2f * q.Z * q.X * v.Z - |
138 | q.z * q.z * v.X - | 78 | q.Z * q.Z * v.X - |
139 | q.y * q.y * v.X; | 79 | q.Y * q.Y * v.X; |
140 | 80 | ||
141 | v2.Y = | 81 | v2.Y = |
142 | 2f * q.x * q.y * v.X + | 82 | 2f * q.X * q.Y * v.X + |
143 | q.y * q.y * v.Y + | 83 | q.Y * q.Y * v.Y + |
144 | 2f * q.z * q.y * v.Z + | 84 | 2f * q.Z * q.Y * v.Z + |
145 | 2f * q.w * q.z * v.X - | 85 | 2f * q.W * q.Z * v.X - |
146 | q.z * q.z * v.Y + | 86 | q.Z * q.Z * v.Y + |
147 | q.w * q.w * v.Y - | 87 | q.W * q.W * v.Y - |
148 | 2f * q.x * q.w * v.Z - | 88 | 2f * q.X * q.W * v.Z - |
149 | q.x * q.x * v.Y; | 89 | q.X * q.X * v.Y; |
150 | 90 | ||
151 | v2.Z = | 91 | v2.Z = |
152 | 2f * q.x * q.z * v.X + | 92 | 2f * q.X * q.Z * v.X + |
153 | 2f * q.y * q.z * v.Y + | 93 | 2f * q.Y * q.Z * v.Y + |
154 | q.z * q.z * v.Z - | 94 | q.Z * q.Z * v.Z - |
155 | 2f * q.w * q.y * v.X - | 95 | 2f * q.W * q.Y * v.X - |
156 | q.y * q.y * v.Z + | 96 | q.Y * q.Y * v.Z + |
157 | 2f * q.w * q.x * v.Y - | 97 | 2f * q.W * q.X * v.Y - |
158 | q.x * q.x * v.Z + | 98 | q.X * q.X * v.Z + |
159 | q.w * q.w * v.Z; | 99 | q.W * q.W * v.Z; |
160 | 100 | ||
161 | return v2; | 101 | return v2; |
162 | } | 102 | } |