/* * 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 "FaceTarget.h" #include #include #include #include #include "StartingPointCamera/StartingPointCameraConstants.h" #include #include #include namespace Camera { void FaceTarget::Reflect(AZ::ReflectContext* reflection) { AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { serializeContext->Class() ->Version(1) ; AZ::EditContext* editContext = serializeContext->GetEditContext(); if (editContext) { editContext->Class("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