OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneObjectSpatialTests.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.Reflection;
30 using System.Threading;
31 using NUnit.Framework;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Tests.Common;
36 
37 namespace OpenSim.Region.Framework.Scenes.Tests
38 {
42  [TestFixture]
44  {
45  TestScene m_scene;
46  UUID m_ownerId = TestHelpers.ParseTail(0x1);
47 
48  [SetUp]
49  public override void SetUp()
50  {
51  base.SetUp();
52 
53  m_scene = new SceneHelpers().SetupScene();
54  }
55 
56  [Test]
58  {
59  TestHelpers.InMethod();
60 
61  Vector3 position = new Vector3(10, 20, 30);
62 
64  = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10);
65  so.AbsolutePosition = position;
66  m_scene.AddNewSceneObject(so, false);
67 
68  Assert.That(so.AbsolutePosition, Is.EqualTo(position));
69  }
70 
71  [Test]
73  {
74  TestHelpers.InMethod();
75 
76  Vector3 partPosition = new Vector3(10, 20, 30);
77 
79  = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10);
80  so.AbsolutePosition = partPosition;
81  m_scene.AddNewSceneObject(so, false);
82 
83  Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition));
84  Assert.That(so.RootPart.GroupPosition, Is.EqualTo(partPosition));
85  Assert.That(so.RootPart.GetWorldPosition(), Is.EqualTo(partPosition));
86  Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition));
87  Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero));
88  }
89 
90  [Test]
92  {
93  TestHelpers.InMethod();
94 
95  Vector3 rootPartPosition = new Vector3(10, 20, 30);
96  Vector3 childOffsetPosition = new Vector3(2, 3, 4);
97 
99  = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10);
100  so.AbsolutePosition = rootPartPosition;
101  so.Parts[1].OffsetPosition = childOffsetPosition;
102 
103  m_scene.AddNewSceneObject(so, false);
104 
105  // Calculate child absolute position.
106  Vector3 childPosition = new Vector3(rootPartPosition + childOffsetPosition);
107 
108  SceneObjectPart childPart = so.Parts[1];
109  Assert.That(childPart.AbsolutePosition, Is.EqualTo(childPosition));
110  Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition));
111  Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition));
112  Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition));
113  Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition));
114  }
115 
116  [Test]
118  {
119  TestHelpers.InMethod();
120 
121  Vector3 rootPartPosition = new Vector3(10, 20, 30);
122  Vector3 childOffsetPosition = new Vector3(2, 3, 4);
123 
125  = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10);
126  so.AbsolutePosition = rootPartPosition;
127  so.Parts[1].OffsetPosition = childOffsetPosition;
128 
129  m_scene.AddNewSceneObject(so, false);
130 
131  so.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 0, -90 * Utils.DEG_TO_RAD));
132 
133  // Calculate child absolute position.
134  Vector3 rotatedChildOffsetPosition
135  = new Vector3(childOffsetPosition.Y, -childOffsetPosition.X, childOffsetPosition.Z);
136 
137  Vector3 childPosition = new Vector3(rootPartPosition + rotatedChildOffsetPosition);
138 
139  SceneObjectPart childPart = so.Parts[1];
140 
141  Assert.That(childPart.AbsolutePosition, Is.EqualTo(childPosition));
142 
143  Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition));
144  Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition));
145 
146  // Relative to root part as (0, 0, 0)
147  Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition));
148 
149  // Relative to root part as (0, 0, 0)
150  Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition));
151  }
152  }
153 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Spatial scene object tests (will eventually cover root and child part position, rotation properties...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60