@@ -125,23 +125,18 @@ bool Camera::IsPointOnView(const Vector3& worldSpaceLocation) const
|
|||||||
Vector3 cameraUp = GetTransform().GetUp();
|
Vector3 cameraUp = GetTransform().GetUp();
|
||||||
Vector3 cameraForward = GetTransform().GetForward();
|
Vector3 cameraForward = GetTransform().GetForward();
|
||||||
Vector3 directionToPosition = (worldSpaceLocation - GetPosition()).GetNormalized();
|
Vector3 directionToPosition = (worldSpaceLocation - GetPosition()).GetNormalized();
|
||||||
|
|
||||||
if (Vector3::Dot(cameraForward, directionToPosition) < 0)
|
if (Vector3::Dot(cameraForward, directionToPosition) < 0)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
Quaternion lookAt = Quaternion::LookRotation(directionToPosition, cameraUp);
|
Quaternion lookAt = Quaternion::LookRotation(directionToPosition, cameraUp);
|
||||||
Vector3 lookAtDirection = lookAt * Vector3::Forward;
|
Vector3 lookAtDirection = lookAt * Vector3::Forward;
|
||||||
Vector3 newWorldLocation = GetPosition() + lookAtDirection;
|
Vector3 newWorldLocation = GetPosition() + lookAtDirection;
|
||||||
|
|
||||||
Float2 windowSpace = Float2();
|
Float2 windowSpace;
|
||||||
Float2 screenSize = GetViewport().Size;
|
const Viewport viewport = GetViewport();
|
||||||
|
ProjectPoint(newWorldLocation, windowSpace, viewport);
|
||||||
|
|
||||||
ProjectPoint(newWorldLocation, windowSpace);
|
return windowSpace.X >= 0 && windowSpace.X <= viewport.Size.X && windowSpace.Y >= 0 && windowSpace.Y <= viewport.Size.Y;
|
||||||
|
|
||||||
return (windowSpace.X >= 0 && windowSpace.X <= screenSize.X) &&
|
|
||||||
(windowSpace.Y >= 0 && windowSpace.Y <= screenSize.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ray Camera::ConvertMouseToRay(const Float2& mousePosition) const
|
Ray Camera::ConvertMouseToRay(const Float2& mousePosition) const
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the 3d point of the world is in the camera's field of view.
|
/// Checks if the 3d point of the world is in the camera's field of view.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="worldSpaceLocation">World Position (XYZ)</param>
|
/// <param name="worldSpaceLocation">World Position (XYZ).</param>
|
||||||
/// <returns>Returns true if the point is within the field of view</returns>
|
/// <returns>Returns true if the point is within the field of view.</returns>
|
||||||
API_FUNCTION() bool IsPointOnView(const Vector3& worldSpaceLocation) const;
|
API_FUNCTION() bool IsPointOnView(const Vector3& worldSpaceLocation) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user