Changeset 2907 for code/branches/questsystem5/src/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
- Timestamp:
- Apr 8, 2009, 12:36:08 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
r2662 r2907 5 5 This software is provided 'as-is', without any express or implied warranty. 6 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 9 subject to the following restrictions: 10 10 … … 23 23 //#include <stdio.h> 24 24 25 btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped )25 btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold) 26 26 : btCollisionAlgorithm(ci), 27 27 m_ownManifold(false), 28 28 m_manifoldPtr(mf), 29 m_isSwapped(isSwapped) 29 m_isSwapped(isSwapped), 30 m_numPerturbationIterations(numPerturbationIterations), 31 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold) 30 32 { 31 33 btCollisionObject* convexObj = m_isSwapped? col1 : col0; 32 34 btCollisionObject* planeObj = m_isSwapped? col0 : col1; 33 35 34 36 if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj)) 35 37 { … … 49 51 } 50 52 51 52 53 void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 53 void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 54 54 { 55 (void)dispatchInfo; 56 (void)resultOut; 57 if (!m_manifoldPtr) 58 return; 59 60 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 55 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 61 56 btCollisionObject* planeObj = m_isSwapped? body0: body1; 62 57 … … 64 59 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 65 60 66 61 bool hasCollision = false; 67 62 const btVector3& planeNormal = planeShape->getPlaneNormal(); 68 63 const btScalar& planeConstant = planeShape->getPlaneConstant(); 64 65 btTransform convexWorldTransform = convexObj->getWorldTransform(); 66 btTransform convexInPlaneTrans; 67 convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform; 68 //now perturbe the convex-world transform 69 convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot); 69 70 btTransform planeInConvex; 70 planeInConvex= convex Obj->getWorldTransform().inverse() * planeObj->getWorldTransform();71 btTransform convexInPlaneTrans;72 convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->getWorldTransform();71 planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform(); 72 73 btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal); 73 74 74 btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);75 75 btVector3 vtxInPlane = convexInPlaneTrans(vtx); 76 76 btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant); … … 88 88 resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance); 89 89 } 90 } 91 92 93 void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 94 { 95 (void)dispatchInfo; 96 if (!m_manifoldPtr) 97 return; 98 99 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 100 btCollisionObject* planeObj = m_isSwapped? body0: body1; 101 102 btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape(); 103 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 104 105 bool hasCollision = false; 106 const btVector3& planeNormal = planeShape->getPlaneNormal(); 107 const btScalar& planeConstant = planeShape->getPlaneConstant(); 108 109 //first perform a collision query with the non-perturbated collision objects 110 { 111 btQuaternion rotq(0,0,0,1); 112 collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut); 113 } 114 115 if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold) 116 { 117 btVector3 v0,v1; 118 btPlaneSpace1(planeNormal,v0,v1); 119 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects 120 121 const btScalar angleLimit = 0.125f * SIMD_PI; 122 btScalar perturbeAngle; 123 btScalar radius = convexShape->getAngularMotionDisc(); 124 perturbeAngle = gContactBreakingThreshold / radius; 125 if ( perturbeAngle > angleLimit ) 126 perturbeAngle = angleLimit; 127 128 btQuaternion perturbeRot(v0,perturbeAngle); 129 for (int i=0;i<m_numPerturbationIterations;i++) 130 { 131 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); 132 btQuaternion rotq(planeNormal,iterationAngle); 133 collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0,body1,dispatchInfo,resultOut); 134 } 135 } 136 90 137 if (m_ownManifold) 91 138 {
Note: See TracChangeset
for help on using the changeset viewer.