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 #include "btUniformScalingShape.h"
18 btUniformScalingShape::btUniformScalingShape( btConvexShape* convexChildShape,btScalar uniformScalingFactor):
19 btConvexShape (), m_childConvexShape(convexChildShape),
20 m_uniformScalingFactor(uniformScalingFactor)
22 m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE;
25 btUniformScalingShape::~btUniformScalingShape()
30 btVector3 btUniformScalingShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
33 tmpVertex = m_childConvexShape->localGetSupportingVertexWithoutMargin(vec);
34 return tmpVertex*m_uniformScalingFactor;
37 void btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
39 m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors);
41 for (i=0;i<numVectors;i++)
43 supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor;
48 btVector3 btUniformScalingShape::localGetSupportingVertex(const btVector3& vec)const
51 tmpVertex = m_childConvexShape->localGetSupportingVertex(vec);
52 return tmpVertex*m_uniformScalingFactor;
56 void btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
59 ///this linear upscaling is not realistic, but we don't deal with large mass ratios...
61 m_childConvexShape->calculateLocalInertia(mass,tmpInertia);
62 inertia = tmpInertia * m_uniformScalingFactor;
66 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
67 void btUniformScalingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
69 getAabbSlow(trans,aabbMin,aabbMax);
73 void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
76 btVector3 _directions[] =
78 btVector3( 1., 0., 0.),
79 btVector3( 0., 1., 0.),
80 btVector3( 0., 0., 1.),
81 btVector3( -1., 0., 0.),
82 btVector3( 0., -1., 0.),
83 btVector3( 0., 0., -1.)
86 btVector3 _supporting[] =
88 btVector3( 0., 0., 0.),
89 btVector3( 0., 0., 0.),
90 btVector3( 0., 0., 0.),
91 btVector3( 0., 0., 0.),
92 btVector3( 0., 0., 0.),
93 btVector3( 0., 0., 0.)
98 _directions[i] = _directions[i]*t.getBasis();
101 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
103 btVector3 aabbMin1(0,0,0),aabbMax1(0,0,0);
105 for ( int i = 0; i < 3; ++i )
107 aabbMax1[i] = t(_supporting[i])[i];
108 aabbMin1[i] = t(_supporting[i + 3])[i];
110 btVector3 marginVec(getMargin(),getMargin(),getMargin());
111 aabbMin = aabbMin1-marginVec;
112 aabbMax = aabbMax1+marginVec;
116 btScalar margin = getMargin();
117 for (int i=0;i<3;i++)
119 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
120 vec[i] = btScalar(1.);
121 btVector3 sv = localGetSupportingVertex(vec*t.getBasis());
122 btVector3 tmp = t(sv);
123 aabbMax[i] = tmp[i]+margin;
124 vec[i] = btScalar(-1.);
125 sv = localGetSupportingVertex(vec*t.getBasis());
127 aabbMin[i] = tmp[i]-margin;
133 void btUniformScalingShape::setLocalScaling(const btVector3& scaling)
135 m_childConvexShape->setLocalScaling(scaling);
138 const btVector3& btUniformScalingShape::getLocalScaling() const
140 return m_childConvexShape->getLocalScaling();
143 void btUniformScalingShape::setMargin(btScalar margin)
145 m_childConvexShape->setMargin(margin);
147 btScalar btUniformScalingShape::getMargin() const
149 return m_childConvexShape->getMargin() * m_uniformScalingFactor;
152 int btUniformScalingShape::getNumPreferredPenetrationDirections() const
154 return m_childConvexShape->getNumPreferredPenetrationDirections();
157 void btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
159 m_childConvexShape->getPreferredPenetrationDirection(index,penetrationVector);