aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs81
1 files changed, 69 insertions, 12 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
index acaeb90..b232a44 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
@@ -32,12 +32,10 @@ using Nini.Config;
32using NUnit.Framework; 32using NUnit.Framework;
33using OpenMetaverse; 33using OpenMetaverse;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers; 35using OpenSim.Framework.Servers;
37using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; 37using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
39using OpenSim.Tests.Common; 38using OpenSim.Tests.Common;
40using OpenSim.Tests.Common.Mock;
41using System.Threading; 39using System.Threading;
42 40
43namespace OpenSim.Region.Framework.Scenes.Tests 41namespace OpenSim.Region.Framework.Scenes.Tests
@@ -73,6 +71,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
73 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); 71 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
74 Assert.That(part.GetSittingAvatars(), Is.Null); 72 Assert.That(part.GetSittingAvatars(), Is.Null);
75 Assert.That(m_sp.ParentID, Is.EqualTo(0)); 73 Assert.That(m_sp.ParentID, Is.EqualTo(0));
74 Assert.AreEqual(startPos, m_sp.AbsolutePosition);
76 } 75 }
77 76
78 [Test] 77 [Test]
@@ -87,15 +86,21 @@ namespace OpenSim.Region.Framework.Scenes.Tests
87 86
88 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; 87 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
89 88
89 // We need to preserve this here because phys actor is removed by the sit.
90 Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
90 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); 91 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
91 92
92 Assert.That(m_sp.PhysicsActor, Is.Null); 93 Assert.That(m_sp.PhysicsActor, Is.Null);
93 94
95 Assert.That(
96 m_sp.AbsolutePosition,
97 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
98
94 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); 99 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
95 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); 100 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
96 HashSet<UUID> sittingAvatars = part.GetSittingAvatars(); 101 HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
97 Assert.That(sittingAvatars.Count, Is.EqualTo(1)); 102 Assert.That(sittingAvatars.Count, Is.EqualTo(1));
98 Assert.That(sittingAvatars.Contains(m_sp.UUID)); 103 Assert.That(sittingAvatars.Contains(m_sp));
99 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); 104 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
100 } 105 }
101 106
@@ -111,15 +116,43 @@ namespace OpenSim.Region.Framework.Scenes.Tests
111 116
112 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; 117 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
113 118
119 // We need to preserve this here because phys actor is removed by the sit.
120 Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
121 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
122
123 Assert.That(
124 m_sp.AbsolutePosition,
125 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
126
127 m_sp.StandUp();
128
129 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
130 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
131 Assert.That(part.GetSittingAvatars(), Is.Null);
132 Assert.That(m_sp.ParentID, Is.EqualTo(0));
133 Assert.That(m_sp.PhysicsActor, Is.Not.Null);
134 }
135
136 [Test]
137 public void TestSitAndStandWithNoSitTargetChildPrim()
138 {
139 TestHelpers.InMethod();
140// log4net.Config.XmlConfigurator.Configure();
141
142 // Make sure we're within range to sit
143 Vector3 startPos = new Vector3(1, 1, 1);
144 m_sp.AbsolutePosition = startPos;
145
146 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene, 2, m_sp.UUID, "part", 0x10).Parts[1];
147 part.OffsetPosition = new Vector3(2, 3, 4);
148
149 // We need to preserve this here because phys actor is removed by the sit.
150 Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
114 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); 151 m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
115 152
116 // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the
117 // default avatar.
118 // Curiously, Vector3.ToString() will not display the last two places of the float. For example,
119 // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337>
120 Assert.That( 153 Assert.That(
121 m_sp.AbsolutePosition, 154 m_sp.AbsolutePosition,
122 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f))); 155 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
123 156
124 m_sp.StandUp(); 157 m_sp.StandUp();
125 158
@@ -147,15 +180,39 @@ namespace OpenSim.Region.Framework.Scenes.Tests
147 180
148 Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID)); 181 Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID));
149 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); 182 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
183
184 // This section is copied from ScenePresence.HandleAgentSit(). Correctness is not guaranteed.
185 double x, y, z, m1, m2;
186
187 Quaternion r = part.SitTargetOrientation;;
188 m1 = r.X * r.X + r.Y * r.Y;
189 m2 = r.Z * r.Z + r.W * r.W;
190
191 // Rotate the vector <0, 0, 1>
192 x = 2 * (r.X * r.Z + r.Y * r.W);
193 y = 2 * (-r.X * r.W + r.Y * r.Z);
194 z = m2 - m1;
195
196 // Set m to be the square of the norm of r.
197 double m = m1 + m2;
198
199 // This constant is emperically determined to be what is used in SL.
200 // See also http://opensimulator.org/mantis/view.php?id=7096
201 double offset = 0.05;
202
203 Vector3 up = new Vector3((float)x, (float)y, (float)z);
204 Vector3 sitOffset = up * (float)offset;
205 // End of copied section.
206
150 Assert.That( 207 Assert.That(
151 m_sp.AbsolutePosition, 208 m_sp.AbsolutePosition,
152 Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); 209 Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition - sitOffset + ScenePresence.SIT_TARGET_ADJUSTMENT));
153 Assert.That(m_sp.PhysicsActor, Is.Null); 210 Assert.That(m_sp.PhysicsActor, Is.Null);
154 211
155 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); 212 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
156 HashSet<UUID> sittingAvatars = part.GetSittingAvatars(); 213 HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
157 Assert.That(sittingAvatars.Count, Is.EqualTo(1)); 214 Assert.That(sittingAvatars.Count, Is.EqualTo(1));
158 Assert.That(sittingAvatars.Contains(m_sp.UUID)); 215 Assert.That(sittingAvatars.Contains(m_sp));
159 216
160 m_sp.StandUp(); 217 m_sp.StandUp();
161 218