aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs208
1 files changed, 104 insertions, 104 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs
index 7a76d24..3a780c1 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs
@@ -1,104 +1,104 @@
1/* 1/*
2 Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru 2 Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru
3 Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com 3 Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4 4
5 This software is provided 'as-is', without any express or implied 5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages 6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software. 7 arising from the use of this software.
8 8
9 Permission is granted to anyone to use this software for any purpose, 9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it 10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions: 11 freely, subject to the following restrictions:
12 12
13 1. The origin of this software must not be misrepresented; you must not 13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software 14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be 15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required. 16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be 17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software. 18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution. 19 3. This notice may not be removed or altered from any source distribution.
20*/ 20*/
21 21
22using System; 22using System;
23using System.Collections.Generic; 23using System.Collections.Generic;
24using System.Text; 24using System.Text;
25using MonoXnaCompactMaths; 25using MonoXnaCompactMaths;
26 26
27namespace XnaDevRu.BulletX 27namespace XnaDevRu.BulletX
28{ 28{
29 public class SphereSphereCollisionAlgorithm : CollisionAlgorithm 29 public class SphereSphereCollisionAlgorithm : CollisionAlgorithm
30 { 30 {
31 private bool _ownManifold; 31 private bool _ownManifold;
32 private PersistentManifold _manifold; 32 private PersistentManifold _manifold;
33 33
34 public SphereSphereCollisionAlgorithm(PersistentManifold manifold, CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) 34 public SphereSphereCollisionAlgorithm(PersistentManifold manifold, CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB)
35 : base(collisionAlgorithmConstructionInfo) 35 : base(collisionAlgorithmConstructionInfo)
36 { 36 {
37 _ownManifold = false; 37 _ownManifold = false;
38 _manifold = manifold; 38 _manifold = manifold;
39 39
40 if (_manifold == null) 40 if (_manifold == null)
41 { 41 {
42 _manifold = Dispatcher.GetNewManifold(bodyA, bodyB); 42 _manifold = Dispatcher.GetNewManifold(bodyA, bodyB);
43 _ownManifold = true; 43 _ownManifold = true;
44 } 44 }
45 } 45 }
46 46
47 public SphereSphereCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo) 47 public SphereSphereCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo)
48 : base(collisionAlgorithmConstructionInfo) { } 48 : base(collisionAlgorithmConstructionInfo) { }
49 49
50 ~SphereSphereCollisionAlgorithm() 50 ~SphereSphereCollisionAlgorithm()
51 { 51 {
52 if (_ownManifold) 52 if (_ownManifold)
53 { 53 {
54 if (_manifold != null) 54 if (_manifold != null)
55 Dispatcher.ReleaseManifold(_manifold); 55 Dispatcher.ReleaseManifold(_manifold);
56 } 56 }
57 } 57 }
58 58
59 public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) 59 public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
60 { 60 {
61 if (_manifold == null) 61 if (_manifold == null)
62 return; 62 return;
63 63
64 SphereShape sphereA = bodyA.CollisionShape as SphereShape; 64 SphereShape sphereA = bodyA.CollisionShape as SphereShape;
65 SphereShape sphereB = bodyB.CollisionShape as SphereShape; 65 SphereShape sphereB = bodyB.CollisionShape as SphereShape;
66 66
67 Vector3 diff = bodyA.WorldTransform.Translation - bodyB.WorldTransform.Translation; 67 Vector3 diff = bodyA.WorldTransform.Translation - bodyB.WorldTransform.Translation;
68 float len = diff.Length(); 68 float len = diff.Length();
69 float radiusA = sphereA.Radius; 69 float radiusA = sphereA.Radius;
70 float radiusB = sphereB.Radius; 70 float radiusB = sphereB.Radius;
71 71
72 //if distance positive, don't generate a new contact 72 //if distance positive, don't generate a new contact
73 if (len > (radiusA + radiusB)) 73 if (len > (radiusA + radiusB))
74 return; 74 return;
75 75
76 //distance (negative means penetration) 76 //distance (negative means penetration)
77 float dist = len - (radiusA + radiusB); 77 float dist = len - (radiusA + radiusB);
78 78
79 Vector3 normalOnSurfaceB = diff / len; 79 Vector3 normalOnSurfaceB = diff / len;
80 //point on A (worldspace) 80 //point on A (worldspace)
81 Vector3 posA = bodyA.WorldTransform.Translation - radiusA * normalOnSurfaceB; 81 Vector3 posA = bodyA.WorldTransform.Translation - radiusA * normalOnSurfaceB;
82 //point on B (worldspace) 82 //point on B (worldspace)
83 Vector3 posB = bodyB.WorldTransform.Translation + radiusB * normalOnSurfaceB; 83 Vector3 posB = bodyB.WorldTransform.Translation + radiusB * normalOnSurfaceB;
84 84
85 // report a contact. internally this will be kept persistent, and contact reduction is done 85 // report a contact. internally this will be kept persistent, and contact reduction is done
86 resultOut.SetPersistentManifold(_manifold); 86 resultOut.SetPersistentManifold(_manifold);
87 resultOut.AddContactPoint(normalOnSurfaceB, posB, dist); 87 resultOut.AddContactPoint(normalOnSurfaceB, posB, dist);
88 } 88 }
89 89
90 public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) 90 public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
91 { 91 {
92 //not yet 92 //not yet
93 return 1f; 93 return 1f;
94 } 94 }
95 95
96 public class CreateFunc : CollisionAlgorithmCreateFunction 96 public class CreateFunc : CollisionAlgorithmCreateFunction
97 { 97 {
98 public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) 98 public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB)
99 { 99 {
100 return new SphereSphereCollisionAlgorithm(null, collisionAlgorithmConstructionInfo, bodyA, bodyB); 100 return new SphereSphereCollisionAlgorithm(null, collisionAlgorithmConstructionInfo, bodyA, bodyB);
101 } 101 }
102 } 102 }
103 } 103 }
104} 104}