I've two code snippets here, the first one produce an error, but the second work. Why?
public static Vector3? GetRayPlaneIntersectionPoint(Ray ray, Plane plane)
{
float? distance = ray.Intersects(plane);
return distance.HasValue ? ray.Position + ray.Direction * distance.Value : null;
}
Give: Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'Microsoft.Xna.Framework.Vector3'
But the following snippet without ternary operator work just fine.
public static Vector3? GetRayPlaneIntersectionPoint(Ray ray, Plane plane)
{
float? distance = ray.Intersects(plane);
if (distance.HasValue)
return ray.Position + ray.Direction * distance.Value;
else
return null;
}