Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,53 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "OffsetPosition.h"
#include <AzCore/Math/Transform.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Quaternion.h>
namespace Camera
{
void OffsetPosition::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<OffsetPosition>()
->Version(1)
->Field("Positional Offset", &OffsetPosition::m_positionalOffset)
->Field("Offset Is Relative", &OffsetPosition::m_isRelativeOffset);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<OffsetPosition>("OffsetPosition", "Offset the acquired position of the camera's current target")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(0, &OffsetPosition::m_positionalOffset, "Positional Offset", "The vector offset from the current position")
->DataElement(0, &OffsetPosition::m_isRelativeOffset, "Offset Is Relative", "Uses world coordinates for the offset when false and local coordinates when true");
}
}
}
void OffsetPosition::AdjustLookAtTarget([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform)
{
if (m_isRelativeOffset)
{
outLookAtTargetTransform.SetTranslation(outLookAtTargetTransform.GetTranslation() + outLookAtTargetTransform.GetRotation().TransformVector(m_positionalOffset));
}
else
{
outLookAtTargetTransform.SetTranslation(outLookAtTargetTransform.GetTranslation() + m_positionalOffset);
}
}
} // namespace Camera
@@ -0,0 +1,48 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraLookAtBehavior.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Math/Vector3.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// Offset Position will offset the current LookAt target transform by "Positional Offset"
//////////////////////////////////////////////////////////////////////////
class OffsetPosition
: public ICameraLookAtBehavior
{
public:
~OffsetPosition() override = default;
AZ_RTTI(OffsetPosition, "{5B2975A6-839B-4DE0-842B-EDE78D778BC9}", ICameraLookAtBehavior);
AZ_CLASS_ALLOCATOR(OffsetPosition, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraLookAtBehavior
void AdjustLookAtTarget(float deltaTime, const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
AZ::Vector3 m_positionalOffset = AZ::Vector3::CreateZero();
bool m_isRelativeOffset = false;
};
} // namespace Camera
@@ -0,0 +1,111 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "RotateCameraLookAt.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Quaternion.h>
#include <AzCore/Component/TickBus.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include "StartingPointCamera/StartingPointCameraUtilities.h"
namespace Camera
{
void RotateCameraLookAt::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<RotateCameraLookAt>()
->Version(2)
->Field("Axis Of Rotation", &RotateCameraLookAt::m_axisOfRotation)
->Field("Event Name", &RotateCameraLookAt::m_eventName)
->Field("Invert Axis", &RotateCameraLookAt::m_shouldInvertAxis)
->Field("Rotation Speed Scale", &RotateCameraLookAt::m_rotationSpeedScale);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<RotateCameraLookAt>("Rotate Camera Target"
, "This will rotate a Camera Target about Axis when the EventName fires")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(AZ::Edit::UIHandlers::ComboBox, &RotateCameraLookAt::m_axisOfRotation, "Axis Of Rotation",
"This is the direction vector that will be applied to the target's movement scaled for time")
->EnumAttribute(AxisOfRotation::X_Axis, "Camera Target's X Axis")
->EnumAttribute(AxisOfRotation::Y_Axis, "Camera Target's Y Axis")
->EnumAttribute(AxisOfRotation::Z_Axis, "Camera Target's Z Axis")
->DataElement(0, &RotateCameraLookAt::m_eventName, "Event Name", "The Name of the expected Event")
->DataElement(0, &RotateCameraLookAt::m_shouldInvertAxis, "Invert Axis", "True if you want to rotate along a negative axis")
->DataElement(0, &RotateCameraLookAt::m_rotationSpeedScale, "Rotation Speed Scale", "Scale greater than 1 to speed up, between 0 and 1 to slow down")
->Attribute(AZ::Edit::Attributes::Min, 0.001f)
->Attribute(AZ::Edit::Attributes::Step, 0.1f)
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ_CRC("RefreshAttributesAndValues"));
}
}
}
void RotateCameraLookAt::AdjustLookAtTarget([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform)
{
float axisPolarity = m_shouldInvertAxis ? -1.0f : 1.0f;
float rotationAmount = axisPolarity * m_rotationAmount;
// remove translation and scale
AZ::Vector3 translation = outLookAtTargetTransform.GetTranslation();
outLookAtTargetTransform.SetTranslation(AZ::Vector3::CreateZero());
AZ::Vector3 transformScale = outLookAtTargetTransform.ExtractScale();
// perform our rotation
AZ::Transform desiredRotationTransform = AZ::Transform::CreateFromQuaternion(AZ::Quaternion::CreateFromAxisAngle(outLookAtTargetTransform.GetBasis(m_axisOfRotation), rotationAmount));
outLookAtTargetTransform = desiredRotationTransform * outLookAtTargetTransform;
// return scale and translate
outLookAtTargetTransform.SetScale(transformScale);
outLookAtTargetTransform.SetTranslation(translation);
}
void RotateCameraLookAt::Activate(AZ::EntityId entityId)
{
m_rigEntity = entityId;
AZ::Crc32 eventNameCrc = AZ::Crc32(m_eventName.c_str());
AZ::GameplayNotificationId actionBusId(m_rigEntity, eventNameCrc);
AZ::GameplayNotificationBus::Handler::BusConnect(actionBusId);
}
void RotateCameraLookAt::Deactivate()
{
AZ::Crc32 eventNameCrc = AZ::Crc32(m_eventName.c_str());
AZ::GameplayNotificationId actionBusId(m_rigEntity, eventNameCrc);
AZ::GameplayNotificationBus::Handler::BusDisconnect(actionBusId);
}
void RotateCameraLookAt::OnEventBegin(const AZStd::any& value)
{
OnEventUpdating(value);
}
void RotateCameraLookAt::OnEventUpdating(const AZStd::any& value)
{
float frameTime = 0.0f;
EBUS_EVENT_RESULT(frameTime, AZ::TickRequestBus, GetTickDeltaTime);
float floatValue = 0.0f;
AZ_Warning("RotateCameraLookAt", AZStd::any_numeric_cast<float>(&value, floatValue), "Received bad value, expected type numerically convertable to float, got type %s", GetNameFromUuid(value.type()));
if (AZStd::any_numeric_cast<float>(&value, floatValue))
{
m_rotationAmount += floatValue * frameTime * m_rotationSpeedScale;
}
}
void RotateCameraLookAt::OnEventEnd(const AZStd::any&)
{
m_rotationAmount = 0.f;
}
} // namespace Camera
@@ -0,0 +1,65 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraLookAtBehavior.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/std/string/string.h>
#include <LmbrCentral/Scripting/GameplayNotificationBus.h>
#include "StartingPointCamera/StartingPointCameraConstants.h"
#include <AzCore/Memory/SystemAllocator.h>
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This will rotate the camera LookAt transform. If you have a camera that
/// is closely following a target, say in third person perspective you
/// would not want the target to pitch while looking up and down. You may
/// also desire the ability to swivel the camera around the target while
/// the target remains stationary.
//////////////////////////////////////////////////////////////////////////
class RotateCameraLookAt
: public ICameraLookAtBehavior
, public AZ::GameplayNotificationBus::Handler
{
public:
~RotateCameraLookAt() override = default;
AZ_RTTI(RotateCameraLookAt, "{B72C5BE7-2DAF-412B-BBBB-F216B3DFB9A0}", ICameraLookAtBehavior);
AZ_CLASS_ALLOCATOR(RotateCameraLookAt, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraLookAtBehavior
void AdjustLookAtTarget(float deltaTime, const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform) override;
void Activate(AZ::EntityId) override;
void Deactivate() override;
//////////////////////////////////////////////////////////////////////////
// AZ::GameplayNotificationBus
void OnEventBegin(const AZStd::any&) override;
void OnEventUpdating(const AZStd::any&) override;
void OnEventEnd(const AZStd::any&) override;
private:
//////////////////////////////////////////////////////////////////////////
// Reflected data
AxisOfRotation m_axisOfRotation = AxisOfRotation::X_Axis;
AZStd::string m_eventName = "";
float m_rotationSpeedScale = 1.f;
bool m_shouldInvertAxis = false;
//////////////////////////////////////////////////////////////////////////
// internal data
float m_rotationAmount = 0.f;
AZ::EntityId m_rigEntity;
};
} // namespace Camera
@@ -0,0 +1,71 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#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(1)
->Field("Axis to slide along", &SlideAlongAxisBasedOnAngle::m_axisToSlideAlong)
->Field("Angle Type", &SlideAlongAxisBasedOnAngle::m_angleTypeToChangeFor)
->Field("Vector Component To Ignore", &SlideAlongAxisBasedOnAngle::m_vectorComponentToIgnore)
->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(AZ::Edit::UIHandlers::ComboBox, &SlideAlongAxisBasedOnAngle::m_vectorComponentToIgnore, "Vector Component To Ignore", "The Vector Component To Ignore")
->EnumAttribute(VectorComponentType::None, "None")
->EnumAttribute(VectorComponentType::X_Component, "X")
->EnumAttribute(VectorComponentType::Y_Component, "Y")
->EnumAttribute(VectorComponentType::Z_Component, "Z")
->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");
}
}
}
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_vectorComponentToIgnore);
outLookAtTargetTransform.SetTranslation(outLookAtTargetTransform.GetTranslation() + basis * currentPositionOnRange * slideScale);
}
}
@@ -0,0 +1,54 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraLookAtBehavior.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/RTTI/ReflectContext.h>
#include "StartingPointCamera/StartingPointCameraConstants.h"
#include <AzCore/Memory/SystemAllocator.h>
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This will slide the look at target along a desired axis based on a
/// particular Euler angle. As an example setting this up with ForwardBackward
/// and Pitch, the more the target pitches the further forward it will slide.
/// This will have the behavior that when looking down you will be looking
/// down ahead of the target instead of directly at the top. A similar result
/// will occur when looking up. This could also be used for peeking around
/// corners. This is primarily useful for third person cameras.
//////////////////////////////////////////////////////////////////////////
class SlideAlongAxisBasedOnAngle
: public ICameraLookAtBehavior
{
public:
~SlideAlongAxisBasedOnAngle() override = default;
AZ_RTTI(SlideAlongAxisBasedOnAngle, "{8DDA8D0B-5BC3-437E-894B-5144E6E81236}", ICameraLookAtBehavior);
AZ_CLASS_ALLOCATOR(SlideAlongAxisBasedOnAngle, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraLookAtBehavior
void AdjustLookAtTarget(float deltaTime, const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
//////////////////////////////////////////////////////////////////////////
// Reflected data
RelativeAxisType m_axisToSlideAlong = ForwardBackward;
EulerAngleType m_angleTypeToChangeFor = Pitch;
VectorComponentType m_vectorComponentToIgnore = None;
float m_maximumPositiveSlideDistance = 0.0f;
float m_maximumNegativeSlideDistance = 0.0f;
};
} // namespace Camera
@@ -0,0 +1,70 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "AcquireByEntityId.h"
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Transform.h>
#include <StartingPointCamera/StartingPointCameraConstants.h>
namespace Camera
{
void AcquireByEntityId::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
// Deprecating the CameraTargetComponent. This acquire behavior makes it obsolete
serializeContext->ClassDeprecate("CameraTargetComponent", "{0D6A6574-4B79-4907-8529-EB61F343D957}");
serializeContext->Class<AcquireByEntityId>()
->Version(1)
->Field("Entity Target", &AcquireByEntityId::m_target)
->Field("Use Target Rotation", &AcquireByEntityId::m_shouldUseTargetRotation)
->Field("Use Target Position", &AcquireByEntityId::m_shouldUseTargetPosition);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<AcquireByEntityId>("AcquireByEntityId", "Acquires a target by entity ref")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_target, "Entity target", "Specify an entity to target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_shouldUseTargetRotation, "Use target rotation", "Set to false to not have the camera orient itself with the target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_shouldUseTargetPosition, "Use target position", "Set to false to not have the camera position itself with the target");
}
}
}
bool AcquireByEntityId::AcquireTarget(AZ::Transform& outTransformInformation)
{
if (m_target.IsValid())
{
AZ::Transform targetsTransform = AZ::Transform::Identity();
AZ::TransformBus::EventResult(targetsTransform, m_target, &AZ::TransformInterface::GetWorldTM);
if (m_shouldUseTargetPosition)
{
outTransformInformation.SetTranslation(targetsTransform.GetTranslation());
}
if (m_shouldUseTargetRotation)
{
const AZ::Vector3 translation = outTransformInformation.GetTranslation();
outTransformInformation = targetsTransform;
outTransformInformation.SetTranslation(translation);
}
return true;
}
return false;
}
} // namespace Camera
@@ -0,0 +1,52 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/std/string/string.h>
#include <AzCore/RTTI/RTTI.h>
#include <CameraFramework/ICameraTargetAcquirer.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This will request Camera targets from the CameraTarget buses. It will
/// then return that target's transform when requested by the Camera Rig
//////////////////////////////////////////////////////////////////////////
class AcquireByEntityId
: public ICameraTargetAcquirer
{
public:
~AcquireByEntityId() override = default;
AZ_RTTI(AcquireByEntityId, "{14D0D355-1F83-4F46-9DE1-D41D23BDFC3C}", ICameraTargetAcquirer)
AZ_CLASS_ALLOCATOR(AcquireByEntityId, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTargetAcquirer
bool AcquireTarget(AZ::Transform& outTransformInformation) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
AZ::EntityId m_target = AZ::EntityId();
bool m_shouldUseTargetRotation = true;
bool m_shouldUseTargetPosition = true;
};
} //namespace Camera
@@ -0,0 +1,120 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "AcquireByTag.h"
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Transform.h>
#include <StartingPointCamera/StartingPointCameraConstants.h>
namespace Camera
{
namespace ClassConverters
{
static bool DeprecateCameraTargetComponentAcquirer(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
} // namespace ClassConverters
void AcquireByTag::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
// Deprecating the CameraTargetComponent. This acquire behavior makes it obsolete
serializeContext->ClassDeprecate("CameraTargetComponentAcquirer", "{CF1C04E4-1195-42DD-AF0B-C9F94E80B35D}", &ClassConverters::DeprecateCameraTargetComponentAcquirer);
serializeContext->Class<AcquireByTag>()
->Version(1)
->Field("Target Tag", &AcquireByTag::m_targetTag)
->Field("Use Target Rotation", &AcquireByTag::m_shouldUseTargetRotation)
->Field("Use Target Position", &AcquireByTag::m_shouldUseTargetPosition);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<AcquireByTag>("AcquireByTag", "Acquires a target by tag")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByTag::m_targetTag, "Target tag", "The tag on an entity you want to target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByTag::m_shouldUseTargetRotation, "Use target rotation", "Set to false to not have the camera orient itself with the target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByTag::m_shouldUseTargetPosition, "Use target position", "Set to false to not have the camera position itself with the target");
}
}
}
bool AcquireByTag::AcquireTarget(AZ::Transform& outTransformInformation)
{
if (m_targets.size())
{
AZ::Transform targetsTransform = AZ::Transform::Identity();
AZ::TransformBus::EventResult(targetsTransform, m_targets[0], &AZ::TransformInterface::GetWorldTM);
if (m_shouldUseTargetPosition)
{
outTransformInformation.SetTranslation(targetsTransform.GetTranslation());
}
if (m_shouldUseTargetRotation)
{
const AZ::Vector3 translation = outTransformInformation.GetTranslation();
outTransformInformation = targetsTransform;
outTransformInformation.SetTranslation(translation);
}
return true;
}
return false;
}
void AcquireByTag::Activate(AZ::EntityId)
{
LmbrCentral::TagGlobalNotificationBus::Handler::BusConnect(LmbrCentral::Tag(m_targetTag.c_str()));
}
void AcquireByTag::Deactivate()
{
LmbrCentral::TagGlobalNotificationBus::Handler::BusDisconnect();
}
void AcquireByTag::OnEntityTagAdded(const AZ::EntityId& entityId)
{
AZ_Error("AcquireByTag", entityId.IsValid(), "A tag was added to an invalid entity, this should never happen");
m_targets.push_back(entityId);
}
void AcquireByTag::OnEntityTagRemoved(const AZ::EntityId& entityId)
{
auto&& iterator = AZStd::find(m_targets.begin(), m_targets.end(), entityId);
AZ_Error("AcquireByTag", iterator != m_targets.end(), "A tag was removed without being added, this should never happen");
m_targets.erase(iterator);
}
namespace ClassConverters
{
static bool DeprecateCameraTargetComponentAcquirer(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
AZStd::string tag;
classElement.GetChildData(AZ::Crc32("Tag of Specific Target"), tag);
bool useTargetRotation = true;
classElement.GetChildData(AZ::Crc32("Use Target Rotation"), useTargetRotation);
bool useTargetPosition = true;
classElement.GetChildData(AZ::Crc32("Use Target Position"), useTargetPosition);
classElement.Convert(context, AZ::AzTypeInfo<AcquireByTag>::Uuid());
classElement.AddElementWithData(context, "Target Tag", tag);
classElement.AddElementWithData(context, "Use Target Rotation", useTargetRotation);
classElement.AddElementWithData(context, "Use Target Position", useTargetPosition);
return true;
}
} // namespace ClassConverters
} // namespace Camera
@@ -0,0 +1,62 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/RTTI/RTTI.h>
#include <CameraFramework/ICameraTargetAcquirer.h>
#include <AzCore/Component/Component.h>
#include <LmbrCentral/Scripting/TagComponentBus.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This will request Camera targets from the CameraTarget buses. It will
/// then return that target's transform when requested by the Camera Rig
//////////////////////////////////////////////////////////////////////////
class AcquireByTag
: public ICameraTargetAcquirer
, private LmbrCentral::TagGlobalNotificationBus::Handler
{
public:
~AcquireByTag() override = default;
AZ_RTTI(AcquireByTag, "{E76621A5-E5A8-41B0-AC1D-EC87553181F5}", ICameraTargetAcquirer)
AZ_CLASS_ALLOCATOR(AcquireByTag, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTargetAcquirer
bool AcquireTarget(AZ::Transform& outTransformInformation) override;
void Activate(AZ::EntityId) override;
void Deactivate() override;
//////////////////////////////////////////////////////////////////////////
// LmbrCentral::TagGlobalNotificationBus
void OnEntityTagAdded(const AZ::EntityId&) override;
void OnEntityTagRemoved(const AZ::EntityId&) override;
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
AZStd::string m_targetTag;
bool m_shouldUseTargetRotation = true;
bool m_shouldUseTargetPosition = true;
//////////////////////////////////////////////////////////////////////////
// Private Data
AZStd::vector<AZ::EntityId> m_targets;
};
} //namespace Camera
@@ -0,0 +1,54 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "FaceTarget.h"
#include <AzCore/Math/Transform.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Math/Crc.h>
#include <AzCore/Serialization/EditContext.h>
#include "StartingPointCamera/StartingPointCameraConstants.h"
#include <AzCore/Math/Quaternion.h>
#include <MathConversion.h>
#include <StartingPointCamera/StartingPointCameraUtilities.h>
namespace Camera
{
void FaceTarget::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<FaceTarget>()
->Version(1)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<FaceTarget>("FaceTarget", "Causes the camera to face the target")
->ClassElement(AZ::Edit::ClassElements::EditorData, "");
}
}
}
void FaceTarget::AdjustCameraTransform(float /*deltaTime*/, [[maybe_unused]] const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
{
AZ::Vector3 newLookVector = (targetTransform.GetTranslation() - inOutCameraTransform.GetTranslation()).GetNormalized();
if (newLookVector.GetLengthSq() < AZ::Constants::FloatEpsilon)
{
newLookVector = targetTransform.GetBasis(ForwardBackward);
}
inOutCameraTransform.SetRotation(CreateQuaternionFromViewVector(newLookVector.GetNormalized()));
}
} // namespace Camera
@@ -0,0 +1,45 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraTransformBehavior.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This behavior will cause the camera to rotate to face the target
//////////////////////////////////////////////////////////////////////////
class FaceTarget
: public ICameraTransformBehavior
{
public:
~FaceTarget() override = default;
AZ_RTTI(FaceTarget, "{1A2CBCD0-1841-493C-8DB7-1BCA0D293019}", ICameraTransformBehavior)
AZ_CLASS_ALLOCATOR(FaceTarget, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTransformBehavior
void AdjustCameraTransform(float deltaTime, const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
};
}
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "FollowTargetFromAngle.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include "StartingPointCamera/StartingPointCameraUtilities.h"
namespace Camera
{
void FollowTargetFromAngle::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<FollowTargetFromAngle>()
->Version(1)
->Field("Angle", &FollowTargetFromAngle::m_angleInDegrees)
->Field("Rotation Type", &FollowTargetFromAngle::m_rotationType)
->Field("Distance From Target", &FollowTargetFromAngle::m_distanceFromTarget);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<FollowTargetFromAngle>("FollowTargetFromAngle", "Follows behind the target by Angle degrees about RotationType")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(0, &FollowTargetFromAngle::m_angleInDegrees, "Angle", "The angle to rotate about RotationType")
->Attribute(AZ::Edit::Attributes::Suffix, "degrees")
->DataElement(AZ::Edit::UIHandlers::ComboBox, &FollowTargetFromAngle::m_rotationType, "Rotation Type", "Choose to Yaw, Pitch or Roll Angle degrees")
->EnumAttribute(EulerAngleType::Yaw, "Yaw")
->EnumAttribute(EulerAngleType::Pitch, "Pitch")
->EnumAttribute(EulerAngleType::Roll, "Roll")
->DataElement(0, &FollowTargetFromAngle::m_distanceFromTarget, "Distance From Target", "The range at which to follow the target from")
->Attribute(AZ::Edit::Attributes::Suffix, "m");
}
}
}
void FollowTargetFromAngle::AdjustCameraTransform([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
{
// calculate new position based on angles and distance
AZ::Transform rotation = CreateRotationFromEulerAngle(m_rotationType, AZ::DegToRad(m_angleInDegrees));
inOutCameraTransform = rotation;
inOutCameraTransform.SetTranslation(targetTransform.GetTranslation() - rotation.GetBasis(ForwardBackward) * m_distanceFromTarget);
}
} //namespace Camera
@@ -0,0 +1,47 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraTransformBehavior.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/RTTI/ReflectContext.h>
#include "StartingPointCamera/StartingPointCameraConstants.h"
#include <AzCore/Memory/SystemAllocator.h>
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This Camera Transform Behavior will follow the target transform from
/// a given angle of Yaw, Pitch or Roll
//////////////////////////////////////////////////////////////////////////
class FollowTargetFromAngle
: public ICameraTransformBehavior
{
public:
~FollowTargetFromAngle() override = default;
AZ_RTTI(FollowTargetFromAngle, "{4DBE7A2C-8E93-422E-8942-9601A270D37E}", ICameraTransformBehavior)
AZ_CLASS_ALLOCATOR(FollowTargetFromAngle, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTransformBehavior
void AdjustCameraTransform(float deltaTime, const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
float m_angleInDegrees = 0.f;
EulerAngleType m_rotationType = EulerAngleType::Pitch;
float m_distanceFromTarget = 1.0f;
};
} //namespace Camera
@@ -0,0 +1,113 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "FollowTargetFromDistance.h"
#include <AzCore/Math/Transform.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Math/Crc.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include "StartingPointCamera/StartingPointCameraConstants.h"
#include "StartingPointCamera/StartingPointCameraUtilities.h"
namespace Camera
{
void FollowTargetFromDistance::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<FollowTargetFromDistance>()
->Version(2)
->Field("Follow Distance", &FollowTargetFromDistance::m_followDistance)
->Field("Minimum Follow Distance", &FollowTargetFromDistance::m_minFollowDistance)
->Field("Maximum Follow Distance", &FollowTargetFromDistance::m_maxFollowDistance)
->Field("Zoom In Event Name", &FollowTargetFromDistance::m_zoomInEventName)
->Field("Zoom Out Event Name", &FollowTargetFromDistance::m_zoomOutEventName)
->Field("Zoom Speed Scale", &FollowTargetFromDistance::m_zoomSpeedScale)
->Field("Input Source Entity", &FollowTargetFromDistance::m_channelId);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<FollowTargetFromDistance>("FollowTargetFromDistance", "Follows behind the target by Follow Distance meters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(0, &FollowTargetFromDistance::m_followDistance, "Follow Distance", "The distance to follow behind the target in meters")
->Attribute(AZ::Edit::Attributes::Suffix, "m")
->Attribute(AZ::Edit::Attributes::Min, &FollowTargetFromDistance::GetMinimumFollowDistance)
->Attribute(AZ::Edit::Attributes::Max, &FollowTargetFromDistance::GetMaximumFollowDistance)
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ_CRC("RefreshAttributesAndValues"))
->DataElement(0, &FollowTargetFromDistance::m_minFollowDistance, "Minimum Follow Distance", "The MINIMUM distance to follow the behind the target in meters")
->Attribute(AZ::Edit::Attributes::Suffix, "m")
->Attribute(AZ::Edit::Attributes::Min, 0.f)
->Attribute(AZ::Edit::Attributes::Max, &FollowTargetFromDistance::GetMaximumFollowDistance)
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ_CRC("RefreshAttributesAndValues"))
->DataElement(0, &FollowTargetFromDistance::m_maxFollowDistance, "Maximum Follow Distance", "The MAXIMUM distance to follow the behind the target in meters")
->Attribute(AZ::Edit::Attributes::Suffix, "m")
->Attribute(AZ::Edit::Attributes::Min, &FollowTargetFromDistance::GetMinimumFollowDistance)
->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ_CRC("RefreshAttributesAndValues"))
->DataElement(0, &FollowTargetFromDistance::m_zoomInEventName, "Zoom In Event Name", "The name of the event to trigger a zoom in")
->DataElement(0, &FollowTargetFromDistance::m_zoomOutEventName, "Zoom Out Event Name", "The name of the event to trigger a zoom out")
->DataElement(0, &FollowTargetFromDistance::m_zoomSpeedScale, "Zoom Speed Scale", "The amount to scale the incoming zoom event by");
}
}
}
void FollowTargetFromDistance::AdjustCameraTransform(float /*deltaTime*/, const AZ::Transform& /*initialCameraTransform*/, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
{
inOutCameraTransform.SetTranslation(targetTransform.GetTranslation() - targetTransform.GetBasis(ForwardBackward) * m_followDistance);
}
void FollowTargetFromDistance::Activate(AZ::EntityId channelId)
{
m_channelId = channelId;
if (!m_zoomInEventName.empty())
{
AZ::GameplayNotificationId busId(m_channelId, AZ_CRC(m_zoomInEventName.c_str()));
AZ::GameplayNotificationBus::MultiHandler::BusConnect(busId);
}
if (!m_zoomOutEventName.empty())
{
AZ::GameplayNotificationId busId(m_channelId, AZ_CRC(m_zoomOutEventName.c_str()));
AZ::GameplayNotificationBus::MultiHandler::BusConnect(busId);
}
}
void FollowTargetFromDistance::Deactivate()
{
if (!m_zoomInEventName.empty())
{
AZ::GameplayNotificationId busId(m_channelId, AZ_CRC(m_zoomInEventName.c_str()));
AZ::GameplayNotificationBus::MultiHandler::BusDisconnect(busId);
}
if (!m_zoomOutEventName.empty())
{
AZ::GameplayNotificationId busId(m_channelId, AZ_CRC(m_zoomOutEventName.c_str()));
AZ::GameplayNotificationBus::MultiHandler::BusDisconnect(busId);
}
}
void FollowTargetFromDistance::OnEventBegin(const AZStd::any& value)
{
float floatValue = 0.0f;
AZ_Warning("FollowTargetFromDistance", AZStd::any_numeric_cast<float>(&value, floatValue), "Received bad value, expected type numerically convertable to float, got type %s", GetNameFromUuid(value.type()));
if (AZStd::any_numeric_cast<float>(&value, floatValue))
{
m_followDistance = AZ::GetClamp(m_followDistance - (floatValue * m_zoomSpeedScale), m_minFollowDistance, m_maxFollowDistance);
}
}
} // namespace Camera
@@ -0,0 +1,67 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraTransformBehavior.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Math/Transform.h>
#include <LmbrCentral/Scripting/GameplayNotificationBus.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This behavior will cause the camera to follow the target by "Follow Distance"
/// meters. Zoom using action events. Use a distance of 0 for FPS style games
/// and a distance greater than 0 for a Third Person style camera
//////////////////////////////////////////////////////////////////////////
class FollowTargetFromDistance
: public ICameraTransformBehavior
, public AZ::GameplayNotificationBus::MultiHandler
{
public:
~FollowTargetFromDistance() override = default;
AZ_RTTI(FollowTargetFromDistance, "{E6BEDB2C-6812-4369-8C0F-C1E72F380E50}", ICameraTransformBehavior)
AZ_CLASS_ALLOCATOR(FollowTargetFromDistance, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTransformBehavior
void AdjustCameraTransform(float deltaTime, const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform) override;
void Activate(AZ::EntityId) override;
void Deactivate() override;
//////////////////////////////////////////////////////////////////////////
// AZ::GameplayNotificationBus
void OnEventBegin(const AZStd::any&) override;
private:
//////////////////////////////////////////////////////////////////////////
// Editor helpers
float GetMinimumFollowDistance() { return m_minFollowDistance; }
float GetMaximumFollowDistance() { return m_maxFollowDistance; }
//////////////////////////////////////////////////////////////////////////
// Reflected Data
float m_minFollowDistance = 0.f;
float m_followDistance = 0.f;
float m_maxFollowDistance = 0.f;
AZStd::string m_zoomInEventName = "";
AZStd::string m_zoomOutEventName = "";
AZ::EntityId m_channelId;
float m_zoomSpeedScale = 1.f;
};
}
@@ -0,0 +1,48 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "OffsetCameraPosition.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace Camera
{
void OffsetCameraPosition::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<OffsetCameraPosition>()
->Version(1)
->Field("Offset", &OffsetCameraPosition::m_offset)
->Field("Is Offset Relative", &OffsetCameraPosition::m_isRelativeOffset);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<OffsetCameraPosition>("Offset Position", "Offset the Camera's position")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(0, &OffsetCameraPosition::m_offset, "Offset", "The displacement you wish to move the Camera by")
->Attribute(AZ::Edit::Attributes::Suffix, "m")
->DataElement(0, &OffsetCameraPosition::m_isRelativeOffset, "Is Offset Relative", "If yes then the displacement will occur from the perspective of the camera");
}
}
}
void OffsetCameraPosition::AdjustCameraTransform([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
{
AZ::Vector3 currentPosition = targetTransform.GetTranslation();
inOutCameraTransform.SetTranslation(AZ::Vector3::CreateZero());
AZ::Transform rotation = m_isRelativeOffset ? inOutCameraTransform : AZ::Transform::CreateIdentity();
inOutCameraTransform.SetTranslation(currentPosition + rotation.TransformPoint(m_offset));
}
} //namespace Camera
@@ -0,0 +1,44 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraTransformBehavior.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// Use this behavior to offset the camera's position by a fixed amount
//////////////////////////////////////////////////////////////////////////
class OffsetCameraPosition
: public ICameraTransformBehavior
{
public:
~OffsetCameraPosition() override = default;
AZ_RTTI(OffsetCameraPosition, "{DB64D5DA-84B7-45B7-B221-B5A07BDA2F69}", ICameraTransformBehavior)
AZ_CLASS_ALLOCATOR(OffsetCameraPosition, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTransformBehavior
void AdjustCameraTransform(float deltaTime, const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
AZ::Vector3 m_offset = AZ::Vector3::CreateZero();
bool m_isRelativeOffset = false;
};
} // namespace Camera
@@ -0,0 +1,53 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "Rotate.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include "StartingPointCamera/StartingPointCameraUtilities.h"
namespace Camera
{
void Rotate::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<Rotate>()
->Version(1)
->Field("Angle", &Rotate::m_angleInDegrees)
->Field("Axis", &Rotate::m_axisType);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<Rotate>("Rotate", "Rotate Camera Angle degrees about its Axis")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(0, &Rotate::m_angleInDegrees, "Angle", "The angle of rotation")
->Attribute(AZ::Edit::Attributes::Suffix, "degrees")
->DataElement(AZ::Edit::UIHandlers::ComboBox, &Rotate::m_axisType, "Axis", "The relative Axis of rotation")
->EnumAttribute(AxisOfRotation::X_Axis, "X")
->EnumAttribute(AxisOfRotation::Y_Axis, "Y")
->EnumAttribute(AxisOfRotation::Z_Axis, "Z");
}
}
}
void Rotate::AdjustCameraTransform([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& initialCameraTransform, [[maybe_unused]] const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
{
AZ::Vector3 position = inOutCameraTransform.GetTranslation();
inOutCameraTransform.SetTranslation(AZ::Vector3::CreateZero());
AZ::Transform axisRotation = CreateRotationFromEulerAngle(static_cast<EulerAngleType>(m_axisType), AZ::DegToRad(m_angleInDegrees));
inOutCameraTransform = inOutCameraTransform * axisRotation;
inOutCameraTransform.SetTranslation(position);
}
} // namespace Camera
@@ -0,0 +1,45 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <CameraFramework/ICameraTransformBehavior.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/RTTI/ReflectContext.h>
#include "StartingPointCamera/StartingPointCameraConstants.h"
#include <AzCore/Memory/SystemAllocator.h>
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This behavior will rotate the calculated camera transform
//////////////////////////////////////////////////////////////////////////
class Rotate
: public ICameraTransformBehavior
{
public:
~Rotate() override = default;
AZ_RTTI(Rotate, "{EE06111E-75E8-47F0-B243-5A5308A5F605}", ICameraTransformBehavior)
AZ_CLASS_ALLOCATOR(Rotate, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTransformBehavior
void AdjustCameraTransform(float deltaTime, const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
float m_angleInDegrees = 0.f;
AxisOfRotation m_axisType = X_Axis;
};
} // namespace Camera
@@ -0,0 +1,127 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <StartingPointCamera/StartingPointCameraUtilities.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Serialization/SerializeContext.h>
namespace Camera
{
const char* GetNameFromUuid(const AZ::Uuid& uuid)
{
AZ::SerializeContext* serializeContext = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
if (serializeContext)
{
if (const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(uuid))
{
return classData->m_name;
}
}
return "";
}
//////////////////////////////////////////////////////////////////////////
/// This methods will 0 out a vector component and re-normalize it
//////////////////////////////////////////////////////////////////////////
void MaskComponentFromNormalizedVector(AZ::Vector3& v, VectorComponentType vectorComponentType)
{
switch (vectorComponentType)
{
case X_Component:
{
v.SetX(0.f);
break;
}
case Y_Component:
{
v.SetY(0.f);
break;
}
case Z_Component:
{
v.SetZ(0.f);
break;
}
default:
AZ_Assert(false, "MaskComponentFromNormalizedVector: VectorComponentType - unexpected value");
break;
}
v.Normalize();
}
//////////////////////////////////////////////////////////////////////////
/// This will calculate the requested Euler angle from a given AZ::Quaternion
//////////////////////////////////////////////////////////////////////////
float GetEulerAngleFromTransform(const AZ::Transform& rotation, EulerAngleType eulerAngleType)
{
AZ::Vector3 angles = rotation.GetEulerDegrees();
switch (eulerAngleType)
{
case Pitch:
return angles.GetX();
case Roll:
return angles.GetY();
case Yaw:
return angles.GetZ();
default:
AZ_Warning("", false, "GetEulerAngleFromRotation: eulerAngleType - value not supported");
return 0.f;
}
}
//////////////////////////////////////////////////////////////////////////
/// This will calculate an AZ::Transform based on an Euler angle
//////////////////////////////////////////////////////////////////////////
AZ::Transform CreateRotationFromEulerAngle(EulerAngleType rotationType, float radians)
{
switch (rotationType)
{
case Pitch:
return AZ::Transform::CreateRotationX(radians);
case Roll:
return AZ::Transform::CreateRotationY(radians);
case Yaw:
return AZ::Transform::CreateRotationZ(radians);
default:
AZ_Warning("", false, "CreateRotationFromEulerAngle: rotationType - value not supported");
return AZ::Transform::Identity();
}
}
//////////////////////////////////////////////////////////////////////////
/// Creates the Quaternion representing the rotation looking down the vector
//////////////////////////////////////////////////////////////////////////
AZ::Quaternion CreateQuaternionFromViewVector(const AZ::Vector3 lookVector)
{
float twoDimensionLength = AZ::Vector2(lookVector.GetX(), lookVector.GetY()).GetLength();
if (twoDimensionLength > AZ::Constants::FloatEpsilon)
{
AZ::Vector3 hv(lookVector.GetX() / twoDimensionLength, lookVector.GetY() / twoDimensionLength + 1.f, twoDimensionLength + 1.f);
float twoDimensionHVLength = AZ::Vector2(hv.GetX(), hv.GetY()).GetLength();
float twoDZLength = AZ::Vector2(hv.GetZ(), lookVector.GetZ()).GetLength();
float halfCosHV = 0.f;
float halfSinHV = -1.f;
if (twoDimensionHVLength > AZ::Constants::FloatEpsilon)
{
halfCosHV = hv.GetY() / twoDimensionHVLength;
halfSinHV = -hv.GetX() / twoDimensionHVLength;
}
float halfCosZ = hv.GetZ() / twoDZLength;
float halfSinZ = lookVector.GetZ() / twoDZLength;
return AZ::Quaternion(halfCosHV * halfSinZ, halfSinHV * halfSinZ, halfSinHV * halfCosZ, halfCosHV * halfCosZ);
}
return AZ::Quaternion::CreateIdentity();
}
} //namespace Camera
@@ -0,0 +1,96 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
#include "CameraTargetAcquirers/AcquireByEntityId.h"
#include "CameraTargetAcquirers/AcquireByTag.h"
#include "CameraTransformBehaviors/FollowTargetFromDistance.h"
#include "CameraLookAtBehaviors/OffsetPosition.h"
#include "CameraTransformBehaviors/FollowTargetFromAngle.h"
#include "CameraTransformBehaviors/Rotate.h"
#include "CameraTransformBehaviors/OffsetCameraPosition.h"
#include "CameraLookAtBehaviors/SlideAlongAxisBasedOnAngle.h"
#include "CameraLookAtBehaviors/RotateCameraLookAt.h"
#include "CameraTransformBehaviors/FaceTarget.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Module/Module.h>
#include <AzFramework/Metrics/MetricsPlainTextNameRegistration.h>
namespace StartingPointCamera
{
struct StartingPointCameraGemComponent
: public AZ::Component
{
~StartingPointCameraGemComponent() override = default;
AZ_COMPONENT(StartingPointCameraGemComponent, "{728DF62E-6787-4A16-8F07-8A45BECADAD7}");
static void Reflect(AZ::ReflectContext* reflection)
{
Camera::AcquireByEntityId::Reflect(reflection);
Camera::AcquireByTag::Reflect(reflection);
Camera::FollowTargetFromDistance::Reflect(reflection);
Camera::OffsetPosition::Reflect(reflection);
Camera::FollowTargetFromAngle::Reflect(reflection);
Camera::Rotate::Reflect(reflection);
Camera::OffsetCameraPosition::Reflect(reflection);
Camera::SlideAlongAxisBasedOnAngle::Reflect(reflection);
Camera::RotateCameraLookAt::Reflect(reflection);
Camera::FaceTarget::Reflect(reflection);
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection))
{
serializeContext->Class<StartingPointCameraGemComponent, AZ::Component>()
->Version(0)
;
}
}
void Activate() override {}
void Deactivate() override {}
};
class StartingPointCameraModule
: public AZ::Module
{
public:
AZ_RTTI(StartingPointCameraModule, "{87B6E891-9C64-4C5D-9FA1-4079BF6D902D}", AZ::Module);
StartingPointCameraModule()
: AZ::Module()
{
m_descriptors.insert(m_descriptors.end(), {
StartingPointCameraGemComponent::CreateDescriptor(),
});
// This is an internal Amazon gem, so register it's components for metrics tracking, otherwise the name of the component won't get sent back.
// IF YOU ARE A THIRDPARTY WRITING A GEM, DO NOT REGISTER YOUR COMPONENTS WITH EditorMetricsComponentRegistrationBus
AZStd::vector<AZ::Uuid> typeIds;
typeIds.reserve(m_descriptors.size());
for (AZ::ComponentDescriptor* descriptor : m_descriptors)
{
typeIds.emplace_back(descriptor->GetUuid());
}
EBUS_EVENT(AzFramework::MetricsPlainTextNameRegistrationBus, RegisterForNameSending, typeIds);
}
};
}
// DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM
// The first parameter should be GemName_GemIdLower
// The second should be the fully qualified name of the class above
AZ_DECLARE_MODULE_CLASS(Gem_StartingPointCamera, StartingPointCamera::StartingPointCameraModule)
@@ -0,0 +1,12 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "StartingPointCamera_precompiled.h"
@@ -0,0 +1,14 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once