Changeset 2908 for code/branches/questsystem5/src/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
- Timestamp:
- Apr 8, 2009, 12:58:47 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
r2907 r2908 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 , int numPerturbationIterations,int minimumPointsPerturbationThreshold)25 btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped) 26 26 : btCollisionAlgorithm(ci), 27 27 m_ownManifold(false), 28 28 m_manifoldPtr(mf), 29 m_isSwapped(isSwapped), 30 m_numPerturbationIterations(numPerturbationIterations), 31 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold) 29 m_isSwapped(isSwapped) 32 30 { 33 31 btCollisionObject* convexObj = m_isSwapped? col1 : col0; 34 32 btCollisionObject* planeObj = m_isSwapped? col0 : col1; 35 33 36 34 if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj)) 37 35 { … … 51 49 } 52 50 53 void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 51 52 53 void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 54 54 { 55 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 55 (void)dispatchInfo; 56 (void)resultOut; 57 if (!m_manifoldPtr) 58 return; 59 60 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 56 61 btCollisionObject* planeObj = m_isSwapped? body0: body1; 57 62 … … 59 64 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 60 65 61 66 bool hasCollision = false; 62 67 const btVector3& planeNormal = planeShape->getPlaneNormal(); 63 68 const btScalar& planeConstant = planeShape->getPlaneConstant(); 64 65 btTransform convexWorldTransform = convexObj->getWorldTransform();69 btTransform planeInConvex; 70 planeInConvex= convexObj->getWorldTransform().inverse() * planeObj->getWorldTransform(); 66 71 btTransform convexInPlaneTrans; 67 convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform; 68 //now perturbe the convex-world transform 69 convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot); 70 btTransform planeInConvex; 71 planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform(); 72 72 convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->getWorldTransform(); 73 73 74 btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal); 74 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 objects110 {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 objects120 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 137 90 if (m_ownManifold) 138 91 {
Note: See TracChangeset
for help on using the changeset viewer.