OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ScenePresenceAutopilotTests.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 log4net;
32 using Nini.Config;
33 using NUnit.Framework;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Tests.Common;
39 
40 namespace OpenSim.Region.Framework.Scenes.Tests
41 {
42  [TestFixture]
44  {
45  private TestScene m_scene;
46 
47  [TestFixtureSetUp]
48  public void FixtureInit()
49  {
50  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
51  Util.FireAndForgetMethod = FireAndForgetMethod.None;
52  }
53 
54  [TestFixtureTearDown]
55  public void TearDown()
56  {
57  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
58  // threads. Possibly, later tests should be rewritten not to worry about such things.
59  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
60  }
61 
62  [SetUp]
63  public void Init()
64  {
65  m_scene = new SceneHelpers().SetupScene();
66  }
67 
68  [Test]
69  public void TestMove()
70  {
71  TestHelpers.InMethod();
72 // log4net.Config.XmlConfigurator.Configure();
73 
74  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
75 
76  Vector3 startPos = sp.AbsolutePosition;
77 // Vector3 startPos = new Vector3(128, 128, 30);
78 
79  // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
80  sp.Flying = true;
81 
82  m_scene.Update(1);
83  Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
84 
85  Vector3 targetPos = startPos + new Vector3(0, 10, 0);
86  sp.MoveToTarget(targetPos, false, false);
87 
88  Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
89  Assert.That(
90  sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));
91 
92  m_scene.Update(1);
93 
94  // We should really check the exact figure.
95  Assert.That(sp.AbsolutePosition.X, Is.EqualTo(startPos.X));
96  Assert.That(sp.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
97  Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
98  Assert.That(sp.AbsolutePosition.Z, Is.LessThan(targetPos.X));
99 
100  m_scene.Update(10);
101 
102  double distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos);
103  Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on first move");
104  Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos));
105  Assert.That(sp.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
106 
107  // Try a second movement
108  startPos = sp.AbsolutePosition;
109  targetPos = startPos + new Vector3(10, 0, 0);
110  sp.MoveToTarget(targetPos, false, false);
111 
112  Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
113  Assert.That(
114  sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001));
115 
116  m_scene.Update(1);
117 
118  // We should really check the exact figure.
119  Assert.That(sp.AbsolutePosition.X, Is.GreaterThan(startPos.X));
120  Assert.That(sp.AbsolutePosition.X, Is.LessThan(targetPos.X));
121  Assert.That(sp.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
122  Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
123 
124  m_scene.Update(10);
125 
126  distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos);
127  Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on second move");
128  Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos));
129  }
130  }
131 }
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60