makePlaneReflection function

Matrix4 makePlaneReflection(
  1. Vector3 planeNormal,
  2. Vector3 planePoint
)

Returns a transformation matrix that transforms points by reflecting them through the plane specified with planeNormal and planePoint.

Implementation

Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
  final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
      planeNormal.storage[2], 0.0);
  final outer = Matrix4.outer(v, v)..scale(2.0);
  var r = Matrix4.zero();
  r = r - outer;
  final scale = 2.0 * planePoint.dot(planeNormal);
  final scaledNormal = planeNormal.scaled(scale);
  final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
      scaledNormal.storage[2], 1.0);
  r.setColumn(3, T);
  return r;
}