Vector3 ScreenToPlanePos(Camera* camera, const Vector2& screenPos, const Plane& plane)
{
const Vector3 camPos{ camera->GetNode()->GetWorldPosition() };
const float signedDistance{ plane.Distance(camPos) };
const float distance{ Abs(signedDistance) };
const Vector3 normal{ signedDistance > 0.f ? -plane.normal_ : plane.normal_ };
const Vector3 direction{ camera->GetScreenRay(screenPos).direction_ };
const float angle{ direction.Angle(normal) };
const float cos{ Cos(angle) };
return camPos + direction * distance / (cos == 0.f ? M_EPSILON : cos);
}
(result - camPosition).DotProduct(camDirection) > 0.f
or
Plane{ camDirection, camPosition }.Distance(result) > 0.f
…should return true
for positions in front of the camera and false
for values you’d want to ignore.