20 template <
typename Real>
42 void SetMaxLCPIterations(
int maxLCPIterations);
51 template <
typename Real>
54 mLCP.SetMaxIterations(maxLCPIterations);
57 template <
typename Real>
71 for (
int i = 0; i < 3; ++i)
73 V[i] =
Dot(box.axis[i], tempV) + box.extent[i];
74 E0[i] =
Dot(box.axis[i], tempE0);
75 E1[i] =
Dot(box.axis[i], tempE1);
79 Real dotVE0 =
Dot(V, E0);
80 Real dotVE1 =
Dot(V, E1);
81 Real dotE0E0 =
Dot(E0, E0);
82 Real dotE0E1 =
Dot(E0, E1);
83 Real dotE1E1 =
Dot(E1, E1);
86 std::array<Real, 9>
q =
88 -V[0], -V[1], -V[2], dotVE0, dotVE1, K[0], K[1], K[2], (Real)1
91 std::array<std::array<Real, 9>, 9> M;
92 M[0] = { (Real)1, (Real)0, (Real)0, -E0[0], -E1[0], (Real)1, (Real)0, (Real)0, (Real)0 };
93 M[1] = { (Real)0, (Real)1, (Real)0, -E0[1], -E1[1], (Real)0, (Real)1, (Real)0, (Real)0 };
94 M[2] = { (Real)0, (Real)0, (Real)1, -E0[2], -E1[2], (Real)0, (Real)0, (Real)1, (Real)0 };
95 M[3] = { -E0[0], -E0[1], -E0[2], dotE0E0, dotE0E1, (Real)0, (Real)0, (Real)0, (Real)1 };
96 M[4] = { -E1[0], -E1[1], -E1[2], dotE0E1, dotE1E1, (Real)0, (Real)0, (Real)0, (Real)1 };
97 M[5] = { (Real)-1, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0 };
98 M[6] = { (Real)0, (Real)-1, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0 };
99 M[7] = { (Real)0, (Real)0, (Real)-1, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0, (Real)0 };
100 M[8] = { (Real)0, (Real)0, (Real)0, (Real)-1, (Real)-1, (Real)0, (Real)0, (Real)0, (Real)0 };
102 std::array<Real, 9>
w,
z;
103 if (mLCP.Solve(q, M, w, z))
105 result.queryIsSuccessful =
true;
107 result.triangleParameter[0] = (Real)1 - z[3] - z[4];
108 result.triangleParameter[1] = z[3];
109 result.triangleParameter[2] = z[4];
110 result.closestPoint[0] = triangle.v[0] + z[3] * tempE0 + z[4] * tempE1;
111 result.closestPoint[1] = box.center;
112 for (
int i = 0; i < 3; ++i)
114 result.boxParameter[i] = z[i] - box.extent[i];
115 result.closestPoint[1] += result.boxParameter[i] * box.axis[i];
118 Vector3<Real> diff = result.closestPoint[1] - result.closestPoint[0];
119 result.sqrDistance =
Dot(diff, diff);
128 result.queryIsSuccessful =
false;
130 for (
int i = 0; i < 3; ++i)
132 result.triangleParameter[i] = (Real)0;
133 result.boxParameter[i] = (Real)0;
134 result.closestPoint[0][i] = (Real)0;
135 result.closestPoint[1][i] = (Real)0;
137 result.distance = (Real)0;
138 result.sqrDistance = (Real)0;
141 result.numLCPIterations = mLCP.GetNumIterations();
GLsizei GLsizei GLfloat distance
static Real Sqrt(Real const &x)
GLubyte GLubyte GLubyte GLubyte w
std::array< Real, 3 > triangleParameter
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, 9 > mLCP