Add customization point for begin/end of camera behaviors (hide cursor with RMB look) (#1758)
* add customization points for begin/end of camera input to all cursor customization Signed-off-by: hultonha <hultonha@amazon.co.uk> * remove cursor experiments, use cursor bus Signed-off-by: hultonha <hultonha@amazon.co.uk> * run clang-format Signed-off-by: hultonha <hultonha@amazon.co.uk> * add additional unit tests for new camera behaviors Signed-off-by: hultonha <hultonha@amazon.co.uk> * update test name to use snake_case to increase readability Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
committed by
GitHub
parent
9f61ed426c
commit
dafe9f6690
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
@@ -188,7 +188,7 @@ namespace AzFramework
|
||||
m_idleCameraInputs.push_back(AZStd::move(cameraInput));
|
||||
}
|
||||
|
||||
bool Cameras::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta)
|
||||
bool Cameras::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, const float scrollDelta)
|
||||
{
|
||||
bool handling = false;
|
||||
for (auto& cameraInput : m_activeCameraInputs)
|
||||
@@ -308,7 +308,7 @@ namespace AzFramework
|
||||
};
|
||||
}
|
||||
|
||||
bool RotateCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
bool RotateCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, [[maybe_unused]] const float scrollDelta)
|
||||
{
|
||||
const ClickDetector::ClickEvent clickEvent = [&event, this]
|
||||
{
|
||||
@@ -393,7 +393,7 @@ namespace AzFramework
|
||||
}
|
||||
|
||||
bool PanCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] const float scrollDelta)
|
||||
{
|
||||
if (const auto& input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
{
|
||||
@@ -580,7 +580,7 @@ namespace AzFramework
|
||||
m_boost = false;
|
||||
}
|
||||
|
||||
bool OrbitCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta)
|
||||
bool OrbitCameraInput::HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, const float scrollDelta)
|
||||
{
|
||||
if (const auto* input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
{
|
||||
@@ -675,7 +675,7 @@ namespace AzFramework
|
||||
}
|
||||
|
||||
bool OrbitDollyScrollCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] const float scrollDelta)
|
||||
{
|
||||
if (const auto* scroll = AZStd::get_if<ScrollEvent>(&event))
|
||||
{
|
||||
@@ -707,7 +707,7 @@ namespace AzFramework
|
||||
}
|
||||
|
||||
bool OrbitDollyCursorMoveCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] const float scrollDelta)
|
||||
{
|
||||
if (const auto& input = AZStd::get_if<DiscreteInputEvent>(&event))
|
||||
{
|
||||
@@ -747,7 +747,7 @@ namespace AzFramework
|
||||
}
|
||||
|
||||
bool ScrollTranslationCameraInput::HandleEvents(
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] float scrollDelta)
|
||||
const InputEvent& event, [[maybe_unused]] const ScreenVector& cursorDelta, [[maybe_unused]] const float scrollDelta)
|
||||
{
|
||||
if (const auto* scroll = AZStd::get_if<ScrollEvent>(&event))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
@@ -104,6 +104,8 @@ namespace AzFramework
|
||||
class CameraInput
|
||||
{
|
||||
public:
|
||||
using ActivateChangeFn = AZStd::function<void()>;
|
||||
|
||||
//! The state of activation the camera input is currently in.
|
||||
//! State changes of Activation: Idle -> Beginning -> Active -> Ending -> Idle
|
||||
enum class Activation
|
||||
@@ -148,11 +150,28 @@ namespace AzFramework
|
||||
|
||||
void ContinueActivation()
|
||||
{
|
||||
// continue activation is called after the first step of the camera input,
|
||||
// activation began is called once, the first time before the state is set to active
|
||||
if (m_activation == Activation::Beginning)
|
||||
{
|
||||
if (m_activationBeganFn)
|
||||
{
|
||||
m_activationBeganFn();
|
||||
}
|
||||
}
|
||||
|
||||
m_activation = Activation::Active;
|
||||
}
|
||||
|
||||
void ClearActivation()
|
||||
{
|
||||
// clear activation happens after an end has been requested, activation ended
|
||||
// is then called before the camera input is returned to idle
|
||||
if (m_activationEndedFn)
|
||||
{
|
||||
m_activationEndedFn();
|
||||
}
|
||||
|
||||
m_activation = Activation::Idle;
|
||||
}
|
||||
|
||||
@@ -177,6 +196,16 @@ namespace AzFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetActivationBeganFn(ActivateChangeFn activationBeganFn)
|
||||
{
|
||||
m_activationBeganFn = AZStd::move(activationBeganFn);
|
||||
}
|
||||
|
||||
void SetActivationEndedFn(ActivateChangeFn activationEndedFn)
|
||||
{
|
||||
m_activationEndedFn = AZStd::move(activationEndedFn);
|
||||
}
|
||||
|
||||
protected:
|
||||
//! Handle any state reset that may be required for the camera input (optional).
|
||||
virtual void ResetImpl()
|
||||
@@ -185,6 +214,8 @@ namespace AzFramework
|
||||
|
||||
private:
|
||||
Activation m_activation = Activation::Idle; //!< Default all camera inputs to the idle state.
|
||||
AZStd::function<void()> m_activationBeganFn; //!< Called when the camera input successfully makes it to the active state.
|
||||
AZStd::function<void()> m_activationEndedFn; //!< Called when the camera input ends and returns to the idle state.
|
||||
};
|
||||
|
||||
//! Properties to use to configure behavior across all types of camera.
|
||||
|
||||
Reference in New Issue
Block a user