Bullet Collision Detection & Physics Library
btCompoundFromGimpact.h
Go to the documentation of this file.
1 #ifndef BT_COMPOUND_FROM_GIMPACT
2 #define BT_COMPOUND_FROM_GIMPACT
3 
5 #include "btGImpactShape.h"
7 
9 {
10 public:
12 
14  {
15  /*delete all the btBU_Simplex1to4 ChildShapes*/
16  for (int i = 0; i < m_children.size(); i++)
17  {
18  delete m_children[i].m_childShape;
19  }
20  }
21 
22 };
23 
25  {
28 
29 
30  MyCallback(const btVector3& from, const btVector3& to, int ignorePart, int ignoreTriangleIndex)
31  :btTriangleRaycastCallback(from,to),
32  m_ignorePart(ignorePart),
33  m_ignoreTriangleIndex(ignoreTriangleIndex)
34  {
35 
36  }
37  virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
38  {
39  if (partId!=m_ignorePart || triangleIndex!=m_ignoreTriangleIndex)
40  {
41  if (hitFraction < m_hitFraction)
42  return hitFraction;
43  }
44 
45  return m_hitFraction;
46  }
47  };
49  {
53 
55  :m_colShape(colShape),
56  m_gimpactShape(meshShape),
57  m_depth(depth)
58  {
59  }
60 
61  virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
62  {
64  btVector3 v0=triangle[0]*scale;
65  btVector3 v1=triangle[1]*scale;
66  btVector3 v2=triangle[2]*scale;
67 
68  btVector3 centroid = (v0+v1+v2)/3;
69  btVector3 normal = (v1-v0).cross(v2-v0);
70  normal.normalize();
71  btVector3 rayFrom = centroid;
72  btVector3 rayTo = centroid-normal*m_depth;
73 
74  MyCallback cb(rayFrom,rayTo,partId,triangleIndex);
75 
76  m_gimpactShape->processAllTrianglesRay(&cb,rayFrom, rayTo);
77  if (cb.m_hitFraction<1)
78  {
79  rayTo.setInterpolate3(cb.m_from,cb.m_to,cb.m_hitFraction);
80  //rayTo = cb.m_from;
81  //rayTo = rayTo.lerp(cb.m_to,cb.m_hitFraction);
82  //gDebugDraw.drawLine(tr(centroid),tr(centroid+normal),btVector3(1,0,0));
83  }
84 
85 
86 
87  btBU_Simplex1to4* tet = new btBU_Simplex1to4(v0,v1,v2,rayTo);
88  btTransform ident;
89  ident.setIdentity();
90  m_colShape->addChildShape(ident,tet);
91  }
92  };
93 
95 {
97 
98  btTransform tr;
99  tr.setIdentity();
100 
101  MyInternalTriangleIndexCallback cb(colShape,gimpactMesh, depth);
102  btVector3 aabbMin,aabbMax;
103  gimpactMesh->getAabb(tr,aabbMin,aabbMax);
104  gimpactMesh->getMeshInterface()->InternalProcessAllTriangles(&cb,aabbMin,aabbMax);
105 
106  return colShape;
107 }
108 
109 #endif //BT_COMPOUND_FROM_GIMPACT
btTriangleRaycastCallback::m_hitFraction
btScalar m_hitFraction
Definition: btRaycastCallback.h:45
btTriangleRaycastCallback
Definition: btRaycastCallback.h:24
btRaycastCallback.h
btInternalTriangleIndexCallback
Definition: btTriangleCallback.h:32
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btCompoundShape.h
MyInternalTriangleIndexCallback
Definition: btCompoundFromGimpact.h:48
btGImpactShapeInterface::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btGImpactShape.h:169
MyInternalTriangleIndexCallback::internalProcessTriangleIndex
virtual void internalProcessTriangleIndex(btVector3 *triangle, int partId, int triangleIndex)
Definition: btCompoundFromGimpact.h:61
btGImpactMeshShape::getMeshInterface
btStridingMeshInterface * getMeshInterface()
Definition: btGImpactShape.h:936
MyCallback
Definition: btCompoundFromGimpact.h:24
btStridingMeshInterface::InternalProcessAllTriangles
virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btStridingMeshInterface.cpp:25
btGImpactMeshShape
This class manages a mesh supplied by the btStridingMeshInterface interface.
Definition: btGImpactShape.h:890
btVector3::setInterpolate3
void setInterpolate3(const btVector3 &v0, const btVector3 &v1, btScalar rt)
Definition: btVector3.h:503
btGImpactShapeInterface::getAabb
void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
If the Bounding box is not updated, then this class attemps to calculate it.
Definition: btGImpactShape.h:134
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btCompoundFromGimpactShape::~btCompoundFromGimpactShape
virtual ~btCompoundFromGimpactShape()
Definition: btCompoundFromGimpact.h:13
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btCompoundFromGimpactShape
Definition: btCompoundFromGimpact.h:8
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
btTriangleRaycastCallback::m_to
btVector3 m_to
Definition: btRaycastCallback.h:30
btGImpactMeshShape::processAllTrianglesRay
virtual void processAllTrianglesRay(btTriangleCallback *callback, const btVector3 &rayFrom, const btVector3 &rayTo) const
Function for retrieve triangles.
Definition: btGImpactShape.cpp:264
MyInternalTriangleIndexCallback::m_colShape
btCompoundShape * m_colShape
Definition: btCompoundFromGimpact.h:51
btCompoundShape
The btCompoundShape allows to store multiple other btCollisionShapes This allows for moving concave c...
Definition: btCompoundShape.h:54
btCreateCompoundFromGimpactShape
btCompoundShape * btCreateCompoundFromGimpactShape(const btGImpactMeshShape *gimpactMesh, btScalar depth)
Definition: btCompoundFromGimpact.h:94
MyInternalTriangleIndexCallback::m_gimpactShape
const btGImpactMeshShape * m_gimpactShape
Definition: btCompoundFromGimpact.h:50
btCompoundShape::addChildShape
void addChildShape(const btTransform &localTransform, btCollisionShape *shape)
Definition: btCompoundShape.cpp:51
MyInternalTriangleIndexCallback::MyInternalTriangleIndexCallback
MyInternalTriangleIndexCallback(btCompoundShape *colShape, const btGImpactMeshShape *meshShape, btScalar depth)
Definition: btCompoundFromGimpact.h:54
btBU_Simplex1to4
The btBU_Simplex1to4 implements tetrahedron, triangle, line, vertex collision shapes....
Definition: btTetrahedronShape.h:25
btTriangleRaycastCallback::m_from
btVector3 m_from
Definition: btRaycastCallback.h:29
MyInternalTriangleIndexCallback::m_depth
btScalar m_depth
Definition: btCompoundFromGimpact.h:52
MyCallback::reportHit
virtual btScalar reportHit(const btVector3 &hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
Definition: btCompoundFromGimpact.h:37
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:309
MyCallback::m_ignoreTriangleIndex
int m_ignoreTriangleIndex
Definition: btCompoundFromGimpact.h:27
btGImpactShape.h
MyCallback::m_ignorePart
int m_ignorePart
Definition: btCompoundFromGimpact.h:26
MyCallback::MyCallback
MyCallback(const btVector3 &from, const btVector3 &to, int ignorePart, int ignoreTriangleIndex)
Definition: btCompoundFromGimpact.h:30