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