/* * 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 #include namespace UnitTest { using MouseInteraction = AzToolsFramework::ViewportInteraction::MouseInteraction; using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent; using MouseButton = AzToolsFramework::ViewportInteraction::MouseButton; using MouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent; using MousePick = AzToolsFramework::ViewportInteraction::MousePick; AZStd::shared_ptr CreateLinearManipulator( const AzToolsFramework::ManipulatorManagerId manipulatorManagerId) { auto manipulator = AzToolsFramework::LinearManipulator::MakeShared(AZ::Transform::CreateIdentity()); // unit sphere view auto sphereView = AzToolsFramework::CreateManipulatorViewSphere( AZ::Colors::Red, 1.0f, [](const MouseInteraction& /*mouseInteraction*/, const bool /*mouseOver*/, const AZ::Color& defaultColor) { return defaultColor; }, true); // unit sphere bound AzToolsFramework::Picking::BoundShapeSphere sphereBound; sphereBound.m_center = AZ::Vector3::CreateZero(); sphereBound.m_radius = 1.0f; // we need the view to construct the manipulator bounds after the manipulator has been registered auto view = sphereView.get(); // construct view and register with manager AzToolsFramework::ManipulatorViews views; views.emplace_back(AZStd::move(sphereView)); manipulator->SetViews(AZStd::move(views)); manipulator->Register(manipulatorManagerId); // this would occur internally when the manipulator is drawn but we must do manually here view->RefreshBound(manipulatorManagerId, manipulator->GetManipulatorId(), sphereBound); return manipulator; } MousePick CreateWorldSpaceMousePickRay(const AZ::Vector3& origin, const AZ::Vector3& direction) { MousePick mousePick; mousePick.m_rayOrigin = origin; mousePick.m_rayDirection = direction; return mousePick; } MouseInteraction CreateMouseInteraction(const MousePick& worldSpaceRay, MouseButton button) { AzToolsFramework::ViewportInteraction::MouseInteraction interaction; interaction.m_mousePick = worldSpaceRay; interaction.m_mouseButtons.m_mouseButtons = static_cast(button); return interaction; } MouseInteractionEvent CreateMouseInteractionEvent( const MousePick& worldSpaceRay, MouseButton button, MouseEvent event) { return MouseInteractionEvent(CreateMouseInteraction(worldSpaceRay, button), event); } void DispatchMouseInteractionEvent(const MouseInteractionEvent& event) { AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus::Event( AzToolsFramework::GetEntityContextId(), &AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions, event); } AzFramework::CameraState SetCameraStatePosition(const AZ::Vector3& position, AzFramework::CameraState& cameraState) { cameraState.m_position = position; return cameraState; } } // namespace UnitTest