Small camera updates (#1460, LYN-2315)
* add interpolation for goto position/orientation * resize default camera look-at point
This commit is contained in:
committed by
GitHub
parent
706cf0e9c3
commit
dc343e2b65
@@ -14,9 +14,15 @@
|
||||
|
||||
#include <Atom/RPI.Public/ViewportContext.h>
|
||||
#include <Atom/RPI.Public/ViewportContextBus.h>
|
||||
#include <AtomToolsFramework/Viewport/ModularViewportCameraControllerRequestBus.h>
|
||||
|
||||
namespace SandboxEditor
|
||||
{
|
||||
static AZ::Quaternion CameraRotation(const float pitch, const float yaw)
|
||||
{
|
||||
return AZ::Quaternion::CreateRotationZ(yaw) * AZ::Quaternion::CreateRotationX(pitch);
|
||||
}
|
||||
|
||||
void SetDefaultViewportCameraPosition(const AZ::Vector3& position)
|
||||
{
|
||||
auto viewportContextManager = AZ::Interface<AZ::RPI::ViewportContextRequestsInterface>::Get();
|
||||
@@ -33,10 +39,20 @@ namespace SandboxEditor
|
||||
auto viewportContextManager = AZ::Interface<AZ::RPI::ViewportContextRequestsInterface>::Get();
|
||||
if (auto viewportContext = viewportContextManager->GetDefaultViewportContext())
|
||||
{
|
||||
const auto rotation = AZ::Quaternion::CreateRotationZ(yaw) * AZ::Quaternion::CreateRotationX(pitch);
|
||||
const auto& currentCameraTransform = viewportContext->GetCameraTransform();
|
||||
viewportContext->SetCameraTransform(
|
||||
AZ::Transform::CreateFromQuaternionAndTranslation(rotation, currentCameraTransform.GetTranslation()));
|
||||
AZ::Transform::CreateFromQuaternionAndTranslation(CameraRotation(pitch, yaw), currentCameraTransform.GetTranslation()));
|
||||
}
|
||||
}
|
||||
|
||||
void InterpolateDefaultViewportCameraToTransform(const AZ::Vector3& position, const float pitch, const float yaw)
|
||||
{
|
||||
auto viewportContextManager = AZ::Interface<AZ::RPI::ViewportContextRequestsInterface>::Get();
|
||||
if (auto viewportContext = viewportContextManager->GetDefaultViewportContext())
|
||||
{
|
||||
AtomToolsFramework::ModularViewportCameraControllerRequestBus::Event(
|
||||
viewportContext->GetId(), &AtomToolsFramework::ModularViewportCameraControllerRequestBus::Events::InterpolateToTransform,
|
||||
AZ::Transform::CreateFromQuaternionAndTranslation(CameraRotation(pitch, yaw), position), 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,12 @@ namespace SandboxEditor
|
||||
//! @param yaw Amount of yaw in radians.
|
||||
SANDBOX_API void SetDefaultViewportCameraRotation(float pitch, float yaw);
|
||||
|
||||
//! Set the camera to interpolate to the given position and orientation.
|
||||
//! @param position The new position of the camera.
|
||||
//! @param pitch Amount of pitch in radians.
|
||||
//! @param yaw Amount of yaw in radians.
|
||||
SANDBOX_API void InterpolateDefaultViewportCameraToTransform(const AZ::Vector3& position, float pitch, float yaw);
|
||||
|
||||
//! Get the default viewport camera transform.
|
||||
SANDBOX_API AZ::Transform GetDefaultViewportCameraTransform();
|
||||
} // namespace SandboxEditor
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
// Editor
|
||||
#include "EditorViewportCamera.h"
|
||||
#include "EditorViewportSettings.h"
|
||||
#include "GameEngine.h"
|
||||
#include "ViewManager.h"
|
||||
|
||||
@@ -111,12 +112,24 @@ void GotoPositionDialog::OnUpdateNumbers()
|
||||
|
||||
void GotoPositionDialog::accept()
|
||||
{
|
||||
SandboxEditor::SetDefaultViewportCameraPosition(AZ::Vector3(
|
||||
aznumeric_cast<float>(m_ui->m_dymX->value()), aznumeric_cast<float>(m_ui->m_dymY->value()),
|
||||
aznumeric_cast<float>(m_ui->m_dymZ->value())));
|
||||
SandboxEditor::SetDefaultViewportCameraRotation(
|
||||
AZ::DegToRad(aznumeric_cast<float>(m_ui->m_dymAnglePitch->value())),
|
||||
AZ::DegToRad(aznumeric_cast<float>(m_ui->m_dymAngleYaw->value())));
|
||||
if (SandboxEditor::UsingNewCameraSystem())
|
||||
{
|
||||
SandboxEditor::InterpolateDefaultViewportCameraToTransform(
|
||||
AZ::Vector3(
|
||||
aznumeric_cast<float>(m_ui->m_dymX->value()), aznumeric_cast<float>(m_ui->m_dymY->value()),
|
||||
aznumeric_cast<float>(m_ui->m_dymZ->value())),
|
||||
AZ::DegToRad(aznumeric_cast<float>(m_ui->m_dymAnglePitch->value())),
|
||||
AZ::DegToRad(aznumeric_cast<float>(m_ui->m_dymAngleYaw->value())));
|
||||
}
|
||||
else
|
||||
{
|
||||
SandboxEditor::SetDefaultViewportCameraPosition(AZ::Vector3(
|
||||
aznumeric_cast<float>(m_ui->m_dymX->value()), aznumeric_cast<float>(m_ui->m_dymY->value()),
|
||||
aznumeric_cast<float>(m_ui->m_dymZ->value())));
|
||||
SandboxEditor::SetDefaultViewportCameraRotation(
|
||||
AZ::DegToRad(aznumeric_cast<float>(m_ui->m_dymAnglePitch->value())),
|
||||
AZ::DegToRad(aznumeric_cast<float>(m_ui->m_dymAngleYaw->value())));
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ namespace AtomToolsFramework
|
||||
nullptr,
|
||||
AZ::ConsoleFunctorFlags::Null,
|
||||
"");
|
||||
AZ_CVAR(float, ed_cameraSystemOrbitPointSize, 0.5f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, ed_cameraSystemOrbitPointSize, 0.1f, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
|
||||
// debug
|
||||
void DrawPreviewAxis(AzFramework::DebugDisplayRequests& display, const AZ::Transform& transform, const float axisLength)
|
||||
|
||||
Reference in New Issue
Block a user