Blender V2.61 - r43446

btUniformScalingShape.cpp

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #include "btUniformScalingShape.h"
00017 
00018 btUniformScalingShape::btUniformScalingShape(   btConvexShape* convexChildShape,btScalar uniformScalingFactor):
00019 btConvexShape (), m_childConvexShape(convexChildShape),
00020 m_uniformScalingFactor(uniformScalingFactor)
00021 {
00022     m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE;
00023 }
00024     
00025 btUniformScalingShape::~btUniformScalingShape()
00026 {
00027 }
00028     
00029 
00030 btVector3   btUniformScalingShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00031 {
00032     btVector3 tmpVertex;
00033     tmpVertex = m_childConvexShape->localGetSupportingVertexWithoutMargin(vec);
00034     return tmpVertex*m_uniformScalingFactor;
00035 }
00036 
00037 void    btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00038 {
00039     m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors);
00040     int i;
00041     for (i=0;i<numVectors;i++)
00042     {
00043         supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor;
00044     }
00045 }
00046 
00047 
00048 btVector3   btUniformScalingShape::localGetSupportingVertex(const btVector3& vec)const
00049 {
00050     btVector3 tmpVertex;
00051     tmpVertex = m_childConvexShape->localGetSupportingVertex(vec);
00052     return tmpVertex*m_uniformScalingFactor;
00053 }
00054 
00055 
00056 void    btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
00057 {
00058 
00060     btVector3 tmpInertia;
00061     m_childConvexShape->calculateLocalInertia(mass,tmpInertia);
00062     inertia = tmpInertia * m_uniformScalingFactor;
00063 }
00064 
00065 
00067 void btUniformScalingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
00068 {
00069     getAabbSlow(trans,aabbMin,aabbMax);
00070 
00071 }
00072 
00073 void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00074 {
00075 #if 1
00076     btVector3 _directions[] =
00077     {
00078         btVector3( 1.,  0.,  0.),
00079         btVector3( 0.,  1.,  0.),
00080         btVector3( 0.,  0.,  1.),
00081         btVector3( -1., 0.,  0.),
00082         btVector3( 0., -1.,  0.),
00083         btVector3( 0.,  0., -1.)
00084     };
00085     
00086     btVector3 _supporting[] =
00087     {
00088         btVector3( 0., 0., 0.),
00089         btVector3( 0., 0., 0.),
00090         btVector3( 0., 0., 0.),
00091         btVector3( 0., 0., 0.),
00092         btVector3( 0., 0., 0.),
00093         btVector3( 0., 0., 0.)
00094     };
00095 
00096     for (int i=0;i<6;i++)
00097     {
00098         _directions[i] = _directions[i]*t.getBasis();
00099     }
00100     
00101     batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
00102     
00103     btVector3 aabbMin1(0,0,0),aabbMax1(0,0,0);
00104 
00105     for ( int i = 0; i < 3; ++i )
00106     {
00107         aabbMax1[i] = t(_supporting[i])[i];
00108         aabbMin1[i] = t(_supporting[i + 3])[i];
00109     }
00110     btVector3 marginVec(getMargin(),getMargin(),getMargin());
00111     aabbMin = aabbMin1-marginVec;
00112     aabbMax = aabbMax1+marginVec;
00113     
00114 #else
00115 
00116     btScalar margin = getMargin();
00117     for (int i=0;i<3;i++)
00118     {
00119         btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
00120         vec[i] = btScalar(1.);
00121         btVector3 sv = localGetSupportingVertex(vec*t.getBasis());
00122         btVector3 tmp = t(sv);
00123         aabbMax[i] = tmp[i]+margin;
00124         vec[i] = btScalar(-1.);
00125         sv = localGetSupportingVertex(vec*t.getBasis());
00126         tmp = t(sv);
00127         aabbMin[i] = tmp[i]-margin;
00128     }
00129 
00130 #endif
00131 }
00132 
00133 void    btUniformScalingShape::setLocalScaling(const btVector3& scaling) 
00134 {
00135     m_childConvexShape->setLocalScaling(scaling);
00136 }
00137 
00138 const btVector3& btUniformScalingShape::getLocalScaling() const
00139 {
00140     return m_childConvexShape->getLocalScaling();
00141 }
00142 
00143 void    btUniformScalingShape::setMargin(btScalar margin)
00144 {
00145     m_childConvexShape->setMargin(margin);
00146 }
00147 btScalar    btUniformScalingShape::getMargin() const
00148 {
00149     return m_childConvexShape->getMargin() * m_uniformScalingFactor;
00150 }
00151 
00152 int     btUniformScalingShape::getNumPreferredPenetrationDirections() const
00153 {
00154     return m_childConvexShape->getNumPreferredPenetrationDirections();
00155 }
00156     
00157 void    btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
00158 {
00159     m_childConvexShape->getPreferredPenetrationDirection(index,penetrationVector);
00160 }