Expose camera input channels to the UI and ensure the cached values are refreshed when updated (#3607)

* expose camera input channels to the ui and ensure the cached values are refreshed when updated

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

* small fixes for tests

Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
hultonha
2021-08-27 09:29:08 +01:00
committed by GitHub
parent 48c959e359
commit b0330ba26a
14 changed files with 624 additions and 261 deletions
@@ -332,6 +332,11 @@ namespace AzFramework
return nextCamera;
}
void RotateCameraInput::SetRotateInputChannelId(const InputChannelId& rotateChannelId)
{
m_rotateChannelId = rotateChannelId;
}
PanCameraInput::PanCameraInput(const InputChannelId& panChannelId, PanAxesFn panAxesFn)
: m_panAxesFn(AZStd::move(panAxesFn))
, m_panChannelId(panChannelId)
@@ -379,35 +384,40 @@ namespace AzFramework
return nextCamera;
}
TranslateCameraInput::TranslationType TranslateCameraInput::TranslationFromKey(
const InputChannelId& channelId, const TranslateCameraInputChannels& translateCameraInputChannels)
void PanCameraInput::SetPanInputChannelId(const InputChannelId& panChannelId)
{
if (channelId == translateCameraInputChannels.m_forwardChannelId)
m_panChannelId = panChannelId;
}
TranslateCameraInput::TranslationType TranslateCameraInput::TranslationFromKey(
const InputChannelId& channelId, const TranslateCameraInputChannelIds& translateCameraInputChannelIds)
{
if (channelId == translateCameraInputChannelIds.m_forwardChannelId)
{
return TranslationType::Forward;
}
if (channelId == translateCameraInputChannels.m_backwardChannelId)
if (channelId == translateCameraInputChannelIds.m_backwardChannelId)
{
return TranslationType::Backward;
}
if (channelId == translateCameraInputChannels.m_leftChannelId)
if (channelId == translateCameraInputChannelIds.m_leftChannelId)
{
return TranslationType::Left;
}
if (channelId == translateCameraInputChannels.m_rightChannelId)
if (channelId == translateCameraInputChannelIds.m_rightChannelId)
{
return TranslationType::Right;
}
if (channelId == translateCameraInputChannels.m_downChannelId)
if (channelId == translateCameraInputChannelIds.m_downChannelId)
{
return TranslationType::Down;
}
if (channelId == translateCameraInputChannels.m_upChannelId)
if (channelId == translateCameraInputChannelIds.m_upChannelId)
{
return TranslationType::Up;
}
@@ -416,9 +426,9 @@ namespace AzFramework
}
TranslateCameraInput::TranslateCameraInput(
TranslationAxesFn translationAxesFn, const TranslateCameraInputChannels& translateCameraInputChannels)
TranslationAxesFn translationAxesFn, const TranslateCameraInputChannelIds& translateCameraInputChannelIds)
: m_translationAxesFn(AZStd::move(translationAxesFn))
, m_translateCameraInputChannels(translateCameraInputChannels)
, m_translateCameraInputChannelIds(translateCameraInputChannelIds)
{
m_translateSpeedFn = []() constexpr
{
@@ -438,13 +448,13 @@ namespace AzFramework
{
if (input->m_state == InputChannel::State::Began)
{
m_translation |= TranslationFromKey(input->m_channelId, m_translateCameraInputChannels);
m_translation |= TranslationFromKey(input->m_channelId, m_translateCameraInputChannelIds);
if (m_translation != TranslationType::Nil)
{
BeginActivation();
}
if (input->m_channelId == m_translateCameraInputChannels.m_boostChannelId)
if (input->m_channelId == m_translateCameraInputChannelIds.m_boostChannelId)
{
m_boost = true;
}
@@ -452,12 +462,12 @@ namespace AzFramework
// ensure we don't process end events in the idle state
else if (input->m_state == InputChannel::State::Ended && !Idle())
{
m_translation &= ~(TranslationFromKey(input->m_channelId, m_translateCameraInputChannels));
m_translation &= ~(TranslationFromKey(input->m_channelId, m_translateCameraInputChannelIds));
if (m_translation == TranslationType::Nil)
{
EndActivation();
}
if (input->m_channelId == m_translateCameraInputChannels.m_boostChannelId)
if (input->m_channelId == m_translateCameraInputChannelIds.m_boostChannelId)
{
m_boost = false;
}
@@ -529,6 +539,11 @@ namespace AzFramework
m_boost = false;
}
void TranslateCameraInput::SetTranslateCameraInputChannelIds(const TranslateCameraInputChannelIds& translateCameraInputChannelIds)
{
m_translateCameraInputChannelIds = translateCameraInputChannelIds;
}
OrbitCameraInput::OrbitCameraInput(const InputChannelId& orbitChannelId)
: m_orbitChannelId(orbitChannelId)
{
@@ -620,6 +635,11 @@ namespace AzFramework
return nextCamera;
}
void OrbitCameraInput::SetOrbitInputChannelId(const InputChannelId& orbitChanneId)
{
m_orbitChannelId = orbitChanneId;
}
OrbitDollyScrollCameraInput::OrbitDollyScrollCameraInput()
{
m_scrollSpeedFn = []() constexpr
@@ -678,6 +698,11 @@ namespace AzFramework
return nextCamera;
}
void OrbitDollyCursorMoveCameraInput::SetDollyInputChannelId(const InputChannelId& dollyChannelId)
{
m_dollyChannelId = dollyChannelId;
}
ScrollTranslationCameraInput::ScrollTranslationCameraInput()
{
m_scrollSpeedFn = []() constexpr
@@ -303,6 +303,8 @@ namespace AzFramework
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
void SetRotateInputChannelId(const InputChannelId& rotateChannelId);
AZStd::function<float()> m_rotateSpeedFn;
AZStd::function<bool()> m_invertPitchFn;
AZStd::function<bool()> m_invertYawFn;
@@ -355,6 +357,8 @@ namespace AzFramework
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
void SetPanInputChannelId(const InputChannelId& panChannelId);
AZStd::function<float()> m_panSpeedFn;
AZStd::function<bool()> m_invertPanXFn;
AZStd::function<bool()> m_invertPanYFn;
@@ -398,7 +402,7 @@ namespace AzFramework
}
//! Groups all camera translation inputs.
struct TranslateCameraInputChannels
struct TranslateCameraInputChannelIds
{
InputChannelId m_forwardChannelId;
InputChannelId m_backwardChannelId;
@@ -414,13 +418,15 @@ namespace AzFramework
{
public:
explicit TranslateCameraInput(
TranslationAxesFn translationAxesFn, const TranslateCameraInputChannels& translateCameraInputChannels);
TranslationAxesFn translationAxesFn, const TranslateCameraInputChannelIds& translateCameraInputChannelIds);
// CameraInput overrides ...
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
void ResetImpl() override;
void SetTranslateCameraInputChannelIds(const TranslateCameraInputChannelIds& translateCameraInputChannelIds);
AZStd::function<float()> m_translateSpeedFn;
AZStd::function<float()> m_boostMultiplierFn;
@@ -482,11 +488,11 @@ namespace AzFramework
//! Converts from a generic input channel id to a concrete translation type (based on the user's key mappings).
TranslationType TranslationFromKey(
const InputChannelId& channelId, const TranslateCameraInputChannels& translateCameraInputChannels);
const InputChannelId& channelId, const TranslateCameraInputChannelIds& translateCameraInputChannelIds);
TranslationType m_translation = TranslationType::Nil; //!< Types of translation the camera input is under.
TranslationAxesFn m_translationAxesFn; //!< Builder for translation axes.
TranslateCameraInputChannels m_translateCameraInputChannels; //!< Input channel ids that map to internal translation types.
TranslateCameraInputChannelIds m_translateCameraInputChannelIds; //!< Input channel ids that map to internal translation types.
bool m_boost = false; //!< Is the translation speed currently being multiplied/scaled upwards.
};
@@ -513,6 +519,8 @@ namespace AzFramework
bool HandleEvents(const InputEvent& event, const ScreenVector& cursorDelta, float scrollDelta) override;
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
void SetDollyInputChannelId(const InputChannelId& dollyChannelId);
AZStd::function<float()> m_cursorSpeedFn;
private:
@@ -548,6 +556,8 @@ namespace AzFramework
Camera StepCamera(const Camera& targetCamera, const ScreenVector& cursorDelta, float scrollDelta, float deltaTime) override;
bool Exclusive() const override;
void SetOrbitInputChannelId(const InputChannelId& orbitChanneId);
Cameras m_orbitCameras; //!< The camera inputs to run when this camera input is active (only these will run as it is exclusive).
//! Override the default behavior for how a look-at point is calculated.