aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-04-03 23:20:37 +0100
committerJustin Clark-Casey (justincc)2014-04-03 23:22:57 +0100
commitaec723b9552322fd29413086be223e38298df92f (patch)
treea85e0ecb32c161cdb507fb2d0c774d5d577b4ce8 /OpenSim/Region
parentremove some whitespace that snuck in with last patch (diff)
downloadopensim-SC_OLD-aec723b9552322fd29413086be223e38298df92f.zip
opensim-SC_OLD-aec723b9552322fd29413086be223e38298df92f.tar.gz
opensim-SC_OLD-aec723b9552322fd29413086be223e38298df92f.tar.bz2
opensim-SC_OLD-aec723b9552322fd29413086be223e38298df92f.tar.xz
Fix sp.AbsolutePosition when agent is sitting on a child prim, which in turns fixes llDetectedPos(), llGetLinkPrimitiveParams() and similar functions.
Add regression test for this case. In relation to http://opensimulator.org/mantis/view.php?id=7043
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs66
2 files changed, 64 insertions, 4 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index a0b4019..6e613a7 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -538,7 +538,7 @@ namespace OpenSim.Region.Framework.Scenes
538 SceneObjectPart sitPart = ParentPart; 538 SceneObjectPart sitPart = ParentPart;
539 539
540 if (sitPart != null) 540 if (sitPart != null)
541 return sitPart.AbsolutePosition + (m_pos * sitPart.GetWorldRotation()); 541 return sitPart.ParentGroup.AbsolutePosition + (m_pos * sitPart.GetWorldRotation());
542 } 542 }
543 543
544 return m_pos; 544 return m_pos;
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
index dcdec5c..03ea969 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
@@ -73,6 +73,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
73 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); 73 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
74 Assert.That(part.GetSittingAvatars(), Is.Null); 74 Assert.That(part.GetSittingAvatars(), Is.Null);
75 Assert.That(m_sp.ParentID, Is.EqualTo(0)); 75 Assert.That(m_sp.ParentID, Is.EqualTo(0));
76 Assert.AreEqual(startPos, m_sp.AbsolutePosition);
76 } 77 }
77 78
78 [Test] 79 [Test]
@@ -87,10 +88,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests
87 88
88 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; 89 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
89 90
91 // We need to preserve this here because phys actor is removed by the sit.
92 Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
90 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); 93 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
91 94
92 Assert.That(m_sp.PhysicsActor, Is.Null); 95 Assert.That(m_sp.PhysicsActor, Is.Null);
93 96
97 Assert.That(
98 m_sp.AbsolutePosition,
99 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
100
94 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); 101 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
95 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); 102 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
96 HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars(); 103 HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
@@ -129,6 +136,36 @@ namespace OpenSim.Region.Framework.Scenes.Tests
129 } 136 }
130 137
131 [Test] 138 [Test]
139 public void TestSitAndStandWithNoSitTargetChildPrim()
140 {
141 TestHelpers.InMethod();
142// log4net.Config.XmlConfigurator.Configure();
143
144 // Make sure we're within range to sit
145 Vector3 startPos = new Vector3(1, 1, 1);
146 m_sp.AbsolutePosition = startPos;
147
148 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene, 2, m_sp.UUID, "part", 0x10).Parts[1];
149 part.OffsetPosition = new Vector3(2, 3, 4);
150
151 // We need to preserve this here because phys actor is removed by the sit.
152 Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
153 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
154
155 Assert.That(
156 m_sp.AbsolutePosition,
157 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
158
159 m_sp.StandUp();
160
161 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
162 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
163 Assert.That(part.GetSittingAvatars(), Is.Null);
164 Assert.That(m_sp.ParentID, Is.EqualTo(0));
165 Assert.That(m_sp.PhysicsActor, Is.Not.Null);
166 }
167
168 [Test]
132 public void TestSitAndStandWithSitTarget() 169 public void TestSitAndStandWithSitTarget()
133 { 170 {
134 TestHelpers.InMethod(); 171 TestHelpers.InMethod();
@@ -145,9 +182,32 @@ namespace OpenSim.Region.Framework.Scenes.Tests
145 182
146 Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID)); 183 Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID));
147 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); 184 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
148// Assert.That( 185
149// m_sp.AbsolutePosition, 186 // This section is copied from ScenePresence.HandleAgentSit(). Correctness is not guaranteed.
150// Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); 187 Quaternion r = part.SitTargetOrientation;
188 double x, y, z, m;
189 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
190
191 if (Math.Abs(1.0 - m) > 0.000001)
192 {
193 m = 1.0 / Math.Sqrt(m);
194 r.X *= (float)m;
195 r.Y *= (float)m;
196 r.Z *= (float)m;
197 r.W *= (float)m;
198 }
199
200 x = 2 * (r.X * r.Z + r.Y * r.W);
201 y = 2 * (-r.X * r.W + r.Y * r.Z);
202 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
203
204 Vector3 up = new Vector3((float)x, (float)y, (float)z);
205 Vector3 sitOffset = up * m_sp.Appearance.AvatarHeight * 0.02638f;
206 // End of copied section.
207
208 Assert.That(
209 m_sp.AbsolutePosition,
210 Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + sitOffset + ScenePresence.SIT_TARGET_ADJUSTMENT));
151 Assert.That(m_sp.PhysicsActor, Is.Null); 211 Assert.That(m_sp.PhysicsActor, Is.Null);
152 212
153 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); 213 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));