18 template <
typename Real>
51 void SetMaxLCPIterations(
int maxLCPIterations);
57 std::unique_ptr<LCPSolver<Real>>
mLCP;
61 template <
typename Real>
66 int const n = numTriangles + 3;
67 mLCP = std::make_unique<LCPSolver<Real>>(
n);
68 mMaxLCPIterations = mLCP->GetMaxIterations();
72 mMaxLCPIterations = 0;
76 template <
typename Real>
79 mMaxLCPIterations = maxLCPIterations;
82 mLCP->SetMaxIterations(mMaxLCPIterations);
86 template <
typename Real>
93 int const numTriangles =
static_cast<int>(polyhedron.planes.size());
94 if (numTriangles == 0)
97 result.queryIsSuccessful =
false;
98 for (
int i = 0; i < 3; ++i)
100 result.closestPoint[0][i] = (Real)0;
101 result.closestPoint[1][i] = (Real)0;
103 result.distance = (Real)0;
104 result.sqrDistance = (Real)0;
105 result.numLCPIterations = 0;
109 int const n = numTriangles + 3;
116 std::vector<Real>
q(n);
117 for (
int r = 0;
r < 3; ++
r)
119 q[
r] = polyhedron.alignedBox.min[
r] - point[
r];
121 for (
int r = 3,
t = 0;
r <
n; ++
r, ++
t)
123 q[
r] = -
Dot(polyhedron.planes[
t], hmin);
126 std::vector<Real> M(n * n);
127 M[0] = (Real)1; M[1] = (Real)0; M[2] = (Real)0;
128 M[
n] = (Real)0; M[n + 1] = (Real)1; M[n + 2] = (Real)0;
129 M[2 *
n] = (Real)0; M[2 * n + 1] = (Real)0; M[2 * n + 2] = (Real)1;
130 for (
int t = 0,
c = 3;
t < numTriangles; ++
t, ++
c)
133 for (
int r = 0;
r < 3; ++
r)
135 M[
c + n *
r] = normal[
r];
136 M[
r + n *
c] = -normal[
r];
139 for (
int r = 3;
r <
n; ++
r)
141 for (
int c = 3;
c <
n; ++
c)
143 M[
c + n *
r] = (Real)0;
147 bool needsLCP = (mLCP ==
nullptr);
150 mLCP = std::make_unique<LCPSolver<Real>>(
n);
151 if (mMaxLCPIterations > 0)
153 mLCP->SetMaxIterations(mMaxLCPIterations);
157 std::vector<Real>
w(n),
z(n);
158 if (mLCP->Solve(q, M,
w, z))
160 result.queryIsSuccessful =
true;
161 result.closestPoint[0] = point;
162 for (
int i = 0; i < 3; ++i)
164 result.closestPoint[1][i] = z[i] + polyhedron.alignedBox.min[i];
167 Vector3<Real> diff = result.closestPoint[1] - result.closestPoint[0];
168 result.sqrDistance =
Dot(diff, diff);
177 result.queryIsSuccessful =
false;
180 result.numLCPIterations = mLCP->GetNumIterations();
GLsizei GLsizei GLfloat distance
static Real Sqrt(Real const &x)
GLubyte GLubyte GLubyte GLubyte w
GVector< Real > HLift(GVector< Real > const &v, Real last)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
std::unique_ptr< LCPSolver< Real > > mLCP
GVector< Real > HProject(GVector< Real > const &v)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLdouble GLdouble GLdouble z
GLdouble GLdouble GLdouble GLdouble q