public LSL_List modInvokeL(string fname, params object[] parms) { // m_log.DebugFormat( // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", // fname, // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(object[])) { MODError(String.Format("return type mismatch for {0}", fname)); } object[] result = (object[])modInvoke(fname, parms); object[] llist = new object[result.Length]; for (int i = 0; i < result.Length; i++) { if (result[i] is string) { llist[i] = new LSL_String((string)result[i]); } else if (result[i] is int) { llist[i] = new LSL_Integer((int)result[i]); } else if (result[i] is float) { llist[i] = new LSL_Float((float)result[i]); } else if (result[i] is double) { llist[i] = new LSL_Float((double)result[i]); } else if (result[i] is UUID) { llist[i] = new LSL_Key(result[i].ToString()); } else if (result[i] is OpenMetaverse.Vector3) { OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i]; llist[i] = new LSL_Vector(vresult.X, vresult.Y, vresult.Z); } else if (result[i] is OpenMetaverse.Quaternion) { OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i]; llist[i] = new LSL_Rotation(qresult.X, qresult.Y, qresult.Z, qresult.W); } else { MODError(String.Format("unknown list element {1} returned by {0}", fname, result[i].GetType().Name)); } } return(new LSL_List(llist)); }
public static void PrintParam(StringBuilder sb, object p) { if (p == null) { sb.Append("null"); } else if (p is LSL_List) { sb.Append('['); object[] d = ((LSL_List)p).Data; for (int i = 0; i < d.Length; i++) { if (i > 0) { sb.Append(','); } PrintParam(sb, d[i]); } sb.Append(']'); } else if (p is LSL_Rotation) { LSL_Rotation r = (LSL_Rotation)p; sb.Append('<'); sb.Append(r.x); sb.Append(','); sb.Append(r.y); sb.Append(','); sb.Append(r.z); sb.Append(','); sb.Append(r.s); sb.Append('>'); } else if (p is LSL_String) { PrintParamString(sb, (string)(LSL_String)p); } else if (p is LSL_Vector) { LSL_Vector v = (LSL_Vector)p; sb.Append('<'); sb.Append(v.x); sb.Append(','); sb.Append(v.y); sb.Append(','); sb.Append(v.z); sb.Append('>'); } else if (p is string) { PrintParamString(sb, (string)p); } else { sb.Append(p.ToString()); } }
public const int Sorpra_TIMEOUT_MS = 30000; // ie, 30sec public override bool xmrSetObjRegPosRotAsync(LSL_Vector pos, LSL_Rotation rot, int options, int evcode, LSL_List evargs) { // do the move SceneObjectGroup sog = m_Part.ParentGroup; sog.UpdateGroupRotationPR(pos, rot); // it is always synchronous return(false); }
public LSL_List modInvokeL(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(object[])) { MODError(String.Format("return type mismatch for {0}", fname)); } object[] result = (object[])modInvoke(fname, parms); object[] llist = new object[result.Length]; for (int i = 0; i < result.Length; i++) { if (result[i] is string) { llist[i] = new LSL_String((string)result[i]); } else if (result[i] is int) { llist[i] = new LSL_Integer((int)result[i]); } else if (result[i] is float) { llist[i] = new LSL_Float((float)result[i]); } else if (result[i] is UUID) { llist[i] = new LSL_Key(result[i].ToString()); } else if (result[i] is OpenMetaverse.Vector3) { OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i]; llist[i] = new LSL_Vector(vresult.X, vresult.Y, vresult.Z); } else if (result[i] is OpenMetaverse.Quaternion) { OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i]; llist[i] = new LSL_Rotation(qresult.X, qresult.Y, qresult.Z, qresult.W); } else { MODError(String.Format("unknown list element {1} returned by {0}", fname, result[i].GetType().Name)); } } return(new LSL_List(llist)); }
private static int MyRotationComparer(object a, object b) { LSL_Rotation ar = (LSL_Rotation)a; LSL_Rotation br = (LSL_Rotation)b; if (ar.x < br.x) { return(-1); } if (ar.x > br.x) { return(1); } if (ar.y < br.y) { return(-1); } if (ar.y > br.y) { return(1); } if (ar.z < br.z) { return(-1); } if (ar.z > br.z) { return(1); } if (ar.s < br.s) { return(-1); } if (ar.s > br.s) { return(1); } return(0); }
//CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in //CFK 9/28: so these are not complete yet. public void llSetVehicleRotationParam(int param, LSL_Rotation rot) { m_host.AddScriptLPS(1); if (!m_host.ParentGroup.IsDeleted) { m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, Rot2Quaternion(rot)); } }
// jcochran 5/jan/2012 public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b) { m_host.AddScriptLPS(1); double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s); double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s); double aa_bb = aa * bb; if (aa_bb == 0) return 0.0; double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s); double quotient = (ab * ab) / aa_bb; if (quotient >= 1.0) return 0.0; return Math.Acos(2 * quotient - 1); }
// Xantor 29/apr/2008 // converts a Quaternion to X,Y,Z axis rotations public LSL_Vector llRot2Axis(LSL_Rotation rot) { m_host.AddScriptLPS(1); double x,y,z; if (rot.s > 1) // normalization needed { double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y + rot.z * rot.z + rot.s * rot.s); rot.x /= length; rot.y /= length; rot.z /= length; rot.s /= length; } // double angle = 2 * Math.Acos(rot.s); double s = Math.Sqrt(1 - rot.s * rot.s); if (s < 0.001) { x = 1; y = z = 0; } else { x = rot.x / s; // normalise axis y = rot.y / s; z = rot.z / s; } return new LSL_Vector(x,y,z); }
public void llRotLookAt(LSL_Rotation target, double strength, double damping) { m_host.AddScriptLPS(1); // Per discussion with Melanie, for non-physical objects llLookAt appears to simply // set the rotation of the object, copy that behavior PhysicsActor pa = m_host.PhysActor; if (strength == 0 || pa == null || !pa.IsPhysical) { llSetLocalRot(target); } else { m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping); } }
public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) { llRezAtRoot(inventory, pos, vel, rot, param); }
public LSL_List modInvokeL(string fname, params object[] parms) { Type returntype = m_comms.LookupReturnType(fname); if (returntype != typeof(object[])) MODError(String.Format("return type mismatch for {0}",fname)); object[] result = (object[])modInvoke(fname,parms); object[] llist = new object[result.Length]; for (int i = 0; i < result.Length; i++) { if (result[i] is string) { llist[i] = new LSL_String((string)result[i]); } else if (result[i] is int) { llist[i] = new LSL_Integer((int)result[i]); } else if (result[i] is float) { llist[i] = new LSL_Float((float)result[i]); } else if (result[i] is UUID) { llist[i] = new LSL_Key(result[i].ToString()); } else if (result[i] is OpenMetaverse.Vector3) { OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i]; llist[i] = new LSL_Vector(vresult.X, vresult.Y, vresult.Z); } else if (result[i] is OpenMetaverse.Quaternion) { OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i]; llist[i] = new LSL_Rotation(qresult.X, qresult.Y, qresult.Z, qresult.W); } else { MODError(String.Format("unknown list element {1} returned by {0}", fname, result[i].GetType().Name)); } } return new LSL_List(llist); }
public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) { CheckThreatLevel(ThreatLevel.High, "osNpcSetRot"); m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); if (npcModule != null) { UUID npcId; if (!UUID.TryParse(npc.m_string, out npcId)) return; if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) return; ScenePresence sp = World.GetScenePresence(npcId); if (sp != null) sp.Rotation = rotation; } }
public void llRotLookAt(LSL_Rotation target, double strength, double damping) { m_LSL_Functions.llRotLookAt(target, strength, damping); }
public LSL_Vector llRot2Up(LSL_Rotation r) { return m_LSL_Functions.llRot2Up(r); }
public static LSL_List RotationToList(LSL_Rotation r) { return(new LSL_List(new object[] { r })); }
public static string RotationToString(LSL_Rotation x) { return(x.ToString()); }
/* * Because the calls are funky, let the compiler handle them. */ public static bool RotationToBool(LSL_Rotation x) { return(!x.Equals(ScriptBaseClass.ZERO_ROTATION)); }
public LSL_Integer osApproxEquals(rotation ra, rotation rb, LSL_Float margin) { return(m_OSSL_Functions.osApproxEquals(ra, rb, margin)); }
public void llSitTarget(LSL_Vector offset, LSL_Rotation rot) { m_host.AddScriptLPS(1); SitTarget(m_host, offset, rot); }
public LSL_Integer llRotTarget(LSL_Rotation rot, double error) { return m_LSL_Functions.llRotTarget(rot, error); }
public LSL_Integer osApproxEquals(rotation ra, rotation rb) { return(m_OSSL_Functions.osApproxEquals(ra, rb)); }
public void llSetRot(LSL_Rotation rot) { m_LSL_Functions.llSetRot(rot); }
public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) { CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt"); m_host.AddScriptLPS(1); DropAttachmentAt(true, pos, rot); }
public void llSetVehicleRotationParam(int param, LSL_Rotation rot) { m_LSL_Functions.llSetVehicleRotationParam(param, rot); }
public static string RotStr(LSL_Rotation r) { return("new LSL_Rotation(" + r.x + "," + r.y + "," + r.z + "," + r.s + ")"); }
public void llSitTarget(LSL_Vector offset, LSL_Rotation rot) { m_LSL_Functions.llSitTarget(offset, rot); }
// convert a LSL_Rotation to a Quaternion public static Quaternion Rot2Quaternion(LSL_Rotation r) { Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); q.Normalize(); return q; }
public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot) { m_LSL_Functions.llLinkSitTarget(link, offset, rot); }
//Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke /// <summary> /// Convert an LSL rotation to a Euler vector. /// </summary> /// <remarks> /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2 /// </remarks> /// <param name="r"></param> /// <returns></returns> public LSL_Vector llRot2Euler(LSL_Rotation r) { m_host.AddScriptLPS(1); LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r. double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later. if (m == 0.0) return new LSL_Vector(); double x = Math.Atan2(-v.y, v.z); double sin = v.x / m; if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities. double y = Math.Asin(sin); // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0))); double z = Math.Atan2(v.y, v.x); return new LSL_Vector(x, y, z); }
public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b) { return m_LSL_Functions.llAngleBetween(a, b); }
// Returns the angle of a quaternion (see llRot2Axis for the axis) public LSL_Float llRot2Angle(LSL_Rotation rot) { m_host.AddScriptLPS(1); if (rot.s > 1) // normalization needed { double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y + rot.z * rot.z + rot.s * rot.s); rot.x /= length; rot.y /= length; rot.z /= length; rot.s /= length; } double angle = 2 * Math.Acos(rot.s); return angle; }
public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b) { //A and B should both be normalized m_host.AddScriptLPS(1); LSL_Rotation rotBetween; // Check for zero vectors. If either is zero, return zero rotation. Otherwise, // continue calculation. if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) { rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); } else { a = LSL_Vector.Norm(a); b = LSL_Vector.Norm(b); double dotProduct = LSL_Vector.Dot(a, b); // There are two degenerate cases possible. These are for vectors 180 or // 0 degrees apart. These have to be detected and handled individually. // // Check for vectors 180 degrees apart. // A dot product of -1 would mean the angle between vectors is 180 degrees. if (dotProduct < -0.9999999f) { // First assume X axis is orthogonal to the vectors. LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); // Check for near zero vector. A very small non-zero number here will create // a rotation in an undesired direction. if (LSL_Vector.Mag(orthoVector) > 0.0001) { rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); } // If the magnitude of the vector was near zero, then assume the X axis is not // orthogonal and use the Z axis instead. else { // Set 180 z rotation. rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f); } } // Check for parallel vectors. // A dot product of 1 would mean the angle between vectors is 0 degrees. else if (dotProduct > 0.9999999f) { // Set zero rotation. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); } else { // All special checks have been performed so get the axis of rotation. LSL_Vector crossProduct = LSL_Vector.Cross(a, b); // Quarternion s value is the length of the unit vector + dot product. double qs = 1.0 + dotProduct; rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs); // Normalize the rotation. double mag = LSL_Rotation.Mag(rotBetween); // We shouldn't have to worry about a divide by zero here. The qs value will be // non-zero because we already know if we're here, then the dotProduct is not -1 so // qs will not be zero. Also, we've already handled the input vectors being zero so the // crossProduct vector should also not be zero. rotBetween.x = rotBetween.x / mag; rotBetween.y = rotBetween.y / mag; rotBetween.z = rotBetween.z / mag; rotBetween.s = rotBetween.s / mag; // Check for undefined values and set zero rotation if any found. This code might not actually be required // any longer since zero vectors are checked for at the top. if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s)) { rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); } } } return rotBetween; }
public LSL_Vector llRot2Up(LSL_Rotation r) { m_host.AddScriptLPS(1); double x, y, z, m; m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s; // m is always greater than zero // if m is not equal to 1 then Rotation needs to be normalized if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision { m = 1.0 / Math.Sqrt(m); r.x *= m; r.y *= m; r.z *= m; r.s *= m; } // Fast Algebric Calculations instead of Vectors & Quaternions Product x = 2 * (r.x * r.z + r.y * r.s); y = 2 * (-r.x * r.s + r.y * r.z); z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s; return (new LSL_Vector(x, y, z)); }
public void osSetInertiaAsBox(LSL_Float mass, vector boxSize, vector centerOfMass, rotation rot) { m_OSSL_Functions.osSetInertiaAsBox(mass, boxSize, centerOfMass, rot); }
protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot) { // LSL quaternions can normalize to 0, normal Quaternions can't. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0) rot.z = 1; // ZERO_ROTATION = 0,0,0,1 part.SitTargetPosition = new Vector3((float)offset.x, (float)offset.y, (float)offset.z); part.SitTargetOrientation = Rot2Quaternion(rot); part.ParentGroup.HasGroupChanged = true; }
public LSL_Integer osTeleportObject(LSL_Key objectUUID, vector targetPos, rotation targetrotation, LSL_Integer flags) { return(m_OSSL_Functions.osTeleportObject(objectUUID, targetPos, targetrotation, flags)); }
public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot) { m_host.AddScriptLPS(1); if (link == ScriptBaseClass.LINK_ROOT) SitTarget(m_host.ParentGroup.RootPart, offset, rot); else if (link == ScriptBaseClass.LINK_THIS) SitTarget(m_host, offset, rot); else { SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link); if (null != part) { SitTarget(part, offset, rot); } } }
public rotation osSlerp(rotation a, rotation b, LSL_Float amount) { return(m_OSSL_Functions.osSlerp(a, b, amount)); }
public void osForceDropAttachmentAt(vector pos, rotation rot) { m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); }
/** * @brief Add arbitrary constant available to script compilation. * CAUTION: These values get compiled-in to a script and must not * change over time as previously compiled scripts will * still have the old values. */ public static ScriptConst AddConstant(string name, object value) { CompValu cv = null; if (value is char) { cv = new CompValuChar(new TokenTypeChar(null), (char)value); } else if (value is double) { cv = new CompValuFloat(new TokenTypeFloat(null), (double)(double)value); } else if (value is float) { cv = new CompValuFloat(new TokenTypeFloat(null), (double)(float)value); } else if (value is int) { cv = new CompValuInteger(new TokenTypeInt(null), (int)value); } else if (value is string) { cv = new CompValuString(new TokenTypeStr(null), (string)value); } else if (value is LSL_Float) { cv = new CompValuFloat(new TokenTypeFloat(null), (double)((LSL_Float)value).value); } else if (value is LSL_Integer) { cv = new CompValuInteger(new TokenTypeInt(null), ((LSL_Integer)value).value); } else if (value is LSL_Rotation) { LSL_Rotation r = (LSL_Rotation)value; CompValu x = new CompValuFloat(new TokenTypeFloat(null), r.x); CompValu y = new CompValuFloat(new TokenTypeFloat(null), r.y); CompValu z = new CompValuFloat(new TokenTypeFloat(null), r.z); CompValu s = new CompValuFloat(new TokenTypeFloat(null), r.s); cv = new CompValuRot(new TokenTypeRot(null), x, y, z, s); } else if (value is LSL_String) { cv = new CompValuString(new TokenTypeStr(null), (string)(LSL_String)value); } else if (value is LSL_Vector) { LSL_Vector v = (LSL_Vector)value; CompValu x = new CompValuFloat(new TokenTypeFloat(null), v.x); CompValu y = new CompValuFloat(new TokenTypeFloat(null), v.y); CompValu z = new CompValuFloat(new TokenTypeFloat(null), v.z); cv = new CompValuVec(new TokenTypeVec(null), x, y, z); } else if (value is OpenMetaverse.Quaternion) { OpenMetaverse.Quaternion r = (OpenMetaverse.Quaternion)value; CompValu x = new CompValuFloat(new TokenTypeFloat(null), r.X); CompValu y = new CompValuFloat(new TokenTypeFloat(null), r.Y); CompValu z = new CompValuFloat(new TokenTypeFloat(null), r.Z); CompValu s = new CompValuFloat(new TokenTypeFloat(null), r.W); cv = new CompValuRot(new TokenTypeRot(null), x, y, z, s); } else if (value is OpenMetaverse.UUID) { cv = new CompValuString(new TokenTypeKey(null), value.ToString()); } else if (value is OpenMetaverse.Vector3) { OpenMetaverse.Vector3 v = (OpenMetaverse.Vector3)value; CompValu x = new CompValuFloat(new TokenTypeFloat(null), v.X); CompValu y = new CompValuFloat(new TokenTypeFloat(null), v.Y); CompValu z = new CompValuFloat(new TokenTypeFloat(null), v.Z); cv = new CompValuVec(new TokenTypeVec(null), x, y, z); } if (cv == null) { throw new Exception("bad type " + value.GetType().Name); } return(new ScriptConst(scriptConstants, name, cv)); }
public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, vector centerOfMass, rotation lslrot) { m_OSSL_Functions.osSetInertiaAsCylinder(mass, radius, lenght, centerOfMass, lslrot); }
public void osSetInertia(LSL_Float mass, vector centerOfMass, vector principalInertiaScaled, rotation rot) { m_OSSL_Functions.osSetInertia(mass, centerOfMass, principalInertiaScaled, rot); }
public void osNpcSetRot(key npc, rotation rot) { m_OSSL_Functions.osNpcSetRot(npc, rot); }
public void llSetRot(LSL_Rotation rot) { m_host.AddScriptLPS(1); // try to let this work as in SL... if (m_host.ParentID == 0) { // special case: If we are root, rotate complete SOG to new rotation SetRot(m_host, Rot2Quaternion(rot)); } else { // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. SceneObjectPart rootPart = m_host.ParentGroup.RootPart; if (rootPart != null) // better safe than sorry { SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot)); } } ScriptSleep(200); }
protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot) { if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment")) { return; } IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID); if (attachmentsModule != null && sp != null) { attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot); } }
public void llSetLocalRot(LSL_Rotation rot) { m_host.AddScriptLPS(1); SetRot(m_host, Rot2Quaternion(rot)); ScriptSleep(200); }
public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) { CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt"); m_host.AddScriptLPS(1); DropAttachmentAt(false, pos, rot); }
public LSL_Integer llRotTarget(LSL_Rotation rot, double error) { m_host.AddScriptLPS(1); return m_host.ParentGroup.registerRotTargetWaypoint( new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), (float)error); }
private void processXstate(XmlDocument doc) { XmlNodeList rootL = doc.GetElementsByTagName("ScriptState"); if (rootL.Count != 1) { throw new Exception("Xstate <ScriptState> missing"); } XmlNode rootNode = rootL[0]; if (rootNode == null) { throw new Exception("Xstate root missing"); } string stateName = ""; bool running = false; UUID permsGranter = UUID.Zero; int permsMask = 0; double minEventDelay = 0.0; Object[] pluginData = new Object[0]; UUID experienceKey = UUID.Zero; LinkedList <EventParams> eventQueue = new LinkedList <EventParams>(); Dictionary <string, int> intNames = new Dictionary <string, int>(); Dictionary <string, int> doubleNames = new Dictionary <string, int>(); Dictionary <string, int> stringNames = new Dictionary <string, int>(); Dictionary <string, int> vectorNames = new Dictionary <string, int>(); Dictionary <string, int> rotationNames = new Dictionary <string, int>(); Dictionary <string, int> listNames = new Dictionary <string, int>(); int nn = m_ObjCode.globalVarNames.Count; int[] ints = null; double[] doubles = null; string[] strings = null; LSL_Vector[] vectors = null; LSL_Rotation[] rotations = null; LSL_List[] lists = null; if (nn > 0) { if (m_ObjCode.globalVarNames.ContainsKey("iarIntegers")) { getvarNames(m_ObjCode.globalVarNames["iarIntegers"], intNames); ints = new int[m_ObjCode.globalVarNames["iarIntegers"].Count]; } if (m_ObjCode.globalVarNames.ContainsKey("iarFloats")) { getvarNames(m_ObjCode.globalVarNames["iarFloats"], doubleNames); doubles = new double[m_ObjCode.globalVarNames["iarFloats"].Count]; } if (m_ObjCode.globalVarNames.ContainsKey("iarVectors")) { getvarNames(m_ObjCode.globalVarNames["iarVectors"], vectorNames); vectors = new LSL_Vector[m_ObjCode.globalVarNames["iarVectors"].Count]; } if (m_ObjCode.globalVarNames.ContainsKey("iarRotations")) { getvarNames(m_ObjCode.globalVarNames["iarRotations"], rotationNames); rotations = new LSL_Rotation[m_ObjCode.globalVarNames["iarRotations"].Count]; } if (m_ObjCode.globalVarNames.ContainsKey("iarStrings")) { getvarNames(m_ObjCode.globalVarNames["iarStrings"], stringNames); strings = new string[m_ObjCode.globalVarNames["iarStrings"].Count]; } if (m_ObjCode.globalVarNames.ContainsKey("iarLists")) { getvarNames(m_ObjCode.globalVarNames["iarLists"], listNames); lists = new LSL_List[m_ObjCode.globalVarNames["iarLists"].Count]; } } int heapsz = 0; try { XmlNodeList partL = rootNode.ChildNodes; foreach (XmlNode part in partL) { switch (part.Name) { case "State": stateName = part.InnerText; break; case "Running": running = bool.Parse(part.InnerText); break; case "ExperienceKey": experienceKey = UUID.Parse(part.InnerText); break; case "Variables": int indx; XmlNodeList varL = part.ChildNodes; foreach (XmlNode var in varL) { string varName; object o = ReadXTypedValue(var, out varName); Type otype = o.GetType(); if (otype == typeof(LSL_Integer)) { if (intNames.TryGetValue(varName, out indx)) { ints[indx] = ((LSL_Integer)o); } continue; } if (otype == typeof(LSL_Float)) { if (doubleNames.TryGetValue(varName, out indx)) { doubles[indx] = ((LSL_Float)o); } continue; } if (otype == typeof(LSL_String)) { if (stringNames.TryGetValue(varName, out indx)) { strings[indx] = ((LSL_String)o); heapsz += ((LSL_String)o).Length; } continue; } if (otype == typeof(LSL_Rotation)) { if (rotationNames.TryGetValue(varName, out indx)) { rotations[indx] = ((LSL_Rotation)o); } continue; } if (otype == typeof(LSL_Vector)) { if (vectorNames.TryGetValue(varName, out indx)) { vectors[indx] = ((LSL_Vector)o); } continue; } if (otype == typeof(LSL_Key)) { if (stringNames.TryGetValue(varName, out indx)) { strings[indx] = ((LSL_Key)o); heapsz += ((LSL_String)o).Length; } continue; } if (otype == typeof(UUID)) { if (stringNames.TryGetValue(varName, out indx)) { LSL_String id = ((UUID)o).ToString(); strings[indx] = (id); heapsz += id.Length; } continue; } if (otype == typeof(LSL_List)) { if (listNames.TryGetValue(varName, out indx)) { LSL_List lo = (LSL_List)o; lists[indx] = (lo); heapsz += lo.Size; } continue; } } break; case "Queue": XmlNodeList itemL = part.ChildNodes; foreach (XmlNode item in itemL) { List <Object> parms = new List <Object>(); List <DetectParams> detected = new List <DetectParams>(); string eventName = item.Attributes.GetNamedItem("event").Value; XmlNodeList eventL = item.ChildNodes; foreach (XmlNode evt in eventL) { switch (evt.Name) { case "Params": XmlNodeList prms = evt.ChildNodes; foreach (XmlNode pm in prms) { parms.Add(ReadXTypedValue(pm)); } break; case "Detected": XmlNodeList detL = evt.ChildNodes; foreach (XmlNode det in detL) { string vect = det.Attributes.GetNamedItem("pos").Value; LSL_Vector v = new LSL_Vector(vect); int d_linkNum = 0; UUID d_group = UUID.Zero; string d_name = String.Empty; UUID d_owner = UUID.Zero; LSL_Vector d_position = new LSL_Vector(); LSL_Rotation d_rotation = new LSL_Rotation(); int d_type = 0; LSL_Vector d_velocity = new LSL_Vector(); try { string tmp; tmp = det.Attributes.GetNamedItem("linkNum").Value; int.TryParse(tmp, out d_linkNum); tmp = det.Attributes.GetNamedItem("group").Value; UUID.TryParse(tmp, out d_group); d_name = det.Attributes.GetNamedItem("name").Value; tmp = det.Attributes.GetNamedItem("owner").Value; UUID.TryParse(tmp, out d_owner); tmp = det.Attributes.GetNamedItem("position").Value; d_position = new LSL_Types.Vector3(tmp); tmp = det.Attributes.GetNamedItem("rotation").Value; d_rotation = new LSL_Rotation(tmp); tmp = det.Attributes.GetNamedItem("type").Value; int.TryParse(tmp, out d_type); tmp = det.Attributes.GetNamedItem("velocity").Value; d_velocity = new LSL_Vector(tmp); } catch (Exception) // Old version XML { } UUID uuid = new UUID(); UUID.TryParse(det.InnerText, out uuid); DetectParams d = new DetectParams(); d.Key = uuid; d.OffsetPos = v; d.LinkNum = d_linkNum; d.Group = d_group; d.Name = d_name; d.Owner = d_owner; d.Position = d_position; d.Rotation = d_rotation; d.Type = d_type; d.Velocity = d_velocity; detected.Add(d); } break; } } EventParams ep = new EventParams( eventName, parms.ToArray(), detected.ToArray()); eventQueue.AddLast(ep); } break; case "Plugins": List <Object> olist = new List <Object>(); XmlNodeList itemLP = part.ChildNodes; foreach (XmlNode item in itemLP) { olist.Add(ReadXTypedValue(item)); } pluginData = olist.ToArray(); break; case "Permissions": string tmpPerm; int mask = 0; tmpPerm = part.Attributes.GetNamedItem("mask").Value; if (tmpPerm != null) { int.TryParse(tmpPerm, out mask); if (mask != 0) { tmpPerm = part.Attributes.GetNamedItem("granter").Value; if (tmpPerm != null) { UUID granter = new UUID(); UUID.TryParse(tmpPerm, out granter); if (granter != UUID.Zero) { permsMask = mask; permsGranter = granter; } } } } break; case "MinEventDelay": double.TryParse(part.InnerText, out minEventDelay); break; } } } catch { throw new Exception("Xstate fail decode"); } int k = 0; stateCode = 0; foreach (string sn in m_ObjCode.stateNames) { if (stateName == sn) { stateCode = k; break; } k++; } eventCode = ScriptEventCode.None; m_Running = running; doGblInit = false; m_Item.PermsGranter = permsGranter; m_Item.PermsMask = permsMask; m_Item.ExperienceID = experienceKey; m_Part.Inventory.UpdateInventoryItem(m_Item, false, false); lock (m_RunLock) { glblVars.iarIntegers = ints; glblVars.iarFloats = doubles; glblVars.iarVectors = vectors; glblVars.iarRotations = rotations; glblVars.iarStrings = strings; glblVars.iarLists = lists; AddArraysHeapUse(heapsz); CheckRunLockInvariants(true); } lock (m_QueueLock) { m_DetectParams = null; foreach (EventParams evt in m_EventQueue) { eventQueue.AddLast(evt); } m_EventQueue = eventQueue; for (int i = m_EventCounts.Length; --i >= 0;) { m_EventCounts[i] = 0; } foreach (EventParams evt in m_EventQueue) { if (m_eventCodeMap.TryGetValue(evt.EventName, out ScriptEventCode evtCode)) { m_EventCounts[(int)evtCode]++; } } } AsyncCommandManager.CreateFromData(m_Engine, m_LocalID, m_ItemID, m_Part.UUID, pluginData); MinEventDelay = minEventDelay; }
public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) { m_host.AddScriptLPS(1); Util.FireAndForget(delegate (object x) { if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) return; float dist = (float)llVecDist(llGetPos(), pos); if (dist > m_ScriptDistanceFactor * 10.0f) return; //Clone is thread-safe TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) { if (inv.Value.Name == inventory) { // make sure we're an object. if (inv.Value.InvType != (int)InventoryType.Object) { llSay(0, "Unable to create requested object. Object is missing from database."); return; } Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); // need the magnitude later // float velmag = (float)Util.GetMagnitude(llvel); SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); // If either of these are null, then there was an unknown error. if (new_group == null) continue; // objects rezzed with this method are die_at_edge by default. new_group.RootPart.SetDieAtEdge(true); new_group.ResumeScripts(); m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( "object_rez", new Object[] { new LSL_String( new_group.RootPart.UUID.ToString()) }, new DetectParams[0])); float groupmass = new_group.GetMass(); PhysicsActor pa = new_group.RootPart.PhysActor; if (pa != null && pa.IsPhysical && llvel != Vector3.Zero) { //Recoil. llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); } // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) return; } } llSay(0, "Could not find object " + inventory); }); //ScriptSleep((int)((groupmass * velmag) / 10)); ScriptSleep(100); }