| [1963] | 1 | /* | 
|---|
|  | 2 | Bullet Continuous Collision Detection and Physics Library | 
|---|
|  | 3 | Copyright (c) 2003-2007 Erwin Coumans  http://continuousphysics.com/Bullet/ | 
|---|
|  | 4 |  | 
|---|
|  | 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: | 
|---|
|  | 10 |  | 
|---|
|  | 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. | 
|---|
|  | 14 | */ | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include "btUniformScalingShape.h" | 
|---|
|  | 17 |  | 
|---|
|  | 18 | btUniformScalingShape::btUniformScalingShape(   btConvexShape* convexChildShape,btScalar uniformScalingFactor): | 
|---|
|  | 19 | btConvexShape (), m_childConvexShape(convexChildShape), | 
|---|
|  | 20 | m_uniformScalingFactor(uniformScalingFactor) | 
|---|
|  | 21 | { | 
|---|
|  | 22 | m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE; | 
|---|
|  | 23 | } | 
|---|
|  | 24 |  | 
|---|
|  | 25 | btUniformScalingShape::~btUniformScalingShape() | 
|---|
|  | 26 | { | 
|---|
|  | 27 | } | 
|---|
|  | 28 |  | 
|---|
|  | 29 |  | 
|---|
|  | 30 | btVector3       btUniformScalingShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const | 
|---|
|  | 31 | { | 
|---|
|  | 32 | btVector3 tmpVertex; | 
|---|
|  | 33 | tmpVertex = m_childConvexShape->localGetSupportingVertexWithoutMargin(vec); | 
|---|
|  | 34 | return tmpVertex*m_uniformScalingFactor; | 
|---|
|  | 35 | } | 
|---|
|  | 36 |  | 
|---|
|  | 37 | void    btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const | 
|---|
|  | 38 | { | 
|---|
|  | 39 | m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors); | 
|---|
|  | 40 | int i; | 
|---|
|  | 41 | for (i=0;i<numVectors;i++) | 
|---|
|  | 42 | { | 
|---|
|  | 43 | supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor; | 
|---|
|  | 44 | } | 
|---|
|  | 45 | } | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
|  | 48 | btVector3       btUniformScalingShape::localGetSupportingVertex(const btVector3& vec)const | 
|---|
|  | 49 | { | 
|---|
|  | 50 | btVector3 tmpVertex; | 
|---|
|  | 51 | tmpVertex = m_childConvexShape->localGetSupportingVertex(vec); | 
|---|
|  | 52 | return tmpVertex*m_uniformScalingFactor; | 
|---|
|  | 53 | } | 
|---|
|  | 54 |  | 
|---|
|  | 55 |  | 
|---|
|  | 56 | void    btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const | 
|---|
|  | 57 | { | 
|---|
|  | 58 |  | 
|---|
|  | 59 | ///this linear upscaling is not realistic, but we don't deal with large mass ratios... | 
|---|
|  | 60 | btVector3 tmpInertia; | 
|---|
|  | 61 | m_childConvexShape->calculateLocalInertia(mass,tmpInertia); | 
|---|
|  | 62 | inertia = tmpInertia * m_uniformScalingFactor; | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 |  | 
|---|
|  | 66 | ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version | 
|---|
|  | 67 | void btUniformScalingShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const | 
|---|
|  | 68 | { | 
|---|
|  | 69 | m_childConvexShape->getAabb(t,aabbMin,aabbMax); | 
|---|
|  | 70 | btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5); | 
|---|
|  | 71 | btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor; | 
|---|
|  | 72 |  | 
|---|
|  | 73 | aabbMin = aabbCenter - scaledAabbHalfExtends; | 
|---|
|  | 74 | aabbMax = aabbCenter + scaledAabbHalfExtends; | 
|---|
|  | 75 |  | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
|  | 78 | void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const | 
|---|
|  | 79 | { | 
|---|
|  | 80 | m_childConvexShape->getAabbSlow(t,aabbMin,aabbMax); | 
|---|
|  | 81 | btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5); | 
|---|
|  | 82 | btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor; | 
|---|
|  | 83 |  | 
|---|
|  | 84 | aabbMin = aabbCenter - scaledAabbHalfExtends; | 
|---|
|  | 85 | aabbMax = aabbCenter + scaledAabbHalfExtends; | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | void    btUniformScalingShape::setLocalScaling(const btVector3& scaling) | 
|---|
|  | 89 | { | 
|---|
|  | 90 | m_childConvexShape->setLocalScaling(scaling); | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | const btVector3& btUniformScalingShape::getLocalScaling() const | 
|---|
|  | 94 | { | 
|---|
|  | 95 | return m_childConvexShape->getLocalScaling(); | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | void    btUniformScalingShape::setMargin(btScalar margin) | 
|---|
|  | 99 | { | 
|---|
|  | 100 | m_childConvexShape->setMargin(margin); | 
|---|
|  | 101 | } | 
|---|
|  | 102 | btScalar        btUniformScalingShape::getMargin() const | 
|---|
|  | 103 | { | 
|---|
|  | 104 | return m_childConvexShape->getMargin() * m_uniformScalingFactor; | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | int             btUniformScalingShape::getNumPreferredPenetrationDirections() const | 
|---|
|  | 108 | { | 
|---|
|  | 109 | return m_childConvexShape->getNumPreferredPenetrationDirections(); | 
|---|
|  | 110 | } | 
|---|
|  | 111 |  | 
|---|
|  | 112 | void    btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const | 
|---|
|  | 113 | { | 
|---|
|  | 114 | m_childConvexShape->getPreferredPenetrationDirection(index,penetrationVector); | 
|---|
|  | 115 | } | 
|---|