Fix issue with mouse input for viewport camera (#3210)

* fix for drift accumulating in the viewport camera

Signed-off-by: hultonha <hultonha@amazon.co.uk>

* fix typo and update how events are stored

Signed-off-by: hultonha <hultonha@amazon.co.uk>

* respond to PR feedback and fix linux and windows build issues

Signed-off-by: hultonha <hultonha@amazon.co.uk>

* fix failing unit tests in camera input

Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
hultonha
2021-08-19 09:06:24 +01:00
committed by GitHub
parent 586678a5f9
commit 80e08dd947
18 changed files with 538 additions and 134 deletions
@@ -18,9 +18,22 @@ namespace AtomToolsFramework
{
class ModularViewportCameraControllerInstance;
//! A reduced ViewportContext interface for use by the ModularViewportCameraController.
//! @note This extra indirection is used to facilitate testing the ModularViewportCameraController.
class ModularCameraViewportContext
{
public:
virtual ~ModularCameraViewportContext() = default;
virtual AZ::Transform GetCameraTransform() const = 0;
virtual void SetCameraTransform(const AZ::Transform& transform) = 0;
virtual void ConnectViewMatrixChangedHandler(AZ::RPI::ViewportContext::MatrixChangedEvent::Handler& handler) = 0;
};
//! A function object to represent returning a camera controller priority.
using CameraControllerPriorityFn =
AZStd::function<AzFramework::ViewportControllerPriority(const AzFramework::CameraSystem& cameraSystem)>;
using CameraViewportContextFn = AZStd::function<AZStd::unique_ptr<ModularCameraViewportContext>(AzFramework::ViewportId)>;
//! The default behavior for what priority the camera controller should respond to events at.
//! @note This can change based on the state of the camera controller/system.
@@ -38,6 +51,7 @@ namespace AtomToolsFramework
using CameraListBuilder = AZStd::function<void(AzFramework::Cameras&)>;
using CameraPropsBuilder = AZStd::function<void(AzFramework::CameraProps&)>;
using CameraPriorityBuilder = AZStd::function<void(CameraControllerPriorityFn&)>;
using CameraViewportContextBuilder = AZStd::function<void(AZStd::unique_ptr<ModularCameraViewportContext>&)>;
//! Sets the camera list builder callback used to populate new ModularViewportCameraControllerInstances.
void SetCameraListBuilderCallback(const CameraListBuilder& builder);
@@ -45,6 +59,8 @@ namespace AtomToolsFramework
void SetCameraPropsBuilderCallback(const CameraPropsBuilder& builder);
//! Sets the camera controller priority builder callback used to populate new ModularViewportCameraControllerInstances.
void SetCameraPriorityBuilderCallback(const CameraPriorityBuilder& builder);
//! Sets the camera controller viewport context builder callback to populate new ModularViewportCameraControllerInstances.
void SetCameraViewportContextBuilderCallback(const CameraViewportContextBuilder& builder);
private:
//! Sets up a camera list based on this controller's CameraListBuilderCallback.
@@ -53,6 +69,8 @@ namespace AtomToolsFramework
void SetupCameraProperties(AzFramework::CameraProps& cameraProps);
//! Sets up how the camera controller should decide at what priority level to respond to.
void SetupCameraControllerPriority(CameraControllerPriorityFn& cameraPriorityFn);
//! Sets up what viewport context should be used by the camera controller.
void SetupCameraControllerViewportContext(AZStd::unique_ptr<ModularCameraViewportContext>& cameraViewportContext);
//! Builder to generate a list of CameraInputs to run in the ModularViewportCameraControllerInstance.
CameraListBuilder m_cameraListBuilder;
@@ -60,6 +78,24 @@ namespace AtomToolsFramework
CameraPropsBuilder m_cameraPropsBuilder;
//! Builder to define what priority level the camera controller should respond to events at.
CameraPriorityBuilder m_cameraControllerPriorityBuilder;
//! Builder to define what viewport context interface the camera controller should use.
CameraViewportContextBuilder m_cameraViewportContextBuilder;
};
//! The production modular camera viewport context backed by an AZ::RPI::ViewportContextPtr.
//! @note This is instantiated during normal runtime use.
class ModularCameraViewportContextImpl : public ModularCameraViewportContext
{
public:
explicit ModularCameraViewportContextImpl(AzFramework::ViewportId viewportId);
// ModularCameraViewportContext overrides ...
AZ::Transform GetCameraTransform() const override;
void SetCameraTransform(const AZ::Transform& transform) override;
void ConnectViewMatrixChangedHandler(AZ::RPI::ViewportContext::MatrixChangedEvent::Handler& handler) override;
private:
AzFramework::ViewportId m_viewportId;
};
//! A customizable camera controller that can be configured to run a varying set of CameraInput instances.
@@ -115,5 +151,7 @@ namespace AtomToolsFramework
bool m_updatingTransformInternally = false;
//! Listen for camera view changes outside of the camera controller.
AZ::RPI::ViewportContext::MatrixChangedEvent::Handler m_cameraViewMatrixChangeHandler;
//! The current instance of the modular camera viewport context.
AZStd::unique_ptr<ModularCameraViewportContext> m_modularCameraViewportContext;
};
} // namespace AtomToolsFramework