1
0

SceneObjectSpatialTests.cs 6.2 KB

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