particleTrimesh1 method
bool
particleTrimesh1(
- Particle si,
- Trimesh sj,
- Vec3 xi,
- Vec3 xj,
- Quaternion qi,
- Quaternion qj,
- Body bi,
- Body bj, [
- Shape? rsi,
- Shape? rsj,
- bool justTest = false,
])
Implementation
bool particleTrimesh1(
Particle si,
Trimesh sj,
Vec3 xi,
Vec3 xj,
Quaternion qi,
Quaternion qj,
Body bi,
Body bj,
[
Shape? rsi,
Shape? rsj,
bool justTest = false
]){
final local = Vec3();
final localAABB = AABB();
final triangles = _sphereTrimeshTriangles;
// Transform ray to local space!
Transform.pointToLocalFrame(xj, qj, xi, local);
localAABB.lowerBound.set(
local.x - 0.1,
local.y - 0.1,
local.z - 0.1
);
localAABB.upperBound.set(
local.x + 0.1,
local.y + 0.1,
local.z + 0.1
);
sj.getTrianglesInAABB(localAABB, triangles);
final va = Vec3();
final vb = Vec3();
final vc = Vec3();
final normal = Vec3();
final relpos = Vec3();
for (int i = 0; i < triangles.length; i++) {
sj.getTriangleVertices(triangles[i], va, vb, vc);
sj.getFaceNormal(triangles[i], normal);
//final normal = Vec3();
//normal.set(0, 0, 1);
//bj.quaternion.vmult(normal, normal); // Turn normal according to plane
xi.vsub(vc, relpos);
final dot = normal.dot(relpos);
if (dot <= 0.0) {
if (justTest) {
return true;
}
final r = createContactEquation(bi, bj, si, sj, rsi, rsj);
r.ni.copy(normal); // Contact normal is the plane normal
r.ni.negate(r.ni);
r.ri.set(0, 0, 0); // Center of particle
// Get particle position projected on plane
final projected = _particlePlaneProjected;
normal.scale(normal.dot(xi), projected);
xi.vsub(projected, projected);
// rj is now the projected world position minus plane position
r.rj.copy(projected);
result.add(r);
createFrictionEquationsFromContact(r, frictionResult);
}
}
triangles.clear();
return false;
}