diff options
author | Melanie Thielker | 2010-08-22 13:42:29 +0200 |
---|---|---|
committer | Melanie Thielker | 2010-08-22 13:42:29 +0200 |
commit | a0a25bb8ca846c87b3e8e0de74d4fbcc985ae456 (patch) | |
tree | 04d549fc297cdd701a7386874d4bc756d07f5568 /OpenSim/Region/ScriptEngine/Shared/Api/Implementation | |
parent | Don't allow oversized search reply packets (diff) | |
download | opensim-SC-a0a25bb8ca846c87b3e8e0de74d4fbcc985ae456.zip opensim-SC-a0a25bb8ca846c87b3e8e0de74d4fbcc985ae456.tar.gz opensim-SC-a0a25bb8ca846c87b3e8e0de74d4fbcc985ae456.tar.bz2 opensim-SC-a0a25bb8ca846c87b3e8e0de74d4fbcc985ae456.tar.xz |
A stab at making a better bounding box calculation
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 105 |
1 files changed, 74 insertions, 31 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 9615d08..d856464 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -7829,55 +7829,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7829 | m_host.AddScriptLPS(1); | 7829 | m_host.AddScriptLPS(1); |
7830 | UUID objID = UUID.Zero; | 7830 | UUID objID = UUID.Zero; |
7831 | LSL_List result = new LSL_List(); | 7831 | LSL_List result = new LSL_List(); |
7832 | |||
7833 | // If the ID is not valid, return null result | ||
7832 | if (!UUID.TryParse(obj, out objID)) | 7834 | if (!UUID.TryParse(obj, out objID)) |
7833 | { | 7835 | { |
7834 | result.Add(new LSL_Vector()); | 7836 | result.Add(new LSL_Vector()); |
7835 | result.Add(new LSL_Vector()); | 7837 | result.Add(new LSL_Vector()); |
7836 | return result; | 7838 | return result; |
7837 | } | 7839 | } |
7840 | |||
7841 | // Check if this is an attached prim. If so, replace | ||
7842 | // the UUID with the avatar UUID and report it's bounding box | ||
7843 | SceneObjectPart part = World.GetSceneObjectPart(objID); | ||
7844 | if (part != null && part.ParentGroup.IsAttachment) | ||
7845 | objID = part.ParentGroup.RootPart.AttachedAvatar; | ||
7846 | |||
7847 | // Find out if this is an avatar ID. If so, return it's box | ||
7838 | ScenePresence presence = World.GetScenePresence(objID); | 7848 | ScenePresence presence = World.GetScenePresence(objID); |
7839 | if (presence != null) | 7849 | if (presence != null) |
7840 | { | 7850 | { |
7841 | if (presence.ParentID == 0) // not sat on an object | 7851 | // As per LSL Wiki, there is no difference between sitting |
7852 | // and standing avatar since server 1.36 | ||
7853 | LSL_Vector lower; | ||
7854 | LSL_Vector upper; | ||
7855 | if (presence.Animator.Animations.DefaultAnimation.AnimID | ||
7856 | == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) | ||
7842 | { | 7857 | { |
7843 | LSL_Vector lower; | 7858 | // This is for ground sitting avatars |
7844 | LSL_Vector upper; | 7859 | float height = presence.Appearance.AvatarHeight / 2.66666667f; |
7845 | if (presence.Animator.Animations.DefaultAnimation.AnimID | 7860 | lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); |
7846 | == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) | 7861 | upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); |
7847 | { | ||
7848 | // This is for ground sitting avatars | ||
7849 | float height = presence.Appearance.AvatarHeight / 2.66666667f; | ||
7850 | lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); | ||
7851 | upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); | ||
7852 | } | ||
7853 | else | ||
7854 | { | ||
7855 | // This is for standing/flying avatars | ||
7856 | float height = presence.Appearance.AvatarHeight / 2.0f; | ||
7857 | lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); | ||
7858 | upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); | ||
7859 | } | ||
7860 | result.Add(lower); | ||
7861 | result.Add(upper); | ||
7862 | return result; | ||
7863 | } | 7862 | } |
7864 | else | 7863 | else |
7865 | { | 7864 | { |
7866 | // sitting on an object so we need the bounding box of that | 7865 | // This is for standing/flying avatars |
7867 | // which should include the avatar so set the UUID to the | 7866 | float height = presence.Appearance.AvatarHeight / 2.0f; |
7868 | // UUID of the object the avatar is sat on and allow it to fall through | 7867 | lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); |
7869 | // to processing an object | 7868 | upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); |
7870 | SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID); | ||
7871 | objID = p.UUID; | ||
7872 | } | 7869 | } |
7870 | |||
7871 | // Adjust to the documented error offsets (see LSL Wiki) | ||
7872 | lower += new LSL_Vector(0.05f, 0.05f, 0.05f); | ||
7873 | upper -= new LSL_Vector(0.05f, 0.05f, 0.05f); | ||
7874 | |||
7875 | if (lower.x > upper.x) | ||
7876 | lower.x = upper.x; | ||
7877 | if (lower.y > upper.y) | ||
7878 | lower.y = upper.y; | ||
7879 | if (lower.z > upper.z) | ||
7880 | lower.z = upper.z; | ||
7881 | |||
7882 | result.Add(lower); | ||
7883 | result.Add(upper); | ||
7884 | return result; | ||
7873 | } | 7885 | } |
7874 | SceneObjectPart part = World.GetSceneObjectPart(objID); | 7886 | |
7887 | part = World.GetSceneObjectPart(objID); | ||
7875 | // Currently only works for single prims without a sitting avatar | 7888 | // Currently only works for single prims without a sitting avatar |
7876 | if (part != null) | 7889 | if (part != null) |
7877 | { | 7890 | { |
7878 | Vector3 halfSize = part.Scale / 2.0f; | 7891 | float minX; |
7879 | LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); | 7892 | float maxX; |
7880 | LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); | 7893 | float minY; |
7894 | float maxY; | ||
7895 | float minZ; | ||
7896 | float maxZ; | ||
7897 | |||
7898 | // This BBox is in sim coordinates, with the offset being | ||
7899 | // a contained point. | ||
7900 | Vector3[] offsets = World.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup }, | ||
7901 | out minX, out maxX, out minY, out maxY, out minZ, out maxZ); | ||
7902 | |||
7903 | minX -= offsets[0].X; | ||
7904 | maxX -= offsets[0].X; | ||
7905 | minY -= offsets[0].Y; | ||
7906 | maxY -= offsets[0].Y; | ||
7907 | minZ -= offsets[0].Z; | ||
7908 | maxZ -= offsets[0].Z; | ||
7909 | |||
7910 | LSL_Vector lower; | ||
7911 | LSL_Vector upper; | ||
7912 | |||
7913 | // Adjust to the documented error offsets (see LSL Wiki) | ||
7914 | lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f); | ||
7915 | upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f); | ||
7916 | |||
7917 | if (lower.x > upper.x) | ||
7918 | lower.x = upper.x; | ||
7919 | if (lower.y > upper.y) | ||
7920 | lower.y = upper.y; | ||
7921 | if (lower.z > upper.z) | ||
7922 | lower.z = upper.z; | ||
7923 | |||
7881 | result.Add(lower); | 7924 | result.Add(lower); |
7882 | result.Add(upper); | 7925 | result.Add(upper); |
7883 | return result; | 7926 | return result; |