Bullet Collision Detection & Physics Library: btCompoundFromGimpact.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btCompoundFromGimpact.h
Go to the documentation of this file.
1 #ifndef BT_COMPOUND_FROM_GIMPACT
2 #define BT_COMPOUND_FROM_GIMPACT
3
4 #include "BulletCollision/CollisionShapes/btCompoundShape.h"
5 #include "btGImpactShape.h"
6 #include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
7
8 struct MyCallback : public btTriangleRaycastCallback
9 {
10 int m_ignorePart;
11 int m_ignoreTriangleIndex;
12
13
14 MyCallback(const btVector3& from, const btVector3& to, int ignorePart, int ignoreTriangleIndex)
15 :btTriangleRaycastCallback(from,to),
16 m_ignorePart(ignorePart),
17 m_ignoreTriangleIndex(ignoreTriangleIndex)
18 {
19
20 }
21 virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
22 {
23 if (partId!=m_ignorePart || triangleIndex!=m_ignoreTriangleIndex)
24 {
25 if (hitFraction < m_hitFraction)
26 return hitFraction;
27 }
28
29 return m_hitFraction;
30 }
31 };
32 struct MyInternalTriangleIndexCallback :public btInternalTriangleIndexCallback
33 {
34 const btGImpactMeshShape* m_gimpactShape;
35 btCompoundShape* m_colShape;
36 btScalar m_depth;
37
38 MyInternalTriangleIndexCallback (btCompoundShape* colShape, const btGImpactMeshShape* meshShape, btScalar depth)
39 :m_colShape(colShape),
40 m_gimpactShape(meshShape),
41 m_depth(depth)
42 {
43 }
44
45 virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
46 {
47 btVector3 scale = m_gimpactShape->getLocalScaling();
48 btVector3 v0=triangle[0]*scale;
49 btVector3 v1=triangle[1]*scale;
50 btVector3 v2=triangle[2]*scale;
51
52 btVector3 centroid = (v0+v1+v2)/3;
53 btVector3 normal = (v1-v0).cross(v2-v0);
54 normal.normalize();
55 btVector3 rayFrom = centroid;
56 btVector3 rayTo = centroid-normal*m_depth;
57
58 MyCallback cb(rayFrom,rayTo,partId,triangleIndex);
59
60 m_gimpactShape->processAllTrianglesRay(&cb,rayFrom, rayTo);
61 if (cb.m_hitFraction<1)
62 {
63 rayTo.setInterpolate3(cb.m_from,cb.m_to,cb.m_hitFraction);
64 //rayTo = cb.m_from;
65 //rayTo = rayTo.lerp(cb.m_to,cb.m_hitFraction);
66 //gDebugDraw.drawLine(tr(centroid),tr(centroid+normal),btVector3(1,0,0));
67 }
68
69
70
71 btBU_Simplex1to4* tet = new btBU_Simplex1to4(v0,v1,v2,rayTo);
72 btTransform ident;
73 ident.setIdentity();
74 m_colShape->addChildShape(ident,tet);
75 }
76 };
77
78 btCompoundShape* btCreateCompoundFromGimpactShape(const btGImpactMeshShape* gimpactMesh, btScalar depth)
79 {
80 btCompoundShape* colShape = new btCompoundShape();
81
82 btTransform tr;
83 tr.setIdentity();
84
85 MyInternalTriangleIndexCallback cb(colShape,gimpactMesh, depth);
86 btVector3 aabbMin,aabbMax;
87 gimpactMesh->getAabb(tr,aabbMin,aabbMax);
88 gimpactMesh->getMeshInterface()->InternalProcessAllTriangles(&cb,aabbMin,aabbMax);
89
90 return colShape;
91 }
92
93 #endif //BT_COMPOUND_FROM_GIMPACT
MyCallback::m_ignoreTriangleIndex
int m_ignoreTriangleIndex
Definition: btCompoundFromGimpact.h:11
btTriangleRaycastCallback
Definition: btRaycastCallback.h:24
MyInternalTriangleIndexCallback::internalProcessTriangleIndex
virtual void internalProcessTriangleIndex(btVector3 *triangle, int partId, int triangleIndex)
Definition: btCompoundFromGimpact.h:45
MyInternalTriangleIndexCallback::m_gimpactShape
const btGImpactMeshShape * m_gimpactShape
Definition: btCompoundFromGimpact.h:34
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btCreateCompoundFromGimpactShape
btCompoundShape * btCreateCompoundFromGimpactShape(const btGImpactMeshShape *gimpactMesh, btScalar depth)
Definition: btCompoundFromGimpact.h:78
btRaycastCallback.h
btGImpactShape.h
MyInternalTriangleIndexCallback
Definition: btCompoundFromGimpact.h:32
btCompoundShape::addChildShape
void addChildShape(const btTransform &localTransform, btCollisionShape *shape)
Definition: btCompoundShape.cpp:51
btGImpactMeshShape
This class manages a mesh supplied by the btStridingMeshInterface interface.
Definition: btGImpactShape.h:910
btInternalTriangleIndexCallback
Definition: btTriangleCallback.h:32
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
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:297
MyCallback
Definition: btCompoundFromGimpact.h:8
btGImpactMeshShape::getMeshInterface
btStridingMeshInterface * getMeshInterface()
Definition: btGImpactShape.h:956
btGImpactMeshShape::processAllTrianglesRay
virtual void processAllTrianglesRay(btTriangleCallback *callback, const btVector3 &rayFrom, const btVector3 &rayTo) const
Function for retrieve triangles.
Definition: btGImpactShape.cpp:211
btBU_Simplex1to4
The btBU_Simplex1to4 implements tetrahedron, triangle, line, vertex collision shapes. In most cases it is better to use btConvexHullShape instead.
Definition: btTetrahedronShape.h:25
MyInternalTriangleIndexCallback::m_colShape
btCompoundShape * m_colShape
Definition: btCompoundFromGimpact.h:35
btTriangleRaycastCallback::m_to
btVector3 m_to
Definition: btRaycastCallback.h:30
btTriangleRaycastCallback::m_from
btVector3 m_from
Definition: btRaycastCallback.h:29
MyInternalTriangleIndexCallback::m_depth
btScalar m_depth
Definition: btCompoundFromGimpact.h:36
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
MyInternalTriangleIndexCallback::MyInternalTriangleIndexCallback
MyInternalTriangleIndexCallback(btCompoundShape *colShape, const btGImpactMeshShape *meshShape, btScalar depth)
Definition: btCompoundFromGimpact.h:38
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btGImpactShapeInterface::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btGImpactShape.h:169
MyCallback::reportHit
virtual btScalar reportHit(const btVector3 &hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
Definition: btCompoundFromGimpact.h:21
btCompoundShape
The btCompoundShape allows to store multiple other btCollisionShapes This allows for moving concave c...
Definition: btCompoundShape.h:54
btCompoundShape.h
MyCallback::m_ignorePart
int m_ignorePart
Definition: btCompoundFromGimpact.h:10
btVector3::setInterpolate3
void setInterpolate3(const btVector3 &v0, const btVector3 &v1, btScalar rt)
Definition: btVector3.h:491
MyCallback::MyCallback
MyCallback(const btVector3 &from, const btVector3 &to, int ignorePart, int ignoreTriangleIndex)
Definition: btCompoundFromGimpact.h:14
btTriangleRaycastCallback::m_hitFraction
btScalar m_hitFraction
Definition: btRaycastCallback.h:45
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btStridingMeshInterface::InternalProcessAllTriangles
virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btStridingMeshInterface.cpp:25