Blender V2.61 - r43446
|
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 00017 #include "btConvexInternalShape.h" 00018 00019 00020 00021 btConvexInternalShape::btConvexInternalShape() 00022 : m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), 00023 m_collisionMargin(CONVEX_DISTANCE_MARGIN) 00024 { 00025 } 00026 00027 00028 void btConvexInternalShape::setLocalScaling(const btVector3& scaling) 00029 { 00030 m_localScaling = scaling.absolute(); 00031 } 00032 00033 00034 00035 void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const 00036 { 00037 #ifndef __SPU__ 00038 //use localGetSupportingVertexWithoutMargin? 00039 btScalar margin = getMargin(); 00040 for (int i=0;i<3;i++) 00041 { 00042 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); 00043 vec[i] = btScalar(1.); 00044 00045 btVector3 sv = localGetSupportingVertex(vec*trans.getBasis()); 00046 00047 btVector3 tmp = trans(sv); 00048 maxAabb[i] = tmp[i]+margin; 00049 vec[i] = btScalar(-1.); 00050 tmp = trans(localGetSupportingVertex(vec*trans.getBasis())); 00051 minAabb[i] = tmp[i]-margin; 00052 } 00053 #endif 00054 } 00055 00056 00057 00058 btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)const 00059 { 00060 #ifndef __SPU__ 00061 00062 btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec); 00063 00064 if ( getMargin()!=btScalar(0.) ) 00065 { 00066 btVector3 vecnorm = vec; 00067 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON)) 00068 { 00069 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.)); 00070 } 00071 vecnorm.normalize(); 00072 supVertex+= getMargin() * vecnorm; 00073 } 00074 return supVertex; 00075 00076 #else 00077 btAssert(0); 00078 return btVector3(0,0,0); 00079 #endif //__SPU__ 00080 00081 } 00082 00083 00084 btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape() 00085 : btConvexInternalShape(), 00086 m_localAabbMin(1,1,1), 00087 m_localAabbMax(-1,-1,-1), 00088 m_isLocalAabbValid(false) 00089 { 00090 } 00091 00092 00093 void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 00094 { 00095 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 00096 } 00097 00098 void btConvexInternalAabbCachingShape::setLocalScaling(const btVector3& scaling) 00099 { 00100 btConvexInternalShape::setLocalScaling(scaling); 00101 recalcLocalAabb(); 00102 } 00103 00104 00105 void btConvexInternalAabbCachingShape::recalcLocalAabb() 00106 { 00107 m_isLocalAabbValid = true; 00108 00109 #if 1 00110 static const btVector3 _directions[] = 00111 { 00112 btVector3( 1., 0., 0.), 00113 btVector3( 0., 1., 0.), 00114 btVector3( 0., 0., 1.), 00115 btVector3( -1., 0., 0.), 00116 btVector3( 0., -1., 0.), 00117 btVector3( 0., 0., -1.) 00118 }; 00119 00120 btVector3 _supporting[] = 00121 { 00122 btVector3( 0., 0., 0.), 00123 btVector3( 0., 0., 0.), 00124 btVector3( 0., 0., 0.), 00125 btVector3( 0., 0., 0.), 00126 btVector3( 0., 0., 0.), 00127 btVector3( 0., 0., 0.) 00128 }; 00129 00130 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6); 00131 00132 for ( int i = 0; i < 3; ++i ) 00133 { 00134 m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin; 00135 m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin; 00136 } 00137 00138 #else 00139 00140 for (int i=0;i<3;i++) 00141 { 00142 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); 00143 vec[i] = btScalar(1.); 00144 btVector3 tmp = localGetSupportingVertex(vec); 00145 m_localAabbMax[i] = tmp[i]+m_collisionMargin; 00146 vec[i] = btScalar(-1.); 00147 tmp = localGetSupportingVertex(vec); 00148 m_localAabbMin[i] = tmp[i]-m_collisionMargin; 00149 } 00150 #endif 00151 }