Blender  V3.3
btConvexInternalShape.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #include "btConvexInternalShape.h"
17 
19  : m_localScaling(btScalar(1.), btScalar(1.), btScalar(1.)),
21 {
22 }
23 
25 {
26  m_localScaling = scaling.absolute();
27 }
28 
29 void btConvexInternalShape::getAabbSlow(const btTransform& trans, btVector3& minAabb, btVector3& maxAabb) const
30 {
31 #ifndef __SPU__
32  //use localGetSupportingVertexWithoutMargin?
33  btScalar margin = getMargin();
34  for (int i = 0; i < 3; i++)
35  {
36  btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
37  vec[i] = btScalar(1.);
38 
39  btVector3 sv = localGetSupportingVertex(vec * trans.getBasis());
40 
41  btVector3 tmp = trans(sv);
42  maxAabb[i] = tmp[i] + margin;
43  vec[i] = btScalar(-1.);
44  tmp = trans(localGetSupportingVertex(vec * trans.getBasis()));
45  minAabb[i] = tmp[i] - margin;
46  }
47 #endif
48 }
49 
51 {
52 #ifndef __SPU__
53 
55 
56  if (getMargin() != btScalar(0.))
57  {
58  btVector3 vecnorm = vec;
59  if (vecnorm.length2() < (SIMD_EPSILON * SIMD_EPSILON))
60  {
61  vecnorm.setValue(btScalar(-1.), btScalar(-1.), btScalar(-1.));
62  }
63  vecnorm.normalize();
64  supVertex += getMargin() * vecnorm;
65  }
66  return supVertex;
67 
68 #else
69  btAssert(0);
70  return btVector3(0, 0, 0);
71 #endif //__SPU__
72 }
73 
76  m_localAabbMin(1, 1, 1),
77  m_localAabbMax(-1, -1, -1),
78  m_isLocalAabbValid(false)
79 {
80 }
81 
82 void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax) const
83 {
84  getNonvirtualAabb(trans, aabbMin, aabbMax, getMargin());
85 }
86 
88 {
91 }
92 
94 {
95  m_isLocalAabbValid = true;
96 
97 #if 1
98  static const btVector3 _directions[] =
99  {
100  btVector3(1., 0., 0.),
101  btVector3(0., 1., 0.),
102  btVector3(0., 0., 1.),
103  btVector3(-1., 0., 0.),
104  btVector3(0., -1., 0.),
105  btVector3(0., 0., -1.)};
106 
107  btVector3 _supporting[] =
108  {
109  btVector3(0., 0., 0.),
110  btVector3(0., 0., 0.),
111  btVector3(0., 0., 0.),
112  btVector3(0., 0., 0.),
113  btVector3(0., 0., 0.),
114  btVector3(0., 0., 0.)};
115 
116  batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
117 
118  for (int i = 0; i < 3; ++i)
119  {
120  m_localAabbMax[i] = _supporting[i][i];
121  m_localAabbMin[i] = _supporting[i + 3][i];
122  }
123 
124 #else
125 
126  for (int i = 0; i < 3; i++)
127  {
128  btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
129  vec[i] = btScalar(1.);
131  m_localAabbMax[i] = tmp[i];
132  vec[i] = btScalar(-1.);
133  tmp = localGetSupportingVertex(vec);
134  m_localAabbMin[i] = tmp[i];
135  }
136 #endif
137 }
virtual void setLocalScaling(const btVector3 &scaling)
in case we receive negative scaling
Definition: btBox2dShape.h:120
SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
btConvexShape Interface
Definition: btBox2dShape.h:62
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
Definition: btBox2dShape.h:51
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
Definition: btBox2dShape.h:71
#define CONVEX_DISTANCE_MARGIN
virtual btScalar getMargin() const =0
btVector3 m_localAabbMin
btScalar m_collisionMargin
btVector3 m_localAabbMax
btVector3 m_localScaling
virtual void getAabbSlow(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
btConvexInternalShape()
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define SIMD_EPSILON
Definition: btScalar.h:543
#define btAssert(x)
Definition: btScalar.h:295
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
void getNonvirtualAabb(const btTransform &trans, btVector3 &aabbMin, btVector3 &aabbMax, btScalar margin) const
virtual void setLocalScaling(const btVector3 &scaling)
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const