From 4a35f0a3058383093be6b1c2ecc8f056d4a29fd1 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 18 Aug 2012 01:17:01 +0100 Subject: [PATCH] refactoring for Vector3 operator & constructor tweaks --- .../Shared/Api/Implementation/LSL_Api.cs | 107 +++++++----------- .../Shared/Api/Implementation/LS_Api.cs | 8 +- .../Shared/Api/Implementation/MOD_Api.cs | 7 +- .../Shared/Api/Implementation/OSSL_Api.cs | 22 ++-- .../Implementation/Plugins/SensorRepeat.cs | 9 +- OpenSim/Region/ScriptEngine/Shared/Helpers.cs | 28 ++--- .../Region/ScriptEngine/Shared/LSL_Types.cs | 39 +++++++ .../ScriptEngine/XEngine/EventManager.cs | 20 +--- .../Region/ScriptEngine/XEngine/XEngine.cs | 4 +- 9 files changed, 119 insertions(+), 125 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 01a89b3421..2fa9ccc6ed 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1092,9 +1092,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Float llGround(LSL_Vector offset) { m_host.AddScriptLPS(1); - Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x, - (float)offset.y, - (float)offset.z); + Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset; //Get the slope normal. This gives us the equation of the plane tangent to the slope. LSL_Vector vsn = llGroundNormal(offset); @@ -1394,7 +1392,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (face == ScriptBaseClass.ALL_SIDES) face = SceneObjectPart.ALL_SIDES; - m_host.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); + m_host.SetFaceColor(color, face); } public void SetTexGen(SceneObjectPart part, int face,int style) @@ -1988,7 +1986,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api bool sameParcel = here.GlobalID == there.GlobalID; - if (!sameParcel && !World.Permissions.CanRezObject(m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, new Vector3((float)pos.x, (float)pos.y, (float)pos.z))) + if (!sameParcel && !World.Permissions.CanRezObject( + m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos)) { return 0; } @@ -2048,13 +2047,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0) targetPos.z = ground; SceneObjectGroup parent = part.ParentGroup; - LSL_Vector real_vec = !adjust ? targetPos : SetPosAdjust(currentPos, targetPos); - parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z)); + parent.UpdateGroupPosition(!adjust ? targetPos : + SetPosAdjust(currentPos, targetPos)); } else { - LSL_Vector rel_vec = !adjust ? targetPos : SetPosAdjust(currentPos, targetPos); - part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z); + part.OffsetPosition = !adjust ? targetPos : SetPosAdjust( + currentPos, targetPos); SceneObjectGroup parent = part.ParentGroup; parent.HasGroupChanged = true; parent.ScheduleGroupForTerseUpdate(); @@ -2098,7 +2097,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos); - return new LSL_Vector(pos.X, pos.Y, pos.Z); + return new LSL_Vector(pos); } public void llSetRot(LSL_Rotation rot) @@ -2214,7 +2213,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (local != 0) force *= llGetRot(); - m_host.ParentGroup.RootPart.SetForce(new Vector3((float)force.x, (float)force.y, (float)force.z)); + m_host.ParentGroup.RootPart.SetForce(force); } } @@ -2226,10 +2225,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!m_host.ParentGroup.IsDeleted) { - Vector3 tmpForce = m_host.ParentGroup.RootPart.GetForce(); - force.x = tmpForce.X; - force.y = tmpForce.Y; - force.z = tmpForce.Z; + force = m_host.ParentGroup.RootPart.GetForce(); } return force; @@ -2238,8 +2234,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llTarget(LSL_Vector position, double range) { m_host.AddScriptLPS(1); - return m_host.ParentGroup.registerTargetWaypoint( - new Vector3((float)position.x, (float)position.y, (float)position.z), (float)range); + return m_host.ParentGroup.registerTargetWaypoint(position, + (float)range); } public void llTargetRemove(int number) @@ -2264,7 +2260,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llMoveToTarget(LSL_Vector target, double tau) { m_host.AddScriptLPS(1); - m_host.MoveToTarget(new Vector3((float)target.x, (float)target.y, (float)target.z), (float)tau); + m_host.MoveToTarget(target, (float)tau); } public void llStopMoveToTarget() @@ -2277,7 +2273,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); //No energy force yet - Vector3 v = new Vector3((float)force.x, (float)force.y, (float)force.z); + Vector3 v = force; if (v.Length() > 20000.0f) { v.Normalize(); @@ -2289,13 +2285,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llApplyRotationalImpulse(LSL_Vector force, int local) { m_host.AddScriptLPS(1); - m_host.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0); + m_host.ApplyAngularImpulse(force, local != 0); } public void llSetTorque(LSL_Vector torque, int local) { m_host.AddScriptLPS(1); - m_host.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0); + m_host.SetAngularImpulse(torque, local != 0); } public LSL_Vector llGetTorque() @@ -2849,13 +2845,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api 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, item, llpos, Rot2Quaternion(rot), llvel, param); + SceneObjectGroup new_group = World.RezObject(m_host, item, pos, Rot2Quaternion(rot), vel, param); // If either of these are null, then there was an unknown error. if (new_group == null) @@ -2876,10 +2869,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api PhysicsActor pa = new_group.RootPart.PhysActor; - if (pa != null && pa.IsPhysical && llvel != Vector3.Zero) + if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) { //Recoil. - llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); + llApplyImpulse(vel * groupmass, 0); } // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) }); @@ -3405,7 +3398,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain) { - part.UpdateAngularVelocity(new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate))); + part.UpdateAngularVelocity(axis * spinrate); } public LSL_Integer llGetStartParameter() @@ -3604,7 +3597,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api List parts = GetLinkParts(linknumber); foreach (SceneObjectPart part in parts) - part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); + part.SetFaceColor(color, face); } public void llCreateLink(string target, int parent) @@ -4045,8 +4038,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llSetText(string text, LSL_Vector color, double alpha) { m_host.AddScriptLPS(1); - Vector3 av3 = Util.Clip(new Vector3((float)color.x, (float)color.y, - (float)color.z), 0.0f, 1.0f); + Vector3 av3 = Util.Clip(color, 0.0f, 1.0f); m_host.SetText(text.Length > 254 ? text.Remove(254) : text, av3, Util.Clip((float)alpha, 0.0f, 1.0f)); //m_host.ParentGroup.HasGroupChanged = true; //m_host.ParentGroup.ScheduleGroupForFullUpdate(); @@ -4243,14 +4235,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api ScriptSleep(5000); } - public void llTeleportAgent(string agent, string destination, LSL_Vector pos, LSL_Vector lookAt) + public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt) { m_host.AddScriptLPS(1); UUID agentId = new UUID(); - Vector3 targetPos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); - Vector3 targetLookAt = new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z); - if (UUID.TryParse(agent, out agentId)) { ScenePresence presence = World.GetScenePresence(agentId); @@ -4279,15 +4268,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } - public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector pos, LSL_Vector lookAt) + public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt) { m_host.AddScriptLPS(1); UUID agentId = new UUID(); ulong regionHandle = Utils.UIntsToLong((uint)global_coords.x, (uint)global_coords.y); - Vector3 targetPos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); - Vector3 targetLookAt = new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z); if (UUID.TryParse(agent, out agentId)) { ScenePresence presence = World.GetScenePresence(agentId); @@ -4563,7 +4550,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api distance_attenuation = 1f / normalized_units; } - Vector3 applied_linear_impulse = new Vector3((float)impulse.x, (float)impulse.y, (float)impulse.z); + Vector3 applied_linear_impulse = impulse; { float impulse_length = applied_linear_impulse.Length(); @@ -6012,9 +5999,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api //Plug the x,y coordinates of the slope normal into the equation of the plane to get //the height of that point on the plane. The resulting vector gives the slope. - Vector3 vsl = new Vector3(); - vsl.X = (float)vsn.x; - vsl.Y = (float)vsn.y; + Vector3 vsl = vsn; vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z)); vsl.Normalize(); //Normalization might be overkill here @@ -6025,9 +6010,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Vector llGroundNormal(LSL_Vector offset) { m_host.AddScriptLPS(1); - Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x, - (float)offset.y, - (float)offset.z); + Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset; // Clamp to valid position if (pos.X < 0) pos.X = 0; @@ -6480,8 +6463,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!m_host.ParentGroup.IsDeleted) { - m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, - new Vector3((float)vec.x, (float)vec.y, (float)vec.z)); + m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec); } } @@ -6523,7 +6505,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api 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.SitTargetPosition = offset; part.SitTargetOrientation = Rot2Quaternion(rot); part.ParentGroup.HasGroupChanged = true; } @@ -6627,13 +6609,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llSetCameraEyeOffset(LSL_Vector offset) { m_host.AddScriptLPS(1); - m_host.SetCameraEyeOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z)); + m_host.SetCameraEyeOffset(offset); } public void llSetCameraAtOffset(LSL_Vector offset) { m_host.AddScriptLPS(1); - m_host.SetCameraAtOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z)); + m_host.SetCameraAtOffset(offset); } public LSL_String llDumpList2String(LSL_List src, string seperator) @@ -6655,7 +6637,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llScriptDanger(LSL_Vector pos) { m_host.AddScriptLPS(1); - bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.x, (float)pos.y, (float)pos.z)); + bool result = World.ScriptDanger(m_host.LocalId, pos); if (result) { return 1; @@ -7481,7 +7463,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Vector color=rules.GetVector3Item(idx++); double alpha=(double)rules.GetLSLFloatItem(idx++); - part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); + part.SetFaceColor(color, face); SetAlpha(part, alpha, face); break; @@ -7600,9 +7582,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api string primText = rules.GetLSLStringItem(idx++); LSL_Vector primTextColor = rules.GetVector3Item(idx++); LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++); - Vector3 av3 = Util.Clip(new Vector3((float)primTextColor.x, - (float)primTextColor.y, - (float)primTextColor.z), 0.0f, 1.0f); + Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f); part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f)); break; @@ -7647,11 +7627,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (part.ParentGroup.RootPart == part) { SceneObjectGroup parent = part.ParentGroup; - parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z)); + parent.UpdateGroupPosition(currentPosition); } else { - part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z); + part.OffsetPosition = currentPosition; SceneObjectGroup parent = part.ParentGroup; parent.HasGroupChanged = true; parent.ScheduleGroupForTerseUpdate(); @@ -7882,8 +7862,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (part != null) { Vector3 halfSize = part.Scale / 2.0f; - LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); - LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); + LSL_Vector lower = (new LSL_Vector(halfSize)) * -1.0f; + LSL_Vector upper = new LSL_Vector(halfSize); result.Add(lower); result.Add(upper); return result; @@ -9885,9 +9865,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api ScenePresence avatar = World.GetScenePresence(detectedParams.Key); if (avatar != null) { - avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, simname, - new Vector3((float)pos.x, (float)pos.y, (float)pos.z), - new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); + avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, + simname, pos, lookAt); } ScriptSleep(1000); } @@ -11087,8 +11066,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); - Vector3 rayStart = new Vector3((float)start.x, (float)start.y, (float)start.z); - Vector3 rayEnd = new Vector3((float)end.x, (float)end.y, (float)end.z); + Vector3 rayStart = start; + Vector3 rayEnd = end; Vector3 dir = rayEnd - rayStart; float dist = Vector3.Mag(dir); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs index b399ce93b3..1d6cb6d4dc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs @@ -305,7 +305,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: idx++; iV = rules.GetVector3Item(idx); - wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); + wl.cloudDetailXYDensity = iV; break; case (int)ScriptBaseClass.WL_CLOUD_SCALE: idx++; @@ -330,7 +330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: idx++; iV = rules.GetVector3Item(idx); - wl.cloudXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); + wl.cloudXYDensity = iV; break; case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: idx++; @@ -385,7 +385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: idx++; iV = rules.GetVector3Item(idx); - wl.reflectionWaveletScale = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); + wl.reflectionWaveletScale = iV; break; case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: idx++; @@ -423,7 +423,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.WL_WATER_COLOR: idx++; iV = rules.GetVector3Item(idx); - wl.waterColor = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); + wl.waterColor = iV; break; case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: idx++; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 35f128c574..766a4ebb4d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -408,8 +408,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { if (type == typeof(OpenMetaverse.Vector3)) { - LSL_Vector vect = (LSL_Vector)lslparm; - return new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); + return (OpenMetaverse.Vector3)((LSL_Vector)lslparm); } } @@ -441,8 +440,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } else if (plist[i] is LSL_Vector) { - LSL_Vector vect = (LSL_Vector)plist[i]; - result[i] = new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); + result[i] = (OpenMetaverse.Vector3)( + (LSL_Vector)plist[i]); } else MODError("unknown LSL list element type"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 280fea63e6..78dc8666d3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -775,10 +775,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // We will launch the teleport on a new thread so that when the script threads are terminated // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. - Util.FireAndForget( - o => World.RequestTeleportLocation(presence.ControllingClient, regionName, - new Vector3((float)position.x, (float)position.y, (float)position.z), - new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation)); + Util.FireAndForget(o => World.RequestTeleportLocation( + presence.ControllingClient, regionName, position, + lookat, (uint)TPFlags.ViaLocation)); ScriptSleep(5000); @@ -821,10 +820,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // We will launch the teleport on a new thread so that when the script threads are terminated // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. - Util.FireAndForget( - o => World.RequestTeleportLocation(presence.ControllingClient, regionHandle, - new Vector3((float)position.x, (float)position.y, (float)position.z), - new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation)); + Util.FireAndForget(o => World.RequestTeleportLocation( + presence.ControllingClient, regionHandle, + position, lookat, (uint)TPFlags.ViaLocation)); ScriptSleep(5000); @@ -2338,7 +2336,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api ownerID = m_host.OwnerID; UUID x = module.CreateNPC(firstname, lastname, - new Vector3((float) position.x, (float) position.y, (float) position.z), + position, ownerID, senseAsAgent, World, @@ -2459,7 +2457,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return new LSL_Vector(0, 0, 0); } - public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) + public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos) { CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); m_host.AddScriptLPS(1); @@ -2474,7 +2472,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!module.CheckPermissions(npcId, m_host.OwnerID)) return; - Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); module.MoveToTarget(npcId, World, pos, false, true, false); } } @@ -2494,11 +2491,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!module.CheckPermissions(npcId, m_host.OwnerID)) return; - Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z); module.MoveToTarget( new UUID(npc.m_string), World, - pos, + target, (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0, (options & ScriptBaseClass.OS_NPC_RUNNING) != 0); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 0d45cd9d1c..8a8e9ce2e6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -433,9 +433,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins try { Vector3 diff = toRegionPos - fromRegionPos; - LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z); - double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); - double mag_obj = LSL_Types.Vector3.Mag(obj_dir); + double dot = LSL_Types.Vector3.Dot(forward_dir, diff); + double mag_obj = LSL_Types.Vector3.Mag(diff); ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); } catch @@ -565,8 +564,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins double ang_obj = 0; try { - Vector3 diff = toRegionPos - fromRegionPos; - LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z); + LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3( + toRegionPos - fromRegionPos); double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); double mag_obj = LSL_Types.Vector3.Mag(obj_dir); ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs index a3c2a47645..e02d35ed6d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs @@ -178,11 +178,11 @@ namespace OpenSim.Region.ScriptEngine.Shared else { // Set the values from the touch data provided by the client - touchST = new LSL_Types.Vector3(value.STCoord.X, value.STCoord.Y, value.STCoord.Z); - touchUV = new LSL_Types.Vector3(value.UVCoord.X, value.UVCoord.Y, value.UVCoord.Z); - touchNormal = new LSL_Types.Vector3(value.Normal.X, value.Normal.Y, value.Normal.Z); - touchBinormal = new LSL_Types.Vector3(value.Binormal.X, value.Binormal.Y, value.Binormal.Z); - touchPos = new LSL_Types.Vector3(value.Position.X, value.Position.Y, value.Position.Z); + touchST = new LSL_Types.Vector3(value.STCoord); + touchUV = new LSL_Types.Vector3(value.UVCoord); + touchNormal = new LSL_Types.Vector3(value.Normal); + touchBinormal = new LSL_Types.Vector3(value.Binormal); + touchPos = new LSL_Types.Vector3(value.Position); touchFace = value.FaceIndex; } } @@ -199,19 +199,13 @@ namespace OpenSim.Region.ScriptEngine.Shared Name = presence.Firstname + " " + presence.Lastname; Owner = Key; - Position = new LSL_Types.Vector3( - presence.AbsolutePosition.X, - presence.AbsolutePosition.Y, - presence.AbsolutePosition.Z); + Position = new LSL_Types.Vector3(presence.AbsolutePosition); Rotation = new LSL_Types.Quaternion( presence.Rotation.X, presence.Rotation.Y, presence.Rotation.Z, presence.Rotation.W); - Velocity = new LSL_Types.Vector3( - presence.Velocity.X, - presence.Velocity.Y, - presence.Velocity.Z); + Velocity = new LSL_Types.Vector3(presence.Velocity); if (presence.PresenceType != PresenceType.Npc) { @@ -259,16 +253,12 @@ namespace OpenSim.Region.ScriptEngine.Shared } } - Position = new LSL_Types.Vector3(part.AbsolutePosition.X, - part.AbsolutePosition.Y, - part.AbsolutePosition.Z); + Position = new LSL_Types.Vector3(part.AbsolutePosition); Quaternion wr = part.ParentGroup.GroupRotation; Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W); - Velocity = new LSL_Types.Vector3(part.Velocity.X, - part.Velocity.Y, - part.Velocity.Z); + Velocity = new LSL_Types.Vector3(part.Velocity); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index d23aba3f4d..a4f4d265a5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -31,6 +31,11 @@ using System.Globalization; using System.Text.RegularExpressions; using OpenSim.Framework; +using OpenMetaverse; +using OMV_Vector3 = OpenMetaverse.Vector3; +using OMV_Vector3d = OpenMetaverse.Vector3d; +using OMV_Quaternion = OpenMetaverse.Quaternion; + namespace OpenSim.Region.ScriptEngine.Shared { [Serializable] @@ -54,6 +59,20 @@ namespace OpenSim.Region.ScriptEngine.Shared z = (float)vector.z; } + public Vector3(OMV_Vector3 vector) + { + x = vector.X; + y = vector.Y; + z = vector.Z; + } + + public Vector3(OMV_Vector3d vector) + { + x = vector.X; + y = vector.Y; + z = vector.Z; + } + public Vector3(double X, double Y, double Z) { x = X; @@ -109,6 +128,26 @@ namespace OpenSim.Region.ScriptEngine.Shared return new list(new object[] { vec }); } + public static implicit operator OMV_Vector3(Vector3 vec) + { + return new OMV_Vector3((float)vec.x, (float)vec.y, (float)vec.z); + } + + public static implicit operator Vector3(OMV_Vector3 vec) + { + return new Vector3(vec); + } + + public static implicit operator OMV_Vector3d(Vector3 vec) + { + return new OMV_Vector3d(vec.x, vec.y, vec.z); + } + + public static implicit operator Vector3(OMV_Vector3d vec) + { + return new Vector3(vec); + } + public static bool operator ==(Vector3 lhs, Vector3 rhs) { return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs index aaf56c69b7..2dc59b41b2 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs @@ -152,9 +152,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine det[0] = new DetectParams(); det[0].Key = remoteClient.AgentId; det[0].Populate(myScriptEngine.World); - det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X, - offsetPos.Y, - offsetPos.Z); + det[0].OffsetPos = offsetPos; if (originalID == 0) { @@ -298,9 +296,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine foreach (DetectedObject detobj in col.Colliders) { DetectParams d = new DetectParams(); - d.Position = new LSL_Types.Vector3(detobj.posVector.X, - detobj.posVector.Y, - detobj.posVector.Z); + d.Position = detobj.posVector; d.Populate(myScriptEngine.World); det.Add(d); myScriptEngine.PostObjectEvent(localID, new EventParams( @@ -318,9 +314,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine foreach (DetectedObject detobj in col.Colliders) { DetectParams d = new DetectParams(); - d.Position = new LSL_Types.Vector3(detobj.posVector.X, - detobj.posVector.Y, - detobj.posVector.Z); + d.Position = detobj.posVector; d.Populate(myScriptEngine.World); det.Add(d); myScriptEngine.PostObjectEvent(localID, new EventParams( @@ -337,9 +331,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine foreach (DetectedObject detobj in col.Colliders) { DetectParams d = new DetectParams(); - d.Position = new LSL_Types.Vector3(detobj.posVector.X, - detobj.posVector.Y, - detobj.posVector.Z); + d.Position = detobj.posVector; d.Populate(myScriptEngine.World); det.Add(d); myScriptEngine.PostObjectEvent(localID, new EventParams( @@ -381,8 +373,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine myScriptEngine.PostObjectEvent(localID, new EventParams( "at_target", new object[] { new LSL_Types.LSLInteger(handle), - new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z), - new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) }, + new LSL_Types.Vector3(targetpos), + new LSL_Types.Vector3(atpos) }, new DetectParams[0])); } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 84d194ff84..cac4e5b428 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1616,7 +1616,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine else if (p[i] is string) lsl_p[i] = new LSL_Types.LSLString((string)p[i]); else if (p[i] is Vector3) - lsl_p[i] = new LSL_Types.Vector3(((Vector3)p[i]).X, ((Vector3)p[i]).Y, ((Vector3)p[i]).Z); + lsl_p[i] = new LSL_Types.Vector3((Vector3)p[i]); else if (p[i] is Quaternion) lsl_p[i] = new LSL_Types.Quaternion(((Quaternion)p[i]).X, ((Quaternion)p[i]).Y, ((Quaternion)p[i]).Z, ((Quaternion)p[i]).W); else if (p[i] is float) @@ -1642,7 +1642,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine else if (p[i] is string) lsl_p[i] = new LSL_Types.LSLString((string)p[i]); else if (p[i] is Vector3) - lsl_p[i] = new LSL_Types.Vector3(((Vector3)p[i]).X, ((Vector3)p[i]).Y, ((Vector3)p[i]).Z); + lsl_p[i] = new LSL_Types.Vector3((Vector3)p[i]); else if (p[i] is Quaternion) lsl_p[i] = new LSL_Types.Quaternion(((Quaternion)p[i]).X, ((Quaternion)p[i]).Y, ((Quaternion)p[i]).Z, ((Quaternion)p[i]).W); else if (p[i] is float)