1
0

SceneObjectSpatialTests.cs 6.1 KB

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