/* * 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 #include #include #include "ScriptCanvasDataInterface.h" namespace ScriptCanvasEditor { class ScriptCanvasQuaternionDataInterface : public ScriptCanvasDataInterface { public: AZ_CLASS_ALLOCATOR(ScriptCanvasQuaternionDataInterface, AZ::SystemAllocator, 0); ScriptCanvasQuaternionDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId) : ScriptCanvasDataInterface(nodeId, slotId) { ConvertToEulerValues(); } ~ScriptCanvasQuaternionDataInterface() = default; int GetElementCount() const override { return 3; } double GetValue(int index) const override { if (index < GetElementCount()) { const ScriptCanvas::Datum* object = GetSlotObject(); if (object) { const AZ::Quaternion* retVal = object->GetAs(); if (retVal) { return aznumeric_cast(static_cast(m_eulerAngles.GetElement(index))); } } } return 0.0; } void SetValue(int index, double value) override { if (index < GetElementCount()) { ScriptCanvas::ModifiableDatumView datumView; ModifySlotObject(datumView); if (datumView.IsValid()) { m_eulerAngles.SetElement(index, aznumeric_cast(value)); AZ::Quaternion newValue = AZ::ConvertEulerDegreesToQuaternion(m_eulerAngles); datumView.SetAs(newValue); PostUndoPoint(); PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid); } } } const char* GetLabel(int index) const override { switch (index) { case 0: return "P"; case 1: return "R"; case 2: return "Y"; default: return "???"; } } AZStd::string GetStyle() const override { return "vectorized"; } AZStd::string GetElementStyle(int index) const override { return AZStd::string::format("quat_%i", index); } const char* GetSuffix(int index) const override { return " deg"; } void OnInputChanged(const ScriptCanvas::SlotId& slotId) override { if (slotId == GetSlotId()) { ConvertToEulerValues(); } ScriptCanvasDataInterface::OnInputChanged(slotId); } private: void ConvertToEulerValues() { const ScriptCanvas::Datum* object = GetSlotObject(); if (object) { const AZ::Quaternion* quat = object->GetAs(); if (quat) { m_eulerAngles = AZ::ConvertTransformToEulerDegrees(AZ::Transform::CreateFromQuaternion((*quat))); } } } AZ::Vector3 m_eulerAngles; }; }