Add an Orthogonal Projection option to the Camera Gem (#2414)
* Add an Orthogonal Projection option to the Camera Gem This adds a check-box to opt into an ortho projection along with a half-width parameter to adjust the size of the visible area. Includes some light tweaks to ensure debug rendering looks OK and that we generate a correct camera state for these non-perspective views. Known issue: while in "Be this camera" mode in the Editor using an ortho projection manipulators aren't working correctly. This appears to be a downstream issue with CameraState consumers not actually checking the ortho flag. Signed-off-by: nvsickle <nvsickle@amazon.com> * Fix some typos Signed-off-by: nvsickle <nvsickle@amazon.com> * Account for reversed depth buffer Signed-off-by: nvsickle <nvsickle@amazon.com> * Clarify depth reversal for MakeOrthographicMatrixRH Signed-off-by: nvsickle <nvsickle@amazon.com>
This commit is contained in:
committed by
GitHub
parent
e81f59d1e1
commit
7f84a4318c
@@ -463,7 +463,7 @@ void EditorViewportWidget::Update()
|
||||
|
||||
if (m_updateCameraPositionNextTick)
|
||||
{
|
||||
auto cameraState = m_renderViewport->GetCameraState();
|
||||
auto cameraState = GetCameraState();
|
||||
AZ::Matrix3x4 matrix;
|
||||
matrix.SetBasisAndTranslation(cameraState.m_side, cameraState.m_forward, cameraState.m_up, cameraState.m_position);
|
||||
auto m = AZMatrix3x4ToLYMatrix3x4(matrix);
|
||||
@@ -1138,6 +1138,17 @@ void EditorViewportWidget::OnMenuSelectCurrentCamera()
|
||||
|
||||
AzFramework::CameraState EditorViewportWidget::GetCameraState()
|
||||
{
|
||||
if (m_viewEntityId.IsValid())
|
||||
{
|
||||
bool cameraStateAcquired = false;
|
||||
AzFramework::CameraState cameraState;
|
||||
Camera::EditorCameraViewRequestBus::BroadcastResult(cameraStateAcquired,
|
||||
&Camera::EditorCameraViewRequestBus::Events::GetCameraState, cameraState);
|
||||
if (cameraStateAcquired)
|
||||
{
|
||||
return cameraState;
|
||||
}
|
||||
}
|
||||
return m_renderViewport->GetCameraState();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace AZ
|
||||
return &out;
|
||||
}
|
||||
|
||||
Matrix4x4* MakeOrthographicMatrixRH(Matrix4x4& out, float left, float right, float bottom, float top, float nearDist, float farDist)
|
||||
Matrix4x4* MakeOrthographicMatrixRH(Matrix4x4& out, float left, float right, float bottom, float top, float nearDist, float farDist, bool reverseDepth)
|
||||
{
|
||||
AZ_Assert(right > left, "right should be greater than left");
|
||||
// valid to have matrix invert top/bottom and far/near
|
||||
@@ -83,6 +83,11 @@ namespace AZ
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (reverseDepth)
|
||||
{
|
||||
AZStd::swap(nearDist, farDist);
|
||||
}
|
||||
|
||||
out.SetRow(0, 2.f/(right - left), 0.f, 0.f, - (right + left) / (right - left) );
|
||||
out.SetRow(1, 0.f, 2.f / (top - bottom), 0.f, - (top + bottom) / (top - bottom) );
|
||||
out.SetRow(2, 0.f, 0.f, 1 / (nearDist - farDist), nearDist / (nearDist - farDist) );
|
||||
|
||||
@@ -57,8 +57,9 @@ namespace AZ
|
||||
//! @param top The y coordinate of top view-plane
|
||||
//! @param near Distance to the near view-plane. Must be no less than zero.
|
||||
//! @param far Distance to the far view-plane. Must be greater than zero.
|
||||
//! @param reverseDepth Set to true to reverse depth which means near distance maps to 1 and far distance maps to 0.
|
||||
//! @return Pointer of the output matrix
|
||||
Matrix4x4* MakeOrthographicMatrixRH(Matrix4x4& out, float left, float right, float bottom, float top, float nearDist, float farDist);
|
||||
Matrix4x4* MakeOrthographicMatrixRH(Matrix4x4& out, float left, float right, float bottom, float top, float nearDist, float farDist, bool reverseDepth = false);
|
||||
|
||||
//! Transforms a position by a matrix. This function can be used with any generic cases which include projection matrices.
|
||||
Vector3 MatrixTransformPosition(const Matrix4x4& matrix, const Vector3& inPosition);
|
||||
|
||||
@@ -63,6 +63,13 @@ namespace Camera
|
||||
//! @return The camera frustum's height
|
||||
virtual float GetFrustumHeight() = 0;
|
||||
|
||||
//! Gets whether or not the camera is using an orthographic projection.
|
||||
//! @return True if the camera is using an orthographic projection, or false if the camera is using a perspective projection.
|
||||
virtual bool IsOrthographic() = 0;
|
||||
|
||||
//! @return The half width of the orthographic projection, @see SetOrthographicHalfWidth.
|
||||
virtual float GetOrthographicHalfWidth() = 0;
|
||||
|
||||
//! Sets the camera's field of view in degrees between 0 < fov < 180 degrees
|
||||
//! @param fov The camera frustum's new field of view in degrees
|
||||
virtual void SetFov(float fov)
|
||||
@@ -95,6 +102,15 @@ namespace Camera
|
||||
//! @param height The camera frustum's new height
|
||||
virtual void SetFrustumHeight(float height) = 0;
|
||||
|
||||
//! Sets whether or not the camera should use an orthographic projection in place of a perspective projection.
|
||||
//! @param orthographic If true, the camera will use an orthographic projection
|
||||
virtual void SetOrthographic(bool orthographic) = 0;
|
||||
|
||||
//! Sets the half-width of the orthographic projection.
|
||||
//! @params halfWidth Used to calculate the bounds of the projection while in orthographic mode.
|
||||
//! The height is calculated automatically based on the aspect ratio.
|
||||
virtual void SetOrthographicHalfWidth(float halfWidth) = 0;
|
||||
|
||||
//! Makes the camera the active view
|
||||
virtual void MakeActiveView() = 0;
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Camera
|
||||
using EditorCameraNotificationBus = AZ::EBus<EditorCameraNotifications>;
|
||||
|
||||
/**
|
||||
* This bus is for requesting any camera-view-related changes
|
||||
* This bus is for requesting any camera-view-related changes or information
|
||||
*/
|
||||
class EditorCameraViewRequests : public AZ::ComponentBus
|
||||
{
|
||||
@@ -115,6 +115,11 @@ namespace Camera
|
||||
* Sets this camera as the active view in the scene, otherwise restores the default editor camera if it was already active
|
||||
*/
|
||||
virtual void ToggleCameraAsActiveView() = 0;
|
||||
|
||||
/**
|
||||
* Gets the camera state associated with this view.
|
||||
*/
|
||||
virtual bool GetCameraState(AzFramework::CameraState& cameraState) = 0;
|
||||
};
|
||||
|
||||
using EditorCameraViewRequestBus = AZ::EBus<EditorCameraViewRequests>;
|
||||
|
||||
Reference in New Issue
Block a user