19 template <
typename Real>
41 void SetMaxLCPIterations(
int maxLCPIterations);
50 template <
typename Real>
53 mLCP.SetMaxIterations(maxLCPIterations);
56 template <
typename Real>
66 for (
int i = 0; i < 3; ++i)
68 delta += box0.extent[i] * box0.axis[i];
69 delta -= box1.extent[i] * box1.axis[i];
73 for (
int i = 0; i < 3; ++i)
75 R0Delta[i] =
Dot(box0.axis[i], delta);
76 R1Delta[i] =
Dot(box1.axis[i], delta);
79 std::array<std::array<Real, 3>, 3> R0TR1;
80 for (
int r = 0;
r < 3; ++
r)
82 for (
int c = 0;
c < 3; ++
c)
84 R0TR1[
r][
c] =
Dot(box0.axis[
r], box1.axis[
c]);
92 std::array<Real, 12>
q =
94 -R0Delta[0], -R0Delta[1], -R0Delta[2], R1Delta[0], R1Delta[1], R1Delta[2],
95 twoExtent0[0], twoExtent0[1], twoExtent0[2], twoExtent1[0], twoExtent1[1], twoExtent1[2]
98 std::array<std::array<Real, 12>, 12> M;
100 Real
const z = (Real)0;
101 Real
const p = (Real)1;
102 Real
const m = (Real)-1;
103 M[ 0] = {
p,
z,
z, -R0TR1[0][0], -R0TR1[0][1], -R0TR1[0][2],
p,
z,
z,
z,
z, z };
104 M[ 1] = {
z,
p,
z, -R0TR1[1][0], -R0TR1[1][1], -R0TR1[1][2],
z,
p,
z,
z,
z, z };
105 M[ 2] = {
z,
z,
p, -R0TR1[2][0], -R0TR1[2][1], -R0TR1[2][2],
z,
z,
p,
z,
z, z };
106 M[ 3] = { -R0TR1[0][0], -R0TR1[1][0], -R0TR1[2][0],
p,
z,
z,
z,
z,
z,
p,
z, z };
107 M[ 4] = { -R0TR1[0][1], -R0TR1[1][1], -R0TR1[2][1],
z,
p,
z,
z,
z,
z,
z,
p, z };
108 M[ 5] = { -R0TR1[0][2], -R0TR1[1][2], -R0TR1[2][2],
z,
z,
p,
z,
z,
z,
z,
z, p };
109 M[ 6] = {
m,
z,
z,
z,
z,
z,
z,
z,
z,
z,
z, z };
110 M[ 7] = {
z,
m,
z,
z,
z,
z,
z,
z,
z,
z,
z, z };
111 M[ 8] = {
z,
z,
m,
z,
z,
z,
z,
z,
z,
z,
z, z };
112 M[ 9] = {
z,
z,
z,
m,
z,
z,
z,
z,
z,
z,
z, z };
113 M[10] = {
z,
z,
z,
z,
m,
z,
z,
z,
z,
z,
z, z };
114 M[11] = {
z,
z,
z,
z,
z,
m,
z,
z,
z,
z,
z, z };
117 std::array<Real, 12>
w,
z;
118 if (mLCP.Solve(q, M, w, z))
120 result.queryIsSuccessful =
true;
122 result.closestPoint[0] = box0.center;
123 for (
int i = 0; i < 3; ++i)
125 result.box0Parameter[i] = z[i] - box0.extent[i];
126 result.closestPoint[0] += result.box0Parameter[i] * box0.axis[i];
129 result.closestPoint[1] = box1.center;
130 for (
int i = 0, j = 3; i < 3; ++i, ++j)
132 result.box1Parameter[i] = z[j] - box1.extent[i];
133 result.closestPoint[1] += result.box1Parameter[i] * box1.axis[i];
136 Vector3<Real> diff = result.closestPoint[1] - result.closestPoint[0];
137 result.sqrDistance =
Dot(diff, diff);
146 result.queryIsSuccessful =
false;
148 for (
int i = 0; i < 3; ++i)
150 result.box0Parameter[i] = (Real)0;
151 result.box1Parameter[i] = (Real)0;
152 result.closestPoint[0][i] = (Real)0;
153 result.closestPoint[1][i] = (Real)0;
155 result.distance = (Real)0;
156 result.sqrDistance = (Real)0;
159 result.numLCPIterations = mLCP.GetNumIterations();
std::array< Real, 3 > box1Parameter
GLsizei GLsizei GLfloat distance
static Real Sqrt(Real const &x)
GLubyte GLubyte GLubyte GLubyte w
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLdouble GLdouble GLdouble z
GLdouble GLdouble GLdouble GLdouble q
LCPSolver< Real, 12 > mLCP