capsuleIntersect method

OctreeData? capsuleIntersect(
  1. Capsule capsule
)

Implementation

OctreeData? capsuleIntersect(Capsule capsule) {
  _capsule.copy(capsule);

  List<Triangle> triangles = getCapsuleTriangles(_capsule, []);
  bool hit = false;
  for (int i = 0; i < triangles.length; i++) {
    OctreeData? result = triangleCapsuleIntersect(_capsule, triangles[i]);
    if (result != null) {
      hit = true;
      _capsule.translate(result.normal.multiplyScalar(result.depth));
    }
  }

  if (hit) {
    Vector3 collisionVector = _capsule.getCenter(Vector3()).sub(capsule.getCenter(_v1));
    num depth = collisionVector.length();
    return OctreeData(normal: collisionVector.normalize(), depth: depth);
  }

  return null;
}