Blender V4.3
btSubSimplexConvexCast.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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
21#include "btPointCollector.h"
23
25 : m_simplexSolver(simplexSolver),
26 m_convexA(convexA),
27 m_convexB(convexB)
28{
29}
30
31
33 const btTransform& fromA,
34 const btTransform& toA,
35 const btTransform& fromB,
36 const btTransform& toB,
37 CastResult& result)
38{
39 m_simplexSolver->reset();
40
41 btVector3 linVelA, linVelB;
42 linVelA = toA.getOrigin() - fromA.getOrigin();
43 linVelB = toB.getOrigin() - fromB.getOrigin();
44
45 btScalar lambda = btScalar(0.);
46
47 btTransform interpolatedTransA = fromA;
48 btTransform interpolatedTransB = fromB;
49
51 btVector3 r = (linVelA - linVelB);
52 btVector3 v;
53
54 btVector3 supVertexA = fromA(m_convexA->localGetSupportingVertex(-r * fromA.getBasis()));
55 btVector3 supVertexB = fromB(m_convexB->localGetSupportingVertex(r * fromB.getBasis()));
56 v = supVertexA - supVertexB;
57 int maxIter = result.m_subSimplexCastMaxIterations;
58
59 btVector3 n;
60 n.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
61
62 btVector3 c;
63
64 btScalar dist2 = v.length2();
65
66
67
68 btVector3 w, p;
69 btScalar VdotR;
70
71 while ((dist2 > result.m_subSimplexCastEpsilon) && maxIter--)
72 {
73 supVertexA = interpolatedTransA(m_convexA->localGetSupportingVertex(-v * interpolatedTransA.getBasis()));
74 supVertexB = interpolatedTransB(m_convexB->localGetSupportingVertex(v * interpolatedTransB.getBasis()));
75 w = supVertexA - supVertexB;
76
77 btScalar VdotW = v.dot(w);
78
79 if (lambda > btScalar(1.0))
80 {
81 return false;
82 }
83
84 if (VdotW > btScalar(0.))
85 {
86 VdotR = v.dot(r);
87
88 if (VdotR >= -(SIMD_EPSILON * SIMD_EPSILON))
89 return false;
90 else
91 {
92 lambda = lambda - VdotW / VdotR;
93 //interpolate to next lambda
94 // x = s + lambda * r;
95 interpolatedTransA.getOrigin().setInterpolate3(fromA.getOrigin(), toA.getOrigin(), lambda);
96 interpolatedTransB.getOrigin().setInterpolate3(fromB.getOrigin(), toB.getOrigin(), lambda);
97 //m_simplexSolver->reset();
98 //check next line
99 w = supVertexA - supVertexB;
100
101 n = v;
102 }
103 }
105 if (!m_simplexSolver->inSimplex(w))
106 m_simplexSolver->addVertex(w, supVertexA, supVertexB);
107
108 if (m_simplexSolver->closest(v))
109 {
110 dist2 = v.length2();
111
112 //todo: check this normal for validity
113 //n=v;
114 //printf("V=%f , %f, %f\n",v[0],v[1],v[2]);
115 //printf("DIST2=%f\n",dist2);
116 //printf("numverts = %i\n",m_simplexSolver->numVertices());
117 }
118 else
119 {
120 dist2 = btScalar(0.);
121 }
122 }
123
124 //int numiter = MAX_ITERATIONS - maxIter;
125 // printf("number of iterations: %d", numiter);
126
127 //don't report a time of impact when moving 'away' from the hitnormal
128
129 result.m_fraction = lambda;
130 if (n.length2() >= (SIMD_EPSILON * SIMD_EPSILON))
131 result.m_normal = n.normalized();
132 else
133 result.m_normal = btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0));
134
135 //don't report time of impact for motion away from the contact normal (or causes minor penetration)
136 if (result.m_normal.dot(r) >= -result.m_allowedPenetration)
137 return false;
138
139 btVector3 hitA, hitB;
140 m_simplexSolver->compute_points(hitA, hitB);
141 result.m_hitPoint = hitB;
142 return true;
143}
ATTR_WARN_UNUSED_RESULT const BMVert * v
btConvexShape()
not supported on IBM SDK, until we fix the alignment of btVector3
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define SIMD_EPSILON
Definition btScalar.h:543
#define btSimplexSolverInterface
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition btVector3.h:82
btSubsimplexConvexCast(const btConvexShape *shapeA, const btConvexShape *shapeB, btSimplexSolverInterface *simplexSolver)
virtual bool calcTimeOfImpact(const btTransform &fromA, const btTransform &toA, const btTransform &fromB, const btTransform &toB, CastResult &result)