Bullet Collision Detection & Physics Library: btSdfCollisionShape.cpp Source File

Bullet Collision Detection & Physics Library

btSdfCollisionShape.cpp
Go to the documentation of this file.
1 #include "btSdfCollisionShape.h"
2 #include "btMiniSDF.h"
3 #include "LinearMath/btAabbUtil2.h"
4
5 struct btSdfCollisionShapeInternalData
6 {
7 btVector3 m_localScaling;
8 btScalar m_margin;
9 btMiniSDF m_sdf;
10
11 btSdfCollisionShapeInternalData()
12 : m_localScaling(1, 1, 1),
13 m_margin(0)
14 {
15 }
16 };
17
18 bool btSdfCollisionShape::initializeSDF(const char* sdfData, int sizeInBytes)
19 {
20 bool valid = m_data->m_sdf.load(sdfData, sizeInBytes);
21 return valid;
22 }
23 btSdfCollisionShape::btSdfCollisionShape()
24 {
25 m_shapeType = SDF_SHAPE_PROXYTYPE;
26 m_data = new btSdfCollisionShapeInternalData();
27
28 //"E:/develop/bullet3/data/toys/ground_hole64_64_8.cdf");//ground_cube.cdf");
29 /*unsigned int field_id=0;
30 Eigen::Vector3d x (1,10,1);
31 Eigen::Vector3d gradient;
32 double dist = m_data->m_sdf.interpolate(field_id, x, &gradient);
33 printf("dist=%g\n", dist);
34 */
35 }
36 btSdfCollisionShape::~btSdfCollisionShape()
37 {
38 delete m_data;
39 }
40
41 void btSdfCollisionShape::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
42 {
43 btAssert(m_data->m_sdf.isValid());
44 btVector3 localAabbMin = m_data->m_sdf.m_domain.m_min;
45 btVector3 localAabbMax = m_data->m_sdf.m_domain.m_max;
46 btScalar margin(0);
47 btTransformAabb(localAabbMin, localAabbMax, margin, t, aabbMin, aabbMax);
48 }
49
50 void btSdfCollisionShape::setLocalScaling(const btVector3& scaling)
51 {
52 m_data->m_localScaling = scaling;
53 }
54 const btVector3& btSdfCollisionShape::getLocalScaling() const
55 {
56 return m_data->m_localScaling;
57 }
58 void btSdfCollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
59 {
60 inertia.setValue(0, 0, 0);
61 }
62 const char* btSdfCollisionShape::getName() const
63 {
64 return "btSdfCollisionShape";
65 }
66 void btSdfCollisionShape::setMargin(btScalar margin)
67 {
68 m_data->m_margin = margin;
69 }
70 btScalar btSdfCollisionShape::getMargin() const
71 {
72 return m_data->m_margin;
73 }
74
75 void btSdfCollisionShape::processAllTriangles(btTriangleCallback* callback, const btVector3& aabbMin, const btVector3& aabbMax) const
76 {
77 //not yet
78 }
79
80 bool btSdfCollisionShape::queryPoint(const btVector3& ptInSDF, btScalar& distOut, btVector3& normal)
81 {
82 int field = 0;
83 btVector3 grad;
84 double dist;
85 bool hasResult = m_data->m_sdf.interpolate(field, dist, ptInSDF, &grad);
86 if (hasResult)
87 {
88 normal.setValue(grad[0], grad[1], grad[2]);
89 distOut = dist;
90 }
91 return hasResult;
92 }
btMiniSDF::load
bool load(const char *data, int size)
Definition: btMiniSDF.cpp:45
btSdfCollisionShapeInternalData::m_margin
btScalar m_margin
Definition: btSdfCollisionShape.cpp:8
btSdfCollisionShape::setMargin
virtual void setMargin(btScalar margin)
Definition: btSdfCollisionShape.cpp:66
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btMiniSDF.h
btSdfCollisionShape::btSdfCollisionShape
btSdfCollisionShape()
Definition: btSdfCollisionShape.cpp:23
btSdfCollisionShapeInternalData::btSdfCollisionShapeInternalData
btSdfCollisionShapeInternalData()
Definition: btSdfCollisionShape.cpp:11
btMiniSDF
Definition: btMiniSDF.h:91
btSdfCollisionShape::getName
virtual const char * getName() const
Definition: btSdfCollisionShape.cpp:62
btCollisionShape::m_shapeType
int m_shapeType
Definition: btCollisionShape.h:30
btAssert
#define btAssert(x)
Definition: btScalar.h:153
SDF_SHAPE_PROXYTYPE
@ SDF_SHAPE_PROXYTYPE
Definition: btBroadphaseProxy.h:68
btMiniSDF::interpolate
bool interpolate(unsigned int field_id, double &dist, btVector3 const &x, btVector3 *gradient) const
Definition: btMiniSDF.cpp:442
btSdfCollisionShape::queryPoint
bool queryPoint(const btVector3 &ptInSDF, btScalar &distOut, btVector3 &normal)
Definition: btSdfCollisionShape.cpp:80
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition: btTriangleCallback.h:24
btSdfCollisionShape::~btSdfCollisionShape
virtual ~btSdfCollisionShape()
Definition: btSdfCollisionShape.cpp:36
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btSdfCollisionShape::getMargin
virtual btScalar getMargin() const
Definition: btSdfCollisionShape.cpp:70
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btSdfCollisionShape::processAllTriangles
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btSdfCollisionShape.cpp:75
btSdfCollisionShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btSdfCollisionShape.cpp:54
btMiniSDF::m_domain
btAlignedBox3d m_domain
Definition: btMiniSDF.h:92
btAabbUtil2.h
btSdfCollisionShapeInternalData::m_localScaling
btVector3 m_localScaling
Definition: btSdfCollisionShape.cpp:7
btAlignedBox3d::m_max
btVector3 m_max
Definition: btMiniSDF.h:16
btMiniSDF::isValid
bool isValid() const
Definition: btMiniSDF.h:109
btSdfCollisionShapeInternalData::m_sdf
btMiniSDF m_sdf
Definition: btSdfCollisionShape.cpp:9
btSdfCollisionShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btSdfCollisionShape.cpp:50
btSdfCollisionShape::getAabb
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
Definition: btSdfCollisionShape.cpp:41
btTransformAabb
void btTransformAabb(const btVector3 &halfExtents, btScalar margin, const btTransform &t, btVector3 &aabbMinOut, btVector3 &aabbMaxOut)
Definition: btAabbUtil2.h:172
btAlignedBox3d::m_min
btVector3 m_min
Definition: btMiniSDF.h:15
btSdfCollisionShape::m_data
struct btSdfCollisionShapeInternalData * m_data
Definition: btSdfCollisionShape.h:8
btSdfCollisionShape::initializeSDF
bool initializeSDF(const char *sdfData, int sizeInBytes)
Definition: btSdfCollisionShape.cpp:18
btSdfCollisionShape.h
btSdfCollisionShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btSdfCollisionShape.cpp:58
btSdfCollisionShapeInternalData
Definition: btSdfCollisionShape.cpp:6