Add Camera.UnprojectPoint method
This commit is contained in:
@@ -151,6 +151,20 @@ void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Float2& cameraViewp
|
||||
cameraViewportSpaceLocation = Float2(clipSpaceLocation);
|
||||
}
|
||||
|
||||
void Camera::UnprojectPoint(const Float2& gameWindowSpaceLocation, float depth, Vector3& worldSpaceLocation) const
|
||||
{
|
||||
UnprojectPoint(gameWindowSpaceLocation, depth, worldSpaceLocation, GetViewport());
|
||||
}
|
||||
|
||||
void Camera::UnprojectPoint(const Float2& cameraViewportSpaceLocation, float depth, Vector3& worldSpaceLocation, const Viewport& viewport) const
|
||||
{
|
||||
Matrix v, p, ivp;
|
||||
GetMatrices(v, p, viewport);
|
||||
Matrix::Multiply(v, p, ivp);
|
||||
ivp.Invert();
|
||||
viewport.Unproject(Vector3(cameraViewportSpaceLocation, depth), ivp, worldSpaceLocation);
|
||||
}
|
||||
|
||||
bool Camera::IsPointOnView(const Vector3& worldSpaceLocation) const
|
||||
{
|
||||
Vector3 cameraUp = GetTransform().GetUp();
|
||||
|
||||
@@ -150,6 +150,23 @@ 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>
|
||||
/// Converts a game window-space point into a corresponding point in world space.
|
||||
/// </summary>
|
||||
/// <param name="gameWindowSpaceLocation">The input game window coordinates (XY in screen pixels).</param>
|
||||
/// <param name="depth">The input camera-relative depth position (eg. clipping plane).</param>
|
||||
/// <param name="worldSpaceLocation">The output world-space location (XYZ in world).</param>
|
||||
API_FUNCTION() void UnprojectPoint(const Float2& gameWindowSpaceLocation, float depth, API_PARAM(Out) Vector3& worldSpaceLocation) const;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a camera viewport-space point into a corresponding point in world space.
|
||||
/// </summary>
|
||||
/// <param name="cameraViewportSpaceLocation">The input camera viewport-space location (XY in screen pixels).</param>
|
||||
/// <param name="depth">The input camera-relative depth position (eg. clipping plane).</param>
|
||||
/// <param name="worldSpaceLocation">The output world-space location (XYZ in world).</param>
|
||||
/// <param name="viewport">The viewport.</param>
|
||||
API_FUNCTION() void UnprojectPoint(const Float2& cameraViewportSpaceLocation, float depth, API_PARAM(Out) Vector3& worldSpaceLocation, 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>
|
||||
|
||||
Reference in New Issue
Block a user