Blender V4.3
btMinkowskiSumShape.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#include "btMinkowskiSumShape.h"
17
18btMinkowskiSumShape::btMinkowskiSumShape(const btConvexShape* shapeA, const btConvexShape* shapeB)
19 : btConvexInternalShape(),
20 m_shapeA(shapeA),
21 m_shapeB(shapeB)
22{
24 m_transA.setIdentity();
25 m_transB.setIdentity();
26}
27
28btVector3 btMinkowskiSumShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
29{
30 btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(vec * m_transA.getBasis()));
31 btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin(-vec * m_transB.getBasis()));
32 return supVertexA - supVertexB;
33}
34
35void btMinkowskiSumShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
36{
38 for (int i = 0; i < numVectors; i++)
39 {
40 supportVerticesOut[i] = localGetSupportingVertexWithoutMargin(vectors[i]);
41 }
42}
43
44btScalar btMinkowskiSumShape::getMargin() const
45{
46 return m_shapeA->getMargin() + m_shapeB->getMargin();
47}
48
49void btMinkowskiSumShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
50{
51 (void)mass;
52 //inertia of the AABB of the Minkowski sum
53 btTransform identity;
54 identity.setIdentity();
55 btVector3 aabbMin, aabbMax;
56 getAabb(identity, aabbMin, aabbMax);
57
58 btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
59
60 btScalar margin = getMargin();
61
62 btScalar lx = btScalar(2.) * (halfExtents.x() + margin);
63 btScalar ly = btScalar(2.) * (halfExtents.y() + margin);
64 btScalar lz = btScalar(2.) * (halfExtents.z() + margin);
65 const btScalar x2 = lx * lx;
66 const btScalar y2 = ly * ly;
67 const btScalar z2 = lz * lz;
68 const btScalar scaledmass = mass * btScalar(0.08333333);
69
70 inertia = scaledmass * (btVector3(y2 + z2, x2 + z2, x2 + y2));
71}
SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
btConvexShape Interface
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb's default implementation is brute force, expected derived classes to implement a fast dedicat...
@ MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE
virtual btScalar getMargin() const =0
btConvexShape()
not supported on IBM SDK, until we fix the alignment of btVector3
const btConvexShape * m_shapeA
const btConvexShape * m_shapeB
btTransform m_transB
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
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