Bullet Collision Detection & Physics Library: btMinkowskiSumShape.cpp Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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