2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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:
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.
16 #include "btConvexPointCloudShape.h"
17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
19 #include "LinearMath/btQuaternion.h"
21 void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
23 m_localScaling = scaling;
28 btVector3 btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
30 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
31 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
34 btScalar lenSqr = vec.length2();
35 if (lenSqr < btScalar(0.0001))
40 btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
45 for (int i=0;i<m_numPoints;i++)
47 btVector3 vtx = getScaledPoint(i);
49 newDot = vec.dot(vtx);
59 void btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
62 //use 'w' component of supportVerticesOut?
64 for (int i=0;i<numVectors;i++)
66 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
69 for (int i=0;i<m_numPoints;i++)
71 btVector3 vtx = getScaledPoint(i);
73 for (int j=0;j<numVectors;j++)
75 const btVector3& vec = vectors[j];
77 newDot = vec.dot(vtx);
78 if (newDot > supportVerticesOut[j][3])
80 //WARNING: don't swap next lines, the w component would get overwritten!
81 supportVerticesOut[j] = vtx;
82 supportVerticesOut[j][3] = newDot;
93 btVector3 btConvexPointCloudShape::localGetSupportingVertex(const btVector3& vec)const
95 btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
97 if ( getMargin()!=btScalar(0.) )
99 btVector3 vecnorm = vec;
100 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
102 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
105 supVertex+= getMargin() * vecnorm;
118 //currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
119 //Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
120 int btConvexPointCloudShape::getNumVertices() const
125 int btConvexPointCloudShape::getNumEdges() const
130 void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const
135 void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
137 vtx = m_unscaledPoints[i]*m_localScaling;
140 int btConvexPointCloudShape::getNumPlanes() const
145 void btConvexPointCloudShape::getPlane(btVector3& ,btVector3& ,int ) const
152 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const