ODETestClass.cs 4.4 KB

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