diff options
author | Robert Adams | 2017-09-02 13:06:36 -0700 |
---|---|---|
committer | Robert Adams | 2017-09-02 13:06:36 -0700 |
commit | 0afa3a294ab36382cf720e9cceb9211a83fbf101 (patch) | |
tree | 5e5c1c62be9880052a2cab1a33055017d2d868bd /OpenSim/Region/PhysicsModules/BulletS/Tests | |
parent | fix cache.cs (used on parcels info) (diff) | |
download | opensim-SC_OLD-0afa3a294ab36382cf720e9cceb9211a83fbf101.zip opensim-SC_OLD-0afa3a294ab36382cf720e9cceb9211a83fbf101.tar.gz opensim-SC_OLD-0afa3a294ab36382cf720e9cceb9211a83fbf101.tar.bz2 opensim-SC_OLD-0afa3a294ab36382cf720e9cceb9211a83fbf101.tar.xz |
BulletSim: most of the plumbing for raycast. Needs new BulletSim.dll to
work.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/Tests')
-rwxr-xr-x | OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs new file mode 100755 index 0000000..046df56 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs | |||
@@ -0,0 +1,115 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using NUnit.Framework; | ||
34 | using log4net; | ||
35 | |||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.PhysicsModule.BulletS; | ||
38 | using OpenSim.Region.PhysicsModules.SharedBase; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Region.PhysicsModule.BulletS.Tests | ||
44 | { | ||
45 | [TestFixture] | ||
46 | public class BulletSimRaycast : OpenSimTestCase | ||
47 | { | ||
48 | // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 | ||
49 | // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 | ||
50 | |||
51 | BSScene PhysicsScene { get; set; } | ||
52 | BSPrim TargetSphere { get; set; } | ||
53 | Vector3 TargetSpherePosition { get; set; } | ||
54 | float simulationTimeStep = 0.089f; | ||
55 | |||
56 | [TestFixtureSetUp] | ||
57 | public void Init() | ||
58 | { | ||
59 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); | ||
60 | engineParams.Add("UseBulletRaycast", "true"); | ||
61 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); | ||
62 | |||
63 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); | ||
64 | Vector3 pos = new Vector3(100.0f, 100.0f, 50f); | ||
65 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2f; | ||
66 | TargetSpherePosition = pos; | ||
67 | Vector3 size = new Vector3(10f, 10f, 10f); | ||
68 | pbs.Scale = size; | ||
69 | Quaternion rot = Quaternion.Identity; | ||
70 | bool isPhys = false; | ||
71 | uint localID = 123; | ||
72 | |||
73 | PhysicsScene.AddPrimShape("TargetSphere", pbs, pos, size, rot, isPhys, localID); | ||
74 | TargetSphere = (BSPrim)PhysicsScene.PhysObjects[localID]; | ||
75 | // The actual prim shape creation happens at taint time | ||
76 | PhysicsScene.ProcessTaints(); | ||
77 | |||
78 | } | ||
79 | |||
80 | [TestFixtureTearDown] | ||
81 | public void TearDown() | ||
82 | { | ||
83 | if (PhysicsScene != null) | ||
84 | { | ||
85 | // The Dispose() will also free any physical objects in the scene | ||
86 | PhysicsScene.Dispose(); | ||
87 | PhysicsScene = null; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | // There is a 10x10x10 sphere at <100,100,50> | ||
92 | // Shoot rays around the sphere and verify it hits and doesn't hit | ||
93 | // TestCase parameters are <x,y,z> of start and <x,y,z> of end and expected result | ||
94 | [TestCase(20f, 20f, 50f, 50f, 50f, 50f, true)] // in front to sphere | ||
95 | [TestCase(20f, 20f, 100f, 50f, 50f, 50f, true)] // from above to sphere | ||
96 | [TestCase(50f, 50f, 50f, 150f, 150f, 50f, true)] // through sphere | ||
97 | [TestCase(50f, 50f, 65f, 150f, 150f, 65f, false)] // pass over sphere | ||
98 | public void RaycastAroundObject(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, bool expected) { | ||
99 | Vector3 fromPos = new Vector3(fromX, fromY, fromZ); | ||
100 | Vector3 toPos = new Vector3(toX, toY, toZ); | ||
101 | Vector3 direction = toPos - fromPos; | ||
102 | float len = Vector3.Distance(fromPos, toPos); | ||
103 | |||
104 | List<ContactResult> results = PhysicsScene.RaycastWorld(fromPos, direction, len, 1); | ||
105 | |||
106 | if (expected) { | ||
107 | Assert.True(results.Count > 0); | ||
108 | } | ||
109 | else | ||
110 | { | ||
111 | Assert.False(results.Count > 0); | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | } \ No newline at end of file | ||