diff options
author | Robert Adams | 2017-09-03 17:15:27 -0700 |
---|---|---|
committer | Robert Adams | 2017-09-03 17:15:27 -0700 |
commit | f348f7fa90cf4784e0e173c122594ecc145d3bb8 (patch) | |
tree | c9eaa6f51f9af16935e48a2130dc340d8a8fbcfb /OpenSim/Region/PhysicsModules/BulletS/Tests | |
parent | BulletSim; Update BulletSim.dll's and so's for raycast. (diff) | |
download | opensim-SC-f348f7fa90cf4784e0e173c122594ecc145d3bb8.zip opensim-SC-f348f7fa90cf4784e0e173c122594ecc145d3bb8.tar.gz opensim-SC-f348f7fa90cf4784e0e173c122594ecc145d3bb8.tar.bz2 opensim-SC-f348f7fa90cf4784e0e173c122594ecc145d3bb8.tar.xz |
BulletSim: first version of raycast. Only single contact point and no
filtering.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/Tests')
-rwxr-xr-x | OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs index 046df56..bfa95c1 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/Tests/Raycast.cs | |||
@@ -48,67 +48,76 @@ namespace OpenSim.Region.PhysicsModule.BulletS.Tests | |||
48 | // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 | 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 | 49 | // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 |
50 | 50 | ||
51 | BSScene PhysicsScene { get; set; } | 51 | BSScene _physicsScene { get; set; } |
52 | BSPrim TargetSphere { get; set; } | 52 | BSPrim _targetSphere { get; set; } |
53 | Vector3 TargetSpherePosition { get; set; } | 53 | Vector3 _targetSpherePosition { get; set; } |
54 | float simulationTimeStep = 0.089f; | 54 | float _simulationTimeStep = 0.089f; |
55 | |||
56 | uint _targetLocalID = 123; | ||
55 | 57 | ||
56 | [TestFixtureSetUp] | 58 | [TestFixtureSetUp] |
57 | public void Init() | 59 | public void Init() |
58 | { | 60 | { |
59 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); | 61 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); |
60 | engineParams.Add("UseBulletRaycast", "true"); | 62 | engineParams.Add("UseBulletRaycast", "true"); |
61 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); | 63 | _physicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); |
62 | 64 | ||
63 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); | 65 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); |
64 | Vector3 pos = new Vector3(100.0f, 100.0f, 50f); | 66 | Vector3 pos = new Vector3(100.0f, 100.0f, 50f); |
65 | pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2f; | 67 | _targetSpherePosition = pos; |
66 | TargetSpherePosition = pos; | ||
67 | Vector3 size = new Vector3(10f, 10f, 10f); | 68 | Vector3 size = new Vector3(10f, 10f, 10f); |
68 | pbs.Scale = size; | 69 | pbs.Scale = size; |
69 | Quaternion rot = Quaternion.Identity; | 70 | Quaternion rot = Quaternion.Identity; |
70 | bool isPhys = false; | 71 | bool isPhys = false; |
71 | uint localID = 123; | ||
72 | 72 | ||
73 | PhysicsScene.AddPrimShape("TargetSphere", pbs, pos, size, rot, isPhys, localID); | 73 | _physicsScene.AddPrimShape("TargetSphere", pbs, pos, size, rot, isPhys, _targetLocalID); |
74 | TargetSphere = (BSPrim)PhysicsScene.PhysObjects[localID]; | 74 | _targetSphere = (BSPrim)_physicsScene.PhysObjects[_targetLocalID]; |
75 | // The actual prim shape creation happens at taint time | 75 | // The actual prim shape creation happens at taint time |
76 | PhysicsScene.ProcessTaints(); | 76 | _physicsScene.ProcessTaints(); |
77 | 77 | ||
78 | } | 78 | } |
79 | 79 | ||
80 | [TestFixtureTearDown] | 80 | [TestFixtureTearDown] |
81 | public void TearDown() | 81 | public void TearDown() |
82 | { | 82 | { |
83 | if (PhysicsScene != null) | 83 | if (_physicsScene != null) |
84 | { | 84 | { |
85 | // The Dispose() will also free any physical objects in the scene | 85 | // The Dispose() will also free any physical objects in the scene |
86 | PhysicsScene.Dispose(); | 86 | _physicsScene.Dispose(); |
87 | PhysicsScene = null; | 87 | _physicsScene = null; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | // There is a 10x10x10 sphere at <100,100,50> | 91 | // There is a 10x10x10 sphere at <100,100,50> |
92 | // Shoot rays around the sphere and verify it hits and doesn't hit | 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 | 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 | 94 | [TestCase(100f, 50f, 50f, 100f, 150f, 50f, true, "Pass through sphere from front")] |
95 | [TestCase(20f, 20f, 100f, 50f, 50f, 50f, true)] // from above to sphere | 95 | [TestCase(50f, 100f, 50f, 150f, 100f, 50f, true, "Pass through sphere from side")] |
96 | [TestCase(50f, 50f, 50f, 150f, 150f, 50f, true)] // through sphere | 96 | [TestCase(50f, 50f, 50f, 150f, 150f, 50f, true, "Pass through sphere diaginally")] |
97 | [TestCase(50f, 50f, 65f, 150f, 150f, 65f, false)] // pass over sphere | 97 | [TestCase(100f, 100f, 100f, 100f, 100f, 20f, true, "Pass through sphere from above")] |
98 | public void RaycastAroundObject(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, bool expected) { | 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) { | ||
99 | Vector3 fromPos = new Vector3(fromX, fromY, fromZ); | 101 | Vector3 fromPos = new Vector3(fromX, fromY, fromZ); |
100 | Vector3 toPos = new Vector3(toX, toY, toZ); | 102 | Vector3 toPos = new Vector3(toX, toY, toZ); |
101 | Vector3 direction = toPos - fromPos; | 103 | Vector3 direction = toPos - fromPos; |
102 | float len = Vector3.Distance(fromPos, toPos); | 104 | float len = Vector3.Distance(fromPos, toPos); |
103 | 105 | ||
104 | List<ContactResult> results = PhysicsScene.RaycastWorld(fromPos, direction, len, 1); | 106 | List<ContactResult> results = _physicsScene.RaycastWorld(fromPos, direction, len, 1); |
105 | 107 | ||
106 | if (expected) { | 108 | if (expected) { |
107 | Assert.True(results.Count > 0); | 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"); | ||
108 | } | 113 | } |
109 | else | 114 | else |
110 | { | 115 | { |
111 | Assert.False(results.Count > 0); | 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 | } | ||
112 | } | 121 | } |
113 | } | 122 | } |
114 | } | 123 | } |