2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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:
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.
16 #include "btConvexInternalShape.h"
18 btConvexInternalShape::btConvexInternalShape()
19 : m_localScaling(btScalar(1.), btScalar(1.), btScalar(1.)),
20 m_collisionMargin(CONVEX_DISTANCE_MARGIN)
24 void btConvexInternalShape::setLocalScaling(const btVector3& scaling)
26 m_localScaling = scaling.absolute();
29 void btConvexInternalShape::getAabbSlow(const btTransform& trans, btVector3& minAabb, btVector3& maxAabb) const
32 //use localGetSupportingVertexWithoutMargin?
33 btScalar margin = getMargin();
34 for (int i = 0; i < 3; i++)
36 btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
37 vec[i] = btScalar(1.);
39 btVector3 sv = localGetSupportingVertex(vec * trans.getBasis());
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;
50 btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec) const
54 btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
56 if (getMargin() != btScalar(0.))
58 btVector3 vecnorm = vec;
59 if (vecnorm.length2() < (SIMD_EPSILON * SIMD_EPSILON))
61 vecnorm.setValue(btScalar(-1.), btScalar(-1.), btScalar(-1.));
64 supVertex += getMargin() * vecnorm;
70 return btVector3(0, 0, 0);
74 btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape()
75 : btConvexInternalShape(),
76 m_localAabbMin(1, 1, 1),
77 m_localAabbMax(-1, -1, -1),
78 m_isLocalAabbValid(false)
82 void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax) const
84 getNonvirtualAabb(trans, aabbMin, aabbMax, getMargin());
87 void btConvexInternalAabbCachingShape::setLocalScaling(const btVector3& scaling)
89 btConvexInternalShape::setLocalScaling(scaling);
93 void btConvexInternalAabbCachingShape::recalcLocalAabb()
95 m_isLocalAabbValid = true;
98 static const btVector3 _directions[] =
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.)};
107 btVector3 _supporting[] =
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.)};
116 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
118 for (int i = 0; i < 3; ++i)
120 m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
121 m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
126 for (int i = 0; i < 3; i++)
128 btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
129 vec[i] = btScalar(1.);
130 btVector3 tmp = localGetSupportingVertex(vec);
131 m_localAabbMax[i] = tmp[i] + m_collisionMargin;
132 vec[i] = btScalar(-1.);
133 tmp = localGetSupportingVertex(vec);
134 m_localAabbMin[i] = tmp[i] - m_collisionMargin;