diff options
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 202 |
1 files changed, 116 insertions, 86 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index f63d83c..04e77b8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | |||
@@ -137,6 +137,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
137 | internal int LastEntityProperty = 0; | 137 | internal int LastEntityProperty = 0; |
138 | 138 | ||
139 | internal EntityProperties[] UpdatedObjects; | 139 | internal EntityProperties[] UpdatedObjects; |
140 | internal Dictionary<uint, GhostObject> specialCollisionObjects; | ||
140 | 141 | ||
141 | private static int m_collisionsThisFrame; | 142 | private static int m_collisionsThisFrame; |
142 | private BSScene PhysicsScene { get; set; } | 143 | private BSScene PhysicsScene { get; set; } |
@@ -158,7 +159,13 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
158 | { | 159 | { |
159 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | 160 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
160 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 161 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; |
161 | world.RemoveRigidBody(body); | 162 | CollisionObject collisionObject = ((BulletBodyXNA)pBody).body; |
163 | if (body != null) | ||
164 | world.RemoveRigidBody(body); | ||
165 | else if (collisionObject != null) | ||
166 | world.RemoveCollisionObject(collisionObject); | ||
167 | else | ||
168 | return false; | ||
162 | return true; | 169 | return true; |
163 | } | 170 | } |
164 | 171 | ||
@@ -182,7 +189,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
182 | 189 | ||
183 | public override void SetRestitution(BulletBody pCollisionObject, float pRestitution) | 190 | public override void SetRestitution(BulletBody pCollisionObject, float pRestitution) |
184 | { | 191 | { |
185 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 192 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
186 | collisionObject.SetRestitution(pRestitution); | 193 | collisionObject.SetRestitution(pRestitution); |
187 | } | 194 | } |
188 | 195 | ||
@@ -219,13 +226,13 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
219 | 226 | ||
220 | public override void SetCcdMotionThreshold(BulletBody pCollisionObject, float pccdMotionThreashold) | 227 | public override void SetCcdMotionThreshold(BulletBody pCollisionObject, float pccdMotionThreashold) |
221 | { | 228 | { |
222 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 229 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
223 | collisionObject.SetCcdMotionThreshold(pccdMotionThreashold); | 230 | collisionObject.SetCcdMotionThreshold(pccdMotionThreashold); |
224 | } | 231 | } |
225 | 232 | ||
226 | public override void SetCcdSweptSphereRadius(BulletBody pCollisionObject, float pCcdSweptSphereRadius) | 233 | public override void SetCcdSweptSphereRadius(BulletBody pCollisionObject, float pCcdSweptSphereRadius) |
227 | { | 234 | { |
228 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 235 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
229 | collisionObject.SetCcdSweptSphereRadius(pCcdSweptSphereRadius); | 236 | collisionObject.SetCcdSweptSphereRadius(pCcdSweptSphereRadius); |
230 | } | 237 | } |
231 | 238 | ||
@@ -262,7 +269,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
262 | } | 269 | } |
263 | else | 270 | else |
264 | { | 271 | { |
265 | world.AddCollisionObject(rbody); | 272 | world.AddCollisionObject(cbody); |
266 | } | 273 | } |
267 | cbody.SetWorldTransform(origPos); | 274 | cbody.SetWorldTransform(origPos); |
268 | 275 | ||
@@ -303,7 +310,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
303 | 310 | ||
304 | public override bool SetCollisionGroupMask(BulletBody pCollisionObject, uint pGroup, uint pMask) | 311 | public override bool SetCollisionGroupMask(BulletBody pCollisionObject, uint pGroup, uint pMask) |
305 | { | 312 | { |
306 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 313 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
307 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | 314 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; |
308 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | 315 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; |
309 | if ((uint) collisionObject.GetBroadphaseHandle().m_collisionFilterGroup == 0) | 316 | if ((uint) collisionObject.GetBroadphaseHandle().m_collisionFilterGroup == 0) |
@@ -390,7 +397,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
390 | 397 | ||
391 | public override void SetTranslation(BulletBody pCollisionObject, Vector3 _position, Quaternion _orientation) | 398 | public override void SetTranslation(BulletBody pCollisionObject, Vector3 _position, Quaternion _orientation) |
392 | { | 399 | { |
393 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 400 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
394 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); | 401 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); |
395 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, | 402 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, |
396 | _orientation.W); | 403 | _orientation.W); |
@@ -418,8 +425,11 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
418 | public override void SetMassProps(BulletBody pBody, float pphysMass, Vector3 plocalInertia) | 425 | public override void SetMassProps(BulletBody pBody, float pphysMass, Vector3 plocalInertia) |
419 | { | 426 | { |
420 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | 427 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
421 | IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z); | 428 | if (body != null) // Can't set mass props on collision object. |
422 | body.SetMassProps(pphysMass, inertia); | 429 | { |
430 | IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z); | ||
431 | body.SetMassProps(pphysMass, inertia); | ||
432 | } | ||
423 | } | 433 | } |
424 | 434 | ||
425 | 435 | ||
@@ -432,7 +442,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
432 | 442 | ||
433 | public override void SetFriction(BulletBody pCollisionObject, float _currentFriction) | 443 | public override void SetFriction(BulletBody pCollisionObject, float _currentFriction) |
434 | { | 444 | { |
435 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 445 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
436 | collisionObject.SetFriction(_currentFriction); | 446 | collisionObject.SetFriction(_currentFriction); |
437 | } | 447 | } |
438 | 448 | ||
@@ -459,7 +469,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
459 | 469 | ||
460 | public override CollisionFlags RemoveFromCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags) | 470 | public override CollisionFlags RemoveFromCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags) |
461 | { | 471 | { |
462 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 472 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
463 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags(); | 473 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags(); |
464 | existingcollisionFlags &= ~pcollisionFlags; | 474 | existingcollisionFlags &= ~pcollisionFlags; |
465 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | 475 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); |
@@ -494,8 +504,11 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
494 | public override void SetGravity(BulletBody pBody, Vector3 pGravity) | 504 | public override void SetGravity(BulletBody pBody, Vector3 pGravity) |
495 | { | 505 | { |
496 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | 506 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
497 | IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z); | 507 | if (body != null) // Can't set collisionobject.set gravity |
498 | body.SetGravity(gravity); | 508 | { |
509 | IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z); | ||
510 | body.SetGravity(gravity); | ||
511 | } | ||
499 | } | 512 | } |
500 | 513 | ||
501 | public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint) | 514 | public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint) |
@@ -733,7 +746,8 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
733 | public override void UpdateInertiaTensor(BulletBody pBody) | 746 | public override void UpdateInertiaTensor(BulletBody pBody) |
734 | { | 747 | { |
735 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | 748 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
736 | body.UpdateInertiaTensor(); | 749 | if (body != null) // can't update inertia tensor on CollisionObject |
750 | body.UpdateInertiaTensor(); | ||
737 | } | 751 | } |
738 | 752 | ||
739 | public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape) | 753 | public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape) |
@@ -770,7 +784,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
770 | 784 | ||
771 | public override CollisionObjectTypes GetBodyType(BulletBody pCollisionObject) | 785 | public override CollisionObjectTypes GetBodyType(BulletBody pCollisionObject) |
772 | { | 786 | { |
773 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 787 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
774 | return (CollisionObjectTypes)(int) collisionObject.GetInternalType(); | 788 | return (CollisionObjectTypes)(int) collisionObject.GetInternalType(); |
775 | } | 789 | } |
776 | 790 | ||
@@ -889,7 +903,18 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
889 | world.RemoveRigidBody(bo); | 903 | world.RemoveRigidBody(bo); |
890 | } | 904 | } |
891 | } | 905 | } |
892 | 906 | if (co != null) | |
907 | { | ||
908 | if (co.GetUserPointer() != null) | ||
909 | { | ||
910 | uint localId = (uint) co.GetUserPointer(); | ||
911 | if (specialCollisionObjects.ContainsKey(localId)) | ||
912 | { | ||
913 | specialCollisionObjects.Remove(localId); | ||
914 | } | ||
915 | } | ||
916 | } | ||
917 | |||
893 | } | 918 | } |
894 | 919 | ||
895 | public override void Shutdown(BulletWorld pWorld) | 920 | public override void Shutdown(BulletWorld pWorld) |
@@ -1050,7 +1075,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1050 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | 1075 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); |
1051 | m_maxCollisions = maxCollisions; | 1076 | m_maxCollisions = maxCollisions; |
1052 | m_maxUpdatesPerFrame = maxUpdates; | 1077 | m_maxUpdatesPerFrame = maxUpdates; |
1053 | 1078 | specialCollisionObjects = new Dictionary<uint, GhostObject>(); | |
1054 | 1079 | ||
1055 | return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); | 1080 | return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); |
1056 | } | 1081 | } |
@@ -1310,6 +1335,12 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1310 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | 1335 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1311 | gObj.SetCollisionShape(shape); | 1336 | gObj.SetCollisionShape(shape); |
1312 | gObj.SetUserPointer(pLocalID); | 1337 | gObj.SetUserPointer(pLocalID); |
1338 | |||
1339 | if (specialCollisionObjects.ContainsKey(pLocalID)) | ||
1340 | specialCollisionObjects[pLocalID] = gObj; | ||
1341 | else | ||
1342 | specialCollisionObjects.Add(pLocalID, gObj); | ||
1343 | |||
1313 | // TODO: Add to Special CollisionObjects! | 1344 | // TODO: Add to Special CollisionObjects! |
1314 | return new BulletBodyXNA(pLocalID, gObj); | 1345 | return new BulletBodyXNA(pLocalID, gObj); |
1315 | } | 1346 | } |
@@ -1399,7 +1430,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1399 | } | 1430 | } |
1400 | 1431 | ||
1401 | public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { | 1432 | public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { |
1402 | /* TODO */ | 1433 | |
1403 | if (cShape == null) | 1434 | if (cShape == null) |
1404 | return null; | 1435 | return null; |
1405 | CompoundShape compoundShape = (cShape as BulletShapeXNA).shape as CompoundShape; | 1436 | CompoundShape compoundShape = (cShape as BulletShapeXNA).shape as CompoundShape; |
@@ -1407,7 +1438,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1407 | BulletShape retShape = new BulletShapeXNA(shape, BSShapeTypeFromBroadPhaseNativeType(shape.GetShapeType())); | 1438 | BulletShape retShape = new BulletShapeXNA(shape, BSShapeTypeFromBroadPhaseNativeType(shape.GetShapeType())); |
1408 | 1439 | ||
1409 | 1440 | ||
1410 | return null; | 1441 | return retShape; |
1411 | } | 1442 | } |
1412 | 1443 | ||
1413 | public BSPhysicsShapeType BSShapeTypeFromBroadPhaseNativeType(BroadphaseNativeTypes pin) | 1444 | public BSPhysicsShapeType BSShapeTypeFromBroadPhaseNativeType(BroadphaseNativeTypes pin) |
@@ -1802,26 +1833,29 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1802 | numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); | 1833 | numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); |
1803 | int updates = 0; | 1834 | int updates = 0; |
1804 | 1835 | ||
1805 | 1836 | PersistentManifold contactManifold; | |
1806 | 1837 | CollisionObject objA; | |
1838 | CollisionObject objB; | ||
1839 | ManifoldPoint manifoldPoint; | ||
1840 | PairCachingGhostObject pairCachingGhostObject; | ||
1807 | 1841 | ||
1808 | m_collisionsThisFrame = 0; | 1842 | m_collisionsThisFrame = 0; |
1809 | int numManifolds = world.GetDispatcher().GetNumManifolds(); | 1843 | int numManifolds = world.GetDispatcher().GetNumManifolds(); |
1810 | for (int j = 0; j < numManifolds; j++) | 1844 | for (int j = 0; j < numManifolds; j++) |
1811 | { | 1845 | { |
1812 | PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j); | 1846 | contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j); |
1813 | int numContacts = contactManifold.GetNumContacts(); | 1847 | int numContacts = contactManifold.GetNumContacts(); |
1814 | if (numContacts == 0) | 1848 | if (numContacts == 0) |
1815 | continue; | 1849 | continue; |
1816 | 1850 | ||
1817 | CollisionObject objA = contactManifold.GetBody0() as CollisionObject; | 1851 | objA = contactManifold.GetBody0() as CollisionObject; |
1818 | CollisionObject objB = contactManifold.GetBody1() as CollisionObject; | 1852 | objB = contactManifold.GetBody1() as CollisionObject; |
1819 | 1853 | ||
1820 | ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0); | 1854 | manifoldPoint = contactManifold.GetContactPoint(0); |
1821 | IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB(); | 1855 | //IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB(); |
1822 | IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A | 1856 | // IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A |
1823 | 1857 | ||
1824 | RecordCollision(this, objA, objB, contactPoint, contactNormal,manifoldPoint.GetDistance()); | 1858 | RecordCollision(this, objA, objB, manifoldPoint.GetPositionWorldOnB(), -manifoldPoint.m_normalWorldOnB, manifoldPoint.GetDistance()); |
1825 | m_collisionsThisFrame ++; | 1859 | m_collisionsThisFrame ++; |
1826 | if (m_collisionsThisFrame >= 9999999) | 1860 | if (m_collisionsThisFrame >= 9999999) |
1827 | break; | 1861 | break; |
@@ -1829,12 +1863,19 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1829 | 1863 | ||
1830 | } | 1864 | } |
1831 | 1865 | ||
1832 | updatedEntityCount = LastEntityProperty; | 1866 | foreach (GhostObject ghostObject in specialCollisionObjects.Values) |
1833 | updatedEntities = UpdatedObjects; | 1867 | { |
1834 | 1868 | pairCachingGhostObject = ghostObject as PairCachingGhostObject; | |
1869 | if (pairCachingGhostObject != null) | ||
1870 | { | ||
1871 | RecordGhostCollisions(pairCachingGhostObject); | ||
1872 | } | ||
1835 | 1873 | ||
1874 | } | ||
1836 | 1875 | ||
1837 | 1876 | ||
1877 | updatedEntityCount = LastEntityProperty; | ||
1878 | updatedEntities = UpdatedObjects; | ||
1838 | 1879 | ||
1839 | collidersCount = LastCollisionDesc; | 1880 | collidersCount = LastCollisionDesc; |
1840 | colliders = UpdatedCollisions; | 1881 | colliders = UpdatedCollisions; |
@@ -1860,60 +1901,49 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1860 | } | 1901 | } |
1861 | public void RecordGhostCollisions(PairCachingGhostObject obj) | 1902 | public void RecordGhostCollisions(PairCachingGhostObject obj) |
1862 | { | 1903 | { |
1863 | /* | 1904 | IOverlappingPairCache cache = obj.GetOverlappingPairCache(); |
1864 | *void BulletSim::RecordGhostCollisions(btPairCachingGhostObject* obj) | 1905 | ObjectArray<BroadphasePair> pairs = cache.GetOverlappingPairArray(); |
1865 | { | 1906 | |
1866 | btManifoldArray manifoldArray; | 1907 | DiscreteDynamicsWorld world = (PhysicsScene.World as BulletWorldXNA).world; |
1867 | btBroadphasePairArray& pairArray = obj->getOverlappingPairCache()->getOverlappingPairArray(); | 1908 | PersistentManifoldArray manifoldArray = new PersistentManifoldArray(); |
1868 | int numPairs = pairArray.size(); | 1909 | BroadphasePair collisionPair; |
1869 | 1910 | PersistentManifold contactManifold; | |
1870 | // For all the pairs of sets of contact points | 1911 | |
1871 | for (int i=0; i < numPairs; i++) | 1912 | CollisionObject objA; |
1872 | { | 1913 | CollisionObject objB; |
1873 | if (m_collisionsThisFrame >= m_maxCollisionsPerFrame) | 1914 | |
1874 | break; | 1915 | ManifoldPoint pt; |
1875 | 1916 | ||
1876 | manifoldArray.clear(); | 1917 | int numPairs = pairs.Count; |
1877 | const btBroadphasePair& pair = pairArray[i]; | 1918 | |
1878 | 1919 | for (int i = 0; i < numPairs; i++) | |
1879 | // The real representation is over in the world pair cache | 1920 | { |
1880 | btBroadphasePair* collisionPair = m_worldData.dynamicsWorld->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1); | 1921 | manifoldArray.Clear(); |
1881 | if (!collisionPair) | 1922 | if (LastCollisionDesc < UpdatedCollisions.Length) |
1882 | continue; | 1923 | break; |
1883 | 1924 | collisionPair = world.GetPairCache().FindPair(pairs[i].m_pProxy0, pairs[i].m_pProxy1); | |
1884 | if (collisionPair->m_algorithm) | 1925 | if (collisionPair == null) |
1885 | collisionPair->m_algorithm->getAllContactManifolds(manifoldArray); | 1926 | continue; |
1886 | 1927 | ||
1887 | // The collision pair has sets of collision points (manifolds) | 1928 | collisionPair.m_algorithm.GetAllContactManifolds(manifoldArray); |
1888 | for (int j=0; j < manifoldArray.size(); j++) | 1929 | for (int j = 0; j < manifoldArray.Count; j++) |
1889 | { | 1930 | { |
1890 | btPersistentManifold* contactManifold = manifoldArray[j]; | 1931 | contactManifold = manifoldArray[j]; |
1891 | int numContacts = contactManifold->getNumContacts(); | 1932 | int numContacts = contactManifold.GetNumContacts(); |
1892 | 1933 | objA = contactManifold.GetBody0() as CollisionObject; | |
1893 | const btCollisionObject* objA = static_cast<const btCollisionObject*>(contactManifold->getBody0()); | 1934 | objB = contactManifold.GetBody1() as CollisionObject; |
1894 | const btCollisionObject* objB = static_cast<const btCollisionObject*>(contactManifold->getBody1()); | 1935 | for (int p = 0; p < numContacts; p++) |
1895 | 1936 | { | |
1896 | // TODO: this is a more thurough check than the regular collision code -- | 1937 | pt = contactManifold.GetContactPoint(p); |
1897 | // here we find the penetrating contact in the manifold but for regular | 1938 | if (pt.GetDistance() < 0.0f) |
1898 | // collisions we assume the first point in the manifold is good enough. | 1939 | { |
1899 | // Decide of this extra checking is required or if first point is good enough. | 1940 | RecordCollision(this, objA, objB, pt.GetPositionWorldOnA(), -pt.m_normalWorldOnB,pt.GetDistance()); |
1900 | for (int p=0; p < numContacts; p++) | 1941 | break; |
1901 | { | 1942 | } |
1902 | const btManifoldPoint& pt = contactManifold->getContactPoint(p); | 1943 | } |
1903 | // If a penetrating contact, this is a hit | 1944 | } |
1904 | if (pt.getDistance()<0.f) | 1945 | } |
1905 | { | 1946 | |
1906 | const btVector3& contactPoint = pt.getPositionWorldOnA(); | ||
1907 | const btVector3& normalOnA = -pt.m_normalWorldOnB; | ||
1908 | RecordCollision(objA, objB, contactPoint, normalOnA, pt.getDistance()); | ||
1909 | // Only one contact point for each set of colliding objects | ||
1910 | break; | ||
1911 | } | ||
1912 | } | ||
1913 | } | ||
1914 | } | ||
1915 | } | ||
1916 | */ | ||
1917 | } | 1947 | } |
1918 | private static void RecordCollision(BSAPIXNA world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm, float penetration) | 1948 | private static void RecordCollision(BSAPIXNA world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm, float penetration) |
1919 | { | 1949 | { |
@@ -1934,7 +1964,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1934 | contactNormal = -contactNormal; | 1964 | contactNormal = -contactNormal; |
1935 | } | 1965 | } |
1936 | 1966 | ||
1937 | ulong collisionID = ((ulong) idA << 32) | idB; | 1967 | //ulong collisionID = ((ulong) idA << 32) | idB; |
1938 | 1968 | ||
1939 | CollisionDesc cDesc = new CollisionDesc() | 1969 | CollisionDesc cDesc = new CollisionDesc() |
1940 | { | 1970 | { |