aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API
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/DotNetEngine/Compiler/Server_API
parent* some work on not storing the circuitPack (bad thing if we're going to reuse... (diff)
downloadopensim-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/Server_API')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs40
1 files changed, 24 insertions, 16 deletions
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()