From 0336ed86375aa507c9176c81a2cde483bd451a53 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Sat, 6 Aug 2011 21:50:09 +0000 Subject: [PATCH] prepare support for picking softbody tetrahedra --- src/BulletSoftBody/btSoftBody.cpp | 39 +++++++++++++++++-- src/BulletSoftBody/btSoftBody.h | 1 + .../btSoftRigidDynamicsWorld.cpp | 15 +++++-- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index d440c94a7..11f8e4145 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -19,6 +19,7 @@ subject to the following restrictions: #include "btSoftBodyData.h" #include "LinearMath/btSerializer.h" + // btSoftBody::btSoftBody(btSoftBodyWorldInfo* worldInfo,int node_count, const btVector3* x, const btScalar* m) :m_worldInfo(worldInfo),m_softBodySolver(0) @@ -1909,11 +1910,12 @@ int btSoftBody::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const { int cnt=0; + btVector3 dir = rayTo-rayFrom; + + if(bcountonly||m_fdbvt.empty()) {/* Full search */ - btVector3 dir = rayTo-rayFrom; - dir.normalize(); - + for(int i=0,ni=m_faces.size();im_x; + btVector3 v1=tet.m_n[index1]->m_x; + btVector3 v2=tet.m_n[index2]->m_x; + + + const btScalar t=RayFromToCaster::rayFromToTriangle( rayFrom,rayTo,dir, + v0,v1,v2, + mint); + if(t>0) + { + ++cnt; + if(!bcountonly) + { + feature=btSoftBody::eFeature::Tetra; + index=i; + mint=t; + } + } + } + } return(cnt); } diff --git a/src/BulletSoftBody/btSoftBody.h b/src/BulletSoftBody/btSoftBody.h index dbdaf5d77..ec2f1a68b 100644 --- a/src/BulletSoftBody/btSoftBody.h +++ b/src/BulletSoftBody/btSoftBody.h @@ -117,6 +117,7 @@ public: Node, Link, Face, + Tetra, END };}; diff --git a/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp b/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp index 1b9b5e392..12381031f 100644 --- a/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp +++ b/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp @@ -300,12 +300,19 @@ void btSoftRigidDynamicsWorld::rayTestSingle(const btTransform& rayFromTrans,con shapeInfo.m_shapePart = 0; shapeInfo.m_triangleIndex = softResult.index; // get the normal - btVector3 normal = softBody->m_faces[softResult.index].m_normal; btVector3 rayDir = rayToTrans.getOrigin() - rayFromTrans.getOrigin(); - if (normal.dot(rayDir) > 0) { - // normal always point toward origin of the ray - normal = -normal; + btVector3 normal=-rayDir; + normal.normalize(); + + if (softResult.feature == btSoftBody::eFeature::Face) + { + normal = softBody->m_faces[softResult.index].m_normal; + if (normal.dot(rayDir) > 0) { + // normal always point toward origin of the ray + normal = -normal; + } } + btCollisionWorld::LocalRayResult rayResult (collisionObject, &shapeInfo,