Merge branch 'master' of https://github.com/RuanLucasGD/FlaxEngine into RuanLucasGD-master
This commit is contained in:
@@ -120,6 +120,30 @@ void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Float2& cameraViewp
|
||||
cameraViewportSpaceLocation = Float2(clipSpaceLocation);
|
||||
}
|
||||
|
||||
bool Camera::IsPointOnView(const Vector3& worldSpaceLocation) const
|
||||
{
|
||||
Vector3 cameraUp = GetTransform().GetUp();
|
||||
Vector3 cameraForward = GetTransform().GetForward();
|
||||
Vector3 directionToPosition = (worldSpaceLocation - GetPosition()).GetNormalized();
|
||||
|
||||
if (Vector3::Dot(cameraForward, directionToPosition) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Quaternion lookAt = Quaternion::LookRotation(directionToPosition, cameraUp);
|
||||
Vector3 lookAtDirection = lookAt * Vector3::Forward;
|
||||
Vector3 newWorldLocation = GetPosition() + lookAtDirection;
|
||||
|
||||
Float2 windowSpace = Float2();
|
||||
Float2 screenSize = GetViewport().Size;
|
||||
|
||||
ProjectPoint(newWorldLocation, windowSpace);
|
||||
|
||||
return (windowSpace.X >= 0 && windowSpace.X <= screenSize.X) &&
|
||||
(windowSpace.Y >= 0 && windowSpace.Y <= screenSize.Y);
|
||||
}
|
||||
|
||||
Ray Camera::ConvertMouseToRay(const Float2& mousePosition) const
|
||||
{
|
||||
return ConvertMouseToRay(mousePosition, GetViewport());
|
||||
|
||||
@@ -168,6 +168,13 @@ public:
|
||||
/// <param name="viewport">The viewport.</param>
|
||||
API_FUNCTION() void ProjectPoint(const Vector3& worldSpaceLocation, API_PARAM(Out) Float2& cameraViewportSpaceLocation, API_PARAM(Ref) const Viewport& viewport) const;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the 3d point of the world is in the camera's field of view.
|
||||
/// </summary>
|
||||
/// <param name="worldSpaceLocation">World Position (XYZ)</param>
|
||||
/// <returns>Returns true if the point is within the field of view</returns>
|
||||
API_FUNCTION() bool IsPointOnView(const Vector3& worldSpaceLocation) const;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the mouse position to 3D ray.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user