clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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.Communications; |
||
36 | using OpenSim.Framework.Servers; |
||
37 | using OpenSim.Region.Framework.Interfaces; |
||
38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; |
||
39 | using OpenSim.Tests.Common; |
||
40 | using OpenSim.Tests.Common.Mock; |
||
41 | using System.Threading; |
||
42 | |||
43 | namespace OpenSim.Region.Framework.Scenes.Tests |
||
44 | { |
||
45 | [TestFixture] |
||
46 | public class ScenePresenceSitTests : OpenSimTestCase |
||
47 | { |
||
48 | private TestScene m_scene; |
||
49 | private ScenePresence m_sp; |
||
50 | |||
51 | [SetUp] |
||
52 | public void Init() |
||
53 | { |
||
54 | m_scene = new SceneHelpers().SetupScene(); |
||
55 | m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
56 | } |
||
57 | |||
58 | [Test] |
||
59 | public void TestSitOutsideRangeNoTarget() |
||
60 | { |
||
61 | TestHelpers.InMethod(); |
||
62 | // log4net.Config.XmlConfigurator.Configure(); |
||
63 | |||
64 | // More than 10 meters away from 0, 0, 0 (default part position) |
||
65 | Vector3 startPos = new Vector3(10.1f, 0, 0); |
||
66 | m_sp.AbsolutePosition = startPos; |
||
67 | |||
68 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; |
||
69 | |||
70 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); |
||
71 | |||
72 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
73 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); |
||
74 | Assert.That(part.GetSittingAvatars(), Is.Null); |
||
75 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); |
||
76 | Assert.AreEqual(startPos, m_sp.AbsolutePosition); |
||
77 | } |
||
78 | |||
79 | [Test] |
||
80 | public void TestSitWithinRangeNoTarget() |
||
81 | { |
||
82 | TestHelpers.InMethod(); |
||
83 | // log4net.Config.XmlConfigurator.Configure(); |
||
84 | |||
85 | // Less than 10 meters away from 0, 0, 0 (default part position) |
||
86 | Vector3 startPos = new Vector3(9.9f, 0, 0); |
||
87 | m_sp.AbsolutePosition = startPos; |
||
88 | |||
89 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; |
||
90 | |||
91 | // We need to preserve this here because phys actor is removed by the sit. |
||
92 | Vector3 spPhysActorSize = m_sp.PhysicsActor.Size; |
||
93 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); |
||
94 | |||
95 | Assert.That(m_sp.PhysicsActor, Is.Null); |
||
96 | |||
97 | Assert.That( |
||
98 | m_sp.AbsolutePosition, |
||
99 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2))); |
||
100 | |||
101 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
102 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); |
||
103 | HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars(); |
||
104 | Assert.That(sittingAvatars.Count, Is.EqualTo(1)); |
||
105 | Assert.That(sittingAvatars.Contains(m_sp)); |
||
106 | Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); |
||
107 | } |
||
108 | |||
109 | [Test] |
||
110 | public void TestSitAndStandWithNoSitTarget() |
||
111 | { |
||
112 | TestHelpers.InMethod(); |
||
113 | // log4net.Config.XmlConfigurator.Configure(); |
||
114 | |||
115 | // Make sure we're within range to sit |
||
116 | Vector3 startPos = new Vector3(1, 1, 1); |
||
117 | m_sp.AbsolutePosition = startPos; |
||
118 | |||
119 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; |
||
120 | |||
121 | // We need to preserve this here because phys actor is removed by the sit. |
||
122 | Vector3 spPhysActorSize = m_sp.PhysicsActor.Size; |
||
123 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); |
||
124 | |||
125 | Assert.That( |
||
126 | m_sp.AbsolutePosition, |
||
127 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, spPhysActorSize.Z / 2))); |
||
128 | |||
129 | m_sp.StandUp(); |
||
130 | |||
131 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
132 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); |
||
133 | Assert.That(part.GetSittingAvatars(), Is.Null); |
||
134 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); |
||
135 | Assert.That(m_sp.PhysicsActor, Is.Not.Null); |
||
136 | } |
||
137 | |||
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] |
||
169 | public void TestSitAndStandWithSitTarget() |
||
170 | { |
||
171 | TestHelpers.InMethod(); |
||
172 | // log4net.Config.XmlConfigurator.Configure(); |
||
173 | |||
174 | // If a prim has a sit target then we can sit from any distance away |
||
175 | Vector3 startPos = new Vector3(128, 128, 30); |
||
176 | m_sp.AbsolutePosition = startPos; |
||
177 | |||
178 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; |
||
179 | part.SitTargetPosition = new Vector3(0, 0, 1); |
||
180 | |||
181 | m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); |
||
182 | |||
183 | Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID)); |
||
184 | Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); |
||
185 | |||
186 | // This section is copied from ScenePresence.HandleAgentSit(). Correctness is not guaranteed. |
||
187 | double x, y, z, m1, m2; |
||
188 | |||
189 | Quaternion r = part.SitTargetOrientation;; |
||
190 | m1 = r.X * r.X + r.Y * r.Y; |
||
191 | m2 = r.Z * r.Z + r.W * r.W; |
||
192 | |||
193 | // Rotate the vector <0, 0, 1> |
||
194 | x = 2 * (r.X * r.Z + r.Y * r.W); |
||
195 | y = 2 * (-r.X * r.W + r.Y * r.Z); |
||
196 | z = m2 - m1; |
||
197 | |||
198 | // Set m to be the square of the norm of r. |
||
199 | double m = m1 + m2; |
||
200 | |||
201 | // This constant is emperically determined to be what is used in SL. |
||
202 | // See also http://opensimulator.org/mantis/view.php?id=7096 |
||
203 | double offset = 0.05; |
||
204 | |||
205 | Vector3 up = new Vector3((float)x, (float)y, (float)z); |
||
206 | Vector3 sitOffset = up * (float)offset; |
||
207 | // End of copied section. |
||
208 | |||
209 | Assert.That( |
||
210 | m_sp.AbsolutePosition, |
||
211 | Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition - sitOffset + ScenePresence.SIT_TARGET_ADJUSTMENT)); |
||
212 | Assert.That(m_sp.PhysicsActor, Is.Null); |
||
213 | |||
214 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); |
||
215 | HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars(); |
||
216 | Assert.That(sittingAvatars.Count, Is.EqualTo(1)); |
||
217 | Assert.That(sittingAvatars.Contains(m_sp)); |
||
218 | |||
219 | m_sp.StandUp(); |
||
220 | |||
221 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
222 | Assert.That(m_sp.ParentID, Is.EqualTo(0)); |
||
223 | Assert.That(m_sp.PhysicsActor, Is.Not.Null); |
||
224 | |||
225 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
226 | Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0)); |
||
227 | Assert.That(part.GetSittingAvatars(), Is.Null); |
||
228 | } |
||
229 | |||
230 | [Test] |
||
231 | public void TestSitAndStandOnGround() |
||
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 | } |