Fix several viewport issues (#1045)

* Fix some FOV calculation viewport issues:
-Avoid calculating FOV if we've got an invalid viewport
-Don't override game mode FOV, let the active camera components manage it instead

* Fix viewport font positioning

This updates code in a few places to respect an API change/fix made to AtomFont - also switched the default value of m_virtual800x600ScreenSize to false as it's really behavior you want to opt into

* Don't activate CameraComponentController when in the Editor / not in game mode
This commit is contained in:
Nicholas Van Sickle
2021-06-01 12:20:15 -07:00
committed by GitHub
parent 853cf291be
commit 087677b326
6 changed files with 28 additions and 29 deletions
@@ -54,7 +54,7 @@ namespace AzFramework
AZ::Matrix3x4 m_transform = AZ::Matrix3x4::Identity(); //!< Transform to apply to text quads
bool m_monospace = false; //!< disable character proportional spacing
bool m_depthTest = false; //!< Test character against the depth buffer
bool m_virtual800x600ScreenSize = true; //!< Text placement and size are scaled relative to a virtual 800x600 resolution
bool m_virtual800x600ScreenSize = false; //!< Text placement and size are scaled relative to a virtual 800x600 resolution
bool m_scaleWithWindow = false; //!< Font gets bigger as the window gets bigger
bool m_multiline = true; //!< text respects ascii newline characters
};
+21 -13
View File
@@ -463,16 +463,20 @@ void EditorViewportWidget::Update()
m_renderViewport->GetViewportContext()->SetCameraTransform(LYTransformToAZTransform(m_Camera.GetMatrix()));
}
AZ::Matrix4x4 clipMatrix;
AZ::MakePerspectiveFovMatrixRH(
clipMatrix,
m_Camera.GetFov(),
aznumeric_cast<float>(width()) / aznumeric_cast<float>(height()),
m_Camera.GetNearPlane(),
m_Camera.GetFarPlane(),
true
);
m_renderViewport->GetViewportContext()->SetCameraProjectionMatrix(clipMatrix);
// Don't override the game mode FOV
if (!GetIEditor()->IsInGameMode())
{
AZ::Matrix4x4 clipMatrix;
AZ::MakePerspectiveFovMatrixRH(
clipMatrix,
GetFOV(),
aznumeric_cast<float>(width()) / aznumeric_cast<float>(height()),
m_Camera.GetNearPlane(),
m_Camera.GetFarPlane(),
true
);
m_renderViewport->GetViewportContext()->SetCameraProjectionMatrix(clipMatrix);
}
m_updatingCameraPosition = false;
@@ -870,6 +874,13 @@ void EditorViewportWidget::OnBeginPrepareRender()
int w = m_rcClient.width();
int h = m_rcClient.height();
// Don't bother doing an FOV calculation if we don't have a valid viewport
// This prevents frustum calculation bugs with a null viewport
if (w <= 1 || h <= 1)
{
return;
}
float fov = gSettings.viewports.fDefaultFov;
// match viewport fov to default / selected title menu fov
@@ -1782,9 +1793,6 @@ void EditorViewportWidget::SetViewTM(const Matrix34& viewTM, bool bMoveOnly)
cameraObject->SetWorldTM(camMatrix * AZMatrix3x3ToLYMatrix3x3(lookThroughEntityCorrection));
}
}
using namespace AzToolsFramework;
ComponentEntityObjectRequestBus::Event(cameraObject, &ComponentEntityObjectRequestBus::Events::UpdatePreemptiveUndoCache);
}
else if (m_viewEntityId.IsValid())
{
@@ -1328,7 +1328,7 @@ namespace AZ::AtomBridge
params.m_hAlign = center ? AzFramework::TextHorizontalAlignment::Center : AzFramework::TextHorizontalAlignment::Left; //! Horizontal text alignment
params.m_monospace = false; //! disable character proportional spacing
params.m_depthTest = false; //! Test character against the depth buffer
params.m_virtual800x600ScreenSize = true; //! Text placement and size are scaled relative to a virtual 800x600 resolution
params.m_virtual800x600ScreenSize = false; //! Text placement and size are scaled in viewport pixel coordinates
params.m_scaleWithWindow = false; //! Font gets bigger as the window gets bigger
params.m_multiline = true; //! text respects ascii newline characters
@@ -1364,7 +1364,7 @@ namespace AZ::AtomBridge
params.m_hAlign = center ? AzFramework::TextHorizontalAlignment::Center : AzFramework::TextHorizontalAlignment::Left; //! Horizontal text alignment
params.m_monospace = false; //! disable character proportional spacing
params.m_depthTest = false; //! Test character against the depth buffer
params.m_virtual800x600ScreenSize = true; //! Text placement and size are scaled relative to a virtual 800x600 resolution
params.m_virtual800x600ScreenSize = false; //! Text placement and size are scaled in viewport pixel coordinates
params.m_scaleWithWindow = false; //! Font gets bigger as the window gets bigger
params.m_multiline = true; //! text respects ascii newline characters
@@ -162,7 +162,7 @@ namespace AZ::Render
m_drawParams.m_hAlign = AzFramework::TextHorizontalAlignment::Right;
m_drawParams.m_monospace = false;
m_drawParams.m_depthTest = false;
m_drawParams.m_virtual800x600ScreenSize = true;
m_drawParams.m_virtual800x600ScreenSize = false;
m_drawParams.m_scaleWithWindow = false;
m_drawParams.m_multiline = true;
m_drawParams.m_lineSpacing = 0.5f;
@@ -240,7 +240,9 @@ namespace Camera
CameraBus::Handler::BusConnect();
CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraAdded, m_entityId);
if (m_config.m_makeActiveViewOnActivation)
// Activate our camera if we're running from the launcher or Editor game mode
// Otherwise, let the Editor keep managing the active camera
if (m_config.m_makeActiveViewOnActivation && (!gEnv || !gEnv->IsEditor() || gEnv->IsEditorGameMode()))
{
MakeActiveView();
}
@@ -34,20 +34,9 @@ namespace Camera
auto controllerConfig = m_controller.GetConfiguration();
controllerConfig.m_editorEntityId = GetEntityId().operator AZ::u64();
// The Editor manages active camera state, so while we're in Editor we explicitly
// disable the request to make this the active view at edit component activation time.
bool prevShouldActivateViewOnActivation = controllerConfig.m_makeActiveViewOnActivation;
controllerConfig.m_makeActiveViewOnActivation = false;
m_controller.SetConfiguration(controllerConfig);
// Call base class activate, which in turn calls Activate on our controller.
EditorCameraComponentBase::Activate();
// Reset the original `m_makeActiveViewOnActivation' setting, so that the intended value is serialized, used in BuildGameEntity, etc.
controllerConfig.m_makeActiveViewOnActivation = prevShouldActivateViewOnActivation;
m_controller.SetConfiguration(controllerConfig);
AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId());
EditorCameraNotificationBus::Handler::BusConnect();
EditorCameraViewRequestBus::Handler::BusConnect(GetEntityId());