planeTrimesh method
bool
planeTrimesh(
- Plane planeShape,
- Trimesh sj,
- Vec3 planePos,
- Vec3 xj,
- Quaternion planeQuat,
- Quaternion qj,
- Body planeBody,
- Body bj, [
- Shape? rsi,
- Shape? rsj,
- bool justTest = false,
])
Implementation
bool planeTrimesh(
Plane planeShape,
Trimesh sj,
Vec3 planePos,
Vec3 xj,
Quaternion planeQuat,
Quaternion qj,
Body planeBody,
Body bj,
[
Shape? rsi,
Shape? rsj,
bool justTest = false
]){
// Make contacts!
final v = Vec3();
final normal = _planeTrimeshNormal;
normal.set(0, 0, 1);
planeQuat.vmult(normal, normal);// Turn normal according to plane
for (int i = 0; i < sj.vertices.length / 3; i++) {
// Get world vertex from trimesh
sj.getVertex(i, v);
// Safe up
final v2 = Vec3();
v2.copy(v);
Transform.pointToWorldFrame(xj, qj, v2, v);
// Check plane side
final relpos = _planeTrimeshRelpos;
v.vsub(planePos, relpos);
final dot = normal.dot(relpos);
if (dot <= 0.0) {
if (justTest) {
return true;
}
final r = createContactEquation(planeBody,bj,planeShape,sj, rsi, rsj);
r.ni.copy(normal); // Contact normal is the plane normal
// Get vertex position projected on plane
final projected = _planeTrimeshProjected;
normal.scale(relpos.dot(normal), projected);
v.vsub(projected, projected);
// ri is the projected world position minus plane position
r.ri.copy(projected);
r.ri.vsub(planeBody.position, r.ri);
r.rj.copy(v);
r.rj.vsub(bj.position, r.rj);
// Store result
result.add(r);
createFrictionEquationsFromContact(r, frictionResult);
}
}
return false;
}