aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs124
1 files changed, 124 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..bfa95c1
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs
@@ -0,0 +1,124 @@
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
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Text;
32
33using NUnit.Framework;
34using log4net;
35
36using OpenSim.Framework;
37using OpenSim.Region.PhysicsModule.BulletS;
38using OpenSim.Region.PhysicsModules.SharedBase;
39using OpenSim.Tests.Common;
40
41using OpenMetaverse;
42
43namespace 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 uint _targetLocalID = 123;
57
58 [TestFixtureSetUp]
59 public void Init()
60 {
61 Dictionary<string, string> engineParams = new Dictionary<string, string>();
62 engineParams.Add("UseBulletRaycast", "true");
63 _physicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams);
64
65 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere();
66 Vector3 pos = new Vector3(100.0f, 100.0f, 50f);
67 _targetSpherePosition = pos;
68 Vector3 size = new Vector3(10f, 10f, 10f);
69 pbs.Scale = size;
70 Quaternion rot = Quaternion.Identity;
71 bool isPhys = false;
72
73 _physicsScene.AddPrimShape("TargetSphere", pbs, pos, size, rot, isPhys, _targetLocalID);
74 _targetSphere = (BSPrim)_physicsScene.PhysObjects[_targetLocalID];
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(100f, 50f, 50f, 100f, 150f, 50f, true, "Pass through sphere from front")]
95 [TestCase(50f, 100f, 50f, 150f, 100f, 50f, true, "Pass through sphere from side")]
96 [TestCase(50f, 50f, 50f, 150f, 150f, 50f, true, "Pass through sphere diaginally")]
97 [TestCase(100f, 100f, 100f, 100f, 100f, 20f, true, "Pass through sphere from above")]
98 [TestCase(20f, 20f, 50f, 80f, 80f, 50f, false, "Not reach sphere")]
99 [TestCase(50f, 50f, 65f, 150f, 150f, 65f, false, "Passed over sphere")]
100 public void RaycastAroundObject(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, bool expected, string msg) {
101 Vector3 fromPos = new Vector3(fromX, fromY, fromZ);
102 Vector3 toPos = new Vector3(toX, toY, toZ);
103 Vector3 direction = toPos - fromPos;
104 float len = Vector3.Distance(fromPos, toPos);
105
106 List<ContactResult> results = _physicsScene.RaycastWorld(fromPos, direction, len, 1);
107
108 if (expected) {
109 // The test coordinates should generate a hit
110 Assert.True(results.Count != 0, msg + ": Did not return a hit but expected to.");
111 Assert.True(results.Count == 1, msg + ": Raycast returned not just one hit result.");
112 Assert.True(results[0].ConsumerID == _targetLocalID, msg + ": Raycast returned a collision object other than the target");
113 }
114 else
115 {
116 // The test coordinates should not generate a hit
117 if (results.Count > 0)
118 {
119 Assert.False(results.Count > 0, msg + ": Returned a hit at " + results[0].Pos.ToString());
120 }
121 }
122 }
123 }
124} \ No newline at end of file