Blender V4.3
btConvexPointCloudShape.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
18
20
21void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
22{
23 m_localScaling = scaling;
25}
26
27#ifndef __SPU__
28btVector3 btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0) const
29{
30 btVector3 supVec(btScalar(0.), btScalar(0.), btScalar(0.));
32
33 btVector3 vec = vec0;
34 btScalar lenSqr = vec.length2();
35 if (lenSqr < btScalar(0.0001))
36 {
37 vec.setValue(1, 0, 0);
38 }
39 else
40 {
41 btScalar rlen = btScalar(1.) / btSqrt(lenSqr);
42 vec *= rlen;
43 }
44
45 if (m_numPoints > 0)
46 {
47 // 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.
48 // btVector3 scaled = vec * m_localScaling;
49 int index = (int)vec.maxDot(&m_unscaledPoints[0], m_numPoints, maxDot); //FIXME: may violate encapsulation of m_unscaledPoints
50 return getScaledPoint(index);
51 }
52
53 return supVec;
54}
55
56void btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
57{
58 for (int j = 0; j < numVectors; j++)
59 {
60 const btVector3& vec = vectors[j] * m_localScaling; // dot( a*c, b) = dot(a, b*c)
62 int index = (int)vec.maxDot(&m_unscaledPoints[0], m_numPoints, maxDot);
63 supportVerticesOut[j][3] = btScalar(-BT_LARGE_FLOAT);
64 if (0 <= index)
65 {
66 //WARNING: don't swap next lines, the w component would get overwritten!
67 supportVerticesOut[j] = getScaledPoint(index);
68 supportVerticesOut[j][3] = maxDot;
69 }
70 }
71}
72
73btVector3 btConvexPointCloudShape::localGetSupportingVertex(const btVector3& vec) const
74{
75 btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
76
77 if (getMargin() != btScalar(0.))
78 {
79 btVector3 vecnorm = vec;
80 if (vecnorm.length2() < (SIMD_EPSILON * SIMD_EPSILON))
81 {
82 vecnorm.setValue(btScalar(-1.), btScalar(-1.), btScalar(-1.));
83 }
84 vecnorm.normalize();
85 supVertex += getMargin() * vecnorm;
86 }
87 return supVertex;
88}
89
90#endif
91
92//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
93//Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
94int btConvexPointCloudShape::getNumVertices() const
95{
96 return m_numPoints;
97}
98
99int btConvexPointCloudShape::getNumEdges() const
100{
101 return 0;
102}
103
104void btConvexPointCloudShape::getEdge(int i, btVector3& pa, btVector3& pb) const
105{
106 btAssert(0);
107}
108
109void btConvexPointCloudShape::getVertex(int i, btVector3& vtx) const
110{
111 vtx = m_unscaledPoints[i] * m_localScaling;
112}
113
114int btConvexPointCloudShape::getNumPlanes() const
115{
116 return 0;
117}
118
119void btConvexPointCloudShape::getPlane(btVector3&, btVector3&, int) const
120{
121 btAssert(0);
122}
123
124//not yet
125bool btConvexPointCloudShape::isInside(const btVector3&, btScalar) const
126{
127 btAssert(0);
128 return false;
129}
SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
btConvexShape Interface
virtual btScalar getMargin() const =0
btVector3 m_localScaling
SIMD_FORCE_INLINE btVector3 getScaledPoint(int i) const
int m_numPoints
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define BT_LARGE_FLOAT
Definition btScalar.h:316
SIMD_FORCE_INLINE btScalar btSqrt(btScalar y)
Definition btScalar.h:466
#define SIMD_EPSILON
Definition btScalar.h:543
#define btAssert(x)
Definition btScalar.h:295
void recalcLocalAabb()
SIMD_FORCE_INLINE long maxDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of maximum dot product between this and vectors in array[]
Definition btVector3.h:998
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int