1
0

ODETestClass.cs 6.4 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 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. private OpenSim.Region.PhysicsModule.ODE.OdeModule odemodule;
  48. [SetUp]
  49. public void Initialize()
  50. {
  51. IConfigSource openSimINI = new IniConfigSource();
  52. IConfig startupConfig = openSimINI.AddConfig("Startup");
  53. startupConfig.Set("physics", "OpenDynamicsEngine");
  54. startupConfig.Set("DecodedSculptMapPath", "j2kDecodeCache");
  55. Vector3 regionExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
  56. //PhysicsScene pScene = physicsPluginManager.GetPhysicsScene(
  57. // "BulletSim", "Meshmerizer", openSimINI, "BSTestRegion", regionExtent);
  58. RegionInfo info = new RegionInfo();
  59. info.RegionName = "ODETestRegion";
  60. info.RegionSizeX = info.RegionSizeY = info.RegionSizeZ = Constants.RegionSize;
  61. OpenSim.Region.Framework.Scenes.Scene scene = new OpenSim.Region.Framework.Scenes.Scene(info);
  62. //IMesher mesher = new OpenSim.Region.PhysicsModule.Meshing.Meshmerizer();
  63. //INonSharedRegionModule mod = mesher as INonSharedRegionModule;
  64. //mod.Initialise(openSimINI);
  65. //mod.AddRegion(scene);
  66. //mod.RegionLoaded(scene);
  67. // pScene = new OdeScene();
  68. odemodule = new OpenSim.Region.PhysicsModule.ODE.OdeModule();
  69. Console.WriteLine("HERE " + (odemodule == null ? "Null" : "Not null"));
  70. odemodule.Initialise(openSimINI);
  71. odemodule.AddRegion(scene);
  72. odemodule.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 = scene.PhysicsScene;
  85. pScene.SetTerrain(_heightmap);
  86. }
  87. [TearDown]
  88. public void Terminate()
  89. {
  90. pScene.DeleteTerrain();
  91. pScene.Dispose();
  92. }
  93. [Test]
  94. public void CreateAndDropPhysicalCube()
  95. {
  96. PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
  97. Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
  98. Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
  99. Quaternion rot = Quaternion.Identity;
  100. PhysicsActor prim = pScene.AddPrimShape("CoolShape", newcube, position, size, rot, true, 0);
  101. OdePrim oprim = (OdePrim)prim;
  102. OdeScene pscene = (OdeScene)pScene;
  103. Assert.That(oprim.m_taintadd);
  104. prim.LocalID = 5;
  105. for (int i = 0; i < 58; i++)
  106. {
  107. pScene.Simulate(0.133f);
  108. Assert.That(oprim.prim_geom != (IntPtr)0);
  109. Assert.That(oprim.m_targetSpace != (IntPtr)0);
  110. //Assert.That(oprim.m_targetSpace == pscene.space);
  111. m_log.Info("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space);
  112. Assert.That(!oprim.m_taintadd);
  113. m_log.Info("Prim Position (" + oprim.LocalID + "): " + prim.Position);
  114. // Make sure we're above the ground
  115. //Assert.That(prim.Position.Z > 20f);
  116. //m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore);
  117. // Make sure we've got a Body
  118. Assert.That(oprim.Body != (IntPtr)0);
  119. //m_log.Info(
  120. }
  121. // Make sure we're not somewhere above the ground
  122. Assert.That(prim.Position.Z < 21.5f);
  123. pScene.RemovePrim(prim);
  124. Assert.That(oprim.m_taintremove);
  125. pScene.Simulate(0.133f);
  126. Assert.That(oprim.Body == (IntPtr)0);
  127. }
  128. }
  129. }