Bullet Collision Detection & Physics Library
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
20 m_shapeA(shapeA),
21 m_shapeB(shapeB)
22{
26}
27
29{
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
45{
46 return m_shapeA->getMargin() + m_shapeB->getMargin();
47}
48
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}
@ MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
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...
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
Definition: btConvexShape.h:33
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const =0
virtual btScalar getMargin() const =0
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
virtual btScalar getMargin() const
const btConvexShape * m_shapeB
btMinkowskiSumShape(const btConvexShape *shapeA, const btConvexShape *shapeB)
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
const btConvexShape * m_shapeA
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:109
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:167
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
const btScalar & z() const
Return the z value.
Definition: btVector3.h:579
const btScalar & x() const
Return the x value.
Definition: btVector3.h:575
const btScalar & y() const
Return the y value.
Definition: btVector3.h:577