Blender V2.61 - r43446

btConvexPointCloudShape.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 "btConvexPointCloudShape.h"
00017 #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
00018 
00019 #include "LinearMath/btQuaternion.h"
00020 
00021 void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
00022 {
00023     m_localScaling = scaling;
00024     recalcLocalAabb();
00025 }
00026 
00027 #ifndef __SPU__
00028 btVector3   btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
00029 {
00030     btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
00031     btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
00032 
00033     btVector3 vec = vec0;
00034     btScalar lenSqr = vec.length2();
00035     if (lenSqr < btScalar(0.0001))
00036     {
00037         vec.setValue(1,0,0);
00038     } else
00039     {
00040         btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
00041         vec *= rlen;
00042     }
00043 
00044 
00045     for (int i=0;i<m_numPoints;i++)
00046     {
00047         btVector3 vtx = getScaledPoint(i);
00048 
00049         newDot = vec.dot(vtx);
00050         if (newDot > maxDot)
00051         {
00052             maxDot = newDot;
00053             supVec = vtx;
00054         }
00055     }
00056     return supVec;
00057 }
00058 
00059 void    btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00060 {
00061     btScalar newDot;
00062     //use 'w' component of supportVerticesOut?
00063     {
00064         for (int i=0;i<numVectors;i++)
00065         {
00066             supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
00067         }
00068     }
00069     for (int i=0;i<m_numPoints;i++)
00070     {
00071         btVector3 vtx = getScaledPoint(i);
00072 
00073         for (int j=0;j<numVectors;j++)
00074         {
00075             const btVector3& vec = vectors[j];
00076             
00077             newDot = vec.dot(vtx);
00078             if (newDot > supportVerticesOut[j][3])
00079             {
00080                 //WARNING: don't swap next lines, the w component would get overwritten!
00081                 supportVerticesOut[j] = vtx;
00082                 supportVerticesOut[j][3] = newDot;
00083             }
00084         }
00085     }
00086 
00087 
00088 
00089 }
00090     
00091 
00092 
00093 btVector3   btConvexPointCloudShape::localGetSupportingVertex(const btVector3& vec)const
00094 {
00095     btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
00096 
00097     if ( getMargin()!=btScalar(0.) )
00098     {
00099         btVector3 vecnorm = vec;
00100         if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
00101         {
00102             vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
00103         } 
00104         vecnorm.normalize();
00105         supVertex+= getMargin() * vecnorm;
00106     }
00107     return supVertex;
00108 }
00109 
00110 
00111 #endif
00112 
00113 
00114 
00115 
00116 
00117 
00118 //currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
00119 //Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
00120 int btConvexPointCloudShape::getNumVertices() const
00121 {
00122     return m_numPoints;
00123 }
00124 
00125 int btConvexPointCloudShape::getNumEdges() const
00126 {
00127     return 0;
00128 }
00129 
00130 void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const
00131 {
00132     btAssert (0);
00133 }
00134 
00135 void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
00136 {
00137     vtx = m_unscaledPoints[i]*m_localScaling;
00138 }
00139 
00140 int btConvexPointCloudShape::getNumPlanes() const
00141 {
00142     return 0;
00143 }
00144 
00145 void btConvexPointCloudShape::getPlane(btVector3& ,btVector3& ,int ) const
00146 {
00147 
00148     btAssert(0);
00149 }
00150 
00151 //not yet
00152 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const
00153 {
00154     btAssert(0);
00155     return false;
00156 }
00157