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 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     if( m_numPoints > 0 )
00045     {
00046         // Here we take advantage of dot(a*b, c) = dot( a, b*c) to do less work. Note this transformation is true mathematically, not numerically.
00047     //    btVector3 scaled = vec * m_localScaling;
00048         int index = (int) vec.maxDot( &m_unscaledPoints[0], m_numPoints, maxDot);   //FIXME: may violate encapsulation of m_unscaledPoints
00049         return getScaledPoint(index);
00050     }
00051 
00052         return supVec;
00053 }
00054 
00055 void    btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00056 {
00057     for( int j = 0; j < numVectors; j++ )
00058     {
00059         const btVector3& vec = vectors[j] * m_localScaling;  // dot( a*c, b) = dot(a, b*c)
00060         btScalar maxDot;
00061         int index = (int) vec.maxDot( &m_unscaledPoints[0], m_numPoints, maxDot);
00062         supportVerticesOut[j][3] = btScalar(-BT_LARGE_FLOAT);
00063         if( 0 <= index )
00064         {
00065             //WARNING: don't swap next lines, the w component would get overwritten!
00066             supportVerticesOut[j] = getScaledPoint(index);
00067             supportVerticesOut[j][3] = maxDot;
00068         }
00069     }
00070 
00071 }
00072         
00073 
00074 
00075 btVector3       btConvexPointCloudShape::localGetSupportingVertex(const btVector3& vec)const
00076 {
00077         btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
00078 
00079         if ( getMargin()!=btScalar(0.) )
00080         {
00081                 btVector3 vecnorm = vec;
00082                 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
00083                 {
00084                         vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
00085                 } 
00086                 vecnorm.normalize();
00087                 supVertex+= getMargin() * vecnorm;
00088         }
00089         return supVertex;
00090 }
00091 
00092 
00093 #endif
00094 
00095 
00096 
00097 
00098 
00099 
00100 //currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
00101 //Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
00102 int     btConvexPointCloudShape::getNumVertices() const
00103 {
00104         return m_numPoints;
00105 }
00106 
00107 int btConvexPointCloudShape::getNumEdges() const
00108 {
00109         return 0;
00110 }
00111 
00112 void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const
00113 {
00114         btAssert (0);
00115 }
00116 
00117 void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
00118 {
00119         vtx = m_unscaledPoints[i]*m_localScaling;
00120 }
00121 
00122 int     btConvexPointCloudShape::getNumPlanes() const
00123 {
00124         return 0;
00125 }
00126 
00127 void btConvexPointCloudShape::getPlane(btVector3& ,btVector3& ,int ) const
00128 {
00129 
00130         btAssert(0);
00131 }
00132 
00133 //not yet
00134 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const
00135 {
00136         btAssert(0);
00137         return false;
00138 }
00139