aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common
diff options
context:
space:
mode:
authorCharles Krinke2007-12-15 16:26:32 +0000
committerCharles Krinke2007-12-15 16:26:32 +0000
commitfd360406b9be5ac8d32586e0142cde449ee53ee7 (patch)
tree5e1593c2a046dd07d5c528ff3230729b2ad3cace /OpenSim/Region/ScriptEngine/Common
parent* some work on not storing the circuitPack (bad thing if we're going to reuse... (diff)
downloadopensim-SC_OLD-fd360406b9be5ac8d32586e0142cde449ee53ee7.zip
opensim-SC_OLD-fd360406b9be5ac8d32586e0142cde449ee53ee7.tar.gz
opensim-SC_OLD-fd360406b9be5ac8d32586e0142cde449ee53ee7.tar.bz2
opensim-SC_OLD-fd360406b9be5ac8d32586e0142cde449ee53ee7.tar.xz
Thanks again to Alondria for adding: math support for
rot * rot, vec / rot, == and != overriders for Rotations and Vectors. Also: llRotBetween(), llGetRegionTimeDilation(). And fixing: Error in LSL2CSConverter that botched a variable with a type name in it (ex: rotationCenter) Fixed: Error in LSL2CSConverter that parsed which() loops incorrectly. Fixed: Changed definition of Quaternion to <x, y, z, r> from <x, y, z, t> (As per LSL) Finished: llEuler2Rot()
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs193
1 files changed, 150 insertions, 43 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 5618db6..e0cf1e5 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -53,59 +53,53 @@ namespace OpenSim.Region.ScriptEngine.Common
53 y = Y; 53 y = Y;
54 z = Z; 54 z = Z;
55 } 55 }
56 public string ToString() 56
57 #region Overriders
58
59 public override string ToString()
57 { 60 {
58 return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ">"; 61 return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ">";
59 } 62 }
60 public static Vector3 operator *(Vector3 v, float f) 63 public static bool operator ==(Vector3 lhs, Vector3 rhs)
61 { 64 {
62 v.x = v.x * f; 65 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
63 v.y = v.y * f;
64 v.z = v.z * f;
65 return v;
66 } 66 }
67 public static Vector3 operator /(Vector3 v, float f) 67 public static bool operator !=(Vector3 lhs, Vector3 rhs)
68 { 68 {
69 v.x = v.x / f; 69 return !(lhs == rhs);
70 v.y = v.y / f;
71 v.z = v.z / f;
72 return v;
73 } 70 }
74 public static Vector3 operator /(float f, Vector3 v) 71 public override int GetHashCode()
75 { 72 {
76 v.x = v.x / f; 73 return (x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode());
77 v.y = v.y / f;
78 v.z = v.z / f;
79 return v;
80 } 74 }
81 public static Vector3 operator *(float f, Vector3 v) 75
76
77 public override bool Equals(object o)
82 { 78 {
83 v.x = v.x * f; 79 if (!(o is Vector3)) return false;
84 v.y = v.y * f; 80
85 v.z = v.z * f; 81 Vector3 vector = (Vector3)o;
86 return v; 82
83 return (x == vector.x && x == vector.x && z == vector.z);
87 } 84 }
88 public static Vector3 operator *(Vector3 v1, Vector3 v2) 85
86 #endregion
87
88 #region Vector & Vector Math
89 // Vector-Vector Math
90 public static Vector3 operator +(Vector3 lhs, Vector3 rhs)
89 { 91 {
90 v1.x = v1.x * v2.x; 92 return new Vector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
91 v1.y = v1.y * v2.y; 93 }
92 v1.z = v1.z * v2.z; 94 public static Vector3 operator -(Vector3 lhs, Vector3 rhs)
93 return v1;
94 }
95 public static Vector3 operator +(Vector3 v1, Vector3 v2)
96 { 95 {
97 v1.x = v1.x + v2.x; 96 return new Vector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
98 v1.y = v1.y + v2.y;
99 v1.z = v1.z + v2.z;
100 return v1;
101 } 97 }
102 public static Vector3 operator -(Vector3 v1, Vector3 v2) 98 public static Vector3 operator *(Vector3 lhs, Vector3 rhs)
103 { 99 {
104 v1.x = v1.x - v2.x; 100 return new Vector3(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z);
105 v1.y = v1.y - v2.y;
106 v1.z = v1.z - v2.z;
107 return v1;
108 } 101 }
102
109 public static Vector3 operator %(Vector3 v1, Vector3 v2) 103 public static Vector3 operator %(Vector3 v1, Vector3 v2)
110 { 104 {
111 //Cross product 105 //Cross product
@@ -115,6 +109,79 @@ namespace OpenSim.Region.ScriptEngine.Common
115 tv.z = (v1.x * v2.y) - (v1.y * v2.x); 109 tv.z = (v1.x * v2.y) - (v1.y * v2.x);
116 return tv; 110 return tv;
117 } 111 }
112
113 #endregion
114
115 #region Vector & Float Math
116 // Vector-Float and Float-Vector Math
117 public static Vector3 operator *(Vector3 vec, float val)
118 {
119 return new Vector3(vec.x * val, vec.y * val, vec.z * val);
120 }
121
122 public static Vector3 operator *(float val, Vector3 vec)
123 {
124 return new Vector3(vec.x * val, vec.y * val, vec.z * val);
125 }
126
127 public static Vector3 operator /(Vector3 v, float f)
128 {
129 v.x = v.x / f;
130 v.y = v.y / f;
131 v.z = v.z / f;
132 return v;
133 }
134
135 #endregion
136
137 #region Vector & Rotation Math
138 // Vector-Rotation Math
139 public static Vector3 operator *(Vector3 v, Quaternion r)
140 {
141 Quaternion vq = new Quaternion(v.x, v.y, v.z, 0);
142 Quaternion nq = new Quaternion(-r.x, -r.y, -r.z, r.s);
143
144 Quaternion result = (r * vq) * nq;
145
146 return new Vector3(result.x, result.y, result.z);
147 }
148 // I *think* this is how it works....
149 public static Vector3 operator /(Vector3 vec, Quaternion quat)
150 {
151 quat.s = -quat.s;
152 Quaternion vq = new Quaternion(vec.x, vec.y, vec.z, 0);
153 Quaternion nq = new Quaternion(-quat.x, -quat.y, -quat.z, quat.s);
154
155 Quaternion result = (quat * vq) * nq;
156
157 return new Vector3(result.x, result.y, result.z);
158 }
159 #endregion
160
161 #region Static Helper Functions
162 public static double Dot(Vector3 v1, Vector3 v2)
163 {
164 return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
165 }
166 public static Vector3 Cross(Vector3 v1, Vector3 v2)
167 {
168 return new Vector3
169 (
170 v1.y * v2.z - v1.z * v2.y,
171 v1.z * v2.x - v1.x * v2.z,
172 v1.x * v2.y - v1.y * v2.x
173 );
174 }
175 public static float Mag(Vector3 v)
176 {
177 return (float)Math.Sqrt(v.x * v.y + v.y * v.y + v.z * v.z);
178 }
179 public static Vector3 Norm(Vector3 vector)
180 {
181 float mag = Mag(vector);
182 return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag);
183 }
184 #endregion
118 } 185 }
119 186
120 [Serializable] 187 [Serializable]
@@ -123,26 +190,66 @@ namespace OpenSim.Region.ScriptEngine.Common
123 public double x; 190 public double x;
124 public double y; 191 public double y;
125 public double z; 192 public double z;
126 public double r; 193 public double s;
127 194
128 public Quaternion(Quaternion Quat) 195 public Quaternion(Quaternion Quat)
129 { 196 {
130 x = (float) Quat.x; 197 x = (float) Quat.x;
131 y = (float) Quat.y; 198 y = (float) Quat.y;
132 z = (float) Quat.z; 199 z = (float) Quat.z;
133 r = (float) Quat.r; 200 s = (float) Quat.s;
134 } 201 }
135 202
136 public Quaternion(double X, double Y, double Z, double R) 203 public Quaternion(double X, double Y, double Z, double S)
137 { 204 {
138 x = X; 205 x = X;
139 y = Y; 206 y = Y;
140 z = Z; 207 z = Z;
141 r = R; 208 s = S;
142 } 209 }
143 public string ToString() 210
211 #region Overriders
212
213 public override int GetHashCode()
214 {
215 return (x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode() ^ s.GetHashCode());
216 }
217
218
219 public override bool Equals(object o)
220 {
221 if (!(o is Quaternion)) return false;
222
223 Quaternion quaternion = (Quaternion)o;
224
225 return x == quaternion.x && y == quaternion.y && z == quaternion.z && s == quaternion.s;
226 }
227 public override string ToString()
228 {
229 return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ", " + s.ToString() + ">";
230 }
231
232 public static bool operator ==(Quaternion lhs, Quaternion rhs)
233 {
234 // Return true if the fields match:
235 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.s == rhs.s;
236 }
237
238 public static bool operator !=(Quaternion lhs, Quaternion rhs)
239 {
240 return !(lhs == rhs);
241 }
242
243 #endregion
244
245 public static Quaternion operator *(Quaternion a, Quaternion b)
144 { 246 {
145 return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ", " + r.ToString() + ">"; 247 Quaternion c;
248 c.x = a.s * b.x + a.x * b.s + a.y * b.z - a.z * b.y;
249 c.y = a.s * b.y + a.y * b.s + a.z * b.x - a.x * b.z;
250 c.z = a.s * b.z + a.z * b.s + a.x * b.y - a.y * b.x;
251 c.s = a.s * b.s - a.x * b.x - a.y * b.y - a.z * b.z;
252 return c;
146 } 253 }
147 } 254 }
148 } 255 }