projectToNdc method

Vector3 projectToNdc(
  1. Vector3 eyePosition, {
  2. double aspect = 1.0,
})

Projects an eye-space point to NDC.

The only honest way to assert what a projection actually does, which is why it lives on the abstraction rather than in test-only code.

Implementation

Vector3 projectToNdc(Vector3 eyePosition, {double aspect = 1.0}) {
  final clip = toMatrix(
    ProjectionRequest(aspect: aspect),
  ).transform(Vector4(eyePosition.x, eyePosition.y, eyePosition.z, 1.0));
  if (clip.w == 0.0) {
    throw ArgumentError('Point projects onto the camera plane (w == 0).');
  }
  return Vector3(clip.x / clip.w, clip.y / clip.w, clip.z / clip.w);
}