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) : btConvexShape(), m_childConvexShape(convexChildShape), m_uniformScalingFactor(uniformScalingFactor)
20 m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE;
23 btUniformScalingShape::~btUniformScalingShape()
27 btVector3 btUniformScalingShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
30 tmpVertex = m_childConvexShape->localGetSupportingVertexWithoutMargin(vec);
31 return tmpVertex * m_uniformScalingFactor;
34 void btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
36 m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors, supportVerticesOut, numVectors);
38 for (i = 0; i < numVectors; i++)
40 supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor;
44 btVector3 btUniformScalingShape::localGetSupportingVertex(const btVector3& vec) const
47 tmpVertex = m_childConvexShape->localGetSupportingVertex(vec);
48 return tmpVertex * m_uniformScalingFactor;
51 void btUniformScalingShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
53 ///this linear upscaling is not realistic, but we don't deal with large mass ratios...
55 m_childConvexShape->calculateLocalInertia(mass, tmpInertia);
56 inertia = tmpInertia * m_uniformScalingFactor;
59 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
60 void btUniformScalingShape::getAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax) const
62 getAabbSlow(trans, aabbMin, aabbMax);
65 void btUniformScalingShape::getAabbSlow(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
68 btVector3 _directions[] =
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.)};
77 btVector3 _supporting[] =
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.)};
86 for (int i = 0; i < 6; i++)
88 _directions[i] = _directions[i] * t.getBasis();
91 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
93 btVector3 aabbMin1(0, 0, 0), aabbMax1(0, 0, 0);
95 for (int i = 0; i < 3; ++i)
97 aabbMax1[i] = t(_supporting[i])[i];
98 aabbMin1[i] = t(_supporting[i + 3])[i];
100 btVector3 marginVec(getMargin(), getMargin(), getMargin());
101 aabbMin = aabbMin1 - marginVec;
102 aabbMax = aabbMax1 + marginVec;
106 btScalar margin = getMargin();
107 for (int i = 0; i < 3; i++)
109 btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
110 vec[i] = btScalar(1.);
111 btVector3 sv = localGetSupportingVertex(vec * t.getBasis());
112 btVector3 tmp = t(sv);
113 aabbMax[i] = tmp[i] + margin;
114 vec[i] = btScalar(-1.);
115 sv = localGetSupportingVertex(vec * t.getBasis());
117 aabbMin[i] = tmp[i] - margin;
123 void btUniformScalingShape::setLocalScaling(const btVector3& scaling)
125 m_childConvexShape->setLocalScaling(scaling);
128 const btVector3& btUniformScalingShape::getLocalScaling() const
130 return m_childConvexShape->getLocalScaling();
133 void btUniformScalingShape::setMargin(btScalar margin)
135 m_childConvexShape->setMargin(margin);
137 btScalar btUniformScalingShape::getMargin() const
139 return m_childConvexShape->getMargin() * m_uniformScalingFactor;
142 int btUniformScalingShape::getNumPreferredPenetrationDirections() const
144 return m_childConvexShape->getNumPreferredPenetrationDirections();
147 void btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
149 m_childConvexShape->getPreferredPenetrationDirection(index, penetrationVector);