opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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.Framework.Communications;
35 using OpenSim.Region.Framework.Scenes;
36 using OpenSim.Tests.Common;
37 using OpenSim.Tests.Common.Mock;
38  
39 namespace OpenSim.Region.Framework.Scenes.Tests
40 {
41 /// <summary>
42 /// Spatial scene object tests (will eventually cover root and child part position, rotation properties, etc.)
43 /// </summary>
44 [TestFixture]
45 public class SceneObjectSpatialTests : OpenSimTestCase
46 {
47 TestScene m_scene;
48 UUID m_ownerId = TestHelpers.ParseTail(0x1);
49  
50 [SetUp]
51 public override void SetUp()
52 {
53 base.SetUp();
54  
55 m_scene = new SceneHelpers().SetupScene();
56 }
57  
58 [Test]
59 public void TestGetSceneObjectGroupPosition()
60 {
61 TestHelpers.InMethod();
62  
63 Vector3 position = new Vector3(10, 20, 30);
64  
65 SceneObjectGroup so
66 = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10);
67 so.AbsolutePosition = position;
68 m_scene.AddNewSceneObject(so, false);
69  
70 Assert.That(so.AbsolutePosition, Is.EqualTo(position));
71 }
72  
73 [Test]
74 public void TestGetRootPartPosition()
75 {
76 TestHelpers.InMethod();
77  
78 Vector3 partPosition = new Vector3(10, 20, 30);
79  
80 SceneObjectGroup so
81 = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10);
82 so.AbsolutePosition = partPosition;
83 m_scene.AddNewSceneObject(so, false);
84  
85 Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition));
86 Assert.That(so.RootPart.GroupPosition, Is.EqualTo(partPosition));
87 Assert.That(so.RootPart.GetWorldPosition(), Is.EqualTo(partPosition));
88 Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition));
89 Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero));
90 }
91  
92 [Test]
93 public void TestGetChildPartPosition()
94 {
95 TestHelpers.InMethod();
96  
97 Vector3 rootPartPosition = new Vector3(10, 20, 30);
98 Vector3 childOffsetPosition = new Vector3(2, 3, 4);
99  
100 SceneObjectGroup so
101 = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10);
102 so.AbsolutePosition = rootPartPosition;
103 so.Parts[1].OffsetPosition = childOffsetPosition;
104  
105 m_scene.AddNewSceneObject(so, false);
106  
107 // Calculate child absolute position.
108 Vector3 childPosition = new Vector3(rootPartPosition + childOffsetPosition);
109  
110 SceneObjectPart childPart = so.Parts[1];
111 Assert.That(childPart.AbsolutePosition, Is.EqualTo(childPosition));
112 Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition));
113 Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition));
114 Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition));
115 Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition));
116 }
117  
118 [Test]
119 public void TestGetChildPartPositionAfterObjectRotation()
120 {
121 TestHelpers.InMethod();
122  
123 Vector3 rootPartPosition = new Vector3(10, 20, 30);
124 Vector3 childOffsetPosition = new Vector3(2, 3, 4);
125  
126 SceneObjectGroup so
127 = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10);
128 so.AbsolutePosition = rootPartPosition;
129 so.Parts[1].OffsetPosition = childOffsetPosition;
130  
131 m_scene.AddNewSceneObject(so, false);
132  
133 so.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 0, -90 * Utils.DEG_TO_RAD));
134  
135 // Calculate child absolute position.
136 Vector3 rotatedChildOffsetPosition
137 = new Vector3(childOffsetPosition.Y, -childOffsetPosition.X, childOffsetPosition.Z);
138  
139 Vector3 childPosition = new Vector3(rootPartPosition + rotatedChildOffsetPosition);
140  
141 SceneObjectPart childPart = so.Parts[1];
142  
143 // FIXME: Should be childPosition after rotation?
144 Assert.That(childPart.AbsolutePosition, Is.EqualTo(rootPartPosition + childOffsetPosition));
145  
146 Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition));
147 Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition));
148  
149 // Relative to root part as (0, 0, 0)
150 Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition));
151  
152 // Relative to root part as (0, 0, 0)
153 Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition));
154 }
155 }
156 }