aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs89
1 files changed, 40 insertions, 49 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 712bd7d..ed63aee 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -451,12 +451,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
451 public LSL_Vector llVecNorm(LSL_Vector v) 451 public LSL_Vector llVecNorm(LSL_Vector v)
452 { 452 {
453 m_host.AddScriptLPS(1); 453 m_host.AddScriptLPS(1);
454 double mag = LSL_Vector.Mag(v); 454 return LSL_Vector.Norm(v);
455 LSL_Vector nor = new LSL_Vector();
456 nor.x = v.x / mag;
457 nor.y = v.y / mag;
458 nor.z = v.z / mag;
459 return nor;
460 } 455 }
461 456
462 public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b) 457 public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
@@ -470,22 +465,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
470 465
471 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 466 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
472 467
473 // Utility function for llRot2Euler 468 // Old implementation of llRot2Euler. Normalization not required as Atan2 function will
474 469 // only return values >= -PI (-180 degrees) and <= PI (180 degrees).
475 // normalize an angle between -PI and PI (-180 to +180 degrees)
476 protected double NormalizeAngle(double angle)
477 {
478 if (angle > -Math.PI && angle < Math.PI)
479 return angle;
480
481 int numPis = (int)(Math.PI / angle);
482 double remainder = angle - Math.PI * numPis;
483 if (numPis % 2 == 1)
484 return Math.PI - angle;
485 return remainder;
486 }
487
488 // Old implementation of llRot2Euler, now normalized
489 470
490 public LSL_Vector llRot2Euler(LSL_Rotation r) 471 public LSL_Vector llRot2Euler(LSL_Rotation r)
491 { 472 {
@@ -497,13 +478,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
497 double n = 2 * (r.y * r.s + r.x * r.z); 478 double n = 2 * (r.y * r.s + r.x * r.z);
498 double p = m * m - n * n; 479 double p = m * m - n * n;
499 if (p > 0) 480 if (p > 0)
500 return new LSL_Vector(NormalizeAngle(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s))), 481 return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)),
501 NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))), 482 Math.Atan2(n, Math.Sqrt(p)),
502 NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)))); 483 Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)));
503 else if (n > 0) 484 else if (n > 0)
504 return new LSL_Vector(0.0, Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 485 return new LSL_Vector(0.0, Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
505 else 486 else
506 return new LSL_Vector(0.0, -Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 487 return new LSL_Vector(0.0, -Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
507 } 488 }
508 489
509 /* From wiki: 490 /* From wiki:
@@ -1953,13 +1934,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1953 } 1934 }
1954 else 1935 else
1955 { 1936 {
1956 if (llVecDist(new LSL_Vector(0,0,0), targetPos) <= 10.0f) 1937 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos);
1957 { 1938 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1958 part.OffsetPosition = new Vector3((float)targetPos.x, (float)targetPos.y, (float)targetPos.z); 1939 SceneObjectGroup parent = part.ParentGroup;
1959 SceneObjectGroup parent = part.ParentGroup; 1940 parent.HasGroupChanged = true;
1960 parent.HasGroupChanged = true; 1941 parent.ScheduleGroupForTerseUpdate();
1961 parent.ScheduleGroupForTerseUpdate();
1962 }
1963 } 1942 }
1964 } 1943 }
1965 1944
@@ -2945,9 +2924,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2945 2924
2946 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 2925 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
2947 if (attachmentsModule != null) 2926 if (attachmentsModule != null)
2948 attachmentsModule.AttachObject( 2927 attachmentsModule.AttachObject(presence.ControllingClient,
2949 presence.ControllingClient, grp.LocalId, 2928 grp, (uint)attachment, false);
2950 (uint)attachment, Quaternion.Identity, Vector3.Zero, false);
2951 } 2929 }
2952 } 2930 }
2953 2931
@@ -3270,17 +3248,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3270 public void llPointAt(LSL_Vector pos) 3248 public void llPointAt(LSL_Vector pos)
3271 { 3249 {
3272 m_host.AddScriptLPS(1); 3250 m_host.AddScriptLPS(1);
3273 ScenePresence Owner = World.GetScenePresence(m_host.UUID);
3274 LSL_Rotation rot = llEuler2Rot(pos);
3275 Owner.PreviousRotation = Owner.Rotation;
3276 Owner.Rotation = (new Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s));
3277 } 3251 }
3278 3252
3279 public void llStopPointAt() 3253 public void llStopPointAt()
3280 { 3254 {
3281 m_host.AddScriptLPS(1); 3255 m_host.AddScriptLPS(1);
3282 ScenePresence Owner = m_host.ParentGroup.Scene.GetScenePresence(m_host.OwnerID);
3283 Owner.Rotation = Owner.PreviousRotation;
3284 } 3256 }
3285 3257
3286 public void llTargetOmega(LSL_Vector axis, double spinrate, double gain) 3258 public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
@@ -3938,22 +3910,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3938 UUID uuid = (UUID)id; 3910 UUID uuid = (UUID)id;
3939 3911
3940 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 3912 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
3913 if (account == null)
3914 return UUID.Zero.ToString();
3915
3941 3916
3942 PresenceInfo pinfo = null; 3917 PresenceInfo pinfo = null;
3943 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 3918 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
3944 if (pinfos != null && pinfos.Length > 0) 3919 if (pinfos != null && pinfos.Length > 0)
3945 pinfo = pinfos[0]; 3920 pinfo = pinfos[0];
3946 3921
3947 if (pinfo == null)
3948 return UUID.Zero.ToString();
3949
3950 string reply = String.Empty; 3922 string reply = String.Empty;
3951 3923
3952 switch (data) 3924 switch (data)
3953 { 3925 {
3954 case 1: // DATA_ONLINE (0|1) 3926 case 1: // DATA_ONLINE (0|1)
3955 // TODO: implement fetching of this information 3927 if (pinfo != null && pinfo.RegionID != UUID.Zero)
3956 if (pinfo != null)
3957 reply = "1"; 3928 reply = "1";
3958 else 3929 else
3959 reply = "0"; 3930 reply = "0";
@@ -4950,7 +4921,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4950 case ',': 4921 case ',':
4951 if (parens == 0) 4922 if (parens == 0)
4952 { 4923 {
4953 result.Add(src.Substring(start,length).Trim()); 4924 result.Add(new LSL_String(src.Substring(start,length).Trim()));
4954 start += length+1; 4925 start += length+1;
4955 length = 0; 4926 length = 0;
4956 } 4927 }
@@ -5879,6 +5850,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5879 PSYS_PART_MAX_AGE = 7, 5850 PSYS_PART_MAX_AGE = 7,
5880 PSYS_SRC_ACCEL = 8, 5851 PSYS_SRC_ACCEL = 8,
5881 PSYS_SRC_PATTERN = 9, 5852 PSYS_SRC_PATTERN = 9,
5853 PSYS_SRC_INNERANGLE = 10,
5854 PSYS_SRC_OUTERANGLE = 11,
5882 PSYS_SRC_TEXTURE = 12, 5855 PSYS_SRC_TEXTURE = 12,
5883 PSYS_SRC_BURST_RATE = 13, 5856 PSYS_SRC_BURST_RATE = 13,
5884 PSYS_SRC_BURST_PART_COUNT = 15, 5857 PSYS_SRC_BURST_PART_COUNT = 15,
@@ -6011,6 +5984,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6011 prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi; 5984 prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
6012 break; 5985 break;
6013 5986
5987 // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
5988 // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
5989 // client tells the difference between the two by looking at the 0x02 bit in
5990 // the PartFlags variable.
5991 case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
5992 tempf = (float)rules.GetLSLFloatItem(i + 1);
5993 prules.InnerAngle = (float)tempf;
5994 prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
5995 break;
5996
5997 case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
5998 tempf = (float)rules.GetLSLFloatItem(i + 1);
5999 prules.OuterAngle = (float)tempf;
6000 prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
6001 break;
6002
6014 case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: 6003 case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
6015 prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1)); 6004 prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1));
6016 break; 6005 break;
@@ -6067,11 +6056,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6067 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN: 6056 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
6068 tempf = (float)rules.GetLSLFloatItem(i + 1); 6057 tempf = (float)rules.GetLSLFloatItem(i + 1);
6069 prules.InnerAngle = (float)tempf; 6058 prules.InnerAngle = (float)tempf;
6059 prules.PartFlags |= 0x02; // Set new angle format.
6070 break; 6060 break;
6071 6061
6072 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END: 6062 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
6073 tempf = (float)rules.GetLSLFloatItem(i + 1); 6063 tempf = (float)rules.GetLSLFloatItem(i + 1);
6074 prules.OuterAngle = (float)tempf; 6064 prules.OuterAngle = (float)tempf;
6065 prules.PartFlags |= 0x02; // Set new angle format.
6075 break; 6066 break;
6076 } 6067 }
6077 6068