ODETestClass.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.PhysicsModules.SharedBase;
  33. using OpenSim.Region.PhysicsModule.ODE;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Tests.Common;
  37. using log4net;
  38. using System.Reflection;
  39. namespace OpenSim.Region.PhysicsModule.ODE.Tests
  40. {
  41. [TestFixture]
  42. public class ODETestClass : OpenSimTestCase
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. //private OpenSim.Region.PhysicsModule.ODE.OdePlugin cbt;
  46. private PhysicsScene pScene;
  47. [SetUp]
  48. public void Initialize()
  49. {
  50. IConfigSource openSimINI = new IniConfigSource();
  51. IConfig startupConfig = openSimINI.AddConfig("Startup");
  52. startupConfig.Set("physics", "OpenDynamicsEngine");
  53. startupConfig.Set("DecodedSculptMapPath", "j2kDecodeCache");
  54. Vector3 regionExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
  55. //PhysicsScene pScene = physicsPluginManager.GetPhysicsScene(
  56. // "BulletSim", "Meshmerizer", openSimINI, "BSTestRegion", regionExtent);
  57. RegionInfo info = new RegionInfo();
  58. info.RegionName = "ODETestRegion";
  59. info.RegionSizeX = info.RegionSizeY = info.RegionSizeZ = Constants.RegionSize;
  60. OpenSim.Region.Framework.Scenes.Scene scene = new OpenSim.Region.Framework.Scenes.Scene(info);
  61. //IMesher mesher = new OpenSim.Region.PhysicsModules.Meshing.Meshmerizer();
  62. //INonSharedRegionModule mod = mesher as INonSharedRegionModule;
  63. //mod.Initialise(openSimINI);
  64. //mod.AddRegion(scene);
  65. //mod.RegionLoaded(scene);
  66. pScene = new OdeScene();
  67. Console.WriteLine("HERE " + (pScene == null ? "Null" : "Not null"));
  68. INonSharedRegionModule mod = (pScene as INonSharedRegionModule);
  69. Console.WriteLine("HERE " + (mod == null ? "Null" : "Not null"));
  70. mod.Initialise(openSimINI);
  71. mod.AddRegion(scene);
  72. mod.RegionLoaded(scene);
  73. // Loading ODEPlugin
  74. //cbt = new OdePlugin();
  75. // Getting Physics Scene
  76. //ps = cbt.GetScene("test");
  77. // Initializing Physics Scene.
  78. //ps.Initialise(imp.GetMesher(TopConfig), null, Vector3.Zero);
  79. float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize];
  80. for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++)
  81. {
  82. _heightmap[i] = 21f;
  83. }
  84. pScene.SetTerrain(_heightmap);
  85. }
  86. [TearDown]
  87. public void Terminate()
  88. {
  89. pScene.DeleteTerrain();
  90. pScene.Dispose();
  91. }
  92. [Test]
  93. public void CreateAndDropPhysicalCube()
  94. {
  95. PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
  96. Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
  97. Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
  98. Quaternion rot = Quaternion.Identity;
  99. PhysicsActor prim = pScene.AddPrimShape("CoolShape", newcube, position, size, rot, true, 0);
  100. OdePrim oprim = (OdePrim)prim;
  101. OdeScene pscene = (OdeScene)pScene;
  102. Assert.That(oprim.m_taintadd);
  103. prim.LocalID = 5;
  104. for (int i = 0; i < 58; i++)
  105. {
  106. pScene.Simulate(0.133f);
  107. Assert.That(oprim.prim_geom != (IntPtr)0);
  108. Assert.That(oprim.m_targetSpace != (IntPtr)0);
  109. //Assert.That(oprim.m_targetSpace == pscene.space);
  110. m_log.Info("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space);
  111. Assert.That(!oprim.m_taintadd);
  112. m_log.Info("Prim Position (" + oprim.LocalID + "): " + prim.Position);
  113. // Make sure we're above the ground
  114. //Assert.That(prim.Position.Z > 20f);
  115. //m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore);
  116. // Make sure we've got a Body
  117. Assert.That(oprim.Body != (IntPtr)0);
  118. //m_log.Info(
  119. }
  120. // Make sure we're not somewhere above the ground
  121. Assert.That(prim.Position.Z < 21.5f);
  122. pScene.RemovePrim(prim);
  123. Assert.That(oprim.m_taintremove);
  124. pScene.Simulate(0.133f);
  125. Assert.That(oprim.Body == (IntPtr)0);
  126. }
  127. }
  128. }