OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ODETestClass.cs
Go to the documentation of this file.
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 
28 using System;
29 using Nini.Config;
30 using NUnit.Framework;
31 using OpenMetaverse;
32 using OpenSim.Framework;
33 using OpenSim.Region.PhysicsModules.SharedBase;
34 using OpenSim.Region.PhysicsModule.ODE;
35 using OpenSim.Region.Framework.Scenes;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Tests.Common;
38 using log4net;
39 using System.Reflection;
40 
41 namespace OpenSim.Region.PhysicsModule.ODE.Tests
42 {
43  [TestFixture]
45  {
46  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 
48  //private OpenSim.Region.PhysicsModule.ODE.OdePlugin cbt;
49  private PhysicsScene pScene;
51 
52 
53  [SetUp]
54  public void Initialize()
55  {
56  IConfigSource openSimINI = new IniConfigSource();
57  IConfig startupConfig = openSimINI.AddConfig("Startup");
58  startupConfig.Set("physics", "OpenDynamicsEngine");
59  startupConfig.Set("DecodedSculptMapPath", "j2kDecodeCache");
60 
61  Vector3 regionExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
62 
63  //PhysicsScene pScene = physicsPluginManager.GetPhysicsScene(
64  // "BulletSim", "Meshmerizer", openSimINI, "BSTestRegion", regionExtent);
65  RegionInfo info = new RegionInfo();
66  info.RegionName = "ODETestRegion";
67  info.RegionSizeX = info.RegionSizeY = info.RegionSizeZ = Constants.RegionSize;
69 
70  //IMesher mesher = new OpenSim.Region.PhysicsModule.Meshing.Meshmerizer();
71  //INonSharedRegionModule mod = mesher as INonSharedRegionModule;
72  //mod.Initialise(openSimINI);
73  //mod.AddRegion(scene);
74  //mod.RegionLoaded(scene);
75 
76  // pScene = new OdeScene();
78  Console.WriteLine("HERE " + (odemodule == null ? "Null" : "Not null"));
79  odemodule.Initialise(openSimINI);
80  odemodule.AddRegion(scene);
81  odemodule.RegionLoaded(scene);
82 
83  // Loading ODEPlugin
84  //cbt = new OdePlugin();
85  // Getting Physics Scene
86  //ps = cbt.GetScene("test");
87  // Initializing Physics Scene.
88  //ps.Initialise(imp.GetMesher(TopConfig), null, Vector3.Zero);
89  float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize];
90  for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++)
91  {
92  _heightmap[i] = 21f;
93  }
94  pScene = scene.PhysicsScene;
95  pScene.SetTerrain(_heightmap);
96  }
97 
98  [TearDown]
99  public void Terminate()
100  {
101  pScene.DeleteTerrain();
102  pScene.Dispose();
103 
104  }
105 
106  [Test]
108  {
109  PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
110  Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
111  Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
112  Quaternion rot = Quaternion.Identity;
113  PhysicsActor prim = pScene.AddPrimShape("CoolShape", newcube, position, size, rot, true, 0);
114  OdePrim oprim = (OdePrim)prim;
115  OdeScene pscene = (OdeScene)pScene;
116 
117  Assert.That(oprim.m_taintadd);
118 
119  prim.LocalID = 5;
120 
121  for (int i = 0; i < 58; i++)
122  {
123  pScene.Simulate(0.133f);
124 
125  Assert.That(oprim.prim_geom != (IntPtr)0);
126 
127  Assert.That(oprim.m_targetSpace != (IntPtr)0);
128 
129  //Assert.That(oprim.m_targetSpace == pscene.space);
130  m_log.Info("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space);
131 
132  Assert.That(!oprim.m_taintadd);
133  m_log.Info("Prim Position (" + oprim.LocalID + "): " + prim.Position);
134 
135  // Make sure we're above the ground
136  //Assert.That(prim.Position.Z > 20f);
137  //m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore);
138 
139  // Make sure we've got a Body
140  Assert.That(oprim.Body != (IntPtr)0);
141  //m_log.Info(
142  }
143 
144  // Make sure we're not somewhere above the ground
145  Assert.That(prim.Position.Z < 21.5f);
146 
147  pScene.RemovePrim(prim);
148  Assert.That(oprim.m_taintremove);
149  pScene.Simulate(0.133f);
150  Assert.That(oprim.Body == (IntPtr)0);
151  }
152  }
153 }
OpenSim.Framework.RegionInfo RegionInfo
Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ours...
Definition: ODEPrim.cs:59
Interactive OpenSim region server
Definition: OpenSim.cs:55