ODETestClass.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 Nini.Config;
  29. using NUnit.Framework;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Physics.Manager;
  33. using log4net;
  34. using System.Reflection;
  35. namespace OpenSim.Region.Physics.OdePlugin
  36. {
  37. [TestFixture]
  38. public class ODETestClass
  39. {
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. private OdePlugin cbt;
  42. private PhysicsScene ps;
  43. private IMeshingPlugin imp;
  44. [SetUp]
  45. public void Initialize()
  46. {
  47. // Loading ODEPlugin
  48. cbt = new OdePlugin();
  49. // Loading Zero Mesher
  50. imp = new ZeroMesherPlugin();
  51. // Getting Physics Scene
  52. ps = cbt.GetScene("test");
  53. // Initializing Physics Scene.
  54. ps.Initialise(imp.GetMesher(),null);
  55. float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize];
  56. for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++)
  57. {
  58. _heightmap[i] = 21f;
  59. }
  60. ps.SetTerrain(_heightmap);
  61. }
  62. [TearDown]
  63. public void Terminate()
  64. {
  65. ps.DeleteTerrain();
  66. ps.Dispose();
  67. }
  68. [Test]
  69. public void CreateAndDropPhysicalCube()
  70. {
  71. PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
  72. Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
  73. Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
  74. Quaternion rot = Quaternion.Identity;
  75. PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true);
  76. OdePrim oprim = (OdePrim)prim;
  77. OdeScene pscene = (OdeScene) ps;
  78. Assert.That(oprim.m_taintadd);
  79. prim.LocalID = 5;
  80. for (int i = 0; i < 58; i++)
  81. {
  82. ps.Simulate(0.133f);
  83. Assert.That(oprim.prim_geom != (IntPtr)0);
  84. Assert.That(oprim.m_targetSpace != (IntPtr)0);
  85. //Assert.That(oprim.m_targetSpace == pscene.space);
  86. m_log.Info("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space);
  87. Assert.That(!oprim.m_taintadd);
  88. m_log.Info("Prim Position (" + oprim.m_localID + "): " + prim.Position.ToString());
  89. // Make sure we're above the ground
  90. //Assert.That(prim.Position.Z > 20f);
  91. //m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore);
  92. // Make sure we've got a Body
  93. Assert.That(oprim.Body != (IntPtr)0);
  94. //m_log.Info(
  95. }
  96. // Make sure we're not somewhere above the ground
  97. Assert.That(prim.Position.Z < 21.5f);
  98. ps.RemovePrim(prim);
  99. Assert.That(oprim.m_taintremove);
  100. ps.Simulate(0.133f);
  101. Assert.That(oprim.Body == (IntPtr)0);
  102. }
  103. }
  104. }