You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
4.5 KiB
C++
71 lines
4.5 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include "SlideAlongAxisBasedOnAngle.h"
|
|
#include "StartingPointCamera/StartingPointCameraUtilities.h"
|
|
#include <AzCore/Math/Quaternion.h>
|
|
#include <AzCore/Serialization/EditContext.h>
|
|
#include <AzCore/Math/Transform.h>
|
|
|
|
namespace Camera
|
|
{
|
|
void SlideAlongAxisBasedOnAngle::Reflect(AZ::ReflectContext* reflection)
|
|
{
|
|
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
|
|
if (serializeContext)
|
|
{
|
|
serializeContext->Class<SlideAlongAxisBasedOnAngle>()
|
|
->Version(2)
|
|
->Field("Axis to slide along", &SlideAlongAxisBasedOnAngle::m_axisToSlideAlong)
|
|
->Field("Angle Type", &SlideAlongAxisBasedOnAngle::m_angleTypeToChangeFor)
|
|
->Field("Ignore X Component", &SlideAlongAxisBasedOnAngle::m_ignoreX)
|
|
->Field("Ignore Y Component", &SlideAlongAxisBasedOnAngle::m_ignoreY)
|
|
->Field("Ignore Z Component", &SlideAlongAxisBasedOnAngle::m_ignoreZ)
|
|
->Field("Max Positive Slide Distance", &SlideAlongAxisBasedOnAngle::m_maximumPositiveSlideDistance)
|
|
->Field("Max Negative Slide Distance", &SlideAlongAxisBasedOnAngle::m_maximumNegativeSlideDistance);
|
|
|
|
AZ::EditContext* editContext = serializeContext->GetEditContext();
|
|
if (editContext)
|
|
{
|
|
editContext->Class<SlideAlongAxisBasedOnAngle>("SlideAlongAxisBasedOnAngle", "Slide 0..SlideDistance along Axis based on Angle Type. Maps from 90..-90 degrees")
|
|
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
|
->DataElement(AZ::Edit::UIHandlers::ComboBox, &SlideAlongAxisBasedOnAngle::m_axisToSlideAlong, "Axis to slide along", "The Axis to slide along")
|
|
->EnumAttribute(RelativeAxisType::ForwardBackward, "Forwards and Backwards")
|
|
->EnumAttribute(RelativeAxisType::LeftRight, "Right and Left")
|
|
->EnumAttribute(RelativeAxisType::UpDown, "Up and Down")
|
|
->DataElement(AZ::Edit::UIHandlers::ComboBox, &SlideAlongAxisBasedOnAngle::m_angleTypeToChangeFor, "Angle Type", "The angle type to base the slide off of")
|
|
->EnumAttribute(EulerAngleType::Pitch, "Pitch")
|
|
->EnumAttribute(EulerAngleType::Roll, "Roll")
|
|
->EnumAttribute(EulerAngleType::Yaw, "Yaw")
|
|
->DataElement(0, &SlideAlongAxisBasedOnAngle::m_maximumPositiveSlideDistance, "Max Positive Slide Distance", "The maximum distance to slide in the positive")
|
|
->Attribute(AZ::Edit::Attributes::Suffix, "m")
|
|
->DataElement(0, &SlideAlongAxisBasedOnAngle::m_maximumNegativeSlideDistance, "Max Negative Slide Distance", "The maximum distance to slide in the negative")
|
|
->Attribute(AZ::Edit::Attributes::Suffix, "m")
|
|
->ClassElement(AZ::Edit::ClassElements::Group, "Vector Components To Ignore")
|
|
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
|
->DataElement(0, &SlideAlongAxisBasedOnAngle::m_ignoreX, "X", "When active, the X Component will be ignored.")
|
|
->DataElement(0, &SlideAlongAxisBasedOnAngle::m_ignoreY, "Y", "When active, the Y Component will be ignored.")
|
|
->DataElement(0, &SlideAlongAxisBasedOnAngle::m_ignoreZ, "Z", "When active, the Z Component will be ignored.")
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SlideAlongAxisBasedOnAngle::AdjustLookAtTarget([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform)
|
|
{
|
|
float angle = GetEulerAngleFromTransform(outLookAtTargetTransform, m_angleTypeToChangeFor);
|
|
float currentPositionOnRange = -angle / AZ::Constants::HalfPi;
|
|
float slideScale = currentPositionOnRange > 0.0f ? m_maximumPositiveSlideDistance : m_maximumNegativeSlideDistance;
|
|
|
|
AZ::Vector3 basis = outLookAtTargetTransform.GetBasis(m_axisToSlideAlong);
|
|
MaskComponentFromNormalizedVector(basis, m_ignoreX, m_ignoreY, m_ignoreZ);
|
|
|
|
outLookAtTargetTransform.SetTranslation(outLookAtTargetTransform.GetTranslation() + basis * currentPositionOnRange * slideScale);
|
|
}
|
|
}
|