Blender  V3.3
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 btCompoundFromGimpactShape : public btCompoundShape
10 {
11 public:
13 
15  {
16  /*delete all the btBU_Simplex1to4 ChildShapes*/
17  for (int i = 0; i < m_children.size(); i++)
18  {
19  delete m_children[i].m_childShape;
20  }
21  }
22 };
23 
25 {
28 
29  MyCallback(const btVector3& from, const btVector3& to, int ignorePart, int ignoreTriangleIndex)
31  m_ignorePart(ignorePart),
32  m_ignoreTriangleIndex(ignoreTriangleIndex)
33  {
34  }
35  virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
36  {
37  if (partId != m_ignorePart || triangleIndex != m_ignoreTriangleIndex)
38  {
39  if (hitFraction < m_hitFraction)
40  return hitFraction;
41  }
42 
43  return m_hitFraction;
44  }
45 };
47 {
51 
53  : m_colShape(colShape),
54  m_gimpactShape(meshShape),
55  m_depth(depth)
56  {
57  }
58 
59  virtual void internalProcessTriangleIndex(btVector3* triangle, int partId, int triangleIndex)
60  {
62  btVector3 v0 = triangle[0] * scale;
63  btVector3 v1 = triangle[1] * scale;
64  btVector3 v2 = triangle[2] * scale;
65 
66  btVector3 centroid = (v0 + v1 + v2) / 3;
67  btVector3 normal = (v1 - v0).cross(v2 - v0);
68  normal.normalize();
69  btVector3 rayFrom = centroid;
70  btVector3 rayTo = centroid - normal * m_depth;
71 
72  MyCallback cb(rayFrom, rayTo, partId, triangleIndex);
73 
74  m_gimpactShape->processAllTrianglesRay(&cb, rayFrom, rayTo);
75  if (cb.m_hitFraction < 1)
76  {
77  rayTo.setInterpolate3(cb.m_from, cb.m_to, cb.m_hitFraction);
78  //rayTo = cb.m_from;
79  //rayTo = rayTo.lerp(cb.m_to,cb.m_hitFraction);
80  //gDebugDraw.drawLine(tr(centroid),tr(centroid+normal),btVector3(1,0,0));
81  }
82 
83  btBU_Simplex1to4* tet = new btBU_Simplex1to4(v0, v1, v2, rayTo);
84  btTransform ident;
85  ident.setIdentity();
86  m_colShape->addChildShape(ident, tet);
87  }
88 };
89 
91 {
92  btCompoundShape* colShape = new btCompoundFromGimpactShape();
93 
94  btTransform tr;
95  tr.setIdentity();
96 
97  MyInternalTriangleIndexCallback cb(colShape, gimpactMesh, depth);
98  btVector3 aabbMin, aabbMax;
99  gimpactMesh->getAabb(tr, aabbMin, aabbMax);
100  gimpactMesh->getMeshInterface()->InternalProcessAllTriangles(&cb, aabbMin, aabbMax);
101 
102  return colShape;
103 }
104 
105 #endif //BT_COMPOUND_FROM_GIMPACT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
btCompoundShape * btCreateCompoundFromGimpactShape(const btGImpactMeshShape *gimpactMesh, btScalar depth)
virtual ~btCompoundFromGimpactShape()
btCompoundShape(bool enableDynamicAabbTree=true, const int initialChildCapacity=0)
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:425
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:285
btBU_Simplex1to4()
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
This class manages a mesh supplied by the btStridingMeshInterface interface.
virtual void processAllTrianglesRay(btTriangleCallback *callback, const btVector3 &rayFrom, const btVector3 &rayTo) const
Function for retrieve triangles.
btStridingMeshInterface * getMeshInterface()
void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
If the Bounding box is not updated, then this class attemps to calculate it.
virtual const btVector3 & getLocalScaling() const
StackEntry * from
IconTextureDrawCall normal
vec_base< T, 3 > cross(const vec_base< T, 3 > &a, const vec_base< T, 3 > &b)
virtual btScalar reportHit(const btVector3 &hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
MyCallback(const btVector3 &from, const btVector3 &to, int ignorePart, int ignoreTriangleIndex)
const btGImpactMeshShape * m_gimpactShape
MyInternalTriangleIndexCallback(btCompoundShape *colShape, const btGImpactMeshShape *meshShape, btScalar depth)
virtual void internalProcessTriangleIndex(btVector3 *triangle, int partId, int triangleIndex)