SceneObjectSpatialTests.cs 6.2 KB

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