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
#ifndef BT_OBB_BOX_MINKOWSKI_H
17
#define BT_OBB_BOX_MINKOWSKI_H
19
#include "btPolyhedralConvexShape.h"
20
#include "btCollisionMargin.h"
21
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
22
#include "LinearMath/btVector3.h"
23
#include "LinearMath/btMinMax.h"
25
///The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
26
class btBoxShape: public btPolyhedralConvexShape
29
//btVector3 m_boxHalfExtents1; //use m_implicitShapeDimensions instead
34
btVector3 getHalfExtentsWithMargin() const
36
btVector3 halfExtents = getHalfExtentsWithoutMargin();
37
btVector3 margin(getMargin(),getMargin(),getMargin());
38
halfExtents += margin;
42
const btVector3& getHalfExtentsWithoutMargin() const
44
return m_implicitShapeDimensions;//scaling is included, margin is not
48
virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
50
btVector3 halfExtents = getHalfExtentsWithoutMargin();
51
btVector3 margin(getMargin(),getMargin(),getMargin());
52
halfExtents += margin;
54
return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
55
btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
56
btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
59
SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const
61
const btVector3& halfExtents = getHalfExtentsWithoutMargin();
63
return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
64
btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
65
btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
68
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
70
const btVector3& halfExtents = getHalfExtentsWithoutMargin();
72
for (int i=0;i<numVectors;i++)
74
const btVector3& vec = vectors[i];
75
supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
76
btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
77
btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
83
btBoxShape( const btVector3& boxHalfExtents)
84
: btPolyhedralConvexShape()
86
m_shapeType = BOX_SHAPE_PROXYTYPE;
87
btVector3 margin(getMargin(),getMargin(),getMargin());
88
m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
91
virtual void setMargin(btScalar collisionMargin)
93
//correct the m_implicitShapeDimensions for the margin
94
btVector3 oldMargin(getMargin(),getMargin(),getMargin());
95
btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
97
btConvexInternalShape::setMargin(collisionMargin);
98
btVector3 newMargin(getMargin(),getMargin(),getMargin());
99
m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
102
virtual void setLocalScaling(const btVector3& scaling)
104
btVector3 oldMargin(getMargin(),getMargin(),getMargin());
105
btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
106
btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
108
btConvexInternalShape::setLocalScaling(scaling);
110
m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
114
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
118
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
120
virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const
122
//this plane might not be aligned...
124
getPlaneEquation(plane,i);
125
planeNormal = btVector3(plane.getX(),plane.getY(),plane.getZ());
126
planeSupport = localGetSupportingVertex(-planeNormal);
130
virtual int getNumPlanes() const
135
virtual int getNumVertices() const
140
virtual int getNumEdges() const
146
virtual void getVertex(int i,btVector3& vtx) const
148
btVector3 halfExtents = getHalfExtentsWithMargin();
151
halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1),
152
halfExtents.y() * (1-((i&2)>>1)) - halfExtents.y() * ((i&2)>>1),
153
halfExtents.z() * (1-((i&4)>>2)) - halfExtents.z() * ((i&4)>>2));
157
virtual void getPlaneEquation(btVector4& plane,int i) const
159
btVector3 halfExtents = getHalfExtentsWithoutMargin();
164
plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.),-halfExtents.x());
167
plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.),-halfExtents.x());
170
plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.),-halfExtents.y());
173
plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.),-halfExtents.y());
176
plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.),-halfExtents.z());
179
plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.),-halfExtents.z());
187
virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
188
//virtual void getEdge(int i,Edge& edge) const
250
getVertex(edgeVert0,pa );
251
getVertex(edgeVert1,pb );
258
virtual bool isInside(const btVector3& pt,btScalar tolerance) const
260
btVector3 halfExtents = getHalfExtentsWithoutMargin();
262
//btScalar minDist = 2*tolerance;
264
bool result = (pt.x() <= (halfExtents.x()+tolerance)) &&
265
(pt.x() >= (-halfExtents.x()-tolerance)) &&
266
(pt.y() <= (halfExtents.y()+tolerance)) &&
267
(pt.y() >= (-halfExtents.y()-tolerance)) &&
268
(pt.z() <= (halfExtents.z()+tolerance)) &&
269
(pt.z() >= (-halfExtents.z()-tolerance));
276
virtual const char* getName()const
281
virtual int getNumPreferredPenetrationDirections() const
286
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
291
penetrationVector.setValue(btScalar(1.),btScalar(0.),btScalar(0.));
294
penetrationVector.setValue(btScalar(-1.),btScalar(0.),btScalar(0.));
297
penetrationVector.setValue(btScalar(0.),btScalar(1.),btScalar(0.));
300
penetrationVector.setValue(btScalar(0.),btScalar(-1.),btScalar(0.));
303
penetrationVector.setValue(btScalar(0.),btScalar(0.),btScalar(1.));
306
penetrationVector.setValue(btScalar(0.),btScalar(0.),btScalar(-1.));
316
#endif //BT_OBB_BOX_MINKOWSKI_H