OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ScenePresenceSitTests.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using Nini.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Servers;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
38 using OpenSim.Tests.Common;
39 using System.Threading;
40 
41 namespace OpenSim.Region.Framework.Scenes.Tests
42 {
43  [TestFixture]
45  {
46  private TestScene m_scene;
47  private ScenePresence m_sp;
48 
49  [SetUp]
50  public void Init()
51  {
52  m_scene = new SceneHelpers().SetupScene();
53  m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
54  }
55 
56  [Test]
58  {
59  TestHelpers.InMethod();
60 // log4net.Config.XmlConfigurator.Configure();
61 
62  // More than 10 meters away from 0, 0, 0 (default part position)
63  Vector3 startPos = new Vector3(10.1f, 0, 0);
64  m_sp.AbsolutePosition = startPos;
65 
66  SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
67 
68  m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
69 
70  Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
71  Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
72  Assert.That(part.GetSittingAvatars(), Is.Null);
73  Assert.That(m_sp.ParentID, Is.EqualTo(0));
74  Assert.AreEqual(startPos, m_sp.AbsolutePosition);
75  }
76 
77  [Test]
79  {
80  TestHelpers.InMethod();
81 // log4net.Config.XmlConfigurator.Configure();
82 
83  // Less than 10 meters away from 0, 0, 0 (default part position)
84  Vector3 startPos = new Vector3(9.9f, 0, 0);
85  m_sp.AbsolutePosition = startPos;
86 
87  SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
88 
89  // We need to preserve this here because phys actor is removed by the sit.
90  Vector3 spPhysActorSize = m_sp.PhysicsActor.Size;
91  m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
92 
93  Assert.That(m_sp.PhysicsActor, Is.Null);
94 
95  Assert.That(
96  m_sp.AbsolutePosition,
97  Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
98 
99  Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
100  Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
101  HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
102  Assert.That(sittingAvatars.Count, Is.EqualTo(1));
103  Assert.That(sittingAvatars.Contains(m_sp));
104  Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
105  }
106 
107  [Test]
109  {
110  TestHelpers.InMethod();
111 // log4net.Config.XmlConfigurator.Configure();
112 
113  // Make sure we're within range to sit
114  Vector3 startPos = new Vector3(1, 1, 1);
115  m_sp.AbsolutePosition = startPos;
116 
117  SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
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]
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;
151  m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
152 
153  Assert.That(
154  m_sp.AbsolutePosition,
155  Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2)));
156 
157  m_sp.StandUp();
158 
159  Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
160  Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
161  Assert.That(part.GetSittingAvatars(), Is.Null);
162  Assert.That(m_sp.ParentID, Is.EqualTo(0));
163  Assert.That(m_sp.PhysicsActor, Is.Not.Null);
164  }
165 
166  [Test]
168  {
169 /* sit position math as changed, this needs to be fixed later
170  TestHelpers.InMethod();
171 // log4net.Config.XmlConfigurator.Configure();
172 
173  // If a prim has a sit target then we can sit from any distance away
174  Vector3 startPos = new Vector3(128, 128, 30);
175  m_sp.AbsolutePosition = startPos;
176 
177  SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
178  part.SitTargetPosition = new Vector3(0, 0, 1);
179 
180  m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
181 
182  Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID));
183  Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
184 
185  // This section is copied from ScenePresence.HandleAgentSit(). Correctness is not guaranteed.
186  double x, y, z, m1, m2;
187 
188  Quaternion r = part.SitTargetOrientation;;
189  m1 = r.X * r.X + r.Y * r.Y;
190  m2 = r.Z * r.Z + r.W * r.W;
191 
192  // Rotate the vector <0, 0, 1>
193  x = 2 * (r.X * r.Z + r.Y * r.W);
194  y = 2 * (-r.X * r.W + r.Y * r.Z);
195  z = m2 - m1;
196 
197  // Set m to be the square of the norm of r.
198  double m = m1 + m2;
199 
200  // This constant is emperically determined to be what is used in SL.
201  // See also http://opensimulator.org/mantis/view.php?id=7096
202  double offset = 0.05;
203 
204  Vector3 up = new Vector3((float)x, (float)y, (float)z);
205  Vector3 sitOffset = up * (float)offset;
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));
211  Assert.That(m_sp.PhysicsActor, Is.Null);
212 
213  Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
214  HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
215  Assert.That(sittingAvatars.Count, Is.EqualTo(1));
216  Assert.That(sittingAvatars.Contains(m_sp));
217 
218  m_sp.StandUp();
219 
220  Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
221  Assert.That(m_sp.ParentID, Is.EqualTo(0));
222  Assert.That(m_sp.PhysicsActor, Is.Not.Null);
223 
224  Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
225  Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
226  Assert.That(part.GetSittingAvatars(), Is.Null);
227 */
228  }
229 
230  [Test]
232  {
233  TestHelpers.InMethod();
234 // log4net.Config.XmlConfigurator.Configure();
235 
236  // If a prim has a sit target then we can sit from any distance away
237 // Vector3 startPos = new Vector3(128, 128, 30);
238 // sp.AbsolutePosition = startPos;
239 
240  m_sp.HandleAgentSitOnGround();
241 
242  Assert.That(m_sp.SitGround, Is.True);
243  Assert.That(m_sp.PhysicsActor, Is.Null);
244 
245  m_sp.StandUp();
246 
247  Assert.That(m_sp.SitGround, Is.False);
248  Assert.That(m_sp.PhysicsActor, Is.Not.Null);
249  }
250  }
251 }
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60