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 
19 bool btSdfCollisionShape::initializeSDF(const char* sdfData, int sizeInBytes)
20 {
21  bool valid = m_data->m_sdf.load(sdfData, sizeInBytes);
22  return valid;
23 }
25 {
26  m_shapeType = SDF_SHAPE_PROXYTYPE;
27  m_data = new btSdfCollisionShapeInternalData();
28 
29 
30 
31  //"E:/develop/bullet3/data/toys/ground_hole64_64_8.cdf");//ground_cube.cdf");
32  /*unsigned int field_id=0;
33  Eigen::Vector3d x (1,10,1);
34  Eigen::Vector3d gradient;
35  double dist = m_data->m_sdf.interpolate(field_id, x, &gradient);
36  printf("dist=%g\n", dist);
37  */
38 
39 }
41 {
42  delete m_data;
43 }
44 
45 void btSdfCollisionShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
46 {
47  btAssert(m_data->m_sdf.isValid());
48  btVector3 localAabbMin = m_data->m_sdf.m_domain.m_min;
49  btVector3 localAabbMax = m_data->m_sdf.m_domain.m_max;
50  btScalar margin(0);
51  btTransformAabb(localAabbMin,localAabbMax,margin,t,aabbMin,aabbMax);
52 
53 }
54 
55 
57 {
58  m_data->m_localScaling = scaling;
59 }
61 {
62  return m_data->m_localScaling;
63 }
65 {
66  inertia.setValue(0,0,0);
67 }
68 const char* btSdfCollisionShape::getName()const
69 {
70  return "btSdfCollisionShape";
71 }
73 {
74  m_data->m_margin = margin;
75 }
77 {
78  return m_data->m_margin;
79 }
80 
81 void btSdfCollisionShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
82 {
83  //not yet
84 }
85 
86 
87 bool btSdfCollisionShape::queryPoint(const btVector3& ptInSDF, btScalar& distOut, btVector3& normal)
88 {
89  int field = 0;
90  btVector3 grad;
91  double dist;
92  bool hasResult = m_data->m_sdf.interpolate(field,dist, ptInSDF,&grad);
93  if (hasResult)
94  {
95  normal.setValue(grad[0],grad[1],grad[2]);
96  distOut= dist;
97  }
98  return hasResult;
99 }
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...
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
bool initializeSDF(const char *sdfData, int sizeInBytes)
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
#define btAssert(x)
Definition: btScalar.h:131
virtual const char * getName() const
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
virtual void setLocalScaling(const btVector3 &scaling)
virtual void setMargin(btScalar margin)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
virtual const btVector3 & getLocalScaling() const
bool queryPoint(const btVector3 &ptInSDF, btScalar &distOut, btVector3 &normal)
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
void btTransformAabb(const btVector3 &halfExtents, btScalar margin, const btTransform &t, btVector3 &aabbMinOut, btVector3 &aabbMaxOut)
Definition: btAabbUtil2.h:182
virtual btScalar getMargin() const
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292