Bullet Collision Detection & Physics Library
btSdfCollisionShape.cpp
Go to the documentation of this file.
1 #include "btSdfCollisionShape.h"
2 #include "btMiniSDF.h"
4 
6 {
10 
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 }
24 {
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 }
37 {
38  delete m_data;
39 }
40 
41 void btSdfCollisionShape::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
42 {
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 
51 {
52  m_data->m_localScaling = scaling;
53 }
55 {
56  return m_data->m_localScaling;
57 }
59 {
60  inertia.setValue(0, 0, 0);
61 }
62 const char* btSdfCollisionShape::getName() const
63 {
64  return "btSdfCollisionShape";
65 }
67 {
68  m_data->m_margin = margin;
69 }
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 }
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640
bool initializeSDF(const char *sdfData, int sizeInBytes)
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...
btVector3 m_min
Definition: btMiniSDF.h:15
#define btAssert(x)
Definition: btScalar.h:133
btVector3 m_max
Definition: btMiniSDF.h:16
bool interpolate(unsigned int field_id, double &dist, btVector3 const &x, btVector3 *gradient) const
Definition: btMiniSDF.cpp:442
btAlignedBox3d m_domain
Definition: btMiniSDF.h:92
bool load(const char *data, int size)
Definition: btMiniSDF.cpp:45
virtual const char * getName() const
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
virtual void setLocalScaling(const btVector3 &scaling)
struct btSdfCollisionShapeInternalData * m_data
virtual void setMargin(btScalar margin)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
virtual btScalar getMargin() const
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:28
bool queryPoint(const btVector3 &ptInSDF, btScalar &distOut, btVector3 &normal)
bool isValid() const
Definition: btMiniSDF.h:109
virtual const btVector3 & getLocalScaling() const
void btTransformAabb(const btVector3 &halfExtents, btScalar margin, const btTransform &t, btVector3 &aabbMinOut, btVector3 &aabbMaxOut)
Definition: btAabbUtil2.h:172
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:294