Bullet Collision Detection & Physics Library
btUniformScalingShape.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
17
18btUniformScalingShape::btUniformScalingShape(btConvexShape* convexChildShape, btScalar uniformScalingFactor) : btConvexShape(), m_childConvexShape(convexChildShape), m_uniformScalingFactor(uniformScalingFactor)
19{
21}
22
24{
25}
26
28{
29 btVector3 tmpVertex;
31 return tmpVertex * m_uniformScalingFactor;
32}
33
34void btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
35{
36 m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors, supportVerticesOut, numVectors);
37 int i;
38 for (i = 0; i < numVectors; i++)
39 {
40 supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor;
41 }
42}
43
45{
46 btVector3 tmpVertex;
48 return tmpVertex * m_uniformScalingFactor;
49}
50
52{
54 btVector3 tmpInertia;
56 inertia = tmpInertia * m_uniformScalingFactor;
57}
58
60void btUniformScalingShape::getAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax) const
61{
62 getAabbSlow(trans, aabbMin, aabbMax);
63}
64
65void btUniformScalingShape::getAabbSlow(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
66{
67#if 1
68 btVector3 _directions[] =
69 {
70 btVector3(1., 0., 0.),
71 btVector3(0., 1., 0.),
72 btVector3(0., 0., 1.),
73 btVector3(-1., 0., 0.),
74 btVector3(0., -1., 0.),
75 btVector3(0., 0., -1.)};
76
77 btVector3 _supporting[] =
78 {
79 btVector3(0., 0., 0.),
80 btVector3(0., 0., 0.),
81 btVector3(0., 0., 0.),
82 btVector3(0., 0., 0.),
83 btVector3(0., 0., 0.),
84 btVector3(0., 0., 0.)};
85
86 for (int i = 0; i < 6; i++)
87 {
88 _directions[i] = _directions[i] * t.getBasis();
89 }
90
91 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
92
93 btVector3 aabbMin1(0, 0, 0), aabbMax1(0, 0, 0);
94
95 for (int i = 0; i < 3; ++i)
96 {
97 aabbMax1[i] = t(_supporting[i])[i];
98 aabbMin1[i] = t(_supporting[i + 3])[i];
99 }
100 btVector3 marginVec(getMargin(), getMargin(), getMargin());
101 aabbMin = aabbMin1 - marginVec;
102 aabbMax = aabbMax1 + marginVec;
103
104#else
105
106 btScalar margin = getMargin();
107 for (int i = 0; i < 3; i++)
108 {
109 btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
110 vec[i] = btScalar(1.);
112 btVector3 tmp = t(sv);
113 aabbMax[i] = tmp[i] + margin;
114 vec[i] = btScalar(-1.);
115 sv = localGetSupportingVertex(vec * t.getBasis());
116 tmp = t(sv);
117 aabbMin[i] = tmp[i] - margin;
118 }
119
120#endif
121}
122
124{
126}
127
129{
131}
132
134{
136}
138{
140}
141
143{
145}
146
148{
149 m_childConvexShape->getPreferredPenetrationDirection(index, penetrationVector);
150}
@ UNIFORM_SCALING_SHAPE_PROXYTYPE
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const =0
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
Definition: btConvexShape.h:33
virtual const btVector3 & getLocalScaling() const =0
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const =0
virtual void setLocalScaling(const btVector3 &scaling)=0
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const =0
virtual void setMargin(btScalar margin)=0
virtual int getNumPreferredPenetrationDirections() const =0
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const =0
virtual btScalar getMargin() const =0
virtual void getPreferredPenetrationDirection(int index, btVector3 &penetrationVector) const =0
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
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
virtual void getPreferredPenetrationDirection(int index, btVector3 &penetrationVector) const
btUniformScalingShape(btConvexShape *convexChildShape, btScalar uniformScalingFactor)
virtual void setLocalScaling(const btVector3 &scaling)
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
virtual btScalar getMargin() const
virtual void getAabbSlow(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
virtual void setMargin(btScalar margin)
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
btConvexShape * m_childConvexShape
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...
virtual int getNumPreferredPenetrationDirections() const
virtual const btVector3 & getLocalScaling() const
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82