diff options
author | Charles Krinke | 2007-12-15 16:26:32 +0000 |
---|---|---|
committer | Charles Krinke | 2007-12-15 16:26:32 +0000 |
commit | fd360406b9be5ac8d32586e0142cde449ee53ee7 (patch) | |
tree | 5e1593c2a046dd07d5c528ff3230729b2ad3cace /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler | |
parent | * some work on not storing the circuitPack (bad thing if we're going to reuse... (diff) | |
download | opensim-SC-fd360406b9be5ac8d32586e0142cde449ee53ee7.zip opensim-SC-fd360406b9be5ac8d32586e0142cde449ee53ee7.tar.gz opensim-SC-fd360406b9be5ac8d32586e0142cde449ee53ee7.tar.bz2 opensim-SC-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 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 11 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs | 40 |
2 files changed, 31 insertions, 20 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index d9ebd14..00ddbba 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | |||
@@ -47,7 +47,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
47 | dataTypes.Add("key", "string"); | 47 | dataTypes.Add("key", "string"); |
48 | dataTypes.Add("vector", "LSL_Types.Vector3"); | 48 | dataTypes.Add("vector", "LSL_Types.Vector3"); |
49 | dataTypes.Add("rotation", "LSL_Types.Quaternion"); | 49 | dataTypes.Add("rotation", "LSL_Types.Quaternion"); |
50 | dataTypes.Add("list", "List"); | 50 | dataTypes.Add("list", "List<string>"); |
51 | dataTypes.Add("null", "null"); | 51 | dataTypes.Add("null", "null"); |
52 | } | 52 | } |
53 | 53 | ||
@@ -203,7 +203,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
203 | //Console.WriteLine("Replacing using statename: " + current_statename); | 203 | //Console.WriteLine("Replacing using statename: " + current_statename); |
204 | cache = | 204 | cache = |
205 | Regex.Replace(cache, | 205 | Regex.Replace(cache, |
206 | @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", | 206 | @"^(\s*)((?!(if|switch|for|while)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", |
207 | @"$1public " + current_statename + "_event_$2", | 207 | @"$1public " + current_statename + "_event_$2", |
208 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 208 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); |
209 | } | 209 | } |
@@ -236,7 +236,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
236 | RegexOptions.Compiled | RegexOptions.Multiline); | 236 | RegexOptions.Compiled | RegexOptions.Multiline); |
237 | // Replace return types and function variables - integer a() and f(integer a, integer a) | 237 | // Replace return types and function variables - integer a() and f(integer a, integer a) |
238 | Script = | 238 | Script = |
239 | Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)", @"$1$2" + val + "$3", | 239 | Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s+)", @"$1$2" + val + "$3", |
240 | RegexOptions.Compiled | RegexOptions.Multiline); | ||
241 | Script = | ||
242 | Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)[,]", @"$1$2" + val + "$3,", | ||
240 | RegexOptions.Compiled | RegexOptions.Multiline); | 243 | RegexOptions.Compiled | RegexOptions.Multiline); |
241 | } | 244 | } |
242 | 245 | ||
@@ -281,7 +284,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
281 | // Add namespace, class name and inheritance | 284 | // Add namespace, class name and inheritance |
282 | 285 | ||
283 | Return = "" + | 286 | Return = "" + |
284 | "using OpenSim.Region.ScriptEngine.Common;"; | 287 | "using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; |
285 | //"using System; " + | 288 | //"using System; " + |
286 | //"using System.Collections.Generic; " + | 289 | //"using System.Collections.Generic; " + |
287 | //"using System.Text; " + | 290 | //"using System.Text; " + |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs index 8563694..00e79c0 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs | |||
@@ -191,19 +191,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
191 | public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r) | 191 | public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r) |
192 | { | 192 | { |
193 | //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke | 193 | //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke |
194 | LSL_Types.Quaternion t = new LSL_Types.Quaternion(r.x*r.x, r.y*r.y, r.z*r.z, r.r*r.r); | 194 | LSL_Types.Quaternion t = new LSL_Types.Quaternion(r.x*r.x, r.y*r.y, r.z*r.z, r.s*r.s); |
195 | double m = (t.x + t.y + t.z + t.r); | 195 | double m = (t.x + t.y + t.z + t.s); |
196 | if (m == 0) return new LSL_Types.Vector3(); | 196 | if (m == 0) return new LSL_Types.Vector3(); |
197 | double n = 2*(r.y*r.r + r.x*r.z); | 197 | double n = 2*(r.y*r.s + r.x*r.z); |
198 | double p = m*m - n*n; | 198 | double p = m*m - n*n; |
199 | if (p > 0) | 199 | if (p > 0) |
200 | return new LSL_Types.Vector3(Math.Atan2(2.0*(r.x*r.r - r.y*r.z), (-t.x - t.y + t.z + t.r)), | 200 | return new LSL_Types.Vector3(Math.Atan2(2.0*(r.x*r.s - r.y*r.z), (-t.x - t.y + t.z + t.s)), |
201 | Math.Atan2(n, Math.Sqrt(p)), | 201 | Math.Atan2(n, Math.Sqrt(p)), |
202 | Math.Atan2(2.0*(r.z*r.r - r.x*r.y), (t.x - t.y - t.z + t.r))); | 202 | Math.Atan2(2.0*(r.z*r.s - r.x*r.y), (t.x - t.y - t.z + t.s))); |
203 | else if (n > 0) | 203 | else if (n > 0) |
204 | return new LSL_Types.Vector3(0.0, Math.PI/2, Math.Atan2((r.z*r.r + r.x*r.y), 0.5 - t.x - t.z)); | 204 | return new LSL_Types.Vector3(0.0, Math.PI/2, Math.Atan2((r.z*r.s + r.x*r.y), 0.5 - t.x - t.z)); |
205 | else | 205 | else |
206 | return new LSL_Types.Vector3(0.0, -Math.PI/2, Math.Atan2((r.z*r.r + r.x*r.y), 0.5 - t.x - t.z)); | 206 | return new LSL_Types.Vector3(0.0, -Math.PI/2, Math.Atan2((r.z*r.s + r.x*r.y), 0.5 - t.x - t.z)); |
207 | } | 207 | } |
208 | 208 | ||
209 | public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v) | 209 | public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v) |
@@ -219,6 +219,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
219 | LSL_Types.Quaternion a1 = new LSL_Types.Quaternion(0.0, 0.0, cz, cw); | 219 | LSL_Types.Quaternion a1 = new LSL_Types.Quaternion(0.0, 0.0, cz, cw); |
220 | LSL_Types.Quaternion a2 = new LSL_Types.Quaternion(0.0, by, 0.0, bw); | 220 | LSL_Types.Quaternion a2 = new LSL_Types.Quaternion(0.0, by, 0.0, bw); |
221 | LSL_Types.Quaternion a3 = new LSL_Types.Quaternion(ax, 0.0, 0.0, aw); | 221 | LSL_Types.Quaternion a3 = new LSL_Types.Quaternion(ax, 0.0, 0.0, aw); |
222 | LSL_Types.Quaternion a = (a1 * a2) * a3; | ||
222 | //This multiplication doesnt compile, yet. a = a1 * a2 * a3; | 223 | //This multiplication doesnt compile, yet. a = a1 * a2 * a3; |
223 | LSL_Types.Quaternion b = new LSL_Types.Quaternion(ax*bw*cw + aw*by*cz, | 224 | LSL_Types.Quaternion b = new LSL_Types.Quaternion(ax*bw*cw + aw*by*cz, |
224 | aw*by*cw - ax*bw*cz, aw*bw*cz + ax*by*cw, | 225 | aw*by*cw - ax*bw*cz, aw*bw*cz + ax*by*cw, |
@@ -230,13 +231,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
230 | if ((Math.Abs(c.x) > err && Math.Abs(d.x) > err) || | 231 | if ((Math.Abs(c.x) > err && Math.Abs(d.x) > err) || |
231 | (Math.Abs(c.y) > err && Math.Abs(d.y) > err) || | 232 | (Math.Abs(c.y) > err && Math.Abs(d.y) > err) || |
232 | (Math.Abs(c.z) > err && Math.Abs(d.z) > err) || | 233 | (Math.Abs(c.z) > err && Math.Abs(d.z) > err) || |
233 | (Math.Abs(c.r) > err && Math.Abs(d.r) > err)) | 234 | (Math.Abs(c.s) > err && Math.Abs(d.s) > err)) |
234 | { | 235 | { |
236 | return b; | ||
235 | //return a new Quaternion that is null until I figure this out | 237 | //return a new Quaternion that is null until I figure this out |
236 | // return b; | 238 | // return b; |
237 | // return a; | 239 | // return a; |
238 | } | 240 | } |
239 | return new LSL_Types.Quaternion(); | 241 | return a; |
240 | } | 242 | } |
241 | 243 | ||
242 | public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up) | 244 | public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up) |
@@ -258,12 +260,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
258 | { | 260 | { |
259 | return new LSL_Types.Vector3(); | 261 | return new LSL_Types.Vector3(); |
260 | } | 262 | } |
261 | 263 | public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b) | |
262 | public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 start, LSL_Types.Vector3 end) | ||
263 | { | 264 | { |
264 | return new LSL_Types.Quaternion(); | 265 | //A and B should both be normalized |
265 | } | ||
266 | 266 | ||
267 | double dotProduct = LSL_Types.Vector3.Dot(a, b); | ||
268 | LSL_Types.Vector3 crossProduct = LSL_Types.Vector3.Cross(a, b); | ||
269 | double magProduct = LSL_Types.Vector3.Mag(a) * LSL_Types.Vector3.Mag(b); | ||
270 | double angle = Math.Acos(dotProduct / magProduct); | ||
271 | LSL_Types.Vector3 axis = LSL_Types.Vector3.Norm(crossProduct); | ||
272 | double s = Math.Sin(angle / 2); | ||
273 | |||
274 | return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2)); | ||
275 | } | ||
267 | public void llWhisper(int channelID, string text) | 276 | public void llWhisper(int channelID, string text) |
268 | { | 277 | { |
269 | World.SimChat(Helpers.StringToField(text), | 278 | World.SimChat(Helpers.StringToField(text), |
@@ -629,7 +638,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
629 | } | 638 | } |
630 | if (face == -1) | 639 | if (face == -1) |
631 | { | 640 | { |
632 | LLObject.TextureEntryFace texface; | ||
633 | for (int i = 0; i < 32; i++) | 641 | for (int i = 0; i < 32; i++) |
634 | { | 642 | { |
635 | if (tex.FaceTextures[i] != null) | 643 | if (tex.FaceTextures[i] != null) |
@@ -729,7 +737,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
729 | 737 | ||
730 | public void llSetRot(LSL_Types.Quaternion rot) | 738 | public void llSetRot(LSL_Types.Quaternion rot) |
731 | { | 739 | { |
732 | m_host.UpdateRotation(new LLQuaternion((float) rot.x, (float) rot.y, (float) rot.z, (float) rot.r)); | 740 | m_host.UpdateRotation(new LLQuaternion((float) rot.x, (float) rot.y, (float) rot.z, (float) rot.s)); |
733 | } | 741 | } |
734 | 742 | ||
735 | public LSL_Types.Quaternion llGetRot() | 743 | public LSL_Types.Quaternion llGetRot() |
@@ -1778,7 +1786,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler | |||
1778 | 1786 | ||
1779 | public double llGetRegionTimeDilation() | 1787 | public double llGetRegionTimeDilation() |
1780 | { | 1788 | { |
1781 | return 1.0f; | 1789 | return (double)World.TimeDilation; |
1782 | } | 1790 | } |
1783 | 1791 | ||
1784 | public double llGetRegionFPS() | 1792 | public double llGetRegionFPS() |