EditorCameraComponent.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzToolsFramework/ToolsComponents/EditorComponentAdapter.h>
  11. #include <AzCore/Math/Color.h>
  12. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  13. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  14. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  15. #include <AzToolsFramework/API/EditorCameraBus.h>
  16. #include <AzFramework/Viewport/ViewportColors.h>
  17. #include <AzFramework/Components/CameraBus.h>
  18. #include <AzFramework/Components/EditorEntityEvents.h>
  19. #include "CameraComponent.h"
  20. #include "CameraComponentController.h"
  21. #include <Atom/RPI.Public/Base.h>
  22. namespace Camera
  23. {
  24. //////////////////////////////////////////////////////////////////////////
  25. /// The CameraComponent holds all of the data necessary for a camera.
  26. /// Get and set data through the CameraRequestBus or TransformBus
  27. //////////////////////////////////////////////////////////////////////////
  28. using EditorCameraComponentBase = AzToolsFramework::Components::EditorComponentAdapter<CameraComponentController, CameraComponent, CameraComponentConfig>;
  29. class EditorCameraComponent
  30. : public EditorCameraComponentBase
  31. , public EditorCameraViewRequestBus::Handler
  32. , private AzFramework::EntityDebugDisplayEventBus::Handler
  33. {
  34. public:
  35. AZ_EDITOR_COMPONENT(EditorCameraComponent, EditorCameraComponentTypeId, AzToolsFramework::Components::EditorComponentBase);
  36. virtual ~EditorCameraComponent() = default;
  37. static void Reflect(AZ::ReflectContext* reflection);
  38. // AZ::Component overrides ...
  39. void Activate() override;
  40. void Deactivate() override;
  41. AZ::u32 OnConfigurationChanged() override;
  42. // AzFramework::DebugDisplayRequestBus::Handler overrides ...
  43. void DisplayEntityViewport(
  44. const AzFramework::ViewportInfo& viewportInfo,
  45. AzFramework::DebugDisplayRequests& debugDisplay) override;
  46. /// EditorCameraViewRequestBus::Handler overrides ...
  47. void ToggleCameraAsActiveView() override;
  48. void MatchViewport() override;
  49. bool IsActiveCamera() const override;
  50. bool GetCameraState(AzFramework::CameraState& cameraState) override;
  51. protected:
  52. void EditorDisplay(AzFramework::DebugDisplayRequests& displayInterface, const AZ::Transform& world);
  53. AZ::Crc32 OnPossessCameraButtonClicked();
  54. AZ::Crc32 OnMatchViewportClicked();
  55. AZStd::string GetCameraViewButtonText() const;
  56. float m_frustumViewPercentLength = 1.f;
  57. AZ::Color m_frustumDrawColor = AzFramework::ViewportColors::HoverColor;
  58. };
  59. } // Camera