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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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